-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patheventlabel.cpp
78 lines (68 loc) · 1.53 KB
/
eventlabel.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
#include "eventlabel.h"
#include <QMouseEvent>
#include <QMessageBox>
#include <QApplication>
#include "mainwindow.h"
EventLabel::EventLabel(QWidget *parent) : QLabel(parent)
{
this->setMouseTracking(true);
}
void EventLabel::paintEvent(QPaintEvent *event)
{
QLabel::paintEvent(event);
QPainter painter(this);
painter.setPen(QPen(Qt::red, 2));
currRect = QRect(x1, y1, x2-x1, y2-y1);
if (isClearLastBox)
{
x1 = 0;
x2 = 0;
y1 = 0;
y2 = 0;
isClearLastBox = false;
}
painter.drawRect(currRect);
for (int i=0; i < rectlist.size(); i++)
{
painter.drawRect(rectlist[i]);
}
}
void EventLabel::deleteLastRect()
{
rectlist.pop_back();
// isClearLastBox = true;
}
void EventLabel::mousePressEvent(QMouseEvent *event)
{
x1 = event->x();
y1 = event->y();
QCursor cursor;
cursor.setShape(Qt::ClosedHandCursor);
QApplication::setOverrideCursor(cursor);
}
void EventLabel::mouseReleaseEvent(QMouseEvent *event)
{
x2 = event->x();
y2 = event->y();
update();
rectlist.append(currRect);
QApplication::restoreOverrideCursor();
QList<int> rectLocation;
rectLocation << x1 << x2 << y1 << y2;
emit mouseReleaseSignal();
emit rectLocationSet(rectLocation);
}
void EventLabel::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() & Qt::LeftButton)
{
x2 = event->x();
y2 = event->y();
update();
}
}
void EventLabel::deleteRectlist()
{
rectlist.clear();
isClearLastBox = true;
}