Qt 4.8
qaction.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 QACTION_H
43 #define QACTION_H
44 
45 #include <QtGui/qkeysequence.h>
46 #include <QtCore/qstring.h>
47 #include <QtGui/qwidget.h>
48 #include <QtCore/qvariant.h>
49 #include <QtGui/qicon.h>
50 
52 
54 
55 QT_MODULE(Gui)
56 
57 #ifndef QT_NO_ACTION
58 
59 class QMenu;
60 class QActionGroup;
61 class QActionPrivate;
62 class QGraphicsWidget;
63 
65 {
66  Q_OBJECT
68 
72  bool checkable;
73  bool checked;
74  bool enabled;
75  QIcon icon;
77  QString iconText;
78  QString toolTip;
79  QString statusTip;
80  QString whatsThis;
81  QFont font;
82 #ifndef QT_NO_SHORTCUT
85  bool autoRepeat;
86 #endif
87  bool visible;
92 
93 public:
94  enum MenuRole { NoRole, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole,
95  AboutRole, PreferencesRole, QuitRole };
96  enum SoftKeyRole {
97  NoSoftKey, PositiveSoftKey, NegativeSoftKey, SelectSoftKey };
98  enum Priority { LowPriority = 0,
99  NormalPriority = 128,
100  HighPriority = 256};
101  explicit QAction(QObject* parent);
102  QAction(const QString &text, QObject* parent);
103  QAction(const QIcon &icon, const QString &text, QObject* parent);
104 
105 #ifdef QT3_SUPPORT
106  QT3_SUPPORT_CONSTRUCTOR QAction(QObject* parent, const char* name);
107  QT3_SUPPORT_CONSTRUCTOR QAction(const QString &text, const QKeySequence &shortcut,
108  QObject* parent, const char* name);
109  QT3_SUPPORT_CONSTRUCTOR QAction(const QIcon &icon, const QString &text,
110  const QKeySequence &shortcut,
111  QObject* parent, const char* name);
112 #endif
113  ~QAction();
114 
115  void setActionGroup(QActionGroup *group);
116  QActionGroup *actionGroup() const;
117  void setIcon(const QIcon &icon);
118  QIcon icon() const;
119 
120  void setText(const QString &text);
121  QString text() const;
122 
123  void setIconText(const QString &text);
124  QString iconText() const;
125 
126  void setToolTip(const QString &tip);
127  QString toolTip() const;
128 
129  void setStatusTip(const QString &statusTip);
130  QString statusTip() const;
131 
132  void setWhatsThis(const QString &what);
133  QString whatsThis() const;
134 
135  void setPriority(Priority priority);
136  Priority priority() const;
137 
138 #ifndef QT_NO_MENU
139  QMenu *menu() const;
140  void setMenu(QMenu *menu);
141 #endif
142 
143  void setSeparator(bool b);
144  bool isSeparator() const;
145 
146 #ifndef QT_NO_SHORTCUT
147  void setShortcut(const QKeySequence &shortcut);
148  QKeySequence shortcut() const;
149 
150  void setShortcuts(const QList<QKeySequence> &shortcuts);
151  void setShortcuts(QKeySequence::StandardKey);
152  QList<QKeySequence> shortcuts() const;
153 
154  void setShortcutContext(Qt::ShortcutContext context);
155  Qt::ShortcutContext shortcutContext() const;
156 
157  void setAutoRepeat(bool);
158  bool autoRepeat() const;
159 #endif
160 
161  void setFont(const QFont &font);
162  QFont font() const;
163 
164  void setCheckable(bool);
165  bool isCheckable() const;
166 
167  QVariant data() const;
168  void setData(const QVariant &var);
169 
170  bool isChecked() const;
171 
172  bool isEnabled() const;
173 
174  bool isVisible() const;
175 
176  enum ActionEvent { Trigger, Hover };
177  void activate(ActionEvent event);
178  bool showStatusText(QWidget *widget=0);
179 
180  void setMenuRole(MenuRole menuRole);
181  MenuRole menuRole() const;
182 
183  void setSoftKeyRole(SoftKeyRole softKeyRole);
184  SoftKeyRole softKeyRole() const;
185 
186  void setIconVisibleInMenu(bool visible);
187  bool isIconVisibleInMenu() const;
188 
189 #ifdef QT3_SUPPORT
190  inline QT3_SUPPORT void setMenuText(const QString &text) { setText(text); }
191  inline QT3_SUPPORT QString menuText() const { return text(); }
192  inline QT3_SUPPORT bool isOn() const { return isChecked(); }
193  inline QT3_SUPPORT bool isToggleAction() const { return isCheckable(); }
194  inline QT3_SUPPORT void setToggleAction(bool b) { setCheckable(b); }
195  inline QT3_SUPPORT void setIconSet(const QIcon &i) { setIcon(i); }
196  inline QT3_SUPPORT QIcon iconSet() const { return icon(); }
197  inline QT3_SUPPORT bool addTo(QWidget *w) { w->addAction(this); return true; }
198  inline QT3_SUPPORT bool removeFrom(QWidget *w) { w->removeAction(this); return true; }
199  inline QT3_SUPPORT void setAccel(const QKeySequence &shortcut) { setShortcut(shortcut); }
200  inline QT3_SUPPORT QKeySequence accel() const { return shortcut(); }
201 #endif
202 
203  QWidget *parentWidget() const;
204 
205  QList<QWidget *> associatedWidgets() const;
206 #ifndef QT_NO_GRAPHICSVIEW
207  QList<QGraphicsWidget *> associatedGraphicsWidgets() const; // ### suboptimal
208 #endif
209 
210 protected:
211  bool event(QEvent *);
212  QAction(QActionPrivate &dd, QObject *parent);
213 
214 public Q_SLOTS:
215 #ifdef QT3_SUPPORT
216  inline QT_MOC_COMPAT void setOn(bool b) { setChecked(b); }
217 #endif
218  void trigger() { activate(Trigger); }
219  void hover() { activate(Hover); }
220  void setChecked(bool);
221  void toggle();
222  void setEnabled(bool);
223  inline void setDisabled(bool b) { setEnabled(!b); }
224  void setVisible(bool);
225 
226 Q_SIGNALS:
227  void changed();
228  void triggered(bool checked = false);
229  void hovered();
230  void toggled(bool);
231 #ifdef QT3_SUPPORT
232  QT_MOC_COMPAT void activated(int = 0);
233 #endif
234 
235 private:
237 
238 #ifdef QT3_SUPPORT
239  friend class QMenuItem;
240 #endif
241  friend class QGraphicsWidget;
242  friend class QWidget;
243  friend class QActionGroup;
244  friend class QMenu;
245  friend class QMenuPrivate;
246  friend class QMenuBar;
247  friend class QShortcutMap;
248  friend class QToolButton;
249 #ifdef Q_WS_MAC
250  friend void qt_mac_clear_status_text(QAction *action);
251 #endif
252 };
253 
255 #include <QtGui/qactiongroup.h>
257 
258 #endif // QT_NO_ACTION
259 
261 
263 
264 #endif // QACTION_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
#define QT_MOC_COMPAT
Definition: qglobal.h:1128
void hover()
This is a convenience slot that calls activate(Hover).
Definition: qaction.h:219
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
EventRef event
QPointer< QWidget > widget
#define QT_MODULE(x)
Definition: qglobal.h:2783
QKeySequence shortcut
the action&#39;s primary shortcut key
Definition: qaction.h:83
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
ActionEvent
This enum type is used when calling QAction::activate()
Definition: qaction.h:176
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
Priority
This enum defines priorities for actions in user interface.
Definition: qaction.h:98
void setDisabled(bool b)
This is a convenience function for the enabled property, that is useful for signals–slots connection...
Definition: qaction.h:223
#define QT_END_INCLUDE_NAMESPACE
This macro is equivalent to QT_BEGIN_NAMESPACE.
Definition: qglobal.h:92
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
StandardKey
This enum represent standard key bindings.
Definition: qkeysequence.h:75
#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
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
#define Q_SIGNALS
Definition: qobjectdefs.h:72
void addAction(QAction *action)
Appends the action action to this widget&#39;s list of actions.
Definition: qwidget.cpp:3317
bool iconVisibleInMenu
Whether or not an action should show an icon in a menu.
Definition: qaction.h:90
The QActionGroup class groups actions together.
Definition: qactiongroup.h:57
MenuRole menuRole
the action&#39;s menu role
Definition: qaction.h:88
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void trigger()
This is a convenience slot that calls activate(Trigger).
Definition: qaction.h:218
static bool setData(const QByteArray &data, STGMEDIUM *pmedium)
Definition: qmime_win.cpp:141
const char * name
static const char * data(const QByteArray &arr)
bool visible
whether the action can be seen (e.g.
Definition: qaction.h:87
static bool isSeparator(register char c)
SoftKeyRole
This enum describes how an action should be placed in the softkey bar.
Definition: qaction.h:96
Priority priority
the actions&#39;s priority in the user interface.
Definition: qaction.h:91
#define Q_OBJECT
Definition: qobjectdefs.h:157
static QWidget * parentWidget(const QWidget *w)
bool autoRepeat
whether the action can auto repeat
Definition: qaction.h:85
SoftKeyRole softKeyRole
the action&#39;s softkey role
Definition: qaction.h:89
The QMenuBar class provides a horizontal menu bar.
Definition: qmenubar.h:62
The QKeySequence class encapsulates a key sequence as used by shortcuts.
Definition: qkeysequence.h:72
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
Qt::ShortcutContext shortcutContext
the context for the action&#39;s shortcut
Definition: qaction.h:84
void removeAction(QAction *action)
Removes the action action from this widget&#39;s list of actions.
Definition: qwidget.cpp:3386
MenuRole
This enum describes how an action should be moved into the application menu on Mac OS X...
Definition: qaction.h:94
#define QT_BEGIN_INCLUDE_NAMESPACE
This macro is equivalent to QT_END_NAMESPACE.
Definition: qglobal.h:91
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
ShortcutContext
Definition: qnamespace.h:1478
The QToolButton class provides a quick-access button to commands or options, usually used inside a QT...
Definition: qtoolbutton.h:59
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define QT_END_HEADER
Definition: qglobal.h:137
#define enabled
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
#define text
Definition: qobjectdefs.h:80
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60