QtGui/qtoolbutton.h Source File

qtoolbutton.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QTOOLBUTTON_H
43 #define QTOOLBUTTON_H
44 
45 #include <QtGui/qabstractbutton.h>
46 
48 
50 
51 QT_MODULE(Gui)
52 
53 #ifndef QT_NO_TOOLBUTTON
54 
55 class QToolButtonPrivate;
56 class QMenu;
58 
59 class Q_GUI_EXPORT QToolButton : public QAbstractButton
60 {
61  Q_OBJECT
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 {
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);
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 
196 
198 
199 #endif // QTOOLBUTTON_H
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:872
void setIcon(const QIcon &icon)
GLint mode
Definition: GLee.h:4479
ArrowType
Definition: qnamespace.h:1126
#define QT_END_NAMESPACE
Definition: qglobal.h:128
int height() const
Definition: qsize.h:129
#define Q_PROPERTY(text)
Definition: qobjectdefs.h:80
#define QT_BEGIN_HEADER
Definition: qglobal.h:141
void setToolTip(const QString &)
GLXFBConfig Pixmap pixmap
Definition: GLee.h:10237
Definition: qnamespace.h:54
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
virtual void paintEvent(QPaintEvent *e)=0
#define Q_SLOTS
Definition: qobjectdefs.h:71
#define Q_SIGNALS
Definition: qobjectdefs.h:72
Definition: qicon.h:60
QString text() const
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
Definition: qpoint.h:53
virtual void nextCheckState()
#define QT_BEGIN_NAMESPACE
Definition: qglobal.h:127
void setIconSize(const QSize &size)
Definition: qmenu.h:72
virtual QSize sizeHint() const
void setText(const QString &text)
#define Q_OBJECT
Definition: qobjectdefs.h:157
QSize iconSize() const
void changeEvent(QEvent *e)
void mousePressEvent(QMouseEvent *e)
QIcon icon() const
Definition: qsize.h:53
GLuint const GLchar * name
Definition: GLee.h:1704
ToolButtonStyle
Definition: qnamespace.h:1572
bool event(QEvent *e)
virtual QSize minimumSizeHint() const
void timerEvent(QTimerEvent *e)
void mouseReleaseEvent(QMouseEvent *e)
GLdouble s
Definition: GLee.h:1173
#define QT_END_HEADER
Definition: qglobal.h:142
virtual bool hitButton(const QPoint &pos) const
virtual void leaveEvent(QEvent *)
virtual void actionEvent(QActionEvent *)
virtual void enterEvent(QEvent *)