1 /****************************************************************************
2 **
3 ** DQt - D bindings for the Qt Toolkit
4 **
5 ** GNU Lesser General Public License Usage
6 ** This file may be used under the terms of the GNU Lesser
7 ** General Public License version 3 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
9 ** packaging of this file. Please review the following information to
10 ** ensure the GNU Lesser General Public License version 3 requirements
11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
12 **
13 ****************************************************************************/
14 module qt.widgets.action;
15 extern(C++):
16 
17 import qt.config;
18 import qt.helpers;
19 version(QT_NO_ACTION){}else
20 {
21     import qt.core.coreevent;
22     import qt.core.list;
23     import qt.core.namespace;
24     import qt.core.object;
25     import qt.core.string;
26     import qt.core.variant;
27     import qt.gui.font;
28     import qt.gui.icon;
29     import qt.gui.keysequence;
30     import qt.widgets.actiongroup;
31     import qt.widgets.menu;
32     import qt.widgets.widget;
33 }
34 
35 version(QT_NO_ACTION)
36 {
37 class QAction;
38 }
39 
40 version(QT_NO_ACTION){}else
41 {
42 
43 /+ class QMenu;
44 class QActionGroup; +/
45 extern(C++, class) struct QActionPrivate;
46 extern(C++, class) struct QGraphicsWidget;
47 
48 class /+ Q_WIDGETS_EXPORT +/ QAction : QObject
49 {
50     mixin(Q_OBJECT);
51     /+ Q_DECLARE_PRIVATE(QAction) +/
52 
53     /+ Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY changed)
54     Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled)
55     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY changed)
56     Q_PROPERTY(QIcon icon READ icon WRITE setIcon NOTIFY changed)
57     Q_PROPERTY(QString text READ text WRITE setText NOTIFY changed)
58     Q_PROPERTY(QString iconText READ iconText WRITE setIconText NOTIFY changed)
59     Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip NOTIFY changed)
60     Q_PROPERTY(QString statusTip READ statusTip WRITE setStatusTip NOTIFY changed)
61     Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis NOTIFY changed)
62     Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY changed)
63 #if QT_CONFIG(shortcut)
64     Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut NOTIFY changed)
65     Q_PROPERTY(Qt::ShortcutContext shortcutContext READ shortcutContext WRITE setShortcutContext NOTIFY changed)
66     Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat NOTIFY changed)
67 #endif
68     Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY changed)
69     Q_PROPERTY(MenuRole menuRole READ menuRole WRITE setMenuRole NOTIFY changed)
70     Q_PROPERTY(bool iconVisibleInMenu READ isIconVisibleInMenu WRITE setIconVisibleInMenu NOTIFY changed)
71     Q_PROPERTY(bool shortcutVisibleInContextMenu READ isShortcutVisibleInContextMenu WRITE setShortcutVisibleInContextMenu NOTIFY changed)
72     Q_PROPERTY(Priority priority READ priority WRITE setPriority) +/
73 
74 public:
75     // note this is copied into qplatformmenu.h, which must stay in sync
76     enum MenuRole { NoRole = 0, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole,
77                     AboutRole, PreferencesRole, QuitRole }
78     /+ Q_ENUM(MenuRole) +/
79     enum Priority { LowPriority = 0,
80                     NormalPriority = 128,
81                     HighPriority = 256}
82     /+ Q_ENUM(Priority) +/
83     /+ explicit +/this(QObject parent = null);
84     /+ explicit +/this(ref const(QString) text, QObject parent = null);
85     /+ explicit +/this(ref const(QIcon) icon, ref const(QString) text, QObject parent = null);
86 
87     ~this();
88 
89     final void setActionGroup(QActionGroup group);
90     final QActionGroup actionGroup() const;
91     final void setIcon(ref const(QIcon) icon);
92     final QIcon icon() const;
93 
94     final void setText(ref const(QString) text);
95     final void setText(const QString s){setText(s);}
96     final QString text() const;
97 
98     final void setIconText(ref const(QString) text);
99     final QString iconText() const;
100 
101     final void setToolTip(ref const(QString) tip);
102     final QString toolTip() const;
103 
104     final void setStatusTip(ref const(QString) statusTip);
105     final QString statusTip() const;
106 
107     final void setWhatsThis(ref const(QString) what);
108     final QString whatsThis() const;
109 
110     final void setPriority(Priority priority);
111     final Priority priority() const;
112 
113 /+ #if QT_CONFIG(menu) +/
114     final QMenu menu() const;
115     final void setMenu(QMenu menu);
116 /+ #endif +/
117 
118     final void setSeparator(bool b);
119     final bool isSeparator() const;
120 
121 /+ #if QT_CONFIG(shortcut) +/
122     final void setShortcut(ref const(QKeySequence) shortcut);
123     final void setShortcut(const QString  shortcut)
124     {
125         auto tmp = QKeySequence(shortcut);
126         setShortcut(tmp);
127     }
128     final QKeySequence shortcut() const;
129 
130     final void setShortcuts(ref const(QList!(QKeySequence)) shortcuts);
131     final void setShortcuts(mixin((!versionIsSet!("QT_NO_SHORTCUT")) ? q{QKeySequence.StandardKey} : q{AliasSeq!()}));
132     final QList!(QKeySequence) shortcuts() const;
133 
134     final void setShortcutContext(/+ Qt:: +/qt.core.namespace.ShortcutContext context);
135     final /+ Qt:: +/qt.core.namespace.ShortcutContext shortcutContext() const;
136 
137     final void setAutoRepeat(bool);
138     final bool autoRepeat() const;
139 /+ #endif +/
140 
141     final void setFont(ref const(QFont) font);
142     final QFont font() const;
143 
144     final void setCheckable(bool);
145     final bool isCheckable() const;
146 
147     final QVariant data() const;
148     final void setData(ref const(QVariant) var);
149 
150     final bool isChecked() const;
151 
152     final bool isEnabled() const;
153 
154     final bool isVisible() const;
155 
156     enum ActionEvent { Trigger, Hover }
157     final void activate(ActionEvent event);
158     final bool showStatusText(QWidget widget = null);
159 
160     final void setMenuRole(MenuRole menuRole);
161     final MenuRole menuRole() const;
162 
163     final void setIconVisibleInMenu(bool visible);
164     final bool isIconVisibleInMenu() const;
165 
166     final void setShortcutVisibleInContextMenu(bool show);
167     final bool isShortcutVisibleInContextMenu() const;
168 
169     final QWidget parentWidget() const;
170 
171     final QList!(QWidget) associatedWidgets() const;
172 /+ #if QT_CONFIG(graphicsview) +/
173     final QList!(QGraphicsWidget*) associatedGraphicsWidgets() const; // ### suboptimal
174 /+ #endif +/
175 
176 protected:
177     override bool event(QEvent );
178     this(ref QActionPrivate dd, QObject parent);
179 
180 public /+ Q_SLOTS +/:
181     @QSlot final void trigger() { activate(ActionEvent.Trigger); }
182     @QSlot final void hover() { activate(ActionEvent.Hover); }
183     @QSlot final void setChecked(bool);
184     @QSlot final void toggle();
185     @QSlot final void setEnabled(bool);
186     pragma(inline, true) @QSlot final void setDisabled(bool b) { setEnabled(!b); }
187     @QSlot final void setVisible(bool);
188 
189 /+ Q_SIGNALS +/public:
190     @QSignal final void changed();
191     @QSignal final void triggered(bool checked = false);
192     @QSignal final void hovered();
193     @QSignal final void toggled(bool);
194 
195 private:
196     /+ Q_DISABLE_COPY(QAction) +/
197 
198     /+ friend class QGraphicsWidget; +/
199     /+ friend class QWidget; +/
200     /+ friend class QActionGroup; +/
201     /+ friend class QMenu; +/
202     /+ friend class QMenuPrivate; +/
203     /+ friend class QMenuBar; +/
204     /+ friend class QToolButton; +/
205     static if((versionIsSet!("OSX") || versionIsSet!("iOS") || versionIsSet!("TVOS") || versionIsSet!("WatchOS")))
206     {
207         /+ friend void qt_mac_clear_status_text(QAction *action); +/
208     }
209 }
210 
211 /+ #ifndef QT_NO_DEBUG_STREAM
212 Q_WIDGETS_EXPORT QDebug operator<<(QDebug, const QAction *);
213 #endif
214 
215 QT_BEGIN_INCLUDE_NAMESPACE
216 QT_END_INCLUDE_NAMESPACE +/
217 
218 }
219 /+ class QAction; +/
220