-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathTracer.cpp
More file actions
75 lines (66 loc) · 1.98 KB
/
Copy pathTracer.cpp
File metadata and controls
75 lines (66 loc) · 1.98 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
#include "Tracer.h"
#include "QDebug"
#include "QPen"
#include "QBrush"
#include "QPainter"
#include "QMenu"
#include "QGraphicsSceneContextMenuEvent"
Tracer::Tracer(QVariant type,
int frame,
float orientation,
QPointF pos,
float w,
float h,
QPen pen,
QBrush brush,
QAbstractGraphicsShapeItem* parent)
: QAbstractGraphicsShapeItem(parent)
, _type(type.toString())
, _frame(frame)
, _w(w)
, _h(h)
{
setPos(pos);
setPen(pen);
setBrush(brush);
setRotation(_h > _w ? -90 - orientation : -orientation);
}
Tracer::~Tracer()
{
}
QRectF Tracer::boundingRect() const
{
return QRect(-_w / 2, -_h / 2, _w, _h);
}
void Tracer::paint(QPainter* painter,
const QStyleOptionGraphicsItem* option,
QWidget* widget)
{
painter->setPen(pen());
painter->setBrush(brush());
if (_type == "point") {
int dim = _w <= _h ? _w : _h;
painter->drawEllipse(QRect(-dim / 2, -dim / 2, dim, dim));
} else if (_type == "ellipse") {
painter->drawEllipse(QRect(-_w / 2, -_h / 2, _w, _h));
} else if (_type == "rectangle") {
painter->drawRect(QRect(-_w / 2, -_h / 2, _w, _h));
}
// default for polygon shape are point tracers for simplicity
else if (_type == "polygon") {
int dim = _w <= _h ? _w : _h;
painter->drawEllipse(QRect(-dim / 2, -dim / 2, dim, dim));
}
}
void Tracer::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
{
QMenu menu;
menu.addAction("Go to frame ",
dynamic_cast<Tracer*>(this),
SLOT(goToFrame()));
menu.exec(event->screenPos());
}
void Tracer::goToFrame()
{
Q_EMIT emitGoToFrame(_frame);
}