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"
94 // +getIncludeImageAttr()
99 s+=valueElement("heading", getHeading(),
100 attribut ("textColor",QColor( bo->getColor()).name()));
104 if (frame->getFrameType()!=FrameObj::NoFrame)
105 s+=frame->saveToDir ();
107 // save names of flags set
108 s+=standardFlags->saveToDir(tmpdir,prefix,0);
111 for (int i=0; i<floatimage.size(); ++i)
112 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
116 if (!note.isEmpty() )
121 TreeItem *ti=getBranchNum(i);
124 s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset);
131 QString ol; // old link
132 QString cl; // current link
133 for (int i=0; i<xlink.size(); ++i)
135 cl=xlink.at(i)->saveToDir();
142 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
148 s+=endElement ("branch");
152 void BranchItem::updateVisibility() // FIXME-1
156 void BranchItem::setVymLink(QString s)
160 // We need the relative (from loading)
161 // or absolute path (from User event)
162 // and build the absolute path.
163 // Note: If we have relative, use path of
164 // current map to build absolute path
166 if (!d.path().startsWith ("/"))
168 QString p=model->getDestPath();
169 int i=p.findRev("/",-1);
170 d.setPath(p.left(i)+"/"+s);
174 //FIXME-2 systemFlags->activate("vymLink");
178 //FIXME-2 systemFlags->deactivate("vymLink");
182 calcBBoxSize(); // recalculate bbox
183 positionBBox(); // rearrange contents
188 QString BranchItem::getVymLink()
193 void BranchItem::setHeadingColor (QColor color)
195 TreeItem::setHeadingColor (color);
196 if (lmo) ((BranchObj*)lmo)->setColor (color);
199 void BranchItem::unScroll()
201 if (tmpUnscrolled) resetTmpUnscroll();
202 if (scrolled) toggleScroll();
205 void BranchItem::toggleScroll()
207 BranchItem *bi=getFirstBranch();
213 //FIXME-1 systemFlags->deactivate("scrolledright");
216 bo=(BranchObj*)(bi->getLMO());
217 if (bo) bo->setVisibility(true);
218 bi=getNextBranch(bi);
223 //FIXME-1 systemFlags->activate("scrolledright");
226 bo=(BranchObj*)(bi->getLMO());
227 if (bo) bo->setVisibility(false);
228 bi=getNextBranch(bi);
235 bo->forceReposition();
239 bool BranchItem::isScrolled()
244 bool BranchItem::hasScrolledParent(BranchItem *start)
246 // Calls parents recursivly to
247 // find out, if we are scrolled at all.
248 // But ignore myself, just look at parents.
250 if (this !=start && scrolled) return true;
252 BranchItem* bi=(BranchItem*)parentItem;
254 return bi->hasScrolledParent(start);
259 void BranchItem::tmpUnscroll()
261 // Unscroll parent (recursivly)
262 BranchItem * bi=(BranchItem*)parentItem;
263 if (bi) bi->tmpUnscroll();
269 // FIXME-1 systemFlags->activate("tmpUnscrolledright");
274 void BranchItem::resetTmpUnscroll()
276 // Unscroll parent (recursivly)
277 BranchItem * bi=(BranchItem*)parentItem;
278 if (bi) bi->resetTmpUnscroll();
284 // FIXME-1 systemFlags->deactivate("tmpUnscrolledright");
289 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
293 for (int i=0; i<branchCount(); ++i)
295 ti=getBranchNum(i)->findMapItem(p, excludeTI);
296 if (ti != NULL) return ti;
301 if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
304 /* FIXME-2 // Search float images
305 for (int i=0; i<floatimage.size(); ++i )
306 if (floatimage.at(i)->isInClickBox(p) &&
307 (floatimage.at(i) != excludeTI) &&
308 floatimage.at(i)->getParObj()!= excludeTI &&
309 floatimage.at(i)->isVisibleObj()
310 ) return floatimage.at(i)->getTreeItem();
315 TreeItem* BranchItem::findID (QString sid)
319 for (int i=0; i<branchCount(); ++i)
321 ti=getBranchNum(i)->findID (sid);
322 if (ti != NULL) return ti;
326 if (sid==objID) return this;
330 // Search float images
331 for (int i=0; i<floatimage.size(); ++i )
332 if (floatimage.at(i)->inBox(p) &&
333 (floatimage.at(i) != excludeLMO) &&
334 floatimage.at(i)->getParObj()!= excludeLMO &&
335 floatimage.at(i)->isVisibleObj()
336 ) return floatimage.at(i);
342 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
344 return (BranchObj*)lmo;
347 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)
349 // Initialize BranchObj, order of things is important...
350 BranchObj* newbo=new BranchObj(scene);
352 newbo->setParObj(parent()->getLMO() );
353 newbo->setTreeItem (this);
354 newbo->setDefAttr(BranchObj::NewBranch);
358 if (!getHeading().isEmpty() )
360 newbo->updateHeading();
361 newbo->setColor (headingColor);
365 //newbo->updateLink(); //FIXME-3