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::setHeadingColor (QColor color)
188 TreeItem::setHeadingColor (color);
189 if (lmo) ((BranchObj*)lmo)->setColor (color);
192 void BranchItem::unScroll()
194 if (tmpUnscrolled) resetTmpUnscroll();
195 if (scrolled) toggleScroll();
198 void BranchItem::toggleScroll()
203 //FIXME-1 systemFlags->deactivate("scrolledright");
205 for (int i=0; i<branch.size(); ++i)
206 branch.at(i)->setVisibility(true);
212 //FIXME-1 systemFlags->activate("scrolledright");
213 for (int i=0; i<branch.size(); ++i)
214 branch.at(i)->setVisibility(false);
220 move (absPos.x(), absPos.y() );
225 bool BranchItem::isScrolled()
230 bool BranchItem::hasScrolledParent(BranchItem *start)
232 // Calls parents recursivly to
233 // find out, if we are scrolled at all.
234 // But ignore myself, just look at parents.
236 if (this !=start && scrolled) return true;
238 BranchItem* bi=(BranchItem*)parentItem;
240 return bi->hasScrolledParent(start);
245 void BranchItem::tmpUnscroll()
247 // Unscroll parent (recursivly)
248 BranchItem * bi=(BranchItem*)parentItem;
249 if (bi) bi->tmpUnscroll();
255 // FIXME-1 systemFlags->activate("tmpUnscrolledright");
260 void BranchItem::resetTmpUnscroll()
262 // Unscroll parent (recursivly)
263 BranchItem * bi=(BranchItem*)parentItem;
264 if (bi) bi->resetTmpUnscroll();
270 // FIXME-1 systemFlags->deactivate("tmpUnscrolledright");
275 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
279 for (int i=0; i<branchCount(); ++i)
281 ti=getBranchNum(i)->findMapItem(p, excludeTI);
282 if (ti != NULL) return ti;
287 if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
290 /* FIXME-2 // Search float images
291 for (int i=0; i<floatimage.size(); ++i )
292 if (floatimage.at(i)->isInClickBox(p) &&
293 (floatimage.at(i) != excludeTI) &&
294 floatimage.at(i)->getParObj()!= excludeTI &&
295 floatimage.at(i)->isVisibleObj()
296 ) return floatimage.at(i)->getTreeItem();
301 TreeItem* BranchItem::findID (QString sid)
305 for (int i=0; i<branchCount(); ++i)
307 ti=getBranchNum(i)->findID (sid);
308 if (ti != NULL) return ti;
312 if (sid==objID) return this;
316 // Search float images
317 for (int i=0; i<floatimage.size(); ++i )
318 if (floatimage.at(i)->inBox(p) &&
319 (floatimage.at(i) != excludeLMO) &&
320 floatimage.at(i)->getParObj()!= excludeLMO &&
321 floatimage.at(i)->isVisibleObj()
322 ) return floatimage.at(i);
328 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
330 return (BranchObj*)lmo;
333 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)
335 // Initialize BranchObj, order of things is important...
336 BranchObj* newbo=new BranchObj(scene);
337 newbo->setParObj(parent()->getLMO() );
338 newbo->setTreeItem (this);
339 newbo->setDefAttr(BranchObj::NewBranch);
342 if (!getHeading().isEmpty() )
344 newbo->updateHeading();
345 newbo->setColor (headingColor);
349 //newbo->updateLink(); //FIXME-3