QmlMaterial 0.1.0
Loading...
Searching...
No Matches
action_command.hpp
1#pragma once
2
3#include "qml_material/control/action.hpp"
4#include "qml_material/control/command_button.hpp"
5
6namespace qml_material
7{
8class QML_MATERIAL_API ActionCommand : public QObject {
9 Q_OBJECT
10 QML_NAMED_ELEMENT(ActionCommand)
11 QML_UNCREATABLE("Attached to a command button")
12 QML_ATTACHED(ActionCommand)
13 Q_PROPERTY(Action* action READ action WRITE setAction NOTIFY actionChanged FINAL)
14 Q_PROPERTY(QString text READ text NOTIFY textChanged FINAL)
15 Q_PROPERTY(ActionIcon* icon READ icon NOTIFY actionChanged FINAL)
16 Q_PROPERTY(bool enabled READ isEnabled NOTIFY enabledChanged FINAL)
17public:
18 static ActionCommand* qmlAttachedProperties(QObject*);
19 Action* action() const { return m_action; }
20 void setAction(Action*);
21 QString text() const { return m_action ? m_action->text() : QString(); }
22 ActionIcon* icon() const { return m_action ? m_action->icon() : nullptr; }
23 bool isEnabled() const { return ! m_action || m_action->isEnabled(); }
24 Q_SIGNAL void actionChanged();
25 Q_SIGNAL void textChanged();
26 Q_SIGNAL void enabledChanged();
27
28private:
29 explicit ActionCommand(CommandButton*);
30 QPointer<CommandButton> m_button;
31 QPointer<Action> m_action;
32 QList<QMetaObject::Connection> m_connections;
33 quint64 m_revision = 0;
34};
35} // namespace qml_material
36QML_DECLARE_TYPEINFO(qml_material::ActionCommand, QML_HAS_ATTACHED_PROPERTIES)