Fixed problem with images included in branches. Added missing adaptormodel.* files
1 #include "branchitem.h"
10 BranchItem::BranchItem(const QList<QVariant> &data, TreeItem *parent):MapItem (data,parent)
12 //cout << "Constr. BranchItem\n";
18 includeImagesVer=false;
19 includeImagesHor=false;
22 BranchItem::~BranchItem()
24 cout << "Destr. BranchItem "<<getHeadingStd()<<endl;
32 void BranchItem::copy (BranchItem *other)
34 scrolled=other->scrolled;
35 tmpUnscrolled=other->tmpUnscrolled;
38 void BranchItem::insertBranch (int pos, BranchItem *branch)
41 if (pos>branchCounter) pos=branchCounter;
42 childItems.insert(pos+branchOffset,branch);
43 branch->parentItem=this;
44 branch->setModel (model);
47 branchOffset=childItems.count()-1;
51 QString BranchItem::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset) //FIXME-3 Check if everything is saved...
53 // Cloudy stuff can be hidden during exports
54 if (hidden) return QString();
57 BranchObj *bo=(BranchObj*)lmo;
59 // Update of note is usually done while unselecting a branch
63 scrolledAttr=attribut ("scrolled","yes");
67 // save area, if not scrolled // FIXME-5 not needed if HTML is rewritten...
68 // also we should check if _any_ of parents is scrolled
70 if (lmo && parentItem->isBranchLikeType() && !((BranchItem*)parentItem)->isScrolled() )
72 qreal x=lmo->getAbsPos().x();
73 qreal y=lmo->getAbsPos().y();
75 attribut("x1",QString().setNum(x-offset.x())) +
76 attribut("y1",QString().setNum(y-offset.y())) +
77 attribut("x2",QString().setNum(x+lmo->width()-offset.x())) +
78 attribut("y2",QString().setNum(y+lmo->height()-offset.y()));
84 // FIXME-3 Providing an ID for a branch makes export to XHTML easier
87 idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
93 if (parentItem==rootItem)
94 elementName="mapcenter";
98 s=beginElement (elementName
104 +getIncludeImageAttr()
109 s+=valueElement("heading", getHeading(),
110 attribut ("textColor",QColor( bo->getColor()).name()));
112 // Save frame //FIXME-4 not saved if there is no LMO
113 if (lmo && ((OrnamentedObj*)lmo)->getFrame()->getFrameType()!=FrameObj::NoFrame)
114 s+=((OrnamentedObj*)lmo)->getFrame()->saveToDir ();
116 // save names of flags set
117 s+=standardFlags.saveToDir(tmpdir,prefix,0);
120 for (int i=0; i<imageCount(); ++i)
121 s+=getImageNum(i)->saveToDir (tmpdir,prefix);
124 if (!note.isEmpty() )
129 TreeItem *ti=getBranchNum(i);
132 s+=getBranchNum(i)->saveToDir(tmpdir,prefix,offset);
139 QString ol; // old link
140 QString cl; // current link
141 for (int i=0; i<xlink.size(); ++i)
143 cl=xlink.at(i)->saveToDir();
150 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
156 s+=endElement (elementName);
160 void BranchItem::updateVisibility()
162 // Needed to hide relinked branch, if parent is scrolled
164 lmo->setVisibility(!((BranchItem*)parentItem)->isScrolled());
167 void BranchItem::setHeadingColor (QColor color)
169 TreeItem::setHeadingColor (color);
170 if (lmo) ((BranchObj*)lmo)->setColor (color);
173 void BranchItem::unScroll()
175 if (tmpUnscrolled) resetTmpUnscroll();
176 if (scrolled) toggleScroll();
179 bool BranchItem::toggleScroll()
185 systemFlags.deactivate("system-scrolledright");
188 for (int i=0;i<branchCounter;++i)
190 bo=(BranchObj*)(getBranchNum(i)->getLMO());
191 if (bo) bo->setVisibility(true);
197 systemFlags.activate("system-scrolledright");
200 for (int i=0;i<branchCounter;++i)
202 bo=(BranchObj*)(getBranchNum(i)->getLMO());
203 if (bo) bo->setVisibility(false);
207 model->reposition(); // FIXME-3 we don't really want to update view from here...
211 bool BranchItem::isScrolled()
216 bool BranchItem::hasScrolledParent(BranchItem *start)
218 // Calls parents recursivly to
219 // find out, if we are scrolled at all.
220 // But ignore myself, just look at parents.
222 //cout << "BI::hasScrolledParent this="<<this<<" "<<getHeadingStd()<<endl;
223 if (this !=start && scrolled) return true;
225 BranchItem* bi=(BranchItem*)parentItem;
226 if (bi && bi!=rootItem && bi->isBranchLikeType() )
227 return bi->hasScrolledParent(start);
232 void BranchItem::tmpUnscroll()
234 // Unscroll parent (recursivly)
235 BranchItem * pi=(BranchItem*)parentItem;
236 if (pi && pi->isBranchLikeType() ) pi->tmpUnscroll();
242 systemFlags.activate("system-tmpUnscrolledRight");
244 model->emitDataHasChanged (this);
248 void BranchItem::resetTmpUnscroll()
250 // Unscroll parent (recursivly)
251 BranchItem * pi=(BranchItem*)parentItem;
252 if (pi && pi->isBranchLikeType() ) pi->resetTmpUnscroll();
258 systemFlags.deactivate("system-tmpUnscrolledRight");
260 model->emitDataHasChanged (this);
264 void BranchItem::setIncludeImagesVer(bool b)
267 /* calcBBoxSize(); FIXME-2
273 bool BranchItem::getIncludeImagesVer()
275 return includeImagesVer;
278 void BranchItem::setIncludeImagesHor(bool b)
281 /* calcBBoxSize(); FIXME-2
287 bool BranchItem::getIncludeImagesHor()
289 return includeImagesHor;
292 QString BranchItem::getIncludeImageAttr()
295 if (includeImagesVer)
296 a=attribut ("incImgV","true");
297 if (includeImagesHor)
298 a+=attribut ("incImgH","true");
304 TreeItem* BranchItem::findMapItem (QPointF p, TreeItem* excludeTI)
308 for (int i=0; i<branchCount(); ++i)
310 ti=getBranchNum(i)->findMapItem(p, excludeTI);
311 if (ti != NULL) return ti;
316 if (getBranchObj()->isInClickBox (p) && (this != excludeTI) && getBranchObj()->isVisibleObj() )
321 for (int i=0; i<imageCount(); ++i )
324 LinkableMapObj *mo=ii->getLMO();
325 if (mo && mo->isInClickBox(p) &&
334 TreeItem* BranchItem::findID (QString sid)
338 for (int i=0; i<branchCount(); ++i)
340 ti=getBranchNum(i)->findID (sid);
341 if (ti != NULL) return ti;
345 if (sid==objID) return this;
349 // Search float images //FIXME-4
350 for (int i=0; i<floatimage.size(); ++i )
351 if (floatimage.at(i)->inBox(p) &&
352 (floatimage.at(i) != excludeLMO) &&
353 floatimage.at(i)->getParObj()!= excludeLMO &&
354 floatimage.at(i)->isVisibleObj()
355 ) return floatimage.at(i);
360 void BranchItem::updateStyles()
362 // FIXME-5 compare also MapItem::initLMO...
364 if (lmo && parentItem != rootItem)
366 lmo->setParObj ( ((MapItem*)parentItem)->getLMO() );
370 BranchObj* BranchItem::getBranchObj() // FIXME-3 only for transition BO->BI
372 return (BranchObj*)lmo;
375 BranchObj* BranchItem::createMapObj(QGraphicsScene *scene)
378 newbo=new BranchObj(scene);
379 newbo->setTreeItem (this);
382 if (parentItem==rootItem)
384 newbo->setParObj(NULL);
385 newbo->setFrameType (FrameObj::Rectangle);
388 newbo->setParObj( ((MapItem*)parentItem)->getLMO() );
389 // Set visibility depending on parents
390 if (((BranchItem*)parentItem)->scrolled || !((MapItem*)parentItem)->getLMO()->isVisibleObj() )
391 newbo->setVisibility (false);
393 newbo->setDefAttr(BranchObj::NewBranch);
396 if (!getHeading().isEmpty() )
398 newbo->updateData(); //FIXME-3 maybe better model->emitDataHasChanged()?
399 newbo->setColor (headingColor);
402 //newbo->updateLinkGeometry(); //FIXME-3