1 #include "attributeitem.h"
2 #include "branchitem.h"
12 BranchItem::BranchItem(const QList<QVariant> &data, TreeItem *parent):MapItem (data,parent)
14 //cout << "Constr. BranchItem\n";
16 // Set type if parent is known yet
17 // if not, type is set in insertBranch or TreeItem::appendChild
26 includeImagesVer=false;
27 includeImagesHor=false;
29 lastSelectedBranchNum=-1;
30 lastSelectedBranchNumAlt=-1;
33 BranchItem::~BranchItem()
35 //cout << "Destr. BranchItem "<<getHeadingStd()<<endl;
43 void BranchItem::copy (BranchItem *other)
45 scrolled=other->scrolled;
46 tmpUnscrolled=other->tmpUnscrolled;
49 BranchItem* BranchItem::parentBranch ()
51 return (BranchItem*) parentItem;
54 void BranchItem::insertBranch (int pos, BranchItem *branch)
57 if (pos>branchCounter) pos=branchCounter;
58 childItems.insert(pos+branchOffset,branch);
59 branch->parentItem=this;
60 branch->rootItem=rootItem;
61 branch->setModel (model);
62 if (parentItem==rootItem)
69 branchOffset=childItems.count()-1;
73 QString BranchItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset) //FIXME-3 Check if everything is saved...
75 // Cloudy stuff can be hidden during exports
76 if (hidden) return QString();
79 BranchObj *bo=(BranchObj*)lmo;
81 // Update of note is usually done while unselecting a branch
85 scrolledAttr=attribut ("scrolled","yes");
89 // save area, if not scrolled // FIXME-5 not needed if HTML is rewritten...
90 // also we should check if _any_ of parents is scrolled
92 if (lmo && parentItem->isBranchLikeType() && !((BranchItem*)parentItem)->isScrolled() )
94 qreal x=lmo->getAbsPos().x();
95 qreal y=lmo->getAbsPos().y();
97 attribut("x1",QString().setNum(x-offset.x())) +
98 attribut("y1",QString().setNum(y-offset.y())) +
99 attribut("x2",QString().setNum(x+lmo->width()-offset.x())) +
100 attribut("y2",QString().setNum(y+lmo->height()-offset.y()));
105 // Provide an ID for a branch makes export to XHTML easier
108 idAttr=attribut ("id",model->getSelectString(this));
113 if (parentItem==rootItem)
114 elementName="mapcenter";
116 elementName="branch";
118 s=beginElement (elementName
122 // +areaAttr // FIXME-4 not needed anymore. Wait until end of 2010 before removing...
124 +getIncludeImageAttr()
129 s+=valueElement("heading", getHeading(),
130 attribut ("textColor",QColor( bo->getColor()).name()));
132 // Save frame //FIXME-4 not saved if there is no LMO
133 if (lmo && ((OrnamentedObj*)lmo)->getFrame()->getFrameType()!=FrameObj::NoFrame)
134 s+=((OrnamentedObj*)lmo)->getFrame()->saveToDir ();
136 // save names of flags set
137 s+=standardFlags.saveToDir(tmpdir,prefix,0);
140 for (int i=0; i<imageCount(); ++i)
141 s+=getImageNum(i)->saveToDir (tmpdir,prefix);
144 if (!note.isEmpty() )
149 TreeItem *ti=getBranchNum(i);
152 s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset);
158 QString ol; // old link
159 QString cl; // current link
160 for (int i=0; i<xlinkCount(); ++i)
162 cl=getXLinkNum(i)->saveToDir();
169 qWarning (QString("BranchItem::saveToDir Ignoring of duplicate xLink in %1").arg(getHeading()));
174 s+=endElement (elementName);
178 void BranchItem::updateVisibility()
180 // Needed to hide relinked branch, if parent is scrolled
183 if (hasScrolledParent(this) || hidden)
184 lmo->setVisibility (false);
186 lmo->setVisibility (true);
190 void BranchItem::setHeadingColor (QColor color)
192 TreeItem::setHeadingColor (color);
193 if (lmo) ((BranchObj*)lmo)->setColor (color);
196 void BranchItem::unScroll()
198 if (tmpUnscrolled) resetTmpUnscroll();
199 if (scrolled) toggleScroll();
202 bool BranchItem::toggleScroll()
208 systemFlags.deactivate("system-scrolledright");
211 for (int i=0;i<branchCounter;++i)
213 bo=(BranchObj*)(getBranchNum(i)->getLMO());
214 if (bo) bo->setVisibility(true);
220 systemFlags.activate("system-scrolledright");
223 for (int i=0;i<branchCounter;++i)
225 bo=(BranchObj*)(getBranchNum(i)->getLMO());
226 if (bo) bo->setVisibility(false);
230 //model->reposition(); // FIXME-3 we don't really want to update view from here...
234 bool BranchItem::isScrolled()
239 bool BranchItem::hasScrolledParent(BranchItem *start)
241 // Calls parents recursivly to
242 // find out, if we are scrolled at all.
243 // But ignore myself, just look at parents.
245 if (this !=start && scrolled) return true;
247 BranchItem* bi=(BranchItem*)parentItem;
248 if (bi && bi!=rootItem )
249 return bi->hasScrolledParent(start);
254 bool BranchItem::tmpUnscroll()
258 // Unscroll parent (recursivly)
259 BranchItem * pi=(BranchItem*)parentItem;
260 if (pi && pi->isBranchLikeType() ) result=pi->tmpUnscroll();
266 systemFlags.activate("system-tmpUnscrolledRight");
268 model->emitDataHasChanged (this);
274 bool BranchItem::resetTmpUnscroll()
278 // Unscroll parent (recursivly)
279 BranchItem * pi=(BranchItem*)parentItem;
280 if (pi && pi->isBranchLikeType() ) result=pi->resetTmpUnscroll();
286 systemFlags.deactivate("system-tmpUnscrolledRight");
288 model->emitDataHasChanged (this);
294 void BranchItem::sortChildren(bool inverse)
296 int childCount=branchCounter;
298 bool madeChanges=false;
302 for(curChildIndex=1;curChildIndex<childCount;curChildIndex++)
304 BranchItem* curChild =getBranchNum(curChildIndex);
305 BranchItem* prevChild=getBranchNum(curChildIndex-1);
308 if (prevChild->getHeading().compare(curChild->getHeading())<0)
310 model->moveUp (curChild);
314 if (prevChild->getHeading().compare(curChild->getHeading())>0)
316 model->moveUp (curChild);
323 void BranchItem::setIncludeImagesVer(bool b)
326 /* calcBBoxSize(); FIXME-3
332 bool BranchItem::getIncludeImagesVer()
334 return includeImagesVer;
337 void BranchItem::setIncludeImagesHor(bool b)
340 /* calcBBoxSize(); FIXME-3
346 bool BranchItem::getIncludeImagesHor()
348 return includeImagesHor;
351 QString BranchItem::getIncludeImageAttr()
354 if (includeImagesVer)
355 a=attribut ("incImgV","true");
356 if (includeImagesHor)
357 a+=attribut ("incImgH","true");
361 void BranchItem::setLastSelectedBranch()
367 // Hack to save an additional lastSelected for mapcenters in MapEditor
368 // depending on orientation
369 // this allows to go both left and right from there
370 if (lmo && lmo->getOrientation()==LinkableMapObj::LeftOfCenter)
372 ((BranchItem*)parentItem)->lastSelectedBranchNumAlt=parentItem->num(this);
375 ((BranchItem*)parentItem)->lastSelectedBranchNum=parentItem->num(this);
379 void BranchItem::setLastSelectedBranch(int i)
381 lastSelectedBranchNum=i;
384 BranchItem* BranchItem::getLastSelectedBranch()
386 if (lastSelectedBranchNum>=branchCounter)
387 return getBranchNum (branchCounter-1);
389 return getBranchNum (lastSelectedBranchNum);
392 BranchItem* BranchItem::getLastSelectedBranchAlt()
394 return getBranchNum (lastSelectedBranchNumAlt);
400 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
404 for (int i=0; i<branchCount(); ++i)
406 ti=getBranchNum(i)->findMapItem(p, excludeTI);
407 if (ti != NULL) return ti;
412 if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
417 for (int i=0; i<imageCount(); ++i )
420 LinkableMapObj *mo=ii->getLMO();
421 if (mo && mo->isInClickBox(p) &&
430 for (int i=0; i<attributeCount(); ++i )
432 ai=getAttributeNum (i);
433 LinkableMapObj *mo=ai->getLMO();
434 if (mo && mo->isInClickBox(p) &&
444 void BranchItem::updateStyles(const bool &keepFrame)
446 // FIXME-5 compare also MapItem::initLMO...
450 if ( parentItem != rootItem)
451 lmo->setParObj ( ((MapItem*)parentItem)->getLMO() );
453 lmo->setParObj (NULL);
454 ((BranchObj*)lmo)->setDefAttr(BranchObj::MovedBranch,keepFrame);
458 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
460 return (BranchObj*)lmo;
463 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene) // FIXME-4 maybe move this into MapEditor to get rid of scene in VymModel?
466 newbo=new BranchObj(scene,this);
469 if (parentItem==rootItem)
471 newbo->setParObj(NULL);
472 //newbo->setFrameType (FrameObj::Rectangle); //FIXME-4 maybe call updateStyles?
475 newbo->setParObj( ((MapItem*)parentItem)->getLMO() );
476 // Set visibility depending on parents
477 if (parentItem!=rootItem &&
478 ( ((BranchItem*)parentItem)->scrolled || !((MapItem*)parentItem)->getLMO()->isVisibleObj() ) )
479 newbo->setVisibility (false);
481 newbo->setDefAttr(BranchObj::NewBranch);
484 if (!getHeading().isEmpty() )
486 newbo->updateData(); //FIXME-3 maybe better model->emitDataHasChanged()?
487 newbo->setColor (headingColor);
490 //newbo->updateLinkGeometry(); //FIXME-3