1 #include "branchitem.h"
10 BranchItem::BranchItem(const QList<QVariant> &data, TreeItem *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
101 // +getIncludeImageAttr()
106 s+=valueElement("heading", getHeading(),
107 attribut ("textColor",QColor( bo->getColor()).name()));
109 // Save frame //FIXME-4 not saved if there is no LMO
110 if (lmo && ((OrnamentedObj*)lmo)->getFrame()->getFrameType()!=FrameObj::NoFrame)
111 s+=((OrnamentedObj*)lmo)->getFrame()->saveToDir ();
113 // save names of flags set
114 s+=standardFlags.saveToDir(tmpdir,prefix,0);
117 for (int i=0; i<imageCount(); ++i)
118 s+=getImageNum(i)->saveToDir (tmpdir,prefix);
121 if (!note.isEmpty() )
126 TreeItem *ti=getBranchNum(i);
129 s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset);
136 QString ol; // old link
137 QString cl; // current link
138 for (int i=0; i<xlink.size(); ++i)
140 cl=xlink.at(i)->saveToDir();
147 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
153 s+=endElement (elementName);
157 void BranchItem::updateVisibility()
159 // Needed to hide relinked branch, if parent is scrolled
161 lmo->setVisibility(!((BranchItem*)parentItem)->isScrolled());
164 void BranchItem::setHeadingColor (QColor color)
166 TreeItem::setHeadingColor (color);
167 if (lmo) ((BranchObj*)lmo)->setColor (color);
170 void BranchItem::unScroll()
172 if (tmpUnscrolled) resetTmpUnscroll();
173 if (scrolled) toggleScroll();
176 bool BranchItem::toggleScroll()
182 systemFlags.deactivate("system-scrolledright");
185 for (int i=0;i<branchCounter;++i)
187 bo=(BranchObj*)(getBranchNum(i)->getLMO());
188 if (bo) bo->setVisibility(true);
194 systemFlags.activate("system-scrolledright");
197 for (int i=0;i<branchCounter;++i)
199 bo=(BranchObj*)(getBranchNum(i)->getLMO());
200 if (bo) bo->setVisibility(false);
204 model->reposition(); // FIXME-3 we don't really want to update view from here...
208 bool BranchItem::isScrolled()
213 bool BranchItem::hasScrolledParent(BranchItem *start)
215 // Calls parents recursivly to
216 // find out, if we are scrolled at all.
217 // But ignore myself, just look at parents.
219 //cout << "BI::hasScrolledParent this="<<this<<" "<<getHeadingStd()<<endl;
220 if (this !=start && scrolled) return true;
222 BranchItem* bi=(BranchItem*)parentItem;
223 if (bi && bi!=rootItem && bi->isBranchLikeType() )
224 return bi->hasScrolledParent(start);
229 void BranchItem::tmpUnscroll()
231 // Unscroll parent (recursivly)
232 BranchItem * pi=(BranchItem*)parentItem;
233 if (pi && pi->isBranchLikeType() ) pi->tmpUnscroll();
239 systemFlags.activate("system-tmpUnscrolledRight");
241 model->emitDataHasChanged (this);
245 void BranchItem::resetTmpUnscroll()
247 // Unscroll parent (recursivly)
248 BranchItem * pi=(BranchItem*)parentItem;
249 if (pi && pi->isBranchLikeType() ) pi->resetTmpUnscroll();
255 systemFlags.deactivate("system-tmpUnscrolledRight");
257 model->emitDataHasChanged (this);
261 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
265 for (int i=0; i<branchCount(); ++i)
267 ti=getBranchNum(i)->findMapItem(p, excludeTI);
268 if (ti != NULL) return ti;
273 if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
278 for (int i=0; i<imageCount(); ++i )
281 LinkableMapObj *mo=ii->getLMO();
282 if (mo && mo->isInClickBox(p) &&
291 TreeItem* BranchItem::findID (QString sid)
295 for (int i=0; i<branchCount(); ++i)
297 ti=getBranchNum(i)->findID (sid);
298 if (ti != NULL) return ti;
302 if (sid==objID) return this;
306 // Search float images
307 for (int i=0; i<floatimage.size(); ++i )
308 if (floatimage.at(i)->inBox(p) &&
309 (floatimage.at(i) != excludeLMO) &&
310 floatimage.at(i)->getParObj()!= excludeLMO &&
311 floatimage.at(i)->isVisibleObj()
312 ) return floatimage.at(i);
317 void BranchItem::updateStyles()
319 // FIXME-5 compare also MapItem::initLMO...
321 if (lmo && parentItem != rootItem)
323 lmo->setParObj ( ((MapItem*)parentItem)->getLMO() );
327 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
329 return (BranchObj*)lmo;
332 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)
335 newbo=new BranchObj(scene);
336 newbo->setTreeItem (this);
339 if (parentItem==rootItem)
341 newbo->setParObj(NULL);
342 newbo->setFrameType (FrameObj::Rectangle);
345 newbo->setParObj( ((MapItem*)parentItem)->getLMO() );
346 // Set visibility depending on parents
347 if (((BranchItem*)parentItem)->scrolled || !((MapItem*)parentItem)->getLMO()->isVisibleObj() )
348 newbo->setVisibility (false);
350 newbo->setDefAttr(BranchObj::NewBranch);
353 if (!getHeading().isEmpty() )
355 newbo->updateData(); //FIXME-3 maybe better model->emitDataHasChanged()?
356 newbo->setColor (headingColor);
359 //newbo->updateLinkGeometry(); //FIXME-3