Remove dependencies of QShortcutMap onto widgets
[profile/ivi/qtbase.git] / src / widgets / kernel / qaction.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtGui module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
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 <QtWidgets/qwidget.h>
48 #include <QtCore/qvariant.h>
49 #include <QtWidgets/qicon.h>
50
51 QT_BEGIN_HEADER
52
53 QT_BEGIN_NAMESPACE
54
55 QT_MODULE(Gui)
56
57 #ifndef QT_NO_ACTION
58
59 class QMenu;
60 class QActionGroup;
61 class QActionPrivate;
62 class QGraphicsWidget;
63
64 class Q_WIDGETS_EXPORT QAction : public QObject
65 {
66     Q_OBJECT
67     Q_DECLARE_PRIVATE(QAction)
68
69     Q_ENUMS(MenuRole)
70     Q_ENUMS(SoftKeyRole)
71     Q_ENUMS(Priority)
72     Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY changed)
73     Q_PROPERTY(bool checked READ isChecked WRITE setChecked DESIGNABLE isCheckable NOTIFY toggled)
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)
82 #ifndef QT_NO_SHORTCUT
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)
86 #endif
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)
92
93 public:
94     enum MenuRole { NoRole, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole,
95                     AboutRole, PreferencesRole, QuitRole };
96     enum SoftKeyRole {
97                     NoSoftKey, PositiveSoftKey, NegativeSoftKey, SelectSoftKey };
98     enum Priority { LowPriority = 0,
99                     NormalPriority = 128,
100                     HighPriority = 256};
101     explicit QAction(QObject* parent);
102     QAction(const QString &text, QObject* parent);
103     QAction(const QIcon &icon, const QString &text, QObject* parent);
104
105     ~QAction();
106
107     void setActionGroup(QActionGroup *group);
108     QActionGroup *actionGroup() const;
109     void setIcon(const QIcon &icon);
110     QIcon icon() const;
111
112     void setText(const QString &text);
113     QString text() const;
114
115     void setIconText(const QString &text);
116     QString iconText() const;
117
118     void setToolTip(const QString &tip);
119     QString toolTip() const;
120
121     void setStatusTip(const QString &statusTip);
122     QString statusTip() const;
123
124     void setWhatsThis(const QString &what);
125     QString whatsThis() const;
126
127     void setPriority(Priority priority);
128     Priority priority() const;
129
130 #ifndef QT_NO_MENU
131     QMenu *menu() const;
132     void setMenu(QMenu *menu);
133 #endif
134
135     void setSeparator(bool b);
136     bool isSeparator() const;
137
138 #ifndef QT_NO_SHORTCUT
139     void setShortcut(const QKeySequence &shortcut);
140     QKeySequence shortcut() const;
141
142     void setShortcuts(const QList<QKeySequence> &shortcuts);
143     void setShortcuts(QKeySequence::StandardKey);
144     QList<QKeySequence> shortcuts() const;
145
146     void setShortcutContext(Qt::ShortcutContext context);
147     Qt::ShortcutContext shortcutContext() const;
148
149     void setAutoRepeat(bool);
150     bool autoRepeat() const;
151 #endif
152
153     void setFont(const QFont &font);
154     QFont font() const;
155
156     void setCheckable(bool);
157     bool isCheckable() const;
158
159     QVariant data() const;
160     void setData(const QVariant &var);
161
162     bool isChecked() const;
163
164     bool isEnabled() const;
165
166     bool isVisible() const;
167
168     enum ActionEvent { Trigger, Hover };
169     void activate(ActionEvent event);
170     bool showStatusText(QWidget *widget=0);
171
172     void setMenuRole(MenuRole menuRole);
173     MenuRole menuRole() const;
174
175     void setSoftKeyRole(SoftKeyRole softKeyRole);
176     SoftKeyRole softKeyRole() const;
177
178     void setIconVisibleInMenu(bool visible);
179     bool isIconVisibleInMenu() const;
180
181
182     QWidget *parentWidget() const;
183
184     QList<QWidget *> associatedWidgets() const;
185 #ifndef QT_NO_GRAPHICSVIEW
186     QList<QGraphicsWidget *> associatedGraphicsWidgets() const; // ### suboptimal
187 #endif
188
189 protected:
190     bool event(QEvent *);
191     QAction(QActionPrivate &dd, QObject *parent);
192
193 public Q_SLOTS:
194     void trigger() { activate(Trigger); }
195     void hover() { activate(Hover); }
196     void setChecked(bool);
197     void toggle();
198     void setEnabled(bool);
199     inline void setDisabled(bool b) { setEnabled(!b); }
200     void setVisible(bool);
201
202 Q_SIGNALS:
203     void changed();
204     void triggered(bool checked = false);
205     void hovered();
206     void toggled(bool);
207
208 private:
209     Q_DISABLE_COPY(QAction)
210
211     friend class QGraphicsWidget;
212     friend class QWidget;
213     friend class QActionGroup;
214     friend class QMenu;
215     friend class QMenuPrivate;
216     friend class QMenuBar;
217     friend class QToolButton;
218 #ifdef Q_OS_MAC
219     friend void qt_mac_clear_status_text(QAction *action);
220 #endif
221 };
222
223 QT_BEGIN_INCLUDE_NAMESPACE
224 #include <QtWidgets/qactiongroup.h>
225 QT_END_INCLUDE_NAMESPACE
226
227 #endif // QT_NO_ACTION
228
229 QT_END_NAMESPACE
230
231 QT_END_HEADER
232
233 #endif // QACTION_H