QtGui/qaction.h Source File

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 
64 class Q_GUI_EXPORT QAction : public QObject
65 {
66  Q_OBJECT
67  Q_DECLARE_PRIVATE(QAction)
68 
72  Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY changed)
73  Q_PROPERTY(bool checked READ isChecked WRITE setChecked DESIGNABLE isCheckable NOTIFY toggled)
74  Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY changed)
75  Q_PROPERTY(QIcon icon READ icon WRITE setIcon NOTIFY changed)
76  Q_PROPERTY(QString text READ text WRITE setText NOTIFY changed)
77  Q_PROPERTY(QString iconText READ iconText WRITE setIconText NOTIFY changed)
78  Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip NOTIFY changed)
79  Q_PROPERTY(QString statusTip READ statusTip WRITE setStatusTip NOTIFY changed)
80  Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis NOTIFY changed)
81  Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY changed)
82 #ifndef QT_NO_SHORTCUT
83  Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut NOTIFY changed)
84  Q_PROPERTY(Qt::ShortcutContext shortcutContext READ shortcutContext WRITE setShortcutContext NOTIFY changed)
85  Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat NOTIFY changed)
86 #endif
87  Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY changed)
88  Q_PROPERTY(MenuRole menuRole READ menuRole WRITE setMenuRole NOTIFY changed)
89  Q_PROPERTY(SoftKeyRole softKeyRole READ softKeyRole WRITE setSoftKeyRole NOTIFY changed)
90  Q_PROPERTY(bool iconVisibleInMenu READ isIconVisibleInMenu WRITE setIconVisibleInMenu NOTIFY changed)
91  Q_PROPERTY(Priority priority READ priority WRITE setPriority)
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:
236  Q_DISABLE_COPY(QAction)
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
#define QT_END_NAMESPACE
Definition: qglobal.h:128
#define Q_PROPERTY(text)
Definition: qobjectdefs.h:80
void removeAction(QAction *action)
#define QT_BEGIN_HEADER
Definition: qglobal.h:141
Definition: qnamespace.h:54
#define QT_END_INCLUDE_NAMESPACE
Definition: qglobal.h:131
#define Q_SLOTS
Definition: qobjectdefs.h:71
void hover()
Definition: qaction.h:219
#define Q_SIGNALS
Definition: qobjectdefs.h:72
Definition: qicon.h:60
Priority
Definition: qaction.h:98
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
SoftKeyRole
Definition: qaction.h:96
void setDisabled(bool b)
Definition: qaction.h:223
#define QT_BEGIN_NAMESPACE
Definition: qglobal.h:127
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: GLee.h:880
Definition: qfont.h:64
void trigger()
Definition: qaction.h:218
Definition: qmenu.h:72
#define Q_OBJECT
Definition: qobjectdefs.h:157
GLubyte GLubyte b
Definition: GLee.h:5404
MenuRole
Definition: qaction.h:94
void addAction(QAction *action)
virtual bool event(QEvent *)
GLuint const GLchar * name
Definition: GLee.h:1704
GLXContext context
Definition: GLee.h:10414
ShortcutContext
Definition: qnamespace.h:1478
#define QT_BEGIN_INCLUDE_NAMESPACE
Definition: qglobal.h:130
GLubyte GLubyte GLubyte GLubyte w
Definition: GLee.h:1775
ActionEvent
Definition: qaction.h:176
#define QT_END_HEADER
Definition: qglobal.h:142