source: trunk/src/gui/kernel/qaction.h@ 858

Last change on this file since 858 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 8.8 KB
RevLine 
[2]1/****************************************************************************
2**
[846]3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
[561]4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
[2]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**
[561]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.
[2]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**
[561]36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
[2]38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QACTION_H
43#define QACTION_H
44
45#include <QtGui/qkeysequence.h>
46#include <QtCore/qstring.h>
47#include <QtGui/qwidget.h>
48#include <QtCore/qvariant.h>
49#include <QtGui/qicon.h>
50
51QT_BEGIN_HEADER
52
53QT_BEGIN_NAMESPACE
54
55QT_MODULE(Gui)
56
57#ifndef QT_NO_ACTION
58
59class QMenu;
60class QActionGroup;
61class QActionPrivate;
62class QGraphicsWidget;
63
64class Q_GUI_EXPORT QAction : public QObject
65{
66 Q_OBJECT
67 Q_DECLARE_PRIVATE(QAction)
68
69 Q_ENUMS(MenuRole)
[561]70 Q_ENUMS(SoftKeyRole)
71 Q_ENUMS(Priority)
72 Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY changed)
[2]73 Q_PROPERTY(bool checked READ isChecked WRITE setChecked DESIGNABLE isCheckable NOTIFY toggled)
[561]74 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY changed)
75 Q_PROPERTY(QIcon icon READ icon WRITE setIcon NOTIFY changed)
76 Q_PROPERTY(QString text READ text WRITE setText NOTIFY changed)
77 Q_PROPERTY(QString iconText READ iconText WRITE setIconText NOTIFY changed)
78 Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip NOTIFY changed)
79 Q_PROPERTY(QString statusTip READ statusTip WRITE setStatusTip NOTIFY changed)
80 Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis NOTIFY changed)
81 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY changed)
[2]82#ifndef QT_NO_SHORTCUT
[561]83 Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut NOTIFY changed)
84 Q_PROPERTY(Qt::ShortcutContext shortcutContext READ shortcutContext WRITE setShortcutContext NOTIFY changed)
85 Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat NOTIFY changed)
[2]86#endif
[561]87 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY changed)
88 Q_PROPERTY(MenuRole menuRole READ menuRole WRITE setMenuRole NOTIFY changed)
89 Q_PROPERTY(SoftKeyRole softKeyRole READ softKeyRole WRITE setSoftKeyRole NOTIFY changed)
90 Q_PROPERTY(bool iconVisibleInMenu READ isIconVisibleInMenu WRITE setIconVisibleInMenu NOTIFY changed)
91 Q_PROPERTY(Priority priority READ priority WRITE setPriority)
[2]92
93public:
94 enum MenuRole { NoRole, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole,
95 AboutRole, PreferencesRole, QuitRole };
[561]96 enum SoftKeyRole {
97 NoSoftKey, PositiveSoftKey, NegativeSoftKey, SelectSoftKey };
98 enum Priority { LowPriority = 0,
99 NormalPriority = 128,
100 HighPriority = 256};
[2]101 explicit QAction(QObject* parent);
102 QAction(const QString &text, QObject* parent);
103 QAction(const QIcon &icon, const QString &text, QObject* parent);
104
105#ifdef QT3_SUPPORT
106 QT3_SUPPORT_CONSTRUCTOR QAction(QObject* parent, const char* name);
107 QT3_SUPPORT_CONSTRUCTOR QAction(const QString &text, const QKeySequence &shortcut,
108 QObject* parent, const char* name);
109 QT3_SUPPORT_CONSTRUCTOR QAction(const QIcon &icon, const QString &text,
110 const QKeySequence &shortcut,
111 QObject* parent, const char* name);
112#endif
113 ~QAction();
114
115 void setActionGroup(QActionGroup *group);
116 QActionGroup *actionGroup() const;
117 void setIcon(const QIcon &icon);
118 QIcon icon() const;
119
120 void setText(const QString &text);
121 QString text() const;
122
123 void setIconText(const QString &text);
124 QString iconText() const;
125
126 void setToolTip(const QString &tip);
127 QString toolTip() const;
128
129 void setStatusTip(const QString &statusTip);
130 QString statusTip() const;
131
132 void setWhatsThis(const QString &what);
133 QString whatsThis() const;
134
[561]135 void setPriority(Priority priority);
136 Priority priority() const;
137
[2]138#ifndef QT_NO_MENU
139 QMenu *menu() const;
140 void setMenu(QMenu *menu);
141#endif
142
143 void setSeparator(bool b);
144 bool isSeparator() const;
145
146#ifndef QT_NO_SHORTCUT
147 void setShortcut(const QKeySequence &shortcut);
148 QKeySequence shortcut() const;
149
150 void setShortcuts(const QList<QKeySequence> &shortcuts);
151 void setShortcuts(QKeySequence::StandardKey);
152 QList<QKeySequence> shortcuts() const;
153
154 void setShortcutContext(Qt::ShortcutContext context);
155 Qt::ShortcutContext shortcutContext() const;
156
157 void setAutoRepeat(bool);
158 bool autoRepeat() const;
159#endif
160
161 void setFont(const QFont &font);
162 QFont font() const;
163
164 void setCheckable(bool);
165 bool isCheckable() const;
166
167 QVariant data() const;
168 void setData(const QVariant &var);
169
170 bool isChecked() const;
171
172 bool isEnabled() const;
173
174 bool isVisible() const;
175
176 enum ActionEvent { Trigger, Hover };
177 void activate(ActionEvent event);
178 bool showStatusText(QWidget *widget=0);
179
180 void setMenuRole(MenuRole menuRole);
181 MenuRole menuRole() const;
182
[561]183 void setSoftKeyRole(SoftKeyRole softKeyRole);
184 SoftKeyRole softKeyRole() const;
185
[2]186 void setIconVisibleInMenu(bool visible);
187 bool isIconVisibleInMenu() const;
188
189#ifdef QT3_SUPPORT
190 inline QT3_SUPPORT void setMenuText(const QString &text) { setText(text); }
191 inline QT3_SUPPORT QString menuText() const { return text(); }
192 inline QT3_SUPPORT bool isOn() const { return isChecked(); }
193 inline QT3_SUPPORT bool isToggleAction() const { return isCheckable(); }
194 inline QT3_SUPPORT void setToggleAction(bool b) { setCheckable(b); }
195 inline QT3_SUPPORT void setIconSet(const QIcon &i) { setIcon(i); }
196 inline QT3_SUPPORT QIcon iconSet() const { return icon(); }
197 inline QT3_SUPPORT bool addTo(QWidget *w) { w->addAction(this); return true; }
198 inline QT3_SUPPORT bool removeFrom(QWidget *w) { w->removeAction(this); return true; }
199 inline QT3_SUPPORT void setAccel(const QKeySequence &shortcut) { setShortcut(shortcut); }
200 inline QT3_SUPPORT QKeySequence accel() const { return shortcut(); }
201#endif
202
203 QWidget *parentWidget() const;
204
205 QList<QWidget *> associatedWidgets() const;
206#ifndef QT_NO_GRAPHICSVIEW
207 QList<QGraphicsWidget *> associatedGraphicsWidgets() const; // ### suboptimal
208#endif
209
210protected:
211 bool event(QEvent *);
212 QAction(QActionPrivate &dd, QObject *parent);
213
214public Q_SLOTS:
215#ifdef QT3_SUPPORT
216 inline QT_MOC_COMPAT void setOn(bool b) { setChecked(b); }
217#endif
218 void trigger() { activate(Trigger); }
219 void hover() { activate(Hover); }
220 void setChecked(bool);
221 void toggle();
222 void setEnabled(bool);
223 inline void setDisabled(bool b) { setEnabled(!b); }
224 void setVisible(bool);
225
226Q_SIGNALS:
227 void changed();
228 void triggered(bool checked = false);
229 void hovered();
230 void toggled(bool);
231#ifdef QT3_SUPPORT
232 QT_MOC_COMPAT void activated(int = 0);
233#endif
234
235private:
236 Q_DISABLE_COPY(QAction)
237
238#ifdef QT3_SUPPORT
239 friend class QMenuItem;
240#endif
241 friend class QGraphicsWidget;
242 friend class QWidget;
243 friend class QActionGroup;
244 friend class QMenu;
245 friend class QMenuPrivate;
246 friend class QMenuBar;
247 friend class QShortcutMap;
248 friend class QToolButton;
[846]249#ifdef Q_WS_MAC
250 friend void qt_mac_clear_status_text(QAction *action);
251#endif
[2]252};
253
254QT_BEGIN_INCLUDE_NAMESPACE
255#include <QtGui/qactiongroup.h>
256QT_END_INCLUDE_NAMESPACE
257
258#endif // QT_NO_ACTION
259
260QT_END_NAMESPACE
261
262QT_END_HEADER
263
264#endif // QACTION_H
Note: See TracBrowser for help on using the repository browser.