forked from ZhujinLi/SomeRuler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeometrycalculator.h
55 lines (40 loc) · 1.17 KB
/
geometrycalculator.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
#ifndef GEOMETRYCALCULATOR_H
#define GEOMETRYCALCULATOR_H
#include <QSize>
#include <QTransform>
enum RotationMode
{
RotationMode_up,
RotationMode_down,
RotationMode_both
};
class GeometryCalculator
{
public:
GeometryCalculator();
void setRulerLength(int len);
void setRotationMode(RotationMode mode) { m_rotationMode = mode; }
RotationMode getRotationMode() { return m_rotationMode; }
// Unit: degrees
// It will be clamped to [0, 90].
// Initial value: 0
void setRotation(qreal rotation);
qreal getRotation() { return m_rotation; }
// Initial value: 0
void setPaddings(int paddings) { m_paddings = paddings; }
const QSize& getRulerSize() { return m_rulerSize; }
QSize getWindowSize() const { return m_windowSize; }
QTransform getTransform() const { return m_transform; }
QPoint transformPos(const QPoint& pos) const;
QPoint inversePos(const QPoint& pos) const;
private:
void _update();
QSize m_rulerSize;
qreal m_rotation;
QSize m_windowSize;
QTransform m_transform;
QTransform m_invTransform;
int m_paddings;
RotationMode m_rotationMode;
};
#endif // GEOMETRYCALCULATOR_H