source: trunk/src/gui/widgets/qmenu.h@ 332

Last change on this file since 332 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 15.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
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 [email protected].
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
54QT_BEGIN_HEADER
55
56QT_BEGIN_NAMESPACE
57
58QT_MODULE(Gui)
59
60#ifndef QT_NO_MENU
61
62class QMenuPrivate;
63class QStyleOptionMenuItem;
64#ifdef QT3_SUPPORT
65class QMenuItem;
66#endif
67
68class Q_GUI_EXPORT QMenu : public QWidget
69{
70private:
71 Q_OBJECT
72 Q_DECLARE_PRIVATE(QMenu)
73
74 Q_PROPERTY(bool tearOffEnabled READ isTearOffEnabled WRITE setTearOffEnabled)
75 Q_PROPERTY(QString title READ title WRITE setTitle)
76 Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
77 Q_PROPERTY(bool separatorsCollapsible READ separatorsCollapsible WRITE setSeparatorsCollapsible)
78
79public:
80 explicit QMenu(QWidget *parent = 0);
81 explicit QMenu(const QString &title, QWidget *parent = 0);
82 ~QMenu();
83
84#ifdef Q_NO_USING_KEYWORD
85 inline void addAction(QAction *action) { QWidget::addAction(action); }
86#else
87 using QWidget::addAction;
88#endif
89 QAction *addAction(const QString &text);
90 QAction *addAction(const QIcon &icon, const QString &text);
91 QAction *addAction(const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0);
92 QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0);
93
94 QAction *addMenu(QMenu *menu);
95 QMenu *addMenu(const QString &title);
96 QMenu *addMenu(const QIcon &icon, const QString &title);
97
98 QAction *addSeparator();
99
100 QAction *insertMenu(QAction *before, QMenu *menu);
101 QAction *insertSeparator(QAction *before);
102
103 bool isEmpty() const;
104 void clear();
105
106 void setTearOffEnabled(bool);
107 bool isTearOffEnabled() const;
108
109 bool isTearOffMenuVisible() const;
110 void hideTearOffMenu();
111
112 void setDefaultAction(QAction *);
113 QAction *defaultAction() const;
114
115 void setActiveAction(QAction *act);
116 QAction *activeAction() const;
117
118 void popup(const QPoint &pos, QAction *at=0);
119 QAction *exec();
120 QAction *exec(const QPoint &pos, QAction *at=0);
121
122 // ### Qt 5: merge
123 static QAction *exec(QList<QAction*> actions, const QPoint &pos, QAction *at=0);
124 static QAction *exec(QList<QAction*> actions, const QPoint &pos, QAction *at, QWidget *parent);
125
126 QSize sizeHint() const;
127
128 QRect actionGeometry(QAction *) const;
129 QAction *actionAt(const QPoint &) const;
130
131 QAction *menuAction() const;
132
133 QString title() const;
134 void setTitle(const QString &title);
135
136 QIcon icon() const;
137 void setIcon(const QIcon &icon);
138
139 void setNoReplayFor(QWidget *widget);
140#ifdef Q_WS_MAC
141 OSMenuRef macMenu(OSMenuRef merge=0);