forked from OpenDDS/OpenDDS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEdge.cpp
More file actions
80 lines (68 loc) · 1.55 KB
/
Copy pathEdge.cpp
File metadata and controls
80 lines (68 loc) · 1.55 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
/*
*
*
* Distributed under the OpenDDS License.
* See: http://www.opendds.org/license.html
*/
#include "Edge.h"
Monitor::Edge::Edge(Node* ancestor, Node* child, bool pubSub, QGraphicsItem *):
parent_(ancestor),
child_(child),
pubSub_(pubSub)
{
setFlag(ItemIsMovable);
// setFlag(ItemIsSelectable);
setFlag(ItemSendsGeometryChanges);
setCacheMode(DeviceCoordinateCache);
setZValue(1);
}
void
Monitor::Edge::adjust()
{
prepareGeometryChange();
}
QRectF
Monitor::Edge::boundingRect() const
{
if (!parent_ || !child_) {
return QRectF();
}
int x1 = parent_->scenePos().x() + parent_->boundingRect().width() - 2;
int y1 = parent_->scenePos().y() + parent_->boundingRect().height() - 2;
int x2 = child_->scenePos().x() + 2;
int y2 = child_->scenePos().y() + 2;
// calculate the proper bounding rect.
if (x1 < x2) {
if (y1 < y2) {
return QRectF(x1, y1, x2, y2);
}
else {
return QRectF(x1, y2, x2, y1);
}
}
else {
if (y1 < y2) {
return QRectF(x2, y1, x1, y2);
}
else {
return QRectF(x2, y2, x1, y1);
}
}
}
void
Monitor::Edge::paint(QPainter *painter,const QStyleOptionGraphicsItem *,QWidget *)
{
if (pubSub_) {
QPen pen;
pen.setWidth(3);
painter->setPen(pen);
}
int x1 = parent_->scenePos().x() + parent_->boundingRect().width() - 2;
int y1 = parent_->scenePos().y() + parent_->boundingRect().height() - 2;
int x2 = child_->scenePos().x() + 2;
int y2 = child_->scenePos().y() + 2;
QLine line;
line.setLine(x1, y1, x2, y2);
painter->drawLine(line);
update();
}