1 #include "branchitem.h"
10 BranchItem::BranchItem(const QList<QVariant> &data, TreeItem *parent):MapItem (data,parent)
12 //cout << "Constr. BranchItem\n";
18 includeImagesVer=false;
19 includeImagesHor=false;
21 lastSelectedBranchNum=-1;
22 lastSelectedBranchNumAlt=-1;
25 BranchItem::~BranchItem()
27 cout << "Destr. BranchItem "<<getHeadingStd()<<endl;
35 void BranchItem::copy (BranchItem *other)
37 scrolled=other->scrolled;
38 tmpUnscrolled=other->tmpUnscrolled;
41 void BranchItem::insertBranch (int pos, BranchItem *branch)
44 if (pos>branchCounter) pos=branchCounter;
45 childItems.insert(pos+branchOffset,branch);
46 branch->parentItem=this;
47 branch->setModel (model);
50 branchOffset=childItems.count()-1;
54 QString BranchItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset) //FIXME-3 Check if everything is saved...
56 // Cloudy stuff can be hidden during exports
57 if (hidden) return QString();
60 BranchObj *bo=(BranchObj*)lmo;
62 // Update of note is usually done while unselecting a branch
66 scrolledAttr=attribut ("scrolled","yes");
70 // save area, if not scrolled // FIXME-5 not needed if HTML is rewritten...
71 // also we should check if _any_ of parents is scrolled
73 if (lmo && parentItem->isBranchLikeType() && !((BranchItem*)parentItem)->isScrolled() )
75 qreal x=lmo->getAbsPos().x();
76 qreal y=lmo->getAbsPos().y();
78 attribut("x1",QString().setNum(x-offset.x())) +
79 attribut("y1",QString().setNum(y-offset.y())) +
80 attribut("x2",QString().setNum(x+lmo->width()-offset.x())) +
81 attribut("y2",QString().setNum(y+lmo->height()-offset.y()));
87 // FIXME-3 Providing an ID for a branch makes export to XHTML easier
90 idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
96 if (parentItem==rootItem)
97 elementName="mapcenter";
101 s=beginElement (elementName
107 +getIncludeImageAttr()
112 s+=valueElement("heading", getHeading(),
113 attribut ("textColor",QColor( bo->getColor()).name()));
115 // Save frame //FIXME-4 not saved if there is no LMO
116 if (lmo && ((OrnamentedObj*)lmo)->getFrame()->getFrameType()!=FrameObj::NoFrame)
117 s+=((OrnamentedObj*)lmo)->getFrame()->saveToDir ();
119 // save names of flags set
120 s+=standardFlags.saveToDir(tmpdir,prefix,0);
123 for (int i=0; i<imageCount(); ++i)
124 s+=getImageNum(i)->saveToDir (tmpdir,prefix);
127 if (!note.isEmpty() )
132 TreeItem *ti=getBranchNum(i);
135 s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset);
142 QString ol; // old link
143 QString cl; // current link
144 for (int i=0; i<xlink.size(); ++i)
146 cl=xlink.at(i)->saveToDir();
153 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
159 s+=endElement (elementName);
163 void BranchItem::updateVisibility()
165 // Needed to hide relinked branch, if parent is scrolled
167 lmo->setVisibility(!((BranchItem*)parentItem)->isScrolled());
170 void BranchItem::setHeadingColor (QColor color)
172 TreeItem::setHeadingColor (color);
173 if (lmo) ((BranchObj*)lmo)->setColor (color);
176 void BranchItem::unScroll()
178 if (tmpUnscrolled) resetTmpUnscroll();
179 if (scrolled) toggleScroll();
182 bool BranchItem::toggleScroll()
188 systemFlags.deactivate("system-scrolledright");
191 for (int i=0;i<branchCounter;++i)
193 bo=(BranchObj*)(getBranchNum(i)->getLMO());
194 if (bo) bo->setVisibility(true);
200 systemFlags.activate("system-scrolledright");
203 for (int i=0;i<branchCounter;++i)
205 bo=(BranchObj*)(getBranchNum(i)->getLMO());
206 if (bo) bo->setVisibility(false);
210 model->reposition(); // FIXME-3 we don't really want to update view from here...
214 bool BranchItem::isScrolled()
219 bool BranchItem::hasScrolledParent(BranchItem *start)
221 // Calls parents recursivly to
222 // find out, if we are scrolled at all.
223 // But ignore myself, just look at parents.
225 //cout << "BI::hasScrolledParent this="<<this<<" "<<getHeadingStd()<<endl;
226 if (this !=start && scrolled) return true;
228 BranchItem* bi=(BranchItem*)parentItem;
229 if (bi && bi!=rootItem && bi->isBranchLikeType() )
230 return bi->hasScrolledParent(start);
235 void BranchItem::tmpUnscroll()
237 // Unscroll parent (recursivly)
238 BranchItem * pi=(BranchItem*)parentItem;
239 if (pi && pi->isBranchLikeType() ) pi->tmpUnscroll();
245 systemFlags.activate("system-tmpUnscrolledRight");
247 model->emitDataHasChanged (this);
251 void BranchItem::resetTmpUnscroll()
253 // Unscroll parent (recursivly)
254 BranchItem * pi=(BranchItem*)parentItem;
255 if (pi && pi->isBranchLikeType() ) pi->resetTmpUnscroll();
261 systemFlags.deactivate("system-tmpUnscrolledRight");
263 model->emitDataHasChanged (this);
267 void BranchItem::setIncludeImagesVer(bool b)
270 /* calcBBoxSize(); FIXME-2
276 bool BranchItem::getIncludeImagesVer()
278 return includeImagesVer;
281 void BranchItem::setIncludeImagesHor(bool b)
284 /* calcBBoxSize(); FIXME-2
290 bool BranchItem::getIncludeImagesHor()
292 return includeImagesHor;
295 QString BranchItem::getIncludeImageAttr()
298 if (includeImagesVer)
299 a=attribut ("incImgV","true");
300 if (includeImagesHor)
301 a+=attribut ("incImgH","true");
305 void BranchItem::setLastSelectedBranch()
311 // Hack to save an additional lastSelected for mapcenters in MapEditor
312 // depending on orientation
313 // this allows to go both left and right from there
314 if (lmo && lmo->getOrientation()==LinkableMapObj::LeftOfCenter)
316 ((BranchItem*)parentItem)->lastSelectedBranchNumAlt=parentItem->num(this);
319 ((BranchItem*)parentItem)->lastSelectedBranchNum=parentItem->num(this);
323 void BranchItem::setLastSelectedBranch(int i)
325 lastSelectedBranchNum=i;
328 BranchItem* BranchItem::getLastSelectedBranch()
330 return getBranchNum (lastSelectedBranchNum);
333 BranchItem* BranchItem::getLastSelectedBranchAlt()
335 return getBranchNum (lastSelectedBranchNumAlt);
342 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
346 for (int i=0; i<branchCount(); ++i)
348 ti=getBranchNum(i)->findMapItem(p, excludeTI);
349 if (ti != NULL) return ti;
354 if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
359 for (int i=0; i<imageCount(); ++i )
362 LinkableMapObj *mo=ii->getLMO();
363 if (mo && mo->isInClickBox(p) &&
372 TreeItem* BranchItem::findID (QString sid)
376 for (int i=0; i<branchCount(); ++i)
378 ti=getBranchNum(i)->findID (sid);
379 if (ti != NULL) return ti;
383 if (sid==objID) return this;
387 // Search float images //FIXME-4
388 for (int i=0; i<floatimage.size(); ++i )
389 if (floatimage.at(i)->inBox(p) &&
390 (floatimage.at(i) != excludeLMO) &&
391 floatimage.at(i)->getParObj()!= excludeLMO &&
392 floatimage.at(i)->isVisibleObj()
393 ) return floatimage.at(i);
398 void BranchItem::updateStyles()
400 // FIXME-5 compare also MapItem::initLMO...
402 if (lmo && parentItem != rootItem)
404 lmo->setParObj ( ((MapItem*)parentItem)->getLMO() );
408 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
410 return (BranchObj*)lmo;
413 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene) // FIXME-4 maybe move this into MapEditor to get rid of scene in VymModel?
416 newbo=new BranchObj(scene);
417 newbo->setTreeItem (this);
420 if (parentItem==rootItem)
422 newbo->setParObj(NULL);
423 newbo->setFrameType (FrameObj::Rectangle);
426 newbo->setParObj( ((MapItem*)parentItem)->getLMO() );
427 // Set visibility depending on parents
428 if (((BranchItem*)parentItem)->scrolled || !((MapItem*)parentItem)->getLMO()->isVisibleObj() )
429 newbo->setVisibility (false);
431 newbo->setDefAttr(BranchObj::NewBranch);
434 if (!getHeading().isEmpty() )
436 newbo->updateData(); //FIXME-3 maybe better model->emitDataHasChanged()?
437 newbo->setColor (headingColor);
440 //newbo->updateLinkGeometry(); //FIXME-3