QmlMaterial 0.1.0
Loading...
Searching...
No Matches
repeat_button.hpp
1#pragma once
2
3#include "qml_material/control/command_button.hpp"
4
5namespace qml_material
6{
8class QML_MATERIAL_API RepeatButton : public CommandButton {
9 Q_OBJECT
10 QML_NAMED_ELEMENT(RepeatButtonBase)
11 Q_PROPERTY(int repeatDelay READ repeatDelay WRITE setRepeatDelay NOTIFY repeatChanged FINAL)
12 Q_PROPERTY(
13 int repeatInterval READ repeatInterval WRITE setRepeatInterval NOTIFY repeatChanged FINAL)
14public:
15 explicit RepeatButton(QQuickItem* parent = nullptr): CommandButton(parent) {
16 inputHost().click().repeat();
17 }
18 int repeatDelay() { return inputHost().click().repeat().delay; }
19 int repeatInterval() { return inputHost().click().repeat().interval; }
20 void setRepeatDelay(int value) { configure(value, repeatInterval()); }
21 void setRepeatInterval(int value) { configure(repeatDelay(), value); }
22 Q_SIGNAL void repeatChanged();
23
24private:
25 void configure(int delay, int interval) {
26 delay = qMax(1, delay);
27 interval = qMax(1, interval);
28 if (delay == repeatDelay() && interval == repeatInterval()) return;
29 const QPointer<RepeatButton> guard(this);
30 cancelActivation();
31 if (! guard) return;
32 auto& repeat = inputHost().click().repeat();
33 repeat.delay = delay;
34 repeat.interval = interval;
35 Q_EMIT repeatChanged();
36 }
37};
38} // namespace qml_material