1 #include "branchitem.h"
10 BranchItem::BranchItem(const QList<QVariant> &data, MapItem *parent):MapItem (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
100 // +getIncludeImageAttr()
105 s+=valueElement("heading", getHeading(),
106 attribut ("textColor",QColor( bo->getColor()).name()));
109 // Save frame //FIXME-2
110 if (frame->getFrameType()!=FrameObj::NoFrame)
111 s+=frame->saveToDir ();
114 // save names of flags set
115 s+=standardFlags.saveToDir(tmpdir,prefix,0);
118 for (int i=0; i<imageCount(); ++i)
119 s+=getImageNum(i)->saveToDir (tmpdir,prefix);
122 if (!note.isEmpty() )
127 TreeItem *ti=getBranchNum(i);
130 s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset);
137 QString ol; // old link
138 QString cl; // current link
139 for (int i=0; i<xlink.size(); ++i)
141 cl=xlink.at(i)->saveToDir();
148 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
154 s+=endElement (elementName);
158 void BranchItem::updateVisibility() // FIXME-3 Check if this is needed after all...
162 void BranchItem::setVymLink(QString s)
166 // We need the relative (from loading)
167 // or absolute path (from User event)
168 // and build the absolute path.
169 // Note: If we have relative, use path of
170 // current map to build absolute path
172 if (!d.path().startsWith ("/"))
174 QString p=model->getDestPath();
175 int i=p.findRev("/",-1);
176 d.setPath(p.left(i)+"/"+s);
180 //FIXME-2 systemFlags->activate("vymLink");
184 //FIXME-2 systemFlags->deactivate("vymLink");
188 calcBBoxSize(); // recalculate bbox
189 positionBBox(); // rearrange contents
194 QString BranchItem::getVymLink()
199 void BranchItem::setHeadingColor (QColor color)
201 TreeItem::setHeadingColor (color);
202 if (lmo) ((BranchObj*)lmo)->setColor (color);
205 void BranchItem::unScroll()
207 if (tmpUnscrolled) resetTmpUnscroll();
208 if (scrolled) toggleScroll();
211 bool BranchItem::toggleScroll()
217 systemFlags.deactivate("system-scrolledright");
220 for (int i=0;i<branchCounter;++i)
222 bo=(BranchObj*)(getBranchNum(i)->getLMO());
223 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);
239 model->reposition(); // FIXME-3 we don't really want to update view from here...
243 bool BranchItem::isScrolled()
248 bool BranchItem::hasScrolledParent(BranchItem *start)
250 // Calls parents recursivly to
251 // find out, if we are scrolled at all.
252 // But ignore myself, just look at parents.
254 if (this !=start && scrolled) return true;
256 BranchItem* bi=(BranchItem*)parentItem;
257 if (bi && bi->isBranchLikeType() )
258 return bi->hasScrolledParent(start);
263 void BranchItem::tmpUnscroll()
265 // Unscroll parent (recursivly)
266 BranchItem * pi=(BranchItem*)parentItem;
267 if (pi && pi->isBranchLikeType() ) pi->tmpUnscroll();
273 systemFlags.activate("system-tmpUnscrolledRight");
275 model->emitDataHasChanged (this);
279 void BranchItem::resetTmpUnscroll()
281 // Unscroll parent (recursivly)
282 BranchItem * pi=(BranchItem*)parentItem;
283 if (pi && pi->isBranchLikeType() ) pi->resetTmpUnscroll();
289 systemFlags.deactivate("system-tmpUnscrolledRight");
291 model->emitDataHasChanged (this);
295 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
299 for (int i=0; i<branchCount(); ++i)
301 ti=getBranchNum(i)->findMapItem(p, excludeTI);
302 if (ti != NULL) return ti;
307 if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
312 for (int i=0; i<imageCount(); ++i )
315 LinkableMapObj *mo=ii->getLMO();
316 if (mo && mo->isInClickBox(p) &&
325 TreeItem* BranchItem::findID (QString sid)
329 for (int i=0; i<branchCount(); ++i)
331 ti=getBranchNum(i)->findID (sid);
332 if (ti != NULL) return ti;
336 if (sid==objID) return this;
340 // Search float images
341 for (int i=0; i<floatimage.size(); ++i )
342 if (floatimage.at(i)->inBox(p) &&
343 (floatimage.at(i) != excludeLMO) &&
344 floatimage.at(i)->getParObj()!= excludeLMO &&
345 floatimage.at(i)->isVisibleObj()
346 ) return floatimage.at(i);
351 void BranchItem::updateStyles()
353 // FIXME-5 compare also MapItem::initLMO...
357 lmo->setParObj ( ((MapItem*)parentItem)->getLMO() );
361 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
363 return (BranchObj*)lmo;
366 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)
369 newbo=new BranchObj(scene);
370 newbo->setTreeItem (this);
373 if (parentItem==rootItem)
375 newbo->setParObj(NULL);
376 newbo->setFrameType (FrameObj::Rectangle);
379 newbo->setParObj( ((MapItem*)parentItem)->getLMO() );
380 // Set visibility depending on parents
381 if (((BranchItem*)parentItem)->scrolled || !((MapItem*)parentItem)->getLMO()->isVisibleObj() )
382 newbo->setVisibility (false);
384 newbo->setDefAttr(BranchObj::NewBranch);
387 if (!getHeading().isEmpty() )
389 newbo->updateData(); //FIXME-3 maybe better model->emitDataHasChanged()?
390 newbo->setColor (headingColor);
393 //newbo->updateLink(); //FIXME-3