insilmaril@747
|
1 |
#include "branchitem.h"
|
insilmaril@747
|
2 |
#include "branchobj.h"
|
insilmaril@753
|
3 |
#include "vymmodel.h"
|
insilmaril@747
|
4 |
|
insilmaril@747
|
5 |
#include <iostream>
|
insilmaril@753
|
6 |
#include <QDir>
|
insilmaril@753
|
7 |
|
insilmaril@747
|
8 |
using namespace std;
|
insilmaril@747
|
9 |
|
insilmaril@779
|
10 |
BranchItem::BranchItem(const QList<QVariant> &data, TreeItem *parent):MapItem (data,parent)
|
insilmaril@747
|
11 |
{
|
insilmaril@749
|
12 |
//cout << "Constr. BranchItem\n";
|
insilmaril@749
|
13 |
|
insilmaril@749
|
14 |
scrolled=false;
|
insilmaril@749
|
15 |
tmpUnscrolled=false;
|
insilmaril@760
|
16 |
type=Branch;
|
insilmaril@747
|
17 |
}
|
insilmaril@747
|
18 |
|
insilmaril@747
|
19 |
BranchItem::~BranchItem()
|
insilmaril@747
|
20 |
{
|
insilmaril@776
|
21 |
cout << "Destr. BranchItem "<<getHeadingStd()<<endl;
|
insilmaril@756
|
22 |
if (lmo)
|
insilmaril@756
|
23 |
{
|
insilmaril@756
|
24 |
delete lmo;
|
insilmaril@756
|
25 |
lmo=NULL;
|
insilmaril@756
|
26 |
}
|
insilmaril@747
|
27 |
}
|
insilmaril@747
|
28 |
|
insilmaril@749
|
29 |
void BranchItem::copy (BranchItem *other)
|
insilmaril@749
|
30 |
{
|
insilmaril@749
|
31 |
scrolled=other->scrolled;
|
insilmaril@749
|
32 |
tmpUnscrolled=other->tmpUnscrolled;
|
insilmaril@749
|
33 |
}
|
insilmaril@749
|
34 |
|
insilmaril@756
|
35 |
void BranchItem::insertBranch (int pos, BranchItem *branch)
|
insilmaril@756
|
36 |
{
|
insilmaril@756
|
37 |
if (pos<0) pos=0;
|
insilmaril@756
|
38 |
if (pos>branchCounter) pos=branchCounter;
|
insilmaril@756
|
39 |
childItems.insert(pos+branchOffset,branch);
|
insilmaril@756
|
40 |
branch->parentItem=this;
|
insilmaril@756
|
41 |
branch->setModel (model);
|
insilmaril@756
|
42 |
|
insilmaril@756
|
43 |
if (branchCounter==0)
|
insilmaril@756
|
44 |
branchOffset=childItems.count()-1;
|
insilmaril@756
|
45 |
branchCounter++;
|
insilmaril@756
|
46 |
}
|
insilmaril@756
|
47 |
|
insilmaril@771
|
48 |
QString BranchItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset) //FIXME-3 Check if everything is saved...
|
insilmaril@747
|
49 |
{
|
insilmaril@747
|
50 |
// Cloudy stuff can be hidden during exports
|
insilmaril@748
|
51 |
if (hidden) return QString();
|
insilmaril@747
|
52 |
|
insilmaril@747
|
53 |
QString s,a;
|
insilmaril@747
|
54 |
BranchObj *bo=(BranchObj*)lmo;
|
insilmaril@747
|
55 |
|
insilmaril@747
|
56 |
// Update of note is usually done while unselecting a branch
|
insilmaril@747
|
57 |
|
insilmaril@747
|
58 |
QString scrolledAttr;
|
insilmaril@747
|
59 |
if (scrolled)
|
insilmaril@747
|
60 |
scrolledAttr=attribut ("scrolled","yes");
|
insilmaril@747
|
61 |
else
|
insilmaril@747
|
62 |
scrolledAttr="";
|
insilmaril@747
|
63 |
|
insilmaril@775
|
64 |
// save area, if not scrolled // FIXME-5 not needed if HTML is rewritten...
|
insilmaril@768
|
65 |
// also we should check if _any_ of parents is scrolled
|
insilmaril@747
|
66 |
QString areaAttr;
|
insilmaril@775
|
67 |
if (lmo && parentItem->isBranchLikeType() && !((BranchItem*)parentItem)->isScrolled() )
|
insilmaril@747
|
68 |
{
|
insilmaril@775
|
69 |
qreal x=lmo->getAbsPos().x();
|
insilmaril@775
|
70 |
qreal y=lmo->getAbsPos().y();
|
insilmaril@747
|
71 |
areaAttr=
|
insilmaril@775
|
72 |
attribut("x1",QString().setNum(x-offset.x())) +
|
insilmaril@775
|
73 |
attribut("y1",QString().setNum(y-offset.y())) +
|
insilmaril@775
|
74 |
attribut("x2",QString().setNum(x+lmo->width()-offset.x())) +
|
insilmaril@775
|
75 |
attribut("y2",QString().setNum(y+lmo->height()-offset.y()));
|
insilmaril@747
|
76 |
|
insilmaril@747
|
77 |
} else
|
insilmaril@747
|
78 |
areaAttr="";
|
insilmaril@747
|
79 |
|
insilmaril@775
|
80 |
/*
|
insilmaril@775
|
81 |
// FIXME-3 Providing an ID for a branch makes export to XHTML easier
|
insilmaril@747
|
82 |
QString idAttr;
|
insilmaril@747
|
83 |
if (countXLinks()>0)
|
insilmaril@747
|
84 |
idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
|
insilmaril@747
|
85 |
else
|
insilmaril@747
|
86 |
idAttr="";
|
insilmaril@747
|
87 |
|
insilmaril@747
|
88 |
*/
|
insilmaril@773
|
89 |
QString elementName;
|
insilmaril@773
|
90 |
if (parentItem==rootItem)
|
insilmaril@773
|
91 |
elementName="mapcenter";
|
insilmaril@773
|
92 |
else
|
insilmaril@773
|
93 |
elementName="branch";
|
insilmaril@773
|
94 |
|
insilmaril@773
|
95 |
s=beginElement (elementName
|
insilmaril@779
|
96 |
+getMapAttr()
|
insilmaril@779
|
97 |
+getGeneralAttr()
|
insilmaril@768
|
98 |
+scrolledAttr
|
insilmaril@747
|
99 |
// +areaAttr
|
insilmaril@747
|
100 |
// +idAttr
|
insilmaril@747
|
101 |
// +getIncludeImageAttr()
|
insilmaril@747
|
102 |
);
|
insilmaril@747
|
103 |
incIndent();
|
insilmaril@747
|
104 |
|
insilmaril@747
|
105 |
// save heading
|
insilmaril@747
|
106 |
s+=valueElement("heading", getHeading(),
|
insilmaril@747
|
107 |
attribut ("textColor",QColor( bo->getColor()).name()));
|
insilmaril@747
|
108 |
|
insilmaril@777
|
109 |
// Save frame //FIXME-4 not saved if there is no LMO
|
insilmaril@777
|
110 |
if (lmo && ((OrnamentedObj*)lmo)->getFrame()->getFrameType()!=FrameObj::NoFrame)
|
insilmaril@777
|
111 |
s+=((OrnamentedObj*)lmo)->getFrame()->saveToDir ();
|
insilmaril@747
|
112 |
|
insilmaril@747
|
113 |
// save names of flags set
|
insilmaril@768
|
114 |
s+=standardFlags.saveToDir(tmpdir,prefix,0);
|
insilmaril@747
|
115 |
|
insilmaril@776
|
116 |
// Save Images
|
insilmaril@776
|
117 |
for (int i=0; i<imageCount(); ++i)
|
insilmaril@776
|
118 |
s+=getImageNum(i)->saveToDir (tmpdir,prefix);
|
insilmaril@747
|
119 |
|
insilmaril@747
|
120 |
// save note
|
insilmaril@747
|
121 |
if (!note.isEmpty() )
|
insilmaril@747
|
122 |
s+=note.saveToDir();
|
insilmaril@747
|
123 |
|
insilmaril@747
|
124 |
// Save branches
|
insilmaril@760
|
125 |
int i=0;
|
insilmaril@760
|
126 |
TreeItem *ti=getBranchNum(i);
|
insilmaril@760
|
127 |
while (ti)
|
insilmaril@760
|
128 |
{
|
insilmaril@760
|
129 |
s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset);
|
insilmaril@760
|
130 |
i++;
|
insilmaril@760
|
131 |
ti=getBranchNum(i);
|
insilmaril@760
|
132 |
}
|
insilmaril@747
|
133 |
|
insilmaril@747
|
134 |
/*
|
insilmaril@747
|
135 |
// Save XLinks
|
insilmaril@747
|
136 |
QString ol; // old link
|
insilmaril@747
|
137 |
QString cl; // current link
|
insilmaril@747
|
138 |
for (int i=0; i<xlink.size(); ++i)
|
insilmaril@747
|
139 |
{
|
insilmaril@747
|
140 |
cl=xlink.at(i)->saveToDir();
|
insilmaril@747
|
141 |
if (cl!=ol)
|
insilmaril@747
|
142 |
{
|
insilmaril@747
|
143 |
s+=cl;
|
insilmaril@747
|
144 |
ol=cl;
|
insilmaril@747
|
145 |
} else
|
insilmaril@747
|
146 |
{
|
insilmaril@747
|
147 |
qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
|
insilmaril@747
|
148 |
}
|
insilmaril@747
|
149 |
}
|
insilmaril@747
|
150 |
*/
|
insilmaril@747
|
151 |
|
insilmaril@747
|
152 |
decIndent();
|
insilmaril@773
|
153 |
s+=endElement (elementName);
|
insilmaril@747
|
154 |
return s;
|
insilmaril@747
|
155 |
}
|
insilmaril@747
|
156 |
|
insilmaril@781
|
157 |
void BranchItem::updateVisibility()
|
insilmaril@753
|
158 |
{
|
insilmaril@781
|
159 |
// Needed to hide relinked branch, if parent is scrolled
|
insilmaril@781
|
160 |
if (lmo)
|
insilmaril@781
|
161 |
lmo->setVisibility(!((BranchItem*)parentItem)->isScrolled());
|
insilmaril@753
|
162 |
}
|
insilmaril@753
|
163 |
|
insilmaril@758
|
164 |
void BranchItem::setHeadingColor (QColor color)
|
insilmaril@758
|
165 |
{
|
insilmaril@758
|
166 |
TreeItem::setHeadingColor (color);
|
insilmaril@758
|
167 |
if (lmo) ((BranchObj*)lmo)->setColor (color);
|
insilmaril@758
|
168 |
}
|
insilmaril@758
|
169 |
|
insilmaril@749
|
170 |
void BranchItem::unScroll()
|
insilmaril@749
|
171 |
{
|
insilmaril@749
|
172 |
if (tmpUnscrolled) resetTmpUnscroll();
|
insilmaril@749
|
173 |
if (scrolled) toggleScroll();
|
insilmaril@749
|
174 |
}
|
insilmaril@747
|
175 |
|
insilmaril@767
|
176 |
bool BranchItem::toggleScroll()
|
insilmaril@749
|
177 |
{
|
insilmaril@763
|
178 |
BranchObj *bo=NULL;
|
insilmaril@749
|
179 |
if (scrolled)
|
insilmaril@749
|
180 |
{
|
insilmaril@749
|
181 |
scrolled=false;
|
insilmaril@767
|
182 |
systemFlags.deactivate("system-scrolledright");
|
insilmaril@767
|
183 |
if (branchCounter>0)
|
insilmaril@763
|
184 |
{
|
insilmaril@767
|
185 |
for (int i=0;i<branchCounter;++i)
|
insilmaril@767
|
186 |
{
|
insilmaril@767
|
187 |
bo=(BranchObj*)(getBranchNum(i)->getLMO());
|
insilmaril@767
|
188 |
if (bo) bo->setVisibility(true);
|
insilmaril@767
|
189 |
}
|
insilmaril@763
|
190 |
}
|
insilmaril@749
|
191 |
} else
|
insilmaril@749
|
192 |
{
|
insilmaril@749
|
193 |
scrolled=true;
|
insilmaril@767
|
194 |
systemFlags.activate("system-scrolledright");
|
insilmaril@767
|
195 |
if (branchCounter>0)
|
insilmaril@763
|
196 |
{
|
insilmaril@767
|
197 |
for (int i=0;i<branchCounter;++i)
|
insilmaril@767
|
198 |
{
|
insilmaril@767
|
199 |
bo=(BranchObj*)(getBranchNum(i)->getLMO());
|
insilmaril@767
|
200 |
if (bo) bo->setVisibility(false);
|
insilmaril@767
|
201 |
}
|
insilmaril@763
|
202 |
}
|
insilmaril@749
|
203 |
}
|
insilmaril@772
|
204 |
model->reposition(); // FIXME-3 we don't really want to update view from here...
|
insilmaril@767
|
205 |
return true;
|
insilmaril@749
|
206 |
}
|
insilmaril@749
|
207 |
|
insilmaril@749
|
208 |
bool BranchItem::isScrolled()
|
insilmaril@749
|
209 |
{
|
insilmaril@749
|
210 |
return scrolled;
|
insilmaril@749
|
211 |
}
|
insilmaril@749
|
212 |
|
insilmaril@749
|
213 |
bool BranchItem::hasScrolledParent(BranchItem *start)
|
insilmaril@749
|
214 |
{
|
insilmaril@749
|
215 |
// Calls parents recursivly to
|
insilmaril@749
|
216 |
// find out, if we are scrolled at all.
|
insilmaril@749
|
217 |
// But ignore myself, just look at parents.
|
insilmaril@749
|
218 |
|
insilmaril@779
|
219 |
//cout << "BI::hasScrolledParent this="<<this<<" "<<getHeadingStd()<<endl;
|
insilmaril@749
|
220 |
if (this !=start && scrolled) return true;
|
insilmaril@749
|
221 |
|
insilmaril@749
|
222 |
BranchItem* bi=(BranchItem*)parentItem;
|
insilmaril@779
|
223 |
if (bi && bi!=rootItem && bi->isBranchLikeType() )
|
insilmaril@749
|
224 |
return bi->hasScrolledParent(start);
|
insilmaril@749
|
225 |
else
|
insilmaril@749
|
226 |
return false;
|
insilmaril@749
|
227 |
}
|
insilmaril@749
|
228 |
|
insilmaril@749
|
229 |
void BranchItem::tmpUnscroll()
|
insilmaril@749
|
230 |
{
|
insilmaril@749
|
231 |
// Unscroll parent (recursivly)
|
insilmaril@775
|
232 |
BranchItem * pi=(BranchItem*)parentItem;
|
insilmaril@775
|
233 |
if (pi && pi->isBranchLikeType() ) pi->tmpUnscroll();
|
insilmaril@749
|
234 |
|
insilmaril@749
|
235 |
// Unscroll myself
|
insilmaril@749
|
236 |
if (scrolled)
|
insilmaril@749
|
237 |
{
|
insilmaril@749
|
238 |
tmpUnscrolled=true;
|
insilmaril@775
|
239 |
systemFlags.activate("system-tmpUnscrolledRight");
|
insilmaril@749
|
240 |
toggleScroll();
|
insilmaril@775
|
241 |
model->emitDataHasChanged (this);
|
insilmaril@749
|
242 |
}
|
insilmaril@749
|
243 |
}
|
insilmaril@749
|
244 |
|
insilmaril@749
|
245 |
void BranchItem::resetTmpUnscroll()
|
insilmaril@749
|
246 |
{
|
insilmaril@749
|
247 |
// Unscroll parent (recursivly)
|
insilmaril@775
|
248 |
BranchItem * pi=(BranchItem*)parentItem;
|
insilmaril@775
|
249 |
if (pi && pi->isBranchLikeType() ) pi->resetTmpUnscroll();
|
insilmaril@749
|
250 |
|
insilmaril@749
|
251 |
// Unscroll myself
|
insilmaril@749
|
252 |
if (tmpUnscrolled)
|
insilmaril@749
|
253 |
{
|
insilmaril@749
|
254 |
tmpUnscrolled=false;
|
insilmaril@775
|
255 |
systemFlags.deactivate("system-tmpUnscrolledRight");
|
insilmaril@749
|
256 |
toggleScroll();
|
insilmaril@775
|
257 |
model->emitDataHasChanged (this);
|
insilmaril@749
|
258 |
}
|
insilmaril@749
|
259 |
}
|
insilmaril@749
|
260 |
|
insilmaril@758
|
261 |
TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
|
insilmaril@754
|
262 |
{
|
insilmaril@754
|
263 |
// Search branches
|
insilmaril@754
|
264 |
TreeItem *ti;
|
insilmaril@754
|
265 |
for (int i=0; i<branchCount(); ++i)
|
insilmaril@754
|
266 |
{
|
insilmaril@758
|
267 |
ti=getBranchNum(i)->findMapItem(p, excludeTI);
|
insilmaril@754
|
268 |
if (ti != NULL) return ti;
|
insilmaril@754
|
269 |
}
|
insilmaril@754
|
270 |
|
insilmaril@754
|
271 |
|
insilmaril@754
|
272 |
// Search myself
|
insilmaril@758
|
273 |
if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
|
insilmaril@754
|
274 |
return this;
|
insilmaril@754
|
275 |
|
insilmaril@776
|
276 |
// Search images
|
insilmaril@776
|
277 |
ImageItem *ii;
|
insilmaril@776
|
278 |
for (int i=0; i<imageCount(); ++i )
|
insilmaril@776
|
279 |
{
|
insilmaril@776
|
280 |
ii=getImageNum (i);
|
insilmaril@776
|
281 |
LinkableMapObj *mo=ii->getLMO();
|
insilmaril@776
|
282 |
if (mo && mo->isInClickBox(p) &&
|
insilmaril@776
|
283 |
(ii != excludeTI) &&
|
insilmaril@776
|
284 |
this!= excludeTI &&
|
insilmaril@776
|
285 |
mo->isVisibleObj()
|
insilmaril@776
|
286 |
) return ii;
|
insilmaril@776
|
287 |
}
|
insilmaril@776
|
288 |
return NULL;
|
insilmaril@754
|
289 |
}
|
insilmaril@754
|
290 |
|
insilmaril@754
|
291 |
TreeItem* BranchItem::findID (QString sid)
|
insilmaril@754
|
292 |
{
|
insilmaril@754
|
293 |
// Search branches
|
insilmaril@754
|
294 |
TreeItem *ti;
|
insilmaril@754
|
295 |
for (int i=0; i<branchCount(); ++i)
|
insilmaril@754
|
296 |
{
|
insilmaril@754
|
297 |
ti=getBranchNum(i)->findID (sid);
|
insilmaril@754
|
298 |
if (ti != NULL) return ti;
|
insilmaril@754
|
299 |
}
|
insilmaril@754
|
300 |
|
insilmaril@754
|
301 |
// Search myself
|
insilmaril@754
|
302 |
if (sid==objID) return this;
|
insilmaril@754
|
303 |
|
insilmaril@754
|
304 |
|
insilmaril@754
|
305 |
/*
|
insilmaril@754
|
306 |
// Search float images
|
insilmaril@754
|
307 |
for (int i=0; i<floatimage.size(); ++i )
|
insilmaril@754
|
308 |
if (floatimage.at(i)->inBox(p) &&
|
insilmaril@754
|
309 |
(floatimage.at(i) != excludeLMO) &&
|
insilmaril@754
|
310 |
floatimage.at(i)->getParObj()!= excludeLMO &&
|
insilmaril@754
|
311 |
floatimage.at(i)->isVisibleObj()
|
insilmaril@754
|
312 |
) return floatimage.at(i);
|
insilmaril@754
|
313 |
*/
|
insilmaril@754
|
314 |
return NULL;
|
insilmaril@754
|
315 |
}
|
insilmaril@754
|
316 |
|
insilmaril@773
|
317 |
void BranchItem::updateStyles()
|
insilmaril@773
|
318 |
{
|
insilmaril@773
|
319 |
// FIXME-5 compare also MapItem::initLMO...
|
insilmaril@773
|
320 |
|
insilmaril@779
|
321 |
if (lmo && parentItem != rootItem)
|
insilmaril@773
|
322 |
{
|
insilmaril@779
|
323 |
lmo->setParObj ( ((MapItem*)parentItem)->getLMO() );
|
insilmaril@773
|
324 |
}
|
insilmaril@773
|
325 |
}
|
insilmaril@754
|
326 |
|
insilmaril@750
|
327 |
BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
|
insilmaril@750
|
328 |
{
|
insilmaril@750
|
329 |
return (BranchObj*)lmo;
|
insilmaril@750
|
330 |
}
|
insilmaril@749
|
331 |
|
insilmaril@755
|
332 |
BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)
|
insilmaril@755
|
333 |
{
|
insilmaril@773
|
334 |
BranchObj *newbo;
|
insilmaril@775
|
335 |
newbo=new BranchObj(scene);
|
insilmaril@775
|
336 |
newbo->setTreeItem (this);
|
insilmaril@775
|
337 |
lmo=newbo;
|
insilmaril@775
|
338 |
|
insilmaril@773
|
339 |
if (parentItem==rootItem)
|
insilmaril@773
|
340 |
{
|
insilmaril@773
|
341 |
newbo->setParObj(NULL);
|
insilmaril@775
|
342 |
newbo->setFrameType (FrameObj::Rectangle);
|
insilmaril@773
|
343 |
} else
|
insilmaril@773
|
344 |
{
|
insilmaril@779
|
345 |
newbo->setParObj( ((MapItem*)parentItem)->getLMO() );
|
insilmaril@775
|
346 |
// Set visibility depending on parents
|
insilmaril@779
|
347 |
if (((BranchItem*)parentItem)->scrolled || !((MapItem*)parentItem)->getLMO()->isVisibleObj() )
|
insilmaril@775
|
348 |
newbo->setVisibility (false);
|
insilmaril@773
|
349 |
}
|
insilmaril@775
|
350 |
newbo->setDefAttr(BranchObj::NewBranch);
|
insilmaril@760
|
351 |
initLMO();
|
insilmaril@758
|
352 |
|
insilmaril@758
|
353 |
if (!getHeading().isEmpty() )
|
insilmaril@758
|
354 |
{
|
insilmaril@775
|
355 |
newbo->updateData(); //FIXME-3 maybe better model->emitDataHasChanged()?
|
insilmaril@775
|
356 |
newbo->setColor (headingColor);
|
insilmaril@758
|
357 |
}
|
insilmaril@758
|
358 |
|
insilmaril@779
|
359 |
//newbo->updateLinkGeometry(); //FIXME-3
|
insilmaril@755
|
360 |
|
insilmaril@755
|
361 |
return newbo;
|
insilmaril@755
|
362 |
}
|
insilmaril@755
|
363 |
|