-
Notifications
You must be signed in to change notification settings - Fork 0
/
GraphicsEdge.cpp
51 lines (40 loc) · 1021 Bytes
/
GraphicsEdge.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
#include "GraphicsEdge.h"
#include <QPainter>
#include <QDebug>
GraphicsEdge::GraphicsEdge() : QGraphicsPathItem()
{
defaultOutlinePen = QPen(QColor(255, 255, 255, 150));
defaultOutlinePen.setWidth(4);
selectedOutlinePen = QPen(Qt::yellow);
selectedOutlinePen.setWidth(4);
setFlags(QGraphicsItem::ItemIsSelectable);
}
GraphicsEdge::~GraphicsEdge()
{
qDebug() << "Edge removed";
}
void GraphicsEdge::updatePath()
{
painterPath = QPainterPath(src);
painterPath.lineTo(dst);
setPath(painterPath);
setZValue(-1);
}
void GraphicsEdge::setSource(QPoint A)
{
src = A;
}
void GraphicsEdge::setDest(QPoint B)
{
dst = B;
}
void GraphicsEdge::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
updatePath();
Q_UNUSED(option);
Q_UNUSED(widget);
if (this->isSelected()) painter->setPen(selectedOutlinePen);
else painter->setPen(defaultOutlinePen);
painter->setBrush(Qt::NoBrush);
painter->drawPath(painterPath);
}