-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmark.cpp
77 lines (69 loc) · 1.53 KB
/
mark.cpp
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
#include "mark.h"
Mark::Mark(MarkOrientation orientation, int position, int sceneWidth, int sceneHeight, QGraphicsItem *parent) :
QGraphicsObject(parent)
{
m_orientation = orientation;
m_position = position;
m_sceneWidth = sceneWidth;
m_sceneHeight = sceneHeight;
}
/*
* Getter / Setter
*/
void Mark::setOrientation(Mark::MarkOrientation orientation)
{
m_orientation = orientation;
}
Mark::MarkOrientation Mark::orientation() const
{
return m_orientation;
}
void Mark::setPosition(int position)
{
prepareGeometryChange();
m_position = position;
emit positionChange();
}
int Mark::position() const
{
return m_position;
}
void Mark::setSceneSize(int width, int height)
{
m_sceneWidth = width;
m_sceneHeight = height;
}
/*
* Public Methods
*/
QRectF Mark::boundingRect() const
{
return QRectF(beginPoint(),endPoint()).adjusted(-1,-1,1,1);
}
void Mark::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
QPen pen;
pen.setStyle(Qt::SolidLine);
pen.setColor(QColor(180,0,0));
painter->setPen(pen);
painter->drawLine(beginPoint(),endPoint());
}
/*
* Private Methods
*/
QPoint Mark::beginPoint() const
{
if(m_orientation == MarkHorizontal)
return QPoint(0,m_position);
else
return QPoint(m_position,0);
}
QPoint Mark::endPoint() const
{
if(m_orientation == MarkHorizontal)
return QPoint(m_sceneWidth,m_position);
else
return QPoint(m_position,m_sceneHeight);
}