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 cout << "BI::saveToDir: "<<getHeadingStd()<<endl;
51 // Cloudy stuff can be hidden during exports
52 if (hidden) return QString();
55 BranchObj *bo=(BranchObj*)lmo;
58 // Update of note is usually done while unselecting a branch
59 if (isNoteInEditor) getNoteFromTextEditor();
63 scrolledAttr=attribut ("scrolled","yes");
67 // save area, if not scrolled
69 if (!((BranchObj*)(parObj))->isScrolled() )
72 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
73 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
74 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
75 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
80 // Providing an ID for a branch makes export to XHTML easier
83 idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
88 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 ();
106 // save names of flags set
107 s+=standardFlags->saveToDir(tmpdir,prefix,0);
110 for (int i=0; i<floatimage.size(); ++i)
111 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
115 if (!note.isEmpty() )
120 TreeItem *ti=getBranchNum(i);
123 s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset);
130 QString ol; // old link
131 QString cl; // current link
132 for (int i=0; i<xlink.size(); ++i)
134 cl=xlink.at(i)->saveToDir();
141 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
147 s+=endElement ("branch");
151 void BranchItem::updateVisibility() // FIXME-1
155 void BranchItem::setVymLink(QString s)
159 // We need the relative (from loading)
160 // or absolute path (from User event)
161 // and build the absolute path.
162 // Note: If we have relative, use path of
163 // current map to build absolute path
165 if (!d.path().startsWith ("/"))
167 QString p=model->getDestPath();
168 int i=p.findRev("/",-1);
169 d.setPath(p.left(i)+"/"+s);
173 //FIXME-2 systemFlags->activate("vymLink");
177 //FIXME-2 systemFlags->deactivate("vymLink");
181 calcBBoxSize(); // recalculate bbox
182 positionBBox(); // rearrange contents
187 QString BranchItem::getVymLink()
192 void BranchItem::setHeadingColor (QColor color)
194 TreeItem::setHeadingColor (color);
195 if (lmo) ((BranchObj*)lmo)->setColor (color);
198 void BranchItem::unScroll()
200 if (tmpUnscrolled) resetTmpUnscroll();
201 if (scrolled) toggleScroll();
204 void BranchItem::toggleScroll()
209 //FIXME-1 systemFlags->deactivate("scrolledright");
211 for (int i=0; i<branch.size(); ++i)
212 branch.at(i)->setVisibility(true);
218 //FIXME-1 systemFlags->activate("scrolledright");
219 for (int i=0; i<branch.size(); ++i)
220 branch.at(i)->setVisibility(false);
226 move (absPos.x(), absPos.y() );
231 bool BranchItem::isScrolled()
236 bool BranchItem::hasScrolledParent(BranchItem *start)
238 // Calls parents recursivly to
239 // find out, if we are scrolled at all.
240 // But ignore myself, just look at parents.
242 if (this !=start && scrolled) return true;
244 BranchItem* bi=(BranchItem*)parentItem;
246 return bi->hasScrolledParent(start);
251 void BranchItem::tmpUnscroll()
253 // Unscroll parent (recursivly)
254 BranchItem * bi=(BranchItem*)parentItem;
255 if (bi) bi->tmpUnscroll();
261 // FIXME-1 systemFlags->activate("tmpUnscrolledright");
266 void BranchItem::resetTmpUnscroll()
268 // Unscroll parent (recursivly)
269 BranchItem * bi=(BranchItem*)parentItem;
270 if (bi) bi->resetTmpUnscroll();
276 // FIXME-1 systemFlags->deactivate("tmpUnscrolledright");
281 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
285 for (int i=0; i<branchCount(); ++i)
287 ti=getBranchNum(i)->findMapItem(p, excludeTI);
288 if (ti != NULL) return ti;
293 if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
296 /* FIXME-2 // Search float images
297 for (int i=0; i<floatimage.size(); ++i )
298 if (floatimage.at(i)->isInClickBox(p) &&
299 (floatimage.at(i) != excludeTI) &&
300 floatimage.at(i)->getParObj()!= excludeTI &&
301 floatimage.at(i)->isVisibleObj()
302 ) return floatimage.at(i)->getTreeItem();
307 TreeItem* BranchItem::findID (QString sid)
311 for (int i=0; i<branchCount(); ++i)
313 ti=getBranchNum(i)->findID (sid);
314 if (ti != NULL) return ti;
318 if (sid==objID) return this;
322 // Search float images
323 for (int i=0; i<floatimage.size(); ++i )
324 if (floatimage.at(i)->inBox(p) &&
325 (floatimage.at(i) != excludeLMO) &&
326 floatimage.at(i)->getParObj()!= excludeLMO &&
327 floatimage.at(i)->isVisibleObj()
328 ) return floatimage.at(i);
334 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
336 return (BranchObj*)lmo;
339 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)
341 // Initialize BranchObj, order of things is important...
342 BranchObj* newbo=new BranchObj(scene);
344 newbo->setParObj(parent()->getLMO() );
345 newbo->setTreeItem (this);
346 newbo->setDefAttr(BranchObj::NewBranch);
350 if (!getHeading().isEmpty() )
352 newbo->updateHeading();
353 newbo->setColor (headingColor);
357 //newbo->updateLink(); //FIXME-3