-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwireconnection.cpp
More file actions
48 lines (37 loc) · 1.36 KB
/
Copy pathwireconnection.cpp
File metadata and controls
48 lines (37 loc) · 1.36 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
#include "wireconnection.h"
WireConnection::WireConnection(AbstractScheme *parent,
GraphicsComponent *first, GraphicsComponent *second)
:GraphicsComponent(parent)
{
this->setFlags(this->flags() ^ QGraphicsItem::ItemIsMovable);
this->setFlags(this->flags() ^ QGraphicsItem::ItemIsSelectable);
this->first = first;
this->second = second;
QObject::connect(first, SIGNAL(itemMoved(GraphicsComponent*)), this, SLOT(componentMoved(GraphicsComponent*)));
QObject::connect(second, SIGNAL(itemMoved(GraphicsComponent*)), this, SLOT(componentMoved(GraphicsComponent*)));
rebuildPath();
}
void WireConnection::rebuildPath()
{
QPointF firstPos = first->pos();
QPointF secondPos = second->pos();
QPointF intermediate;
intermediate.setX(first->x());
intermediate.setY(second->y());
for(QList<QGraphicsLineItem*>::iterator i = path.begin(); i != path.end();i++)
{
this->removeFromGroup(*i);
}
qDeleteAll(this->path);
this->path.clear();
this->path.append(new QGraphicsLineItem(QLineF(firstPos, intermediate)));
this->path.append(new QGraphicsLineItem(QLineF(intermediate, secondPos)));
for(QList<QGraphicsLineItem*>::iterator i = path.begin(); i != path.end();i++)
{
this->addToGroup(*i);
}
}
void WireConnection::componentMoved(GraphicsComponent *moved)
{
rebuildPath();
}