insilmaril@0
|
1 |
#include "linkablemapobj.h"
|
insilmaril@0
|
2 |
#include "branchobj.h"
|
insilmaril@0
|
3 |
#include "mapeditor.h"
|
insilmaril@0
|
4 |
|
insilmaril@0
|
5 |
#include "version.h"
|
insilmaril@0
|
6 |
|
insilmaril@0
|
7 |
|
insilmaril@0
|
8 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
9 |
// LinkableMapObj
|
insilmaril@0
|
10 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
11 |
|
insilmaril@0
|
12 |
LinkableMapObj::LinkableMapObj():MapObj()
|
insilmaril@0
|
13 |
{
|
insilmaril@0
|
14 |
// cout << "Const LinkableMapObj ()\n";
|
insilmaril@0
|
15 |
init ();
|
insilmaril@0
|
16 |
}
|
insilmaril@0
|
17 |
|
insilmaril@0
|
18 |
LinkableMapObj::LinkableMapObj(QCanvas* c) :MapObj(c)
|
insilmaril@0
|
19 |
{
|
insilmaril@0
|
20 |
// cout << "Const LinkableMapObj\n";
|
insilmaril@0
|
21 |
init ();
|
insilmaril@0
|
22 |
}
|
insilmaril@0
|
23 |
|
insilmaril@0
|
24 |
LinkableMapObj::LinkableMapObj (LinkableMapObj* lmo) : MapObj (lmo->canvas)
|
insilmaril@0
|
25 |
{
|
insilmaril@0
|
26 |
copy (lmo);
|
insilmaril@0
|
27 |
}
|
insilmaril@0
|
28 |
|
insilmaril@0
|
29 |
LinkableMapObj::~LinkableMapObj()
|
insilmaril@0
|
30 |
{
|
insilmaril@0
|
31 |
delete (bottomline);
|
insilmaril@0
|
32 |
delete (selbox);
|
insilmaril@0
|
33 |
delete (frame);
|
insilmaril@0
|
34 |
delLink();
|
insilmaril@0
|
35 |
}
|
insilmaril@0
|
36 |
|
insilmaril@0
|
37 |
void LinkableMapObj::delLink()
|
insilmaril@0
|
38 |
{
|
insilmaril@0
|
39 |
switch (style)
|
insilmaril@0
|
40 |
{
|
insilmaril@0
|
41 |
case StyleLine:
|
insilmaril@0
|
42 |
delete (l);
|
insilmaril@0
|
43 |
break;
|
insilmaril@0
|
44 |
case StyleParabel:
|
insilmaril@0
|
45 |
segment.clear();
|
insilmaril@0
|
46 |
break;
|
insilmaril@0
|
47 |
case StylePolyLine:
|
insilmaril@0
|
48 |
delete (p);
|
insilmaril@0
|
49 |
delete (l);
|
insilmaril@0
|
50 |
break;
|
insilmaril@0
|
51 |
case StylePolyParabel:
|
insilmaril@0
|
52 |
delete (p);
|
insilmaril@0
|
53 |
segment.clear();
|
insilmaril@0
|
54 |
break;
|
insilmaril@0
|
55 |
default:
|
insilmaril@0
|
56 |
break;
|
insilmaril@0
|
57 |
}
|
insilmaril@0
|
58 |
}
|
insilmaril@0
|
59 |
|
insilmaril@0
|
60 |
void LinkableMapObj::init ()
|
insilmaril@0
|
61 |
{
|
insilmaril@0
|
62 |
depth=-1;
|
insilmaril@0
|
63 |
childObj=NULL;
|
insilmaril@0
|
64 |
parObj=NULL;
|
insilmaril@0
|
65 |
parObjTmpBuf=NULL;
|
insilmaril@0
|
66 |
parPos=QPoint(0,0);
|
insilmaril@0
|
67 |
childPos=QPoint(0,0);
|
insilmaril@0
|
68 |
link2ParPos=false;
|
insilmaril@0
|
69 |
l=NULL;
|
insilmaril@0
|
70 |
orientation=OrientUndef;
|
insilmaril@0
|
71 |
linkwidth=20;
|
insilmaril@0
|
72 |
thickness_start=8;
|
insilmaril@0
|
73 |
style=StyleUndef;
|
insilmaril@0
|
74 |
linkpos=LinkBottom;
|
insilmaril@0
|
75 |
segment.setAutoDelete (TRUE);
|
insilmaril@0
|
76 |
arcsegs=13;
|
insilmaril@0
|
77 |
QPointArray pa(arcsegs*2+2);
|
insilmaril@0
|
78 |
|
insilmaril@0
|
79 |
bottomline=new QCanvasLine(canvas);
|
insilmaril@0
|
80 |
bottomline->setPen( QPen(linkcolor, 1) );
|
insilmaril@0
|
81 |
bottomline->setZ(Z_LINK);
|
insilmaril@0
|
82 |
bottomline->show();
|
insilmaril@0
|
83 |
|
insilmaril@0
|
84 |
// Prepare showing the selection of a MapObj
|
insilmaril@0
|
85 |
selbox = new QCanvasRectangle (canvas);
|
insilmaril@0
|
86 |
selbox->setZ(Z_SELBOX);
|
insilmaril@0
|
87 |
selbox->setBrush( QColor(255,255,0) );
|
insilmaril@0
|
88 |
selbox->setPen( QPen(QColor(255,255,0) ));
|
insilmaril@0
|
89 |
selbox->hide();
|
insilmaril@0
|
90 |
selected=false;
|
insilmaril@0
|
91 |
|
insilmaril@0
|
92 |
// initialize frame
|
insilmaril@0
|
93 |
frame = new FrameObj (canvas);
|
insilmaril@0
|
94 |
|
insilmaril@0
|
95 |
repositionRequest=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@0
|
104 |
}
|
insilmaril@0
|
105 |
|
insilmaril@0
|
106 |
void LinkableMapObj::setChildObj(LinkableMapObj* o)
|
insilmaril@0
|
107 |
{
|
insilmaril@0
|
108 |
childObj=o;
|
insilmaril@0
|
109 |
}
|
insilmaril@0
|
110 |
|
insilmaril@0
|
111 |
void LinkableMapObj::setParObj(LinkableMapObj* o)
|
insilmaril@0
|
112 |
{
|
insilmaril@0
|
113 |
parObj=o;
|
insilmaril@0
|
114 |
mapEditor=parObj->getMapEditor();
|
insilmaril@0
|
115 |
}
|
insilmaril@0
|
116 |
|
insilmaril@0
|
117 |
void LinkableMapObj::setParObjTmp(LinkableMapObj*,QPoint,int)
|
insilmaril@0
|
118 |
{
|
insilmaril@0
|
119 |
}
|
insilmaril@0
|
120 |
|
insilmaril@0
|
121 |
void LinkableMapObj::unsetParObjTmp()
|
insilmaril@0
|
122 |
{
|
insilmaril@0
|
123 |
}
|
insilmaril@0
|
124 |
|
insilmaril@0
|
125 |
LinkStyle LinkableMapObj::getDefLinkStyle ()
|
insilmaril@0
|
126 |
{
|
insilmaril@0
|
127 |
LinkStyle ls=mapEditor->getLinkStyle();
|
insilmaril@0
|
128 |
switch (ls)
|
insilmaril@0
|
129 |
{
|
insilmaril@0
|
130 |
case StyleLine:
|
insilmaril@0
|
131 |
return ls;
|
insilmaril@0
|
132 |
break;
|
insilmaril@0
|
133 |
case StyleParabel:
|
insilmaril@0
|
134 |
return ls;
|
insilmaril@0
|
135 |
break;
|
insilmaril@0
|
136 |
case StylePolyLine:
|
insilmaril@0
|
137 |
if (depth>1)
|
insilmaril@0
|
138 |
return StyleLine;
|
insilmaril@0
|
139 |
else
|
insilmaril@0
|
140 |
return ls;
|
insilmaril@0
|
141 |
break;
|
insilmaril@0
|
142 |
case StylePolyParabel:
|
insilmaril@0
|
143 |
if (depth>1)
|
insilmaril@0
|
144 |
return StyleParabel;
|
insilmaril@0
|
145 |
else
|
insilmaril@0
|
146 |
return ls;
|
insilmaril@0
|
147 |
break;
|
insilmaril@0
|
148 |
default:
|
insilmaril@0
|
149 |
break;
|
insilmaril@0
|
150 |
}
|
insilmaril@0
|
151 |
return StyleUndef;
|
insilmaril@0
|
152 |
}
|
insilmaril@0
|
153 |
|
insilmaril@0
|
154 |
void LinkableMapObj::setLinkStyle(LinkStyle newstyle)
|
insilmaril@0
|
155 |
{
|
insilmaril@83
|
156 |
//if (newstyle=style) return;
|
insilmaril@0
|
157 |
delLink();
|
insilmaril@0
|
158 |
|
insilmaril@0
|
159 |
style=newstyle;
|
insilmaril@0
|
160 |
|
insilmaril@0
|
161 |
if (childObj!=NULL && parObj != NULL)
|
insilmaril@0
|
162 |
{
|
insilmaril@0
|
163 |
int i;
|
insilmaril@0
|
164 |
QCanvasLine* cl;
|
insilmaril@0
|
165 |
switch (style)
|
insilmaril@0
|
166 |
{
|
insilmaril@0
|
167 |
case StyleUndef:
|
insilmaril@0
|
168 |
bottomline->hide();
|
insilmaril@0
|
169 |
break;
|
insilmaril@0
|
170 |
case StyleLine:
|
insilmaril@0
|
171 |
l = new QCanvasLine(canvas);
|
insilmaril@0
|
172 |
l->setPen( QPen(linkcolor, 1) );
|
insilmaril@0
|
173 |
l->setZ(Z_LINK);
|
insilmaril@0
|
174 |
if (visible)
|
insilmaril@0
|
175 |
l->show();
|
insilmaril@0
|
176 |
else
|
insilmaril@0
|
177 |
l->hide();
|
insilmaril@0
|
178 |
break;
|
insilmaril@0
|
179 |
case StyleParabel:
|
insilmaril@0
|
180 |
for (i=0;i<arcsegs;i++)
|
insilmaril@0
|
181 |
{
|
insilmaril@0
|
182 |
cl = new QCanvasLine(canvas);
|
insilmaril@0
|
183 |
cl->setPen( QPen(linkcolor, 1) );
|
insilmaril@0
|
184 |
cl->setPoints( 0,0,i*10,100);
|
insilmaril@0
|
185 |
cl->setZ(Z_LINK);
|
insilmaril@0
|
186 |
if (visible)
|
insilmaril@0
|
187 |
cl->show();
|
insilmaril@0
|
188 |
else
|
insilmaril@0
|
189 |
cl->hide();
|
insilmaril@0
|
190 |
segment.append(cl);
|
insilmaril@0
|
191 |
}
|
insilmaril@0
|
192 |
pa0.resize (arcsegs+1);
|
insilmaril@0
|
193 |
break;
|
insilmaril@0
|
194 |
case StylePolyLine:
|
insilmaril@0
|
195 |
p = new QCanvasPolygon(canvas);
|
insilmaril@0
|
196 |
p->setBrush( linkcolor );
|
insilmaril@0
|
197 |
p->setZ(Z_LINK);
|
insilmaril@0
|
198 |
if (visible)
|
insilmaril@0
|
199 |
p->show();
|
insilmaril@0
|
200 |
else
|
insilmaril@0
|
201 |
p->hide();
|
insilmaril@0
|
202 |
pa0.resize (3);
|
insilmaril@0
|
203 |
// TODO
|
insilmaril@0
|
204 |
// a bit awkward: draw the lines additionally to polygon, to avoid
|
insilmaril@0
|
205 |
// missing pixels, when polygon is extremly flat
|
insilmaril@0
|
206 |
l = new QCanvasLine(canvas);
|
insilmaril@0
|
207 |
l->setPen( QPen(linkcolor, 1) );
|
insilmaril@0
|
208 |
l->setZ(Z_LINK);
|
insilmaril@0
|
209 |
if (visible)
|
insilmaril@0
|
210 |
l->show();
|
insilmaril@0
|
211 |
else
|
insilmaril@0
|
212 |
l->hide();
|
insilmaril@0
|
213 |
break;
|
insilmaril@0
|
214 |
case StylePolyParabel:
|
insilmaril@0
|
215 |
p = new QCanvasPolygon(canvas);
|
insilmaril@0
|
216 |
p->setBrush( linkcolor );
|
insilmaril@0
|
217 |
p->setZ(Z_LINK);
|
insilmaril@0
|
218 |
if (visible)
|
insilmaril@0
|
219 |
p->show();
|
insilmaril@0
|
220 |
else
|
insilmaril@0
|
221 |
p->hide();
|
insilmaril@0
|
222 |
pa0.resize (arcsegs*2+2);
|
insilmaril@0
|
223 |
pa1.resize (arcsegs+1);
|
insilmaril@0
|
224 |
pa2.resize (arcsegs+1);
|
insilmaril@0
|
225 |
|
insilmaril@0
|
226 |
// TODO
|
insilmaril@0
|
227 |
// a bit awkward: draw the lines additionally
|
insilmaril@0
|
228 |
// to polygon, to avoid missing pixels,
|
insilmaril@0
|
229 |
// if polygon is extremly flat
|
insilmaril@0
|
230 |
for (i=0;i<arcsegs;i++)
|
insilmaril@0
|
231 |
{
|
insilmaril@0
|
232 |
cl = new QCanvasLine(canvas);
|
insilmaril@0
|
233 |
cl->setPen( QPen(linkcolor, 1) );
|
insilmaril@0
|
234 |
cl->setPoints( 0,0,i*10,100);
|
insilmaril@0
|
235 |
cl->setZ(Z_LINK);
|
insilmaril@0
|
236 |
if (visible)
|
insilmaril@0
|
237 |
cl->show();
|
insilmaril@0
|
238 |
else
|
insilmaril@0
|
239 |
cl->hide();
|
insilmaril@0
|
240 |
segment.append(cl);
|
insilmaril@0
|
241 |
}
|
insilmaril@0
|
242 |
break;
|
insilmaril@0
|
243 |
default:
|
insilmaril@0
|
244 |
break;
|
insilmaril@0
|
245 |
}
|
insilmaril@93
|
246 |
// FIXME updateLink is usually called (multiple times) later:
|
insilmaril@93
|
247 |
//updateLink();
|
insilmaril@0
|
248 |
} else
|
insilmaril@0
|
249 |
{
|
insilmaril@83
|
250 |
qWarning ("Error: ChildObj or parObj == NULL in LinkableMapObj::setLinkStyle\n");
|
insilmaril@0
|
251 |
}
|
insilmaril@0
|
252 |
}
|
insilmaril@0
|
253 |
|
insilmaril@0
|
254 |
LinkStyle LinkableMapObj::getLinkStyle()
|
insilmaril@0
|
255 |
{
|
insilmaril@0
|
256 |
return style;
|
insilmaril@0
|
257 |
}
|
insilmaril@0
|
258 |
|
insilmaril@0
|
259 |
void LinkableMapObj::setLinkPos(LinkPos lp)
|
insilmaril@0
|
260 |
{
|
insilmaril@0
|
261 |
linkpos=lp;
|
insilmaril@0
|
262 |
}
|
insilmaril@0
|
263 |
|
insilmaril@0
|
264 |
LinkPos LinkableMapObj::getLinkPos()
|
insilmaril@0
|
265 |
{
|
insilmaril@0
|
266 |
return linkpos;
|
insilmaril@0
|
267 |
}
|
insilmaril@0
|
268 |
|
insilmaril@0
|
269 |
|
insilmaril@0
|
270 |
void LinkableMapObj::setLinkColor()
|
insilmaril@0
|
271 |
{
|
insilmaril@0
|
272 |
// Overloaded in BranchObj and childs
|
insilmaril@0
|
273 |
// here only set default color
|
insilmaril@0
|
274 |
setLinkColor (mapEditor->getDefLinkColor());
|
insilmaril@0
|
275 |
}
|
insilmaril@0
|
276 |
|
insilmaril@0
|
277 |
void LinkableMapObj::setLinkColor(QColor col)
|
insilmaril@0
|
278 |
{
|
insilmaril@0
|
279 |
linkcolor=col;
|
insilmaril@0
|
280 |
bottomline->setPen( QPen(linkcolor, 1) );
|
insilmaril@0
|
281 |
QCanvasLine *cl;
|
insilmaril@0
|
282 |
switch (style)
|
insilmaril@0
|
283 |
{
|
insilmaril@0
|
284 |
case StyleLine:
|
insilmaril@0
|
285 |
l->setPen( QPen(col,1));
|
insilmaril@0
|
286 |
break;
|
insilmaril@0
|
287 |
case StyleParabel:
|
insilmaril@0
|
288 |
for (cl=segment.first(); cl; cl=segment.next() )
|
insilmaril@0
|
289 |
cl->setPen( QPen(col,1));
|
insilmaril@0
|
290 |
break;
|
insilmaril@0
|
291 |
case StylePolyLine:
|
insilmaril@0
|
292 |
p->setBrush( QBrush(col));
|
insilmaril@0
|
293 |
l->setPen( QPen(col,1));
|
insilmaril@0
|
294 |
break;
|
insilmaril@0
|
295 |
case StylePolyParabel:
|
insilmaril@0
|
296 |
p->setBrush( QBrush(col));
|
insilmaril@0
|
297 |
for (cl=segment.first(); cl; cl=segment.next() )
|
insilmaril@0
|
298 |
cl->setPen( QPen(col,1));
|
insilmaril@0
|
299 |
break;
|
insilmaril@0
|
300 |
default:
|
insilmaril@0
|
301 |
break;
|
insilmaril@0
|
302 |
} // switch (style)
|
insilmaril@93
|
303 |
//FIXME updateLink();
|
insilmaril@0
|
304 |
}
|
insilmaril@0
|
305 |
|
insilmaril@0
|
306 |
QColor LinkableMapObj::getLinkColor()
|
insilmaril@0
|
307 |
{
|
insilmaril@0
|
308 |
return linkcolor;
|
insilmaril@0
|
309 |
}
|
insilmaril@0
|
310 |
|
insilmaril@0
|
311 |
FrameType LinkableMapObj::getFrameType()
|
insilmaril@0
|
312 |
{
|
insilmaril@0
|
313 |
return frame->getFrameType();
|
insilmaril@0
|
314 |
}
|
insilmaril@0
|
315 |
|
insilmaril@0
|
316 |
void LinkableMapObj::setFrameType(const FrameType &t)
|
insilmaril@0
|
317 |
{
|
insilmaril@0
|
318 |
frame->setFrameType(t);
|
insilmaril@0
|
319 |
calcBBoxSize();
|
insilmaril@0
|
320 |
positionBBox();
|
insilmaril@0
|
321 |
requestReposition();
|
insilmaril@0
|
322 |
}
|
insilmaril@0
|
323 |
|
insilmaril@0
|
324 |
void LinkableMapObj::setFrameType(const QString &t)
|
insilmaril@0
|
325 |
{
|
insilmaril@0
|
326 |
frame->setFrameType(t);
|
insilmaril@0
|
327 |
calcBBoxSize();
|
insilmaril@0
|
328 |
positionBBox();
|
insilmaril@0
|
329 |
requestReposition();
|
insilmaril@0
|
330 |
}
|
insilmaril@0
|
331 |
|
insilmaril@0
|
332 |
void LinkableMapObj::setVisibility (bool v)
|
insilmaril@0
|
333 |
{
|
insilmaril@0
|
334 |
MapObj::setVisibility (v);
|
insilmaril@0
|
335 |
if (visible)
|
insilmaril@0
|
336 |
{
|
insilmaril@0
|
337 |
bottomline->show();
|
insilmaril@0
|
338 |
// FIXME lines and segments should be done in LMO?
|
insilmaril@0
|
339 |
if (style==StyleLine && l)
|
insilmaril@0
|
340 |
{
|
insilmaril@0
|
341 |
l->show();
|
insilmaril@0
|
342 |
} else
|
insilmaril@0
|
343 |
{
|
insilmaril@0
|
344 |
QCanvasLine* cl;
|
insilmaril@0
|
345 |
for (cl=segment.first(); cl; cl=segment.next() )
|
insilmaril@0
|
346 |
cl->show();
|
insilmaril@0
|
347 |
}
|
insilmaril@0
|
348 |
} else
|
insilmaril@0
|
349 |
{
|
insilmaril@0
|
350 |
bottomline->hide();
|
insilmaril@0
|
351 |
if (style==StyleLine && l)
|
insilmaril@0
|
352 |
{
|
insilmaril@0
|
353 |
l->hide();
|
insilmaril@0
|
354 |
} else
|
insilmaril@0
|
355 |
{
|
insilmaril@0
|
356 |
QCanvasLine* cl;
|
insilmaril@0
|
357 |
for (cl=segment.first(); cl; cl=segment.next() )
|
insilmaril@0
|
358 |
cl->hide();
|
insilmaril@0
|
359 |
}
|
insilmaril@0
|
360 |
}
|
insilmaril@0
|
361 |
}
|
insilmaril@0
|
362 |
|
insilmaril@0
|
363 |
void LinkableMapObj::updateLink()
|
insilmaril@0
|
364 |
{
|
insilmaril@0
|
365 |
// needs:
|
insilmaril@0
|
366 |
// childPos of parent
|
insilmaril@0
|
367 |
// orient of parent
|
insilmaril@0
|
368 |
// style
|
insilmaril@0
|
369 |
//
|
insilmaril@0
|
370 |
// sets:
|
insilmaril@0
|
371 |
// orientation
|
insilmaril@0
|
372 |
// childPos
|
insilmaril@0
|
373 |
// parPos
|
insilmaril@0
|
374 |
// offset
|
insilmaril@0
|
375 |
// drawing of the link itself
|
insilmaril@0
|
376 |
|
insilmaril@0
|
377 |
|
insilmaril@0
|
378 |
// updateLink is called from move, but called from constructor we don't
|
insilmaril@0
|
379 |
// have parents yet...
|
insilmaril@0
|
380 |
if (style==StyleUndef) return;
|
insilmaril@0
|
381 |
|
insilmaril@0
|
382 |
if (frame->getFrameType() == NoFrame)
|
insilmaril@0
|
383 |
linkpos=LinkBottom;
|
insilmaril@0
|
384 |
else
|
insilmaril@0
|
385 |
linkpos=LinkMiddle;
|
insilmaril@0
|
386 |
switch (linkpos)
|
insilmaril@0
|
387 |
{
|
insilmaril@0
|
388 |
case LinkMiddle:
|
insilmaril@0
|
389 |
offset=bbox.height() /2;
|
insilmaril@0
|
390 |
break;
|
insilmaril@0
|
391 |
default :
|
insilmaril@0
|
392 |
offset=bbox.height()-1; // draw link to bottom of bbox
|
insilmaril@0
|
393 |
break;
|
insilmaril@0
|
394 |
}
|
insilmaril@0
|
395 |
|
insilmaril@0
|
396 |
double p2x,p2y; // Set P2 Before setting
|
insilmaril@0
|
397 |
if (!link2ParPos)
|
insilmaril@0
|
398 |
{
|
insilmaril@0
|
399 |
p2x=QPoint( parObj->getChildPos() ).x(); // P1, we have to look at
|
insilmaril@0
|
400 |
p2y=QPoint( parObj->getChildPos() ).y(); // orientation
|
insilmaril@0
|
401 |
} else
|
insilmaril@0
|
402 |
{
|
insilmaril@0
|
403 |
p2x=QPoint( parObj->getParPos() ).x();
|
insilmaril@0
|
404 |
p2y=QPoint( parObj->getParPos() ).y();
|
insilmaril@0
|
405 |
}
|
insilmaril@0
|
406 |
|
insilmaril@0
|
407 |
LinkOrient orientOld=orientation;
|
insilmaril@0
|
408 |
|
insilmaril@0
|
409 |
// Set orientation, first look for orientation of parent
|
insilmaril@0
|
410 |
if (parObj->getOrientation() != OrientUndef )
|
insilmaril@0
|
411 |
// use the orientation of the parent:
|
insilmaril@0
|
412 |
orientation=parObj->getOrientation();
|
insilmaril@0
|
413 |
else
|
insilmaril@0
|
414 |
{
|
insilmaril@0
|
415 |
// calc orientation depending on position rel to mapCenter
|
insilmaril@0
|
416 |
if (absPos.x() < QPoint(parObj->getChildPos() ).x() )
|
insilmaril@0
|
417 |
orientation=OrientLeftOfCenter;
|
insilmaril@0
|
418 |
else
|
insilmaril@0
|
419 |
orientation=OrientRightOfCenter;
|
insilmaril@0
|
420 |
}
|
insilmaril@0
|
421 |
|
insilmaril@0
|
422 |
if ((orientation!=orientOld) && (orientOld!= OrientUndef))
|
insilmaril@0
|
423 |
{
|
insilmaril@0
|
424 |
// Orientation just changed. Reorient this subbranch, because move is called
|
insilmaril@0
|
425 |
// before updateLink => Position is still the old one, which could lead to
|
insilmaril@0
|
426 |
// linking of subranch to itself => segfault
|
insilmaril@0
|
427 |
//
|
insilmaril@0
|
428 |
// Also possible: called in BranchObj::init(), then orientOld==OrientUndef,
|
insilmaril@0
|
429 |
// no need to reposition now
|
insilmaril@0
|
430 |
reposition();
|
insilmaril@0
|
431 |
}
|
insilmaril@0
|
432 |
|
insilmaril@0
|
433 |
if (orientation==OrientLeftOfCenter )
|
insilmaril@0
|
434 |
{
|
insilmaril@0
|
435 |
childPos=QPoint (absPos.x(),absPos.y()+offset);
|
insilmaril@0
|
436 |
parPos=QPoint (absPos.x()+ bbox.width(), absPos.y() + offset );
|
insilmaril@0
|
437 |
} else
|
insilmaril@0
|
438 |
{
|
insilmaril@0
|
439 |
childPos=QPoint (absPos.x()+ bbox.width(), absPos.y() + offset );
|
insilmaril@0
|
440 |
parPos=QPoint (absPos.x(),absPos.y()+offset);
|
insilmaril@0
|
441 |
}
|
insilmaril@0
|
442 |
|
insilmaril@0
|
443 |
double p1x=parPos.x(); // Link is drawn from P1 to P2
|
insilmaril@0
|
444 |
double p1y=parPos.y();
|
insilmaril@0
|
445 |
|
insilmaril@0
|
446 |
double vx=p2x - p1x; // V=P2-P1
|
insilmaril@0
|
447 |
double vy=p2y - p1y;
|
insilmaril@0
|
448 |
|
insilmaril@0
|
449 |
// Draw the horizontal line below heading (from ChildPos to ParPos)
|
insilmaril@104
|
450 |
bottomline->setPoints (qRound(childPos.x()),
|
insilmaril@104
|
451 |
qRound(childPos.y()),
|
insilmaril@104
|
452 |
qRound(p1x),
|
insilmaril@104
|
453 |
qRound(p1y) );
|
insilmaril@0
|
454 |
|
insilmaril@0
|
455 |
double a; // angle
|
insilmaril@0
|
456 |
if (vx > -0.000001 && vx < 0.000001)
|
insilmaril@0
|
457 |
a=M_PI_2;
|
insilmaril@0
|
458 |
else
|
insilmaril@0
|
459 |
a=atan( vy / vx );
|
insilmaril@0
|
460 |
// "turning point" for drawing polygonal links
|
insilmaril@104
|
461 |
QPoint tp (-qRound(sin (a)*thickness_start), qRound(cos (a)*thickness_start));
|
insilmaril@0
|
462 |
|
insilmaril@0
|
463 |
QCanvasLine *cl;
|
insilmaril@0
|
464 |
|
insilmaril@0
|
465 |
int i;
|
insilmaril@0
|
466 |
|
insilmaril@0
|
467 |
// Draw the link
|
insilmaril@0
|
468 |
switch (style)
|
insilmaril@0
|
469 |
{
|
insilmaril@0
|
470 |
case StyleLine:
|
insilmaril@104
|
471 |
l->setPoints( qRound (parPos.x()),
|
insilmaril@104
|
472 |
qRound(parPos.y()),
|
insilmaril@104
|
473 |
qRound(p2x),
|
insilmaril@104
|
474 |
qRound(p2y) );
|
insilmaril@0
|
475 |
break;
|
insilmaril@0
|
476 |
case StyleParabel:
|
insilmaril@0
|
477 |
parabel (pa0, p1x,p1y,p2x,p2y);
|
insilmaril@0
|
478 |
i=0;
|
insilmaril@0
|
479 |
for (cl=segment.first(); cl; cl=segment.next() )
|
insilmaril@0
|
480 |
{
|
insilmaril@0
|
481 |
cl->setPoints( pa0.point(i).x(), pa0.point(i).y(),pa0.point(i+1).x(),pa0.point(i+1).y());
|
insilmaril@0
|
482 |
i++;
|
insilmaril@0
|
483 |
}
|
insilmaril@0
|
484 |
break;
|
insilmaril@0
|
485 |
case StylePolyLine:
|
insilmaril@104
|
486 |
pa0[0]=QPoint (qRound(p2x+tp.x()), qRound(p2y+tp.y()));
|
insilmaril@104
|
487 |
pa0[1]=QPoint (qRound(p2x-tp.x()), qRound(p2y-tp.y()));
|
insilmaril@104
|
488 |
pa0[2]=QPoint (qRound (parPos.x()), qRound(parPos.y()) );
|
insilmaril@0
|
489 |
p->setPoints (pa0);
|
insilmaril@0
|
490 |
// here too, draw line to avoid missing pixels
|
insilmaril@104
|
491 |
l->setPoints( qRound (parPos.x()),
|
insilmaril@104
|
492 |
qRound(parPos.y()),
|
insilmaril@104
|
493 |
qRound(p2x),
|
insilmaril@104
|
494 |
qRound(p2y) );
|
insilmaril@0
|
495 |
break;
|
insilmaril@0
|
496 |
case StylePolyParabel:
|
insilmaril@0
|
497 |
parabel (pa1, p1x,p1y,p2x+tp.x(),p2y+tp.y());
|
insilmaril@0
|
498 |
parabel (pa2, p1x,p1y,p2x-tp.x(),p2y-tp.y());
|
insilmaril@0
|
499 |
for (i=0;i<=arcsegs;i++)
|
insilmaril@0
|
500 |
{
|
insilmaril@0
|
501 |
// Combine the arrays to a single one
|
insilmaril@0
|
502 |
pa0[i]=pa1[i];
|
insilmaril@0
|
503 |
pa0[i+arcsegs+1]=pa2[arcsegs-i];
|
insilmaril@0
|
504 |
}
|
insilmaril@0
|
505 |
p->setPoints (pa0);
|
insilmaril@0
|
506 |
i=0;
|
insilmaril@0
|
507 |
for (cl=segment.first(); cl; cl=segment.next() )
|
insilmaril@0
|
508 |
{
|
insilmaril@0
|
509 |
cl->setPoints( pa1.point(i).x(), pa1.point(i).y(),pa1.point(i+1).x(),pa1.point(i+1).y());
|
insilmaril@0
|
510 |
i++;
|
insilmaril@0
|
511 |
}
|
insilmaril@0
|
512 |
break;
|
insilmaril@0
|
513 |
default:
|
insilmaril@0
|
514 |
break;
|
insilmaril@0
|
515 |
} // switch (style)
|
insilmaril@0
|
516 |
}
|
insilmaril@0
|
517 |
|
insilmaril@0
|
518 |
LinkableMapObj* LinkableMapObj::getChildObj()
|
insilmaril@0
|
519 |
{
|
insilmaril@0
|
520 |
return childObj;
|
insilmaril@0
|
521 |
}
|
insilmaril@0
|
522 |
|
insilmaril@0
|
523 |
LinkableMapObj* LinkableMapObj::getParObj()
|
insilmaril@0
|
524 |
{
|
insilmaril@0
|
525 |
return parObj;
|
insilmaril@0
|
526 |
}
|
insilmaril@0
|
527 |
|
insilmaril@106
|
528 |
LinkableMapObj* LinkableMapObj::findObjBySelect (QString s)
|
insilmaril@95
|
529 |
{
|
insilmaril@95
|
530 |
LinkableMapObj *lmo=this;
|
insilmaril@95
|
531 |
QString part;
|
insilmaril@95
|
532 |
QString typ;
|
insilmaril@95
|
533 |
QString num;
|
insilmaril@95
|
534 |
while (!s.isEmpty() )
|
insilmaril@95
|
535 |
{
|
insilmaril@95
|
536 |
part=s.section(",",0,0);
|
insilmaril@95
|
537 |
typ=part.left (3);
|
insilmaril@95
|
538 |
num=part.right(part.length() - 3);
|
insilmaril@95
|
539 |
if (typ=="mc:")
|
insilmaril@95
|
540 |
{
|
insilmaril@95
|
541 |
if (depth>0)
|
insilmaril@95
|
542 |
return false; // in a subtree there is no center
|
insilmaril@95
|
543 |
else
|
insilmaril@95
|
544 |
break;
|
insilmaril@95
|
545 |
} else
|
insilmaril@95
|
546 |
if (typ=="bo:")
|
insilmaril@95
|
547 |
lmo=((BranchObj*)(lmo))->getBranchNum (num.toUInt());
|
insilmaril@95
|
548 |
else
|
insilmaril@95
|
549 |
if (typ=="fi:")
|
insilmaril@95
|
550 |
lmo=((BranchObj*)(lmo))->getFloatImageNum (num.toUInt());
|
insilmaril@95
|
551 |
if (!lmo) break;
|
insilmaril@95
|
552 |
|
insilmaril@95
|
553 |
if (s.contains(","))
|
insilmaril@95
|
554 |
s=s.right(s.length() - part.length() -1 );
|
insilmaril@95
|
555 |
else
|
insilmaril@95
|
556 |
break;
|
insilmaril@95
|
557 |
}
|
insilmaril@95
|
558 |
return lmo;
|
insilmaril@95
|
559 |
}
|
insilmaril@95
|
560 |
|
insilmaril@0
|
561 |
QPoint LinkableMapObj::getChildPos()
|
insilmaril@0
|
562 |
{
|
insilmaril@0
|
563 |
return childPos;
|
insilmaril@0
|
564 |
}
|
insilmaril@0
|
565 |
|
insilmaril@0
|
566 |
QPoint LinkableMapObj::getParPos()
|
insilmaril@0
|
567 |
{
|
insilmaril@0
|
568 |
return parPos;
|
insilmaril@0
|
569 |
}
|
insilmaril@0
|
570 |
|
insilmaril@0
|
571 |
QPoint LinkableMapObj::getRelPos()
|
insilmaril@0
|
572 |
{
|
insilmaril@0
|
573 |
if (!parObj) return QPoint (0,0);
|
insilmaril@0
|
574 |
return QPoint(
|
insilmaril@0
|
575 |
absPos.x() - parObj->x(),
|
insilmaril@0
|
576 |
absPos.y() - parObj->y()
|
insilmaril@0
|
577 |
);
|
insilmaril@0
|
578 |
}
|
insilmaril@0
|
579 |
|
insilmaril@0
|
580 |
LinkOrient LinkableMapObj::getOrientation()
|
insilmaril@0
|
581 |
{
|
insilmaril@0
|
582 |
return orientation;
|
insilmaril@0
|
583 |
}
|
insilmaril@0
|
584 |
|
insilmaril@0
|
585 |
int LinkableMapObj::getDepth()
|
insilmaril@0
|
586 |
{
|
insilmaril@0
|
587 |
return depth;
|
insilmaril@0
|
588 |
}
|
insilmaril@0
|
589 |
|
insilmaril@0
|
590 |
void LinkableMapObj::setMapEditor (MapEditor *me)
|
insilmaril@0
|
591 |
{
|
insilmaril@0
|
592 |
mapEditor=me;
|
insilmaril@0
|
593 |
}
|
insilmaril@0
|
594 |
|
insilmaril@0
|
595 |
MapEditor* LinkableMapObj::getMapEditor ()
|
insilmaril@0
|
596 |
{
|
insilmaril@0
|
597 |
return mapEditor;
|
insilmaril@0
|
598 |
}
|
insilmaril@0
|
599 |
|
insilmaril@0
|
600 |
QPoint LinkableMapObj::getRandPos()
|
insilmaril@0
|
601 |
{
|
insilmaril@0
|
602 |
// Choose a random position with given distance to parent:
|
insilmaril@0
|
603 |
double a=rand()%360 * 2 * M_PI / 360;
|
insilmaril@0
|
604 |
return QPoint ( (int)( + 150*cos (a)),
|
insilmaril@0
|
605 |
(int)( + 150*sin (a)));
|
insilmaril@0
|
606 |
}
|
insilmaril@0
|
607 |
|
insilmaril@0
|
608 |
void LinkableMapObj::alignRelativeTo (QPoint ref)
|
insilmaril@0
|
609 |
{
|
insilmaril@95
|
610 |
cout << "LMO::alignRelTo ref="<<ref<<endl;
|
insilmaril@95
|
611 |
//FIXME
|
insilmaril@0
|
612 |
}
|
insilmaril@0
|
613 |
|
insilmaril@0
|
614 |
void LinkableMapObj::reposition()
|
insilmaril@0
|
615 |
{
|
insilmaril@0
|
616 |
if (depth==0)
|
insilmaril@0
|
617 |
{
|
insilmaril@0
|
618 |
// only calculate the sizes once. If the deepest LMO changes its height,
|
insilmaril@0
|
619 |
// all upper LMOs have to change, too.
|
insilmaril@0
|
620 |
calcBBoxSizeWithChilds();
|
insilmaril@0
|
621 |
|
insilmaril@0
|
622 |
alignRelativeTo ( QPoint (absPos.x(),
|
insilmaril@0
|
623 |
absPos.y()-(bboxTotal.height()-bbox.height())/2) );
|
insilmaril@0
|
624 |
} else
|
insilmaril@0
|
625 |
{
|
insilmaril@0
|
626 |
// This is only important for moving branches:
|
insilmaril@0
|
627 |
// For editing a branch it isn't called...
|
insilmaril@0
|
628 |
alignRelativeTo ( QPoint (absPos.x(),
|
insilmaril@0
|
629 |
absPos.y()-(bboxTotal.height()-bbox.height())/2) );
|
insilmaril@0
|
630 |
}
|
insilmaril@0
|
631 |
}
|
insilmaril@0
|
632 |
|
insilmaril@0
|
633 |
void LinkableMapObj::requestReposition()
|
insilmaril@0
|
634 |
{
|
insilmaril@0
|
635 |
if (!repositionRequest)
|
insilmaril@0
|
636 |
{
|
insilmaril@0
|
637 |
// Pass on the request to parental objects, if this hasn't
|
insilmaril@0
|
638 |
// been done yet
|
insilmaril@0
|
639 |
repositionRequest=true;
|
insilmaril@0
|
640 |
if (parObj) parObj->requestReposition();
|
insilmaril@0
|
641 |
}
|
insilmaril@0
|
642 |
}
|
insilmaril@0
|
643 |
|
insilmaril@0
|
644 |
void LinkableMapObj::forceReposition()
|
insilmaril@0
|
645 |
{
|
insilmaril@0
|
646 |
// Sometimes a reposition has to be done immediatly: For example
|
insilmaril@0
|
647 |
// if the note editor flag changes, there is no user event in mapeditor
|
insilmaril@0
|
648 |
// which could collect requests for a reposition.
|
insilmaril@0
|
649 |
// Then we have to call forceReposition()
|
insilmaril@0
|
650 |
// But no rule without exception: While loading a map or undoing it,
|
insilmaril@0
|
651 |
// we want to block expensive repositioning, but just do it once at
|
insilmaril@0
|
652 |
// the end, thus check first:
|
insilmaril@0
|
653 |
|
insilmaril@0
|
654 |
if (mapEditor->blockReposition()) return;
|
insilmaril@0
|
655 |
|
insilmaril@0
|
656 |
// Pass on the request to parental objects, if this hasn't been done yet
|
insilmaril@0
|
657 |
|
insilmaril@0
|
658 |
if (parObj)
|
insilmaril@0
|
659 |
parObj->forceReposition();
|
insilmaril@0
|
660 |
else
|
insilmaril@83
|
661 |
reposition();
|
insilmaril@83
|
662 |
}
|
insilmaril@0
|
663 |
|
insilmaril@0
|
664 |
bool LinkableMapObj::repositionRequested()
|
insilmaril@0
|
665 |
{
|
insilmaril@0
|
666 |
return repositionRequest;
|
insilmaril@0
|
667 |
}
|
insilmaril@0
|
668 |
|
insilmaril@0
|
669 |
|
insilmaril@0
|
670 |
void LinkableMapObj::setSelBox()
|
insilmaril@0
|
671 |
{
|
insilmaril@0
|
672 |
selbox->setX (bbox.x() );
|
insilmaril@0
|
673 |
selbox->setY (bbox.y() );
|
insilmaril@0
|
674 |
selbox->setSize (bbox.width(), bbox.height() );
|
insilmaril@0
|
675 |
}
|
insilmaril@0
|
676 |
|
insilmaril@0
|
677 |
void LinkableMapObj::select()
|
insilmaril@0
|
678 |
{
|
insilmaril@0
|
679 |
setSelBox();
|
insilmaril@0
|
680 |
selected=true;
|
insilmaril@0
|
681 |
selbox->show();
|
insilmaril@0
|
682 |
}
|
insilmaril@0
|
683 |
|
insilmaril@0
|
684 |
|
insilmaril@0
|
685 |
void LinkableMapObj::unselect()
|
insilmaril@0
|
686 |
{
|
insilmaril@0
|
687 |
selected=false;
|
insilmaril@0
|
688 |
selbox->hide();
|
insilmaril@0
|
689 |
}
|
insilmaril@0
|
690 |
|
insilmaril@0
|
691 |
void LinkableMapObj::parabel (QPointArray &ya, double p1x, double p1y, double p2x, double p2y)
|
insilmaril@0
|
692 |
|
insilmaril@0
|
693 |
{
|
insilmaril@0
|
694 |
double vx=p2x - p1x; // V=P2-P1
|
insilmaril@0
|
695 |
double vy=p2y - p1y;
|
insilmaril@0
|
696 |
|
insilmaril@0
|
697 |
double dx; // delta x during calculation of parabel
|
insilmaril@0
|
698 |
|
insilmaril@0
|
699 |
double pnx; // next point
|
insilmaril@0
|
700 |
double pny;
|
insilmaril@0
|
701 |
double m;
|
insilmaril@0
|
702 |
|
insilmaril@0
|
703 |
if (vx > -0.0001 && vx < 0.0001)
|
insilmaril@0
|
704 |
m=0;
|
insilmaril@0
|
705 |
else
|
insilmaril@0
|
706 |
m=(vy / (vx*vx));
|
insilmaril@0
|
707 |
dx=vx/(arcsegs);
|
insilmaril@0
|
708 |
int i;
|
insilmaril@104
|
709 |
ya.setPoint (0,QPoint (qRound(p1x),qRound(p1y)));
|
insilmaril@0
|
710 |
for (i=1;i<=arcsegs;i++)
|
insilmaril@0
|
711 |
{
|
insilmaril@0
|
712 |
pnx=p1x+dx;
|
insilmaril@0
|
713 |
pny=m*(pnx-parPos.x())*(pnx-parPos.x())+parPos.y();
|
insilmaril@104
|
714 |
ya.setPoint (i,QPoint (qRound(pnx),qRound(pny)));
|
insilmaril@0
|
715 |
p1x=pnx;
|
insilmaril@0
|
716 |
p1y=pny;
|
insilmaril@0
|
717 |
}
|
insilmaril@0
|
718 |
}
|
insilmaril@0
|
719 |
|