1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QMENU_H |
5 | #define |
6 | |
7 | #include <QtWidgets/qtwidgetsglobal.h> |
8 | #include <QtWidgets/qwidget.h> |
9 | #include <QtCore/qstring.h> |
10 | #include <QtGui/qicon.h> |
11 | #include <QtGui/qaction.h> |
12 | |
13 | #if defined(Q_OS_MACOS) || defined(Q_QDOC) |
14 | Q_FORWARD_DECLARE_OBJC_CLASS(NSMenu); |
15 | #endif |
16 | |
17 | QT_REQUIRE_CONFIG(menu); |
18 | |
19 | QT_BEGIN_NAMESPACE |
20 | |
21 | class ; |
22 | class ; |
23 | class ; |
24 | |
25 | class Q_WIDGETS_EXPORT : public QWidget |
26 | { |
27 | private: |
28 | Q_OBJECT |
29 | Q_DECLARE_PRIVATE(QMenu) |
30 | |
31 | Q_PROPERTY(bool tearOffEnabled READ isTearOffEnabled WRITE setTearOffEnabled) |
32 | Q_PROPERTY(QString title READ title WRITE setTitle) |
33 | Q_PROPERTY(QIcon icon READ icon WRITE setIcon) |
34 | Q_PROPERTY(bool separatorsCollapsible READ separatorsCollapsible WRITE setSeparatorsCollapsible) |
35 | Q_PROPERTY(bool toolTipsVisible READ toolTipsVisible WRITE setToolTipsVisible) |
36 | |
37 | public: |
38 | explicit (QWidget *parent = nullptr); |
39 | explicit (const QString &title, QWidget *parent = nullptr); |
40 | (); |
41 | |
42 | using QWidget::addAction; |
43 | #if QT_WIDGETS_REMOVED_SINCE(6, 3) |
44 | QAction *addAction(const QString &text); |
45 | QAction *addAction(const QIcon &icon, const QString &text); |
46 | #if !QT_CONFIG(shortcut) |
47 | QAction *addAction(const QString &text, const QObject *receiver, const char* member); |
48 | QAction *addAction(const QIcon &icon, const QString &text, |
49 | const QObject *receiver, const char* member); |
50 | #endif |
51 | #endif |
52 | |
53 | #if QT_CONFIG(shortcut) |
54 | #if QT_DEPRECATED_SINCE(6, 4) |
55 | QT_DEPRECATED_VERSION_X_6_4("Use addAction(text, shortcut, receiver, member) instead." ) |
56 | QAction *(const QString &text, const QObject *receiver, const char* member, |
57 | const QKeySequence &shortcut); |
58 | QT_DEPRECATED_VERSION_X_6_4("Use addAction(icon, text, shortcut, receiver, member) instead." ) |
59 | QAction *(const QIcon &icon, const QString &text, |
60 | const QObject *receiver, const char* member, |
61 | const QKeySequence &shortcut); |
62 | |
63 | #ifdef Q_QDOC |
64 | template<typename Functor> |
65 | QAction *addAction(const QString &text, Functor functor, const QKeySequence &shortcut); |
66 | template<typename Functor> |
67 | QAction *addAction(const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut); |
68 | template<typename Functor> |
69 | QAction *addAction(const QIcon &icon, const QString &text, Functor functor, const QKeySequence &shortcut); |
70 | template<typename Functor> |
71 | QAction *addAction(const QIcon &icon, const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut); |
72 | #else |
73 | // addAction(QString): Connect to a QObject slot / functor or function pointer (with context) |
74 | template<class Obj, typename Func1> |
75 | QT_DEPRECATED_VERSION_X_6_4("Use addAction(text, shortcut, object, slot) instead." ) |
76 | inline typename std::enable_if<!std::is_same<const char*, Func1>::value |
77 | && QtPrivate::IsPointerToTypeDerivedFromQObject<Obj*>::Value, QAction *>::type |
78 | (const QString &text, const Obj *object, Func1 slot, |
79 | const QKeySequence &shortcut) |
80 | { |
81 | return addAction(text, shortcut, object, slot); |
82 | } |
83 | // addAction(QString): Connect to a functor or function pointer (without context) |
84 | template <typename Func1> |
85 | QT_DEPRECATED_VERSION_X_6_4("Use addAction(text, shortcut, slot) instead." ) |
86 | inline QAction *(const QString &text, Func1 slot, const QKeySequence &shortcut) |
87 | { |
88 | return addAction(text, shortcut, slot); |
89 | } |
90 | // addAction(QIcon, QString): Connect to a QObject slot / functor or function pointer (with context) |
91 | template<class Obj, typename Func1> |
92 | QT_DEPRECATED_VERSION_X_6_4("Use addAction(icon, text, shortcut, object, slot) instead." ) |
93 | inline typename std::enable_if<!std::is_same<const char*, Func1>::value |
94 | && QtPrivate::IsPointerToTypeDerivedFromQObject<Obj*>::Value, QAction *>::type |
95 | (const QIcon &actionIcon, const QString &text, const Obj *object, Func1 slot, |
96 | const QKeySequence &shortcut) |
97 | |
98 | { |
99 | return addAction(actionIcon, text, shortcut, object, slot); |
100 | } |
101 | // addAction(QIcon, QString): Connect to a functor or function pointer (without context) |
102 | template <typename Func1> |
103 | QT_DEPRECATED_VERSION_X_6_4("Use addAction(icon, text, shortcut, slot) instead." ) |
104 | inline QAction *(const QIcon &actionIcon, const QString &text, Func1 slot, |
105 | const QKeySequence &shortcut) |
106 | { |
107 | return addAction(actionIcon, text, shortcut, slot); |
108 | } |
109 | #endif // !Q_QDOC |
110 | #endif // QT_DEPRECATED_SINCE(6, 4) |
111 | #endif // QT_CONFIG(shortcut) |
112 | |
113 | QAction *(QMenu *); |
114 | QMenu *(const QString &title); |
115 | QMenu *(const QIcon &icon, const QString &title); |
116 | |
117 | QAction *(); |
118 | |
119 | QAction *(const QString &text); |
120 | QAction *(const QIcon &icon, const QString &text); |
121 | |
122 | QAction *(QAction *before, QMenu *); |
123 | QAction *(QAction *before); |
124 | QAction *(QAction *before, const QString &text); |
125 | QAction *(QAction *before, const QIcon &icon, const QString &text); |
126 | |
127 | bool () const; |
128 | void (); |
129 | |
130 | void (bool); |
131 | bool () const; |
132 | |
133 | bool () const; |
134 | void (); |
135 | void (const QPoint &pos); |
136 | void (); |
137 | |
138 | void (QAction *); |
139 | QAction *() const; |
140 | |
141 | void (QAction *act); |
142 | QAction *() const; |
143 | |
144 | void (const QPoint &pos, QAction *at = nullptr); |
145 | QAction *(); |
146 | QAction *(const QPoint &pos, QAction *at = nullptr); |
147 | |
148 | static QAction *(const QList<QAction *> &actions, const QPoint &pos, QAction *at = nullptr, QWidget *parent = nullptr); |
149 | |
150 | QSize () const override; |
151 | |
152 | QRect (QAction *) const; |
153 | QAction *(const QPoint &) const; |
154 | |
155 | QAction *() const; |
156 | static QMenu *(const QAction *action) |
157 | { return qobject_cast<QMenu *>(object: action->menuObject()); } |
158 | |
159 | QString () const; |
160 | void (const QString &title); |
161 | |
162 | QIcon () const; |
163 | void (const QIcon &icon); |
164 | |
165 | void (QWidget *widget); |
166 | QPlatformMenu *(); |
167 | void (QPlatformMenu *); |
168 | |
169 | #if defined(Q_OS_MACOS) || defined(Q_QDOC) |
170 | NSMenu* toNSMenu(); |
171 | void setAsDockMenu(); |
172 | #endif |
173 | |
174 | bool () const; |
175 | void (bool collapse); |
176 | |
177 | bool () const; |
178 | void (bool visible); |
179 | |
180 | Q_SIGNALS: |
181 | void (); |
182 | void (); |
183 | void (QAction *action); |
184 | void (QAction *action); |
185 | |
186 | protected: |
187 | int columnCount() const; |
188 | |
189 | void (QEvent *) override; |
190 | void (QKeyEvent *) override; |
191 | void (QMouseEvent *) override; |
192 | void (QMouseEvent *) override; |
193 | void (QMouseEvent *) override; |
194 | #if QT_CONFIG(wheelevent) |
195 | void (QWheelEvent *) override; |
196 | #endif |
197 | void (QEnterEvent *) override; |
198 | void (QEvent *) override; |
199 | void (QHideEvent *) override; |
200 | void (QPaintEvent *) override; |
201 | void (QActionEvent *) override; |
202 | void (QTimerEvent *) override; |
203 | bool (QEvent *) override; |
204 | bool (bool next) override; |
205 | virtual void (QStyleOptionMenuItem *option, const QAction *action) const; |
206 | |
207 | private Q_SLOTS: |
208 | void (); |
209 | |
210 | private: |
211 | Q_PRIVATE_SLOT(d_func(), void _q_actionTriggered()) |
212 | Q_PRIVATE_SLOT(d_func(), void _q_actionHovered()) |
213 | Q_PRIVATE_SLOT(d_func(), void _q_overrideMenuActionDestroyed()) |
214 | Q_PRIVATE_SLOT(d_func(), void _q_platformMenuAboutToShow()) |
215 | |
216 | protected: |
217 | (QMenuPrivate &dd, QWidget* parent = nullptr); |
218 | |
219 | private: |
220 | Q_DISABLE_COPY() |
221 | |
222 | friend class QMenuBar; |
223 | friend class ; |
224 | friend class ; |
225 | friend class QComboBox; |
226 | friend class QtWidgetsActionPrivate; |
227 | friend class QToolButtonPrivate; |
228 | friend void (QMenu *, bool show); |
229 | friend void (QMenu *, QAction *action); |
230 | }; |
231 | |
232 | QT_END_NAMESPACE |
233 | |
234 | #endif // QMENU_H |
235 | |