Menu

[557893]: / xlinkobj.cpp  Maximize  Restore  History

Download this file

203 lines (173 with data), 4.4 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
 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include <QDebug>
#include "xlinkobj.h"
#include "branchobj.h"
#include "branchitem.h"
#include "math.h" // atan
#include "misc.h" // max
/////////////////////////////////////////////////////////////////
// XLinkObj
/////////////////////////////////////////////////////////////////
int XLinkObj::arrowSize=10; // make instances
XLinkObj::XLinkObj (QGraphicsScene* scene,Link *l):MapObj(scene)
{
//qDebug()<< "Const XLinkObj (s,Link)";
link=l;
init();
}
XLinkObj::~XLinkObj ()
{
//qDebug() << "Destr XLinkObj";
delete (line);
delete (poly);
}
void XLinkObj::init ()
{
visBranch=NULL;
pen.setColor ( link->getColor() );
pen.setWidth ( link->getWidth() );
pen.setCapStyle ( Qt::RoundCap );
line=scene->addLine(QLineF(1,1,1,1),pen);
line->setZValue (Z_INIT);
poly=scene->addPolygon(QPolygonF(),pen, link->getColor()); //FIXME-2 needed???
poly->setZValue (Z_INIT);
setVisibility (true);
}
void XLinkObj::setEnd (QPointF p)
{
endPos=p;
}
void XLinkObj::updateXLink()
{
QPointF a,b;
QPolygonF pa;
if (visBranch)
{
// Only one of the linked branches is visible
BranchObj *bo=(BranchObj*)(visBranch->getLMO());
if (!bo) return;
a=b=bo->getChildPos();
if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
{
b.setX (b.x()+25);
pa.clear();
pa<< QPointF(b.x(),b.y())<<
QPointF(b.x()-arrowSize,b.y()-arrowSize)<<
QPointF(b.x()-arrowSize,b.y()+arrowSize);
poly->setPolygon(pa);
} else
{
b.setX (b.x()-25);
pa.clear();
pa<< QPointF(b.x(),b.y())<<
QPointF(b.x()+arrowSize,b.y()-arrowSize)<<
QPointF(b.x()+arrowSize,b.y()+arrowSize);
poly->setPolygon (pa);
}
} else
{
// Both linked branches are visible
BranchItem *bi=link->getBeginBranch();
if ( bi)
{
// If a link is just drawn in the editor,
// we have already a beginBranch
BranchObj *bo=(BranchObj*)(bi->getLMO());
if (bo)
a=bo->getChildPos();
else
return;
}
else
// This shouldn't be reached normally...
a=beginPos;
bi=link->getEndBranch();
if (bi)
{
BranchObj *bo=(BranchObj*)(bi->getLMO());
if (bo)
b=bo->getChildPos();
else
return;
}
else
b=endPos;
}
beginPos=a;
endPos=b;
// Recalc clickBox
qreal w= - getAngle (b-a);
QPointF v(0,1);
QPointF vn(v.x()*cos (w) - v.y()*sin(w),v.y()*cos (w) + v.x()*sin(w));
clickPoly.clear();
clickPoly << a + vn *clickBorder;
clickPoly << b + vn *clickBorder;
clickPoly << b - vn *clickBorder;
clickPoly << a - vn *clickBorder;
pen.setColor ( link->getColor() );
pen.setWidth ( link->getWidth() );
poly->setBrush (link->getColor() );
line->setPen (pen);
line->setLine(a.x(), a.y(), b.x(), b.y());
BranchItem *bi_begin=link->getBeginBranch();
BranchItem *bi_end =link->getEndBranch();
if (bi_begin && bi_end && link->getState()==Link::activeXLink)
// FIXME-2 z-values: it may happen, that XLink is hidden below a separate rectFrame. Could lead to jumping on releasing mouse button
line->setZValue (dZ_DEPTH * max(bi_begin->depth(),bi_end->depth()) + dZ_XLINK);
else
line->setZValue (Z_INIT);
}
void XLinkObj::positionBBox()
{
}
void XLinkObj::calcBBoxSize()
{
}
void XLinkObj::setVisibility (bool b)
{
MapObj::setVisibility (b);
if (b)
{
line->show();
if (visBranch)
poly->show();
else
poly->hide();
}
else
{
line->hide();
poly->hide();
}
}
void XLinkObj::setVisibility ()
{
BranchItem* beginBI=link->getBeginBranch();
BranchObj* beginBO=NULL;
if (beginBI) beginBO=(BranchObj*)(beginBI->getLMO());
BranchObj* endBO=NULL;
BranchItem* endBI=link->getEndBranch();
if (endBI) endBO=(BranchObj*)(endBI->getLMO());
if (beginBO && endBO)
{
if(beginBO->isVisibleObj() && endBO->isVisibleObj())
{ // Both ends are visible
visBranch=NULL;
setVisibility (true);
} else
{
if(!beginBO->isVisibleObj() && !endBO->isVisibleObj())
{ //None of the ends is visible
visBranch=NULL;
setVisibility (false);
} else
{ // Just one end is visible, draw a symbol that shows
// that there is a link to a scrolled branch
if (beginBO->isVisibleObj())
visBranch=beginBI;
else
visBranch=endBI;
setVisibility (true);
}
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.