1 #include "branchitem.h"
10 BranchItem::BranchItem(const QList<QVariant> &data, TreeItem *parent):TreeItem (data,parent)
12 //cout << "Constr. BranchItem\n";
19 BranchItem::~BranchItem()
21 cout << "Destr. BranchItem "<<getHeadingStd()<<endl;
29 void BranchItem::copy (BranchItem *other)
31 scrolled=other->scrolled;
32 tmpUnscrolled=other->tmpUnscrolled;
35 void BranchItem::insertBranch (int pos, BranchItem *branch)
38 if (pos>branchCounter) pos=branchCounter;
39 childItems.insert(pos+branchOffset,branch);
40 branch->parentItem=this;
41 branch->setModel (model);
44 branchOffset=childItems.count()-1;
48 QString BranchItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset) //FIXME-3 Check if everything is saved...
50 // Cloudy stuff can be hidden during exports
51 if (hidden) return QString();
54 BranchObj *bo=(BranchObj*)lmo;
56 // Update of note is usually done while unselecting a branch
60 scrolledAttr=attribut ("scrolled","yes");
64 // save area, if not scrolled // FIXME-5 not needed if HTML is rewritten...
65 // also we should check if _any_ of parents is scrolled
67 if (lmo && parentItem->isBranchLikeType() && !((BranchItem*)parentItem)->isScrolled() )
69 qreal x=lmo->getAbsPos().x();
70 qreal y=lmo->getAbsPos().y();
72 attribut("x1",QString().setNum(x-offset.x())) +
73 attribut("y1",QString().setNum(y-offset.y())) +
74 attribut("x2",QString().setNum(x+lmo->width()-offset.x())) +
75 attribut("y2",QString().setNum(y+lmo->height()-offset.y()));
81 // FIXME-3 Providing an ID for a branch makes export to XHTML easier
84 idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
90 if (parentItem==rootItem)
91 elementName="mapcenter";
95 s=beginElement (elementName
100 // +getIncludeImageAttr()
105 s+=valueElement("heading", getHeading(),
106 attribut ("textColor",QColor( bo->getColor()).name()));
108 // Save frame //FIXME-4 not saved if there is no LMO
109 if (lmo && ((OrnamentedObj*)lmo)->getFrame()->getFrameType()!=FrameObj::NoFrame)
110 s+=((OrnamentedObj*)lmo)->getFrame()->saveToDir ();
112 // save names of flags set
113 s+=standardFlags.saveToDir(tmpdir,prefix,0);
116 for (int i=0; i<imageCount(); ++i)
117 s+=getImageNum(i)->saveToDir (tmpdir,prefix);
120 if (!note.isEmpty() )
125 TreeItem *ti=getBranchNum(i);
128 s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset);
135 QString ol; // old link
136 QString cl; // current link
137 for (int i=0; i<xlink.size(); ++i)
139 cl=xlink.at(i)->saveToDir();
146 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
152 s+=endElement (elementName);
156 void BranchItem::updateVisibility() // FIXME-3 Check if this is needed after all...
160 void BranchItem::setVymLink(QString s)
164 // We need the relative (from loading)
165 // or absolute path (from User event)
166 // and build the absolute path.
167 // Note: If we have relative, use path of
168 // current map to build absolute path
170 if (!d.path().startsWith ("/"))
172 QString p=model->getDestPath();
173 int i=p.findRev("/",-1);
174 d.setPath(p.left(i)+"/"+s);
178 //FIXME-2 systemFlags->activate("vymLink");
182 //FIXME-2 systemFlags->deactivate("vymLink");
186 calcBBoxSize(); // recalculate bbox
187 positionBBox(); // rearrange contents
192 QString BranchItem::getVymLink()
197 void BranchItem::setHeadingColor (QColor color)
199 TreeItem::setHeadingColor (color);
200 if (lmo) ((BranchObj*)lmo)->setColor (color);
203 void BranchItem::unScroll()
205 if (tmpUnscrolled) resetTmpUnscroll();
206 if (scrolled) toggleScroll();
209 bool BranchItem::toggleScroll()
215 systemFlags.deactivate("system-scrolledright");
218 for (int i=0;i<branchCounter;++i)
220 bo=(BranchObj*)(getBranchNum(i)->getLMO());
221 if (bo) bo->setVisibility(true);
227 systemFlags.activate("system-scrolledright");
230 for (int i=0;i<branchCounter;++i)
232 bo=(BranchObj*)(getBranchNum(i)->getLMO());
233 if (bo) bo->setVisibility(false);
237 model->reposition(); // FIXME-3 we don't really want to update view from here...
241 bool BranchItem::isScrolled()
246 bool BranchItem::hasScrolledParent(BranchItem *start)
248 // Calls parents recursivly to
249 // find out, if we are scrolled at all.
250 // But ignore myself, just look at parents.
252 if (this !=start && scrolled) return true;
254 BranchItem* bi=(BranchItem*)parentItem;
255 if (bi && bi->isBranchLikeType() )
256 return bi->hasScrolledParent(start);
261 void BranchItem::tmpUnscroll()
263 // Unscroll parent (recursivly)
264 BranchItem * pi=(BranchItem*)parentItem;
265 if (pi && pi->isBranchLikeType() ) pi->tmpUnscroll();
271 systemFlags.activate("system-tmpUnscrolledRight");
273 model->emitDataHasChanged (this);
277 void BranchItem::resetTmpUnscroll()
279 // Unscroll parent (recursivly)
280 BranchItem * pi=(BranchItem*)parentItem;
281 if (pi && pi->isBranchLikeType() ) pi->resetTmpUnscroll();
287 systemFlags.deactivate("system-tmpUnscrolledRight");
289 model->emitDataHasChanged (this);
293 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
297 for (int i=0; i<branchCount(); ++i)
299 ti=getBranchNum(i)->findMapItem(p, excludeTI);
300 if (ti != NULL) return ti;
305 if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
310 for (int i=0; i<imageCount(); ++i )
313 LinkableMapObj *mo=ii->getLMO();
314 if (mo && mo->isInClickBox(p) &&
323 TreeItem* BranchItem::findID (QString sid)
327 for (int i=0; i<branchCount(); ++i)
329 ti=getBranchNum(i)->findID (sid);
330 if (ti != NULL) return ti;
334 if (sid==objID) return this;
338 // Search float images
339 for (int i=0; i<floatimage.size(); ++i )
340 if (floatimage.at(i)->inBox(p) &&
341 (floatimage.at(i) != excludeLMO) &&
342 floatimage.at(i)->getParObj()!= excludeLMO &&
343 floatimage.at(i)->isVisibleObj()
344 ) return floatimage.at(i);
349 void BranchItem::updateStyles()
351 // FIXME-5 compare also MapItem::initLMO...
355 lmo->setParObj ( parentItem->getLMO() );
359 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
361 return (BranchObj*)lmo;
364 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)
367 newbo=new BranchObj(scene);
368 newbo->setTreeItem (this);
371 if (parentItem==rootItem)
373 newbo->setParObj(NULL);
374 newbo->setFrameType (FrameObj::Rectangle);
377 newbo->setParObj( parentItem->getLMO() );
378 // Set visibility depending on parents
379 if (((BranchItem*)parentItem)->scrolled || !parentItem->getLMO()->isVisibleObj() )
380 newbo->setVisibility (false);
382 newbo->setDefAttr(BranchObj::NewBranch);
385 if (!getHeading().isEmpty() )
387 newbo->updateData(); //FIXME-3 maybe better model->emitDataHasChanged()?
388 newbo->setColor (headingColor);
391 //newbo->updateLink(); //FIXME-3