1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
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>
62 class QGraphicsWidget;
64 class Q_WIDGETS_EXPORT QAction : public QObject
67 Q_DECLARE_PRIVATE(QAction)
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)
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)
94 enum MenuRole { NoRole, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole,
95 AboutRole, PreferencesRole, QuitRole };
97 NoSoftKey, PositiveSoftKey, NegativeSoftKey, SelectSoftKey };
98 enum Priority { LowPriority = 0,
101 explicit QAction(QObject* parent);
102 QAction(const QString &text, QObject* parent);
103 QAction(const QIcon &icon, const QString &text, QObject* parent);
107 void setActionGroup(QActionGroup *group);
108 QActionGroup *actionGroup() const;
109 void setIcon(const QIcon &icon);
112 void setText(const QString &text);
113 QString text() const;
115 void setIconText(const QString &text);
116 QString iconText() const;
118 void setToolTip(const QString &tip);
119 QString toolTip() const;
121 void setStatusTip(const QString &statusTip);
122 QString statusTip() const;
124 void setWhatsThis(const QString &what);
125 QString whatsThis() const;
127 void setPriority(Priority priority);
128 Priority priority() const;
132 void setMenu(QMenu *menu);
135 void setSeparator(bool b);
136 bool isSeparator() const;
138 #ifndef QT_NO_SHORTCUT
139 void setShortcut(const QKeySequence &shortcut);
140 QKeySequence shortcut() const;
142 void setShortcuts(const QList<QKeySequence> &shortcuts);
143 void setShortcuts(QKeySequence::StandardKey);
144 QList<QKeySequence> shortcuts() const;
146 void setShortcutContext(Qt::ShortcutContext context);
147 Qt::ShortcutContext shortcutContext() const;
149 void setAutoRepeat(bool);
150 bool autoRepeat() const;
153 void setFont(const QFont &font);
156 void setCheckable(bool);
157 bool isCheckable() const;
159 QVariant data() const;
160 void setData(const QVariant &var);
162 bool isChecked() const;
164 bool isEnabled() const;
166 bool isVisible() const;
168 enum ActionEvent { Trigger, Hover };
169 void activate(ActionEvent event);
170 bool showStatusText(QWidget *widget=0);
172 void setMenuRole(MenuRole menuRole);
173 MenuRole menuRole() const;
175 void setSoftKeyRole(SoftKeyRole softKeyRole);
176 SoftKeyRole softKeyRole() const;
178 void setIconVisibleInMenu(bool visible);
179 bool isIconVisibleInMenu() const;
182 QWidget *parentWidget() const;
184 QList<QWidget *> associatedWidgets() const;
185 #ifndef QT_NO_GRAPHICSVIEW
186 QList<QGraphicsWidget *> associatedGraphicsWidgets() const; // ### suboptimal
190 bool event(QEvent *);
191 QAction(QActionPrivate &dd, QObject *parent);
194 void trigger() { activate(Trigger); }
195 void hover() { activate(Hover); }
196 void setChecked(bool);
198 void setEnabled(bool);
199 inline void setDisabled(bool b) { setEnabled(!b); }
200 void setVisible(bool);
204 void triggered(bool checked = false);
209 Q_DISABLE_COPY(QAction)
211 friend class QGraphicsWidget;
212 friend class QWidget;
213 friend class QActionGroup;
215 friend class QMenuPrivate;
216 friend class QMenuBar;
217 friend class QToolButton;
219 friend void qt_mac_clear_status_text(QAction *action);
223 QT_BEGIN_INCLUDE_NAMESPACE
224 #include <QtWidgets/qactiongroup.h>
225 QT_END_INCLUDE_NAMESPACE
227 #endif // QT_NO_ACTION