-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawline.cpp
70 lines (67 loc) · 1.19 KB
/
drawline.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
#include "drawline.h"
DrawLine::DrawLine()
{
IsRemoveLast = false;
IsHasP1 = false;
}
void DrawLine::paint(QPainter *painter)
{
if(lines.size() == 0) {
return;
}
QPen pen;
pen.setColor("red");
pen.setWidth(15);
painter->setPen(pen);
painter->setRenderHint(QPainter::Antialiasing, true);//反锯齿
painter->drawLines(lines);
}
void DrawLine::setDrawLineP1(const QPointF& p1)
{
line.setP1(p1);
IsHasP1 = true;
}
void DrawLine::setDrawLineP2(const QPointF& p2)
{
if(IsRemoveLast) {
lines.removeLast();
}
line.setP2(p2);
lines.append(line);
IsRemoveLast = true;
update();
}
void DrawLine::addLine(const QPointF &p2)
{
if(IsRemoveLast) {
lines.removeLast();
}
line.setP2(p2);
lines.append(line);
setDrawLineP1(p2);
IsRemoveLast = false;
update();
}
void DrawLine::finishedDrawLine()
{
if(IsRemoveLast) {
lines.removeLast();
}
IsRemoveLast = false;
update();
}
QPointF DrawLine::getP1()
{
return line.p1();
}
bool DrawLine::hasP1()
{
return IsHasP1;
}
void DrawLine::clearLines()
{
lines.clear();
IsRemoveLast = false;
IsHasP1 = false;
update();
}