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

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

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

File size: 8.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 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)
70 Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable)
71 Q_PROPERTY(bool checked READ isChecked WRITE setChecked DESIGNABLE isCheckable NOTIFY toggled)
72 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
73 Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
74 Q_PROPERTY(QString text READ text WRITE setText)
75 Q_PROPERTY(QString iconText READ iconText WRITE setIconText)
76 Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip)
77 Q_PROPERTY(QString statusTip READ statusTip WRITE setStatusTip)
78 Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis)
79 Q_PROPERTY(QFont font READ font WRITE setFont)
80#ifndef QT_NO_SHORTCUT
81 Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut)
82 Q_PROPERTY(Qt::ShortcutContext shortcutContext READ shortcutContext WRITE setShortcutContext)
83 Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat)
84#endif
85 Q_PROPERTY(bool visible READ isVisible WRITE setVisible)
86 Q_PROPERTY(MenuRole menuRole READ menuRole WRITE setMenuRole)
87 Q_PROPERTY(bool iconVisibleInMenu READ isIconVisibleInMenu WRITE setIconVisibleInMenu)
88
89public:
90 enum MenuRole { NoRole, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole,
91 AboutRole, PreferencesRole, QuitRole };
92 explicit QAction(QObject* parent);
93 QAction(const QString &text, QObject* parent);
94 QAction(const QIcon &icon, const QString &text, QObject* parent);
95
96#ifdef QT3_SUPPORT
97 QT3_SUPPORT_CONSTRUCTOR QAction(QObject* parent, const char* name);
98 QT3_SUPPORT_CONSTRUCTOR QAction(const QString &text, const QKeySequence &shortcut,
99 QObject* parent, const char* name);
100 QT3_SUPPORT_CONSTRUCTOR QAction(const QIcon &icon, const QString &text,
101 const QKeySequence &shortcut,
102 QObject* parent, const char* name);
103#endif
104 ~QAction();
105
106 void setActionGroup(QActionGroup *group);
107 QActionGroup *actionGroup() const;
108 void setIcon(const QIcon &icon);
109 QIcon icon() const;
110
111 void setText(const QString &text);
112 QString text() const;
113
114 void setIconText(const QString &text);
115 QString iconText() const;
116
117 void setToolTip(const QString &tip);
118 QString toolTip() const;
119
120 void setStatusTip(const QString &statusTip);
121 QString statusTip() const;
122
123 void setWhatsThis(const QString &what);
124 QString whatsThis() const;
125
126#ifndef QT_NO_MENU
127 QMenu *menu() const;
128 void setMenu(QMenu *menu);
129#endif
130
131 void setSeparator(bool b);
132 bool isSeparator() const;
133
134#ifndef QT_NO_SHORTCUT
135 void setShortcut(const QKeySequence &shortcut);
136 QKeySequence shortcut() const;
137
138 void setShortcuts(const QList<QKeySequence> &shortcuts);
139 void setShortcuts(QKeySequence::StandardKey);
140 QList<QKeySequence> shortcuts() const;
141
142 void setShortcutContext(Qt::ShortcutContext context);
143 Qt::ShortcutContext shortcutContext() const;
144
145 void setAutoRepeat(bool);
146 bool autoRepeat() const;
147#endif
148
149 void setFont(const QFont &font);
150 QFont font() const;
151
152 void setCheckable(bool);
153 bool isCheckable() const;
154
155 QVariant data() const;
156 void setData(const QVariant &var);
157
158 bool isChecked() const;
159
160 bool isEnabled() const;
161
162 bool isVisible() const;
163
164 enum ActionEvent { Trigger, Hover };
165 void activate(ActionEvent event);
166 bool showStatusText(QWidget *widget=0);
167
168 void setMenuRole(MenuRole menuRole);
169 MenuRole menuRole() const;
170
171 void setIconVisibleInMenu(bool visible);
172 bool isIconVisibleInMenu() const;
173
174#ifdef QT3_SUPPORT
175 inline QT3_SUPPORT void setMenuText(const QString &text) { setText(text); }
176 inline QT3_SUPPORT QString menuText() const { return text(); }
177 inline QT3_SUPPORT bool isOn() const { return isChecked(); }
178 inline QT3_SUPPORT bool isToggleAction() const { return isCheckable(); }
179 inline QT3_SUPPORT void setToggleAction(bool b) { setCheckable(b); }
180 inline QT3_SUPPORT void setIconSet(const QIcon &i) { setIcon(i); }
181 inline QT3_SUPPORT QIcon iconSet() const { return icon(); }
182 inline QT3_SUPPORT bool addTo(QWidget *w) { w->addAction(this); return true; }
183 inline QT3_SUPPORT bool removeFrom(QWidget *w) { w->removeAction(this); return true; }
184 inline QT3_SUPPORT void setAccel(const QKeySequence &shortcut) { setShortcut(shortcut); }
185 inline QT3_SUPPORT QKeySequence accel() const { return shortcut(); }
186#endif
187
188 QWidget *parentWidget() const;
189
190 QList<QWidget *> associatedWidgets() const;
191#ifndef QT_NO_GRAPHICSVIEW
192 QList<QGraphicsWidget *> associatedGraphicsWidgets() const; // ### suboptimal
193#endif
194
195protected:
196 bool event(QEvent *);
197 QAction(QActionPrivate &dd, QObject *parent);
198
199public Q_SLOTS:
200#ifdef QT3_SUPPORT
201 inline QT_MOC_COMPAT void setOn(bool b) { setChecked(b); }
202#endif
203 void trigger() { activate(Trigger); }
204 void hover() { activate(Hover); }
205 void setChecked(bool);
206 void toggle();
207 void setEnabled(bool);
208 inline void setDisabled(bool b) { setEnabled(!b); }
209 void setVisible(bool);
210
211Q_SIGNALS:
212 void changed();
213 void triggered(bool checked = false);
214 void hovered();
215 void toggled(bool);
216#ifdef QT3_SUPPORT
217 QT_MOC_COMPAT void activated(int = 0);
218#endif
219
220private:
221 Q_DISABLE_COPY(QAction)
222
223#ifdef QT3_SUPPORT
224 friend class QMenuItem;
225#endif
226 friend class QGraphicsWidget;
227 friend class QWidget;
228 friend class QActionGroup;
229 friend class QMenu;
230 friend class QMenuPrivate;
231 friend class QMenuBar;
232 friend class QShortcutMap;
233 friend class QToolButton;
234};
235
236QT_BEGIN_INCLUDE_NAMESPACE
237#include <QtGui/qactiongroup.h>
238QT_END_INCLUDE_NAMESPACE
239
240#endif // QT_NO_ACTION
241
242QT_END_NAMESPACE
243
244QT_END_HEADER
245
246#endif // QACTION_H
Note: See TracBrowser for help on using the repository browser.