-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.cpp
More file actions
63 lines (54 loc) · 1.5 KB
/
Copy pathplot.cpp
File metadata and controls
63 lines (54 loc) · 1.5 KB
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
#include "plot.h"
#include <QPainter>
Plot::Plot(QWidget *parent) : QLabel(parent)
{
}
void Plot::drawRectangle(int xStart, int yStart, int xEnd, int yEnd) {
QRect a;
a.setTopLeft(QPoint(xStart, yStart));
a.setTopRight(QPoint(xEnd, yStart));
a.setBottomRight(QPoint(xEnd, yEnd));
a.setBottomLeft(QPoint(xStart, yEnd));
this->rect->push_back(a);
this->repaint();
}
void Plot::clearRectangle() {
this->rect->clear();
}
void Plot::mouseMoveEvent(QMouseEvent *e) {
this->x = e->localPos().x();
this->y = e->localPos().y();
emit mousePos();
}
void Plot::mousePressEvent(QMouseEvent *e) {
this->xStart = e->localPos().x();
this->yStart = e->localPos().y();
emit mousePressed();
}
void Plot::mouseReleaseEvent(QMouseEvent *e) {
this->xEnd = e->localPos().x();
this->yEnd = e->localPos().y();
if (this->xStart > this->xEnd) {
int help = this->xStart;
this->xStart = this->xEnd;
this->xEnd = help;
}
if (this->yStart > this->yEnd) {
int help = this->yStart;
this->yStart = this->yEnd;
this->yEnd = help;
}
emit mouseReleased();
}
void Plot::paintEvent(QPaintEvent *e) {
QLabel::paintEvent(e);
if (this->rect->size() > 0) {
for (uint ind = 0; ind < this->rect->size(); ind++) {
QPainter painter(this);
QPen paintpen(Qt::red);
paintpen.setWidth(1);
painter.setPen(paintpen);
painter.drawRect(this->rect->at(ind));
}
}
}