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-1
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-1
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()
209 if (!branchCount()>0) return false;
214 systemFlags.deactivate("system-scrolledright");
217 for (int i=0;i<branchCounter;++i)
219 bo=(BranchObj*)(getBranchNum(i)->getLMO());
220 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);
240 bool BranchItem::isScrolled()
245 bool BranchItem::hasScrolledParent(BranchItem *start)
247 // Calls parents recursivly to
248 // find out, if we are scrolled at all.
249 // But ignore myself, just look at parents.
251 if (this !=start && scrolled) return true;
253 BranchItem* bi=(BranchItem*)parentItem;
255 return bi->hasScrolledParent(start);
260 void BranchItem::tmpUnscroll()
262 // Unscroll parent (recursivly)
263 BranchItem * bi=(BranchItem*)parentItem;
264 if (bi) bi->tmpUnscroll();
270 // FIXME-1 systemFlags->activate("tmpUnscrolledright");
275 void BranchItem::resetTmpUnscroll()
277 // Unscroll parent (recursivly)
278 BranchItem * bi=(BranchItem*)parentItem;
279 if (bi) bi->resetTmpUnscroll();
285 // FIXME-1 systemFlags->deactivate("tmpUnscrolledright");
290 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
294 for (int i=0; i<branchCount(); ++i)
296 ti=getBranchNum(i)->findMapItem(p, excludeTI);
297 if (ti != NULL) return ti;
302 if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
305 /* FIXME-2 // Search float images
306 for (int i=0; i<floatimage.size(); ++i )
307 if (floatimage.at(i)->isInClickBox(p) &&
308 (floatimage.at(i) != excludeTI) &&
309 floatimage.at(i)->getParObj()!= excludeTI &&
310 floatimage.at(i)->isVisibleObj()
311 ) return floatimage.at(i)->getTreeItem();
316 TreeItem* BranchItem::findID (QString sid)
320 for (int i=0; i<branchCount(); ++i)
322 ti=getBranchNum(i)->findID (sid);
323 if (ti != NULL) return ti;
327 if (sid==objID) return this;
331 // Search float images
332 for (int i=0; i<floatimage.size(); ++i )
333 if (floatimage.at(i)->inBox(p) &&
334 (floatimage.at(i) != excludeLMO) &&
335 floatimage.at(i)->getParObj()!= excludeLMO &&
336 floatimage.at(i)->isVisibleObj()
337 ) return floatimage.at(i);
343 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
345 return (BranchObj*)lmo;
348 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)
350 // Initialize BranchObj, order of things is important...
351 BranchObj* newbo=new BranchObj(scene);
353 newbo->setParObj(parent()->getLMO() );
354 newbo->setTreeItem (this);
355 newbo->setDefAttr(BranchObj::NewBranch);
359 if (!getHeading().isEmpty() )
361 newbo->updateData(); //FIXME-3 maybe better model->emitDataHasChanged()?
362 newbo->setColor (headingColor);
366 //newbo->updateLink(); //FIXME-3