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
87 s=beginElement ("branch"
93 // +getIncludeImageAttr()
98 s+=valueElement("heading", getHeading(),
99 attribut ("textColor",QColor( bo->getColor()).name()));
103 if (frame->getFrameType()!=FrameObj::NoFrame)
104 s+=frame->saveToDir ();
107 // save names of flags set
108 s+=standardFlags.saveToDir(tmpdir,prefix,0);
112 for (int i=0; i<floatimage.size(); ++i)
113 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
117 if (!note.isEmpty() )
122 TreeItem *ti=getBranchNum(i);
125 s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset);
132 QString ol; // old link
133 QString cl; // current link
134 for (int i=0; i<xlink.size(); ++i)
136 cl=xlink.at(i)->saveToDir();
143 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
149 s+=endElement ("branch");
153 void BranchItem::updateVisibility() // FIXME-3 Check if this is needed after all...
157 void BranchItem::setVymLink(QString s)
161 // We need the relative (from loading)
162 // or absolute path (from User event)
163 // and build the absolute path.
164 // Note: If we have relative, use path of
165 // current map to build absolute path
167 if (!d.path().startsWith ("/"))
169 QString p=model->getDestPath();
170 int i=p.findRev("/",-1);
171 d.setPath(p.left(i)+"/"+s);
175 //FIXME-2 systemFlags->activate("vymLink");
179 //FIXME-2 systemFlags->deactivate("vymLink");
183 calcBBoxSize(); // recalculate bbox
184 positionBBox(); // rearrange contents
189 QString BranchItem::getVymLink()
194 void BranchItem::setHeadingColor (QColor color)
196 TreeItem::setHeadingColor (color);
197 if (lmo) ((BranchObj*)lmo)->setColor (color);
200 void BranchItem::unScroll()
202 if (tmpUnscrolled) resetTmpUnscroll();
203 if (scrolled) toggleScroll();
206 bool BranchItem::toggleScroll()
212 systemFlags.deactivate("system-scrolledright");
215 for (int i=0;i<branchCounter;++i)
217 bo=(BranchObj*)(getBranchNum(i)->getLMO());
218 if (bo) bo->setVisibility(true);
224 systemFlags.activate("system-scrolledright");
227 for (int i=0;i<branchCounter;++i)
229 bo=(BranchObj*)(getBranchNum(i)->getLMO());
230 if (bo) bo->setVisibility(false);
234 model->reposition(); // FIXME-3 we don't really want to update view from here...
238 bool BranchItem::isScrolled()
243 bool BranchItem::hasScrolledParent(BranchItem *start)
245 // Calls parents recursivly to
246 // find out, if we are scrolled at all.
247 // But ignore myself, just look at parents.
249 if (this !=start && scrolled) return true;
251 BranchItem* bi=(BranchItem*)parentItem;
253 return bi->hasScrolledParent(start);
258 void BranchItem::tmpUnscroll()
260 // Unscroll parent (recursivly)
261 BranchItem * bi=(BranchItem*)parentItem;
262 if (bi) bi->tmpUnscroll();
268 // FIXME-1 systemFlags->activate("tmpUnscrolledright");
273 void BranchItem::resetTmpUnscroll()
275 // Unscroll parent (recursivly)
276 BranchItem * bi=(BranchItem*)parentItem;
277 if (bi) bi->resetTmpUnscroll();
283 // FIXME-1 systemFlags->deactivate("tmpUnscrolledright");
288 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
292 for (int i=0; i<branchCount(); ++i)
294 ti=getBranchNum(i)->findMapItem(p, excludeTI);
295 if (ti != NULL) return ti;
300 if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
303 /* FIXME-2 // Search float images
304 for (int i=0; i<floatimage.size(); ++i )
305 if (floatimage.at(i)->isInClickBox(p) &&
306 (floatimage.at(i) != excludeTI) &&
307 floatimage.at(i)->getParObj()!= excludeTI &&
308 floatimage.at(i)->isVisibleObj()
309 ) return floatimage.at(i)->getTreeItem();
314 TreeItem* BranchItem::findID (QString sid)
318 for (int i=0; i<branchCount(); ++i)
320 ti=getBranchNum(i)->findID (sid);
321 if (ti != NULL) return ti;
325 if (sid==objID) return this;
329 // Search float images
330 for (int i=0; i<floatimage.size(); ++i )
331 if (floatimage.at(i)->inBox(p) &&
332 (floatimage.at(i) != excludeLMO) &&
333 floatimage.at(i)->getParObj()!= excludeLMO &&
334 floatimage.at(i)->isVisibleObj()
335 ) return floatimage.at(i);
341 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
343 return (BranchObj*)lmo;
346 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)
348 // Initialize BranchObj, order of things is important...
349 BranchObj* newbo=new BranchObj(scene);
351 BranchObj* parbo=(BranchObj*)(parentItem->getLMO());
352 newbo->setParObj(parbo);
353 newbo->setTreeItem (this);
354 newbo->setDefAttr(BranchObj::NewBranch);
355 if (((BranchItem*)parentItem)->scrolled || !parbo->isVisibleObj() )
356 newbo->setVisibility (false);
360 if (!getHeading().isEmpty() )
362 newbo->updateData(); //FIXME-3 maybe better model->emitDataHasChanged()?
363 newbo->setColor (headingColor);
367 //newbo->updateLink(); //FIXME-3