Qt 4.8
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 
60 {
61  Q_OBJECT
63 #ifndef QT_NO_MENU
64  ToolButtonPopupMode popupMode;
65 #endif
67  bool autoRaise;
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:
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:
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 public:
139 #ifdef QT3_SUPPORT
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
ToolButtonPopupMode
Describes how a menu should be popped up for tool buttons that has a menu set or contains a list of a...
Definition: qtoolbutton.h:71
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
#define QT_MOC_COMPAT
Definition: qglobal.h:1128
bool autoRaise
whether auto-raising is enabled or not.
Definition: qtoolbutton.h:67
int type
Definition: qmetatype.cpp:239
Qt::ArrowType arrowType
whether the button displays an arrow instead of a normal icon
Definition: qtoolbutton.h:68
Qt::ToolButtonStyle toolButtonStyle
whether the tool button displays an icon only, text only, or text beside/below the icon...
Definition: qtoolbutton.h:66
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QString text() const
void setText(const QString &text)
#define QT_MODULE(x)
Definition: qglobal.h:2783
virtual QSize minimumSizeHint() const
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
virtual void paintEvent(QPaintEvent *e)=0
Reimplemented Function
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
void timerEvent(QTimerEvent *e)
This event handler can be reimplemented in a subclass to receive timer events for the object...
virtual void leaveEvent(QEvent *)
This event handler can be reimplemented in a subclass to receive widget leave events which are passed...
Definition: qwidget.cpp:9491
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
The QActionEvent class provides an event that is generated when a QAction is added, removed, or changed.
Definition: qevent.h:632
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_SIGNALS
Definition: qobjectdefs.h:72
The QStyleOptionToolButton class is used to describe the parameters for drawing a tool button...
Definition: qstyleoption.h:768
virtual QSize sizeHint() const
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
bool event(QEvent *e)
Reimplemented Function
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
virtual void nextCheckState()
This virtual handler is called when a button is clicked.
const char * name
virtual void actionEvent(QActionEvent *)
This event handler is called with the given event whenever the widget&#39;s actions are changed...
Definition: qwidget.cpp:9600
#define Q_OBJECT
Definition: qobjectdefs.h:157
void setToolTip(const QString &)
Definition: qwidget.cpp:11600
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
QSize iconSize() const
void mouseReleaseEvent(QMouseEvent *e)
Reimplemented Function
void changeEvent(QEvent *e)
Reimplemented Function
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
void setIconSize(const QSize &size)
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int height() const
Returns the height.
Definition: qsize.h:129
ToolButtonPopupMode popupMode
describes the way that popup menus are used with tool buttons
Definition: qtoolbutton.h:64
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
ToolButtonStyle
Definition: qnamespace.h:1572
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
virtual bool hitButton(const QPoint &pos) const
Returns true if pos is inside the clickable button rectangle; otherwise returns false.
The QToolButton class provides a quick-access button to commands or options, usually used inside a QT...
Definition: qtoolbutton.h:59
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
void setIcon(const QIcon &icon)
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define QT_END_HEADER
Definition: qglobal.h:137
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
virtual void enterEvent(QEvent *)
This event handler can be reimplemented in a subclass to receive widget enter events which are passed...
Definition: qwidget.cpp:9475
#define text
Definition: qobjectdefs.h:80
void mousePressEvent(QMouseEvent *e)
Reimplemented Function
QIcon icon() const
ArrowType
Definition: qnamespace.h:1126
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60