- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qmenubar.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtGui module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QMENUBAR_H
    00043 #define QMENUBAR_H
    00044
    00045 #include <QtGui/qmenu.h>
    00046
    00047 QT_BEGIN_HEADER
    00048
    00049 QT_BEGIN_NAMESPACE
    00050
    00051 QT_MODULE(Gui)
    00052
    00053 #ifndef QT_NO_MENUBAR
    00054
    00055 class QMenuBarPrivate;
    00056 class QStyleOptionMenuItem;
    00057 class QWindowsStyle;
    00058 #ifdef QT3_SUPPORT
    00059 class QMenuItem;
    00060 #endif
    00061
    00062 class Q_GUI_EXPORT QMenuBar : public QWidget
    00063 {
    00064     Q_OBJECT
    00065
    00066     Q_PROPERTY(bool defaultUp READ isDefaultUp WRITE setDefaultUp)
    00067     Q_PROPERTY(bool nativeMenuBar READ isNativeMenuBar WRITE setNativeMenuBar)
    00068
    00069 public:
    00070     explicit QMenuBar(QWidget *parent = 0);
    00071     ~QMenuBar();
    00072
    00073 #ifdef Q_NO_USING_KEYWORD
    00074     void addAction(QAction *action) { QWidget::addAction(action); }
    00075 #else
    00076     using QWidget::addAction;
    00077 #endif
    00078     QAction *addAction(const QString &text);
    00079     QAction *addAction(const QString &text, const QObject *receiver, const char* member);
    00080
    00081     QAction *addMenu(QMenu *menu);
    00082     QMenu *addMenu(const QString &title);
    00083     QMenu *addMenu(const QIcon &icon, const QString &title);
    00084
    00085
    00086     QAction *addSeparator();
    00087     QAction *insertSeparator(QAction *before);
    00088
    00089     QAction *insertMenu(QAction *before, QMenu *menu);
    00090
    00091     void clear();
    00092
    00093     QAction *activeAction() const;
    00094     void setActiveAction(QAction *action);
    00095
    00096     void setDefaultUp(bool);
    00097     bool isDefaultUp() const;
    00098
    00099     QSize sizeHint() const;
    00100     QSize minimumSizeHint() const;
    00101     int heightForWidth(int) const;
    00102
    00103     QRect actionGeometry(QAction *) const;
    00104     QAction *actionAt(const QPoint &) const;
    00105
    00106     void setCornerWidget(QWidget *w, Qt::Corner corner = Qt::TopRightCorner);
    00107     QWidget *cornerWidget(Qt::Corner corner = Qt::TopRightCorner) const;
    00108
    00109 #ifdef Q_WS_MAC
    00110     OSMenuRef macMenu();
    00111     static bool macUpdateMenuBar();
    00112 #endif
    00113
    00114 #ifdef Q_WS_WINCE
    00115     void setDefaultAction(QAction *);
    00116     QAction *defaultAction() const;
    00117
    00118     static void wceCommands(uint command);
    00119     static void wceRefresh();
    00120 #endif
    00121
    00122     bool isNativeMenuBar() const;
    00123     void setNativeMenuBar(bool nativeMenuBar);
    00124
    00125 public Q_SLOTS:
    00126     virtual void setVisible(bool visible);
    00127
    00128 Q_SIGNALS:
    00129     void triggered(QAction *action);
    00130     void hovered(QAction *action);
    00131
    00132 protected:
    00133     void changeEvent(QEvent *);
    00134     void keyPressEvent(QKeyEvent *);
    00135     void mouseReleaseEvent(QMouseEvent *);
    00136     void mousePressEvent(QMouseEvent *);
    00137     void mouseMoveEvent(QMouseEvent *);
    00138     void leaveEvent(QEvent *);
    00139     void paintEvent(QPaintEvent *);
    00140     void resizeEvent(QResizeEvent *);
    00141     void actionEvent(QActionEvent *);
    00142     void focusOutEvent(QFocusEvent *);
    00143     void focusInEvent(QFocusEvent *);
    00144     void timerEvent(QTimerEvent *);
    00145     bool eventFilter(QObject *, QEvent *);
    00146     bool event(QEvent *);
    00147     void initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const;
    00148
    00149 #ifdef QT3_SUPPORT
    00150 public:
    00151     QT3_SUPPORT_CONSTRUCTOR QMenuBar(QWidget *parent, const char *name);
    00152     inline QT3_SUPPORT uint count() const { return actions().count(); }
    00153     inline QT3_SUPPORT int insertItem(const QString &text, const QObject *receiver, const char* member,
    00154                                     const QKeySequence& shortcut = 0, int id = -1, int index = -1) {
    00155         return insertAny(0, &text, receiver, member, &shortcut, 0, id, index);
    00156     }
    00157     inline QT3_SUPPORT int insertItem(const QIcon& icon, const QString &text,
    00158                                     const QObject *receiver, const char* member,
    00159                                     const QKeySequence& shortcut = 0, int id = -1, int index = -1) {
    00160         return insertAny(&icon, &text, receiver, member, &shortcut, 0, id, index);
    00161     }
    00162     inline QT3_SUPPORT int insertItem(const QPixmap &pixmap, const QObject *receiver, const char* member,
    00163                                     const QKeySequence& shortcut = 0, int id = -1, int index = -1) {
    00164         QIcon icon(pixmap);
    00165         return insertAny(&icon, 0, receiver, member, &shortcut, 0, id, index);
    00166     }
    00167     inline QT3_SUPPORT int insertItem(const QString &text, int id=-1, int index=-1) {
    00168         return insertAny(0, &text, 0, 0, 0, 0, id, index);
    00169     }
    00170     inline QT3_SUPPORT int insertItem(const QIcon& icon, const QString &text, int id=-1, int index=-1) {
    00171         return insertAny(&icon, &text, 0, 0, 0, 0, id, index);
    00172     }
    00173     inline QT3_SUPPORT int insertItem(const QString &text, QMenu *popup, int id=-1, int index=-1) {
    00174         return insertAny(0, &text, 0, 0, 0, popup, id, index);
    00175     }
    00176     inline QT3_SUPPORT int insertItem(const QIcon& icon, const QString &text, QMenu *popup, int id=-1, int index=-1) {
    00177         return insertAny(&icon, &text, 0, 0, 0, popup, id, index);
    00178     }
    00179     inline QT3_SUPPORT int insertItem(const QPixmap &pixmap, int id=-1, int index=-1) {
    00180         QIcon icon(pixmap);
    00181         return insertAny(&icon, 0, 0, 0, 0, 0, id, index);
    00182     }
    00183     inline QT3_SUPPORT int insertItem(const QPixmap &pixmap, QMenu *popup, int id=-1, int index=-1) {
    00184         QIcon icon(pixmap);
    00185         return insertAny(&icon, 0, 0, 0, 0, popup, id, index);
    00186     }
    00187     QT3_SUPPORT int insertSeparator(int index=-1);
    00188     inline QT3_SUPPORT void removeItem(int id) {
    00189         if(QAction *act = findActionForId(id))
    00190             removeAction(act); }
    00191     inline QT3_SUPPORT void removeItemAt(int index) {
    00192         if(QAction *act = actions().value(index))
    00193             removeAction(act); }
    00194 #ifndef QT_NO_SHORTCUT
    00195     inline QT3_SUPPORT QKeySequence accel(int id) const {
    00196         if(QAction *act = findActionForId(id))
    00197             return act->shortcut();
    00198         return QKeySequence(); }
    00199     inline QT3_SUPPORT void setAccel(const QKeySequence& key, int id) {
    00200         if(QAction *act = findActionForId(id))
    00201             act->setShortcut(key);
    00202     }
    00203 #endif
    00204     inline QT3_SUPPORT QIcon iconSet(int id) const {
    00205         if(QAction *act = findActionForId(id))
    00206             return act->icon();
    00207         return QIcon(); }
    00208     inline QT3_SUPPORT QString text(int id) const {
    00209         if(QAction *act = findActionForId(id))
    00210             return act->text();
    00211         return QString(); }
    00212     inline QT3_SUPPORT QPixmap pixmap(int id) const {
    00213         if(QAction *act = findActionForId(id))
    00214             return act->icon().pixmap(QSize(22,22));
    00215         return QPixmap(); }
    00216     inline QT3_SUPPORT void setWhatsThis(int id, const QString &w) {
    00217         if(QAction *act = findActionForId(id))
    00218             act->setWhatsThis(w); }
    00219     inline QT3_SUPPORT QString whatsThis(int id) const {
    00220         if(QAction *act = findActionForId(id))
    00221             return act->whatsThis();
    00222         return QString(); }
    00223
    00224     inline QT3_SUPPORT void changeItem(int id, const QString &text) {
    00225         if(QAction *act = findActionForId(id))
    00226             act->setText(text); }
    00227     inline QT3_SUPPORT void changeItem(int id, const QPixmap &pixmap) {
    00228         if(QAction *act = findActionForId(id))
    00229             act->setIcon(QIcon(pixmap)); }
    00230     inline QT3_SUPPORT void changeItem(int id, const QIcon &icon, const QString &text) {
    00231         if(QAction *act = findActionForId(id)) {
    00232             act->setIcon(icon);
    00233             act->setText(text);
    00234         }
    00235     }
    00236     inline QT3_SUPPORT bool isItemActive(int id) const { return findActionForId(id) == activeAction(); }
    00237     inline QT3_SUPPORT bool isItemEnabled(int id) const {
    00238         if(QAction *act = findActionForId(id))
    00239             return act->isEnabled();
    00240         return false; }
    00241     inline QT3_SUPPORT void setItemEnabled(int id, bool enable) {
    00242         if(QAction *act = findActionForId(id))
    00243             act->setEnabled(enable); }
    00244     inline QT3_SUPPORT bool isItemChecked(int id) const {
    00245         if(QAction *act = findActionForId(id))
    00246             return act->isChecked();
    00247         return false; }
    00248     inline QT3_SUPPORT void setItemChecked(int id, bool check) {
    00249         if(QAction *act = findActionForId(id))
    00250             act->setChecked(check); }
    00251     inline QT3_SUPPORT bool isItemVisible(int id) const {
    00252         if(QAction *act = findActionForId(id))
    00253             return act->isVisible();
    00254         return false; }
    00255     inline QT3_SUPPORT void setItemVisible(int id, bool visible) {
    00256         if(QAction *act = findActionForId(id))
    00257             act->setVisible(visible); }
    00258     inline QT3_SUPPORT int indexOf(int id) const { return actions().indexOf(findActionForId(id)); }
    00259     inline QT3_SUPPORT int idAt(int index) const {
    00260         return index >= 0 && index < actions().size()
    00261                         ? findIdForAction(actions().at(index))
    00262                         : -1;
    00263     }
    00264     inline QT3_SUPPORT void activateItemAt(int index) {
    00265         if(QAction *ret = actions().value(index))
    00266             setActiveAction(ret);
    00267     }
    00268     inline QT3_SUPPORT bool connectItem(int id, const QObject *receiver, const char* member) {
    00269         if(QAction *act = findActionForId(id)) {
    00270             QObject::connect(act, SIGNAL(triggered()), receiver, member);
    00271             return true;
    00272         }
    00273         return false;
    00274     }
    00275     inline QT3_SUPPORT bool disconnectItem(int id,const QObject *receiver, const char* member) {
    00276         if(QAction *act = findActionForId(id)) {
    00277             QObject::disconnect(act, SIGNAL(triggered()), receiver, member);
    00278             return true;
    00279         }
    00280         return false;
    00281     }
    00282     inline QT3_SUPPORT QMenuItem *findItem(int id) const {
    00283         return (QMenuItem*)findActionForId(id);
    00284     }
    00285     QT3_SUPPORT bool setItemParameter(int id, int param);
    00286     QT3_SUPPORT int itemParameter(int id) const;
    00287
    00288     //frame
    00289     QT3_SUPPORT int frameWidth() const;
    00290
    00291     QT3_SUPPORT void setFrameRect(QRect) {}
    00292     QT3_SUPPORT QRect frameRect() const { return QRect(); }
    00293     enum DummyFrame { Box, Sunken, Plain, Raised, MShadow, NoFrame, Panel, StyledPanel,
    00294                       HLine, VLine, GroupBoxPanel, WinPanel, ToolBarPanel, MenuBarPanel,
    00295                       PopupPanel, LineEditPanel, TabWidgetPanel, MShape };
    00296     QT3_SUPPORT void setFrameShadow(DummyFrame) {}
    00297     QT3_SUPPORT DummyFrame frameShadow() const { return Plain; }
    00298     QT3_SUPPORT void setFrameShape(DummyFrame) {}
    00299     QT3_SUPPORT DummyFrame frameShape() const { return NoFrame; }
    00300     QT3_SUPPORT void setFrameStyle(int) {}
    00301     QT3_SUPPORT int frameStyle() const  { return 0; }
    00302     QT3_SUPPORT void setLineWidth(int) {}
    00303     QT3_SUPPORT int lineWidth() const { return 0; }
    00304     QT3_SUPPORT void setMargin(int margin) { setContentsMargins(margin, margin, margin, margin); }
    00305     QT3_SUPPORT int margin() const
    00306     { int margin; int dummy; getContentsMargins(&margin, &dummy, &dummy, &dummy);  return margin; }
    00307     QT3_SUPPORT void setMidLineWidth(int) {}
    00308     QT3_SUPPORT int midLineWidth() const { return 0; }
    00309
    00310     //menubar
    00311     enum Separator { Never=0, InWindowsStyle=1 };
    00312     inline QT3_SUPPORT Separator separator() const { return InWindowsStyle; }
    00313     inline QT3_SUPPORT void setSeparator(Separator) { }
    00314
    00315     QT3_SUPPORT void setAutoGeometry(bool);
    00316     QT3_SUPPORT bool autoGeometry() const;
    00317
    00318 Q_SIGNALS:
    00319     QT_MOC_COMPAT void activated(int itemId);
    00320     QT_MOC_COMPAT void highlighted(int itemId);
    00321
    00322 protected:
    00323     inline QT3_SUPPORT QRect itemRect(int index) {
    00324         if(QAction *act = actions().value(index))
    00325             return actionGeometry(act);
    00326         return QRect();
    00327     }
    00328     inline QT3_SUPPORT int itemAtPos(const QPoint &p) {
    00329         return findIdForAction(actionAt(p));
    00330     }
    00331 private:
    00332     QAction *findActionForId(int id) const;
    00333     int insertAny(const QIcon *icon, const QString *text, const QObject *receiver, const char *member,
    00334                   const QKeySequence *shorcut, const QMenu *popup, int id, int index);
    00335     int findIdForAction(QAction*) const;
    00336 #endif
    00337
    00338 private:
    00339     Q_DECLARE_PRIVATE(QMenuBar)
    00340     Q_DISABLE_COPY(QMenuBar)
    00341     Q_PRIVATE_SLOT(d_func(), void _q_actionTriggered())
    00342     Q_PRIVATE_SLOT(d_func(), void _q_actionHovered())
    00343     Q_PRIVATE_SLOT(d_func(), void _q_internalShortcutActivated(int))
    00344     Q_PRIVATE_SLOT(d_func(), void _q_updateLayout())
    00345
    00346 #ifdef Q_WS_WINCE
    00347     Q_PRIVATE_SLOT(d_func(), void _q_updateDefaultAction())
    00348 #endif
    00349
    00350     friend class QMenu;
    00351     friend class QMenuPrivate;
    00352     friend class QWindowsStyle;
    00353
    00354 #ifdef Q_WS_MAC
    00355     friend class QApplicationPrivate;
    00356     friend class QWidgetPrivate;
    00357     friend bool qt_mac_activate_action(MenuRef, uint, QAction::ActionEvent, bool);
    00358 #endif
    00359 };
    00360
    00361 #endif // QT_NO_MENUBAR
    00362
    00363 QT_END_NAMESPACE
    00364
    00365 QT_END_HEADER
    00366
    00367 #endif // QMENUBAR_H