-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathdot.h
83 lines (67 loc) · 1.44 KB
/
dot.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
#ifndef DOT_H
#define DOT_H
#include <QWidget>
#include <QPoint>
/*
* Represents a single polygon dot in a plate selector
*/
class Dot : public QWidget
{
Q_OBJECT
public:
Dot(QWidget *parent = nullptr);
/*
* Center point of the dot in parent's coordinates
*/
void setCenterPoint(const QPoint ¢er);
/*
* Center point
*/
QPoint centerPoint() const;
/*
* Appropriate not scaled point in the original image in pixels
*/
void setPointInImage(const QPoint &point);
QPoint pointInImage() const;
protected:
virtual void mousePressEvent(QMouseEvent *e) override;
virtual void mouseMoveEvent(QMouseEvent *e) override;
virtual void mouseReleaseEvent(QMouseEvent *e) override;
virtual void paintEvent(QPaintEvent *e) override;
private:
QPoint relativeCenter() const;
void dragTo(const QPoint &pos);
signals:
void moving();
void moved();
private:
QPoint m_lastMousePoint;
QPoint m_pointInImage;
bool inMove;
};
inline
void Dot::setCenterPoint(const QPoint ¢er)
{
move(center - relativeCenter());
}
inline
QPoint Dot::centerPoint() const
{
return pos() + relativeCenter();
}
inline
void Dot::setPointInImage(const QPoint &point)
{
m_pointInImage = point;
}
inline
QPoint Dot::pointInImage() const
{
return m_pointInImage;
}
inline
QPoint Dot::relativeCenter() const
{
return QPoint(width()/2, height()/2);
}
#endif // DOT_H