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() // FIXME-3 Check if this is needed after all...
161 void BranchItem::setHeadingColor (QColor color)
163 TreeItem::setHeadingColor (color);
164 if (lmo) ((BranchObj*)lmo)->setColor (color);
167 void BranchItem::unScroll()
169 if (tmpUnscrolled) resetTmpUnscroll();
170 if (scrolled) toggleScroll();
173 bool BranchItem::toggleScroll()
179 systemFlags.deactivate("system-scrolledright");
182 for (int i=0;i<branchCounter;++i)
184 bo=(BranchObj*)(getBranchNum(i)->getLMO());
185 if (bo) bo->setVisibility(true);
191 systemFlags.activate("system-scrolledright");
194 for (int i=0;i<branchCounter;++i)
196 bo=(BranchObj*)(getBranchNum(i)->getLMO());
197 if (bo) bo->setVisibility(false);
201 model->reposition(); // FIXME-3 we don't really want to update view from here...
205 bool BranchItem::isScrolled()
210 bool BranchItem::hasScrolledParent(BranchItem *start)
212 // Calls parents recursivly to
213 // find out, if we are scrolled at all.
214 // But ignore myself, just look at parents.
216 //cout << "BI::hasScrolledParent this="<<this<<" "<<getHeadingStd()<<endl;
217 if (this !=start && scrolled) return true;
219 BranchItem* bi=(BranchItem*)parentItem;
220 if (bi && bi!=rootItem && bi->isBranchLikeType() )
221 return bi->hasScrolledParent(start);
226 void BranchItem::tmpUnscroll()
228 // Unscroll parent (recursivly)
229 BranchItem * pi=(BranchItem*)parentItem;
230 if (pi && pi->isBranchLikeType() ) pi->tmpUnscroll();
236 systemFlags.activate("system-tmpUnscrolledRight");
238 model->emitDataHasChanged (this);
242 void BranchItem::resetTmpUnscroll()
244 // Unscroll parent (recursivly)
245 BranchItem * pi=(BranchItem*)parentItem;
246 if (pi && pi->isBranchLikeType() ) pi->resetTmpUnscroll();
252 systemFlags.deactivate("system-tmpUnscrolledRight");
254 model->emitDataHasChanged (this);
258 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
262 for (int i=0; i<branchCount(); ++i)
264 ti=getBranchNum(i)->findMapItem(p, excludeTI);
265 if (ti != NULL) return ti;
270 if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
275 for (int i=0; i<imageCount(); ++i )
278 LinkableMapObj *mo=ii->getLMO();
279 if (mo && mo->isInClickBox(p) &&
288 TreeItem* BranchItem::findID (QString sid)
292 for (int i=0; i<branchCount(); ++i)
294 ti=getBranchNum(i)->findID (sid);
295 if (ti != NULL) return ti;
299 if (sid==objID) return this;
303 // Search float images
304 for (int i=0; i<floatimage.size(); ++i )
305 if (floatimage.at(i)->inBox(p) &&
306 (floatimage.at(i) != excludeLMO) &&
307 floatimage.at(i)->getParObj()!= excludeLMO &&
308 floatimage.at(i)->isVisibleObj()
309 ) return floatimage.at(i);
314 void BranchItem::updateStyles()
316 // FIXME-5 compare also MapItem::initLMO...
318 if (lmo && parentItem != rootItem)
320 lmo->setParObj ( ((MapItem*)parentItem)->getLMO() );
324 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
326 return (BranchObj*)lmo;
329 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)
332 newbo=new BranchObj(scene);
333 newbo->setTreeItem (this);
336 if (parentItem==rootItem)
338 newbo->setParObj(NULL);
339 newbo->setFrameType (FrameObj::Rectangle);
342 newbo->setParObj( ((MapItem*)parentItem)->getLMO() );
343 // Set visibility depending on parents
344 if (((BranchItem*)parentItem)->scrolled || !((MapItem*)parentItem)->getLMO()->isVisibleObj() )
345 newbo->setVisibility (false);
347 newbo->setDefAttr(BranchObj::NewBranch);
350 if (!getHeading().isEmpty() )
352 newbo->updateData(); //FIXME-3 maybe better model->emitDataHasChanged()?
353 newbo->setColor (headingColor);
356 //newbo->updateLinkGeometry(); //FIXME-3