Go to the
documentation of this file.
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
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