qtoolbutton.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtGui module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QTOOLBUTTON_H
00043 #define QTOOLBUTTON_H
00044 
00045 #include <QtGui/qabstractbutton.h>
00046 
00047 QT_BEGIN_HEADER
00048 
00049 QT_BEGIN_NAMESPACE
00050 
00051 QT_MODULE(Gui)
00052 
00053 #ifndef QT_NO_TOOLBUTTON
00054 
00055 class QToolButtonPrivate;
00056 class QMenu;
00057 class QStyleOptionToolButton;
00058 
00059 class Q_GUI_EXPORT QToolButton : public QAbstractButton
00060 {
00061     Q_OBJECT
00062     Q_ENUMS(Qt::ToolButtonStyle Qt::ArrowType ToolButtonPopupMode)
00063 #ifndef QT_NO_MENU
00064     Q_PROPERTY(ToolButtonPopupMode popupMode READ popupMode WRITE setPopupMode)
00065 #endif
00066     Q_PROPERTY(Qt::ToolButtonStyle toolButtonStyle READ toolButtonStyle WRITE setToolButtonStyle)
00067     Q_PROPERTY(bool autoRaise READ autoRaise WRITE setAutoRaise)
00068     Q_PROPERTY(Qt::ArrowType arrowType READ arrowType WRITE setArrowType)
00069 
00070 public:
00071     enum ToolButtonPopupMode {
00072         DelayedPopup,
00073         MenuButtonPopup,
00074         InstantPopup
00075     };
00076 
00077     explicit QToolButton(QWidget * parent=0);
00078     ~QToolButton();
00079 
00080     QSize sizeHint() const;
00081     QSize minimumSizeHint() const;
00082 
00083     Qt::ToolButtonStyle toolButtonStyle() const;
00084 
00085     Qt::ArrowType arrowType() const;
00086     void setArrowType(Qt::ArrowType type);
00087 
00088 #ifndef QT_NO_MENU
00089     void setMenu(QMenu* menu);
00090     QMenu* menu() const;
00091 
00092     void setPopupMode(ToolButtonPopupMode mode);
00093     ToolButtonPopupMode popupMode() const;
00094 #endif
00095 
00096     QAction *defaultAction() const;
00097 
00098     void setAutoRaise(bool enable);
00099     bool autoRaise() const;
00100 
00101 public Q_SLOTS:
00102 #ifndef QT_NO_MENU
00103     void showMenu();
00104 #endif
00105     void setToolButtonStyle(Qt::ToolButtonStyle style);
00106     void setDefaultAction(QAction *);
00107 
00108 Q_SIGNALS:
00109     void triggered(QAction *);
00110 
00111 protected:
00112     QToolButton(QToolButtonPrivate &, QWidget* parent);
00113     bool event(QEvent *e);
00114     void mousePressEvent(QMouseEvent *);
00115     void mouseReleaseEvent(QMouseEvent *);
00116     void paintEvent(QPaintEvent *);
00117     void actionEvent(QActionEvent *);
00118 
00119     void enterEvent(QEvent *);
00120     void leaveEvent(QEvent *);
00121     void timerEvent(QTimerEvent *);
00122     void changeEvent(QEvent *);
00123 
00124     bool hitButton(const QPoint &pos) const;
00125     void nextCheckState();
00126     void initStyleOption(QStyleOptionToolButton *option) const;
00127 
00128 private:
00129     Q_DISABLE_COPY(QToolButton)
00130     Q_DECLARE_PRIVATE(QToolButton)
00131 #ifndef QT_NO_MENU
00132     Q_PRIVATE_SLOT(d_func(), void _q_buttonPressed())
00133     Q_PRIVATE_SLOT(d_func(), void _q_updateButtonDown())
00134     Q_PRIVATE_SLOT(d_func(), void _q_menuTriggered(QAction*))
00135 #endif
00136     Q_PRIVATE_SLOT(d_func(), void _q_actionTriggered())
00137 
00138 #ifdef QT3_SUPPORT
00139 public:
00140     enum TextPosition {
00141         BesideIcon,
00142         BelowIcon
00143         , Right = BesideIcon,
00144         Under = BelowIcon
00145     };
00146 
00147     QT3_SUPPORT_CONSTRUCTOR QToolButton(QWidget * parent, const char* name);
00148     QT3_SUPPORT_CONSTRUCTOR QToolButton(Qt::ArrowType type, QWidget *parent, const char* name);
00149     QT3_SUPPORT_CONSTRUCTOR QToolButton( const QIcon& s, const QString &textLabel,
00150                                        const QString& grouptext,
00151                                        QObject * receiver, const char* slot,
00152                                        QWidget * parent, const char* name=0 );
00153     inline QT3_SUPPORT void setPixmap(const QPixmap &pixmap) { setIcon(static_cast<QIcon>(pixmap)); }
00154     QT3_SUPPORT void setOnIconSet(const QIcon&);
00155     QT3_SUPPORT void setOffIconSet(const QIcon&);
00156     inline QT3_SUPPORT void setIconSet(const QIcon &icon){setIcon(icon);}
00157     QT3_SUPPORT void setIconSet(const QIcon &, bool on);
00158     inline QT3_SUPPORT void setTextLabel(const QString &text, bool tooltip = true) {
00159         setText(text);
00160 #ifndef QT_NO_TOOLTIP
00161         if (tooltip)
00162             setToolTip(text);
00163 #else
00164         Q_UNUSED(tooltip);
00165 #endif
00166     }
00167     inline QT3_SUPPORT QString textLabel() const { return text(); }
00168     QT3_SUPPORT QIcon onIconSet() const;
00169     QT3_SUPPORT QIcon offIconSet() const;
00170     QT3_SUPPORT QIcon iconSet(bool on) const;
00171     inline QT3_SUPPORT QIcon iconSet() const { return icon(); }
00172     inline QT3_SUPPORT void openPopup()  { showMenu(); }
00173     inline QT3_SUPPORT void setPopup(QMenu* popup) {setMenu(popup); }
00174     inline QT3_SUPPORT QMenu* popup() const { return menu(); }
00175     inline QT3_SUPPORT bool usesBigPixmap() const { return iconSize().height() > 22; }
00176     inline QT3_SUPPORT bool usesTextLabel() const { return toolButtonStyle() != Qt::ToolButtonIconOnly; }
00177     inline QT3_SUPPORT TextPosition textPosition() const
00178     { return toolButtonStyle() == Qt::ToolButtonTextUnderIcon ? BelowIcon : BesideIcon; }
00179     QT3_SUPPORT void setPopupDelay(int delay);
00180     QT3_SUPPORT int popupDelay() const;
00181 
00182 public Q_SLOTS:
00183     QT_MOC_COMPAT void setUsesBigPixmap(bool enable)
00184         { setIconSize(enable?QSize(32,32):QSize(22,22)); }
00185     QT_MOC_COMPAT void setUsesTextLabel(bool enable)
00186         { setToolButtonStyle(enable?Qt::ToolButtonTextUnderIcon : Qt::ToolButtonIconOnly); }
00187     QT_MOC_COMPAT void setTextPosition(QToolButton::TextPosition pos)
00188         { setToolButtonStyle(pos == BesideIcon ? Qt::ToolButtonTextBesideIcon : Qt::ToolButtonTextUnderIcon); }
00189 
00190 #endif
00191 };
00192 
00193 #endif // QT_NO_TOOLBUTTON
00194 
00195 QT_END_NAMESPACE
00196 
00197 QT_END_HEADER
00198 
00199 #endif // QTOOLBUTTON_H