blob: bbd758083c5fce1a2f86f70fea6812c91c6543c7 (
plain)
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
|
// Copyright (C) 2008 Lukas Lalinsky
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include "connector.h"
#include "diagramdocument.h"
#include "hub.h"
#include "line.h"
Connector::Connector(Line *owner)
: m_owner(owner), m_hub(NULL)
{
}
Line *
Connector::owner() const
{
return m_owner;
}
QPointF
Connector::pos() const
{
return m_pos;
}
void
Connector::setPos(const QPointF &pos)
{
if (m_pos != pos) {
m_pos = pos;
if (m_owner->document())
m_owner->document()->updateLineLayout(m_owner);
}
}
qreal
Connector::angle() const
{
return m_angle;
}
void
Connector::setAngle(qreal angle)
{
if (m_angle != angle) {
m_angle = angle;
if (m_owner->document())
m_owner->document()->updateLineLayout(m_owner);
}
}
Hub *
Connector::hub() const
{
return m_hub;
}
void
Connector::setHub(Hub *hub)
{
removeFromHub();
m_hub = hub;
addToHub();
}
bool
Connector::isConnected() const
{
return m_hub;
}
DiagramObject *
Connector::connectedObject() const
{
if (isConnected())
return hub()->owner();
return NULL;
}
Connector *
Connector::otherEnd() const
{
Line *conn = owner();
if (conn->connector(0) == this) {
return conn->connector(1);
}
else {
return conn->connector(0);
}
}
void
Connector::addToHub()
{
if (m_hub)
m_hub->addConnector(this);
}
void
Connector::removeFromHub()
{
if (m_hub)
m_hub->removeConnector(this);
}
|