1 #include "branchitem.h"
3 #include "attributeitem.h"
11 BranchItem::BranchItem(const QList<QVariant> &data, TreeItem *parent):MapItem (data,parent)
13 //qDebug()<< "Constr. BranchItem";
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 //qDebug()<< "Destr. BranchItem this="<<this<<" "<<getHeading();
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, QList <Link*> &tmpLinks ) //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()));
105 if (parentItem==rootItem)
106 elementName="mapcenter";
108 elementName="branch";
110 s=beginElement (elementName
114 // +areaAttr // FIXME-4 not needed anymore. Wait until end of 2010 before removing...
115 +getIncludeImageAttr()
120 s+=valueElement("heading", getHeading(),
121 attribut ("textColor",QColor( bo->getColor()).name()));
123 // Save frame //FIXME-4 not saved if there is no LMO
124 if (lmo && ((OrnamentedObj*)lmo)->getFrame()->getFrameType()!=FrameObj::NoFrame)
125 s+=((OrnamentedObj*)lmo)->getFrame()->saveToDir ();
127 // save names of flags set
128 s+=standardFlags.saveToDir(tmpdir,prefix,0);
131 for (int i=0; i<imageCount(); ++i)
132 s+=getImageNum(i)->saveToDir (tmpdir,prefix);
135 if (!note.isEmpty() )
140 TreeItem *ti=getBranchNum(i);
143 s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset,tmpLinks);
148 // Mark Links for save
149 for (int i=0; i<xlinkCount(); ++i)
150 if (!tmpLinks.contains (getXLinkNum (i)->getLink() ))
151 tmpLinks.append (getXLinkNum(i)->getLink() );
154 s+=endElement (elementName);
158 void BranchItem::updateVisibility()
160 // Needed to hide relinked branch, if parent is scrolled
163 if (hasScrolledParent(this) || hidden)
164 lmo->setVisibility (false);
166 lmo->setVisibility (true);
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 if (this !=start && scrolled) return true;
227 BranchItem* bi=(BranchItem*)parentItem;
228 if (bi && bi!=rootItem )
229 return bi->hasScrolledParent(start);
234 bool BranchItem::tmpUnscroll()
238 // Unscroll parent (recursivly)
239 BranchItem * pi=(BranchItem*)parentItem;
240 if (pi && pi->isBranchLikeType() ) result=pi->tmpUnscroll();
246 systemFlags.activate("system-tmpUnscrolledRight");
248 model->emitDataHasChanged (this);
254 bool BranchItem::resetTmpUnscroll()
258 // Unscroll parent (recursivly)
259 BranchItem * pi=(BranchItem*)parentItem;
260 if (pi && pi->isBranchLikeType() ) result=pi->resetTmpUnscroll();
266 systemFlags.deactivate("system-tmpUnscrolledRight");
268 model->emitDataHasChanged (this);
274 void BranchItem::sortChildren(bool inverse)
276 int childCount=branchCounter;
278 bool madeChanges=false;
282 for(curChildIndex=1;curChildIndex<childCount;curChildIndex++)
284 BranchItem* curChild =getBranchNum(curChildIndex);
285 BranchItem* prevChild=getBranchNum(curChildIndex-1);
288 if (prevChild->getHeading().compare(curChild->getHeading())<0)
290 model->moveUp (curChild);
294 if (prevChild->getHeading().compare(curChild->getHeading())>0)
296 model->moveUp (curChild);
303 void BranchItem::setIncludeImagesVer(bool b)
306 /* calcBBoxSize(); FIXME-3
312 bool BranchItem::getIncludeImagesVer()
314 return includeImagesVer;
317 void BranchItem::setIncludeImagesHor(bool b)
320 /* calcBBoxSize(); FIXME-3
326 bool BranchItem::getIncludeImagesHor()
328 return includeImagesHor;
331 QString BranchItem::getIncludeImageAttr()
334 if (includeImagesVer)
335 a=attribut ("incImgV","true");
336 if (includeImagesHor)
337 a+=attribut ("incImgH","true");
341 void BranchItem::setLastSelectedBranch()
347 // Hack to save an additional lastSelected for mapcenters in MapEditor
348 // depending on orientation
349 // this allows to go both left and right from there
350 if (lmo && lmo->getOrientation()==LinkableMapObj::LeftOfCenter)
352 ((BranchItem*)parentItem)->lastSelectedBranchNumAlt=parentItem->num(this);
355 ((BranchItem*)parentItem)->lastSelectedBranchNum=parentItem->num(this);
359 void BranchItem::setLastSelectedBranch(int i)
361 lastSelectedBranchNum=i;
364 BranchItem* BranchItem::getLastSelectedBranch()
366 if (lastSelectedBranchNum>=branchCounter)
367 return getBranchNum (branchCounter-1);
369 return getBranchNum (lastSelectedBranchNum);
372 BranchItem* BranchItem::getLastSelectedBranchAlt()
374 return getBranchNum (lastSelectedBranchNumAlt);
380 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
384 for (int i=0; i<branchCount(); ++i)
386 ti=getBranchNum(i)->findMapItem(p, excludeTI);
387 if (ti != NULL) return ti;
392 if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
397 for (int i=0; i<imageCount(); ++i )
400 LinkableMapObj *mo=ii->getLMO();
401 if (mo && mo->isInClickBox(p) &&
410 for (int i=0; i<attributeCount(); ++i )
412 ai=getAttributeNum (i);
413 LinkableMapObj *mo=ai->getLMO();
414 if (mo && mo->isInClickBox(p) &&
424 void BranchItem::updateStyles(const bool &keepFrame)
426 // FIXME-5 compare also MapItem::initLMO...
430 if ( parentItem != rootItem)
431 lmo->setParObj ( ((MapItem*)parentItem)->getLMO() );
433 lmo->setParObj (NULL);
434 ((BranchObj*)lmo)->setDefAttr(BranchObj::MovedBranch,keepFrame);
438 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
440 return (BranchObj*)lmo;
443 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene) // FIXME-4 maybe move this into MapEditor to get rid of scene in VymModel?
446 newbo=new BranchObj(scene,this);
449 if (parentItem==rootItem)
451 newbo->setParObj(NULL);
452 //newbo->setFrameType (FrameObj::Rectangle); //FIXME-4 maybe call updateStyles?
455 newbo->setParObj( ((MapItem*)parentItem)->getLMO() );
456 // Set visibility depending on parents
457 if (parentItem!=rootItem &&
458 ( ((BranchItem*)parentItem)->scrolled || !((MapItem*)parentItem)->getLMO()->isVisibleObj() ) )
459 newbo->setVisibility (false);
461 newbo->setDefAttr(BranchObj::NewBranch);
464 if (!getHeading().isEmpty() )
466 newbo->updateData(); //FIXME-3 maybe better model->emitDataHasChanged()?
467 newbo->setColor (headingColor);
470 //newbo->updateLinkGeometry(); //FIXME-3