src/gui/kernel/qaction.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 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 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    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 **
       
    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.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    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 <QtGui/qwidget.h>
       
    48 #include <QtCore/qvariant.h>
       
    49 #include <QtGui/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_GUI_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 #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 
       
   135     void setPriority(Priority priority);
       
   136     Priority priority() const;
       
   137 
       
   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 
       
   183     void setSoftKeyRole(SoftKeyRole softKeyRole);
       
   184     SoftKeyRole softKeyRole() const;
       
   185 
       
   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 
       
   210 protected:
       
   211     bool event(QEvent *);
       
   212     QAction(QActionPrivate &dd, QObject *parent);
       
   213 
       
   214 public 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 
       
   226 Q_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 
       
   235 private:
       
   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;
       
   249 };
       
   250 
       
   251 QT_BEGIN_INCLUDE_NAMESPACE
       
   252 #include <QtGui/qactiongroup.h>
       
   253 QT_END_INCLUDE_NAMESPACE
       
   254 
       
   255 #endif // QT_NO_ACTION
       
   256 
       
   257 QT_END_NAMESPACE
       
   258 
       
   259 QT_END_HEADER
       
   260 
       
   261 #endif // QACTION_H