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 void BranchItem::insertBranch (int pos, BranchItem *branch)
51 if (pos>branchCounter) pos=branchCounter;
52 childItems.insert(pos+branchOffset,branch);
53 branch->parentItem=this;
54 branch->rootItem=rootItem;
55 branch->setModel (model);
56 if (parentItem==rootItem)
63 branchOffset=childItems.count()-1;
67 QString BranchItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset) //FIXME-3 Check if everything is saved...
69 // Cloudy stuff can be hidden during exports
70 if (hidden) return QString();
73 BranchObj *bo=(BranchObj*)lmo;
75 // Update of note is usually done while unselecting a branch
79 scrolledAttr=attribut ("scrolled","yes");
83 // save area, if not scrolled // FIXME-5 not needed if HTML is rewritten...
84 // also we should check if _any_ of parents is scrolled
86 if (lmo && parentItem->isBranchLikeType() && !((BranchItem*)parentItem)->isScrolled() )
88 qreal x=lmo->getAbsPos().x();
89 qreal y=lmo->getAbsPos().y();
91 attribut("x1",QString().setNum(x-offset.x())) +
92 attribut("y1",QString().setNum(y-offset.y())) +
93 attribut("x2",QString().setNum(x+lmo->width()-offset.x())) +
94 attribut("y2",QString().setNum(y+lmo->height()-offset.y()));
99 // Provide an ID for a branch makes export to XHTML easier
102 idAttr=attribut ("id",model->getSelectString(this));
107 if (parentItem==rootItem)
108 elementName="mapcenter";
110 elementName="branch";
112 s=beginElement (elementName
116 // +areaAttr // FIXME-2
118 +getIncludeImageAttr()
123 s+=valueElement("heading", getHeading(),
124 attribut ("textColor",QColor( bo->getColor()).name()));
126 // Save frame //FIXME-4 not saved if there is no LMO
127 if (lmo && ((OrnamentedObj*)lmo)->getFrame()->getFrameType()!=FrameObj::NoFrame)
128 s+=((OrnamentedObj*)lmo)->getFrame()->saveToDir ();
130 // save names of flags set
131 s+=standardFlags.saveToDir(tmpdir,prefix,0);
134 for (int i=0; i<imageCount(); ++i)
135 s+=getImageNum(i)->saveToDir (tmpdir,prefix);
138 if (!note.isEmpty() )
143 TreeItem *ti=getBranchNum(i);
146 s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset);
152 QString ol; // old link
153 QString cl; // current link
154 for (int i=0; i<xlinkCount(); ++i)
156 cl=getXLinkNum(i)->saveToDir();
163 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
168 s+=endElement (elementName);
172 void BranchItem::updateVisibility()
174 // Needed to hide relinked branch, if parent is scrolled
176 lmo->setVisibility(!((BranchItem*)parentItem)->isScrolled());
179 void BranchItem::setHeadingColor (QColor color)
181 TreeItem::setHeadingColor (color);
182 if (lmo) ((BranchObj*)lmo)->setColor (color);
185 void BranchItem::unScroll()
187 if (tmpUnscrolled) resetTmpUnscroll();
188 if (scrolled) toggleScroll();
191 bool BranchItem::toggleScroll()
197 systemFlags.deactivate("system-scrolledright");
200 for (int i=0;i<branchCounter;++i)
202 bo=(BranchObj*)(getBranchNum(i)->getLMO());
203 if (bo) bo->setVisibility(true);
209 systemFlags.activate("system-scrolledright");
212 for (int i=0;i<branchCounter;++i)
214 bo=(BranchObj*)(getBranchNum(i)->getLMO());
215 if (bo) bo->setVisibility(false);
219 model->reposition(); // FIXME-3 we don't really want to update view from here...
223 bool BranchItem::isScrolled()
228 bool BranchItem::hasScrolledParent(BranchItem *start)
230 // Calls parents recursivly to
231 // find out, if we are scrolled at all.
232 // But ignore myself, just look at parents.
234 //cout << "BI::hasScrolledParent this="<<this<<" "<<getHeadingStd()<<endl;
235 if (this !=start && scrolled) return true;
237 BranchItem* bi=(BranchItem*)parentItem;
238 if (bi && bi!=rootItem && bi->isBranchLikeType() )
239 return bi->hasScrolledParent(start);
244 void BranchItem::tmpUnscroll()
246 // Unscroll parent (recursivly)
247 BranchItem * pi=(BranchItem*)parentItem;
248 if (pi && pi->isBranchLikeType() ) pi->tmpUnscroll();
254 systemFlags.activate("system-tmpUnscrolledRight");
256 model->emitDataHasChanged (this);
260 void BranchItem::resetTmpUnscroll()
262 // Unscroll parent (recursivly)
263 BranchItem * pi=(BranchItem*)parentItem;
264 if (pi && pi->isBranchLikeType() ) pi->resetTmpUnscroll();
270 systemFlags.deactivate("system-tmpUnscrolledRight");
272 model->emitDataHasChanged (this);
276 void BranchItem::setIncludeImagesVer(bool b)
279 /* calcBBoxSize(); FIXME-2
285 bool BranchItem::getIncludeImagesVer()
287 return includeImagesVer;
290 void BranchItem::setIncludeImagesHor(bool b)
293 /* calcBBoxSize(); FIXME-2
299 bool BranchItem::getIncludeImagesHor()
301 return includeImagesHor;
304 QString BranchItem::getIncludeImageAttr()
307 if (includeImagesVer)
308 a=attribut ("incImgV","true");
309 if (includeImagesHor)
310 a+=attribut ("incImgH","true");
314 void BranchItem::setLastSelectedBranch()
320 // Hack to save an additional lastSelected for mapcenters in MapEditor
321 // depending on orientation
322 // this allows to go both left and right from there
323 if (lmo && lmo->getOrientation()==LinkableMapObj::LeftOfCenter)
325 ((BranchItem*)parentItem)->lastSelectedBranchNumAlt=parentItem->num(this);
328 ((BranchItem*)parentItem)->lastSelectedBranchNum=parentItem->num(this);
332 void BranchItem::setLastSelectedBranch(int i)
334 lastSelectedBranchNum=i;
337 BranchItem* BranchItem::getLastSelectedBranch()
339 return getBranchNum (lastSelectedBranchNum);
342 BranchItem* BranchItem::getLastSelectedBranchAlt()
344 return getBranchNum (lastSelectedBranchNumAlt);
351 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
355 for (int i=0; i<branchCount(); ++i)
357 ti=getBranchNum(i)->findMapItem(p, excludeTI);
358 if (ti != NULL) return ti;
363 if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
368 for (int i=0; i<imageCount(); ++i )
371 LinkableMapObj *mo=ii->getLMO();
372 if (mo && mo->isInClickBox(p) &&
381 TreeItem* BranchItem::findID (QString sid) //FIXME-3 move to TreeItem //FIXME-4 search images
385 for (int i=0; i<branchCount(); ++i)
387 ti=getBranchNum(i)->findID (sid);
388 if (ti != NULL) return ti;
392 if (sid==objID) return this;
396 // Search float images
397 for (int i=0; i<floatimage.size(); ++i )
398 if (floatimage.at(i)->inBox(p) &&
399 (floatimage.at(i) != excludeLMO) &&
400 floatimage.at(i)->getParObj()!= excludeLMO &&
401 floatimage.at(i)->isVisibleObj()
402 ) return floatimage.at(i);
407 void BranchItem::updateStyles()
409 // FIXME-5 compare also MapItem::initLMO...
411 if (lmo && parentItem != rootItem)
413 lmo->setParObj ( ((MapItem*)parentItem)->getLMO() );
417 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
419 return (BranchObj*)lmo;
422 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene) // FIXME-4 maybe move this into MapEditor to get rid of scene in VymModel?
425 newbo=new BranchObj(scene,this);
428 if (parentItem==rootItem)
430 newbo->setParObj(NULL);
431 newbo->setFrameType (FrameObj::Rectangle);
434 newbo->setParObj( ((MapItem*)parentItem)->getLMO() );
435 // Set visibility depending on parents
436 if (parentItem!=rootItem &&
437 ( ((BranchItem*)parentItem)->scrolled || !((MapItem*)parentItem)->getLMO()->isVisibleObj() ) )
438 newbo->setVisibility (false);
440 newbo->setDefAttr(BranchObj::NewBranch);
443 if (!getHeading().isEmpty() )
445 newbo->updateData(); //FIXME-3 maybe better model->emitDataHasChanged()?
446 newbo->setColor (headingColor);
449 //newbo->updateLinkGeometry(); //FIXME-3