1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
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 Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/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 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | |
42 | #ifndef QMENU_H |
43 | #define QMENU_H |
44 | |
45 | #include <QtGui/qwidget.h> |
46 | #include <QtCore/qstring.h> |
47 | #include <QtGui/qicon.h> |
48 | #include <QtGui/qaction.h> |
49 | |
50 | #ifdef QT3_SUPPORT |
51 | #include <QtGui/qpixmap.h> |
52 | #endif |
53 | |
54 | #ifdef Q_WS_WINCE |
55 | #include <windef.h> // for HMENU |
56 | #endif |
57 | |
58 | QT_BEGIN_HEADER |
59 | |
60 | QT_BEGIN_NAMESPACE |
61 | |
62 | QT_MODULE(Gui) |
63 | |
64 | #ifndef QT_NO_MENU |
65 | |
66 | class ; |
67 | class ; |
68 | #ifdef QT3_SUPPORT |
69 | class ; |
70 | #endif |
71 | |
72 | class Q_GUI_EXPORT : public QWidget |
73 | { |
74 | private: |
75 | Q_OBJECT |
76 | Q_DECLARE_PRIVATE(QMenu) |
77 | |
78 | Q_PROPERTY(bool tearOffEnabled READ isTearOffEnabled WRITE setTearOffEnabled) |
79 | Q_PROPERTY(QString title READ title WRITE setTitle) |
80 | Q_PROPERTY(QIcon icon READ icon WRITE setIcon) |
81 | Q_PROPERTY(bool separatorsCollapsible READ separatorsCollapsible WRITE setSeparatorsCollapsible) |
82 | |
83 | public: |
84 | explicit (QWidget *parent = 0); |
85 | explicit (const QString &title, QWidget *parent = 0); |
86 | (); |
87 | |
88 | #ifdef Q_NO_USING_KEYWORD |
89 | inline void addAction(QAction *action) { QWidget::addAction(action); } |
90 | #else |
91 | using QWidget::addAction; |
92 | #endif |
93 | QAction *(const QString &text); |
94 | QAction *(const QIcon &icon, const QString &text); |
95 | QAction *(const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0); |
96 | QAction *(const QIcon &icon, const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0); |
97 | |
98 | QAction *(QMenu *); |
99 | QMenu *(const QString &title); |
100 | QMenu *(const QIcon &icon, const QString &title); |
101 | |
102 | QAction *(); |
103 | |
104 | QAction *(QAction *before, QMenu *); |
105 | QAction *(QAction *before); |
106 | |
107 | bool () const; |
108 | void (); |
109 | |
110 | void (bool); |
111 | bool () const; |
112 | |
113 | bool () const; |
114 | void (); |
115 | |
116 | void (QAction *); |
117 | QAction *() const; |
118 | |
119 | void (QAction *act); |
120 | QAction *() const; |
121 | |
122 | void (const QPoint &pos, QAction *at=0); |
123 | QAction *(); |
124 | QAction *(const QPoint &pos, QAction *at=0); |
125 | |
126 | // ### Qt 5: merge |
127 | static QAction *(QList<QAction*> actions, const QPoint &pos, QAction *at=0); |
128 | static QAction *(QList<QAction*> actions, const QPoint &pos, QAction *at, QWidget *parent); |
129 | |
130 | QSize () const; |
131 | |
132 | QRect (QAction *) const; |
133 | QAction *(const QPoint &) const; |
134 | |
135 | QAction *() const; |
136 | |
137 | QString () const; |
138 | void (const QString &title); |
139 | |
140 | QIcon () const; |
141 | void (const QIcon &icon); |
142 | |
143 | void (QWidget *widget); |
144 | #ifdef Q_WS_MAC |
145 | OSMenuRef macMenu(OSMenuRef merge=0); |
146 | #endif |
147 | |
148 | #ifdef Q_WS_WINCE |
149 | HMENU wceMenu(); |
150 | #endif |
151 | |
152 | bool () const; |
153 | void (bool collapse); |
154 | |
155 | Q_SIGNALS: |
156 | void (); |
157 | void (); |
158 | void (QAction *action); |
159 | void (QAction *action); |
160 | |
161 | protected: |
162 | int columnCount() const; |
163 | |
164 | void (QEvent *); |
165 | void (QKeyEvent *); |
166 | void (QMouseEvent *); |
167 | void (QMouseEvent *); |
168 | void (QMouseEvent *); |
169 | #ifndef QT_NO_WHEELEVENT |
170 | void (QWheelEvent *); |
171 | #endif |
172 | void (QEvent *); |
173 | void (QEvent *); |
174 | void (QHideEvent *); |
175 | void (QPaintEvent *); |
176 | void (QActionEvent *); |
177 | void (QTimerEvent *); |
178 | bool (QEvent *); |
179 | bool (bool next); |
180 | void (QStyleOptionMenuItem *option, const QAction *action) const; |
181 | |
182 | #ifdef Q_WS_WINCE |
183 | QAction* wceCommands(uint command); |
184 | #endif |
185 | |
186 | private Q_SLOTS: |
187 | void (); |
188 | void (); |
189 | |
190 | private: |
191 | Q_PRIVATE_SLOT(d_func(), void _q_actionTriggered()) |
192 | Q_PRIVATE_SLOT(d_func(), void _q_actionHovered()) |
193 | Q_PRIVATE_SLOT(d_func(), void _q_overrideMenuActionDestroyed()) |
194 | |
195 | #ifdef QT3_SUPPORT |
196 | public: |
197 | //menudata |
198 | inline QT3_SUPPORT uint () const { return actions().count(); } |
199 | inline QT3_SUPPORT int (const QString &text, const QObject *receiver, const char* member, |
200 | const QKeySequence& shortcut = 0, int id = -1, int index = -1) { |
201 | return insertAny(0, &text, receiver, member, &shortcut, 0, id, index); |
202 | } |
203 | inline QT3_SUPPORT int (const QIcon& icon, const QString &text, |
204 | const QObject *receiver, const char* member, |
205 | const QKeySequence& shortcut = 0, int id = -1, int index = -1) { |
206 | return insertAny(&icon, &text, receiver, member, &shortcut, 0, id, index); |
207 | } |
208 | inline QT3_SUPPORT int (const QPixmap &pixmap, const QObject *receiver, const char* member, |
209 | const QKeySequence& shortcut = 0, int id = -1, int index = -1) { |
210 | QIcon icon(pixmap); |
211 | return insertAny(&icon, 0, receiver, member, &shortcut, 0, id, index); |
212 | } |
213 | inline QT3_SUPPORT int (const QString &text, int id=-1, int index=-1) { |
214 | return insertAny(0, &text, 0, 0, 0, 0, id, index); |
215 | } |
216 | inline QT3_SUPPORT int (const QIcon& icon, const QString &text, int id=-1, int index=-1) { |
217 | return insertAny(&icon, &text, 0, 0, 0, 0, id, index); |
218 | } |
219 | inline QT3_SUPPORT int (const QString &text, QMenu *, int id=-1, int index=-1) { |
220 | return insertAny(0, &text, 0, 0, 0, popup, id, index); |
221 | } |
222 | inline QT3_SUPPORT int (const QIcon& icon, const QString &text, QMenu *, int id=-1, int index=-1) { |
223 | return insertAny(&icon, &text, 0, 0, 0, popup, id, index); |
224 | } |
225 | inline QT3_SUPPORT int (const QPixmap &pixmap, int id=-1, int index=-1) { |
226 | QIcon icon(pixmap); |
227 | return insertAny(&icon, 0, 0, 0, 0, 0, id, index); |
228 | } |
229 | inline QT3_SUPPORT int (const QPixmap &pixmap, QMenu *, int id=-1, int index=-1) { |
230 | QIcon icon(pixmap); |
231 | return insertAny(&icon, 0, 0, 0, 0, popup, id, index); |
232 | } |
233 | QT3_SUPPORT int (QMenuItem *item, int id=-1, int index=-1); |
234 | QT3_SUPPORT int (int index=-1); |
235 | inline QT3_SUPPORT void (int id) { |
236 | if(QAction *act = findActionForId(id)) |
237 | removeAction(act); } |
238 | inline QT3_SUPPORT void (int index) { |
239 | if(QAction *act = actions().value(index)) |
240 | removeAction(act); } |
241 | #ifndef QT_NO_SHORTCUT |
242 | inline QT3_SUPPORT QKeySequence (int id) const { |
243 | if(QAction *act = findActionForId(id)) |
244 | return act->shortcut(); |
245 | return QKeySequence(); } |
246 | inline QT3_SUPPORT void (const QKeySequence& key, int id) { |
247 | if(QAction *act = findActionForId(id)) |
248 | act->setShortcut(key); |
249 | } |
250 | #endif |
251 | inline QT3_SUPPORT QIcon (int id) const { |
252 | if(QAction *act = findActionForId(id)) |
253 | return act->icon(); |
254 | return QIcon(); } |
255 | inline QT3_SUPPORT QString (int id) const { |
256 | if(QAction *act = findActionForId(id)) |
257 | return act->text(); |
258 | return QString(); } |
259 | inline QT3_SUPPORT QPixmap (int id) const { |
260 | if(QAction *act = findActionForId(id)) |
261 | return act->icon().pixmap(QSize(22, 22)); |
262 | return QPixmap(); } |
263 | inline QT3_SUPPORT void (int id, const QString &w) { |
264 | if(QAction *act = findActionForId(id)) |
265 | act->setWhatsThis(w); } |
266 | inline QT3_SUPPORT QString (int id) const { |
267 | if(QAction *act = findActionForId(id)) |
268 | return act->whatsThis(); |
269 | return QString(); } |
270 | |
271 | inline QT3_SUPPORT void (int id, const QString &text) { |
272 | if(QAction *act = findActionForId(id)) |
273 | act->setText(text); } |
274 | inline QT3_SUPPORT void (int id, const QPixmap &pixmap) { |
275 | if(QAction *act = findActionForId(id)) |
276 | act->setIcon(QIcon(pixmap)); } |
277 | inline QT3_SUPPORT void (int id, const QIcon &icon, const QString &text) { |
278 | if(QAction *act = findActionForId(id)) { |
279 | act->setIcon(icon); |
280 | act->setText(text); |
281 | } |
282 | } |
283 | inline QT3_SUPPORT void (int id) { |
284 | setActiveAction(findActionForId(id)); |
285 | } |
286 | inline QT3_SUPPORT bool (int id) const { |
287 | return findActionForId(id) == activeAction(); |
288 | } |
289 | inline QT3_SUPPORT bool (int id) const { |
290 | if(QAction *act = findActionForId(id)) |
291 | return act->isEnabled(); |
292 | return false; } |
293 | inline QT3_SUPPORT void (int id, bool enable) { |
294 | if(QAction *act = findActionForId(id)) |
295 | act->setEnabled(enable); |
296 | } |
297 | inline QT3_SUPPORT bool (int id) const { |
298 | if(QAction *act = findActionForId(id)) |
299 | return act->isChecked(); |
300 | return false; |
301 | } |
302 | inline QT3_SUPPORT void (int id, bool check) { |
303 | if(QAction *act = findActionForId(id)) { |
304 | act->setCheckable(true); |
305 | act->setChecked(check); |
306 | } |
307 | } |
308 | inline QT3_SUPPORT bool (int id) const { |
309 | if(QAction *act = findActionForId(id)) |
310 | return act->isVisible(); |
311 | return false; |
312 | } |
313 | inline QT3_SUPPORT void (int id, bool visible) { |
314 | if(QAction *act = findActionForId(id)) |
315 | act->setVisible(visible); |
316 | } |
317 | inline QT3_SUPPORT QRect (int index) { |
318 | if(QAction *act = actions().value(index)) |
319 | return actionGeometry(act); |
320 | return QRect(); |
321 | } |
322 | inline QT3_SUPPORT QFont (int id) const { |
323 | if(QAction *act = findActionForId(id)) |
324 | return act->font(); |
325 | return QFont(); |
326 | } |
327 | inline QT3_SUPPORT void (int id, const QFont &font) { |
328 | if(QAction *act = findActionForId(id)) |
329 | act->setFont(font); |
330 | } |
331 | inline QT3_SUPPORT int (int id) const { |
332 | return actions().indexOf(findActionForId(id)); |
333 | } |
334 | inline QT3_SUPPORT int (int index) const { |
335 | return findIdForAction(actions().value(index)); |
336 | } |
337 | QT3_SUPPORT void (int index, int id); |
338 | inline QT3_SUPPORT void (int index) { |
339 | if(QAction *ret = actions().value(index)) |
340 | ret->activate(QAction::Trigger); |
341 | } |
342 | inline QT3_SUPPORT bool (int id, const QObject *receiver, const char* member) { |
343 | if(QAction *act = findActionForId(id)) { |
344 | QObject::connect(act, SIGNAL(activated(int)), receiver, member); |
345 | return true; |
346 | } |
347 | return false; |
348 | } |
349 | inline QT3_SUPPORT bool (int id,const QObject *receiver, const char* member) { |
350 | if(QAction *act = findActionForId(id)) { |
351 | QObject::disconnect(act, SIGNAL(triggered()), receiver, member); |
352 | return true; |
353 | } |
354 | return false; |
355 | } |
356 | inline QT3_SUPPORT QMenuItem *(int id) const { |
357 | return reinterpret_cast<QMenuItem*>(findActionForId(id)); |
358 | } |
359 | |
360 | inline QT3_SUPPORT void (bool){} |
361 | inline QT3_SUPPORT bool () const {return true;} |
362 | |
363 | QT3_SUPPORT QMenuItem *( QMenu *, int *index ); |
364 | |
365 | QT3_SUPPORT bool (int id, int param); |
366 | QT3_SUPPORT int (int id) const; |
367 | |
368 | //frame |
369 | QT3_SUPPORT int () const; |
370 | |
371 | //popupmenu |
372 | inline QT3_SUPPORT void (const QPoint & pos, int indexAtPoint) { popup(pos, actions().value(indexAtPoint)); } |
373 | inline QT3_SUPPORT int insertTearOffHandle(int = 0, int = 0) { |
374 | setTearOffEnabled(true); |
375 | return -1; |
376 | } |
377 | |
378 | protected: |
379 | inline QT3_SUPPORT int (const QPoint &p, bool ignoreSeparator = true) { |
380 | QAction *ret = actionAt(p); |
381 | if(ignoreSeparator && ret && ret->isSeparator()) |
382 | return -1; |
383 | return findIdForAction(ret); |
384 | } |
385 | inline QT3_SUPPORT int columns() const { return columnCount(); } |
386 | inline QT3_SUPPORT int (int index) { |
387 | return actionGeometry(actions().value(index)).height(); |
388 | } |
389 | inline QT3_SUPPORT int (QMenuItem *mi) { |
390 | return actionGeometry(reinterpret_cast<QAction *>(mi)).height(); |
391 | } |
392 | |
393 | Q_SIGNALS: |
394 | QT_MOC_COMPAT void (int itemId); |
395 | QT_MOC_COMPAT void (int itemId); |
396 | |
397 | private: |
398 | int (const QIcon *icon, const QString *text, const QObject *receiver, const char *member, |
399 | const QKeySequence *shorcut, const QMenu *, int id, int index); |
400 | QAction *(int id) const; |
401 | int (QAction*) const; |
402 | #endif |
403 | |
404 | protected: |
405 | (QMenuPrivate &dd, QWidget* parent = 0); |
406 | |
407 | private: |
408 | Q_DISABLE_COPY() |
409 | |
410 | friend class QMenuBar; |
411 | friend class QMenuBarPrivate; |
412 | friend class QTornOffMenu; |
413 | friend class Q3PopupMenu; |
414 | friend class QComboBox; |
415 | friend class QAction; |
416 | friend class QToolButtonPrivate; |
417 | |
418 | #ifdef Q_WS_MAC |
419 | friend void qt_mac_trayicon_activate_action(QMenu *, QAction *action); |
420 | friend bool qt_mac_watchingAboutToShow(QMenu *); |
421 | friend OSStatus qt_mac_menu_event(EventHandlerCallRef, EventRef, void *); |
422 | friend bool qt_mac_activate_action(OSMenuRef, uint, QAction::ActionEvent, bool); |
423 | friend void qt_mac_emit_menuSignals(QMenu *, bool); |
424 | friend void qt_mac_menu_emit_hovered(QMenu *menu, QAction *action); |
425 | #endif |
426 | }; |
427 | |
428 | #endif // QT_NO_MENU |
429 | |
430 | QT_END_NAMESPACE |
431 | |
432 | QT_END_HEADER |
433 | |
434 | #endif // QMENU_H |
435 | |