Fixed problem with images included in branches. Added missing adaptormodel.* files
3 #include "branchitem.h"
6 #include "mainwindow.h"
9 extern FlagRow *standardFlagsMaster;
10 extern FlagRow *systemFlagsMaster;
12 /////////////////////////////////////////////////////////////////
14 /////////////////////////////////////////////////////////////////
16 BranchObj::BranchObj () :OrnamentedObj() // FIXME-3 needed at all?
18 // cout << "Const BranchObj ()\n";
23 BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s)// FIXME-3 needed at all?
25 // cout << "Const BranchObj (s) \n";
31 BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)// FIXME-3 needed at all?
33 // cout << "Const BranchObj (s,p)\n";
36 if (treeItem->depth()==1) // FIXME-3 needed to recursively calc depth?
37 // Calc angle to mapCenter if I am a mainbranch
38 // needed for reordering the mainbranches clockwise
40 angle=getAngle (QPointF (x() - parObj->getChildPos().x() ,
41 (y() - parObj->getChildPos().y() ) ) );
45 BranchObj::~BranchObj ()
47 // cout << "Destr BranchObj of "<<this<<" ("<<treeItem->getHeading().toStdString()<<")"<<endl;
49 // If I'm animated, I need to un-animate myself first
50 if (anim.isAnimated() )
52 anim.setAnimated (false);
53 VymModel *model=treeItem->getModel();
54 model->stopAnimation (this);
57 // Check, if this branch was the last child to be deleted
58 // If so, unset the scrolled flags in parent // FIXME-2 better do this in model?
61 BranchObj *po=(BranchObj*)parObj;
65 bo=((BranchObj*)parObj)->getLastBranch();
66 if (bo) po->unScroll();
72 bool BranchObj::operator< ( const BranchObj & other )
74 return angle < other.angle;
77 bool BranchObj::operator== ( const BranchObj & other )
79 return angle == other.angle;
82 void BranchObj::init ()
87 absPos+=parObj->getChildPos();
91 void BranchObj::copy (BranchObj* other)
93 OrnamentedObj::copy(other);
95 setVisibility (other->visible);
102 void BranchObj::clear()
104 //setVisibility (true); //FIXME-4 needed?
106 while (!xlink.isEmpty())
107 delete xlink.takeFirst();
110 bool isAbove (BranchObj* a, BranchObj *b)
112 if (a->angle < b->angle)
118 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
120 // Temporary link to lmo
121 // m is position of mouse pointer
122 // offset 0: default 1: below lmo -1 above lmo (if possible)
124 BranchItem *pi=(BranchItem*)(lmo->getTreeItem()->parent());
125 int pi_depth=pi->depth();
126 BranchObj* o=(BranchObj*)(lmo);
130 // ignore mapcenter and mainbranch
131 if (pi_depth<2) off=0;
138 // FIXME-2 depth=parObj->getDepth()+1;
140 // setLinkStyle calls updateLinkGeometry, only set it once
141 if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
143 // Move temporary to new position at destination
144 // Usually the positioning would be done by reposition(),
145 // but then also the destination branch would "Jump" around...
146 // Better just do it approximately
147 if (treeItem->depth()==1) // FIXME-3 needed to recursively calc depth?
148 { // new parent is the mapcenter itself
150 QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
151 m.y() - o->getChildPos().y() ));
152 if (p.x()<0) p.setX( p.x()-bbox.width() );
159 // new parent is just a branch, link to it
160 QRectF t=o->getBBoxSizeWithChildren();
161 if (o->getTreeItem()->getLastBranch())
162 y=t.y() + t.height() ;
169 // we want to link above lmo
170 y=o->y() - height() + 5;
172 // we want to link below lmo
173 // Bottom of sel should be 5 pixels above
174 // the bottom of the branch _below_ the target:
175 // Don't try to find that branch, guess 12 pixels
176 y=o->getChildPos().y() -height() + 12;
178 if (o->getOrientation()==LinkableMapObj::LeftOfCenter)
179 move ( o->getChildPos().x() - linkwidth, y );
181 move (o->getChildPos().x() + linkwidth, y );
184 // updateLinkGeometry is called implicitly in move
188 void BranchObj::unsetParObjTmp()
195 //FIXME-2 depth=parObj->getDepth()+1;
196 setLinkStyle (getDefLinkStyle() );
197 updateLinkGeometry();
201 void BranchObj::setVisibility(bool v, int toDepth)
203 BranchItem *bi=(BranchItem*)treeItem;
204 if (bi->depth() <= toDepth)
206 frame->setVisibility(v);
207 heading->setVisibility(v);
208 systemFlags->setVisibility(v);
209 standardFlags->setVisibility(v);
210 LinkableMapObj::setVisibility (v);
212 for (i=0; i<treeItem->imageCount(); ++i)
213 treeItem->getImageObjNum(i)->setVisibility (v);
214 for (i=0; i<xlink.size(); ++i)
215 xlink.at(i)->setVisibility ();
217 // Only change children, if I am not scrolled
218 if (! bi->isScrolled() && (bi->depth() < toDepth))
220 // Now go recursivly through all children //FIXME-3 are there multiple calls for lower level items???
221 for (i=0; i<treeItem->branchCount(); ++i)
222 treeItem->getBranchObjNum(i)->setVisibility (v,toDepth);
224 } // depth <= toDepth
228 void BranchObj::setVisibility(bool v)
230 setVisibility (v,MAX_DEPTH);
234 void BranchObj::setLinkColor ()
236 // Overloaded from LinkableMapObj
237 // BranchObj can use color of heading
239 VymModel *model=treeItem->getModel();
242 if (model->getMapLinkColorHint()==HeadingColor)
243 LinkableMapObj::setLinkColor (heading->getColor() );
245 LinkableMapObj::setLinkColor ();
249 void BranchObj::updateContentSize()
256 void BranchObj::positionContents()
258 for (int i=0; i<treeItem->imageCount(); ++i)
259 treeItem->getImageObjNum(i)->reposition();
260 OrnamentedObj::positionContents();
263 void BranchObj::move (double x, double y)
265 OrnamentedObj::move (x,y);
267 for (int i=0; i<treeItem->imageCount(); ++i )
269 fio=treeItem->getImageObjNum(i);
270 if (fio) fio->reposition();
275 void BranchObj::move (QPointF p)
280 void BranchObj::moveBy (double x, double y)
282 OrnamentedObj::moveBy (x,y);
283 for (int i=0; i<treeItem->branchCount(); ++i)
284 treeItem->getBranchObjNum(i)->moveBy (x,y);
288 void BranchObj::moveBy (QPointF p)
290 moveBy (p.x(), p.y());
294 void BranchObj::positionBBox()
296 QPointF ap=getAbsPos();
297 bbox.moveTopLeft (ap);
301 frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
303 // Update links to other branches
304 for (int i=0; i<xlink.size(); ++i)
305 xlink.at(i)->updateXLink();
308 void BranchObj::calcBBoxSize()
310 QSizeF heading_r=heading->getSize();
311 qreal heading_w=(qreal) heading_r.width() ;
312 qreal heading_h=(qreal) heading_r.height() ;
313 QSizeF sysflags_r=systemFlags->getSize();
314 qreal sysflags_h=sysflags_r.height();
315 qreal sysflags_w=sysflags_r.width();
316 QSizeF stanflags_r=standardFlags->getSize();
317 qreal stanflags_h=stanflags_r.height();
318 qreal stanflags_w=stanflags_r.width();
322 // set width to sum of all widths
323 w=heading_w + sysflags_w + stanflags_w;
324 // set height to maximum needed height
325 h=max (sysflags_h,stanflags_h);
328 // Save the dimension of flags and heading
329 ornamentsBBox.setSize ( QSizeF(w,h));
331 // clickBox includes Flags and Heading
332 clickBox.setSize (ornamentsBBox.size() );
337 topPad=botPad=leftPad=rightPad=0;
338 bool incV=((BranchItem*)treeItem)->getIncludeImagesVer();
339 bool incH=((BranchItem*)treeItem)->getIncludeImagesHor();
343 for (int i=0; i<treeItem->imageCount(); ++i )
345 fio=treeItem->getImageObjNum(i);
350 topPad=max (topPad,-rp.y()-h);
351 if (rp.y()+fio->height() > 0)
352 botPad=max (botPad,rp.y()+fio->height());
356 if (orientation==LinkableMapObj::RightOfCenter)
359 leftPad=max (leftPad,-rp.x()-w);
360 if (rp.x()+fio->width() > 0)
361 rightPad=max (rightPad,rp.x()+fio->width());
365 leftPad=max (leftPad,-rp.x());
366 if (rp.x()+fio->width() > w)
367 rightPad=max (rightPad,rp.x()+fio->width()-w);
376 w+=frame->getPadding();
377 h+=frame->getPadding();
380 bbox.setSize (QSizeF (w,h));
383 void BranchObj::setDockPos()
385 if (treeItem->getType()==TreeItem::MapCenter)
387 // set childPos to middle of MapCenterObj
388 childPos.setX( clickBox.topLeft().x() + clickBox.width()/2 );
389 childPos.setY( clickBox.topLeft().y() + clickBox.height()/2 );
391 for (int i=0; i<treeItem->branchCount(); ++i)
392 treeItem->getBranchObjNum(i)->updateLinkGeometry();
396 // Sets childpos and parpos depending on orientation
397 if (getOrientation()==LinkableMapObj::LeftOfCenter )
400 ornamentsBBox.bottomLeft().x(),
403 ornamentsBBox.bottomRight().x(),
408 ornamentsBBox.bottomRight().x(),
411 ornamentsBBox.bottomLeft().x(),
417 void BranchObj::updateData()
422 qWarning ("BranchObj::udpateHeading treeItem==NULL");
425 QString s=treeItem->getHeading();
426 if (s!=heading->text())
428 heading->setText (s);
431 QStringList TIactiveFlags=treeItem->activeStandardFlagNames();
433 // Add missing standard flags active in TreeItem
434 for (int i=0;i<=TIactiveFlags.size()-1;i++)
436 if (!standardFlags->isActive (TIactiveFlags.at(i) ))
438 Flag *f=standardFlagsMaster->getFlag(TIactiveFlags.at(i));
439 if (f) standardFlags->activate (f);
443 // Remove standard flags no longer active in TreeItem
444 QStringList BOactiveFlags=standardFlags->activeFlagNames();
445 for (int i=0;i<BOactiveFlags.size();++i)
446 if (!TIactiveFlags.contains (BOactiveFlags.at(i)))
448 standardFlags->deactivate (BOactiveFlags.at(i));
452 // Add missing system flags active in TreeItem
453 TIactiveFlags=treeItem->activeSystemFlagNames();
454 for (int i=0;i<TIactiveFlags.size();++i)
456 if (!systemFlags->isActive (TIactiveFlags.at(i) ))
458 Flag *f=systemFlagsMaster->getFlag(TIactiveFlags.at(i));
459 if (f) systemFlags->activate (f);
463 // Remove system flags no longer active in TreeItem
464 BOactiveFlags=systemFlags->activeFlagNames();
465 for (int i=0;i<BOactiveFlags.size();++i)
467 if (!TIactiveFlags.contains (BOactiveFlags.at(i)))
469 systemFlags->deactivate (BOactiveFlags.at(i));
477 void BranchObj::addXLink (XLinkObj *xlo)
483 void BranchObj::removeXLinkRef (XLinkObj *xlo)
485 xlink.removeAt (xlink.indexOf(xlo));
488 void BranchObj::deleteXLink(XLinkObj *xlo)
491 if (!xlo->isUsed()) delete (xlo);
494 void BranchObj::deleteXLinkAt (int i)
496 XLinkObj *xlo=xlink.at(i);
498 if (!xlo->isUsed()) delete(xlo);
501 XLinkObj* BranchObj::XLinkAt (int i)
506 BranchObj* BranchObj::XLinkTargetAt (int i)
508 if (i>=0 && i<xlink.size())
511 return xlink.at(i)->otherBranch (this);
517 // FIXME-3 FloatImageObj* BranchObj::addFloatImage ()
520 FloatImageObj *newfi=new FloatImageObj (scene,this);
521 floatimage.append (newfi);
522 if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
523 newfi->setVisibility (false);
525 newfi->setVisibility(visible);
533 //FIXME-3 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
536 FloatImageObj *newfi=new FloatImageObj (scene,this);
537 floatimage.append (newfi);
539 if (((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
540 newfi->setVisibility (false);
542 newfi->setVisibility(visible);
550 /* FIXME-3 FloatImageObj* BranchObj::getFirstFloatImage ()
552 return floatimage.first();
555 FloatImageObj* BranchObj::getLastFloatImage ()
557 return floatimage.last();
560 FIXME -3 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
562 return floatimage.at(i);
565 void BranchObj::removeFloatImage (FloatImageObj *fio)
567 int i=floatimage.indexOf (fio);
568 if (i>-1) delete (floatimage.takeAt (i));
575 void BranchObj::savePosInAngle ()
577 // Save position in angle
578 for (int i=0; i<treeItem->branchCount(); ++i)
579 treeItem->getBranchObjNum(i)->angle=i;
582 void BranchObj::setDefAttr (BranchModification mod)
585 switch (treeItem->depth())
587 case 0: fontsize=16; break;
588 case 1: fontsize=12; break;
589 default: fontsize=10; break;
593 setLinkStyle(getDefLinkStyle());
594 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
595 font.setPointSize(fontsize);
596 heading->setFont(font );
599 setColor (treeItem->getHeadingColor() );
603 void BranchObj::sortChildren() //FIXME-2
606 int childCount=branch.count();
608 bool madeChanges=false;
612 for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
613 BranchObj* curChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex);
614 BranchObj* prevChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex-1);
615 if(prevChild->heading->text().compare(curChild->heading->text())>0)
617 this->moveBranchUp(curChild);
625 void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
627 qreal th = bboxTotal.height();
628 int depth=treeItem->depth(); // FIXME-3 needed to recursively calc depth?
632 QString h=QString (depth,' ');
633 h+=treeItem->getHeading();
636 QPointF pp; if (parObj) pp=parObj->getChildPos();
637 cout << "BO::alignRelTo ";
638 cout<<h.toStdString();
639 cout << " d="<<depth<<
640 //cout<< " ref="<<ref<<
641 " bbox.tL="<<bboxTotal.topLeft()<<
643 // " relPos="<<relPos<<
645 " w="<<bbox.width()<<
646 " h="<<bbox.height()<<
647 // " orient="<<orientation<<
648 // " alignSelf="<<alignSelf<<
649 // " scrolled="<<((BranchItem*)treeItem)->isScrolled()<<
650 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
651 // " hidden="<<hidden<<
657 //updateLinkGeometry();
659 if (depth==1 && parObj)
661 // Position relatively, if needed
662 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
664 // Calc angle to mapCenter if I am a mainbranch
665 // needed for reordering the mainbranches clockwise
667 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
668 (int)(y() - parObj->getChildPos().y() ) ) );
672 // Align myself depending on orientation and parent, but
673 // only if I am not a mainbranch or mapcenter itself
675 if (anim.isAnimated())
680 LinkableMapObj::Orientation o;
681 o=parObj->getOrientation();
685 case LinkableMapObj::LeftOfCenter:
686 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
687 //move (ref.x() , ref.y() + (th-bbox.height())/2 );
689 case LinkableMapObj::RightOfCenter:
690 move (ref.x() , ref.y() + (th-bbox.height())/2 );
693 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
699 if ( ((BranchItem*)treeItem)->isScrolled() ) return;
701 // Set reference point for alignment of children
703 if (orientation==LinkableMapObj::LeftOfCenter)
704 ref2.setX(bbox.topLeft().x() - linkwidth);
706 ref2.setX(bbox.topRight().x() + linkwidth);
709 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
713 // Align the children depending on reference point
714 for (int i=0; i<treeItem->branchCount(); ++i)
716 if (!treeItem->getBranchNum(i)->isHidden())
718 treeItem->getBranchObjNum(i)->alignRelativeTo (ref2,true);
720 // append next branch below current one
721 ref2.setY(ref2.y() + treeItem->getBranchObjNum(i)->getBBoxSizeWithChildren().height() );
727 void BranchObj::reposition()
730 if (!treeItem->getHeading().isEmpty())
731 cout << "BO::reposition "<<qPrintable(treeItem->getHeading())<<endl;
733 cout << "BO::reposition ???"<<endl;
734 // cout << " orient="<<orientation<<endl;
737 if (treeItem->depth()==0)
739 // only calculate the sizes once. If the deepest LMO
740 // changes its height,
741 // all upper LMOs have to change, too.
742 calcBBoxSizeWithChildren();
743 updateLinkGeometry(); // This update is needed if the scene is resized
744 // due to excessive moving of a FIO
746 alignRelativeTo ( QPointF (absPos.x(),
747 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
748 //FIXME-2 qSort (branch.begin(),branch.end(), isAbove);
749 positionBBox(); // Reposition bbox and contents
752 // This is only important for moving branches:
753 // For editing a branch it isn't called...
754 alignRelativeTo ( QPointF (absPos.x(),
755 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
759 void BranchObj::unsetAllRepositionRequests()
761 repositionRequest=false;
762 for (int i=0; i<treeItem->branchCount(); ++i)
763 treeItem->getBranchObjNum(i)->unsetAllRepositionRequests();
767 QPolygonF BranchObj::shape()
771 QRectF r=getTotalBBox();
772 if (orientation==LinkableMapObj::LeftOfCenter)
775 <<QPointF (bbox.topLeft().x(), r.topLeft().y() )
778 <<QPointF (bbox.bottomLeft().x(), r.bottomLeft().y() ) ;
782 <<QPointF (bbox.topRight().x(), r.topRight().y() )
785 <<QPointF (bbox.bottomRight().x(), r.bottomRight().y() ) ;
789 QRectF BranchObj::getTotalBBox()
793 if ( ((BranchItem*)treeItem)->isScrolled() ) return r;
795 for (int i=0; i<treeItem->branchCount(); ++i)
796 if (!treeItem->getBranchNum(i)->isHidden())
797 r=addBBox(treeItem->getBranchObjNum(i)->getTotalBBox(),r);
799 /* FIXME-3 lots of occurences of treeItem->getBranchObjNum(i) in branchobj.cpp
800 better check if they are not NULL and maybe simplify...
801 (have been NULL at least in calcBBoxSizeWithChilds...)
804 for (int i=0; i<treeItem->imageCount(); ++i)
805 if (!treeItem->isHidden())
806 r=addBBox(treeItem->getImageObjNum(i)->getTotalBBox(),r);
810 QRectF BranchObj::getBBoxSizeWithChildren()
815 void BranchObj::calcBBoxSizeWithChildren()
817 // This is initially called only from reposition and
818 // and only for mapcenter. So it won't be
819 // called more than once for a single user
823 // Calculate size of LMO including all children (to align them later)
824 bboxTotal.setX(bbox.x() );
825 bboxTotal.setY(bbox.y() );
827 // if branch is scrolled, ignore children, but still consider floatimages
828 BranchItem *bi=(BranchItem*)treeItem;
829 if ( bi->isScrolled() )
831 bboxTotal.setWidth (bbox.width());
832 bboxTotal.setHeight(bbox.height());
838 bboxTotal.setWidth (0);
839 bboxTotal.setHeight(0);
842 bboxTotal.setX (parObj->x());
843 bboxTotal.setY (parObj->y());
846 bboxTotal.setX (bbox.x());
847 bboxTotal.setY (bbox.y());
854 // Now calculate recursivly
858 for (int i=0; i<treeItem->branchCount(); i++)
860 if (!bi->getBranchNum(i)->isHidden())
862 bi->getBranchObjNum(i)->calcBBoxSizeWithChildren();
863 br=bi->getBranchObjNum(i)->getBBoxSizeWithChildren();
864 r.setWidth( max (br.width(), r.width() ));
865 r.setHeight(br.height() + r.height() );
866 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
869 // Add myself and also
870 // add width of link to sum if necessary
871 if (bi->branchCount()<1)
872 bboxTotal.setWidth (bbox.width() + r.width() );
874 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
876 bboxTotal.setHeight(max (r.height(), bbox.height()));
879 QString BranchObj::getSelectString()
881 VymModel *model=treeItem->getModel();
883 return model->getSelectString (this);
888 void BranchObj::setAnimation(const AnimPoint &ap)
893 bool BranchObj::animate()
896 if ( anim.isAnimated() )
901 parObj->reposition(); // we might have been relinked meanwhile