1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
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 The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
51 QT_BEGIN_HEADER
52 
53 QT_BEGIN_NAMESPACE
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 
69     Q_ENUMS(MenuRole)
70     Q_ENUMS(SoftKeyRole)
71     Q_ENUMS(Priority)
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
setMenuText(const QString & text)190     inline QT3_SUPPORT void setMenuText(const QString &text) { setText(text); }
menuText()191     inline QT3_SUPPORT QString menuText() const { return text(); }
isOn()192     inline QT3_SUPPORT bool isOn() const { return isChecked(); }
isToggleAction()193     inline QT3_SUPPORT bool isToggleAction() const { return isCheckable(); }
setToggleAction(bool b)194     inline QT3_SUPPORT void setToggleAction(bool b) { setCheckable(b); }
setIconSet(const QIcon & i)195     inline QT3_SUPPORT void setIconSet(const QIcon &i) { setIcon(i); }
iconSet()196     inline QT3_SUPPORT QIcon iconSet() const { return icon(); }
addTo(QWidget * w)197     inline QT3_SUPPORT bool addTo(QWidget *w) { w->addAction(this); return true; }
removeFrom(QWidget * w)198     inline QT3_SUPPORT bool removeFrom(QWidget *w) { w->removeAction(this); return true; }
setAccel(const QKeySequence & shortcut)199     inline QT3_SUPPORT void setAccel(const QKeySequence &shortcut) { setShortcut(shortcut); }
accel()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
setOn(bool b)216     inline QT_MOC_COMPAT void setOn(bool b) { setChecked(b); }
217 #endif
trigger()218     void trigger() { activate(Trigger); }
hover()219     void hover() { activate(Hover); }
220     void setChecked(bool);
221     void toggle();
222     void setEnabled(bool);
setDisabled(bool b)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 
254 QT_BEGIN_INCLUDE_NAMESPACE
255 #include <QtGui/qactiongroup.h>
256 QT_END_INCLUDE_NAMESPACE
257 
258 #endif // QT_NO_ACTION
259 
260 QT_END_NAMESPACE
261 
262 QT_END_HEADER
263 
264 #endif // QACTION_H
265