1 #include "branchitem.h"
10 BranchItem::BranchItem(const QList<QVariant> &data, TreeItem *parent):MapItem (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
101 // +getIncludeImageAttr()
106 s+=valueElement("heading", getHeading(),
107 attribut ("textColor",QColor( bo->getColor()).name()));
109 // Save frame //FIXME-4 not saved if there is no LMO
110 if (lmo && ((OrnamentedObj*)lmo)->getFrame()->getFrameType()!=FrameObj::NoFrame)
111 s+=((OrnamentedObj*)lmo)->getFrame()->saveToDir ();
113 // save names of flags set
114 s+=standardFlags.saveToDir(tmpdir,prefix,0);
117 for (int i=0; i<imageCount(); ++i)
118 s+=getImageNum(i)->saveToDir (tmpdir,prefix);
121 if (!note.isEmpty() )
126 TreeItem *ti=getBranchNum(i);
129 s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset);
136 QString ol; // old link
137 QString cl; // current link
138 for (int i=0; i<xlink.size(); ++i)
140 cl=xlink.at(i)->saveToDir();
147 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
153 s+=endElement (elementName);
157 void BranchItem::updateVisibility() // FIXME-3 Check if this is needed after all...
161 void BranchItem::setVymLink(QString s)
165 // We need the relative (from loading)
166 // or absolute path (from User event)
167 // and build the absolute path.
168 // Note: If we have relative, use path of
169 // current map to build absolute path
171 if (!d.path().startsWith ("/"))
173 QString p=model->getDestPath();
174 int i=p.findRev("/",-1);
175 d.setPath(p.left(i)+"/"+s);
179 //FIXME-2 systemFlags->activate("vymLink");
183 //FIXME-2 systemFlags->deactivate("vymLink");
187 calcBBoxSize(); // recalculate bbox
188 positionBBox(); // rearrange contents
193 QString BranchItem::getVymLink()
198 void BranchItem::setHeadingColor (QColor color)
200 TreeItem::setHeadingColor (color);
201 if (lmo) ((BranchObj*)lmo)->setColor (color);
204 void BranchItem::unScroll()
206 if (tmpUnscrolled) resetTmpUnscroll();
207 if (scrolled) toggleScroll();
210 bool BranchItem::toggleScroll()
216 systemFlags.deactivate("system-scrolledright");
219 for (int i=0;i<branchCounter;++i)
221 bo=(BranchObj*)(getBranchNum(i)->getLMO());
222 if (bo) bo->setVisibility(true);
228 systemFlags.activate("system-scrolledright");
231 for (int i=0;i<branchCounter;++i)
233 bo=(BranchObj*)(getBranchNum(i)->getLMO());
234 if (bo) bo->setVisibility(false);
238 model->reposition(); // FIXME-3 we don't really want to update view from here...
242 bool BranchItem::isScrolled()
247 bool BranchItem::hasScrolledParent(BranchItem *start)
249 // Calls parents recursivly to
250 // find out, if we are scrolled at all.
251 // But ignore myself, just look at parents.
253 //cout << "BI::hasScrolledParent this="<<this<<" "<<getHeadingStd()<<endl;
254 if (this !=start && scrolled) return true;
256 BranchItem* bi=(BranchItem*)parentItem;
257 if (bi && bi!=rootItem && bi->isBranchLikeType() )
258 return bi->hasScrolledParent(start);
263 void BranchItem::tmpUnscroll()
265 // Unscroll parent (recursivly)
266 BranchItem * pi=(BranchItem*)parentItem;
267 if (pi && pi->isBranchLikeType() ) pi->tmpUnscroll();
273 systemFlags.activate("system-tmpUnscrolledRight");
275 model->emitDataHasChanged (this);
279 void BranchItem::resetTmpUnscroll()
281 // Unscroll parent (recursivly)
282 BranchItem * pi=(BranchItem*)parentItem;
283 if (pi && pi->isBranchLikeType() ) pi->resetTmpUnscroll();
289 systemFlags.deactivate("system-tmpUnscrolledRight");
291 model->emitDataHasChanged (this);
295 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
299 for (int i=0; i<branchCount(); ++i)
301 ti=getBranchNum(i)->findMapItem(p, excludeTI);
302 if (ti != NULL) return ti;
307 if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
312 for (int i=0; i<imageCount(); ++i )
315 LinkableMapObj *mo=ii->getLMO();
316 if (mo && mo->isInClickBox(p) &&
325 TreeItem* BranchItem::findID (QString sid)
329 for (int i=0; i<branchCount(); ++i)
331 ti=getBranchNum(i)->findID (sid);
332 if (ti != NULL) return ti;
336 if (sid==objID) return this;
340 // Search float images
341 for (int i=0; i<floatimage.size(); ++i )
342 if (floatimage.at(i)->inBox(p) &&
343 (floatimage.at(i) != excludeLMO) &&
344 floatimage.at(i)->getParObj()!= excludeLMO &&
345 floatimage.at(i)->isVisibleObj()
346 ) return floatimage.at(i);
351 void BranchItem::updateStyles()
353 // FIXME-5 compare also MapItem::initLMO...
355 if (lmo && parentItem != rootItem)
357 lmo->setParObj ( ((MapItem*)parentItem)->getLMO() );
361 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
363 return (BranchObj*)lmo;
366 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)
369 newbo=new BranchObj(scene);
370 newbo->setTreeItem (this);
373 if (parentItem==rootItem)
375 newbo->setParObj(NULL);
376 newbo->setFrameType (FrameObj::Rectangle);
379 newbo->setParObj( ((MapItem*)parentItem)->getLMO() );
380 // Set visibility depending on parents
381 if (((BranchItem*)parentItem)->scrolled || !((MapItem*)parentItem)->getLMO()->isVisibleObj() )
382 newbo->setVisibility (false);
384 newbo->setDefAttr(BranchObj::NewBranch);
387 if (!getHeading().isEmpty() )
389 newbo->updateData(); //FIXME-3 maybe better model->emitDataHasChanged()?
390 newbo->setColor (headingColor);
393 //newbo->updateLinkGeometry(); //FIXME-3