-
Notifications
You must be signed in to change notification settings - Fork 0
/
button.h
46 lines (38 loc) · 855 Bytes
/
button.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef BUTTON_H
#define BUTTON_H
#include <QElapsedTimer>
enum class ButtonState
{
Down,
StillDown,
Up,
None
};
class ButtonTimer
{
protected:
ButtonState m_buttonState;
QElapsedTimer m_timer;
quint32 m_expireDelayMsec;
public:
ButtonTimer();
void start(ButtonState buttonState, quint32 expireDelayMsec);
bool isValid();
void invalidate();
bool hasExpired();
bool stateHasChangedOrExpired(ButtonState buttonState);
};
class ButtonCombo
{
protected:
ButtonState m_targetState;
ButtonTimer m_button1Timer, m_button2Timer;
quint32 m_pressDelayMs;
public:
ButtonCombo() = delete;
ButtonCombo(ButtonState targetState);
void updateState(ButtonState button1State, ButtonState button2State, quint32 pressDelayMsec);
void clear();
bool isComboOn();
};
#endif // BUTTON_H