insilmaril@0
|
1 |
#include "branchobj.h"
|
insilmaril@616
|
2 |
|
insilmaril@749
|
3 |
#include "branchitem.h"
|
insilmaril@643
|
4 |
#include "geometry.h"
|
insilmaril@0
|
5 |
#include "mapeditor.h"
|
insilmaril@0
|
6 |
#include "mainwindow.h"
|
insilmaril@616
|
7 |
#include "misc.h"
|
insilmaril@616
|
8 |
|
insilmaril@767
|
9 |
extern FlagRow *standardFlagsMaster;
|
insilmaril@767
|
10 |
extern FlagRow *systemFlagsMaster;
|
insilmaril@0
|
11 |
|
insilmaril@0
|
12 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
13 |
// BranchObj
|
insilmaril@0
|
14 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
15 |
|
insilmaril@746
|
16 |
BranchObj::BranchObj () :OrnamentedObj() // FIXME-3 needed at all?
|
insilmaril@0
|
17 |
{
|
insilmaril@0
|
18 |
// cout << "Const BranchObj ()\n";
|
insilmaril@0
|
19 |
setParObj (this);
|
insilmaril@0
|
20 |
init();
|
insilmaril@0
|
21 |
}
|
insilmaril@0
|
22 |
|
insilmaril@755
|
23 |
BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s)// FIXME-3 needed at all?
|
insilmaril@0
|
24 |
{
|
insilmaril@755
|
25 |
// cout << "Const BranchObj (s) \n";
|
insilmaril@83
|
26 |
parObj=NULL;
|
insilmaril@408
|
27 |
scene=s;
|
insilmaril@755
|
28 |
init();
|
insilmaril@0
|
29 |
}
|
insilmaril@0
|
30 |
|
insilmaril@755
|
31 |
BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)// FIXME-3 needed at all?
|
insilmaril@0
|
32 |
{
|
insilmaril@408
|
33 |
// cout << "Const BranchObj (s,p)\n";
|
insilmaril@408
|
34 |
scene=s;
|
insilmaril@0
|
35 |
setParObj (p);
|
insilmaril@773
|
36 |
if (treeItem->depth()==1) // FIXME-3 needed to recursively calc depth?
|
insilmaril@0
|
37 |
// Calc angle to mapCenter if I am a mainbranch
|
insilmaril@0
|
38 |
// needed for reordering the mainbranches clockwise
|
insilmaril@0
|
39 |
// around mapcenter
|
insilmaril@408
|
40 |
angle=getAngle (QPointF (x() - parObj->getChildPos().x() ,
|
insilmaril@408
|
41 |
(y() - parObj->getChildPos().y() ) ) );
|
insilmaril@0
|
42 |
init();
|
insilmaril@0
|
43 |
}
|
insilmaril@0
|
44 |
|
insilmaril@0
|
45 |
BranchObj::~BranchObj ()
|
insilmaril@0
|
46 |
{
|
insilmaril@757
|
47 |
// cout << "Destr BranchObj of "<<this<<" ("<<treeItem->getHeading().toStdString()<<")"<<endl;
|
insilmaril@757
|
48 |
|
insilmaril@722
|
49 |
// If I'm animated, I need to un-animate myself first
|
insilmaril@722
|
50 |
if (anim.isAnimated() )
|
insilmaril@722
|
51 |
{
|
insilmaril@722
|
52 |
anim.setAnimated (false);
|
insilmaril@773
|
53 |
VymModel *model=treeItem->getModel();
|
insilmaril@722
|
54 |
model->stopAnimation (this);
|
insilmaril@722
|
55 |
}
|
insilmaril@722
|
56 |
|
insilmaril@0
|
57 |
// Check, if this branch was the last child to be deleted
|
insilmaril@749
|
58 |
// If so, unset the scrolled flags in parent // FIXME-2 better do this in model?
|
insilmaril@0
|
59 |
|
insilmaril@749
|
60 |
/*
|
insilmaril@425
|
61 |
BranchObj *po=(BranchObj*)parObj;
|
insilmaril@83
|
62 |
BranchObj *bo;
|
insilmaril@0
|
63 |
if (po)
|
insilmaril@0
|
64 |
{
|
insilmaril@425
|
65 |
bo=((BranchObj*)parObj)->getLastBranch();
|
insilmaril@425
|
66 |
if (bo) po->unScroll();
|
insilmaril@0
|
67 |
}
|
insilmaril@749
|
68 |
*/
|
insilmaril@83
|
69 |
clear();
|
insilmaril@0
|
70 |
}
|
insilmaril@0
|
71 |
|
insilmaril@0
|
72 |
bool BranchObj::operator< ( const BranchObj & other )
|
insilmaril@0
|
73 |
{
|
insilmaril@0
|
74 |
return angle < other.angle;
|
insilmaril@0
|
75 |
}
|
insilmaril@0
|
76 |
|
insilmaril@0
|
77 |
bool BranchObj::operator== ( const BranchObj & other )
|
insilmaril@0
|
78 |
{
|
insilmaril@0
|
79 |
return angle == other.angle;
|
insilmaril@0
|
80 |
}
|
insilmaril@0
|
81 |
|
insilmaril@0
|
82 |
void BranchObj::init ()
|
insilmaril@0
|
83 |
{
|
insilmaril@83
|
84 |
if (parObj)
|
insilmaril@83
|
85 |
{
|
insilmaril@83
|
86 |
absPos=getRandPos();
|
insilmaril@83
|
87 |
absPos+=parObj->getChildPos();
|
insilmaril@83
|
88 |
}
|
insilmaril@0
|
89 |
|
insilmaril@169
|
90 |
includeImagesVer=false;
|
insilmaril@169
|
91 |
includeImagesHor=false;
|
insilmaril@0
|
92 |
}
|
insilmaril@0
|
93 |
|
insilmaril@0
|
94 |
void BranchObj::copy (BranchObj* other)
|
insilmaril@0
|
95 |
{
|
insilmaril@0
|
96 |
OrnamentedObj::copy(other);
|
insilmaril@0
|
97 |
|
insilmaril@404
|
98 |
for (int i=0; i<other->floatimage.size(); ++i)
|
insilmaril@404
|
99 |
addFloatImage (other->floatimage.at(i));
|
insilmaril@749
|
100 |
|
insilmaril@0
|
101 |
setVisibility (other->visible);
|
insilmaril@0
|
102 |
|
insilmaril@0
|
103 |
angle=other->angle;
|
insilmaril@0
|
104 |
|
insilmaril@0
|
105 |
positionBBox();
|
insilmaril@0
|
106 |
}
|
insilmaril@0
|
107 |
|
insilmaril@0
|
108 |
void BranchObj::clear()
|
insilmaril@0
|
109 |
{
|
insilmaril@755
|
110 |
//setVisibility (true); //FIXME-4 needed?
|
insilmaril@425
|
111 |
|
insilmaril@404
|
112 |
while (!floatimage.isEmpty())
|
insilmaril@404
|
113 |
delete floatimage.takeFirst();
|
insilmaril@404
|
114 |
|
insilmaril@95
|
115 |
while (!xlink.isEmpty())
|
insilmaril@406
|
116 |
delete xlink.takeFirst();
|
insilmaril@0
|
117 |
}
|
insilmaril@0
|
118 |
|
insilmaril@411
|
119 |
bool isAbove (BranchObj* a, BranchObj *b)
|
insilmaril@411
|
120 |
{
|
insilmaril@411
|
121 |
if (a->angle < b->angle)
|
insilmaril@411
|
122 |
return true;
|
insilmaril@411
|
123 |
else
|
insilmaril@411
|
124 |
return false;
|
insilmaril@411
|
125 |
}
|
insilmaril@411
|
126 |
|
insilmaril@408
|
127 |
void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
|
insilmaril@0
|
128 |
{
|
insilmaril@0
|
129 |
// Temporary link to lmo
|
insilmaril@0
|
130 |
// m is position of mouse pointer
|
insilmaril@0
|
131 |
// offset 0: default 1: below lmo -1 above lmo (if possible)
|
insilmaril@0
|
132 |
|
insilmaril@0
|
133 |
|
insilmaril@0
|
134 |
BranchObj* o=(BranchObj*)(lmo);
|
insilmaril@0
|
135 |
if (!parObjTmpBuf)
|
insilmaril@0
|
136 |
parObjTmpBuf=parObj;
|
insilmaril@0
|
137 |
|
insilmaril@0
|
138 |
// ignore mapcenter and mainbranch
|
insilmaril@755
|
139 |
if (treeItem->depth()<2) off=0;
|
insilmaril@0
|
140 |
if (off==0)
|
insilmaril@0
|
141 |
link2ParPos=false;
|
insilmaril@0
|
142 |
else
|
insilmaril@0
|
143 |
link2ParPos=true;
|
insilmaril@93
|
144 |
parObj=o;
|
insilmaril@0
|
145 |
|
insilmaril@755
|
146 |
// FIXME-2 depth=parObj->getDepth()+1;
|
insilmaril@0
|
147 |
|
insilmaril@0
|
148 |
// setLinkStyle calls updateLink, only set it once
|
insilmaril@0
|
149 |
if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
|
insilmaril@0
|
150 |
|
insilmaril@0
|
151 |
// Move temporary to new position at destination
|
insilmaril@0
|
152 |
// Usually the positioning would be done by reposition(),
|
insilmaril@0
|
153 |
// but then also the destination branch would "Jump" around...
|
insilmaril@0
|
154 |
// Better just do it approximately
|
insilmaril@773
|
155 |
if (treeItem->depth()==1) // FIXME-3 needed to recursively calc depth?
|
insilmaril@0
|
156 |
{ // new parent is the mapcenter itself
|
insilmaril@0
|
157 |
|
insilmaril@408
|
158 |
QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
|
insilmaril@0
|
159 |
m.y() - o->getChildPos().y() ));
|
insilmaril@0
|
160 |
if (p.x()<0) p.setX( p.x()-bbox.width() );
|
insilmaril@0
|
161 |
move2RelPos (p);
|
insilmaril@0
|
162 |
} else
|
insilmaril@0
|
163 |
{
|
insilmaril@408
|
164 |
qreal y;
|
insilmaril@0
|
165 |
if (off==0)
|
insilmaril@0
|
166 |
{
|
insilmaril@0
|
167 |
// new parent is just a branch, link to it
|
insilmaril@721
|
168 |
QRectF t=o->getBBoxSizeWithChildren();
|
insilmaril@750
|
169 |
if (o->getTreeItem()->getLastBranch())
|
insilmaril@0
|
170 |
y=t.y() + t.height() ;
|
insilmaril@0
|
171 |
else
|
insilmaril@0
|
172 |
y=t.y();
|
insilmaril@0
|
173 |
|
insilmaril@0
|
174 |
} else
|
insilmaril@0
|
175 |
{
|
insilmaril@0
|
176 |
if (off<0)
|
insilmaril@0
|
177 |
// we want to link above lmo
|
insilmaril@0
|
178 |
y=o->y() - height() + 5;
|
insilmaril@0
|
179 |
else
|
insilmaril@0
|
180 |
// we want to link below lmo
|
insilmaril@0
|
181 |
// Bottom of sel should be 5 pixels above
|
insilmaril@0
|
182 |
// the bottom of the branch _below_ the target:
|
insilmaril@0
|
183 |
// Don't try to find that branch, guess 12 pixels
|
insilmaril@0
|
184 |
y=o->getChildPos().y() -height() + 12;
|
insilmaril@0
|
185 |
}
|
insilmaril@462
|
186 |
if (o->getOrientation()==LinkableMapObj::LeftOfCenter)
|
insilmaril@0
|
187 |
move ( o->getChildPos().x() - linkwidth, y );
|
insilmaril@0
|
188 |
else
|
insilmaril@0
|
189 |
move (o->getChildPos().x() + linkwidth, y );
|
insilmaril@0
|
190 |
}
|
insilmaril@0
|
191 |
|
insilmaril@0
|
192 |
// updateLink is called implicitly in move
|
insilmaril@417
|
193 |
requestReposition();
|
insilmaril@0
|
194 |
}
|
insilmaril@0
|
195 |
|
insilmaril@0
|
196 |
void BranchObj::unsetParObjTmp()
|
insilmaril@0
|
197 |
{
|
insilmaril@0
|
198 |
if (parObjTmpBuf)
|
insilmaril@0
|
199 |
{
|
insilmaril@0
|
200 |
link2ParPos=false;
|
insilmaril@0
|
201 |
parObj=parObjTmpBuf;
|
insilmaril@0
|
202 |
parObjTmpBuf=NULL;
|
insilmaril@755
|
203 |
//FIXME-2 depth=parObj->getDepth()+1;
|
insilmaril@0
|
204 |
setLinkStyle (getDefLinkStyle() );
|
insilmaril@93
|
205 |
updateLink();
|
insilmaril@0
|
206 |
}
|
insilmaril@0
|
207 |
}
|
insilmaril@0
|
208 |
|
insilmaril@0
|
209 |
void BranchObj::setVisibility(bool v, int toDepth)
|
insilmaril@0
|
210 |
{
|
insilmaril@749
|
211 |
BranchItem *bi=(BranchItem*)treeItem;
|
insilmaril@755
|
212 |
if (bi->depth() <= toDepth)
|
insilmaril@0
|
213 |
{
|
insilmaril@0
|
214 |
frame->setVisibility(v);
|
insilmaril@0
|
215 |
heading->setVisibility(v);
|
insilmaril@0
|
216 |
systemFlags->setVisibility(v);
|
insilmaril@0
|
217 |
standardFlags->setVisibility(v);
|
insilmaril@0
|
218 |
LinkableMapObj::setVisibility (v);
|
insilmaril@730
|
219 |
int i;
|
insilmaril@730
|
220 |
for (i=0; i<floatimage.size(); ++i)
|
insilmaril@730
|
221 |
floatimage.at(i)->setVisibility (v);
|
insilmaril@730
|
222 |
for (i=0; i<xlink.size(); ++i)
|
insilmaril@730
|
223 |
xlink.at(i)->setVisibility ();
|
insilmaril@730
|
224 |
|
insilmaril@721
|
225 |
// Only change children, if I am not scrolled
|
insilmaril@749
|
226 |
if (! bi->isScrolled() && (bi->depth() < toDepth))
|
insilmaril@0
|
227 |
{
|
insilmaril@721
|
228 |
// Now go recursivly through all children
|
insilmaril@750
|
229 |
for (i=0; i<treeItem->branchCount(); ++i)
|
insilmaril@753
|
230 |
treeItem->getBranchObjNum(i)->setVisibility (v,toDepth);
|
insilmaril@0
|
231 |
}
|
insilmaril@0
|
232 |
} // depth <= toDepth
|
insilmaril@0
|
233 |
requestReposition();
|
insilmaril@0
|
234 |
}
|
insilmaril@0
|
235 |
|
insilmaril@0
|
236 |
void BranchObj::setVisibility(bool v)
|
insilmaril@0
|
237 |
{
|
insilmaril@0
|
238 |
setVisibility (v,MAX_DEPTH);
|
insilmaril@0
|
239 |
}
|
insilmaril@0
|
240 |
|
insilmaril@0
|
241 |
|
insilmaril@0
|
242 |
void BranchObj::setLinkColor ()
|
insilmaril@0
|
243 |
{
|
insilmaril@0
|
244 |
// Overloaded from LinkableMapObj
|
insilmaril@0
|
245 |
// BranchObj can use color of heading
|
insilmaril@0
|
246 |
|
insilmaril@773
|
247 |
VymModel *model=treeItem->getModel();
|
insilmaril@721
|
248 |
if (model)
|
insilmaril@611
|
249 |
{
|
insilmaril@721
|
250 |
if (model->getMapLinkColorHint()==HeadingColor)
|
insilmaril@164
|
251 |
LinkableMapObj::setLinkColor (heading->getColor() );
|
insilmaril@164
|
252 |
else
|
insilmaril@164
|
253 |
LinkableMapObj::setLinkColor ();
|
insilmaril@611
|
254 |
}
|
insilmaril@0
|
255 |
}
|
insilmaril@0
|
256 |
|
insilmaril@753
|
257 |
void BranchObj::updateContentSize()
|
insilmaril@753
|
258 |
{
|
insilmaril@753
|
259 |
calcBBoxSize();
|
insilmaril@753
|
260 |
positionBBox();
|
insilmaril@753
|
261 |
requestReposition();
|
insilmaril@100
|
262 |
}
|
insilmaril@0
|
263 |
|
insilmaril@333
|
264 |
void BranchObj::positionContents()
|
insilmaril@333
|
265 |
{
|
insilmaril@404
|
266 |
for (int i=0; i<floatimage.size(); ++i )
|
insilmaril@404
|
267 |
floatimage.at(i)->reposition();
|
insilmaril@333
|
268 |
OrnamentedObj::positionContents();
|
insilmaril@333
|
269 |
}
|
insilmaril@0
|
270 |
|
insilmaril@0
|
271 |
void BranchObj::move (double x, double y)
|
insilmaril@0
|
272 |
{
|
insilmaril@0
|
273 |
OrnamentedObj::move (x,y);
|
insilmaril@404
|
274 |
for (int i=0; i<floatimage.size(); ++i )
|
insilmaril@404
|
275 |
floatimage.at(i)->reposition();
|
insilmaril@0
|
276 |
positionBBox();
|
insilmaril@0
|
277 |
}
|
insilmaril@0
|
278 |
|
insilmaril@408
|
279 |
void BranchObj::move (QPointF p)
|
insilmaril@0
|
280 |
{
|
insilmaril@0
|
281 |
move (p.x(), p.y());
|
insilmaril@0
|
282 |
}
|
insilmaril@0
|
283 |
|
insilmaril@0
|
284 |
void BranchObj::moveBy (double x, double y)
|
insilmaril@0
|
285 |
{
|
insilmaril@0
|
286 |
OrnamentedObj::moveBy (x,y);
|
insilmaril@750
|
287 |
for (int i=0; i<treeItem->branchCount(); ++i)
|
insilmaril@753
|
288 |
treeItem->getBranchObjNum(i)->moveBy (x,y);
|
insilmaril@333
|
289 |
positionBBox();
|
insilmaril@0
|
290 |
}
|
insilmaril@83
|
291 |
|
insilmaril@408
|
292 |
void BranchObj::moveBy (QPointF p)
|
insilmaril@0
|
293 |
{
|
insilmaril@0
|
294 |
moveBy (p.x(), p.y());
|
insilmaril@0
|
295 |
}
|
insilmaril@0
|
296 |
|
insilmaril@0
|
297 |
|
insilmaril@0
|
298 |
void BranchObj::positionBBox()
|
insilmaril@0
|
299 |
{
|
insilmaril@408
|
300 |
QPointF ap=getAbsPos();
|
insilmaril@223
|
301 |
bbox.moveTopLeft (ap);
|
insilmaril@169
|
302 |
positionContents();
|
insilmaril@0
|
303 |
|
insilmaril@0
|
304 |
// set the frame
|
insilmaril@408
|
305 |
frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
|
insilmaril@83
|
306 |
|
insilmaril@83
|
307 |
// Update links to other branches
|
insilmaril@406
|
308 |
for (int i=0; i<xlink.size(); ++i)
|
insilmaril@406
|
309 |
xlink.at(i)->updateXLink();
|
insilmaril@0
|
310 |
}
|
insilmaril@0
|
311 |
|
insilmaril@0
|
312 |
void BranchObj::calcBBoxSize()
|
insilmaril@0
|
313 |
{
|
insilmaril@408
|
314 |
QSizeF heading_r=heading->getSize();
|
insilmaril@408
|
315 |
qreal heading_w=(qreal) heading_r.width() ;
|
insilmaril@408
|
316 |
qreal heading_h=(qreal) heading_r.height() ;
|
insilmaril@767
|
317 |
QSizeF sysflags_r=systemFlags->getSize();
|
insilmaril@767
|
318 |
qreal sysflags_h=sysflags_r.height();
|
insilmaril@767
|
319 |
qreal sysflags_w=sysflags_r.width();
|
insilmaril@767
|
320 |
QSizeF stanflags_r=standardFlags->getSize();
|
insilmaril@767
|
321 |
qreal stanflags_h=stanflags_r.height();
|
insilmaril@767
|
322 |
qreal stanflags_w=stanflags_r.width();
|
insilmaril@408
|
323 |
qreal w;
|
insilmaril@408
|
324 |
qreal h;
|
insilmaril@0
|
325 |
|
insilmaril@0
|
326 |
// set width to sum of all widths
|
insilmaril@0
|
327 |
w=heading_w + sysflags_w + stanflags_w;
|
insilmaril@0
|
328 |
// set height to maximum needed height
|
insilmaril@0
|
329 |
h=max (sysflags_h,stanflags_h);
|
insilmaril@0
|
330 |
h=max (h,heading_h);
|
insilmaril@0
|
331 |
|
insilmaril@223
|
332 |
// Save the dimension of flags and heading
|
insilmaril@408
|
333 |
ornamentsBBox.setSize ( QSizeF(w,h));
|
insilmaril@223
|
334 |
|
insilmaril@223
|
335 |
// clickBox includes Flags and Heading
|
insilmaril@223
|
336 |
clickBox.setSize (ornamentsBBox.size() );
|
insilmaril@169
|
337 |
|
insilmaril@169
|
338 |
// Floatimages
|
insilmaril@408
|
339 |
QPointF rp;
|
insilmaril@169
|
340 |
|
insilmaril@169
|
341 |
topPad=botPad=leftPad=rightPad=0;
|
insilmaril@169
|
342 |
if (includeImagesVer || includeImagesHor)
|
insilmaril@169
|
343 |
{
|
insilmaril@749
|
344 |
if (treeItem->imageCount()>0)
|
insilmaril@169
|
345 |
{
|
insilmaril@404
|
346 |
for (int i=0; i<floatimage.size(); ++i )
|
insilmaril@169
|
347 |
{
|
insilmaril@404
|
348 |
rp=floatimage.at(i)->getRelPos();
|
insilmaril@169
|
349 |
if (includeImagesVer)
|
insilmaril@169
|
350 |
{
|
insilmaril@169
|
351 |
if (rp.y() < 0)
|
insilmaril@223
|
352 |
topPad=max (topPad,-rp.y()-h);
|
insilmaril@404
|
353 |
if (rp.y()+floatimage.at(i)->height() > 0)
|
insilmaril@404
|
354 |
botPad=max (botPad,rp.y()+floatimage.at(i)->height());
|
insilmaril@169
|
355 |
}
|
insilmaril@213
|
356 |
if (includeImagesHor)
|
insilmaril@213
|
357 |
{
|
insilmaril@462
|
358 |
if (orientation==LinkableMapObj::RightOfCenter)
|
insilmaril@223
|
359 |
{
|
insilmaril@223
|
360 |
if (-rp.x()-w > 0)
|
insilmaril@223
|
361 |
leftPad=max (leftPad,-rp.x()-w);
|
insilmaril@404
|
362 |
if (rp.x()+floatimage.at(i)->width() > 0)
|
insilmaril@404
|
363 |
rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
|
insilmaril@223
|
364 |
} else
|
insilmaril@223
|
365 |
{
|
insilmaril@223
|
366 |
if (rp.x()< 0)
|
insilmaril@223
|
367 |
leftPad=max (leftPad,-rp.x());
|
insilmaril@404
|
368 |
if (rp.x()+floatimage.at(i)->width() > w)
|
insilmaril@404
|
369 |
rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
|
insilmaril@223
|
370 |
}
|
insilmaril@213
|
371 |
}
|
insilmaril@169
|
372 |
}
|
insilmaril@169
|
373 |
}
|
insilmaril@169
|
374 |
h+=topPad+botPad;
|
insilmaril@213
|
375 |
w+=leftPad+rightPad;
|
insilmaril@169
|
376 |
}
|
insilmaril@169
|
377 |
|
insilmaril@169
|
378 |
// Frame thickness
|
insilmaril@462
|
379 |
w+=frame->getPadding();
|
insilmaril@462
|
380 |
h+=frame->getPadding();
|
insilmaril@169
|
381 |
|
insilmaril@169
|
382 |
// Finally set size
|
insilmaril@408
|
383 |
bbox.setSize (QSizeF (w,h));
|
insilmaril@0
|
384 |
}
|
insilmaril@0
|
385 |
|
insilmaril@223
|
386 |
void BranchObj::setDockPos()
|
insilmaril@223
|
387 |
{
|
insilmaril@382
|
388 |
// Sets childpos and parpos depending on orientation
|
insilmaril@462
|
389 |
if (getOrientation()==LinkableMapObj::LeftOfCenter )
|
insilmaril@223
|
390 |
{
|
insilmaril@440
|
391 |
childPos=QPointF (
|
insilmaril@440
|
392 |
ornamentsBBox.bottomLeft().x(),
|
insilmaril@440
|
393 |
bottomlineY);
|
insilmaril@440
|
394 |
parPos=QPointF (
|
insilmaril@440
|
395 |
ornamentsBBox.bottomRight().x(),
|
insilmaril@440
|
396 |
bottomlineY);
|
insilmaril@223
|
397 |
} else
|
insilmaril@223
|
398 |
{
|
insilmaril@440
|
399 |
childPos=QPointF (
|
insilmaril@440
|
400 |
ornamentsBBox.bottomRight().x(),
|
insilmaril@440
|
401 |
bottomlineY);
|
insilmaril@440
|
402 |
parPos=QPointF (
|
insilmaril@440
|
403 |
ornamentsBBox.bottomLeft().x(),
|
insilmaril@440
|
404 |
bottomlineY);
|
insilmaril@223
|
405 |
}
|
insilmaril@223
|
406 |
}
|
insilmaril@382
|
407 |
|
insilmaril@767
|
408 |
void BranchObj::updateData()
|
insilmaril@0
|
409 |
{
|
insilmaril@767
|
410 |
bool changed=false;
|
insilmaril@753
|
411 |
if (!treeItem)
|
insilmaril@254
|
412 |
{
|
insilmaril@753
|
413 |
qWarning ("BranchObj::udpateHeading treeItem==NULL");
|
insilmaril@753
|
414 |
return;
|
insilmaril@753
|
415 |
}
|
insilmaril@767
|
416 |
QString s=treeItem->getHeading();
|
insilmaril@767
|
417 |
if (s!=heading->text())
|
insilmaril@767
|
418 |
{
|
insilmaril@767
|
419 |
heading->setText (s);
|
insilmaril@767
|
420 |
changed=true;
|
insilmaril@767
|
421 |
}
|
insilmaril@767
|
422 |
QStringList TIactiveFlags=treeItem->activeStandardFlagNames();
|
insilmaril@767
|
423 |
|
insilmaril@767
|
424 |
// Add missing standard flags active in TreeItem
|
insilmaril@767
|
425 |
for (int i=0;i<=TIactiveFlags.size()-1;i++)
|
insilmaril@767
|
426 |
{
|
insilmaril@767
|
427 |
if (!standardFlags->isActive (TIactiveFlags.at(i) ))
|
insilmaril@767
|
428 |
{
|
insilmaril@767
|
429 |
Flag *f=standardFlagsMaster->getFlag(TIactiveFlags.at(i));
|
insilmaril@767
|
430 |
if (f) standardFlags->activate (f);
|
insilmaril@767
|
431 |
changed=true;
|
insilmaril@767
|
432 |
}
|
insilmaril@767
|
433 |
}
|
insilmaril@767
|
434 |
// Remove standard flags no longer active in TreeItem
|
insilmaril@767
|
435 |
QStringList BOactiveFlags=standardFlags->activeFlagNames();
|
insilmaril@767
|
436 |
for (int i=0;i<BOactiveFlags.size();++i)
|
insilmaril@767
|
437 |
if (!TIactiveFlags.contains (BOactiveFlags.at(i)))
|
insilmaril@767
|
438 |
{
|
insilmaril@767
|
439 |
standardFlags->deactivate (BOactiveFlags.at(i));
|
insilmaril@767
|
440 |
changed=true;
|
insilmaril@767
|
441 |
}
|
insilmaril@767
|
442 |
|
insilmaril@767
|
443 |
// Add missing system flags active in TreeItem
|
insilmaril@767
|
444 |
TIactiveFlags=treeItem->activeSystemFlagNames();
|
insilmaril@767
|
445 |
for (int i=0;i<TIactiveFlags.size();++i)
|
insilmaril@767
|
446 |
{
|
insilmaril@767
|
447 |
if (!systemFlags->isActive (TIactiveFlags.at(i) ))
|
insilmaril@767
|
448 |
{
|
insilmaril@767
|
449 |
Flag *f=systemFlagsMaster->getFlag(TIactiveFlags.at(i));
|
insilmaril@767
|
450 |
if (f) systemFlags->activate (f);
|
insilmaril@767
|
451 |
changed=true;
|
insilmaril@767
|
452 |
}
|
insilmaril@767
|
453 |
}
|
insilmaril@767
|
454 |
// Remove system flags no longer active in TreeItem
|
insilmaril@767
|
455 |
BOactiveFlags=systemFlags->activeFlagNames();
|
insilmaril@767
|
456 |
for (int i=0;i<BOactiveFlags.size();++i)
|
insilmaril@767
|
457 |
{
|
insilmaril@767
|
458 |
if (!TIactiveFlags.contains (BOactiveFlags.at(i)))
|
insilmaril@767
|
459 |
{
|
insilmaril@767
|
460 |
systemFlags->deactivate (BOactiveFlags.at(i));
|
insilmaril@767
|
461 |
changed=true;
|
insilmaril@767
|
462 |
}
|
insilmaril@767
|
463 |
}
|
insilmaril@767
|
464 |
|
insilmaril@767
|
465 |
if (changed)
|
insilmaril@767
|
466 |
updateContentSize();
|
insilmaril@254
|
467 |
}
|
insilmaril@254
|
468 |
|
insilmaril@0
|
469 |
|
insilmaril@95
|
470 |
void BranchObj::addXLink (XLinkObj *xlo)
|
insilmaril@83
|
471 |
{
|
insilmaril@95
|
472 |
xlink.append (xlo);
|
insilmaril@83
|
473 |
|
insilmaril@83
|
474 |
}
|
insilmaril@83
|
475 |
|
insilmaril@95
|
476 |
void BranchObj::removeXLinkRef (XLinkObj *xlo)
|
insilmaril@83
|
477 |
{
|
insilmaril@406
|
478 |
xlink.removeAt (xlink.indexOf(xlo));
|
insilmaril@83
|
479 |
}
|
insilmaril@83
|
480 |
|
insilmaril@95
|
481 |
void BranchObj::deleteXLink(XLinkObj *xlo)
|
insilmaril@83
|
482 |
{
|
insilmaril@95
|
483 |
xlo->deactivate();
|
insilmaril@95
|
484 |
if (!xlo->isUsed()) delete (xlo);
|
insilmaril@83
|
485 |
}
|
insilmaril@83
|
486 |
|
insilmaril@95
|
487 |
void BranchObj::deleteXLinkAt (int i)
|
insilmaril@94
|
488 |
{
|
insilmaril@95
|
489 |
XLinkObj *xlo=xlink.at(i);
|
insilmaril@95
|
490 |
xlo->deactivate();
|
insilmaril@95
|
491 |
if (!xlo->isUsed()) delete(xlo);
|
insilmaril@94
|
492 |
}
|
insilmaril@94
|
493 |
|
insilmaril@97
|
494 |
XLinkObj* BranchObj::XLinkAt (int i)
|
insilmaril@97
|
495 |
{
|
insilmaril@97
|
496 |
return xlink.at(i);
|
insilmaril@97
|
497 |
}
|
insilmaril@97
|
498 |
|
insilmaril@95
|
499 |
BranchObj* BranchObj::XLinkTargetAt (int i)
|
insilmaril@89
|
500 |
{
|
insilmaril@406
|
501 |
if (i>=0 && i<xlink.size())
|
insilmaril@406
|
502 |
{
|
insilmaril@406
|
503 |
if (xlink.at(i))
|
insilmaril@406
|
504 |
return xlink.at(i)->otherBranch (this);
|
insilmaril@406
|
505 |
}
|
insilmaril@406
|
506 |
return NULL;
|
insilmaril@89
|
507 |
}
|
insilmaril@89
|
508 |
|
insilmaril@169
|
509 |
void BranchObj::setIncludeImagesVer(bool b)
|
insilmaril@169
|
510 |
{
|
insilmaril@169
|
511 |
includeImagesVer=b;
|
insilmaril@169
|
512 |
calcBBoxSize();
|
insilmaril@169
|
513 |
positionBBox();
|
insilmaril@169
|
514 |
requestReposition();
|
insilmaril@169
|
515 |
}
|
insilmaril@169
|
516 |
|
insilmaril@169
|
517 |
bool BranchObj::getIncludeImagesVer()
|
insilmaril@169
|
518 |
{
|
insilmaril@169
|
519 |
return includeImagesVer;
|
insilmaril@169
|
520 |
}
|
insilmaril@169
|
521 |
|
insilmaril@169
|
522 |
void BranchObj::setIncludeImagesHor(bool b)
|
insilmaril@169
|
523 |
{
|
insilmaril@169
|
524 |
includeImagesHor=b;
|
insilmaril@169
|
525 |
calcBBoxSize();
|
insilmaril@169
|
526 |
positionBBox();
|
insilmaril@169
|
527 |
requestReposition();
|
insilmaril@169
|
528 |
}
|
insilmaril@169
|
529 |
|
insilmaril@169
|
530 |
bool BranchObj::getIncludeImagesHor()
|
insilmaril@169
|
531 |
{
|
insilmaril@169
|
532 |
return includeImagesHor;
|
insilmaril@169
|
533 |
}
|
insilmaril@169
|
534 |
|
insilmaril@169
|
535 |
QString BranchObj::getIncludeImageAttr()
|
insilmaril@169
|
536 |
{
|
insilmaril@169
|
537 |
QString a;
|
insilmaril@169
|
538 |
if (includeImagesVer)
|
insilmaril@169
|
539 |
a=attribut ("incImgV","true");
|
insilmaril@169
|
540 |
else
|
insilmaril@169
|
541 |
a=attribut ("incImgV","false");
|
insilmaril@169
|
542 |
if (includeImagesHor)
|
insilmaril@213
|
543 |
a+=attribut ("incImgH","true");
|
insilmaril@169
|
544 |
else
|
insilmaril@213
|
545 |
a+=attribut ("incImgH","false");
|
insilmaril@169
|
546 |
return a;
|
insilmaril@169
|
547 |
}
|
insilmaril@169
|
548 |
|
insilmaril@395
|
549 |
FloatImageObj* BranchObj::addFloatImage ()
|
insilmaril@0
|
550 |
{
|
insilmaril@408
|
551 |
FloatImageObj *newfi=new FloatImageObj (scene,this);
|
insilmaril@0
|
552 |
floatimage.append (newfi);
|
insilmaril@749
|
553 |
if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
|
insilmaril@0
|
554 |
newfi->setVisibility (false);
|
insilmaril@0
|
555 |
else
|
insilmaril@0
|
556 |
newfi->setVisibility(visible);
|
insilmaril@395
|
557 |
/*
|
insilmaril@169
|
558 |
calcBBoxSize();
|
insilmaril@169
|
559 |
positionBBox();
|
insilmaril@395
|
560 |
*/
|
insilmaril@0
|
561 |
requestReposition();
|
insilmaril@0
|
562 |
return newfi;
|
insilmaril@0
|
563 |
}
|
insilmaril@0
|
564 |
|
insilmaril@395
|
565 |
FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
|
insilmaril@0
|
566 |
{
|
insilmaril@408
|
567 |
FloatImageObj *newfi=new FloatImageObj (scene,this);
|
insilmaril@0
|
568 |
floatimage.append (newfi);
|
insilmaril@0
|
569 |
newfi->copy (fio);
|
insilmaril@749
|
570 |
if (((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
|
insilmaril@0
|
571 |
newfi->setVisibility (false);
|
insilmaril@0
|
572 |
else
|
insilmaril@0
|
573 |
newfi->setVisibility(visible);
|
insilmaril@395
|
574 |
/*
|
insilmaril@169
|
575 |
calcBBoxSize();
|
insilmaril@169
|
576 |
positionBBox();
|
insilmaril@395
|
577 |
*/
|
insilmaril@0
|
578 |
requestReposition();
|
insilmaril@0
|
579 |
return newfi;
|
insilmaril@0
|
580 |
}
|
insilmaril@0
|
581 |
|
insilmaril@0
|
582 |
FloatImageObj* BranchObj::getFirstFloatImage ()
|
insilmaril@0
|
583 |
{
|
insilmaril@0
|
584 |
return floatimage.first();
|
insilmaril@0
|
585 |
}
|
insilmaril@0
|
586 |
|
insilmaril@0
|
587 |
FloatImageObj* BranchObj::getLastFloatImage ()
|
insilmaril@0
|
588 |
{
|
insilmaril@0
|
589 |
return floatimage.last();
|
insilmaril@0
|
590 |
}
|
insilmaril@0
|
591 |
|
insilmaril@0
|
592 |
FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
|
insilmaril@0
|
593 |
{
|
insilmaril@0
|
594 |
return floatimage.at(i);
|
insilmaril@0
|
595 |
}
|
insilmaril@0
|
596 |
|
insilmaril@0
|
597 |
void BranchObj::removeFloatImage (FloatImageObj *fio)
|
insilmaril@0
|
598 |
{
|
insilmaril@404
|
599 |
int i=floatimage.indexOf (fio);
|
insilmaril@411
|
600 |
if (i>-1) delete (floatimage.takeAt (i));
|
insilmaril@169
|
601 |
calcBBoxSize();
|
insilmaril@169
|
602 |
positionBBox();
|
insilmaril@0
|
603 |
requestReposition();
|
insilmaril@0
|
604 |
}
|
insilmaril@0
|
605 |
|
insilmaril@0
|
606 |
void BranchObj::savePosInAngle ()
|
insilmaril@0
|
607 |
{
|
insilmaril@0
|
608 |
// Save position in angle
|
insilmaril@750
|
609 |
for (int i=0; i<treeItem->branchCount(); ++i)
|
insilmaril@753
|
610 |
treeItem->getBranchObjNum(i)->angle=i;
|
insilmaril@0
|
611 |
}
|
insilmaril@0
|
612 |
|
insilmaril@146
|
613 |
void BranchObj::setDefAttr (BranchModification mod)
|
insilmaril@146
|
614 |
{
|
insilmaril@146
|
615 |
int fontsize;
|
insilmaril@755
|
616 |
switch (treeItem->depth())
|
insilmaril@146
|
617 |
{
|
insilmaril@146
|
618 |
case 0: fontsize=16; break;
|
insilmaril@146
|
619 |
case 1: fontsize=12; break;
|
insilmaril@146
|
620 |
default: fontsize=10; break;
|
insilmaril@146
|
621 |
}
|
insilmaril@146
|
622 |
|
insilmaril@146
|
623 |
setLinkColor ();
|
insilmaril@146
|
624 |
setLinkStyle(getDefLinkStyle());
|
insilmaril@146
|
625 |
QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
|
insilmaril@146
|
626 |
font.setPointSize(fontsize);
|
insilmaril@146
|
627 |
heading->setFont(font );
|
insilmaril@146
|
628 |
|
insilmaril@146
|
629 |
if (mod==NewBranch)
|
insilmaril@760
|
630 |
setColor (treeItem->getHeadingColor() );
|
insilmaril@146
|
631 |
calcBBoxSize();
|
insilmaril@146
|
632 |
}
|
insilmaril@146
|
633 |
|
insilmaril@760
|
634 |
void BranchObj::sortChildren() //FIXME-2
|
insilmaril@604
|
635 |
{
|
insilmaril@749
|
636 |
/*
|
insilmaril@749
|
637 |
int childCount=branch.count();
|
insilmaril@604
|
638 |
int curChildIndex;
|
insilmaril@604
|
639 |
bool madeChanges=false;
|
insilmaril@604
|
640 |
do
|
insilmaril@604
|
641 |
{
|
insilmaril@604
|
642 |
madeChanges=false;
|
insilmaril@604
|
643 |
for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
|
insilmaril@753
|
644 |
BranchObj* curChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex);
|
insilmaril@753
|
645 |
BranchObj* prevChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex-1);
|
insilmaril@604
|
646 |
if(prevChild->heading->text().compare(curChild->heading->text())>0)
|
insilmaril@604
|
647 |
{
|
insilmaril@604
|
648 |
this->moveBranchUp(curChild);
|
insilmaril@604
|
649 |
madeChanges=true;
|
insilmaril@604
|
650 |
}
|
insilmaril@604
|
651 |
}
|
insilmaril@604
|
652 |
}while(madeChanges);
|
insilmaril@749
|
653 |
*/
|
insilmaril@604
|
654 |
}
|
insilmaril@604
|
655 |
|
insilmaril@721
|
656 |
void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
|
insilmaril@0
|
657 |
{
|
insilmaril@408
|
658 |
qreal th = bboxTotal.height();
|
insilmaril@773
|
659 |
int depth=treeItem->depth(); // FIXME-3 needed to recursively calc depth?
|
insilmaril@223
|
660 |
// TODO testing
|
insilmaril@223
|
661 |
/*
|
insilmaril@755
|
662 |
|
insilmaril@755
|
663 |
QString h=QString (depth,' ');
|
insilmaril@753
|
664 |
h+=treeItem->getHeading();
|
insilmaril@753
|
665 |
h+=QString (15,' ');
|
insilmaril@753
|
666 |
h.truncate (15);
|
insilmaril@688
|
667 |
QPointF pp; if (parObj) pp=parObj->getChildPos();
|
insilmaril@753
|
668 |
cout << "BO::alignRelTo ";
|
insilmaril@753
|
669 |
cout<<h.toStdString();
|
insilmaril@755
|
670 |
cout << " d="<<depth<<
|
insilmaril@755
|
671 |
//cout<< " ref="<<ref<<
|
insilmaril@753
|
672 |
" bbox.tL="<<bboxTotal.topLeft()<<
|
insilmaril@223
|
673 |
" absPos="<<absPos<<
|
insilmaril@721
|
674 |
// " relPos="<<relPos<<
|
insilmaril@721
|
675 |
// " parPos="<<pp<<
|
insilmaril@753
|
676 |
" w="<<bbox.width()<<
|
insilmaril@753
|
677 |
" h="<<bbox.height()<<
|
insilmaril@753
|
678 |
// " orient="<<orientation<<
|
insilmaril@753
|
679 |
// " alignSelf="<<alignSelf<<
|
insilmaril@753
|
680 |
// " scrolled="<<((BranchItem*)treeItem)->isScrolled()<<
|
insilmaril@254
|
681 |
// " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
|
insilmaril@382
|
682 |
// " hidden="<<hidden<<
|
insilmaril@753
|
683 |
" th="<<th<<
|
insilmaril@382
|
684 |
endl;
|
insilmaril@394
|
685 |
*/
|
insilmaril@0
|
686 |
|
insilmaril@382
|
687 |
setOrientation();
|
insilmaril@382
|
688 |
//updateLink();
|
insilmaril@382
|
689 |
|
insilmaril@755
|
690 |
if (depth==1 && parObj)
|
insilmaril@364
|
691 |
{
|
insilmaril@753
|
692 |
// Position relatively, if needed
|
insilmaril@753
|
693 |
//if (useRelPos) move2RelPos (relPos.x(), relPos.y());
|
insilmaril@382
|
694 |
|
insilmaril@753
|
695 |
// Calc angle to mapCenter if I am a mainbranch
|
insilmaril@753
|
696 |
// needed for reordering the mainbranches clockwise
|
insilmaril@753
|
697 |
// around mapcenter
|
insilmaril@753
|
698 |
angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
|
insilmaril@753
|
699 |
(int)(y() - parObj->getChildPos().y() ) ) );
|
insilmaril@753
|
700 |
}
|
insilmaril@753
|
701 |
if (depth>1)
|
insilmaril@0
|
702 |
{
|
insilmaril@0
|
703 |
// Align myself depending on orientation and parent, but
|
insilmaril@382
|
704 |
// only if I am not a mainbranch or mapcenter itself
|
insilmaril@688
|
705 |
|
insilmaril@688
|
706 |
if (anim.isAnimated())
|
insilmaril@0
|
707 |
{
|
insilmaril@688
|
708 |
move2RelPos(anim);
|
insilmaril@688
|
709 |
} else
|
insilmaril@688
|
710 |
{
|
insilmaril@688
|
711 |
LinkableMapObj::Orientation o;
|
insilmaril@688
|
712 |
o=parObj->getOrientation();
|
insilmaril@721
|
713 |
if (alignSelf)
|
insilmaril@721
|
714 |
switch (orientation)
|
insilmaril@721
|
715 |
{
|
insilmaril@721
|
716 |
case LinkableMapObj::LeftOfCenter:
|
insilmaril@721
|
717 |
move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
|
insilmaril@721
|
718 |
//move (ref.x() , ref.y() + (th-bbox.height())/2 );
|
insilmaril@721
|
719 |
break;
|
insilmaril@721
|
720 |
case LinkableMapObj::RightOfCenter:
|
insilmaril@721
|
721 |
move (ref.x() , ref.y() + (th-bbox.height())/2 );
|
insilmaril@721
|
722 |
break;
|
insilmaril@721
|
723 |
default:
|
insilmaril@721
|
724 |
qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
|
insilmaril@721
|
725 |
break;
|
insilmaril@753
|
726 |
}
|
insilmaril@688
|
727 |
}
|
insilmaril@0
|
728 |
}
|
insilmaril@0
|
729 |
|
insilmaril@749
|
730 |
if ( ((BranchItem*)treeItem)->isScrolled() ) return;
|
insilmaril@0
|
731 |
|
insilmaril@721
|
732 |
// Set reference point for alignment of children
|
insilmaril@408
|
733 |
QPointF ref2;
|
insilmaril@462
|
734 |
if (orientation==LinkableMapObj::LeftOfCenter)
|
insilmaril@223
|
735 |
ref2.setX(bbox.topLeft().x() - linkwidth);
|
insilmaril@0
|
736 |
else
|
insilmaril@223
|
737 |
ref2.setX(bbox.topRight().x() + linkwidth);
|
insilmaril@0
|
738 |
|
insilmaril@0
|
739 |
if (depth==1)
|
insilmaril@0
|
740 |
ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
|
insilmaril@0
|
741 |
else
|
insilmaril@0
|
742 |
ref2.setY(ref.y() );
|
insilmaril@0
|
743 |
|
insilmaril@721
|
744 |
// Align the children depending on reference point
|
insilmaril@750
|
745 |
for (int i=0; i<treeItem->branchCount(); ++i)
|
insilmaril@0
|
746 |
{
|
insilmaril@753
|
747 |
if (!treeItem->getBranchNum(i)->isHidden())
|
insilmaril@254
|
748 |
{
|
insilmaril@753
|
749 |
treeItem->getBranchObjNum(i)->alignRelativeTo (ref2,true);
|
insilmaril@721
|
750 |
|
insilmaril@721
|
751 |
// append next branch below current one
|
insilmaril@753
|
752 |
ref2.setY(ref2.y() + treeItem->getBranchObjNum(i)->getBBoxSizeWithChildren().height() );
|
insilmaril@254
|
753 |
}
|
insilmaril@0
|
754 |
}
|
insilmaril@0
|
755 |
}
|
insilmaril@0
|
756 |
|
insilmaril@0
|
757 |
|
insilmaril@0
|
758 |
void BranchObj::reposition()
|
insilmaril@0
|
759 |
{
|
insilmaril@164
|
760 |
/* TODO testing only
|
insilmaril@753
|
761 |
if (!treeItem->getHeading().isEmpty())
|
insilmaril@753
|
762 |
cout << "BO::reposition "<<qPrintable(treeItem->getHeading())<<endl;
|
insilmaril@0
|
763 |
else
|
insilmaril@0
|
764 |
cout << "BO::reposition ???"<<endl;
|
insilmaril@753
|
765 |
// cout << " orient="<<orientation<<endl;
|
insilmaril@0
|
766 |
*/
|
insilmaril@382
|
767 |
|
insilmaril@755
|
768 |
if (treeItem->depth()==0)
|
insilmaril@0
|
769 |
{
|
insilmaril@0
|
770 |
// only calculate the sizes once. If the deepest LMO
|
insilmaril@0
|
771 |
// changes its height,
|
insilmaril@0
|
772 |
// all upper LMOs have to change, too.
|
insilmaril@721
|
773 |
calcBBoxSizeWithChildren();
|
insilmaril@408
|
774 |
updateLink(); // This update is needed if the scene is resized
|
insilmaril@333
|
775 |
// due to excessive moving of a FIO
|
insilmaril@333
|
776 |
|
insilmaril@408
|
777 |
alignRelativeTo ( QPointF (absPos.x(),
|
insilmaril@0
|
778 |
absPos.y()-(bboxTotal.height()-bbox.height())/2) );
|
insilmaril@753
|
779 |
//FIXME-2 qSort (branch.begin(),branch.end(), isAbove);
|
insilmaril@333
|
780 |
positionBBox(); // Reposition bbox and contents
|
insilmaril@0
|
781 |
} else
|
insilmaril@0
|
782 |
{
|
insilmaril@0
|
783 |
// This is only important for moving branches:
|
insilmaril@0
|
784 |
// For editing a branch it isn't called...
|
insilmaril@408
|
785 |
alignRelativeTo ( QPointF (absPos.x(),
|
insilmaril@0
|
786 |
absPos.y()-(bboxTotal.height()-bbox.height())/2) );
|
insilmaril@0
|
787 |
}
|
insilmaril@0
|
788 |
}
|
insilmaril@0
|
789 |
|
insilmaril@382
|
790 |
void BranchObj::unsetAllRepositionRequests()
|
insilmaril@382
|
791 |
{
|
insilmaril@382
|
792 |
repositionRequest=false;
|
insilmaril@750
|
793 |
for (int i=0; i<treeItem->branchCount(); ++i)
|
insilmaril@753
|
794 |
treeItem->getBranchObjNum(i)->unsetAllRepositionRequests();
|
insilmaril@382
|
795 |
}
|
insilmaril@382
|
796 |
|
insilmaril@0
|
797 |
|
insilmaril@661
|
798 |
QPolygonF BranchObj::shape()
|
insilmaril@661
|
799 |
{
|
insilmaril@661
|
800 |
QPolygonF p;
|
insilmaril@661
|
801 |
|
insilmaril@661
|
802 |
QRectF r=getTotalBBox();
|
insilmaril@661
|
803 |
if (orientation==LinkableMapObj::LeftOfCenter)
|
insilmaril@661
|
804 |
p <<r.bottomLeft()
|
insilmaril@661
|
805 |
<<r.topLeft()
|
insilmaril@661
|
806 |
<<QPointF (bbox.topLeft().x(), r.topLeft().y() )
|
insilmaril@661
|
807 |
<<bbox.topRight()
|
insilmaril@661
|
808 |
<<bbox.bottomRight()
|
insilmaril@661
|
809 |
<<QPointF (bbox.bottomLeft().x(), r.bottomLeft().y() ) ;
|
insilmaril@661
|
810 |
else
|
insilmaril@661
|
811 |
p <<r.bottomRight()
|
insilmaril@661
|
812 |
<<r.topRight()
|
insilmaril@661
|
813 |
<<QPointF (bbox.topRight().x(), r.topRight().y() )
|
insilmaril@661
|
814 |
<<bbox.topLeft()
|
insilmaril@661
|
815 |
<<bbox.bottomLeft()
|
insilmaril@661
|
816 |
<<QPointF (bbox.bottomRight().x(), r.bottomRight().y() ) ;
|
insilmaril@661
|
817 |
return p;
|
insilmaril@661
|
818 |
}
|
insilmaril@661
|
819 |
|
insilmaril@408
|
820 |
QRectF BranchObj::getTotalBBox()
|
insilmaril@0
|
821 |
{
|
insilmaril@408
|
822 |
QRectF r=bbox;
|
insilmaril@0
|
823 |
|
insilmaril@749
|
824 |
if ( ((BranchItem*)treeItem)->isScrolled() ) return r;
|
insilmaril@0
|
825 |
|
insilmaril@750
|
826 |
for (int i=0; i<treeItem->branchCount(); ++i)
|
insilmaril@753
|
827 |
if (!treeItem->getBranchNum(i)->isHidden())
|
insilmaril@753
|
828 |
r=addBBox(treeItem->getBranchObjNum(i)->getTotalBBox(),r);
|
insilmaril@0
|
829 |
|
insilmaril@755
|
830 |
/* FIXME-3 lots of occurences of treeItem->getBranchObjNum(i) in branchobj.cpp
|
insilmaril@755
|
831 |
better check if they are not NULL and maybe simplify...
|
insilmaril@755
|
832 |
(have been NULL at least in calcBBoxSizeWithChilds...)
|
insilmaril@755
|
833 |
*/
|
insilmaril@755
|
834 |
|
insilmaril@753
|
835 |
/*
|
insilmaril@771
|
836 |
FIXME-3 for (int i=0; i<floatimage.size(); ++i)
|
insilmaril@404
|
837 |
if (!floatimage.at(i)->isHidden())
|
insilmaril@404
|
838 |
r=addBBox(floatimage.at(i)->getTotalBBox(),r);
|
insilmaril@753
|
839 |
*/
|
insilmaril@0
|
840 |
return r;
|
insilmaril@0
|
841 |
}
|
insilmaril@0
|
842 |
|
insilmaril@721
|
843 |
QRectF BranchObj::getBBoxSizeWithChildren()
|
insilmaril@0
|
844 |
{
|
insilmaril@0
|
845 |
return bboxTotal;
|
insilmaril@0
|
846 |
}
|
insilmaril@0
|
847 |
|
insilmaril@721
|
848 |
void BranchObj::calcBBoxSizeWithChildren()
|
insilmaril@169
|
849 |
{
|
insilmaril@169
|
850 |
// This is initially called only from reposition and
|
insilmaril@0
|
851 |
// and only for mapcenter. So it won't be
|
insilmaril@0
|
852 |
// called more than once for a single user
|
insilmaril@0
|
853 |
// action
|
insilmaril@0
|
854 |
|
insilmaril@169
|
855 |
|
insilmaril@721
|
856 |
// Calculate size of LMO including all children (to align them later)
|
insilmaril@0
|
857 |
bboxTotal.setX(bbox.x() );
|
insilmaril@0
|
858 |
bboxTotal.setY(bbox.y() );
|
insilmaril@0
|
859 |
|
insilmaril@721
|
860 |
// if branch is scrolled, ignore children, but still consider floatimages
|
insilmaril@753
|
861 |
BranchItem *bi=(BranchItem*)treeItem;
|
insilmaril@753
|
862 |
if ( bi->isScrolled() )
|
insilmaril@0
|
863 |
{
|
insilmaril@0
|
864 |
bboxTotal.setWidth (bbox.width());
|
insilmaril@0
|
865 |
bboxTotal.setHeight(bbox.height());
|
insilmaril@0
|
866 |
return;
|
insilmaril@0
|
867 |
}
|
insilmaril@0
|
868 |
|
insilmaril@753
|
869 |
if (bi->isHidden())
|
insilmaril@254
|
870 |
{
|
insilmaril@254
|
871 |
bboxTotal.setWidth (0);
|
insilmaril@254
|
872 |
bboxTotal.setHeight(0);
|
insilmaril@254
|
873 |
if (parObj)
|
insilmaril@254
|
874 |
{
|
insilmaril@254
|
875 |
bboxTotal.setX (parObj->x());
|
insilmaril@254
|
876 |
bboxTotal.setY (parObj->y());
|
insilmaril@254
|
877 |
} else
|
insilmaril@254
|
878 |
{
|
insilmaril@254
|
879 |
bboxTotal.setX (bbox.x());
|
insilmaril@254
|
880 |
bboxTotal.setY (bbox.y());
|
insilmaril@254
|
881 |
}
|
insilmaril@254
|
882 |
return;
|
insilmaril@254
|
883 |
}
|
insilmaril@254
|
884 |
|
insilmaril@408
|
885 |
QRectF r(0,0,0,0);
|
insilmaril@408
|
886 |
QRectF br;
|
insilmaril@0
|
887 |
// Now calculate recursivly
|
insilmaril@0
|
888 |
// sum of heights
|
insilmaril@0
|
889 |
// maximum of widths
|
insilmaril@0
|
890 |
// minimum of y
|
insilmaril@755
|
891 |
for (int i=0; i<treeItem->branchCount(); i++)
|
insilmaril@0
|
892 |
{
|
insilmaril@753
|
893 |
if (!bi->getBranchNum(i)->isHidden())
|
insilmaril@254
|
894 |
{
|
insilmaril@753
|
895 |
bi->getBranchObjNum(i)->calcBBoxSizeWithChildren();
|
insilmaril@753
|
896 |
br=bi->getBranchObjNum(i)->getBBoxSizeWithChildren();
|
insilmaril@254
|
897 |
r.setWidth( max (br.width(), r.width() ));
|
insilmaril@254
|
898 |
r.setHeight(br.height() + r.height() );
|
insilmaril@254
|
899 |
if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
|
insilmaril@254
|
900 |
}
|
insilmaril@0
|
901 |
}
|
insilmaril@0
|
902 |
// Add myself and also
|
insilmaril@0
|
903 |
// add width of link to sum if necessary
|
insilmaril@753
|
904 |
if (bi->branchCount()<1)
|
insilmaril@0
|
905 |
bboxTotal.setWidth (bbox.width() + r.width() );
|
insilmaril@0
|
906 |
else
|
insilmaril@0
|
907 |
bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
|
insilmaril@169
|
908 |
|
insilmaril@169
|
909 |
bboxTotal.setHeight(max (r.height(), bbox.height()));
|
insilmaril@0
|
910 |
}
|
insilmaril@0
|
911 |
|
insilmaril@0
|
912 |
QString BranchObj::getSelectString()
|
insilmaril@0
|
913 |
{
|
insilmaril@773
|
914 |
VymModel *model=treeItem->getModel();
|
insilmaril@773
|
915 |
if (model)
|
insilmaril@773
|
916 |
return model->getSelectString (this);
|
insilmaril@773
|
917 |
else
|
insilmaril@773
|
918 |
return QString();
|
insilmaril@0
|
919 |
}
|
insilmaril@0
|
920 |
|
insilmaril@688
|
921 |
void BranchObj::setAnimation(const AnimPoint &ap)
|
insilmaril@462
|
922 |
{
|
insilmaril@688
|
923 |
anim=ap;
|
insilmaril@462
|
924 |
}
|
insilmaril@462
|
925 |
|
insilmaril@688
|
926 |
bool BranchObj::animate()
|
insilmaril@688
|
927 |
{
|
insilmaril@688
|
928 |
anim.animate ();
|
insilmaril@721
|
929 |
if ( anim.isAnimated() )
|
insilmaril@721
|
930 |
{
|
insilmaril@721
|
931 |
setRelPos (anim);
|
insilmaril@721
|
932 |
return true;
|
insilmaril@721
|
933 |
}
|
insilmaril@723
|
934 |
parObj->reposition(); // we might have been relinked meanwhile
|
insilmaril@721
|
935 |
return false;
|
insilmaril@688
|
936 |
}
|
insilmaril@688
|
937 |
|