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 Functor> |
86 | QAction *addAction(const QString &text, Functor functor, const QKeySequence &shortcut = 0); |
87 | template<typename Functor> |
88 | QAction *addAction(const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut = 0); |
89 | template<typename Functor> |
90 | QAction *addAction(const QIcon &icon, const QString &text, Functor functor, const QKeySequence &shortcut = 0); |
91 | template<typename Functor> |
92 | QAction *addAction(const QIcon &icon, const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut = 0); |
93 | #else |
94 | // addAction(QString): Connect to a QObject slot / functor or function pointer (with context) |
95 | template<class Obj, typename Func1> |
96 | inline typename std::enable_if<!std::is_same<const char*, Func1>::value |
97 | && QtPrivate::IsPointerToTypeDerivedFromQObject<Obj*>::Value, QAction *>::type |
98 | (const QString &text, const Obj *object, Func1 slot, const QKeySequence &shortcut = 0) |
99 | { |
100 | QAction *result = addAction(text); |
101 | #ifdef QT_NO_SHORTCUT |
102 | Q_UNUSED(shortcut) |
103 | #else |
104 | result->setShortcut(shortcut); |
105 | #endif |
106 | connect(result, &QAction::triggered, object, std::move(slot)); |
107 | return result; |
108 | } |
109 | // addAction(QString): Connect to a functor or function pointer (without context) |
110 | template <typename Func1> |
111 | inline QAction *(const QString &text, Func1 slot, const QKeySequence &shortcut = 0) |
112 | { |
113 | QAction *result = addAction(text); |
114 | #ifdef QT_NO_SHORTCUT |
115 | Q_UNUSED(shortcut) |
116 | #else |
117 | result->setShortcut(shortcut); |
118 | #endif |
119 | connect(result, &QAction::triggered, std::move(slot)); |
120 | return result; |
121 | } |
122 | // addAction(QIcon, QString): Connect to a QObject slot / functor or function pointer (with context) |
123 | template<class Obj, typename Func1> |
124 | inline typename std::enable_if<!std::is_same<const char*, Func1>::value |
125 | && QtPrivate::IsPointerToTypeDerivedFromQObject<Obj*>::Value, QAction *>::type |
126 | (const QIcon &actionIcon, const QString &text, const Obj *object, Func1 slot, const QKeySequence &shortcut = 0) |
127 | { |
128 | QAction *result = addAction(actionIcon, text); |
129 | #ifdef QT_NO_SHORTCUT |
130 | Q_UNUSED(shortcut) |
131 | #else |
132 | result->setShortcut(shortcut); |
133 | #endif |
134 | connect(result, &QAction::triggered, object, std::move(slot)); |
135 | return result; |
136 | } |
137 | // addAction(QIcon, QString): Connect to a functor or function pointer (without context) |
138 | template <typename Func1> |
139 | inline QAction *(const QIcon &actionIcon, const QString &text, Func1 slot, const QKeySequence &shortcut = 0) |
140 | { |
141 | QAction *result = addAction(actionIcon, text); |
142 | #ifdef QT_NO_SHORTCUT |
143 | Q_UNUSED(shortcut) |
144 | #else |
145 | result->setShortcut(shortcut); |
146 | #endif |
147 | connect(result, &QAction::triggered, std::move(slot)); |
148 | return result; |
149 | } |
150 | #endif // !Q_CLANG_QDOC |
151 | |
152 | QAction *(QMenu *); |
153 | QMenu *(const QString &title); |
154 | QMenu *(const QIcon &icon, const QString &title); |
155 | |
156 | QAction *(); |
157 | |
158 | QAction *(const QString &text); |
159 | QAction *(const QIcon &icon, const QString &text); |
160 | |
161 | QAction *(QAction *before, QMenu *); |
162 | QAction *(QAction *before); |
163 | QAction *(QAction *before, const QString &text); |
164 | QAction *(QAction *before, const QIcon &icon, const QString &text); |
165 | |
166 | bool () const; |
167 | void (); |
168 | |
169 | void (bool); |
170 | bool () const; |
171 | |
172 | bool () const; |
173 | void (); |
174 | void (const QPoint &pos); |
175 | void (); |
176 | |
177 | void (QAction *); |
178 | QAction *() const; |
179 | |
180 | void (QAction *act); |
181 | QAction *() const; |
182 | |
183 | void (const QPoint &pos, QAction *at = nullptr); |
184 | QAction *(); |
185 | QAction *(const QPoint &pos, QAction *at = nullptr); |
186 | |
187 | #if QT_VERSION >= QT_VERSION_CHECK(6,0,0) |
188 | static QAction *exec(const QList<QAction *> &actions, const QPoint &pos, QAction *at = nullptr, QWidget *parent = nullptr); |
189 | #else |
190 | static QAction *(QList<QAction*> actions, const QPoint &pos, QAction *at = nullptr, QWidget *parent = nullptr); |
191 | #endif |
192 | |
193 | QSize () const override; |
194 | |
195 | QRect (QAction *) const; |
196 | QAction *(const QPoint &) const; |
197 | |
198 | QAction *() const; |
199 | |
200 | QString () const; |
201 | void (const QString &title); |
202 | |
203 | QIcon () const; |
204 | void (const QIcon &icon); |
205 | |
206 | void (QWidget *widget); |
207 | QPlatformMenu *(); |
208 | void (QPlatformMenu *); |
209 | |
210 | #if defined(Q_OS_MACOS) || defined(Q_CLANG_QDOC) |
211 | NSMenu* toNSMenu(); |
212 | void setAsDockMenu(); |
213 | #endif |
214 | |
215 | bool () const; |
216 | void (bool collapse); |
217 | |
218 | bool () const; |
219 | void (bool visible); |
220 | |
221 | Q_SIGNALS: |
222 | void (); |
223 | void (); |
224 | void (QAction *action); |
225 | void (QAction *action); |
226 | |
227 | protected: |
228 | int columnCount() const; |
229 | |
230 | void (QEvent *) override; |
231 | void (QKeyEvent *) override; |
232 | void (QMouseEvent *) override; |
233 | void (QMouseEvent *) override; |
234 | void (QMouseEvent *) override; |
235 | #if QT_CONFIG(wheelevent) |
236 | void (QWheelEvent *) override; |
237 | #endif |
238 | void (QEvent *) override; |
239 | void (QEvent *) override; |
240 | void (QHideEvent *) override; |
241 | void (QPaintEvent *) override; |
242 | void (QActionEvent *) override; |
243 | void (QTimerEvent *) override; |
244 | bool (QEvent *) override; |
245 | bool (bool next) override; |
246 | void (QStyleOptionMenuItem *option, const QAction *action) const; |
247 | |
248 | private Q_SLOTS: |
249 | void (); |
250 | |
251 | private: |
252 | Q_PRIVATE_SLOT(d_func(), void _q_actionTriggered()) |
253 | Q_PRIVATE_SLOT(d_func(), void _q_actionHovered()) |
254 | Q_PRIVATE_SLOT(d_func(), void _q_overrideMenuActionDestroyed()) |
255 | Q_PRIVATE_SLOT(d_func(), void _q_platformMenuAboutToShow()) |
256 | |
257 | protected: |
258 | (QMenuPrivate &dd, QWidget* parent = nullptr); |
259 | |
260 | private: |
261 | Q_DISABLE_COPY() |
262 | |
263 | friend class QMenuBar; |
264 | friend class QMenuBarPrivate; |
265 | friend class QTornOffMenu; |
266 | friend class QComboBox; |
267 | friend class QAction; |
268 | friend class QToolButtonPrivate; |
269 | friend void (QMenu *, bool show); |
270 | friend void (QMenu *, QAction *action); |
271 | }; |
272 | |
273 | #ifdef Q_OS_MACOS |
274 | // ### Qt 4 compatibility; remove in Qt 6 |
275 | inline QT_DEPRECATED void qt_mac_set_dock_menu(QMenu *menu) { menu->setAsDockMenu(); } |
276 | #endif |
277 | |
278 | QT_END_NAMESPACE |
279 | |
280 | #endif // QMENU_H |
281 | |