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 QMENU_H |
41 | #define |
42 | |
43 | #include <QtWidgets/qtwidgetsglobal.h> |
44 | #include <QtWidgets/qwidget.h> |
45 | #include <QtCore/qstring.h> |
46 | #include <QtGui/qicon.h> |
47 | #include <QtWidgets/qaction.h> |
48 | |
49 | #if defined(Q_OS_MACOS) || defined(Q_CLANG_QDOC) |
50 | Q_FORWARD_DECLARE_OBJC_CLASS(NSMenu); |
51 | #endif |
52 | |
53 | QT_REQUIRE_CONFIG(menu); |
54 | |
55 | QT_BEGIN_NAMESPACE |
56 | |
57 | class ; |
58 | class ; |
59 | class ; |
60 | |
61 | class Q_WIDGETS_EXPORT : public QWidget |
62 | { |
63 | private: |
64 | Q_OBJECT |
65 | Q_DECLARE_PRIVATE(QMenu) |
66 | |
67 | Q_PROPERTY(bool tearOffEnabled READ isTearOffEnabled WRITE setTearOffEnabled) |
68 | Q_PROPERTY(QString title READ title WRITE setTitle) |
69 | Q_PROPERTY(QIcon icon READ icon WRITE setIcon) |
70 | Q_PROPERTY(bool separatorsCollapsible READ separatorsCollapsible WRITE setSeparatorsCollapsible) |
71 | Q_PROPERTY(bool toolTipsVisible READ toolTipsVisible WRITE setToolTipsVisible) |
72 | |
73 | public: |
74 | explicit (QWidget *parent = nullptr); |
75 | explicit (const QString &title, QWidget *parent = nullptr); |
76 | (); |
77 | |
78 | using QWidget::addAction; |
79 | QAction *(const QString &text); |
80 | QAction *(const QIcon &icon, const QString &text); |
81 | QAction *(const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0); |
82 | QAction *(const QIcon &icon, const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0); |
83 | |
84 | #ifdef Q_CLANG_QDOC |
85 | template<typename PointerToMemberFunction> |
86 | QAction *addAction(const QString &text, const QObject *receiver, PointerToMemberFunction method, const QKeySequence &shortcut = 0); |
87 | template<typename Functor> |
88 | QAction *addAction(const QString &text, Functor functor, const QKeySequence &shortcut = 0); |
89 | template<typename Functor> |
90 | QAction *addAction(const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut = 0); |
91 | template<typename PointerToMemberFunction> |
92 | QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, PointerToMemberFunction method, const QKeySequence &shortcut = 0); |
93 | template<typename Functor> |
94 | QAction *addAction(const QIcon &icon, const QString &text, Functor functor, const QKeySequence &shortcut = 0); |
95 | template<typename Functor> |
96 | QAction *addAction(const QIcon &icon, const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut = 0); |
97 | #else |
98 | // addAction(QString): Connect to a QObject slot / functor or function pointer (with context) |
99 | template<class Obj, typename Func1> |
100 | inline typename std::enable_if<!std::is_same<const char*, Func1>::value |
101 | && QtPrivate::IsPointerToTypeDerivedFromQObject<Obj*>::Value, QAction *>::type |
102 | (const QString &text, const Obj *object, Func1 slot, const QKeySequence &shortcut = 0) |
103 | { |
104 | QAction *result = addAction(text); |
105 | #ifdef QT_NO_SHORTCUT |
106 | Q_UNUSED(shortcut) |
107 | #else |
108 | result->setShortcut(shortcut); |
109 | #endif |
110 | connect(result, &QAction::triggered, object, std::move(slot)); |
111 | return result; |
112 | } |
113 | // addAction(QString): Connect to a functor or function pointer (without context) |
114 | template <typename Func1> |
115 | inline QAction *(const QString &text, Func1 slot, const QKeySequence &shortcut = 0) |
116 | { |
117 | QAction *result = addAction(text); |
118 | #ifdef QT_NO_SHORTCUT |
119 | Q_UNUSED(shortcut) |
120 | #else |
121 | result->setShortcut(shortcut); |
122 | #endif |
123 | connect(result, &QAction::triggered, std::move(slot)); |
124 | return result; |
125 | } |
126 | // addAction(QIcon, QString): Connect to a QObject slot / functor or function pointer (with context) |
127 | template<class Obj, typename Func1> |
128 | inline typename std::enable_if<!std::is_same<const char*, Func1>::value |
129 | && QtPrivate::IsPointerToTypeDerivedFromQObject<Obj*>::Value, QAction *>::type |
130 | (const QIcon &actionIcon, const QString &text, const Obj *object, Func1 slot, const QKeySequence &shortcut = 0) |
131 | { |
132 | QAction *result = addAction(actionIcon, text); |
133 | #ifdef QT_NO_SHORTCUT |
134 | Q_UNUSED(shortcut) |
135 | #else |
136 | result->setShortcut(shortcut); |
137 | #endif |
138 | connect(result, &QAction::triggered, object, std::move(slot)); |
139 | return result; |
140 | } |
141 | // addAction(QIcon, QString): Connect to a functor or function pointer (without context) |
142 | template <typename Func1> |
143 | inline QAction *(const QIcon &actionIcon, const QString &text, Func1 slot, const QKeySequence &shortcut = 0) |
144 | { |
145 | QAction *result = addAction(actionIcon, text); |
146 | #ifdef QT_NO_SHORTCUT |
147 | Q_UNUSED(shortcut) |
148 | #else |
149 | result->setShortcut(shortcut); |
150 | #endif |
151 | connect(result, &QAction::triggered, std::move(slot)); |
152 | return result; |
153 | } |
154 | #endif // !Q_CLANG_QDOC |
155 | |
156 | QAction *(QMenu *); |
157 | QMenu *(const QString &title); |
158 | QMenu *(const QIcon &icon, const QString &title); |
159 | |
160 | QAction *(); |
161 | |
162 | QAction *(const QString &text); |
163 | QAction *(const QIcon &icon, const QString &text); |
164 | |
165 | QAction *(QAction *before, QMenu *); |
166 | QAction *(QAction *before); |
167 | QAction *(QAction *before, const QString &text); |
168 | QAction *(QAction *before, const QIcon &icon, const QString &text); |
169 | |
170 | bool () const; |
171 | void (); |
172 | |
173 | void (bool); |
174 | bool () const; |
175 | |
176 | bool () const; |
177 | void (); |
178 | void (const QPoint &pos); |
179 | void (); |
180 | |
181 | void (QAction *); |
182 | QAction *() const; |
183 | |
184 | void (QAction *act); |
185 | QAction *() const; |
186 | |
187 | void (const QPoint &pos, QAction *at = nullptr); |
188 | QAction *(); |
189 | QAction *(const QPoint &pos, QAction *at = nullptr); |
190 | |
191 | #if QT_VERSION >= QT_VERSION_CHECK(6,0,0) |
192 | static QAction *exec(const QList<QAction *> &actions, const QPoint &pos, QAction *at = nullptr, QWidget *parent = nullptr); |
193 | #else |
194 | static QAction *(QList<QAction*> actions, const QPoint &pos, QAction *at = nullptr, QWidget *parent = nullptr); |
195 | #endif |
196 | |
197 | QSize () const override; |
198 | |
199 | QRect (QAction *) const; |
200 | QAction *(const QPoint &) const; |
201 | |
202 | QAction *() const; |
203 | |
204 | QString () const; |
205 | void (const QString &title); |
206 | |
207 | QIcon () const; |
208 | void (const QIcon &icon); |
209 | |
210 | void (QWidget *widget); |
211 | QPlatformMenu *(); |
212 | void (QPlatformMenu *); |
213 | |
214 | #if defined(Q_OS_MACOS) || defined(Q_CLANG_QDOC) |
215 | NSMenu* toNSMenu(); |
216 | void setAsDockMenu(); |
217 | #endif |
218 | |
219 | bool () const; |
220 | void (bool collapse); |
221 | |
222 | bool () const; |
223 | void (bool visible); |
224 | |
225 | Q_SIGNALS: |
226 | void (); |
227 | void (); |
228 | void (QAction *action); |
229 | void (QAction *action); |
230 | |
231 | protected: |
232 | int columnCount() const; |
233 | |
234 | void (QEvent *) override; |
235 | void (QKeyEvent *) override; |
236 | void (QMouseEvent *) override; |
237 | void (QMouseEvent *) override; |
238 | void (QMouseEvent *) override; |
239 | #if QT_CONFIG(wheelevent) |
240 | void (QWheelEvent *) override; |
241 | #endif |
242 | void (QEvent *) override; |
243 | void (QEvent *) override; |
244 | void (QHideEvent *) override; |
245 | void (QPaintEvent *) override; |
246 | void (QActionEvent *) override; |
247 | void (QTimerEvent *) override; |
248 | bool (QEvent *) override; |
249 | bool (bool next) override; |
250 | void (QStyleOptionMenuItem *option, const QAction *action) const; |
251 | |
252 | private Q_SLOTS: |
253 | void (); |
254 | |
255 | private: |
256 | Q_PRIVATE_SLOT(d_func(), void _q_actionTriggered()) |
257 | Q_PRIVATE_SLOT(d_func(), void _q_actionHovered()) |
258 | Q_PRIVATE_SLOT(d_func(), void _q_overrideMenuActionDestroyed()) |
259 | Q_PRIVATE_SLOT(d_func(), void _q_platformMenuAboutToShow()) |
260 | |
261 | protected: |
262 | (QMenuPrivate &dd, QWidget* parent = nullptr); |
263 | |
264 | private: |
265 | Q_DISABLE_COPY() |
266 | |
267 | friend class QMenuBar; |
268 | friend class QMenuBarPrivate; |
269 | friend class QTornOffMenu; |
270 | friend class QComboBox; |
271 | friend class QAction; |
272 | friend class QToolButtonPrivate; |
273 | friend void (QMenu *, bool show); |
274 | friend void (QMenu *, QAction *action); |
275 | }; |
276 | |
277 | #ifdef Q_OS_OSX |
278 | // ### Qt 4 compatibility; remove in Qt 6 |
279 | inline QT_DEPRECATED void qt_mac_set_dock_menu(QMenu *menu) { menu->setAsDockMenu(); } |
280 | #endif |
281 | |
282 | QT_END_NAMESPACE |
283 | |
284 | #endif // QMENU_H |
285 | |