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 QMENUBAR_H |
43 | #define QMENUBAR_H |
44 | |
45 | #include <QtGui/qmenu.h> |
46 | |
47 | QT_BEGIN_HEADER |
48 | |
49 | QT_BEGIN_NAMESPACE |
50 | |
51 | QT_MODULE(Gui) |
52 | |
53 | #ifndef QT_NO_MENUBAR |
54 | |
55 | class ; |
56 | class ; |
57 | class QWindowsStyle; |
58 | #ifdef QT3_SUPPORT |
59 | class QMenuItem; |
60 | #endif |
61 | |
62 | class Q_GUI_EXPORT : public QWidget |
63 | { |
64 | Q_OBJECT |
65 | |
66 | Q_PROPERTY(bool defaultUp READ isDefaultUp WRITE setDefaultUp) |
67 | Q_PROPERTY(bool nativeMenuBar READ isNativeMenuBar WRITE setNativeMenuBar) |
68 | |
69 | public: |
70 | explicit (QWidget *parent = 0); |
71 | (); |
72 | |
73 | #ifdef Q_NO_USING_KEYWORD |
74 | void addAction(QAction *action) { QWidget::addAction(action); } |
75 | #else |
76 | using QWidget::addAction; |
77 | #endif |
78 | QAction *(const QString &text); |
79 | QAction *(const QString &text, const QObject *receiver, const char* member); |
80 | |
81 | QAction *(QMenu *); |
82 | QMenu *(const QString &title); |
83 | QMenu *(const QIcon &icon, const QString &title); |
84 | |
85 | |
86 | QAction *(); |
87 | QAction *(QAction *before); |
88 | |
89 | QAction *(QAction *before, QMenu *); |
90 | |
91 | void (); |
92 | |
93 | QAction *() const; |
94 | void (QAction *action); |
95 | |
96 | void (bool); |
97 | bool () const; |
98 | |
99 | QSize () const; |
100 | QSize () const; |
101 | int (int) const; |
102 | |
103 | QRect (QAction *) const; |
104 | QAction *(const QPoint &) const; |
105 | |
106 | void (QWidget *w, Qt::Corner corner = Qt::TopRightCorner); |
107 | QWidget *(Qt::Corner corner = Qt::TopRightCorner) const; |
108 | |
109 | #ifdef Q_WS_MAC |
110 | OSMenuRef macMenu(); |
111 | static bool macUpdateMenuBar(); |
112 | #endif |
113 | |
114 | #ifdef Q_WS_WINCE |
115 | void setDefaultAction(QAction *); |
116 | QAction *defaultAction() const; |
117 | |
118 | static void wceCommands(uint command); |
119 | static void wceRefresh(); |
120 | #endif |
121 | |
122 | bool () const; |
123 | void (bool ); |
124 | |
125 | public Q_SLOTS: |
126 | virtual void (bool visible); |
127 | |
128 | Q_SIGNALS: |
129 | void (QAction *action); |
130 | void (QAction *action); |
131 | |
132 | protected: |
133 | void (QEvent *); |
134 | void (QKeyEvent *); |
135 | void (QMouseEvent *); |
136 | void (QMouseEvent *); |
137 | void (QMouseEvent *); |
138 | void (QEvent *); |
139 | void (QPaintEvent *); |
140 | void (QResizeEvent *); |
141 | void (QActionEvent *); |
142 | void (QFocusEvent *); |
143 | void (QFocusEvent *); |
144 | void (QTimerEvent *); |
145 | bool (QObject *, QEvent *); |
146 | bool (QEvent *); |
147 | void (QStyleOptionMenuItem *option, const QAction *action) const; |
148 | |
149 | #ifdef QT3_SUPPORT |
150 | public: |
151 | QT3_SUPPORT_CONSTRUCTOR QMenuBar(QWidget *parent, const char *name); |
152 | inline QT3_SUPPORT uint count() const { return actions().count(); } |
153 | inline QT3_SUPPORT int insertItem(const QString &text, const QObject *receiver, const char* member, |
154 | const QKeySequence& shortcut = 0, int id = -1, int index = -1) { |
155 | return insertAny(0, &text, receiver, member, &shortcut, 0, id, index); |
156 | } |
157 | inline QT3_SUPPORT int insertItem(const QIcon& icon, const QString &text, |
158 | const QObject *receiver, const char* member, |
159 | const QKeySequence& shortcut = 0, int id = -1, int index = -1) { |
160 | return insertAny(&icon, &text, receiver, member, &shortcut, 0, id, index); |
161 | } |
162 | inline QT3_SUPPORT int insertItem(const QPixmap &pixmap, const QObject *receiver, const char* member, |
163 | const QKeySequence& shortcut = 0, int id = -1, int index = -1) { |
164 | QIcon icon(pixmap); |
165 | return insertAny(&icon, 0, receiver, member, &shortcut, 0, id, index); |
166 | } |
167 | inline QT3_SUPPORT int insertItem(const QString &text, int id=-1, int index=-1) { |
168 | return insertAny(0, &text, 0, 0, 0, 0, id, index); |
169 | } |
170 | inline QT3_SUPPORT int insertItem(const QIcon& icon, const QString &text, int id=-1, int index=-1) { |
171 | return insertAny(&icon, &text, 0, 0, 0, 0, id, index); |
172 | } |
173 | inline QT3_SUPPORT int insertItem(const QString &text, QMenu *popup, int id=-1, int index=-1) { |
174 | return insertAny(0, &text, 0, 0, 0, popup, id, index); |
175 | } |
176 | inline QT3_SUPPORT int insertItem(const QIcon& icon, const QString &text, QMenu *popup, int id=-1, int index=-1) { |
177 | return insertAny(&icon, &text, 0, 0, 0, popup, id, index); |
178 | } |
179 | inline QT3_SUPPORT int insertItem(const QPixmap &pixmap, int id=-1, int index=-1) { |
180 | QIcon icon(pixmap); |
181 | return insertAny(&icon, 0, 0, 0, 0, 0, id, index); |
182 | } |
183 | inline QT3_SUPPORT int insertItem(const QPixmap &pixmap, QMenu *popup, int id=-1, int index=-1) { |
184 | QIcon icon(pixmap); |
185 | return insertAny(&icon, 0, 0, 0, 0, popup, id, index); |
186 | } |
187 | QT3_SUPPORT int insertSeparator(int index=-1); |
188 | inline QT3_SUPPORT void removeItem(int id) { |
189 | if(QAction *act = findActionForId(id)) |
190 | removeAction(act); } |
191 | inline QT3_SUPPORT void removeItemAt(int index) { |
192 | if(QAction *act = actions().value(index)) |
193 | removeAction(act); } |
194 | #ifndef QT_NO_SHORTCUT |
195 | inline QT3_SUPPORT QKeySequence accel(int id) const { |
196 | if(QAction *act = findActionForId(id)) |
197 | return act->shortcut(); |
198 | return QKeySequence(); } |
199 | inline QT3_SUPPORT void setAccel(const QKeySequence& key, int id) { |
200 | if(QAction *act = findActionForId(id)) |
201 | act->setShortcut(key); |
202 | } |
203 | #endif |
204 | inline QT3_SUPPORT QIcon iconSet(int id) const { |
205 | if(QAction *act = findActionForId(id)) |
206 | return act->icon(); |
207 | return QIcon(); } |
208 | inline QT3_SUPPORT QString text(int id) const { |
209 | if(QAction *act = findActionForId(id)) |
210 | return act->text(); |
211 | return QString(); } |
212 | inline QT3_SUPPORT QPixmap pixmap(int id) const { |
213 | if(QAction *act = findActionForId(id)) |
214 | return act->icon().pixmap(QSize(22,22)); |
215 | return QPixmap(); } |
216 | inline QT3_SUPPORT void setWhatsThis(int id, const QString &w) { |
217 | if(QAction *act = findActionForId(id)) |
218 | act->setWhatsThis(w); } |
219 | inline QT3_SUPPORT QString whatsThis(int id) const { |
220 | if(QAction *act = findActionForId(id)) |
221 | return act->whatsThis(); |
222 | return QString(); } |
223 | |
224 | inline QT3_SUPPORT void changeItem(int id, const QString &text) { |
225 | if(QAction *act = findActionForId(id)) |
226 | act->setText(text); } |
227 | inline QT3_SUPPORT void changeItem(int id, const QPixmap &pixmap) { |
228 | if(QAction *act = findActionForId(id)) |
229 | act->setIcon(QIcon(pixmap)); } |
230 | inline QT3_SUPPORT void changeItem(int id, const QIcon &icon, const QString &text) { |
231 | if(QAction *act = findActionForId(id)) { |
232 | act->setIcon(icon); |
233 | act->setText(text); |
234 | } |
235 | } |
236 | inline QT3_SUPPORT bool isItemActive(int id) const { return findActionForId(id) == activeAction(); } |
237 | inline QT3_SUPPORT bool isItemEnabled(int id) const { |
238 | if(QAction *act = findActionForId(id)) |
239 | return act->isEnabled(); |
240 | return false; } |
241 | inline QT3_SUPPORT void setItemEnabled(int id, bool enable) { |
242 | if(QAction *act = findActionForId(id)) |
243 | act->setEnabled(enable); } |
244 | inline QT3_SUPPORT bool isItemChecked(int id) const { |
245 | if(QAction *act = findActionForId(id)) |
246 | return act->isChecked(); |
247 | return false; } |
248 | inline QT3_SUPPORT void setItemChecked(int id, bool check) { |
249 | if(QAction *act = findActionForId(id)) |
250 | act->setChecked(check); } |
251 | inline QT3_SUPPORT bool isItemVisible(int id) const { |
252 | if(QAction *act = findActionForId(id)) |
253 | return act->isVisible(); |
254 | return false; } |
255 | inline QT3_SUPPORT void setItemVisible(int id, bool visible) { |
256 | if(QAction *act = findActionForId(id)) |
257 | act->setVisible(visible); } |
258 | inline QT3_SUPPORT int indexOf(int id) const { return actions().indexOf(findActionForId(id)); } |
259 | inline QT3_SUPPORT int idAt(int index) const { |
260 | return index >= 0 && index < actions().size() |
261 | ? findIdForAction(actions().at(index)) |
262 | : -1; |
263 | } |
264 | inline QT3_SUPPORT void activateItemAt(int index) { |
265 | if(QAction *ret = actions().value(index)) |
266 | setActiveAction(ret); |
267 | } |
268 | inline QT3_SUPPORT bool connectItem(int id, const QObject *receiver, const char* member) { |
269 | if(QAction *act = findActionForId(id)) { |
270 | QObject::connect(act, SIGNAL(triggered()), receiver, member); |
271 | return true; |
272 | } |
273 | return false; |
274 | } |
275 | inline QT3_SUPPORT bool disconnectItem(int id,const QObject *receiver, const char* member) { |
276 | if(QAction *act = findActionForId(id)) { |
277 | QObject::disconnect(act, SIGNAL(triggered()), receiver, member); |
278 | return true; |
279 | } |
280 | return false; |
281 | } |
282 | inline QT3_SUPPORT QMenuItem *findItem(int id) const { |
283 | return (QMenuItem*)findActionForId(id); |
284 | } |
285 | QT3_SUPPORT bool setItemParameter(int id, int param); |
286 | QT3_SUPPORT int itemParameter(int id) const; |
287 | |
288 | //frame |
289 | QT3_SUPPORT int frameWidth() const; |
290 | |
291 | QT3_SUPPORT void setFrameRect(QRect) {} |
292 | QT3_SUPPORT QRect frameRect() const { return QRect(); } |
293 | enum DummyFrame { Box, Sunken, Plain, Raised, MShadow, NoFrame, Panel, StyledPanel, |
294 | HLine, VLine, GroupBoxPanel, WinPanel, ToolBarPanel, MenuBarPanel, |
295 | PopupPanel, LineEditPanel, TabWidgetPanel, MShape }; |
296 | QT3_SUPPORT void setFrameShadow(DummyFrame) {} |
297 | QT3_SUPPORT DummyFrame frameShadow() const { return Plain; } |
298 | QT3_SUPPORT void setFrameShape(DummyFrame) {} |
299 | QT3_SUPPORT DummyFrame frameShape() const { return NoFrame; } |
300 | QT3_SUPPORT void setFrameStyle(int) {} |
301 | QT3_SUPPORT int frameStyle() const { return 0; } |
302 | QT3_SUPPORT void setLineWidth(int) {} |
303 | QT3_SUPPORT int lineWidth() const { return 0; } |
304 | QT3_SUPPORT void setMargin(int margin) { setContentsMargins(margin, margin, margin, margin); } |
305 | QT3_SUPPORT int margin() const |
306 | { int margin; int dummy; getContentsMargins(&margin, &dummy, &dummy, &dummy); return margin; } |
307 | QT3_SUPPORT void setMidLineWidth(int) {} |
308 | QT3_SUPPORT int midLineWidth() const { return 0; } |
309 | |
310 | //menubar |
311 | enum Separator { Never=0, InWindowsStyle=1 }; |
312 | inline QT3_SUPPORT Separator separator() const { return InWindowsStyle; } |
313 | inline QT3_SUPPORT void setSeparator(Separator) { } |
314 | |
315 | QT3_SUPPORT void setAutoGeometry(bool); |
316 | QT3_SUPPORT bool autoGeometry() const; |
317 | |
318 | Q_SIGNALS: |
319 | QT_MOC_COMPAT void activated(int itemId); |
320 | QT_MOC_COMPAT void highlighted(int itemId); |
321 | |
322 | protected: |
323 | inline QT3_SUPPORT QRect itemRect(int index) { |
324 | if(QAction *act = actions().value(index)) |
325 | return actionGeometry(act); |
326 | return QRect(); |
327 | } |
328 | inline QT3_SUPPORT int itemAtPos(const QPoint &p) { |
329 | return findIdForAction(actionAt(p)); |
330 | } |
331 | private: |
332 | QAction *findActionForId(int id) const; |
333 | int insertAny(const QIcon *icon, const QString *text, const QObject *receiver, const char *member, |
334 | const QKeySequence *shorcut, const QMenu *popup, int id, int index); |
335 | int findIdForAction(QAction*) const; |
336 | #endif |
337 | |
338 | private: |
339 | Q_DECLARE_PRIVATE(QMenuBar) |
340 | Q_DISABLE_COPY() |
341 | Q_PRIVATE_SLOT(d_func(), void _q_actionTriggered()) |
342 | Q_PRIVATE_SLOT(d_func(), void _q_actionHovered()) |
343 | Q_PRIVATE_SLOT(d_func(), void _q_internalShortcutActivated(int)) |
344 | Q_PRIVATE_SLOT(d_func(), void _q_updateLayout()) |
345 | |
346 | #ifdef Q_WS_WINCE |
347 | Q_PRIVATE_SLOT(d_func(), void _q_updateDefaultAction()) |
348 | #endif |
349 | |
350 | friend class QMenu; |
351 | friend class QMenuPrivate; |
352 | friend class QWindowsStyle; |
353 | |
354 | #ifdef Q_WS_MAC |
355 | friend class QApplicationPrivate; |
356 | friend class QWidgetPrivate; |
357 | friend bool qt_mac_activate_action(MenuRef, uint, QAction::ActionEvent, bool); |
358 | #endif |
359 | }; |
360 | |
361 | #endif // QT_NO_MENUBAR |
362 | |
363 | QT_END_NAMESPACE |
364 | |
365 | QT_END_HEADER |
366 | |
367 | #endif // QMENUBAR_H |
368 | |