| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** 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 are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at qt-sales@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 |
|
|---|
| 68 | public:
|
|---|
| 69 | explicit QMenuBar(QWidget *parent = 0);
|
|---|
| 70 | ~QMenuBar();
|
|---|
| 71 |
|
|---|
| 72 | #ifdef Q_NO_USING_KEYWORD
|
|---|
| 73 | void addAction(QAction *action) { QWidget::addAction(action); }
|
|---|
| 74 | #else
|
|---|
| 75 | using QWidget::addAction;
|
|---|
| 76 | #endif
|
|---|
| 77 | QAction *addAction(const QString &text);
|
|---|
| 78 | QAction *addAction(const QString &text, const QObject *receiver, const char* member);
|
|---|
| 79 |
|
|---|
| 80 | QAction *addMenu(QMenu *menu);
|
|---|
| 81 | QMenu *addMenu(const QString &title);
|
|---|
| 82 | QMenu *addMenu(const QIcon &icon, const QString &title);
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 | QAction *addSeparator();
|
|---|
| 86 | QAction *insertSeparator(QAction *before);
|
|---|
| 87 |
|
|---|
| 88 | QAction *insertMenu(QAction *before, QMenu *menu);
|
|---|
| 89 |
|
|---|
| 90 | void clear();
|
|---|
| 91 |
|
|---|
| 92 | QAction *activeAction() const;
|
|---|
| 93 | void setActiveAction(QAction *action);
|
|---|
| 94 |
|
|---|
| 95 | void setDefaultUp(bool);
|
|---|
| 96 | bool isDefaultUp() const;
|
|---|
| 97 |
|
|---|
| 98 | QSize sizeHint() const;
|
|---|
| 99 | QSize minimumSizeHint() const;
|
|---|
| 100 | int heightForWidth(int) const;
|
|---|
| 101 |
|
|---|
| 102 | QRect actionGeometry(QAction *) const;
|
|---|
| 103 | QAction *actionAt(const QPoint &) const;
|
|---|
| 104 |
|
|---|
| 105 | void setCornerWidget(QWidget *w, Qt::Corner corner = Qt::TopRightCorner);
|
|---|
| 106 | QWidget *cornerWidget(Qt::Corner corner = Qt::TopRightCorner) const;
|
|---|
| 107 |
|
|---|
| 108 | #ifdef Q_WS_MAC
|
|---|
| 109 | OSMenuRef macMenu();
|
|---|
| 110 | static bool macUpdateMenuBar();
|
|---|
| 111 | #endif
|
|---|
| 112 |
|
|---|
| 113 | #ifdef Q_OS_WINCE
|
|---|
| 114 | void setDefaultAction(QAction *);
|
|---|
| 115 | QAction *defaultAction() const;
|
|---|
| 116 |
|
|---|
| 117 | static void wceCommands(uint command, HWND controlHandle);
|
|---|
| 118 | static void wceRefresh();
|
|---|
| 119 | #endif
|
|---|
| 120 |
|
|---|
| 121 | public Q_SLOTS:
|
|---|
| 122 | virtual void setVisible(bool visible);
|
|---|
| 123 |
|
|---|
| 124 | Q_SIGNALS:
|
|---|
| 125 | void triggered(QAction *action);
|
|---|
| 126 | void hovered(QAction *action);
|
|---|
| 127 |
|
|---|
| 128 | protected:
|
|---|
| 129 | void changeEvent(QEvent *);
|
|---|
| 130 | void keyPressEvent(QKeyEvent *);
|
|---|
| 131 | void mouseReleaseEvent(QMouseEvent *);
|
|---|
| 132 | void mousePressEvent(QMouseEvent *);
|
|---|
| 133 | void mouseMoveEvent(QMouseEvent *);
|
|---|
| 134 | void leaveEvent(QEvent *);
|
|---|
| 135 | void paintEvent(QPaintEvent *);
|
|---|
| 136 | void resizeEvent(QResizeEvent *);
|
|---|
| 137 | void actionEvent(QActionEvent *);
|
|---|
| 138 | void focusOutEvent(QFocusEvent *);
|
|---|
| 139 | void focusInEvent(QFocusEvent *);
|
|---|
| 140 | void timerEvent(QTimerEvent *);
|
|---|
| 141 | bool eventFilter(QObject *, QEvent *);
|
|---|
| 142 | bool event(QEvent *);
|
|---|
| 143 | void initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const;
|
|---|
| 144 |
|
|---|
| 145 | #ifdef QT3_SUPPORT
|
|---|
| 146 | public:
|
|---|
| 147 | QT3_SUPPORT_CONSTRUCTOR QMenuBar(QWidget *parent, const char *name);
|
|---|
| 148 | inline QT3_SUPPORT uint count() const { return actions().count(); }
|
|---|
| 149 | inline QT3_SUPPORT int insertItem(const QString &text, const QObject *receiver, const char* member,
|
|---|
| 150 | const QKeySequence& shortcut = 0, int id = -1, int index = -1) {
|
|---|
| 151 | return insertAny(0, &text, receiver, member, &shortcut, 0, id, index);
|
|---|
| 152 | }
|
|---|
| 153 | inline QT3_SUPPORT int insertItem(const QIcon& icon, const QString &text,
|
|---|
| 154 | const QObject *receiver, const char* member,
|
|---|
| 155 | const QKeySequence& shortcut = 0, int id = -1, int index = -1) {
|
|---|
| 156 | return insertAny(&icon, &text, receiver, member, &shortcut, 0, id, index);
|
|---|
| 157 | }
|
|---|
| 158 | inline QT3_SUPPORT int insertItem(const QPixmap &pixmap, const QObject *receiver, const char* member,
|
|---|
| 159 | const QKeySequence& shortcut = 0, int id = -1, int index = -1) {
|
|---|
| 160 | QIcon icon(pixmap);
|
|---|
| 161 | return insertAny(&icon, 0, receiver, member, &shortcut, 0, id, index);
|
|---|
| 162 | }
|
|---|
| 163 | inline QT3_SUPPORT int insertItem(const QString &text, int id=-1, int index=-1) {
|
|---|
| 164 | return insertAny(0, &text, 0, 0, 0, 0, id, index);
|
|---|
| 165 | }
|
|---|
| 166 | inline QT3_SUPPORT int insertItem(const QIcon& icon, const QString &text, int id=-1, int index=-1) {
|
|---|
| 167 | return insertAny(&icon, &text, 0, 0, 0, 0, id, index);
|
|---|
| 168 | }
|
|---|
| 169 | inline QT3_SUPPORT int insertItem(const QString &text, QMenu *popup, int id=-1, int index=-1) {
|
|---|
| 170 | return insertAny(0, &text, 0, 0, 0, popup, id, index);
|
|---|
| 171 | }
|
|---|
| 172 | inline QT3_SUPPORT int insertItem(const QIcon& icon, const QString &text, QMenu *popup, int id=-1, int index=-1) {
|
|---|
| 173 | return insertAny(&icon, &text, 0, 0, 0, popup, id, index);
|
|---|
| 174 | }
|
|---|
| 175 | inline QT3_SUPPORT int insertItem(const QPixmap &pixmap, int id=-1, int index=-1) {
|
|---|
| 176 | QIcon icon(pixmap);
|
|---|
| 177 | return insertAny(&icon, 0, 0, 0, 0, 0, id, index);
|
|---|
| 178 | }
|
|---|
| 179 | inline QT3_SUPPORT int insertItem(const QPixmap &pixmap, QMenu *popup, int id=-1, int index=-1) {
|
|---|
| 180 | QIcon icon(pixmap);
|
|---|
| 181 | return insertAny(&icon, 0, 0, 0, 0, popup, id, index);
|
|---|
| 182 | }
|
|---|
| 183 | QT3_SUPPORT int insertSeparator(int index=-1);
|
|---|
| 184 | inline QT3_SUPPORT void removeItem(int id) {
|
|---|
| 185 | if(QAction *act = findActionForId(id))
|
|---|
| 186 | removeAction(act); }
|
|---|
| 187 | inline QT3_SUPPORT void removeItemAt(int index) {
|
|---|
| 188 | if(QAction *act = actions().value(index))
|
|---|
| 189 | removeAction(act); }
|
|---|
| 190 | #ifndef QT_NO_SHORTCUT
|
|---|
| 191 | inline QT3_SUPPORT QKeySequence accel(int id) const {
|
|---|
| 192 | if(QAction *act = findActionForId(id))
|
|---|
| 193 | return act->shortcut();
|
|---|
| 194 | return QKeySequence(); }
|
|---|
| 195 | inline QT3_SUPPORT void setAccel(const QKeySequence& key, int id) {
|
|---|
| 196 | if(QAction *act = findActionForId(id))
|
|---|
| 197 | act->setShortcut(key);
|
|---|
| 198 | }
|
|---|
| 199 | #endif
|
|---|
| 200 | inline QT3_SUPPORT QIcon iconSet(int id) const {
|
|---|
| 201 | if(QAction *act = findActionForId(id))
|
|---|
| 202 | return act->icon();
|
|---|
| 203 | return QIcon(); }
|
|---|
| 204 | inline QT3_SUPPORT QString text(int id) const {
|
|---|
| 205 | if(QAction *act = findActionForId(id))
|
|---|
| 206 | return act->text();
|
|---|
| 207 | return QString(); }
|
|---|
| 208 | inline QT3_SUPPORT QPixmap pixmap(int id) const {
|
|---|
| 209 | if(QAction *act = findActionForId(id))
|
|---|
| 210 | return act->icon().pixmap(QSize(22,22));
|
|---|
| 211 | return QPixmap(); }
|
|---|
| 212 | inline QT3_SUPPORT void setWhatsThis(int id, const QString &w) {
|
|---|
| 213 | if(QAction *act = findActionForId(id))
|
|---|
| 214 | act->setWhatsThis(w); }
|
|---|
| 215 | inline QT3_SUPPORT QString whatsThis(int id) const {
|
|---|
| 216 | if(QAction *act = findActionForId(id))
|
|---|
| 217 | return act->whatsThis();
|
|---|
| 218 | return QString(); }
|
|---|
| 219 |
|
|---|
| 220 | inline QT3_SUPPORT void changeItem(int id, const QString &text) {
|
|---|
| 221 | if(QAction *act = findActionForId(id))
|
|---|
| 222 | act->setText(text); }
|
|---|
| 223 | inline QT3_SUPPORT void changeItem(int id, const QPixmap &pixmap) {
|
|---|
| 224 | if(QAction *act = findActionForId(id))
|
|---|
| 225 | act->setIcon(QIcon(pixmap)); }
|
|---|
| 226 | inline QT3_SUPPORT void changeItem(int id, const QIcon &icon, const QString &text) {
|
|---|
| 227 | if(QAction *act = findActionForId(id)) {
|
|---|
| 228 | act->setIcon(icon);
|
|---|
| 229 | act->setText(text);
|
|---|
| 230 | }
|
|---|
| 231 | }
|
|---|
| 232 | inline QT3_SUPPORT bool isItemActive(int id) const { return findActionForId(id) == activeAction(); }
|
|---|
| 233 | inline QT3_SUPPORT bool isItemEnabled(int id) const {
|
|---|
| 234 | if(QAction *act = findActionForId(id))
|
|---|
| 235 | return act->isEnabled();
|
|---|
| 236 | return false; }
|
|---|
| 237 | inline QT3_SUPPORT void setItemEnabled(int id, bool enable) {
|
|---|
| 238 | if(QAction *act = findActionForId(id))
|
|---|
| 239 | act->setEnabled(enable); }
|
|---|
| 240 | inline QT3_SUPPORT bool isItemChecked(int id) const {
|
|---|
| 241 | if(QAction *act = findActionForId(id))
|
|---|
| 242 | return act->isChecked();
|
|---|
| 243 | return false; }
|
|---|
| 244 | inline QT3_SUPPORT void setItemChecked(int id, bool check) {
|
|---|
| 245 | if(QAction *act = findActionForId(id))
|
|---|
| 246 | act->setChecked(check); }
|
|---|
| 247 | inline QT3_SUPPORT bool isItemVisible(int id) const {
|
|---|
| 248 | if(QAction *act = findActionForId(id))
|
|---|
| 249 | return act->isVisible();
|
|---|
| 250 | return false; }
|
|---|
| 251 | inline QT3_SUPPORT void setItemVisible(int id, bool visible) {
|
|---|
| 252 | if(QAction *act = findActionForId(id))
|
|---|
| 253 | act->setVisible(visible); }
|
|---|
| 254 | inline QT3_SUPPORT int indexOf(int id) const { return actions().indexOf(findActionForId(id)); }
|
|---|
| 255 | inline QT3_SUPPORT int idAt(int index) const {
|
|---|
| 256 | return index >= 0 && index < actions().size()
|
|---|
| 257 | ? findIdForAction(actions().at(index))
|
|---|
| 258 | : -1;
|
|---|
| 259 | }
|
|---|
| 260 | inline QT3_SUPPORT void activateItemAt(int index) {
|
|---|
| 261 | if(QAction *ret = actions().value(index))
|
|---|
| 262 | setActiveAction(ret);
|
|---|
| 263 | }
|
|---|
| 264 | inline QT3_SUPPORT bool connectItem(int id, const QObject *receiver, const char* member) {
|
|---|
| 265 | if(QAction *act = findActionForId(id)) {
|
|---|
| 266 | QObject::connect(act, SIGNAL(triggered()), receiver, member);
|
|---|
| 267 | return true;
|
|---|
| 268 | }
|
|---|
| 269 | return false;
|
|---|
| 270 | }
|
|---|
| 271 | inline QT3_SUPPORT bool disconnectItem(int id,const QObject *receiver, const char* member) {
|
|---|
| 272 | if(QAction *act = findActionForId(id)) {
|
|---|
| 273 | QObject::disconnect(act, SIGNAL(triggered()), receiver, member);
|
|---|
| 274 | return true;
|
|---|
| 275 | }
|
|---|
| 276 | return false;
|
|---|
| 277 | }
|
|---|
| 278 | inline QT3_SUPPORT QMenuItem *findItem(int id) const {
|
|---|
| 279 | return (QMenuItem*)findActionForId(id);
|
|---|
| 280 | }
|
|---|
| 281 | QT3_SUPPORT bool setItemParameter(int id, int param);
|
|---|
| 282 | QT3_SUPPORT int itemParameter(int id) const;
|
|---|
| 283 |
|
|---|
| 284 | //frame
|
|---|
| 285 | QT3_SUPPORT int frameWidth() const;
|
|---|
| 286 |
|
|---|
| 287 | QT3_SUPPORT void setFrameRect(QRect) {}
|
|---|
| 288 | QT3_SUPPORT QRect frameRect() const { return QRect(); }
|
|---|
| 289 | enum DummyFrame { Box, Sunken, Plain, Raised, MShadow, NoFrame, Panel, StyledPanel,
|
|---|
| 290 | HLine, VLine, GroupBoxPanel, WinPanel, ToolBarPanel, MenuBarPanel,
|
|---|
| 291 | PopupPanel, LineEditPanel, TabWidgetPanel, MShape };
|
|---|
| 292 | QT3_SUPPORT void setFrameShadow(DummyFrame) {}
|
|---|
| 293 | QT3_SUPPORT DummyFrame frameShadow() const { return Plain; }
|
|---|
| 294 | QT3_SUPPORT void setFrameShape(DummyFrame) {}
|
|---|
| 295 | QT3_SUPPORT DummyFrame frameShape() const { return NoFrame; }
|
|---|
| 296 | QT3_SUPPORT void setFrameStyle(int) {}
|
|---|
| 297 | QT3_SUPPORT int frameStyle() const { return 0; }
|
|---|
| 298 | QT3_SUPPORT void setLineWidth(int) {}
|
|---|
| 299 | QT3_SUPPORT int lineWidth() const { return 0; }
|
|---|
| 300 | QT3_SUPPORT void setMargin(int margin) { setContentsMargins(margin, margin, margin, margin); }
|
|---|
| 301 | QT3_SUPPORT int margin() const
|
|---|
| 302 | { int margin; int dummy; getContentsMargins(&margin, &dummy, &dummy, &dummy); return margin; }
|
|---|
| 303 | QT3_SUPPORT void setMidLineWidth(int) {}
|
|---|
| 304 | QT3_SUPPORT int midLineWidth() const { return 0; }
|
|---|
| 305 |
|
|---|
| 306 | //menubar
|
|---|
| 307 | enum Separator { Never=0, InWindowsStyle=1 };
|
|---|
| 308 | inline QT3_SUPPORT Separator separator() const { return InWindowsStyle; }
|
|---|
| 309 | inline QT3_SUPPORT void setSeparator(Separator) { }
|
|---|
| 310 |
|
|---|
| 311 | QT3_SUPPORT void setAutoGeometry(bool);
|
|---|
| 312 | QT3_SUPPORT bool autoGeometry() const;
|
|---|
| 313 |
|
|---|
| 314 | Q_SIGNALS:
|
|---|
| 315 | QT_MOC_COMPAT void activated(int itemId);
|
|---|
| 316 | QT_MOC_COMPAT void highlighted(int itemId);
|
|---|
| 317 |
|
|---|
| 318 | protected:
|
|---|
| 319 | inline QT3_SUPPORT QRect itemRect(int index) {
|
|---|
| 320 | if(QAction *act = actions().value(index))
|
|---|
| 321 | return actionGeometry(act);
|
|---|
| 322 | return QRect();
|
|---|
| 323 | }
|
|---|
| 324 | inline QT3_SUPPORT int itemAtPos(const QPoint &p) {
|
|---|
| 325 | return findIdForAction(actionAt(p));
|
|---|
| 326 | }
|
|---|
| 327 | private:
|
|---|
| 328 | QAction *findActionForId(int id) const;
|
|---|
| 329 | int insertAny(const QIcon *icon, const QString *text, const QObject *receiver, const char *member,
|
|---|
| 330 | const QKeySequence *shorcut, const QMenu *popup, int id, int index);
|
|---|
| 331 | int findIdForAction(QAction*) const;
|
|---|
| 332 | #endif
|
|---|
| 333 |
|
|---|
| 334 | private:
|
|---|
| 335 | Q_DECLARE_PRIVATE(QMenuBar)
|
|---|
| 336 | Q_DISABLE_COPY(QMenuBar)
|
|---|
| 337 | Q_PRIVATE_SLOT(d_func(), void _q_actionTriggered())
|
|---|
| 338 | Q_PRIVATE_SLOT(d_func(), void _q_actionHovered())
|
|---|
| 339 | Q_PRIVATE_SLOT(d_func(), void _q_internalShortcutActivated(int))
|
|---|
| 340 | Q_PRIVATE_SLOT(d_func(), void _q_updateLayout())
|
|---|
| 341 |
|
|---|
| 342 | #ifdef Q_OS_WINCE
|
|---|
| 343 | Q_PRIVATE_SLOT(d_func(), void _q_updateDefaultAction())
|
|---|
| 344 | #endif
|
|---|
| 345 |
|
|---|
| 346 | friend class QMenu;
|
|---|
| 347 | friend class QMenuPrivate;
|
|---|
| 348 | friend class QWindowsStyle;
|
|---|
| 349 |
|
|---|
| 350 | #ifdef Q_WS_MAC
|
|---|
| 351 | friend class QApplicationPrivate;
|
|---|
| 352 | friend class QWidgetPrivate;
|
|---|
| 353 | friend bool qt_mac_activate_action(MenuRef, uint, QAction::ActionEvent, bool);
|
|---|
| 354 | #endif
|
|---|
| 355 | };
|
|---|
| 356 |
|
|---|
| 357 | #endif // QT_NO_MENUBAR
|
|---|
| 358 |
|
|---|
| 359 | QT_END_NAMESPACE
|
|---|
| 360 |
|
|---|
| 361 | QT_END_HEADER
|
|---|
| 362 |
|
|---|
| 363 | #endif // QMENUBAR_H
|
|---|