-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconstants.h
84 lines (77 loc) · 1.94 KB
/
constants.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef CONSTANTS_H
#define CONSTANTS_H
#define STATE_OFF 0
#define STATE_ON 1
#define STATE_FAULT 2
#define Q_DECLARE_ROTATION \
Q_PROPERTY(Rotation rotation READ rotation WRITE setRotation); \
\
public: \
enum Rotation { \
NoRotation = 0, \
Rotate90 = 90, \
Rotate180 = 180, \
Rotate270 = 270 \
}; \
\
Q_ENUM(Rotation) \
\
Rotation rotation() const \
{ \
return m_rotation; \
} \
\
void setRotation(const Rotation angle) \
{ \
m_rotation = angle; \
update(); \
} \
\
private: \
Rotation m_rotation;
#define Q_DECLARE_FLIP \
Q_PROPERTY(FlipDirection flip READ flipDirection WRITE setFlipDirection); \
\
public: \
enum FlipDirection { \
NoFlip, \
Horizontal, \
Vertical \
}; \
\
Q_ENUM(FlipDirection); \
\
FlipDirection flipDirection() const \
{ \
return m_flip; \
} \
void setFlipDirection(const FlipDirection direction) \
{ \
m_flip = direction; \
update(); \
} \
\
private: \
FlipDirection m_flip;
#define Q_IMPLEMENT_FLIP \
QTransform t; \
if (m_flip == FlipDirection::Vertical) { \
t.translate(width, 0); \
t.scale(-1, 1); \
painter.setTransform(t);\
} \
else if (m_flip == FlipDirection::Horizontal) { \
t.translate(0, height); \
t.scale(1, -1); \
painter.setTransform(t); \
} \
else { \
t.scale(1, 1); \
painter.setTransform(t); \
} \
#define Q_IMPLEMENT_ROTATION \
int angle = (int) m_rotation; \
painter.translate(width / 2, height / 2); \
painter.rotate(angle); \
painter.translate(-width / 2, -height / 2); \
#endif // CONSTANTS_H