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");
65 // save area, if not scrolled // FIXME-3 not needed if HTML is rewritten...
66 // also we should check if _any_ of parents is scrolled
68 if (!((BranchObj*)(parObj))->isScrolled() )
71 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
72 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
73 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
74 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
79 // Providing an ID for a branch makes export to XHTML easier
82 idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
88 if (parentItem==rootItem)
89 elementName="mapcenter";
93 s=beginElement (elementName
99 // +getIncludeImageAttr()
104 s+=valueElement("heading", getHeading(),
105 attribut ("textColor",QColor( bo->getColor()).name()));
109 if (frame->getFrameType()!=FrameObj::NoFrame)
110 s+=frame->saveToDir ();
113 // save names of flags set
114 s+=standardFlags.saveToDir(tmpdir,prefix,0);
118 for (int i=0; i<floatimage.size(); ++i)
119 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
123 if (!note.isEmpty() )
128 TreeItem *ti=getBranchNum(i);
131 s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset);
138 QString ol; // old link
139 QString cl; // current link
140 for (int i=0; i<xlink.size(); ++i)
142 cl=xlink.at(i)->saveToDir();
149 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
155 s+=endElement (elementName);
159 void BranchItem::updateVisibility() // FIXME-3 Check if this is needed after all...
163 void BranchItem::setVymLink(QString s)
167 // We need the relative (from loading)
168 // or absolute path (from User event)
169 // and build the absolute path.
170 // Note: If we have relative, use path of
171 // current map to build absolute path
173 if (!d.path().startsWith ("/"))
175 QString p=model->getDestPath();
176 int i=p.findRev("/",-1);
177 d.setPath(p.left(i)+"/"+s);
181 //FIXME-2 systemFlags->activate("vymLink");
185 //FIXME-2 systemFlags->deactivate("vymLink");
189 calcBBoxSize(); // recalculate bbox
190 positionBBox(); // rearrange contents
195 QString BranchItem::getVymLink()
200 void BranchItem::setHeadingColor (QColor color)
202 TreeItem::setHeadingColor (color);
203 if (lmo) ((BranchObj*)lmo)->setColor (color);
206 void BranchItem::unScroll()
208 if (tmpUnscrolled) resetTmpUnscroll();
209 if (scrolled) toggleScroll();
212 bool BranchItem::toggleScroll()
218 systemFlags.deactivate("system-scrolledright");
221 for (int i=0;i<branchCounter;++i)
223 bo=(BranchObj*)(getBranchNum(i)->getLMO());
224 if (bo) bo->setVisibility(true);
230 systemFlags.activate("system-scrolledright");
233 for (int i=0;i<branchCounter;++i)
235 bo=(BranchObj*)(getBranchNum(i)->getLMO());
236 if (bo) bo->setVisibility(false);
240 model->reposition(); // FIXME-3 we don't really want to update view from here...
244 bool BranchItem::isScrolled()
249 bool BranchItem::hasScrolledParent(BranchItem *start)
251 // Calls parents recursivly to
252 // find out, if we are scrolled at all.
253 // But ignore myself, just look at parents.
255 if (this !=start && scrolled) return true;
257 BranchItem* bi=(BranchItem*)parentItem;
259 return bi->hasScrolledParent(start);
264 void BranchItem::tmpUnscroll()
266 // Unscroll parent (recursivly)
267 BranchItem * bi=(BranchItem*)parentItem;
268 if (bi) bi->tmpUnscroll();
274 // FIXME-1 systemFlags->activate("tmpUnscrolledright");
279 void BranchItem::resetTmpUnscroll()
281 // Unscroll parent (recursivly)
282 BranchItem * bi=(BranchItem*)parentItem;
283 if (bi) bi->resetTmpUnscroll();
289 // FIXME-1 systemFlags->deactivate("tmpUnscrolledright");
294 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
298 for (int i=0; i<branchCount(); ++i)
300 ti=getBranchNum(i)->findMapItem(p, excludeTI);
301 if (ti != NULL) return ti;
306 if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
309 /* FIXME-2 // Search float images
310 for (int i=0; i<floatimage.size(); ++i )
311 if (floatimage.at(i)->isInClickBox(p) &&
312 (floatimage.at(i) != excludeTI) &&
313 floatimage.at(i)->getParObj()!= excludeTI &&
314 floatimage.at(i)->isVisibleObj()
315 ) return floatimage.at(i)->getTreeItem();
320 TreeItem* BranchItem::findID (QString sid)
324 for (int i=0; i<branchCount(); ++i)
326 ti=getBranchNum(i)->findID (sid);
327 if (ti != NULL) return ti;
331 if (sid==objID) return this;
335 // Search float images
336 for (int i=0; i<floatimage.size(); ++i )
337 if (floatimage.at(i)->inBox(p) &&
338 (floatimage.at(i) != excludeLMO) &&
339 floatimage.at(i)->getParObj()!= excludeLMO &&
340 floatimage.at(i)->isVisibleObj()
341 ) return floatimage.at(i);
346 void BranchItem::updateStyles()
348 // FIXME-5 compare also MapItem::initLMO...
352 lmo->setParObj (parentItem->getLMO() );
356 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
358 return (BranchObj*)lmo;
361 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)
364 cout << "BI::createMO "<<getHeadingStd()<<" pI="<<parentItem<<" rI="<<rootItem<<endl;
365 if (parentItem==rootItem)
367 // Initialize MapCenterObj, order of things is important...
368 cout << "BI::createMO (MCO) "<<getHeadingStd()<<endl;
369 MapCenterObj* mco=new MapCenterObj(scene);
372 newbo->setParObj(NULL);
373 newbo->setTreeItem (this);
374 newbo->setDefAttr(BranchObj::NewBranch);
377 // Initialize BranchObj, order of things is important...
378 cout << "BI::createMO (BO) "<<getHeadingStd()<<endl;
379 newbo=new BranchObj(scene);
381 BranchObj* parbo=(BranchObj*)(parentItem->getLMO());
382 newbo->setParObj(parbo);
383 newbo->setTreeItem (this);
384 newbo->setDefAttr(BranchObj::NewBranch);
386 if (parentItem->isBranchLikeType())
388 // Set visibility depending on parents
389 if (((BranchItem*)parentItem)->scrolled || !parbo->isVisibleObj() )
391 if (parentItem && parentItem->isBranchLikeType())
392 cout <<" scrolled="<<((BranchItem*)parentItem)->scrolled<<endl;
394 cout <<" par->vis="<<parbo->isVisibleObj()<<endl;
395 newbo->setVisibility (false);
398 cout <<" pI=no branch!\n";
403 if (!getHeading().isEmpty() )
405 ((BranchObj*)lmo)->updateData(); //FIXME-3 maybe better model->emitDataHasChanged()?
406 ((BranchObj*)lmo)->setColor (headingColor);
410 //newbo->updateLink(); //FIXME-3