- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qaction.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtGui module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QACTION_H
    00043 #define QACTION_H
    00044
    00045 #include <QtGui/qkeysequence.h>
    00046 #include <QtCore/qstring.h>
    00047 #include <QtGui/qwidget.h>
    00048 #include <QtCore/qvariant.h>
    00049 #include <QtGui/qicon.h>
    00050
    00051 QT_BEGIN_HEADER
    00052
    00053 QT_BEGIN_NAMESPACE
    00054
    00055 QT_MODULE(Gui)
    00056
    00057 #ifndef QT_NO_ACTION
    00058
    00059 class QMenu;
    00060 class QActionGroup;
    00061 class QActionPrivate;
    00062 class QGraphicsWidget;
    00063
    00064 class Q_GUI_EXPORT QAction : public QObject
    00065 {
    00066     Q_OBJECT
    00067     Q_DECLARE_PRIVATE(QAction)
    00068
    00069     Q_ENUMS(MenuRole)
    00070     Q_ENUMS(SoftKeyRole)
    00071     Q_ENUMS(Priority)
    00072     Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY changed)
    00073     Q_PROPERTY(bool checked READ isChecked WRITE setChecked DESIGNABLE isCheckable NOTIFY toggled)
    00074     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY changed)
    00075     Q_PROPERTY(QIcon icon READ icon WRITE setIcon NOTIFY changed)
    00076     Q_PROPERTY(QString text READ text WRITE setText NOTIFY changed)
    00077     Q_PROPERTY(QString iconText READ iconText WRITE setIconText NOTIFY changed)
    00078     Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip NOTIFY changed)
    00079     Q_PROPERTY(QString statusTip READ statusTip WRITE setStatusTip NOTIFY changed)
    00080     Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis NOTIFY changed)
    00081     Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY changed)
    00082 #ifndef QT_NO_SHORTCUT
    00083     Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut NOTIFY changed)
    00084     Q_PROPERTY(Qt::ShortcutContext shortcutContext READ shortcutContext WRITE setShortcutContext NOTIFY changed)
    00085     Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat NOTIFY changed)
    00086 #endif
    00087     Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY changed)
    00088     Q_PROPERTY(MenuRole menuRole READ menuRole WRITE setMenuRole NOTIFY changed)
    00089     Q_PROPERTY(SoftKeyRole softKeyRole READ softKeyRole WRITE setSoftKeyRole NOTIFY changed)
    00090     Q_PROPERTY(bool iconVisibleInMenu READ isIconVisibleInMenu WRITE setIconVisibleInMenu NOTIFY changed)
    00091     Q_PROPERTY(Priority priority READ priority WRITE setPriority)
    00092
    00093 public:
    00094     enum MenuRole { NoRole, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole,
    00095                     AboutRole, PreferencesRole, QuitRole };
    00096     enum SoftKeyRole {
    00097                     NoSoftKey, PositiveSoftKey, NegativeSoftKey, SelectSoftKey };
    00098     enum Priority { LowPriority = 0,
    00099                     NormalPriority = 128,
    00100                     HighPriority = 256};
    00101     explicit QAction(QObject* parent);
    00102     QAction(const QString &text, QObject* parent);
    00103     QAction(const QIcon &icon, const QString &text, QObject* parent);
    00104
    00105 #ifdef QT3_SUPPORT
    00106     QT3_SUPPORT_CONSTRUCTOR QAction(QObject* parent, const char* name);
    00107     QT3_SUPPORT_CONSTRUCTOR QAction(const QString &text, const QKeySequence &shortcut,
    00108                                     QObject* parent, const char* name);
    00109     QT3_SUPPORT_CONSTRUCTOR QAction(const QIcon &icon, const QString &text,
    00110                                     const QKeySequence &shortcut,
    00111                                     QObject* parent, const char* name);
    00112 #endif
    00113     ~QAction();
    00114
    00115     void setActionGroup(QActionGroup *group);
    00116     QActionGroup *actionGroup() const;
    00117     void setIcon(const QIcon &icon);
    00118     QIcon icon() const;
    00119
    00120     void setText(const QString &text);
    00121     QString text() const;
    00122
    00123     void setIconText(const QString &text);
    00124     QString iconText() const;
    00125
    00126     void setToolTip(const QString &tip);
    00127     QString toolTip() const;
    00128
    00129     void setStatusTip(const QString &statusTip);
    00130     QString statusTip() const;
    00131
    00132     void setWhatsThis(const QString &what);
    00133     QString whatsThis() const;
    00134
    00135     void setPriority(Priority priority);
    00136     Priority priority() const;
    00137
    00138 #ifndef QT_NO_MENU
    00139     QMenu *menu() const;
    00140     void setMenu(QMenu *menu);
    00141 #endif
    00142
    00143     void setSeparator(bool b);
    00144     bool isSeparator() const;
    00145
    00146 #ifndef QT_NO_SHORTCUT
    00147     void setShortcut(const QKeySequence &shortcut);
    00148     QKeySequence shortcut() const;
    00149
    00150     void setShortcuts(const QList<QKeySequence> &shortcuts);
    00151     void setShortcuts(QKeySequence::StandardKey);
    00152     QList<QKeySequence> shortcuts() const;
    00153
    00154     void setShortcutContext(Qt::ShortcutContext context);
    00155     Qt::ShortcutContext shortcutContext() const;
    00156
    00157     void setAutoRepeat(bool);
    00158     bool autoRepeat() const;
    00159 #endif
    00160
    00161     void setFont(const QFont &font);
    00162     QFont font() const;
    00163
    00164     void setCheckable(bool);
    00165     bool isCheckable() const;
    00166
    00167     QVariant data() const;
    00168     void setData(const QVariant &var);
    00169
    00170     bool isChecked() const;
    00171
    00172     bool isEnabled() const;
    00173
    00174     bool isVisible() const;
    00175
    00176     enum ActionEvent { Trigger, Hover };
    00177     void activate(ActionEvent event);
    00178     bool showStatusText(QWidget *widget=0);
    00179
    00180     void setMenuRole(MenuRole menuRole);
    00181     MenuRole menuRole() const;
    00182
    00183     void setSoftKeyRole(SoftKeyRole softKeyRole);
    00184     SoftKeyRole softKeyRole() const;
    00185
    00186     void setIconVisibleInMenu(bool visible);
    00187     bool isIconVisibleInMenu() const;
    00188
    00189 #ifdef QT3_SUPPORT
    00190     inline QT3_SUPPORT void setMenuText(const QString &text) { setText(text); }
    00191     inline QT3_SUPPORT QString menuText() const { return text(); }
    00192     inline QT3_SUPPORT bool isOn() const { return isChecked(); }
    00193     inline QT3_SUPPORT bool isToggleAction() const { return isCheckable(); }
    00194     inline QT3_SUPPORT void setToggleAction(bool b) { setCheckable(b); }
    00195     inline QT3_SUPPORT void setIconSet(const QIcon &i) { setIcon(i); }
    00196     inline QT3_SUPPORT QIcon iconSet() const { return icon(); }
    00197     inline QT3_SUPPORT bool addTo(QWidget *w) { w->addAction(this); return true; }
    00198     inline QT3_SUPPORT bool removeFrom(QWidget *w) { w->removeAction(this); return true; }
    00199     inline QT3_SUPPORT void setAccel(const QKeySequence &shortcut) { setShortcut(shortcut); }
    00200     inline QT3_SUPPORT QKeySequence accel() const { return shortcut(); }
    00201 #endif
    00202
    00203     QWidget *parentWidget() const;
    00204
    00205     QList<QWidget *> associatedWidgets() const;
    00206 #ifndef QT_NO_GRAPHICSVIEW
    00207     QList<QGraphicsWidget *> associatedGraphicsWidgets() const; // ### suboptimal
    00208 #endif
    00209
    00210 protected:
    00211     bool event(QEvent *);
    00212     QAction(QActionPrivate &dd, QObject *parent);
    00213
    00214 public Q_SLOTS:
    00215 #ifdef QT3_SUPPORT
    00216     inline QT_MOC_COMPAT void setOn(bool b) { setChecked(b); }
    00217 #endif
    00218     void trigger() { activate(Trigger); }
    00219     void hover() { activate(Hover); }
    00220     void setChecked(bool);
    00221     void toggle();
    00222     void setEnabled(bool);
    00223     inline void setDisabled(bool b) { setEnabled(!b); }
    00224     void setVisible(bool);
    00225
    00226 Q_SIGNALS:
    00227     void changed();
    00228     void triggered(bool checked = false);
    00229     void hovered();
    00230     void toggled(bool);
    00231 #ifdef QT3_SUPPORT
    00232     QT_MOC_COMPAT void activated(int = 0);
    00233 #endif
    00234
    00235 private:
    00236     Q_DISABLE_COPY(QAction)
    00237
    00238 #ifdef QT3_SUPPORT
    00239     friend class QMenuItem;
    00240 #endif
    00241     friend class QGraphicsWidget;
    00242     friend class QWidget;
    00243     friend class QActionGroup;
    00244     friend class QMenu;
    00245     friend class QMenuPrivate;
    00246     friend class QMenuBar;
    00247     friend class QShortcutMap;
    00248     friend class QToolButton;
    00249 #ifdef Q_WS_MAC
    00250     friend void qt_mac_clear_status_text(QAction *action);
    00251 #endif
    00252 };
    00253
    00254 QT_BEGIN_INCLUDE_NAMESPACE
    00255 #include <QtGui/qactiongroup.h>
    00256 QT_END_INCLUDE_NAMESPACE
    00257
    00258 #endif // QT_NO_ACTION
    00259
    00260 QT_END_NAMESPACE
    00261
    00262 QT_END_HEADER
    00263
    00264 #endif // QACTION_H