1 #include "branchitem.h"
11 BranchItem::BranchItem(const QList<QVariant> &data, TreeItem *parent):MapItem (data,parent)
13 //cout << "Constr. BranchItem\n";
23 includeImagesVer=false;
24 includeImagesHor=false;
26 lastSelectedBranchNum=-1;
27 lastSelectedBranchNumAlt=-1;
30 BranchItem::~BranchItem()
32 //cout << "Destr. BranchItem "<<getHeadingStd()<<endl;
40 void BranchItem::copy (BranchItem *other)
42 scrolled=other->scrolled;
43 tmpUnscrolled=other->tmpUnscrolled;
46 void BranchItem::insertBranch (int pos, BranchItem *branch)
49 if (pos>branchCounter) pos=branchCounter;
50 childItems.insert(pos+branchOffset,branch);
51 branch->parentItem=this;
52 branch->setModel (model);
55 branchOffset=childItems.count()-1;
59 QString BranchItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset) //FIXME-3 Check if everything is saved...
61 // Cloudy stuff can be hidden during exports
62 if (hidden) return QString();
65 BranchObj *bo=(BranchObj*)lmo;
67 // Update of note is usually done while unselecting a branch
71 scrolledAttr=attribut ("scrolled","yes");
75 // save area, if not scrolled // FIXME-5 not needed if HTML is rewritten...
76 // also we should check if _any_ of parents is scrolled
78 if (lmo && parentItem->isBranchLikeType() && !((BranchItem*)parentItem)->isScrolled() )
80 qreal x=lmo->getAbsPos().x();
81 qreal y=lmo->getAbsPos().y();
83 attribut("x1",QString().setNum(x-offset.x())) +
84 attribut("y1",QString().setNum(y-offset.y())) +
85 attribut("x2",QString().setNum(x+lmo->width()-offset.x())) +
86 attribut("y2",QString().setNum(y+lmo->height()-offset.y()));
91 // Provide an ID for a branch makes export to XHTML easier
94 idAttr=attribut ("id",model->getSelectString(this));
99 if (parentItem==rootItem)
100 elementName="mapcenter";
102 elementName="branch";
104 s=beginElement (elementName
108 // +areaAttr // FIXME-2
110 +getIncludeImageAttr()
115 s+=valueElement("heading", getHeading(),
116 attribut ("textColor",QColor( bo->getColor()).name()));
118 // Save frame //FIXME-4 not saved if there is no LMO
119 if (lmo && ((OrnamentedObj*)lmo)->getFrame()->getFrameType()!=FrameObj::NoFrame)
120 s+=((OrnamentedObj*)lmo)->getFrame()->saveToDir ();
122 // save names of flags set
123 s+=standardFlags.saveToDir(tmpdir,prefix,0);
126 for (int i=0; i<imageCount(); ++i)
127 s+=getImageNum(i)->saveToDir (tmpdir,prefix);
130 if (!note.isEmpty() )
135 TreeItem *ti=getBranchNum(i);
138 s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset);
144 QString ol; // old link
145 QString cl; // current link
146 for (int i=0; i<xlinkCount(); ++i)
148 cl=getXLinkNum(i)->saveToDir();
155 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
160 s+=endElement (elementName);
164 void BranchItem::updateVisibility()
166 // Needed to hide relinked branch, if parent is scrolled
168 lmo->setVisibility(!((BranchItem*)parentItem)->isScrolled());
171 void BranchItem::setHeadingColor (QColor color)
173 TreeItem::setHeadingColor (color);
174 if (lmo) ((BranchObj*)lmo)->setColor (color);
177 void BranchItem::unScroll()
179 if (tmpUnscrolled) resetTmpUnscroll();
180 if (scrolled) toggleScroll();
183 bool BranchItem::toggleScroll()
189 systemFlags.deactivate("system-scrolledright");
192 for (int i=0;i<branchCounter;++i)
194 bo=(BranchObj*)(getBranchNum(i)->getLMO());
195 if (bo) bo->setVisibility(true);
201 systemFlags.activate("system-scrolledright");
204 for (int i=0;i<branchCounter;++i)
206 bo=(BranchObj*)(getBranchNum(i)->getLMO());
207 if (bo) bo->setVisibility(false);
211 model->reposition(); // FIXME-3 we don't really want to update view from here...
215 bool BranchItem::isScrolled()
220 bool BranchItem::hasScrolledParent(BranchItem *start)
222 // Calls parents recursivly to
223 // find out, if we are scrolled at all.
224 // But ignore myself, just look at parents.
226 //cout << "BI::hasScrolledParent this="<<this<<" "<<getHeadingStd()<<endl;
227 if (this !=start && scrolled) return true;
229 BranchItem* bi=(BranchItem*)parentItem;
230 if (bi && bi!=rootItem && bi->isBranchLikeType() )
231 return bi->hasScrolledParent(start);
236 void BranchItem::tmpUnscroll()
238 // Unscroll parent (recursivly)
239 BranchItem * pi=(BranchItem*)parentItem;
240 if (pi && pi->isBranchLikeType() ) pi->tmpUnscroll();
246 systemFlags.activate("system-tmpUnscrolledRight");
248 model->emitDataHasChanged (this);
252 void BranchItem::resetTmpUnscroll()
254 // Unscroll parent (recursivly)
255 BranchItem * pi=(BranchItem*)parentItem;
256 if (pi && pi->isBranchLikeType() ) pi->resetTmpUnscroll();
262 systemFlags.deactivate("system-tmpUnscrolledRight");
264 model->emitDataHasChanged (this);
268 void BranchItem::setIncludeImagesVer(bool b)
271 /* calcBBoxSize(); FIXME-2
277 bool BranchItem::getIncludeImagesVer()
279 return includeImagesVer;
282 void BranchItem::setIncludeImagesHor(bool b)
285 /* calcBBoxSize(); FIXME-2
291 bool BranchItem::getIncludeImagesHor()
293 return includeImagesHor;
296 QString BranchItem::getIncludeImageAttr()
299 if (includeImagesVer)
300 a=attribut ("incImgV","true");
301 if (includeImagesHor)
302 a+=attribut ("incImgH","true");
306 void BranchItem::setLastSelectedBranch()
312 // Hack to save an additional lastSelected for mapcenters in MapEditor
313 // depending on orientation
314 // this allows to go both left and right from there
315 if (lmo && lmo->getOrientation()==LinkableMapObj::LeftOfCenter)
317 ((BranchItem*)parentItem)->lastSelectedBranchNumAlt=parentItem->num(this);
320 ((BranchItem*)parentItem)->lastSelectedBranchNum=parentItem->num(this);
324 void BranchItem::setLastSelectedBranch(int i)
326 lastSelectedBranchNum=i;
329 BranchItem* BranchItem::getLastSelectedBranch()
331 return getBranchNum (lastSelectedBranchNum);
334 BranchItem* BranchItem::getLastSelectedBranchAlt()
336 return getBranchNum (lastSelectedBranchNumAlt);
343 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
347 for (int i=0; i<branchCount(); ++i)
349 ti=getBranchNum(i)->findMapItem(p, excludeTI);
350 if (ti != NULL) return ti;
355 if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
360 for (int i=0; i<imageCount(); ++i )
363 LinkableMapObj *mo=ii->getLMO();
364 if (mo && mo->isInClickBox(p) &&
373 TreeItem* BranchItem::findID (QString sid) //FIXME-3 move to TreeItem //FIXME-4 search images
377 for (int i=0; i<branchCount(); ++i)
379 ti=getBranchNum(i)->findID (sid);
380 if (ti != NULL) return ti;
384 if (sid==objID) return this;
388 // Search float images
389 for (int i=0; i<floatimage.size(); ++i )
390 if (floatimage.at(i)->inBox(p) &&
391 (floatimage.at(i) != excludeLMO) &&
392 floatimage.at(i)->getParObj()!= excludeLMO &&
393 floatimage.at(i)->isVisibleObj()
394 ) return floatimage.at(i);
399 void BranchItem::updateStyles()
401 // FIXME-5 compare also MapItem::initLMO...
403 if (lmo && parentItem != rootItem)
405 lmo->setParObj ( ((MapItem*)parentItem)->getLMO() );
409 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
411 return (BranchObj*)lmo;
414 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene) // FIXME-4 maybe move this into MapEditor to get rid of scene in VymModel?
417 newbo=new BranchObj(scene,this);
420 if (parentItem==rootItem)
422 newbo->setParObj(NULL);
423 newbo->setFrameType (FrameObj::Rectangle);
426 newbo->setParObj( ((MapItem*)parentItem)->getLMO() );
427 // Set visibility depending on parents
428 if (((BranchItem*)parentItem)->scrolled || !((MapItem*)parentItem)->getLMO()->isVisibleObj() )
429 newbo->setVisibility (false);
431 newbo->setDefAttr(BranchObj::NewBranch);
434 if (!getHeading().isEmpty() )
436 newbo->updateData(); //FIXME-3 maybe better model->emitDataHasChanged()?
437 newbo->setColor (headingColor);
440 //newbo->updateLinkGeometry(); //FIXME-3