-
Notifications
You must be signed in to change notification settings - Fork 0
/
overlaywidget.cpp
executable file
·54 lines (46 loc) · 1.41 KB
/
overlaywidget.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
#include "overlaywidget.h"
#include <QDebug>
OverlayWidget::OverlayWidget(QWidget *parent) : QWidget(parent) {
setWindowFlags(Qt::Widget | Qt::FramelessWindowHint | Qt::ToolTip | Qt::WindowStaysOnTopHint);
setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_PaintOnScreen);
painter = new QPainter(this);
pen.setColor(Qt::red);
pen.setWidth(2);
oldPen.setColor(Qt::blue);
oldPen.setWidth(2);
settingRoi = false;
}
void OverlayWidget::mousePressEvent(QMouseEvent *event) {
settingRoi = true;
if (event->button() == Qt::LeftButton) {
roi = QRect(event->pos(), event->pos());
} else {
roi.setTopLeft(roi.bottomRight());
}
}
void OverlayWidget::mouseMoveEvent(QMouseEvent *event) {
settingRoi = true;
if (event->buttons() & Qt::LeftButton) {
roi.setBottomRight(event->pos());
}
}
void OverlayWidget::mouseReleaseEvent(QMouseEvent *event) {
settingRoi = false;
qDebug() << "new ROI:" << this->size() << roi.normalized();
emit setRoi(roi.normalized());
}
void OverlayWidget::paintEvent(QPaintEvent *event) {
if (roi.topLeft() != roi.bottomRight()) {
painter->begin(this);
painter->setPen(pen);
painter->drawRect(roi);
painter->end();
}
}
void OverlayWidget::updateRoi(QRect roi) {
if (settingRoi == false) {
this->roi = roi;
}
}