QmlMaterial 0.1.0
Loading...
Searching...
No Matches
selection_button.hpp
1#pragma once
2
3#include "qml_material/control/button_control.hpp"
4#include "qml_material/util/qt.hpp"
5
6namespace qml_material
7{
8class QML_MATERIAL_API SelectionButton : public ButtonControl {
9 Q_OBJECT
10 QML_NAMED_ELEMENT(SelectionButtonBase)
11 Q_PROPERTY(bool selected READ isSelected WRITE setSelected NOTIFY selectedChanged FINAL)
12public:
13 explicit SelectionButton(QQuickItem* parent = nullptr): ButtonControl(parent) {
14 m_selectedNotifier = m_selected.addNotifier([this] {
15 Q_EMIT selectedChanged();
16 });
17 }
18 bool isSelected() const { return m_selected; }
19 void setSelected(bool value) { utils::updateBoundValue(m_selected, value); }
20 QBindable<bool> bindableSelected() { return &m_selected; }
21 Q_INVOKABLE void requestSelection() {
22 if (canActivate()) Q_EMIT selectionRequested();
23 }
24 Q_SIGNAL void selectedChanged();
25 Q_SIGNAL void selectionRequested();
26
27protected:
28 void activate() override { requestSelection(); }
29
30private:
31 Q_OBJECT_BINDABLE_PROPERTY(SelectionButton, bool, m_selected)
32 QPropertyNotifier m_selectedNotifier;
33};
34} // namespace qml_material