QmlMaterial 0.1.0
Loading...
Searching...
No Matches
input_state.hpp
1#pragma once
2#include "qml_material/style/common_state.hpp"
3#include <QQuickItem>
4namespace qml_material
5{
6class QML_MATERIAL_API InputState : public CommonState {
7 Q_OBJECT
8 QML_ANONYMOUS
9 Q_PROPERTY(bool error READ error WRITE setError RESET resetError NOTIFY errorChanged BINDABLE
10 bindableError)
11public:
12 ~InputState() override;
13 bool error() const;
14 void setError(bool);
15 void resetError();
16 QBindable<bool> bindableError();
17 Q_SIGNAL void errorChanged();
18 Q_SIGNAL void itemChanged();
19
20protected:
21 explicit InputState(QObject* parent = nullptr);
22 enum class Interaction
23 {
24 Base,
25 Disabled,
26 ErrorHover,
27 Error,
28 Focus,
29 Hovered
30 };
31 StateBindingSet<Interaction> m_bindings { Interaction::Base };
32 QProperty<bool> m_acceptable { true }, m_focused { false }, m_hovered { false };
33 QQuickItem* inputItem() const;
34 void setInputItem(QQuickItem*);
35 void bindInputAppearance(const PropertyKey<QColor>& label, const PropertyKey<qreal>& opacity);
36
37private:
38 struct Selection {
39 Interaction state = Interaction::Base;
40 quint64 generation = 0;
41 bool operator==(const Selection&) const = default;
42 };
43 void selectionChanged();
44 QProperty<QQuickItem*> m_item { nullptr };
45 QProperty<bool> m_disabled { false };
46 QList<QMetaObject::Connection> m_connections;
47 bool m_ready = false;
48 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(InputState, bool, m_error, false,
49 &InputState::errorChanged)
50 Q_OBJECT_BINDABLE_PROPERTY(InputState, Selection, m_selection, &InputState::selectionChanged)
51};
52} // namespace qml_material