From cff492fed1d98f45c4c1f4011f1451120c0d1c23 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 19 Jun 2019 13:00:11 +0200 Subject: Extract QGuiAction(Group) from QAction(Group) into QtGui Simply moving QAction to QtGui was not deemed possible since it operates on a set of controls of some kind. The approach to extract a base class was taken instead, named QGuiAction following the QGuiApplication scheme. QAction remains in widgets, but changes base class. For QActionGroup, the functions addAction(text/icon), which create an action, cannot be implemented in QtGui, hence a base class is needed, too (unless they are deprecated and removed). - Extract base classes providing functionality not based on QtWidgets, using virtuals in QGuiActionPrivate to provide customization points - Change QActionEvent to take QGuiAction, removing the need to forward declare QAction in QtGui [ChangeLog][QtGui] Added QGuiAction(Group) and made the equivalent existing classes in Qt Widgets derive from them. This provides basic functionality for implementing actions in QML. Task-number: QTBUG-69478 Change-Id: Ic490a5e3470939ee8af612d46ff41d4c8c91fbdf Reviewed-by: Lars Knoll Reviewed-by: Mitch Curtis Reviewed-by: Oliver Wolff Reviewed-by: Allan Sandfeld Jensen --- src/widgets/kernel/qaction.h | 127 ++----------------------------------------- 1 file changed, 6 insertions(+), 121 deletions(-) (limited to 'src/widgets/kernel/qaction.h') diff --git a/src/widgets/kernel/qaction.h b/src/widgets/kernel/qaction.h index d232b8d205..f835c50265 100644 --- a/src/widgets/kernel/qaction.h +++ b/src/widgets/kernel/qaction.h @@ -41,13 +41,10 @@ #define QACTION_H #include -#if QT_CONFIG(shortcut) -# include -#endif +#include #include #include #include -#include QT_BEGIN_NAMESPACE @@ -59,121 +56,25 @@ class QActionGroup; class QActionPrivate; class QGraphicsWidget; -class Q_WIDGETS_EXPORT QAction : public QObject +class Q_WIDGETS_EXPORT QAction : public QGuiAction { Q_OBJECT Q_DECLARE_PRIVATE(QAction) - - Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY changed) - Q_PROPERTY(bool checked READ isChecked WRITE setChecked DESIGNABLE isCheckable NOTIFY toggled) - Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY changed) - Q_PROPERTY(QIcon icon READ icon WRITE setIcon NOTIFY changed) - Q_PROPERTY(QString text READ text WRITE setText NOTIFY changed) - Q_PROPERTY(QString iconText READ iconText WRITE setIconText NOTIFY changed) - Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip NOTIFY changed) - Q_PROPERTY(QString statusTip READ statusTip WRITE setStatusTip NOTIFY changed) - Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis NOTIFY changed) - Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY changed) -#if QT_CONFIG(shortcut) - Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut NOTIFY changed) - Q_PROPERTY(Qt::ShortcutContext shortcutContext READ shortcutContext WRITE setShortcutContext NOTIFY changed) - Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat NOTIFY changed) -#endif - Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY changed) - Q_PROPERTY(MenuRole menuRole READ menuRole WRITE setMenuRole NOTIFY changed) - Q_PROPERTY(bool iconVisibleInMenu READ isIconVisibleInMenu WRITE setIconVisibleInMenu NOTIFY changed) - Q_PROPERTY(bool shortcutVisibleInContextMenu READ isShortcutVisibleInContextMenu WRITE setShortcutVisibleInContextMenu NOTIFY changed) - Q_PROPERTY(Priority priority READ priority WRITE setPriority) - public: - // note this is copied into qplatformmenu.h, which must stay in sync - enum MenuRole { NoRole = 0, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole, - AboutRole, PreferencesRole, QuitRole }; - Q_ENUM(MenuRole) - enum Priority { LowPriority = 0, - NormalPriority = 128, - HighPriority = 256}; - Q_ENUM(Priority) - explicit QAction(QObject *parent = nullptr); - explicit QAction(const QString &text, QObject *parent = nullptr); - explicit QAction(const QIcon &icon, const QString &text, QObject *parent = nullptr); - + QAction(QObject* parent = nullptr); + QAction(const QString &text, QObject* parent = nullptr); + QAction(const QIcon &icon, const QString &text, QObject* parent); ~QAction(); - void setActionGroup(QActionGroup *group); QActionGroup *actionGroup() const; - void setIcon(const QIcon &icon); - QIcon icon() const; - - void setText(const QString &text); - QString text() const; - - void setIconText(const QString &text); - QString iconText() const; - - void setToolTip(const QString &tip); - QString toolTip() const; - - void setStatusTip(const QString &statusTip); - QString statusTip() const; - - void setWhatsThis(const QString &what); - QString whatsThis() const; - - void setPriority(Priority priority); - Priority priority() const; #if QT_CONFIG(menu) QMenu *menu() const; void setMenu(QMenu *menu); #endif - void setSeparator(bool b); - bool isSeparator() const; - -#if QT_CONFIG(shortcut) - void setShortcut(const QKeySequence &shortcut); - QKeySequence shortcut() const; - - void setShortcuts(const QList &shortcuts); - void setShortcuts(QKeySequence::StandardKey); - QList shortcuts() const; - - void setShortcutContext(Qt::ShortcutContext context); - Qt::ShortcutContext shortcutContext() const; - - void setAutoRepeat(bool); - bool autoRepeat() const; -#endif - - void setFont(const QFont &font); - QFont font() const; - - void setCheckable(bool); - bool isCheckable() const; - - QVariant data() const; - void setData(const QVariant &var); - - bool isChecked() const; - - bool isEnabled() const; - - bool isVisible() const; - - enum ActionEvent { Trigger, Hover }; - void activate(ActionEvent event); bool showStatusText(QWidget *widget = nullptr); - void setMenuRole(MenuRole menuRole); - MenuRole menuRole() const; - - void setIconVisibleInMenu(bool visible); - bool isIconVisibleInMenu() const; - - void setShortcutVisibleInContextMenu(bool show); - bool isShortcutVisibleInContextMenu() const; - QWidget *parentWidget() const; QList associatedWidgets() const; @@ -182,30 +83,14 @@ public: #endif protected: - bool event(QEvent *) override; QAction(QActionPrivate &dd, QObject *parent); - -public Q_SLOTS: - void trigger() { activate(Trigger); } - void hover() { activate(Hover); } - void setChecked(bool); - void toggle(); - void setEnabled(bool); - inline void setDisabled(bool b) { setEnabled(!b); } - void setVisible(bool); - -Q_SIGNALS: - void changed(); - void triggered(bool checked = false); - void hovered(); - void toggled(bool); + bool event(QEvent *) override; private: Q_DISABLE_COPY(QAction) friend class QGraphicsWidget; friend class QWidget; - friend class QActionGroup; friend class QMenu; friend class QMenuPrivate; friend class QMenuBar; -- cgit v1.2.3