qaction.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the QtWidgets module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #ifndef QACTION_H
  40. #define QACTION_H
  41. #include <QtGui/qkeysequence.h>
  42. #include <QtCore/qstring.h>
  43. #include <QtWidgets/qwidget.h>
  44. #include <QtCore/qvariant.h>
  45. #include <QtGui/qicon.h>
  46. QT_BEGIN_NAMESPACE
  47. #ifndef QT_NO_ACTION
  48. class QMenu;
  49. class QActionGroup;
  50. class QActionPrivate;
  51. class QGraphicsWidget;
  52. class Q_WIDGETS_EXPORT QAction : public QObject
  53. {
  54. Q_OBJECT
  55. Q_DECLARE_PRIVATE(QAction)
  56. Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY changed)
  57. Q_PROPERTY(bool checked READ isChecked WRITE setChecked DESIGNABLE isCheckable NOTIFY toggled)
  58. Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY changed)
  59. Q_PROPERTY(QIcon icon READ icon WRITE setIcon NOTIFY changed)
  60. Q_PROPERTY(QString text READ text WRITE setText NOTIFY changed)
  61. Q_PROPERTY(QString iconText READ iconText WRITE setIconText NOTIFY changed)
  62. Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip NOTIFY changed)
  63. Q_PROPERTY(QString statusTip READ statusTip WRITE setStatusTip NOTIFY changed)
  64. Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis NOTIFY changed)
  65. Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY changed)
  66. #ifndef QT_NO_SHORTCUT
  67. Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut NOTIFY changed)
  68. Q_PROPERTY(Qt::ShortcutContext shortcutContext READ shortcutContext WRITE setShortcutContext NOTIFY changed)
  69. Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat NOTIFY changed)
  70. #endif
  71. Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY changed)
  72. Q_PROPERTY(MenuRole menuRole READ menuRole WRITE setMenuRole NOTIFY changed)
  73. Q_PROPERTY(bool iconVisibleInMenu READ isIconVisibleInMenu WRITE setIconVisibleInMenu NOTIFY changed)
  74. Q_PROPERTY(Priority priority READ priority WRITE setPriority)
  75. public:
  76. // note this is copied into qplatformmenu.h, which must stay in sync
  77. enum MenuRole { NoRole = 0, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole,
  78. AboutRole, PreferencesRole, QuitRole };
  79. Q_ENUM(MenuRole)
  80. enum Priority { LowPriority = 0,
  81. NormalPriority = 128,
  82. HighPriority = 256};
  83. Q_ENUM(Priority)
  84. explicit QAction(QObject *parent = nullptr);
  85. explicit QAction(const QString &text, QObject *parent = nullptr);
  86. explicit QAction(const QIcon &icon, const QString &text, QObject *parent = nullptr);
  87. ~QAction();
  88. void setActionGroup(QActionGroup *group);
  89. QActionGroup *actionGroup() const;
  90. void setIcon(const QIcon &icon);
  91. QIcon icon() const;
  92. void setText(const QString &text);
  93. QString text() const;
  94. void setIconText(const QString &text);
  95. QString iconText() const;
  96. void setToolTip(const QString &tip);
  97. QString toolTip() const;
  98. void setStatusTip(const QString &statusTip);
  99. QString statusTip() const;
  100. void setWhatsThis(const QString &what);
  101. QString whatsThis() const;
  102. void setPriority(Priority priority);
  103. Priority priority() const;
  104. #ifndef QT_NO_MENU
  105. QMenu *menu() const;
  106. void setMenu(QMenu *menu);
  107. #endif
  108. void setSeparator(bool b);
  109. bool isSeparator() const;
  110. #ifndef QT_NO_SHORTCUT
  111. void setShortcut(const QKeySequence &shortcut);
  112. QKeySequence shortcut() const;
  113. void setShortcuts(const QList<QKeySequence> &shortcuts);
  114. void setShortcuts(QKeySequence::StandardKey);
  115. QList<QKeySequence> shortcuts() const;
  116. void setShortcutContext(Qt::ShortcutContext context);
  117. Qt::ShortcutContext shortcutContext() const;
  118. void setAutoRepeat(bool);
  119. bool autoRepeat() const;
  120. #endif
  121. void setFont(const QFont &font);
  122. QFont font() const;
  123. void setCheckable(bool);
  124. bool isCheckable() const;
  125. QVariant data() const;
  126. void setData(const QVariant &var);
  127. bool isChecked() const;
  128. bool isEnabled() const;
  129. bool isVisible() const;
  130. enum ActionEvent { Trigger, Hover };
  131. void activate(ActionEvent event);
  132. bool showStatusText(QWidget *widget = Q_NULLPTR);
  133. void setMenuRole(MenuRole menuRole);
  134. MenuRole menuRole() const;
  135. void setIconVisibleInMenu(bool visible);
  136. bool isIconVisibleInMenu() const;
  137. QWidget *parentWidget() const;
  138. QList<QWidget *> associatedWidgets() const;
  139. #ifndef QT_NO_GRAPHICSVIEW
  140. QList<QGraphicsWidget *> associatedGraphicsWidgets() const; // ### suboptimal
  141. #endif
  142. protected:
  143. bool event(QEvent *) Q_DECL_OVERRIDE;
  144. QAction(QActionPrivate &dd, QObject *parent);
  145. public Q_SLOTS:
  146. void trigger() { activate(Trigger); }
  147. void hover() { activate(Hover); }
  148. void setChecked(bool);
  149. void toggle();
  150. void setEnabled(bool);
  151. inline void setDisabled(bool b) { setEnabled(!b); }
  152. void setVisible(bool);
  153. Q_SIGNALS:
  154. void changed();
  155. void triggered(bool checked = false);
  156. void hovered();
  157. void toggled(bool);
  158. private:
  159. Q_DISABLE_COPY(QAction)
  160. friend class QGraphicsWidget;
  161. friend class QWidget;
  162. friend class QActionGroup;
  163. friend class QMenu;
  164. friend class QMenuPrivate;
  165. friend class QMenuBar;
  166. friend class QToolButton;
  167. #ifdef Q_OS_MAC
  168. friend void qt_mac_clear_status_text(QAction *action);
  169. #endif
  170. };
  171. #ifndef QT_NO_DEBUG_STREAM
  172. Q_WIDGETS_EXPORT QDebug operator<<(QDebug, const QAction *);
  173. #endif
  174. QT_BEGIN_INCLUDE_NAMESPACE
  175. #include <QtWidgets/qactiongroup.h>
  176. QT_END_INCLUDE_NAMESPACE
  177. #endif // QT_NO_ACTION
  178. QT_END_NAMESPACE
  179. #endif // QACTION_H