1 #include "branchitem.h"
11 BranchItem::BranchItem(const QList<QVariant> &data, TreeItem *parent):MapItem (data,parent)
13 //cout << "Constr. BranchItem\n";
15 // Set type if parent is known yet
16 // if not, type is set in insertBranch or TreeItem::appendChild
25 includeImagesVer=false;
26 includeImagesHor=false;
28 lastSelectedBranchNum=-1;
29 lastSelectedBranchNumAlt=-1;
32 BranchItem::~BranchItem()
34 //cout << "Destr. BranchItem "<<getHeadingStd()<<endl;
42 void BranchItem::copy (BranchItem *other)
44 scrolled=other->scrolled;
45 tmpUnscrolled=other->tmpUnscrolled;
48 BranchItem* BranchItem::parentBranch ()
50 return (BranchItem*) parentItem;
53 void BranchItem::insertBranch (int pos, BranchItem *branch)
56 if (pos>branchCounter) pos=branchCounter;
57 childItems.insert(pos+branchOffset,branch);
58 branch->parentItem=this;
59 branch->rootItem=rootItem;
60 branch->setModel (model);
61 if (parentItem==rootItem)
68 branchOffset=childItems.count()-1;
72 QString BranchItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset) //FIXME-3 Check if everything is saved...
74 // Cloudy stuff can be hidden during exports
75 if (hidden) return QString();
78 BranchObj *bo=(BranchObj*)lmo;
80 // Update of note is usually done while unselecting a branch
84 scrolledAttr=attribut ("scrolled","yes");
88 // save area, if not scrolled // FIXME-5 not needed if HTML is rewritten...
89 // also we should check if _any_ of parents is scrolled
91 if (lmo && parentItem->isBranchLikeType() && !((BranchItem*)parentItem)->isScrolled() )
93 qreal x=lmo->getAbsPos().x();
94 qreal y=lmo->getAbsPos().y();
96 attribut("x1",QString().setNum(x-offset.x())) +
97 attribut("y1",QString().setNum(y-offset.y())) +
98 attribut("x2",QString().setNum(x+lmo->width()-offset.x())) +
99 attribut("y2",QString().setNum(y+lmo->height()-offset.y()));
104 // Provide an ID for a branch makes export to XHTML easier
107 idAttr=attribut ("id",model->getSelectString(this));
112 if (parentItem==rootItem)
113 elementName="mapcenter";
115 elementName="branch";
117 s=beginElement (elementName
121 // +areaAttr // FIXME-2
123 +getIncludeImageAttr()
128 s+=valueElement("heading", getHeading(),
129 attribut ("textColor",QColor( bo->getColor()).name()));
131 // Save frame //FIXME-4 not saved if there is no LMO
132 if (lmo && ((OrnamentedObj*)lmo)->getFrame()->getFrameType()!=FrameObj::NoFrame)
133 s+=((OrnamentedObj*)lmo)->getFrame()->saveToDir ();
135 // save names of flags set
136 s+=standardFlags.saveToDir(tmpdir,prefix,0);
139 for (int i=0; i<imageCount(); ++i)
140 s+=getImageNum(i)->saveToDir (tmpdir,prefix);
143 if (!note.isEmpty() )
148 TreeItem *ti=getBranchNum(i);
151 s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset);
157 QString ol; // old link
158 QString cl; // current link
159 for (int i=0; i<xlinkCount(); ++i)
161 cl=getXLinkNum(i)->saveToDir();
168 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
173 s+=endElement (elementName);
177 void BranchItem::updateVisibility()
179 // Needed to hide relinked branch, if parent is scrolled
181 lmo->setVisibility(!((BranchItem*)parentItem)->isScrolled());
184 void BranchItem::setHeadingColor (QColor color)
186 TreeItem::setHeadingColor (color);
187 if (lmo) ((BranchObj*)lmo)->setColor (color);
190 void BranchItem::unScroll()
192 if (tmpUnscrolled) resetTmpUnscroll();
193 if (scrolled) toggleScroll();
196 bool BranchItem::toggleScroll()
202 systemFlags.deactivate("system-scrolledright");
205 for (int i=0;i<branchCounter;++i)
207 bo=(BranchObj*)(getBranchNum(i)->getLMO());
208 if (bo) bo->setVisibility(true);
214 systemFlags.activate("system-scrolledright");
217 for (int i=0;i<branchCounter;++i)
219 bo=(BranchObj*)(getBranchNum(i)->getLMO());
220 if (bo) bo->setVisibility(false);
224 //model->reposition(); // FIXME-3 we don't really want to update view from here...
228 bool BranchItem::isScrolled()
233 bool BranchItem::hasScrolledParent(BranchItem *start)
235 // Calls parents recursivly to
236 // find out, if we are scrolled at all.
237 // But ignore myself, just look at parents.
239 if (this !=start && scrolled) return true;
241 BranchItem* bi=(BranchItem*)parentItem;
242 if (bi && bi!=rootItem )
243 return bi->hasScrolledParent(start);
248 bool BranchItem::tmpUnscroll()
252 // Unscroll parent (recursivly)
253 BranchItem * pi=(BranchItem*)parentItem;
254 if (pi && pi->isBranchLikeType() ) result=pi->tmpUnscroll();
260 systemFlags.activate("system-tmpUnscrolledRight");
262 model->emitDataHasChanged (this);
268 bool BranchItem::resetTmpUnscroll()
272 // Unscroll parent (recursivly)
273 BranchItem * pi=(BranchItem*)parentItem;
274 if (pi && pi->isBranchLikeType() ) result=pi->resetTmpUnscroll();
280 systemFlags.deactivate("system-tmpUnscrolledRight");
282 model->emitDataHasChanged (this);
288 void BranchItem::sortChildren()
290 int childCount=branchCounter;
292 bool madeChanges=false;
296 for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
297 BranchItem* curChild =getBranchNum(curChildIndex);
298 BranchItem* prevChild=getBranchNum(curChildIndex-1);
299 if(prevChild->getHeading().compare(curChild->getHeading())>0)
301 model->moveUp(curChild);
308 void BranchItem::setIncludeImagesVer(bool b)
311 /* calcBBoxSize(); FIXME-3
317 bool BranchItem::getIncludeImagesVer()
319 return includeImagesVer;
322 void BranchItem::setIncludeImagesHor(bool b)
325 /* calcBBoxSize(); FIXME-3
331 bool BranchItem::getIncludeImagesHor()
333 return includeImagesHor;
336 QString BranchItem::getIncludeImageAttr()
339 if (includeImagesVer)
340 a=attribut ("incImgV","true");
341 if (includeImagesHor)
342 a+=attribut ("incImgH","true");
346 void BranchItem::setLastSelectedBranch()
352 // Hack to save an additional lastSelected for mapcenters in MapEditor
353 // depending on orientation
354 // this allows to go both left and right from there
355 if (lmo && lmo->getOrientation()==LinkableMapObj::LeftOfCenter)
357 ((BranchItem*)parentItem)->lastSelectedBranchNumAlt=parentItem->num(this);
360 ((BranchItem*)parentItem)->lastSelectedBranchNum=parentItem->num(this);
364 void BranchItem::setLastSelectedBranch(int i)
366 lastSelectedBranchNum=i;
369 BranchItem* BranchItem::getLastSelectedBranch()
371 if (lastSelectedBranchNum>=branchCounter)
372 return getBranchNum (branchCounter-1);
374 return getBranchNum (lastSelectedBranchNum);
377 BranchItem* BranchItem::getLastSelectedBranchAlt()
379 return getBranchNum (lastSelectedBranchNumAlt);
386 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
390 for (int i=0; i<branchCount(); ++i)
392 ti=getBranchNum(i)->findMapItem(p, excludeTI);
393 if (ti != NULL) return ti;
398 if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
403 for (int i=0; i<imageCount(); ++i )
406 LinkableMapObj *mo=ii->getLMO();
407 if (mo && mo->isInClickBox(p) &&
416 TreeItem* BranchItem::findID (QString sid) //FIXME-3 move to TreeItem //FIXME-4 search images
420 for (int i=0; i<branchCount(); ++i)
422 ti=getBranchNum(i)->findID (sid);
423 if (ti != NULL) return ti;
427 if (sid==objID) return this;
430 // Search float images
431 for (int i=0; i<floatimage.size(); ++i )
432 if (floatimage.at(i)->inBox(p) &&
433 (floatimage.at(i) != excludeLMO) &&
434 floatimage.at(i)->getParObj()!= excludeLMO &&
435 floatimage.at(i)->isVisibleObj()
436 ) return floatimage.at(i);
440 void BranchItem::updateStyles()
442 // FIXME-5 compare also MapItem::initLMO...
446 if ( parentItem != rootItem)
447 lmo->setParObj ( ((MapItem*)parentItem)->getLMO() );
449 lmo->setParObj (NULL);
450 ((BranchObj*)lmo)->setDefAttr(BranchObj::MovedBranch);
454 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
456 return (BranchObj*)lmo;
459 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene) // FIXME-4 maybe move this into MapEditor to get rid of scene in VymModel?
462 newbo=new BranchObj(scene,this);
465 if (parentItem==rootItem)
467 newbo->setParObj(NULL);
468 //newbo->setFrameType (FrameObj::Rectangle); //FIXME-4 maybe call updateStyles?
471 newbo->setParObj( ((MapItem*)parentItem)->getLMO() );
472 // Set visibility depending on parents
473 if (parentItem!=rootItem &&
474 ( ((BranchItem*)parentItem)->scrolled || !((MapItem*)parentItem)->getLMO()->isVisibleObj() ) )
475 newbo->setVisibility (false);
477 newbo->setDefAttr(BranchObj::NewBranch);
480 if (!getHeading().isEmpty() )
482 newbo->updateData(); //FIXME-3 maybe better model->emitDataHasChanged()?
483 newbo->setColor (headingColor);
486 //newbo->updateLinkGeometry(); //FIXME-3