-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyLabel.cpp
104 lines (77 loc) · 1.55 KB
/
MyLabel.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include<MyLabel.h>
MyLabel::MyLabel(QWidget* parent):QLabel(parent)
{
}
/*
MyLabel::MyLabel(QWidget *parent,LabelTool* labelTool):QLabel(parent)
{
this->labelTool = labelTool;
}
*/
MyLabel::~MyLabel()
{
}
void MyLabel::paintEvent(QPaintEvent *event)
{
QLabel::paintEvent(event);//先调用父类的paintEvent为了显示'背景'!!!
paintPoints();
paintLines();
}
void MyLabel::paintPoints()
{
QPainter painter(this);
QBrush brush(QColor(0,0,255));
painter.setBrush(brush);
double width = this->width();
double height = this->height();
for(int i=0;i<points.size();i++)
{
QPoint* p = points[i];
painter.drawEllipse(*p,6,6);
}
}
void MyLabel::paintLines(){
if(points.size()<=1)
return;
QPainter painter(this);
QBrush brush(QColor(255,0,0));
painter.setBrush(brush);
for(int i=0;i<points.size()-1;i++)
{
QPoint* p1 = points[i];
QPoint* p2 = points[i+1];
painter.drawLine(*p1,*p2);
}
if(points.size()==4)
{
QPoint* p1 = points[3];
QPoint* p2 = points[0];
painter.drawLine(*p1,*p2);
}
}
//点的点可能不在图像上
void MyLabel::mousePressEvent(QMouseEvent *event)
{
//以左上角为原点
if (event->button() == Qt::LeftButton){
QPoint p = event->pos();
QPoint *pp = new QPoint(p.x(),p.y());
if(points.size()>4)
points.clear();
points.push_back(pp);
}
update();
//labelTool->showLabel();
}
void MyLabel::mouseMoveEvent(QMouseEvent *event)
{
// QPoint p = event->pos();
}
void MyLabel::mouseReleaseEvent(QMouseEvent *event)
{
// QPoint p = event->pos();
}
void MyLabel::showTruth()
{
//ui.lineEdit
}