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;
57 // Update of note is usually done while unselecting a branch
58 // if (isNoteInEditor) getNoteFromTextEditor(); // FIXME-0 check that this still works...
62 scrolledAttr=attribut ("scrolled","yes");
67 // save area, if not scrolled // FIXME-3 not needed if HTML is rewritten...
68 // also we should check if _any_ of parents is scrolled
70 if (!((BranchObj*)(parObj))->isScrolled() )
73 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
74 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
75 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
76 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
81 // Providing an ID for a branch makes export to XHTML easier
84 idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
89 s=beginElement ("branch"
95 // +getIncludeImageAttr()
100 s+=valueElement("heading", getHeading(),
101 attribut ("textColor",QColor( bo->getColor()).name()));
105 if (frame->getFrameType()!=FrameObj::NoFrame)
106 s+=frame->saveToDir ();
109 // save names of flags set
110 s+=standardFlags.saveToDir(tmpdir,prefix,0);
114 for (int i=0; i<floatimage.size(); ++i)
115 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
119 if (!note.isEmpty() )
124 TreeItem *ti=getBranchNum(i);
127 s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset);
134 QString ol; // old link
135 QString cl; // current link
136 for (int i=0; i<xlink.size(); ++i)
138 cl=xlink.at(i)->saveToDir();
145 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
151 s+=endElement ("branch");
155 void BranchItem::updateVisibility() // FIXME-1
159 void BranchItem::setVymLink(QString s)
163 // We need the relative (from loading)
164 // or absolute path (from User event)
165 // and build the absolute path.
166 // Note: If we have relative, use path of
167 // current map to build absolute path
169 if (!d.path().startsWith ("/"))
171 QString p=model->getDestPath();
172 int i=p.findRev("/",-1);
173 d.setPath(p.left(i)+"/"+s);
177 //FIXME-2 systemFlags->activate("vymLink");
181 //FIXME-2 systemFlags->deactivate("vymLink");
185 calcBBoxSize(); // recalculate bbox
186 positionBBox(); // rearrange contents
191 QString BranchItem::getVymLink()
196 void BranchItem::setHeadingColor (QColor color)
198 TreeItem::setHeadingColor (color);
199 if (lmo) ((BranchObj*)lmo)->setColor (color);
202 void BranchItem::unScroll()
204 if (tmpUnscrolled) resetTmpUnscroll();
205 if (scrolled) toggleScroll();
208 bool BranchItem::toggleScroll()
211 if (!branchCount()>0) return false;
216 systemFlags.deactivate("system-scrolledright");
219 for (int i=0;i<branchCounter;++i)
221 bo=(BranchObj*)(getBranchNum(i)->getLMO());
222 if (bo) bo->setVisibility(true);
229 systemFlags.activate("system-scrolledright");
232 for (int i=0;i<branchCounter;++i)
234 bo=(BranchObj*)(getBranchNum(i)->getLMO());
235 if (bo) bo->setVisibility(false);
242 bool BranchItem::isScrolled()
247 bool BranchItem::hasScrolledParent(BranchItem *start)
249 // Calls parents recursivly to
250 // find out, if we are scrolled at all.
251 // But ignore myself, just look at parents.
253 if (this !=start && scrolled) return true;
255 BranchItem* bi=(BranchItem*)parentItem;
257 return bi->hasScrolledParent(start);
262 void BranchItem::tmpUnscroll()
264 // Unscroll parent (recursivly)
265 BranchItem * bi=(BranchItem*)parentItem;
266 if (bi) bi->tmpUnscroll();
272 // FIXME-1 systemFlags->activate("tmpUnscrolledright");
277 void BranchItem::resetTmpUnscroll()
279 // Unscroll parent (recursivly)
280 BranchItem * bi=(BranchItem*)parentItem;
281 if (bi) bi->resetTmpUnscroll();
287 // FIXME-1 systemFlags->deactivate("tmpUnscrolledright");
292 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
296 for (int i=0; i<branchCount(); ++i)
298 ti=getBranchNum(i)->findMapItem(p, excludeTI);
299 if (ti != NULL) return ti;
304 if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
307 /* FIXME-2 // Search float images
308 for (int i=0; i<floatimage.size(); ++i )
309 if (floatimage.at(i)->isInClickBox(p) &&
310 (floatimage.at(i) != excludeTI) &&
311 floatimage.at(i)->getParObj()!= excludeTI &&
312 floatimage.at(i)->isVisibleObj()
313 ) return floatimage.at(i)->getTreeItem();
318 TreeItem* BranchItem::findID (QString sid)
322 for (int i=0; i<branchCount(); ++i)
324 ti=getBranchNum(i)->findID (sid);
325 if (ti != NULL) return ti;
329 if (sid==objID) return this;
333 // Search float images
334 for (int i=0; i<floatimage.size(); ++i )
335 if (floatimage.at(i)->inBox(p) &&
336 (floatimage.at(i) != excludeLMO) &&
337 floatimage.at(i)->getParObj()!= excludeLMO &&
338 floatimage.at(i)->isVisibleObj()
339 ) return floatimage.at(i);
345 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
347 return (BranchObj*)lmo;
350 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)
352 // Initialize BranchObj, order of things is important...
353 BranchObj* newbo=new BranchObj(scene);
355 newbo->setParObj(parent()->getLMO() );
356 newbo->setTreeItem (this);
357 newbo->setDefAttr(BranchObj::NewBranch);
361 if (!getHeading().isEmpty() )
363 newbo->updateData(); //FIXME-3 maybe better model->emitDataHasChanged()?
364 newbo->setColor (headingColor);
368 //newbo->updateLink(); //FIXME-3