1 #include "branchitem.h"
10 BranchItem::BranchItem(const QList<QVariant> &data, TreeItem *parent):TreeItem (data,parent)
12 //cout << "Constr. BranchItem\n";
18 BranchItem::~BranchItem()
20 // cout << "Destr. BranchItem "<<getHeadingStd()<<endl;
28 void BranchItem::copy (BranchItem *other)
30 scrolled=other->scrolled;
31 tmpUnscrolled=other->tmpUnscrolled;
34 void BranchItem::insertBranch (int pos, BranchItem *branch)
37 if (pos>branchCounter) pos=branchCounter;
38 childItems.insert(pos+branchOffset,branch);
39 branch->parentItem=this;
40 branch->setModel (model);
43 branchOffset=childItems.count()-1;
47 QString BranchItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
49 // Cloudy stuff can be hidden during exports
50 if (hidden) return QString();
53 BranchObj *bo=(BranchObj*)lmo;
56 // Update of note is usually done while unselecting a branch
57 if (isNoteInEditor) getNoteFromTextEditor();
61 scrolledAttr=attribut ("scrolled","yes");
65 // save area, if not scrolled
67 if (!((BranchObj*)(parObj))->isScrolled() )
70 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
71 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
72 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
73 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
78 // Providing an ID for a branch makes export to XHTML easier
81 idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
86 s=beginElement ("branch"
91 // +getIncludeImageAttr()
96 s+=valueElement("heading", getHeading(),
97 attribut ("textColor",QColor( bo->getColor()).name()));
101 if (frame->getFrameType()!=FrameObj::NoFrame)
102 s+=frame->saveToDir ();
104 // save names of flags set
105 s+=standardFlags->saveToDir(tmpdir,prefix,0);
108 for (int i=0; i<floatimage.size(); ++i)
109 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
113 if (!note.isEmpty() )
117 TreeItem *ti=getFirstBranch();
118 TreeItem *last=getLastBranch();
119 while (ti && ti!=last)
120 s+=ti->saveToDir(tmpdir,prefix,offset);
124 QString ol; // old link
125 QString cl; // current link
126 for (int i=0; i<xlink.size(); ++i)
128 cl=xlink.at(i)->saveToDir();
135 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
141 s+=endElement ("branch");
145 void BranchItem::updateVisibility() // FIXME-1
149 void BranchItem::setVymLink(QString s)
153 // We need the relative (from loading)
154 // or absolute path (from User event)
155 // and build the absolute path.
156 // Note: If we have relative, use path of
157 // current map to build absolute path
159 if (!d.path().startsWith ("/"))
161 QString p=model->getDestPath();
162 int i=p.findRev("/",-1);
163 d.setPath(p.left(i)+"/"+s);
167 //FIXME-2 systemFlags->activate("vymLink");
171 //FIXME-2 systemFlags->deactivate("vymLink");
175 calcBBoxSize(); // recalculate bbox
176 positionBBox(); // rearrange contents
181 QString BranchItem::getVymLink()
186 void BranchItem::unScroll()
188 if (tmpUnscrolled) resetTmpUnscroll();
189 if (scrolled) toggleScroll();
192 void BranchItem::toggleScroll()
197 //FIXME-1 systemFlags->deactivate("scrolledright");
199 for (int i=0; i<branch.size(); ++i)
200 branch.at(i)->setVisibility(true);
206 //FIXME-1 systemFlags->activate("scrolledright");
207 for (int i=0; i<branch.size(); ++i)
208 branch.at(i)->setVisibility(false);
214 move (absPos.x(), absPos.y() );
219 bool BranchItem::isScrolled()
224 bool BranchItem::hasScrolledParent(BranchItem *start)
226 // Calls parents recursivly to
227 // find out, if we are scrolled at all.
228 // But ignore myself, just look at parents.
230 if (this !=start && scrolled) return true;
232 BranchItem* bi=(BranchItem*)parentItem;
234 return bi->hasScrolledParent(start);
239 void BranchItem::tmpUnscroll()
241 // Unscroll parent (recursivly)
242 BranchItem * bi=(BranchItem*)parentItem;
243 if (bi) bi->tmpUnscroll();
249 // FIXME-1 systemFlags->activate("tmpUnscrolledright");
254 void BranchItem::resetTmpUnscroll()
256 // Unscroll parent (recursivly)
257 BranchItem * bi=(BranchItem*)parentItem;
258 if (bi) bi->resetTmpUnscroll();
264 // FIXME-1 systemFlags->deactivate("tmpUnscrolledright");
269 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeLMO)
273 for (int i=0; i<branchCount(); ++i)
275 ti=getBranchNum(i)->findMapItem(p, excludeLMO);
276 if (ti != NULL) return ti;
281 if (getBranchObj()->isInClickBox (p) && (this != excludeLMO) && getBranchObj()->isVisibleObj() )
284 /* FIXME-2 // Search float images
285 for (int i=0; i<floatimage.size(); ++i )
286 if (floatimage.at(i)->isInClickBox(p) &&
287 (floatimage.at(i) != excludeLMO) &&
288 floatimage.at(i)->getParObj()!= excludeLMO &&
289 floatimage.at(i)->isVisibleObj()
290 ) return floatimage.at(i)->getTreeItem();
295 TreeItem* BranchItem::findID (QString sid)
299 for (int i=0; i<branchCount(); ++i)
301 ti=getBranchNum(i)->findID (sid);
302 if (ti != NULL) return ti;
306 if (sid==objID) return this;
310 // Search float images
311 for (int i=0; i<floatimage.size(); ++i )
312 if (floatimage.at(i)->inBox(p) &&
313 (floatimage.at(i) != excludeLMO) &&
314 floatimage.at(i)->getParObj()!= excludeLMO &&
315 floatimage.at(i)->isVisibleObj()
316 ) return floatimage.at(i);
322 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
324 return (BranchObj*)lmo;
327 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)
329 // Initialize BranchObj, order of things is important...
330 BranchObj* newbo=new BranchObj(scene);
331 newbo->setParObj(parent()->getLMO() );
332 newbo->setTreeItem (this);
333 newbo->setDefAttr(BranchObj::NewBranch);
334 //newbo->updateLink(); //FIXME-3