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-3 Check if everything is saved...
50 // Cloudy stuff can be hidden during exports
51 if (hidden) return QString();
54 BranchObj *bo=(BranchObj*)lmo;
56 // Update of note is usually done while unselecting a branch
60 scrolledAttr=attribut ("scrolled","yes");
64 // save area, if not scrolled // FIXME-5 not needed if HTML is rewritten...
65 // also we should check if _any_ of parents is scrolled
67 if (lmo && parentItem->isBranchLikeType() && !((BranchItem*)parentItem)->isScrolled() )
69 qreal x=lmo->getAbsPos().x();
70 qreal y=lmo->getAbsPos().y();
72 attribut("x1",QString().setNum(x-offset.x())) +
73 attribut("y1",QString().setNum(y-offset.y())) +
74 attribut("x2",QString().setNum(x+lmo->width()-offset.x())) +
75 attribut("y2",QString().setNum(y+lmo->height()-offset.y()));
81 // FIXME-3 Providing an ID for a branch makes export to XHTML easier
84 idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
90 if (parentItem==rootItem)
91 elementName="mapcenter";
95 s=beginElement (elementName
101 // +getIncludeImageAttr()
106 s+=valueElement("heading", getHeading(),
107 attribut ("textColor",QColor( bo->getColor()).name()));
110 // Save frame //FIXME-2
111 if (frame->getFrameType()!=FrameObj::NoFrame)
112 s+=frame->saveToDir ();
115 // save names of flags set
116 s+=standardFlags.saveToDir(tmpdir,prefix,0);
120 for (int i=0; i<floatimage.size(); ++i)
121 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
125 if (!note.isEmpty() )
130 TreeItem *ti=getBranchNum(i);
133 s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset);
140 QString ol; // old link
141 QString cl; // current link
142 for (int i=0; i<xlink.size(); ++i)
144 cl=xlink.at(i)->saveToDir();
151 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
157 s+=endElement (elementName);
161 void BranchItem::updateVisibility() // FIXME-3 Check if this is needed after all...
165 void BranchItem::setVymLink(QString s)
169 // We need the relative (from loading)
170 // or absolute path (from User event)
171 // and build the absolute path.
172 // Note: If we have relative, use path of
173 // current map to build absolute path
175 if (!d.path().startsWith ("/"))
177 QString p=model->getDestPath();
178 int i=p.findRev("/",-1);
179 d.setPath(p.left(i)+"/"+s);
183 //FIXME-2 systemFlags->activate("vymLink");
187 //FIXME-2 systemFlags->deactivate("vymLink");
191 calcBBoxSize(); // recalculate bbox
192 positionBBox(); // rearrange contents
197 QString BranchItem::getVymLink()
202 void BranchItem::setHeadingColor (QColor color)
204 TreeItem::setHeadingColor (color);
205 if (lmo) ((BranchObj*)lmo)->setColor (color);
208 void BranchItem::unScroll()
210 if (tmpUnscrolled) resetTmpUnscroll();
211 if (scrolled) toggleScroll();
214 bool BranchItem::toggleScroll()
220 systemFlags.deactivate("system-scrolledright");
223 for (int i=0;i<branchCounter;++i)
225 bo=(BranchObj*)(getBranchNum(i)->getLMO());
226 if (bo) bo->setVisibility(true);
232 systemFlags.activate("system-scrolledright");
235 for (int i=0;i<branchCounter;++i)
237 bo=(BranchObj*)(getBranchNum(i)->getLMO());
238 if (bo) bo->setVisibility(false);
242 model->reposition(); // FIXME-3 we don't really want to update view from here...
246 bool BranchItem::isScrolled()
251 bool BranchItem::hasScrolledParent(BranchItem *start)
253 // Calls parents recursivly to
254 // find out, if we are scrolled at all.
255 // But ignore myself, just look at parents.
257 if (this !=start && scrolled) return true;
259 BranchItem* bi=(BranchItem*)parentItem;
260 if (bi && bi->isBranchLikeType() )
261 return bi->hasScrolledParent(start);
266 void BranchItem::tmpUnscroll()
268 // Unscroll parent (recursivly)
269 BranchItem * pi=(BranchItem*)parentItem;
270 if (pi && pi->isBranchLikeType() ) pi->tmpUnscroll();
276 systemFlags.activate("system-tmpUnscrolledRight");
278 model->emitDataHasChanged (this);
282 void BranchItem::resetTmpUnscroll()
284 // Unscroll parent (recursivly)
285 BranchItem * pi=(BranchItem*)parentItem;
286 if (pi && pi->isBranchLikeType() ) pi->resetTmpUnscroll();
292 systemFlags.deactivate("system-tmpUnscrolledRight");
294 model->emitDataHasChanged (this);
298 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
302 for (int i=0; i<branchCount(); ++i)
304 ti=getBranchNum(i)->findMapItem(p, excludeTI);
305 if (ti != NULL) return ti;
310 if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
313 /* FIXME-2 // Search float images
314 for (int i=0; i<floatimage.size(); ++i )
315 if (floatimage.at(i)->isInClickBox(p) &&
316 (floatimage.at(i) != excludeTI) &&
317 floatimage.at(i)->getParObj()!= excludeTI &&
318 floatimage.at(i)->isVisibleObj()
319 ) return floatimage.at(i)->getTreeItem();
324 TreeItem* BranchItem::findID (QString sid)
328 for (int i=0; i<branchCount(); ++i)
330 ti=getBranchNum(i)->findID (sid);
331 if (ti != NULL) return ti;
335 if (sid==objID) return this;
339 // Search float images
340 for (int i=0; i<floatimage.size(); ++i )
341 if (floatimage.at(i)->inBox(p) &&
342 (floatimage.at(i) != excludeLMO) &&
343 floatimage.at(i)->getParObj()!= excludeLMO &&
344 floatimage.at(i)->isVisibleObj()
345 ) return floatimage.at(i);
350 void BranchItem::updateStyles()
352 // FIXME-5 compare also MapItem::initLMO...
356 lmo->setParObj (parentItem->getLMO() );
360 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
362 return (BranchObj*)lmo;
365 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)
368 newbo=new BranchObj(scene);
369 newbo->setTreeItem (this);
372 if (parentItem==rootItem)
374 newbo->setParObj(NULL);
375 newbo->setFrameType (FrameObj::Rectangle);
378 newbo->setParObj(parentItem->getLMO() );
379 // Set visibility depending on parents
380 if (((BranchItem*)parentItem)->scrolled || !parentItem->getLMO()->isVisibleObj() )
381 newbo->setVisibility (false);
383 newbo->setDefAttr(BranchObj::NewBranch);
386 if (!getHeading().isEmpty() )
388 newbo->updateData(); //FIXME-3 maybe better model->emitDataHasChanged()?
389 newbo->setColor (headingColor);
392 //newbo->updateLink(); //FIXME-3