insilmaril@721
|
1 |
#include <iostream>
|
insilmaril@139
|
2 |
#include <math.h>
|
insilmaril@139
|
3 |
|
insilmaril@0
|
4 |
#include "linkablemapobj.h"
|
insilmaril@0
|
5 |
#include "branchobj.h"
|
insilmaril@721
|
6 |
#include "vymmodel.h"
|
insilmaril@721
|
7 |
|
insilmaril@721
|
8 |
using namespace std;
|
insilmaril@0
|
9 |
|
insilmaril@0
|
10 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
11 |
// LinkableMapObj
|
insilmaril@0
|
12 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
13 |
|
insilmaril@790
|
14 |
/* FIXME-3
|
insilmaril@0
|
15 |
LinkableMapObj::LinkableMapObj():MapObj()
|
insilmaril@0
|
16 |
{
|
insilmaril@0
|
17 |
// cout << "Const LinkableMapObj ()\n";
|
insilmaril@0
|
18 |
init ();
|
insilmaril@0
|
19 |
}
|
insilmaril@790
|
20 |
*/
|
insilmaril@0
|
21 |
|
insilmaril@790
|
22 |
LinkableMapObj::LinkableMapObj(QGraphicsScene* s, TreeItem *ti) :MapObj(s,ti)
|
insilmaril@0
|
23 |
{
|
insilmaril@790
|
24 |
// cout << "Const LinkableMapObj s="<<s<<" ti="<<ti<<" treeItem="<<treeItem<<endl;
|
insilmaril@0
|
25 |
init ();
|
insilmaril@0
|
26 |
}
|
insilmaril@0
|
27 |
|
insilmaril@408
|
28 |
LinkableMapObj::LinkableMapObj (LinkableMapObj* lmo) : MapObj (lmo->scene)
|
insilmaril@0
|
29 |
{
|
insilmaril@0
|
30 |
copy (lmo);
|
insilmaril@0
|
31 |
}
|
insilmaril@0
|
32 |
|
insilmaril@0
|
33 |
LinkableMapObj::~LinkableMapObj()
|
insilmaril@0
|
34 |
{
|
insilmaril@791
|
35 |
//cout << "Destructor LMO\n";
|
insilmaril@0
|
36 |
delete (bottomline);
|
insilmaril@0
|
37 |
delLink();
|
insilmaril@0
|
38 |
}
|
insilmaril@0
|
39 |
|
insilmaril@0
|
40 |
void LinkableMapObj::delLink()
|
insilmaril@0
|
41 |
{
|
insilmaril@798
|
42 |
//bottomline->hide();
|
insilmaril@0
|
43 |
switch (style)
|
insilmaril@0
|
44 |
{
|
insilmaril@473
|
45 |
case Line:
|
insilmaril@0
|
46 |
delete (l);
|
insilmaril@0
|
47 |
break;
|
insilmaril@473
|
48 |
case Parabel:
|
insilmaril@406
|
49 |
while (!segment.isEmpty()) delete segment.takeFirst();
|
insilmaril@0
|
50 |
break;
|
insilmaril@473
|
51 |
case PolyLine:
|
insilmaril@0
|
52 |
delete (p);
|
insilmaril@0
|
53 |
break;
|
insilmaril@473
|
54 |
case PolyParabel:
|
insilmaril@0
|
55 |
delete (p);
|
insilmaril@0
|
56 |
break;
|
insilmaril@0
|
57 |
default:
|
insilmaril@0
|
58 |
break;
|
insilmaril@0
|
59 |
}
|
insilmaril@0
|
60 |
}
|
insilmaril@0
|
61 |
|
insilmaril@0
|
62 |
void LinkableMapObj::init ()
|
insilmaril@0
|
63 |
{
|
insilmaril@0
|
64 |
parObj=NULL;
|
insilmaril@0
|
65 |
parObjTmpBuf=NULL;
|
insilmaril@798
|
66 |
tmpParent=false;
|
insilmaril@408
|
67 |
parPos=QPointF(0,0);
|
insilmaril@408
|
68 |
childPos=QPointF(0,0);
|
insilmaril@0
|
69 |
link2ParPos=false;
|
insilmaril@0
|
70 |
l=NULL;
|
insilmaril@727
|
71 |
p=NULL;
|
insilmaril@473
|
72 |
orientation=UndefinedOrientation;
|
insilmaril@0
|
73 |
linkwidth=20;
|
insilmaril@0
|
74 |
thickness_start=8;
|
insilmaril@473
|
75 |
style=UndefinedStyle;
|
insilmaril@473
|
76 |
linkpos=Bottom;
|
insilmaril@0
|
77 |
arcsegs=13;
|
insilmaril@0
|
78 |
|
insilmaril@412
|
79 |
// TODO instead of linkcolor pen.color() could be used all around
|
insilmaril@408
|
80 |
pen.setWidth (1);
|
insilmaril@408
|
81 |
pen.setColor (linkcolor);
|
insilmaril@408
|
82 |
pen.setCapStyle ( Qt::RoundCap );
|
insilmaril@798
|
83 |
|
insilmaril@798
|
84 |
useBottomline=true;
|
insilmaril@408
|
85 |
bottomline=scene->addLine(QLineF(1,1,1,1),pen);
|
insilmaril@408
|
86 |
bottomline->setZValue(Z_LINK);
|
insilmaril@0
|
87 |
bottomline->show();
|
insilmaril@0
|
88 |
|
insilmaril@175
|
89 |
topPad=botPad=leftPad=rightPad=0;
|
insilmaril@175
|
90 |
|
insilmaril@0
|
91 |
repositionRequest=false;
|
insilmaril@218
|
92 |
|
insilmaril@218
|
93 |
// Rel Positions
|
insilmaril@408
|
94 |
relPos=QPointF(0,0);
|
insilmaril@250
|
95 |
useRelPos=false;
|
insilmaril@0
|
96 |
}
|
insilmaril@0
|
97 |
|
insilmaril@0
|
98 |
void LinkableMapObj::copy (LinkableMapObj* other)
|
insilmaril@0
|
99 |
{
|
insilmaril@0
|
100 |
MapObj::copy(other);
|
insilmaril@0
|
101 |
bboxTotal=other->bboxTotal;
|
insilmaril@0
|
102 |
setLinkStyle(other->style);
|
insilmaril@0
|
103 |
setLinkColor (other->linkcolor);
|
insilmaril@218
|
104 |
relPos=other->relPos;
|
insilmaril@726
|
105 |
treeItem=other->treeItem;
|
insilmaril@726
|
106 |
}
|
insilmaril@726
|
107 |
|
insilmaril@0
|
108 |
void LinkableMapObj::setParObj(LinkableMapObj* o)
|
insilmaril@0
|
109 |
{
|
insilmaril@0
|
110 |
parObj=o;
|
insilmaril@0
|
111 |
}
|
insilmaril@0
|
112 |
|
insilmaril@746
|
113 |
void LinkableMapObj::setParObjTmp(LinkableMapObj*,QPointF,int) // FIXME-3 make pure virtual
|
insilmaril@0
|
114 |
{
|
insilmaril@0
|
115 |
}
|
insilmaril@0
|
116 |
|
insilmaril@746
|
117 |
void LinkableMapObj::unsetParObjTmp() // FIXME-3 make pure virtual
|
insilmaril@0
|
118 |
{
|
insilmaril@0
|
119 |
}
|
insilmaril@0
|
120 |
|
insilmaril@164
|
121 |
bool LinkableMapObj::hasParObjTmp()
|
insilmaril@164
|
122 |
{
|
insilmaril@798
|
123 |
return tmpParent;
|
insilmaril@164
|
124 |
}
|
insilmaril@164
|
125 |
|
insilmaril@218
|
126 |
void LinkableMapObj::setUseRelPos (const bool &b)
|
insilmaril@218
|
127 |
{
|
insilmaril@218
|
128 |
useRelPos=b;
|
insilmaril@218
|
129 |
}
|
insilmaril@218
|
130 |
|
insilmaril@835
|
131 |
bool LinkableMapObj::getUseRelPos ()
|
insilmaril@835
|
132 |
{
|
insilmaril@835
|
133 |
return useRelPos;
|
insilmaril@835
|
134 |
}
|
insilmaril@835
|
135 |
|
insilmaril@218
|
136 |
void LinkableMapObj::setRelPos()
|
insilmaril@218
|
137 |
{
|
insilmaril@218
|
138 |
if (parObj)
|
insilmaril@218
|
139 |
{
|
insilmaril@836
|
140 |
setRelPos (absPos - parObj->getChildPos() );
|
insilmaril@836
|
141 |
} else
|
insilmaril@836
|
142 |
qWarning ("LMO::setRelPos() parObj==0");
|
insilmaril@218
|
143 |
}
|
insilmaril@218
|
144 |
|
insilmaril@408
|
145 |
void LinkableMapObj::setRelPos(const QPointF &p)
|
insilmaril@218
|
146 |
{
|
insilmaril@218
|
147 |
if (parObj)
|
insilmaril@388
|
148 |
{
|
insilmaril@836
|
149 |
relPos=p;
|
insilmaril@836
|
150 |
useRelPos=true;
|
insilmaril@388
|
151 |
parObj->calcBBoxSize();
|
insilmaril@388
|
152 |
requestReposition();
|
insilmaril@836
|
153 |
} else
|
insilmaril@836
|
154 |
qWarning ("LMO::setRelPos (p) parObj==0");
|
insilmaril@218
|
155 |
}
|
insilmaril@218
|
156 |
|
insilmaril@408
|
157 |
QPointF LinkableMapObj::getRelPos()
|
insilmaril@366
|
158 |
{
|
insilmaril@835
|
159 |
if (!parObj)
|
insilmaril@835
|
160 |
{
|
insilmaril@835
|
161 |
qWarning("LMO::getRelPos parObj==0");
|
insilmaril@835
|
162 |
return QPointF();
|
insilmaril@835
|
163 |
}
|
insilmaril@366
|
164 |
return relPos;
|
insilmaril@366
|
165 |
}
|
insilmaril@366
|
166 |
|
insilmaril@408
|
167 |
qreal LinkableMapObj::getTopPad()
|
insilmaril@175
|
168 |
{
|
insilmaril@175
|
169 |
return topPad;
|
insilmaril@175
|
170 |
}
|
insilmaril@175
|
171 |
|
insilmaril@408
|
172 |
qreal LinkableMapObj::getLeftPad()
|
insilmaril@175
|
173 |
{
|
insilmaril@175
|
174 |
return leftPad;
|
insilmaril@175
|
175 |
}
|
insilmaril@175
|
176 |
|
insilmaril@408
|
177 |
qreal LinkableMapObj::getRightPad()
|
insilmaril@175
|
178 |
{
|
insilmaril@175
|
179 |
return rightPad;
|
insilmaril@175
|
180 |
}
|
insilmaril@175
|
181 |
|
insilmaril@786
|
182 |
LinkableMapObj::Style LinkableMapObj::getDefLinkStyle (TreeItem *parent)
|
insilmaril@0
|
183 |
{
|
insilmaril@773
|
184 |
VymModel *model=treeItem->getModel();
|
insilmaril@721
|
185 |
if (!model)
|
insilmaril@721
|
186 |
{
|
insilmaril@721
|
187 |
qWarning ("LMO::getDefLinkStyle model=NULL");
|
insilmaril@727
|
188 |
//return UndefinedStyle;
|
insilmaril@721
|
189 |
}
|
insilmaril@721
|
190 |
Style ls=model->getMapLinkStyle();
|
insilmaril@786
|
191 |
int depth=1+parent->depth();
|
insilmaril@727
|
192 |
if (depth==0) return UndefinedStyle;
|
insilmaril@0
|
193 |
switch (ls)
|
insilmaril@0
|
194 |
{
|
insilmaril@473
|
195 |
case Line:
|
insilmaril@0
|
196 |
return ls;
|
insilmaril@0
|
197 |
break;
|
insilmaril@473
|
198 |
case Parabel:
|
insilmaril@0
|
199 |
return ls;
|
insilmaril@0
|
200 |
break;
|
insilmaril@473
|
201 |
case PolyLine:
|
insilmaril@0
|
202 |
if (depth>1)
|
insilmaril@473
|
203 |
return Line;
|
insilmaril@0
|
204 |
else
|
insilmaril@0
|
205 |
return ls;
|
insilmaril@0
|
206 |
break;
|
insilmaril@473
|
207 |
case PolyParabel:
|
insilmaril@0
|
208 |
if (depth>1)
|
insilmaril@473
|
209 |
return Parabel;
|
insilmaril@0
|
210 |
else
|
insilmaril@0
|
211 |
return ls;
|
insilmaril@0
|
212 |
break;
|
insilmaril@0
|
213 |
default:
|
insilmaril@0
|
214 |
break;
|
insilmaril@0
|
215 |
}
|
insilmaril@473
|
216 |
return UndefinedStyle;
|
insilmaril@0
|
217 |
}
|
insilmaril@0
|
218 |
|
insilmaril@473
|
219 |
void LinkableMapObj::setLinkStyle(Style newstyle)
|
insilmaril@0
|
220 |
{
|
insilmaril@0
|
221 |
delLink();
|
insilmaril@0
|
222 |
|
insilmaril@0
|
223 |
style=newstyle;
|
insilmaril@0
|
224 |
|
insilmaril@773
|
225 |
if (parObj != NULL)
|
insilmaril@0
|
226 |
{
|
insilmaril@408
|
227 |
QGraphicsLineItem *cl;
|
insilmaril@0
|
228 |
switch (style)
|
insilmaril@0
|
229 |
{
|
insilmaril@473
|
230 |
case UndefinedStyle:
|
insilmaril@0
|
231 |
bottomline->hide();
|
insilmaril@0
|
232 |
break;
|
insilmaril@473
|
233 |
case Line:
|
insilmaril@408
|
234 |
l = scene->addLine(QLineF(1,1,1,1),pen);
|
insilmaril@408
|
235 |
l->setZValue(Z_LINK);
|
insilmaril@0
|
236 |
if (visible)
|
insilmaril@0
|
237 |
l->show();
|
insilmaril@0
|
238 |
else
|
insilmaril@0
|
239 |
l->hide();
|
insilmaril@0
|
240 |
break;
|
insilmaril@473
|
241 |
case Parabel:
|
insilmaril@408
|
242 |
for (int i=0;i<arcsegs;i++)
|
insilmaril@0
|
243 |
{
|
insilmaril@408
|
244 |
cl = scene->addLine(QLineF(i*5,0,i*10,100),pen);
|
insilmaril@408
|
245 |
cl->setZValue(Z_LINK);
|
insilmaril@0
|
246 |
if (visible)
|
insilmaril@0
|
247 |
cl->show();
|
insilmaril@0
|
248 |
else
|
insilmaril@0
|
249 |
cl->hide();
|
insilmaril@0
|
250 |
segment.append(cl);
|
insilmaril@0
|
251 |
}
|
insilmaril@0
|
252 |
pa0.resize (arcsegs+1);
|
insilmaril@0
|
253 |
break;
|
insilmaril@473
|
254 |
case PolyLine:
|
insilmaril@408
|
255 |
p =scene->addPolygon(QPolygonF(),pen,linkcolor);
|
insilmaril@408
|
256 |
p->setZValue(Z_LINK);
|
insilmaril@0
|
257 |
if (visible)
|
insilmaril@0
|
258 |
p->show();
|
insilmaril@0
|
259 |
else
|
insilmaril@0
|
260 |
p->hide();
|
insilmaril@0
|
261 |
pa0.resize (3);
|
insilmaril@0
|
262 |
break;
|
insilmaril@473
|
263 |
case PolyParabel:
|
insilmaril@408
|
264 |
p = scene->addPolygon(QPolygonF(),pen,linkcolor);
|
insilmaril@408
|
265 |
p->setZValue(Z_LINK);
|
insilmaril@0
|
266 |
if (visible)
|
insilmaril@0
|
267 |
p->show();
|
insilmaril@0
|
268 |
else
|
insilmaril@0
|
269 |
p->hide();
|
insilmaril@0
|
270 |
pa0.resize (arcsegs*2+2);
|
insilmaril@0
|
271 |
pa1.resize (arcsegs+1);
|
insilmaril@0
|
272 |
pa2.resize (arcsegs+1);
|
insilmaril@0
|
273 |
break;
|
insilmaril@0
|
274 |
default:
|
insilmaril@0
|
275 |
break;
|
insilmaril@0
|
276 |
}
|
insilmaril@164
|
277 |
}
|
insilmaril@0
|
278 |
}
|
insilmaril@0
|
279 |
|
insilmaril@473
|
280 |
LinkableMapObj::Style LinkableMapObj::getLinkStyle()
|
insilmaril@0
|
281 |
{
|
insilmaril@0
|
282 |
return style;
|
insilmaril@0
|
283 |
}
|
insilmaril@0
|
284 |
|
insilmaril@473
|
285 |
void LinkableMapObj::setLinkPos(Position lp)
|
insilmaril@0
|
286 |
{
|
insilmaril@0
|
287 |
linkpos=lp;
|
insilmaril@0
|
288 |
}
|
insilmaril@0
|
289 |
|
insilmaril@473
|
290 |
LinkableMapObj::Position LinkableMapObj::getLinkPos()
|
insilmaril@0
|
291 |
{
|
insilmaril@0
|
292 |
return linkpos;
|
insilmaril@0
|
293 |
}
|
insilmaril@0
|
294 |
|
insilmaril@0
|
295 |
void LinkableMapObj::setLinkColor()
|
insilmaril@0
|
296 |
{
|
insilmaril@721
|
297 |
// Overloaded in BranchObj and children
|
insilmaril@0
|
298 |
// here only set default color
|
insilmaril@773
|
299 |
VymModel *model=treeItem->getModel();
|
insilmaril@721
|
300 |
if (model)
|
insilmaril@721
|
301 |
setLinkColor (model->getMapDefLinkColor());
|
insilmaril@0
|
302 |
}
|
insilmaril@0
|
303 |
|
insilmaril@0
|
304 |
void LinkableMapObj::setLinkColor(QColor col)
|
insilmaril@0
|
305 |
{
|
insilmaril@0
|
306 |
linkcolor=col;
|
insilmaril@408
|
307 |
pen.setColor(col);
|
insilmaril@408
|
308 |
bottomline->setPen( pen );
|
insilmaril@0
|
309 |
switch (style)
|
insilmaril@0
|
310 |
{
|
insilmaril@473
|
311 |
case Line:
|
insilmaril@408
|
312 |
l->setPen( pen);
|
insilmaril@0
|
313 |
break;
|
insilmaril@473
|
314 |
case Parabel:
|
insilmaril@406
|
315 |
for (int i=0; i<segment.size(); ++i)
|
insilmaril@408
|
316 |
segment.at(i)->setPen( pen);
|
insilmaril@0
|
317 |
break;
|
insilmaril@473
|
318 |
case PolyLine:
|
insilmaril@0
|
319 |
p->setBrush( QBrush(col));
|
insilmaril@497
|
320 |
p->setPen( pen);
|
insilmaril@0
|
321 |
break;
|
insilmaril@473
|
322 |
case PolyParabel:
|
insilmaril@0
|
323 |
p->setBrush( QBrush(col));
|
insilmaril@497
|
324 |
p->setPen( pen);
|
insilmaril@0
|
325 |
break;
|
insilmaril@0
|
326 |
default:
|
insilmaril@0
|
327 |
break;
|
insilmaril@755
|
328 |
}
|
insilmaril@0
|
329 |
}
|
insilmaril@0
|
330 |
|
insilmaril@0
|
331 |
QColor LinkableMapObj::getLinkColor()
|
insilmaril@0
|
332 |
{
|
insilmaril@0
|
333 |
return linkcolor;
|
insilmaril@0
|
334 |
}
|
insilmaril@0
|
335 |
|
insilmaril@0
|
336 |
void LinkableMapObj::setVisibility (bool v)
|
insilmaril@0
|
337 |
{
|
insilmaril@0
|
338 |
MapObj::setVisibility (v);
|
insilmaril@779
|
339 |
updateVisibility();
|
insilmaril@779
|
340 |
}
|
insilmaril@779
|
341 |
|
insilmaril@779
|
342 |
void LinkableMapObj::setOrientation()
|
insilmaril@779
|
343 |
{
|
insilmaril@779
|
344 |
Orientation orientOld=orientation;
|
insilmaril@779
|
345 |
|
insilmaril@779
|
346 |
if (!parObj)
|
insilmaril@779
|
347 |
{
|
insilmaril@779
|
348 |
orientation=UndefinedOrientation;
|
insilmaril@779
|
349 |
return;
|
insilmaril@779
|
350 |
}
|
insilmaril@779
|
351 |
|
insilmaril@779
|
352 |
// Set orientation, first look for orientation of parent
|
insilmaril@779
|
353 |
if (parObj->getOrientation() != UndefinedOrientation )
|
insilmaril@779
|
354 |
// use the orientation of the parent:
|
insilmaril@779
|
355 |
orientation=parObj->getOrientation();
|
insilmaril@779
|
356 |
else
|
insilmaril@779
|
357 |
{
|
insilmaril@779
|
358 |
// calc orientation depending on position rel to parent
|
insilmaril@779
|
359 |
if (absPos.x() < QPointF(parObj->getChildPos() ).x() )
|
insilmaril@779
|
360 |
orientation=LeftOfCenter;
|
insilmaril@779
|
361 |
else
|
insilmaril@779
|
362 |
orientation=RightOfCenter;
|
insilmaril@779
|
363 |
}
|
insilmaril@779
|
364 |
if (orientOld!=orientation) requestReposition();
|
insilmaril@779
|
365 |
}
|
insilmaril@779
|
366 |
|
insilmaril@779
|
367 |
void LinkableMapObj::updateVisibility()
|
insilmaril@779
|
368 |
{
|
insilmaril@160
|
369 |
bool visnow=visible;
|
insilmaril@260
|
370 |
|
insilmaril@779
|
371 |
if (((MapItem*)treeItem)->getHideLinkUnselected()
|
insilmaril@779
|
372 |
&& treeItem->getModel()->getSelectedLMO() !=this)
|
insilmaril@160
|
373 |
visnow=false;
|
insilmaril@160
|
374 |
|
insilmaril@160
|
375 |
if (visnow)
|
insilmaril@0
|
376 |
{
|
insilmaril@798
|
377 |
if (useBottomline)
|
insilmaril@798
|
378 |
bottomline->show();
|
insilmaril@798
|
379 |
else
|
insilmaril@798
|
380 |
bottomline->hide();
|
insilmaril@798
|
381 |
|
insilmaril@160
|
382 |
switch (style)
|
insilmaril@0
|
383 |
{
|
insilmaril@473
|
384 |
case Line:
|
insilmaril@160
|
385 |
if (l) l->show();
|
insilmaril@160
|
386 |
break;
|
insilmaril@473
|
387 |
case Parabel:
|
insilmaril@406
|
388 |
for (int i=0; i<segment.size(); ++i)
|
insilmaril@406
|
389 |
segment.at(i)->show();
|
insilmaril@160
|
390 |
break;
|
insilmaril@473
|
391 |
case PolyLine:
|
insilmaril@779
|
392 |
if (!p) cout << "LMO::updateVis p==0 (PolyLine)\n"; //FIXME-3
|
insilmaril@160
|
393 |
if (p) p->show();
|
insilmaril@160
|
394 |
break;
|
insilmaril@473
|
395 |
case PolyParabel:
|
insilmaril@779
|
396 |
if (!p) cout << "LMO::updateVis p==0 (PolyParabel) "<<treeItem->getHeading().toStdString()<<endl; //FIXME-3
|
insilmaril@160
|
397 |
if (p) p->show();
|
insilmaril@160
|
398 |
break;
|
insilmaril@160
|
399 |
default:
|
insilmaril@160
|
400 |
break;
|
insilmaril@160
|
401 |
}
|
insilmaril@0
|
402 |
} else
|
insilmaril@0
|
403 |
{
|
insilmaril@0
|
404 |
bottomline->hide();
|
insilmaril@160
|
405 |
switch (style)
|
insilmaril@0
|
406 |
{
|
insilmaril@473
|
407 |
case Line:
|
insilmaril@160
|
408 |
if (l) l->hide();
|
insilmaril@160
|
409 |
break;
|
insilmaril@473
|
410 |
case Parabel:
|
insilmaril@406
|
411 |
for (int i=0; i<segment.size(); ++i)
|
insilmaril@406
|
412 |
segment.at(i)->hide();
|
insilmaril@160
|
413 |
break;
|
insilmaril@473
|
414 |
case PolyLine:
|
insilmaril@160
|
415 |
if (p) p->hide();
|
insilmaril@160
|
416 |
break;
|
insilmaril@473
|
417 |
case PolyParabel:
|
insilmaril@160
|
418 |
if (p) p->hide();
|
insilmaril@160
|
419 |
break;
|
insilmaril@160
|
420 |
default:
|
insilmaril@160
|
421 |
break;
|
insilmaril@160
|
422 |
}
|
insilmaril@0
|
423 |
}
|
insilmaril@0
|
424 |
}
|
insilmaril@0
|
425 |
|
insilmaril@779
|
426 |
void LinkableMapObj::updateLinkGeometry()
|
insilmaril@0
|
427 |
{
|
insilmaril@0
|
428 |
// needs:
|
insilmaril@0
|
429 |
// childPos of parent
|
insilmaril@0
|
430 |
// orient of parent
|
insilmaril@0
|
431 |
// style
|
insilmaril@0
|
432 |
//
|
insilmaril@0
|
433 |
// sets:
|
insilmaril@0
|
434 |
// orientation
|
insilmaril@225
|
435 |
// childPos (by calling setDockPos())
|
insilmaril@225
|
436 |
// parPos (by calling setDockPos())
|
insilmaril@175
|
437 |
// bottomlineY
|
insilmaril@0
|
438 |
// drawing of the link itself
|
insilmaril@0
|
439 |
|
insilmaril@779
|
440 |
// updateLinkGeometry is called from move, but called from constructor we don't
|
insilmaril@0
|
441 |
// have parents yet...
|
insilmaril@775
|
442 |
|
insilmaril@816
|
443 |
//cout <<"LMO::updateLinkGeometry: "<<treeItem->getHeadingStd()<<" "<<parObj<<endl;
|
insilmaril@775
|
444 |
if (!parObj)
|
insilmaril@775
|
445 |
{
|
insilmaril@775
|
446 |
// If I am a mapcenter, set childPos to middle of MapCenterObj
|
insilmaril@775
|
447 |
childPos.setX( clickBox.topLeft().x() + clickBox.width()/2 );
|
insilmaril@775
|
448 |
childPos.setY( clickBox.topLeft().y() + clickBox.height()/2 );
|
insilmaril@775
|
449 |
parPos=childPos;
|
insilmaril@775
|
450 |
// Redraw links to children
|
insilmaril@775
|
451 |
for (int i=0; i<treeItem->branchCount(); ++i)
|
insilmaril@779
|
452 |
treeItem->getBranchObjNum(i)->updateLinkGeometry();
|
insilmaril@775
|
453 |
return;
|
insilmaril@775
|
454 |
}
|
insilmaril@775
|
455 |
|
insilmaril@473
|
456 |
if (style==UndefinedStyle) return;
|
insilmaril@0
|
457 |
|
insilmaril@0
|
458 |
switch (linkpos)
|
insilmaril@0
|
459 |
{
|
insilmaril@473
|
460 |
case Middle:
|
insilmaril@442
|
461 |
bottomlineY=bbox.top() + bbox.height()/2; // draw link to middle (of frame)
|
insilmaril@0
|
462 |
break;
|
insilmaril@473
|
463 |
case Bottom:
|
insilmaril@785
|
464 |
//bottomlineY=bbox.bottom()-1; // draw link to bottom of box
|
insilmaril@785
|
465 |
bottomlineY=bbox.bottom()-botPad;
|
insilmaril@0
|
466 |
break;
|
insilmaril@0
|
467 |
}
|
insilmaril@0
|
468 |
|
insilmaril@0
|
469 |
double p2x,p2y; // Set P2 Before setting
|
insilmaril@0
|
470 |
if (!link2ParPos)
|
insilmaril@0
|
471 |
{
|
insilmaril@408
|
472 |
p2x=QPointF( parObj->getChildPos() ).x(); // P1, we have to look at
|
insilmaril@408
|
473 |
p2y=QPointF( parObj->getChildPos() ).y(); // orientation
|
insilmaril@0
|
474 |
} else
|
insilmaril@0
|
475 |
{
|
insilmaril@408
|
476 |
p2x=QPointF( parObj->getParPos() ).x();
|
insilmaril@408
|
477 |
p2y=QPointF( parObj->getParPos() ).y();
|
insilmaril@0
|
478 |
}
|
insilmaril@0
|
479 |
|
insilmaril@388
|
480 |
setDockPos(); // Call overloaded method
|
insilmaril@393
|
481 |
setOrientation();
|
insilmaril@0
|
482 |
|
insilmaril@0
|
483 |
double p1x=parPos.x(); // Link is drawn from P1 to P2
|
insilmaril@0
|
484 |
double p1y=parPos.y();
|
insilmaril@0
|
485 |
|
insilmaril@0
|
486 |
double vx=p2x - p1x; // V=P2-P1
|
insilmaril@0
|
487 |
double vy=p2y - p1y;
|
insilmaril@0
|
488 |
|
insilmaril@0
|
489 |
// Draw the horizontal line below heading (from ChildPos to ParPos)
|
insilmaril@408
|
490 |
bottomline->setLine (QLine (qRound(childPos.x()),
|
insilmaril@104
|
491 |
qRound(childPos.y()),
|
insilmaril@104
|
492 |
qRound(p1x),
|
insilmaril@408
|
493 |
qRound(p1y) ));
|
insilmaril@0
|
494 |
|
insilmaril@0
|
495 |
double a; // angle
|
insilmaril@0
|
496 |
if (vx > -0.000001 && vx < 0.000001)
|
insilmaril@0
|
497 |
a=M_PI_2;
|
insilmaril@0
|
498 |
else
|
insilmaril@0
|
499 |
a=atan( vy / vx );
|
insilmaril@0
|
500 |
// "turning point" for drawing polygonal links
|
insilmaril@408
|
501 |
QPointF tp (-qRound(sin (a)*thickness_start), qRound(cos (a)*thickness_start));
|
insilmaril@0
|
502 |
|
insilmaril@0
|
503 |
// Draw the link
|
insilmaril@0
|
504 |
switch (style)
|
insilmaril@0
|
505 |
{
|
insilmaril@473
|
506 |
case Line:
|
insilmaril@408
|
507 |
l->setLine( QLine(qRound (parPos.x()),
|
insilmaril@104
|
508 |
qRound(parPos.y()),
|
insilmaril@104
|
509 |
qRound(p2x),
|
insilmaril@408
|
510 |
qRound(p2y) ));
|
insilmaril@0
|
511 |
break;
|
insilmaril@473
|
512 |
case Parabel:
|
insilmaril@0
|
513 |
parabel (pa0, p1x,p1y,p2x,p2y);
|
insilmaril@406
|
514 |
for (int i=0; i<segment.size(); ++i)
|
insilmaril@408
|
515 |
segment.at(i)->setLine(QLineF( pa0.at(i).x(), pa0.at(i).y(),pa0.at(i+1).x(),pa0.at(i+1).y()));
|
insilmaril@0
|
516 |
break;
|
insilmaril@473
|
517 |
case PolyLine:
|
insilmaril@408
|
518 |
pa0.clear();
|
insilmaril@408
|
519 |
pa0<<QPointF (qRound(p2x+tp.x()), qRound(p2y+tp.y()));
|
insilmaril@408
|
520 |
pa0<<QPointF (qRound(p2x-tp.x()), qRound(p2y-tp.y()));
|
insilmaril@408
|
521 |
pa0<<QPointF (qRound (parPos.x()), qRound(parPos.y()) );
|
insilmaril@408
|
522 |
p->setPolygon(QPolygonF (pa0));
|
insilmaril@0
|
523 |
break;
|
insilmaril@473
|
524 |
case PolyParabel:
|
insilmaril@0
|
525 |
parabel (pa1, p1x,p1y,p2x+tp.x(),p2y+tp.y());
|
insilmaril@0
|
526 |
parabel (pa2, p1x,p1y,p2x-tp.x(),p2y-tp.y());
|
insilmaril@408
|
527 |
pa0.clear();
|
insilmaril@406
|
528 |
for (int i=0;i<=arcsegs;i++)
|
insilmaril@408
|
529 |
pa0 << QPointF (pa1.at(i));
|
insilmaril@408
|
530 |
for (int i=0;i<=arcsegs;i++)
|
insilmaril@408
|
531 |
pa0 << QPointF (pa2.at(arcsegs-i));
|
insilmaril@408
|
532 |
p->setPolygon(QPolygonF (pa0));
|
insilmaril@0
|
533 |
break;
|
insilmaril@0
|
534 |
default:
|
insilmaril@0
|
535 |
break;
|
insilmaril@779
|
536 |
}
|
insilmaril@0
|
537 |
}
|
insilmaril@0
|
538 |
|
insilmaril@0
|
539 |
LinkableMapObj* LinkableMapObj::getParObj()
|
insilmaril@0
|
540 |
{
|
insilmaril@0
|
541 |
return parObj;
|
insilmaril@0
|
542 |
}
|
insilmaril@0
|
543 |
|
insilmaril@408
|
544 |
QPointF LinkableMapObj::getChildPos()
|
insilmaril@0
|
545 |
{
|
insilmaril@0
|
546 |
return childPos;
|
insilmaril@0
|
547 |
}
|
insilmaril@0
|
548 |
|
insilmaril@408
|
549 |
QPointF LinkableMapObj::getParPos()
|
insilmaril@0
|
550 |
{
|
insilmaril@0
|
551 |
return parPos;
|
insilmaril@0
|
552 |
}
|
insilmaril@0
|
553 |
|
insilmaril@473
|
554 |
LinkableMapObj::Orientation LinkableMapObj::getOrientation()
|
insilmaril@0
|
555 |
{
|
insilmaril@0
|
556 |
return orientation;
|
insilmaril@0
|
557 |
}
|
insilmaril@0
|
558 |
|
insilmaril@408
|
559 |
QPointF LinkableMapObj::getRandPos()
|
insilmaril@0
|
560 |
{
|
insilmaril@0
|
561 |
// Choose a random position with given distance to parent:
|
insilmaril@0
|
562 |
double a=rand()%360 * 2 * M_PI / 360;
|
insilmaril@408
|
563 |
return QPointF ( (int)( + 150*cos (a)),
|
insilmaril@0
|
564 |
(int)( + 150*sin (a)));
|
insilmaril@0
|
565 |
}
|
insilmaril@0
|
566 |
|
insilmaril@0
|
567 |
void LinkableMapObj::reposition()
|
insilmaril@0
|
568 |
{
|
insilmaril@0
|
569 |
}
|
insilmaril@0
|
570 |
|
insilmaril@785
|
571 |
void LinkableMapObj::requestReposition() //FIXME-3 needed?
|
insilmaril@0
|
572 |
{
|
insilmaril@0
|
573 |
if (!repositionRequest)
|
insilmaril@0
|
574 |
{
|
insilmaril@0
|
575 |
// Pass on the request to parental objects, if this hasn't
|
insilmaril@0
|
576 |
// been done yet
|
insilmaril@0
|
577 |
repositionRequest=true;
|
insilmaril@0
|
578 |
if (parObj) parObj->requestReposition();
|
insilmaril@0
|
579 |
}
|
insilmaril@0
|
580 |
}
|
insilmaril@0
|
581 |
|
insilmaril@0
|
582 |
void LinkableMapObj::forceReposition()
|
insilmaril@0
|
583 |
{
|
insilmaril@0
|
584 |
// Sometimes a reposition has to be done immediatly: For example
|
insilmaril@0
|
585 |
// if the note editor flag changes, there is no user event in mapeditor
|
insilmaril@0
|
586 |
// which could collect requests for a reposition.
|
insilmaril@0
|
587 |
// Then we have to call forceReposition()
|
insilmaril@0
|
588 |
// But no rule without exception: While loading a map or undoing it,
|
insilmaril@0
|
589 |
// we want to block expensive repositioning, but just do it once at
|
insilmaril@0
|
590 |
// the end, thus check first:
|
insilmaril@0
|
591 |
|
insilmaril@773
|
592 |
VymModel *model=treeItem->getModel();
|
insilmaril@724
|
593 |
if (model->isRepositionBlocked()) return;
|
insilmaril@0
|
594 |
|
insilmaril@724
|
595 |
// Pass on the request to parent objects, if this hasn't been done yet
|
insilmaril@0
|
596 |
if (parObj)
|
insilmaril@0
|
597 |
parObj->forceReposition();
|
insilmaril@0
|
598 |
else
|
insilmaril@83
|
599 |
reposition();
|
insilmaril@83
|
600 |
}
|
insilmaril@0
|
601 |
|
insilmaril@0
|
602 |
bool LinkableMapObj::repositionRequested()
|
insilmaril@0
|
603 |
{
|
insilmaril@0
|
604 |
return repositionRequest;
|
insilmaril@0
|
605 |
}
|
insilmaril@0
|
606 |
|
insilmaril@408
|
607 |
void LinkableMapObj::parabel (QPolygonF &ya, double p1x, double p1y, double p2x, double p2y)
|
insilmaril@0
|
608 |
|
insilmaril@0
|
609 |
{
|
insilmaril@0
|
610 |
double vx=p2x - p1x; // V=P2-P1
|
insilmaril@0
|
611 |
double vy=p2y - p1y;
|
insilmaril@0
|
612 |
|
insilmaril@0
|
613 |
double dx; // delta x during calculation of parabel
|
insilmaril@0
|
614 |
|
insilmaril@0
|
615 |
double pnx; // next point
|
insilmaril@0
|
616 |
double pny;
|
insilmaril@0
|
617 |
double m;
|
insilmaril@0
|
618 |
|
insilmaril@0
|
619 |
if (vx > -0.0001 && vx < 0.0001)
|
insilmaril@0
|
620 |
m=0;
|
insilmaril@0
|
621 |
else
|
insilmaril@0
|
622 |
m=(vy / (vx*vx));
|
insilmaril@0
|
623 |
dx=vx/(arcsegs);
|
insilmaril@408
|
624 |
ya.clear();
|
insilmaril@579
|
625 |
ya<<QPointF (p1x,p1y);
|
insilmaril@408
|
626 |
for (int i=1;i<=arcsegs;i++)
|
insilmaril@0
|
627 |
{
|
insilmaril@0
|
628 |
pnx=p1x+dx;
|
insilmaril@0
|
629 |
pny=m*(pnx-parPos.x())*(pnx-parPos.x())+parPos.y();
|
insilmaril@579
|
630 |
ya<<QPointF (pnx,pny);
|
insilmaril@0
|
631 |
p1x=pnx;
|
insilmaril@0
|
632 |
p1y=pny;
|
insilmaril@0
|
633 |
}
|
insilmaril@0
|
634 |
}
|
insilmaril@0
|
635 |
|