1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtWidgets 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 https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://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 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QACTION_H |
41 | #define QACTION_H |
42 | |
43 | #include <QtWidgets/qtwidgetsglobal.h> |
44 | #include <QtGui/qkeysequence.h> |
45 | #include <QtCore/qstring.h> |
46 | #include <QtWidgets/qwidget.h> |
47 | #include <QtCore/qvariant.h> |
48 | #include <QtGui/qicon.h> |
49 | |
50 | QT_BEGIN_NAMESPACE |
51 | |
52 | |
53 | #ifndef QT_NO_ACTION |
54 | |
55 | class ; |
56 | class QActionGroup; |
57 | class QActionPrivate; |
58 | class QGraphicsWidget; |
59 | |
60 | class Q_WIDGETS_EXPORT QAction : public QObject |
61 | { |
62 | Q_OBJECT |
63 | Q_DECLARE_PRIVATE(QAction) |
64 | |
65 | Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY changed) |
66 | Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled) |
67 | Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY changed) |
68 | Q_PROPERTY(QIcon icon READ icon WRITE setIcon NOTIFY changed) |
69 | Q_PROPERTY(QString text READ text WRITE setText NOTIFY changed) |
70 | Q_PROPERTY(QString iconText READ iconText WRITE setIconText NOTIFY changed) |
71 | Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip NOTIFY changed) |
72 | Q_PROPERTY(QString statusTip READ statusTip WRITE setStatusTip NOTIFY changed) |
73 | Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis NOTIFY changed) |
74 | Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY changed) |
75 | #if QT_CONFIG(shortcut) |
76 | Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut NOTIFY changed) |
77 | Q_PROPERTY(Qt::ShortcutContext shortcutContext READ shortcutContext WRITE setShortcutContext NOTIFY changed) |
78 | Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat NOTIFY changed) |
79 | #endif |
80 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY changed) |
81 | Q_PROPERTY(MenuRole menuRole READ menuRole WRITE setMenuRole NOTIFY changed) |
82 | Q_PROPERTY(bool iconVisibleInMenu READ isIconVisibleInMenu WRITE setIconVisibleInMenu NOTIFY changed) |
83 | Q_PROPERTY(bool shortcutVisibleInContextMenu READ isShortcutVisibleInContextMenu WRITE setShortcutVisibleInContextMenu NOTIFY changed) |
84 | Q_PROPERTY(Priority priority READ priority WRITE setPriority) |
85 | |
86 | public: |
87 | // note this is copied into qplatformmenu.h, which must stay in sync |
88 | enum { NoRole = 0, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole, |
89 | AboutRole, PreferencesRole, QuitRole }; |
90 | Q_ENUM(MenuRole) |
91 | enum Priority { LowPriority = 0, |
92 | NormalPriority = 128, |
93 | HighPriority = 256}; |
94 | Q_ENUM(Priority) |
95 | explicit QAction(QObject *parent = nullptr); |
96 | explicit QAction(const QString &text, QObject *parent = nullptr); |
97 | explicit QAction(const QIcon &icon, const QString &text, QObject *parent = nullptr); |
98 | |
99 | ~QAction(); |
100 | |
101 | void setActionGroup(QActionGroup *group); |
102 | QActionGroup *actionGroup() const; |
103 | void setIcon(const QIcon &icon); |
104 | QIcon icon() const; |
105 | |
106 | void setText(const QString &text); |
107 | QString text() const; |
108 | |
109 | void setIconText(const QString &text); |
110 | QString iconText() const; |
111 | |
112 | void setToolTip(const QString &tip); |
113 | QString toolTip() const; |
114 | |
115 | void setStatusTip(const QString &statusTip); |
116 | QString statusTip() const; |
117 | |
118 | void setWhatsThis(const QString &what); |
119 | QString whatsThis() const; |
120 | |
121 | void setPriority(Priority priority); |
122 | Priority priority() const; |
123 | |
124 | #if QT_CONFIG(menu) |
125 | QMenu *() const; |
126 | void (QMenu *); |
127 | #endif |
128 | |
129 | void setSeparator(bool b); |
130 | bool isSeparator() const; |
131 | |
132 | #if QT_CONFIG(shortcut) |
133 | void setShortcut(const QKeySequence &shortcut); |
134 | QKeySequence shortcut() const; |
135 | |
136 | void setShortcuts(const QList<QKeySequence> &shortcuts); |
137 | void setShortcuts(QKeySequence::StandardKey); |
138 | QList<QKeySequence> shortcuts() const; |
139 | |
140 | void setShortcutContext(Qt::ShortcutContext context); |
141 | Qt::ShortcutContext shortcutContext() const; |
142 | |
143 | void setAutoRepeat(bool); |
144 | bool autoRepeat() const; |
145 | #endif |
146 | |
147 | void setFont(const QFont &font); |
148 | QFont font() const; |
149 | |
150 | void setCheckable(bool); |
151 | bool isCheckable() const; |
152 | |
153 | QVariant data() const; |
154 | void setData(const QVariant &var); |
155 | |
156 | bool isChecked() const; |
157 | |
158 | bool isEnabled() const; |
159 | |
160 | bool isVisible() const; |
161 | |
162 | enum ActionEvent { Trigger, Hover }; |
163 | void activate(ActionEvent event); |
164 | bool showStatusText(QWidget *widget = nullptr); |
165 | |
166 | void (MenuRole ); |
167 | MenuRole () const; |
168 | |
169 | void (bool visible); |
170 | bool () const; |
171 | |
172 | void (bool show); |
173 | bool () const; |
174 | |
175 | QWidget *parentWidget() const; |
176 | |
177 | QList<QWidget *> associatedWidgets() const; |
178 | #if QT_CONFIG(graphicsview) |
179 | QList<QGraphicsWidget *> associatedGraphicsWidgets() const; // ### suboptimal |
180 | #endif |
181 | |
182 | protected: |
183 | bool event(QEvent *) override; |
184 | QAction(QActionPrivate &dd, QObject *parent); |
185 | |
186 | public Q_SLOTS: |
187 | void trigger() { activate(Trigger); } |
188 | void hover() { activate(Hover); } |
189 | void setChecked(bool); |
190 | void toggle(); |
191 | void setEnabled(bool); |
192 | inline void setDisabled(bool b) { setEnabled(!b); } |
193 | void setVisible(bool); |
194 | |
195 | Q_SIGNALS: |
196 | void changed(); |
197 | void triggered(bool checked = false); |
198 | void hovered(); |
199 | void toggled(bool); |
200 | |
201 | private: |
202 | Q_DISABLE_COPY(QAction) |
203 | |
204 | friend class QGraphicsWidget; |
205 | friend class QWidget; |
206 | friend class QActionGroup; |
207 | friend class QMenu; |
208 | friend class QMenuPrivate; |
209 | friend class QMenuBar; |
210 | friend class QToolButton; |
211 | #ifdef Q_OS_MAC |
212 | friend void qt_mac_clear_status_text(QAction *action); |
213 | #endif |
214 | }; |
215 | |
216 | #ifndef QT_NO_DEBUG_STREAM |
217 | Q_WIDGETS_EXPORT QDebug operator<<(QDebug, const QAction *); |
218 | #endif |
219 | |
220 | QT_BEGIN_INCLUDE_NAMESPACE |
221 | #include <QtWidgets/qactiongroup.h> |
222 | QT_END_INCLUDE_NAMESPACE |
223 | |
224 | #endif // QT_NO_ACTION |
225 | |
226 | QT_END_NAMESPACE |
227 | |
228 | #endif // QACTION_H |
229 | |