QmlMaterial 0.1.0
Loading...
Searching...
No Matches
drag_handle_state.hpp
1#pragma once
2#include "qml_material/style/common_state.hpp"
3#include <QQuickItem>
4namespace qml_material
5{
6class QML_MATERIAL_API DragHandleState : public CommonState {
7 Q_OBJECT
8 QML_NAMED_ELEMENT(StateDragHandle)
9 Q_PROPERTY(QQuickItem* item READ item WRITE setItem NOTIFY itemChanged FINAL)
10 Q_PROPERTY(
11 bool pressed READ pressed WRITE setPressed NOTIFY pressedChanged BINDABLE bindablePressed)
12 Q_PROPERTY(
13 bool hovered READ hovered WRITE setHovered NOTIFY hoveredChanged BINDABLE bindableHovered)
14 Q_PROPERTY(bool visualFocus READ visualFocus WRITE setVisualFocus NOTIFY visualFocusChanged
15 BINDABLE bindableVisualFocus)
16 Q_PROPERTY(int handlePressedWidth READ handlePressedWidth WRITE setHandlePressedWidth NOTIFY
17 handlePressedWidthChanged BINDABLE bindableHandlePressedWidth)
18 Q_PROPERTY(int handlePressedHeight READ handlePressedHeight WRITE setHandlePressedHeight NOTIFY
19 handlePressedHeightChanged BINDABLE bindableHandlePressedHeight)
20 Q_PROPERTY(int radius READ radius WRITE setRadius RESET resetRadius NOTIFY radiusChanged
21 BINDABLE bindableRadius)
22 Q_PROPERTY(int handleWidth READ handleWidth WRITE setHandleWidth RESET resetHandleWidth NOTIFY
23 handleWidthChanged BINDABLE bindableHandleWidth)
24 Q_PROPERTY(int handleHeight READ handleHeight WRITE setHandleHeight RESET resetHandleHeight
25 NOTIFY handleHeightChanged BINDABLE bindableHandleHeight)
26public:
27 explicit DragHandleState(QObject* parent = nullptr);
28 ~DragHandleState() override;
29 QQuickItem* item() const;
30 void setItem(QQuickItem*);
31 Q_SIGNAL void itemChanged();
32 bool pressed() const;
33 void setPressed(bool);
34 QBindable<bool> bindablePressed();
35 Q_SIGNAL void pressedChanged();
36 bool hovered() const;
37 void setHovered(bool);
38 QBindable<bool> bindableHovered();
39 Q_SIGNAL void hoveredChanged();
40 bool visualFocus() const;
41 void setVisualFocus(bool);
42 QBindable<bool> bindableVisualFocus();
43 Q_SIGNAL void visualFocusChanged();
44 int handlePressedWidth() const;
45 void setHandlePressedWidth(int);
46 QBindable<int> bindableHandlePressedWidth();
47 Q_SIGNAL void handlePressedWidthChanged();
48 int handlePressedHeight() const;
49 void setHandlePressedHeight(int);
50 QBindable<int> bindableHandlePressedHeight();
51 Q_SIGNAL void handlePressedHeightChanged();
52 int radius() const;
53 void setRadius(int);
54 QBindable<int> bindableRadius();
55 Q_SIGNAL void radiusChanged();
56 void resetRadius();
57 int handleWidth() const;
58 void setHandleWidth(int);
59 QBindable<int> bindableHandleWidth();
60 Q_SIGNAL void handleWidthChanged();
61 void resetHandleWidth();
62 int handleHeight() const;
63 void setHandleHeight(int);
64 QBindable<int> bindableHandleHeight();
65 Q_SIGNAL void handleHeightChanged();
66 void resetHandleHeight();
67
68private:
69 enum class Interaction
70 {
71 Base,
72 Disabled,
73 Pressed,
74 Hovered,
75 Focus
76 };
77 struct Selection {
78 Interaction state = Interaction::Base;
79 quint64 generation = 0;
80 bool operator==(const Selection&) const = default;
81 };
82 void selectionChanged();
83 StateBindingSet<Interaction> m_bindings { Interaction::Base };
84 QProperty<QQuickItem*> m_item { nullptr };
85 QProperty<bool> m_disabled { false };
86 QList<QMetaObject::Connection> m_connections;
87 bool m_ready = false;
88 Q_OBJECT_BINDABLE_PROPERTY(DragHandleState, Selection, m_selection,
89 &DragHandleState::selectionChanged)
90 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(DragHandleState, bool, m_pressed, false,
91 &DragHandleState::pressedChanged)
92 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(DragHandleState, bool, m_hovered, false,
93 &DragHandleState::hoveredChanged)
94 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(DragHandleState, bool, m_visualFocus, false,
95 &DragHandleState::visualFocusChanged)
96 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(DragHandleState, int, m_handlePressedWidth, 12,
97 &DragHandleState::handlePressedWidthChanged)
98 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(DragHandleState, int, m_handlePressedHeight, 52,
99 &DragHandleState::handlePressedHeightChanged)
100 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(DragHandleState, int, m_radius, 100,
101 &DragHandleState::radiusChanged)
102 PropertyKey<int> m_radiusKey;
103 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(DragHandleState, int, m_handleWidth, 4,
104 &DragHandleState::handleWidthChanged)
105 PropertyKey<int> m_handleWidthKey;
106 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(DragHandleState, int, m_handleHeight, 48,
107 &DragHandleState::handleHeightChanged)
108 PropertyKey<int> m_handleHeightKey;
109 StateBindingSet<Interaction>::Lifetime m_lifetime { m_bindings.lifetime() };
110};
111} // namespace qml_material