1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
6 | **
|
---|
7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at qt-info@nokia.com.
|
---|
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 QMenuBarPrivate;
|
---|
56 | class QStyleOptionMenuItem;
|
---|
57 | class QWindowsStyle;
|
---|
58 | #ifdef QT3_SUPPORT
|
---|
59 | class QMenuItem;
|
---|
60 | #endif
|
---|
61 |
|
---|
62 | class Q_GUI_EXPORT QMenuBar : 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 QMenuBar(QWidget *parent = 0);
|
---|
71 | ~QMenuBar();
|
---|
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 *addAction(const QString &text);
|
---|
79 | QAction *addAction(const QString &text, const QObject *receiver, const char* member);
|
---|
80 |
|
---|
81 | QAction *addMenu(QMenu *menu);
|
---|
82 | QMenu *addMenu(const QString &title);
|
---|
83 | QMenu *addMenu(const QIcon &icon, const QString &title);
|
---|
84 |
|
---|
85 |
|
---|
86 | QAction *addSeparator();
|
---|
87 | QAction *insertSeparator(QAction *before);
|
---|
88 |
|
---|
89 | QAction *insertMenu(QAction *before, QMenu *menu);
|
---|
90 |
|
---|
91 | void clear();
|
---|
92 |
|
---|
93 | QAction *activeAction() const;
|
---|
94 | void setActiveAction(QAction *action);
|
---|
95 |
|
---|
96 | void setDefaultUp(bool);
|
---|
97 | bool isDefaultUp() const;
|
---|
98 |
|
---|
99 | QSize sizeHint() const;
|
---|
100 | QSize minimumSizeHint() const;
|
---|
101 | int heightForWidth(int) const;
|
---|
102 |
|
---|
103 | QRect actionGeometry(QAction *) const;
|
---|
104 | QAction *actionAt(const QPoint &) const;
|
---|
105 |
|
---|
106 | void setCornerWidget(QWidget *w, Qt::Corner corner = Qt::TopRightCorner);
|
---|
107 | QWidget *cornerWidget(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 isNativeMenuBar() const;
|
---|
123 | void setNativeMenuBar(bool nativeMenuBar);
|
---|
124 |
|
---|
125 | public Q_SLOTS:
|
---|
126 | virtual void setVisible(bool visible);
|
---|
127 |
|
---|
128 | Q_SIGNALS:
|
---|
129 | void triggered(QAction *action);
|
---|
130 | void hovered(QAction *action);
|
---|
131 |
|
---|
132 | protected:
|
---|
133 | void changeEvent(QEvent *);
|
---|
134 | void keyPressEvent(QKeyEvent *);
|
---|
135 | void mouseReleaseEvent(QMouseEvent *);
|
---|
136 | void mousePressEvent(QMouseEvent *);
|
---|
137 | void mouseMoveEvent(QMouseEvent *);
|
---|
138 | void leaveEvent(QEvent *);
|
---|
139 | void paintEvent(QPaintEvent *);
|
---|
140 | void resizeEvent(QResizeEvent *);
|
---|
141 | void actionEvent(QActionEvent *);
|
---|
142 | void focusOutEvent(QFocusEvent *);
|
---|
143 | void focusInEvent(QFocusEvent *);
|
---|
144 | void timerEvent(QTimerEvent *);
|
---|
145 | bool eventFilter(QObject *, QEvent *);
|
---|
146 | bool event(QEvent *);
|
---|
147 | void initStyleOption(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(QMenuBar)
|
---|
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
|
---|