src/gui/widgets/qtoolbutton.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtGui module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef QTOOLBUTTON_H
       
    43 #define QTOOLBUTTON_H
       
    44 
       
    45 #include <QtGui/qabstractbutton.h>
       
    46 
       
    47 QT_BEGIN_HEADER
       
    48 
       
    49 QT_BEGIN_NAMESPACE
       
    50 
       
    51 QT_MODULE(Gui)
       
    52 
       
    53 #ifndef QT_NO_TOOLBUTTON
       
    54 
       
    55 class QToolButtonPrivate;
       
    56 class QMenu;
       
    57 class QStyleOptionToolButton;
       
    58 
       
    59 class Q_GUI_EXPORT QToolButton : public QAbstractButton
       
    60 {
       
    61     Q_OBJECT
       
    62     Q_ENUMS(Qt::ToolButtonStyle Qt::ArrowType ToolButtonPopupMode)
       
    63 #ifndef QT_NO_MENU
       
    64     Q_PROPERTY(ToolButtonPopupMode popupMode READ popupMode WRITE setPopupMode)
       
    65 #endif
       
    66     Q_PROPERTY(Qt::ToolButtonStyle toolButtonStyle READ toolButtonStyle WRITE setToolButtonStyle)
       
    67     Q_PROPERTY(bool autoRaise READ autoRaise WRITE setAutoRaise)
       
    68     Q_PROPERTY(Qt::ArrowType arrowType READ arrowType WRITE setArrowType)
       
    69 
       
    70 public:
       
    71     enum ToolButtonPopupMode {
       
    72         DelayedPopup,
       
    73         MenuButtonPopup,
       
    74         InstantPopup
       
    75     };
       
    76 
       
    77     explicit QToolButton(QWidget * parent=0);
       
    78     ~QToolButton();
       
    79 
       
    80     QSize sizeHint() const;
       
    81     QSize minimumSizeHint() const;
       
    82 
       
    83     Qt::ToolButtonStyle toolButtonStyle() const;
       
    84 
       
    85     Qt::ArrowType arrowType() const;
       
    86     void setArrowType(Qt::ArrowType type);
       
    87 
       
    88 #ifndef QT_NO_MENU
       
    89     void setMenu(QMenu* menu);
       
    90     QMenu* menu() const;
       
    91 
       
    92     void setPopupMode(ToolButtonPopupMode mode);
       
    93     ToolButtonPopupMode popupMode() const;
       
    94 #endif
       
    95 
       
    96     QAction *defaultAction() const;
       
    97 
       
    98     void setAutoRaise(bool enable);
       
    99     bool autoRaise() const;
       
   100 
       
   101 public Q_SLOTS:
       
   102 #ifndef QT_NO_MENU
       
   103     void showMenu();
       
   104 #endif
       
   105     void setToolButtonStyle(Qt::ToolButtonStyle style);
       
   106     void setDefaultAction(QAction *);
       
   107 
       
   108 Q_SIGNALS:
       
   109     void triggered(QAction *);
       
   110 
       
   111 protected:
       
   112     QToolButton(QToolButtonPrivate &, QWidget* parent);
       
   113     bool event(QEvent *e);
       
   114     void mousePressEvent(QMouseEvent *);
       
   115     void mouseReleaseEvent(QMouseEvent *);
       
   116     void paintEvent(QPaintEvent *);
       
   117     void actionEvent(QActionEvent *);
       
   118 
       
   119     void enterEvent(QEvent *);
       
   120     void leaveEvent(QEvent *);
       
   121     void timerEvent(QTimerEvent *);
       
   122     void changeEvent(QEvent *);
       
   123 
       
   124     bool hitButton(const QPoint &pos) const;
       
   125     void nextCheckState();
       
   126     void initStyleOption(QStyleOptionToolButton *option) const;
       
   127 
       
   128 private:
       
   129     Q_DISABLE_COPY(QToolButton)
       
   130     Q_DECLARE_PRIVATE(QToolButton)
       
   131 #ifndef QT_NO_MENU
       
   132     Q_PRIVATE_SLOT(d_func(), void _q_buttonPressed())
       
   133     Q_PRIVATE_SLOT(d_func(), void _q_updateButtonDown())
       
   134     Q_PRIVATE_SLOT(d_func(), void _q_menuTriggered(QAction*))
       
   135 #endif
       
   136     Q_PRIVATE_SLOT(d_func(), void _q_actionTriggered())
       
   137 
       
   138 #ifdef QT3_SUPPORT
       
   139 public:
       
   140     enum TextPosition {
       
   141         BesideIcon,
       
   142         BelowIcon
       
   143         , Right = BesideIcon,
       
   144         Under = BelowIcon
       
   145     };
       
   146 
       
   147     QT3_SUPPORT_CONSTRUCTOR QToolButton(QWidget * parent, const char* name);
       
   148     QT3_SUPPORT_CONSTRUCTOR QToolButton(Qt::ArrowType type, QWidget *parent, const char* name);
       
   149     QT3_SUPPORT_CONSTRUCTOR QToolButton( const QIcon& s, const QString &textLabel,
       
   150                                        const QString& grouptext,
       
   151                                        QObject * receiver, const char* slot,
       
   152                                        QWidget * parent, const char* name=0 );
       
   153     inline QT3_SUPPORT void setPixmap(const QPixmap &pixmap) { setIcon(static_cast<QIcon>(pixmap)); }
       
   154     QT3_SUPPORT void setOnIconSet(const QIcon&);
       
   155     QT3_SUPPORT void setOffIconSet(const QIcon&);
       
   156     inline QT3_SUPPORT void setIconSet(const QIcon &icon){setIcon(icon);}
       
   157     QT3_SUPPORT void setIconSet(const QIcon &, bool on);
       
   158     inline QT3_SUPPORT void setTextLabel(const QString &text, bool tooltip = true) {
       
   159         setText(text);
       
   160 #ifndef QT_NO_TOOLTIP
       
   161         if (tooltip)
       
   162             setToolTip(text);
       
   163 #else
       
   164         Q_UNUSED(tooltip);
       
   165 #endif
       
   166     }
       
   167     inline QT3_SUPPORT QString textLabel() const { return text(); }
       
   168     QT3_SUPPORT QIcon onIconSet() const;
       
   169     QT3_SUPPORT QIcon offIconSet() const;
       
   170     QT3_SUPPORT QIcon iconSet(bool on) const;
       
   171     inline QT3_SUPPORT QIcon iconSet() const { return icon(); }
       
   172     inline QT3_SUPPORT void openPopup()  { showMenu(); }
       
   173     inline QT3_SUPPORT void setPopup(QMenu* popup) {setMenu(popup); }
       
   174     inline QT3_SUPPORT QMenu* popup() const { return menu(); }
       
   175     inline QT3_SUPPORT bool usesBigPixmap() const { return iconSize().height() > 22; }
       
   176     inline QT3_SUPPORT bool usesTextLabel() const { return toolButtonStyle() != Qt::ToolButtonIconOnly; }
       
   177     inline QT3_SUPPORT TextPosition textPosition() const
       
   178     { return toolButtonStyle() == Qt::ToolButtonTextUnderIcon ? BelowIcon : BesideIcon; }
       
   179     QT3_SUPPORT void setPopupDelay(int delay);
       
   180     QT3_SUPPORT int popupDelay() const;
       
   181 
       
   182 public Q_SLOTS:
       
   183     QT_MOC_COMPAT void setUsesBigPixmap(bool enable)
       
   184         { setIconSize(enable?QSize(32,32):QSize(22,22)); }
       
   185     QT_MOC_COMPAT void setUsesTextLabel(bool enable)
       
   186         { setToolButtonStyle(enable?Qt::ToolButtonTextUnderIcon : Qt::ToolButtonIconOnly); }
       
   187     QT_MOC_COMPAT void setTextPosition(QToolButton::TextPosition pos)
       
   188         { setToolButtonStyle(pos == BesideIcon ? Qt::ToolButtonTextBesideIcon : Qt::ToolButtonTextUnderIcon); }
       
   189 
       
   190 #endif
       
   191 };
       
   192 
       
   193 #endif // QT_NO_TOOLBUTTON
       
   194 
       
   195 QT_END_NAMESPACE
       
   196 
       
   197 QT_END_HEADER
       
   198 
       
   199 #endif // QTOOLBUTTON_H