forked from BioroboticsLab/biotracker_sampletracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrackedElementView.cpp
More file actions
133 lines (118 loc) · 4.27 KB
/
Copy pathTrackedElementView.cpp
File metadata and controls
133 lines (118 loc) · 4.27 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "TrackedElementView.h"
#include "QBrush"
#include "QPainter"
#include <QGraphicsSceneHoverEvent>
#include <QMouseEvent>
class QGraphicsSceneHoverEvent;
TrackedElementView::TrackedElementView(QGraphicsItem *parent, IController *controller, IModel *model) :
IViewTrackedComponent(parent, controller, model)
{
m_boundingRect = QRectF(0, 0, 100, 100);
setAcceptHoverEvents(true);
setAcceptedMouseButtons(Qt::MouseButtons::enum_type::LeftButton);
_showSelectorRec = false;
this->installEventFilter(this);
}
void TrackedElementView::rcvDimensionUpdate(int x, int y) {
m_boundingRect = QRectF(0, 0, x, y);
update();
}
QRectF TrackedElementView::boundingRect() const
{
return m_boundingRect;
}
void TrackedElementView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
//painter->drawRoundRect(&*ri);
if (_showSelectorRec) {
QColor color(Qt::cyan);
color.setAlpha(150);
QBrush brush(color);
painter->fillRect(QRectF(_selectorRecStart, _selectorRecEnd), brush);
}
}
void TrackedElementView::getNotified()
{
update();
}
bool TrackedElementView::sceneEventFilter(QGraphicsItem *watched, QEvent *event) {
if (event->type() == QEvent::GraphicsSceneMousePress) {
QGraphicsSceneMouseEvent *e = (QGraphicsSceneMouseEvent *)event;
int x = e->pos().x();
int y = e->pos().y();
std::string note = "shift + left button press on: x="
+ QString::number(x).toStdString() + " y=" + QString::number(y).toStdString();
//initialize coordinates for selection tool
_selectorRecStart.setX(e->pos().x());
_selectorRecStart.setY(e->pos().y());
_selectorRecEnd.setX(e->pos().x());
_selectorRecEnd.setY(e->pos().y());
_showSelectorRec = true;
Q_EMIT update();
}
if (event->type() == QEvent::GraphicsSceneMouseMove) {
QGraphicsSceneMouseEvent *e;
if (_showSelectorRec && (e = dynamic_cast<QGraphicsSceneMouseEvent *>(event))) {
_selectorRecEnd.setX(e->pos().x());
_selectorRecEnd.setY(e->pos().y());
Q_EMIT update();
}
}
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
if (_showSelectorRec) {
QGraphicsSceneMouseEvent *e = (QGraphicsSceneMouseEvent*)event;
_selectorRecEnd.setX(e->pos().x());
_selectorRecEnd.setY(e->pos().y());
_showSelectorRec = false;
//next draw will delete rectangle!
Q_EMIT update();
std::string note = "selected area from " + QString::number(
_selectorRecStart.x()).toStdString() + ":" +
QString::number(_selectorRecStart.y()).toStdString()
+ " to " + QString::number(_selectorRecEnd.x()).toStdString() + ":" +
QString::number(_selectorRecEnd.y()).toStdString();
}
}
return true;
}
bool TrackedElementView::eventFilter(QObject *target, QEvent *event)
{
if (event->type() == QEvent::GraphicsSceneMousePress) {
QGraphicsSceneMouseEvent *e = (QGraphicsSceneMouseEvent *)event;
int x = e->pos().x();
int y = e->pos().y();
std::string note = "shift + left button press on: x="
+ QString::number(x).toStdString() + " y=" + QString::number(y).toStdString();
//initialize coordinates for selection tool
_selectorRecStart.setX(e->pos().x());
_selectorRecStart.setY(e->pos().y());
_selectorRecEnd.setX(e->pos().x());
_selectorRecEnd.setY(e->pos().y());
_showSelectorRec = true;
Q_EMIT update();
}
if (event->type() == QEvent::GraphicsSceneMouseMove) {
QGraphicsSceneMouseEvent *e;
if (_showSelectorRec && (e = dynamic_cast<QGraphicsSceneMouseEvent *>(event))) {
_selectorRecEnd.setX(e->pos().x());
_selectorRecEnd.setY(e->pos().y());
Q_EMIT update();
}
}
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
if (_showSelectorRec) {
QGraphicsSceneMouseEvent *e = (QGraphicsSceneMouseEvent*)event;
_selectorRecEnd.setX(e->pos().x());
_selectorRecEnd.setY(e->pos().y());
_showSelectorRec = false;
//next draw will delete rectangle!
Q_EMIT update();
std::string note = "selected area from " + QString::number(
_selectorRecStart.x()).toStdString() + ":" +
QString::number(_selectorRecStart.y()).toStdString()
+ " to " + QString::number(_selectorRecEnd.x()).toStdString() + ":" +
QString::number(_selectorRecEnd.y()).toStdString();
}
}
return true;// TrackedElementView::eventFilter(target, event);
}