3 #include "branchitem.h"
6 #include "mainwindow.h"
9 //class TextEditor; //FIXME-3
11 //extern TextEditor *textEditor;
12 //extern Main *mainWindow;
13 //extern FlagRowObj *standardFlagsDefault;
16 /////////////////////////////////////////////////////////////////
18 /////////////////////////////////////////////////////////////////
20 BranchObj::BranchObj () :OrnamentedObj() // FIXME-3 needed at all?
22 // cout << "Const BranchObj ()\n";
27 BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s)// FIXME-3 needed at all?
29 // cout << "Const BranchObj (s) \n";
35 BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)// FIXME-3 needed at all?
37 // cout << "Const BranchObj (s,p)\n";
40 if (treeItem->depth()==1)
41 // Calc angle to mapCenter if I am a mainbranch
42 // needed for reordering the mainbranches clockwise
44 angle=getAngle (QPointF (x() - parObj->getChildPos().x() ,
45 (y() - parObj->getChildPos().y() ) ) );
49 BranchObj::~BranchObj ()
51 // cout << "Destr BranchObj of "<<this<<" ("<<treeItem->getHeading().toStdString()<<")"<<endl;
53 // If I'm animated, I need to un-animate myself first
54 if (anim.isAnimated() )
56 anim.setAnimated (false);
57 model->stopAnimation (this);
60 // Check, if this branch was the last child to be deleted
61 // If so, unset the scrolled flags in parent // FIXME-2 better do this in model?
64 BranchObj *po=(BranchObj*)parObj;
68 bo=((BranchObj*)parObj)->getLastBranch();
69 if (bo) po->unScroll();
75 bool BranchObj::operator< ( const BranchObj & other )
77 return angle < other.angle;
80 bool BranchObj::operator== ( const BranchObj & other )
82 return angle == other.angle;
85 void BranchObj::init ()
90 absPos+=parObj->getChildPos();
95 includeImagesVer=false;
96 includeImagesHor=false;
99 void BranchObj::copy (BranchObj* other)
101 OrnamentedObj::copy(other);
103 /* FIXME-3 not needed
104 for (int i=0; i<other->treeItem->branchCount(); ++i)
105 // Make deep copy of b
106 // Because addBranch again calls copy for the children,
107 // Those will get a deep copy, too
108 addBranch(other->branch.at(i) );
111 for (int i=0; i<other->floatimage.size(); ++i)
112 addFloatImage (other->floatimage.at(i));
114 setVisibility (other->visible);
121 void BranchObj::clear()
123 //setVisibility (true); //FIXME-4 needed?
125 while (!floatimage.isEmpty())
126 delete floatimage.takeFirst();
128 while (!xlink.isEmpty())
129 delete xlink.takeFirst();
132 bool isAbove (BranchObj* a, BranchObj *b)
134 if (a->angle < b->angle)
140 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
142 // Temporary link to lmo
143 // m is position of mouse pointer
144 // offset 0: default 1: below lmo -1 above lmo (if possible)
147 BranchObj* o=(BranchObj*)(lmo);
151 // ignore mapcenter and mainbranch
152 if (treeItem->depth()<2) off=0;
159 // FIXME-2 depth=parObj->getDepth()+1;
161 // setLinkStyle calls updateLink, only set it once
162 if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
164 // Move temporary to new position at destination
165 // Usually the positioning would be done by reposition(),
166 // but then also the destination branch would "Jump" around...
167 // Better just do it approximately
168 if (treeItem->depth()==1)
169 { // new parent is the mapcenter itself
171 QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
172 m.y() - o->getChildPos().y() ));
173 if (p.x()<0) p.setX( p.x()-bbox.width() );
180 // new parent is just a branch, link to it
181 QRectF t=o->getBBoxSizeWithChildren();
182 if (o->getTreeItem()->getLastBranch())
183 y=t.y() + t.height() ;
190 // we want to link above lmo
191 y=o->y() - height() + 5;
193 // we want to link below lmo
194 // Bottom of sel should be 5 pixels above
195 // the bottom of the branch _below_ the target:
196 // Don't try to find that branch, guess 12 pixels
197 y=o->getChildPos().y() -height() + 12;
199 if (o->getOrientation()==LinkableMapObj::LeftOfCenter)
200 move ( o->getChildPos().x() - linkwidth, y );
202 move (o->getChildPos().x() + linkwidth, y );
205 // updateLink is called implicitly in move
209 void BranchObj::unsetParObjTmp()
216 //FIXME-2 depth=parObj->getDepth()+1;
217 setLinkStyle (getDefLinkStyle() );
222 void BranchObj::setVisibility(bool v, int toDepth)
224 BranchItem *bi=(BranchItem*)treeItem;
225 if (bi->depth() <= toDepth)
227 frame->setVisibility(v);
228 heading->setVisibility(v);
229 systemFlags->setVisibility(v);
230 standardFlags->setVisibility(v);
231 LinkableMapObj::setVisibility (v);
233 for (i=0; i<floatimage.size(); ++i)
234 floatimage.at(i)->setVisibility (v);
235 for (i=0; i<xlink.size(); ++i)
236 xlink.at(i)->setVisibility ();
238 // Only change children, if I am not scrolled
239 if (! bi->isScrolled() && (bi->depth() < toDepth))
241 // Now go recursivly through all children
242 for (i=0; i<treeItem->branchCount(); ++i)
243 treeItem->getBranchObjNum(i)->setVisibility (v,toDepth);
245 } // depth <= toDepth
249 void BranchObj::setVisibility(bool v)
251 setVisibility (v,MAX_DEPTH);
255 void BranchObj::setLinkColor ()
257 // Overloaded from LinkableMapObj
258 // BranchObj can use color of heading
262 if (model->getMapLinkColorHint()==HeadingColor)
263 LinkableMapObj::setLinkColor (heading->getColor() );
265 LinkableMapObj::setLinkColor ();
269 void BranchObj::setColorSubtree(QColor col)
272 for (int i=0; i<treeItem->branchCount(); ++i)
273 treeItem->getBranchObjNum(i)->setColorSubtree(col);
276 void BranchObj::updateContentSize()
283 void BranchObj::positionContents()
285 for (int i=0; i<floatimage.size(); ++i )
286 floatimage.at(i)->reposition();
287 OrnamentedObj::positionContents();
290 void BranchObj::move (double x, double y)
292 OrnamentedObj::move (x,y);
293 for (int i=0; i<floatimage.size(); ++i )
294 floatimage.at(i)->reposition();
298 void BranchObj::move (QPointF p)
303 void BranchObj::moveBy (double x, double y)
305 OrnamentedObj::moveBy (x,y);
306 for (int i=0; i<treeItem->branchCount(); ++i)
307 treeItem->getBranchObjNum(i)->moveBy (x,y);
311 void BranchObj::moveBy (QPointF p)
313 moveBy (p.x(), p.y());
317 void BranchObj::positionBBox()
319 QPointF ap=getAbsPos();
320 bbox.moveTopLeft (ap);
324 frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
326 // Update links to other branches
327 for (int i=0; i<xlink.size(); ++i)
328 xlink.at(i)->updateXLink();
331 void BranchObj::calcBBoxSize()
333 QSizeF heading_r=heading->getSize();
334 qreal heading_w=(qreal) heading_r.width() ;
335 qreal heading_h=(qreal) heading_r.height() ;
336 QSizeF sysflags_r; //FIXME-1 =systemFlags->getSize();
337 qreal sysflags_h=0;//sysflags_r.height();
338 qreal sysflags_w=0;//sysflags_r.width();
339 QSizeF stanflags_r; //FIXME-1 =standardFlags->getSize();
340 qreal stanflags_h=0; //stanflags_r.height();
341 qreal stanflags_w=0; //stanflags_r.width();
345 // set width to sum of all widths
346 w=heading_w + sysflags_w + stanflags_w;
347 // set height to maximum needed height
348 h=max (sysflags_h,stanflags_h);
351 // Save the dimension of flags and heading
352 ornamentsBBox.setSize ( QSizeF(w,h));
354 // clickBox includes Flags and Heading
355 clickBox.setSize (ornamentsBBox.size() );
360 topPad=botPad=leftPad=rightPad=0;
361 if (includeImagesVer || includeImagesHor)
363 if (treeItem->imageCount()>0)
365 for (int i=0; i<floatimage.size(); ++i )
367 rp=floatimage.at(i)->getRelPos();
368 if (includeImagesVer)
371 topPad=max (topPad,-rp.y()-h);
372 if (rp.y()+floatimage.at(i)->height() > 0)
373 botPad=max (botPad,rp.y()+floatimage.at(i)->height());
375 if (includeImagesHor)
377 if (orientation==LinkableMapObj::RightOfCenter)
380 leftPad=max (leftPad,-rp.x()-w);
381 if (rp.x()+floatimage.at(i)->width() > 0)
382 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
386 leftPad=max (leftPad,-rp.x());
387 if (rp.x()+floatimage.at(i)->width() > w)
388 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
398 w+=frame->getPadding();
399 h+=frame->getPadding();
402 bbox.setSize (QSizeF (w,h));
405 void BranchObj::setDockPos()
407 // Sets childpos and parpos depending on orientation
408 if (getOrientation()==LinkableMapObj::LeftOfCenter )
411 ornamentsBBox.bottomLeft().x(),
414 ornamentsBBox.bottomRight().x(),
419 ornamentsBBox.bottomRight().x(),
422 ornamentsBBox.bottomLeft().x(),
427 void BranchObj::updateHeading()
431 qWarning ("BranchObj::udpateHeading treeItem==NULL");
434 heading->setText (treeItem->getHeading() );
438 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
440 // Cloudy stuff can be hidden during exports
441 // FIXME-1 if (hidden) return "";
443 // Update of note is usually done while unselecting a branch
444 // if (isNoteInEditor) getNoteFromTextEditor(); //FIXME-2 moved to TreeItem
447 QString scrolledAttr;
448 if ( ((BranchItem*)treeItem)->isScrolled() )
449 scrolledAttr=attribut ("scrolled","yes");
453 // save area, if not scrolled
455 if (!((BranchItem*) (treeItem->parent()) )->isScrolled() )
458 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
459 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
460 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
461 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
466 // Providing an ID for a branch makes export to XHTML easier
468 if (treeItem->xlinkCount()>0)
469 idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
473 s=beginElement ("branch"
478 +getIncludeImageAttr() );
482 s+=valueElement("heading", treeItem->getHeading(),
483 attribut ("textColor",QColor(heading->getColor()).name()));
486 if (frame->getFrameType()!=FrameObj::NoFrame)
487 s+=frame->saveToDir ();
489 // save names of flags set
490 s+=standardFlags->saveToDir(tmpdir,prefix,0);
493 for (int i=0; i<floatimage.size(); ++i)
494 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
497 if (!treeItem->getNoteObj().isEmpty() )
498 s+=treeItem->getNoteObj().saveToDir();
501 for (int i=0; i<treeItem->branchCount(); ++i)
502 s+=treeItem->getBranchObjNum(i)->saveToDir(tmpdir,prefix,offset);
505 QString ol; // old link
506 QString cl; // current link
507 for (int i=0; i<xlink.size(); ++i)
509 cl=xlink.at(i)->saveToDir();
516 qWarning (QString("Ignoring of duplicate xLink in %1").arg(treeItem->getHeading()));
521 s+=endElement ("branch");
525 void BranchObj::addXLink (XLinkObj *xlo)
531 void BranchObj::removeXLinkRef (XLinkObj *xlo)
533 xlink.removeAt (xlink.indexOf(xlo));
536 void BranchObj::deleteXLink(XLinkObj *xlo)
539 if (!xlo->isUsed()) delete (xlo);
542 void BranchObj::deleteXLinkAt (int i)
544 XLinkObj *xlo=xlink.at(i);
546 if (!xlo->isUsed()) delete(xlo);
549 XLinkObj* BranchObj::XLinkAt (int i)
554 BranchObj* BranchObj::XLinkTargetAt (int i)
556 if (i>=0 && i<xlink.size())
559 return xlink.at(i)->otherBranch (this);
564 void BranchObj::setIncludeImagesVer(bool b)
572 bool BranchObj::getIncludeImagesVer()
574 return includeImagesVer;
577 void BranchObj::setIncludeImagesHor(bool b)
585 bool BranchObj::getIncludeImagesHor()
587 return includeImagesHor;
590 QString BranchObj::getIncludeImageAttr()
593 if (includeImagesVer)
594 a=attribut ("incImgV","true");
596 a=attribut ("incImgV","false");
597 if (includeImagesHor)
598 a+=attribut ("incImgH","true");
600 a+=attribut ("incImgH","false");
604 FloatImageObj* BranchObj::addFloatImage ()
606 FloatImageObj *newfi=new FloatImageObj (scene,this);
607 floatimage.append (newfi);
608 if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
609 newfi->setVisibility (false);
611 newfi->setVisibility(visible);
620 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
622 FloatImageObj *newfi=new FloatImageObj (scene,this);
623 floatimage.append (newfi);
625 if (((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
626 newfi->setVisibility (false);
628 newfi->setVisibility(visible);
637 FloatImageObj* BranchObj::getFirstFloatImage ()
639 return floatimage.first();
642 FloatImageObj* BranchObj::getLastFloatImage ()
644 return floatimage.last();
647 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
649 return floatimage.at(i);
652 void BranchObj::removeFloatImage (FloatImageObj *fio)
654 int i=floatimage.indexOf (fio);
655 if (i>-1) delete (floatimage.takeAt (i));
661 void BranchObj::savePosInAngle ()
663 // Save position in angle
664 for (int i=0; i<treeItem->branchCount(); ++i)
665 treeItem->getBranchObjNum(i)->angle=i;
668 void BranchObj::setDefAttr (BranchModification mod)
671 switch (treeItem->depth())
673 case 0: fontsize=16; break;
674 case 1: fontsize=12; break;
675 default: fontsize=10; break;
679 setLinkStyle(getDefLinkStyle());
680 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
681 font.setPointSize(fontsize);
682 heading->setFont(font );
685 setColor (((BranchObj*)(parObj))->getColor());
690 BranchObj* BranchObj::addBranch() // FIXME-3 still needed?
692 BranchObj* newbo=new BranchObj(scene,this);
693 newbo->setParObj(this);
694 newbo->setDefAttr(NewBranch);
695 /* FIXME-2 treeItem not set yet!!!
696 if ( ((BranchItem*)treeItem)->isScrolled() )
697 newbo->setVisibility (false);
699 newbo->setVisibility(visible);
706 BranchObj* BranchObj::addBranch(BranchObj* bo)
708 BranchObj* newbo=new BranchObj(scene,this);
709 //FIXME-1 branch.append (newbo);
711 newbo->setParObj(this);
712 newbo->setDefAttr(MovedBranch);
713 if ( ((BranchItem*)treeItem)->isScrolled() )
714 newbo->setVisibility (false);
716 newbo->setVisibility(bo->visible);
722 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
724 //FIXME-1 branch.append (bo);
725 bo->setParObj (this);
726 //FIXME-2 bo->depth=depth+1;
727 bo->setDefAttr(MovedBranch);
728 BranchItem *bi=(BranchItem*)treeItem;
729 if ( bi->isScrolled() ) bi->tmpUnscroll();
730 //setLastSelectedBranch (bo); //FIXME-3 needed?
734 BranchObj* BranchObj::insertBranch(int pos)
737 // Add new bo and resort branches
738 BranchObj *newbo=addBranch ();
739 newbo->angle=pos-0.5;
740 //FIXME-1 qSort (branch.begin(),branch.end(), isAbove);
744 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
747 // Add new bo and resort branches
749 BranchObj *newbo=addBranch (bo);
750 //FIXME-1 qSort (branch.begin(),branch.end(), isAbove);
754 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
757 // Add new bo and resort branches
759 //FIXME-4 branch.append (bo);
760 bo->setParObj (this);
761 //FIXME-2 bo->depth=depth+1;
762 bo->setDefAttr (MovedBranch);
763 BranchItem *bi=(BranchItem*)treeItem;
764 if ( bi->isScrolled() ) bi->tmpUnscroll();
765 //setLastSelectedBranch (bo); //FIXME-3 needed?
766 //FIXME-2 qSort (branch.begin(),branch.end(), isAbove);
770 void BranchObj::removeBranchHere(BranchObj* borem) // FIXME-1 getNum no longer available
773 // This removes the branch bo from list, but
774 // inserts its children at the place of bo
776 bo=borem->getLastBranch();
777 int pos=borem->getNum();
780 bo->linkTo (this,pos+1);
781 bo=borem->getLastBranch();
783 removeBranch (borem);
787 void BranchObj::removeChildren() // FIXME-3 not needed here
792 void BranchObj::removeBranch(BranchObj* bo) // FIXME-1 not needed here
795 // if bo is not in branch remove returns false, we
798 int i=branch.indexOf(bo);
804 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
809 void BranchObj::removeBranchPtr(BranchObj* bo) // FIXME-1 not needed here
812 int i=branch.indexOf(bo);
817 qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
822 bool BranchObj::canMoveBranchUp()
824 /* FIXME-1 move to BranchItem
825 if (!parObj || depth==1) return false;
826 BranchObj* par=(BranchObj*)parObj;
827 if (this==par->getTreeItem()->getFirstBranch())
835 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // FIXME-1
839 int i=branch.indexOf(bo1);
841 { // -1 if bo1 not found
842 treeItem->getBranchObjNum(i)->angle--;
843 treeItem->getBranchObjNum(i-1)->angle++;
844 qSort (branch.begin(),branch.end(), isAbove);
845 return treeItem->getBranchObjNum(i);
851 bool BranchObj::canMoveBranchDown()
853 /* FIXME-1 move to BranchItem
854 if (!parObj|| depth==1) return false;
855 BranchObj* par=(BranchObj*)parObj;
856 if (this==par->getTreeItem()->getLastBranch())
864 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// FIXME-1
868 int i=branch.indexOf(bo1);
870 if (i <treeItem->branchCount())
873 treeItem->getBranchObjNum(i)->angle++;
874 treeItem->getBranchObjNum(j)->angle--;
875 qSort (branch.begin(),branch.end(), isAbove);
876 return treeItem->getBranchObjNum(i);
882 void BranchObj::sortChildren() //FIXME-1
885 int childCount=branch.count();
887 bool madeChanges=false;
891 for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
892 BranchObj* curChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex);
893 BranchObj* prevChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex-1);
894 if(prevChild->heading->text().compare(curChild->heading->text())>0)
896 this->moveBranchUp(curChild);
905 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
907 // Find current parent and
908 // remove pointer to myself there
909 if (!dst) return NULL;
910 BranchObj *par=(BranchObj*)parObj;
912 par->removeBranchPtr (this);
917 // Create new pointer to myself at dst
918 if (pos<0||dst->getDepth()==0)
920 // links myself as last branch at dst
921 dst->addBranchPtr (this);
926 // inserts me at pos in parent of dst
929 BranchObj *bo=dst->insertBranchPtr (this,pos);
930 bo->setDefAttr(MovedBranch);
940 void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
942 qreal th = bboxTotal.height();
943 int depth=treeItem->depth();
947 QString h=QString (depth,' ');
948 h+=treeItem->getHeading();
951 QPointF pp; if (parObj) pp=parObj->getChildPos();
952 cout << "BO::alignRelTo ";
953 cout<<h.toStdString();
954 cout << " d="<<depth<<
955 //cout<< " ref="<<ref<<
956 " bbox.tL="<<bboxTotal.topLeft()<<
958 // " relPos="<<relPos<<
960 " w="<<bbox.width()<<
961 " h="<<bbox.height()<<
962 // " orient="<<orientation<<
963 // " alignSelf="<<alignSelf<<
964 // " scrolled="<<((BranchItem*)treeItem)->isScrolled()<<
965 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
966 // " hidden="<<hidden<<
974 if (depth==1 && parObj)
976 // Position relatively, if needed
977 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
979 // Calc angle to mapCenter if I am a mainbranch
980 // needed for reordering the mainbranches clockwise
982 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
983 (int)(y() - parObj->getChildPos().y() ) ) );
987 // Align myself depending on orientation and parent, but
988 // only if I am not a mainbranch or mapcenter itself
990 if (anim.isAnimated())
995 LinkableMapObj::Orientation o;
996 o=parObj->getOrientation();
1000 case LinkableMapObj::LeftOfCenter:
1001 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1002 //move (ref.x() , ref.y() + (th-bbox.height())/2 );
1004 case LinkableMapObj::RightOfCenter:
1005 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1008 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1014 if ( ((BranchItem*)treeItem)->isScrolled() ) return;
1016 // Set reference point for alignment of children
1018 if (orientation==LinkableMapObj::LeftOfCenter)
1019 ref2.setX(bbox.topLeft().x() - linkwidth);
1021 ref2.setX(bbox.topRight().x() + linkwidth);
1024 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1026 ref2.setY(ref.y() );
1028 // Align the children depending on reference point
1029 for (int i=0; i<treeItem->branchCount(); ++i)
1031 if (!treeItem->getBranchNum(i)->isHidden())
1033 treeItem->getBranchObjNum(i)->alignRelativeTo (ref2,true);
1035 // append next branch below current one
1036 ref2.setY(ref2.y() + treeItem->getBranchObjNum(i)->getBBoxSizeWithChildren().height() );
1042 void BranchObj::reposition()
1044 /* TODO testing only
1045 if (!treeItem->getHeading().isEmpty())
1046 cout << "BO::reposition "<<qPrintable(treeItem->getHeading())<<endl;
1048 cout << "BO::reposition ???"<<endl;
1049 // cout << " orient="<<orientation<<endl;
1052 if (treeItem->depth()==0)
1054 // only calculate the sizes once. If the deepest LMO
1055 // changes its height,
1056 // all upper LMOs have to change, too.
1057 calcBBoxSizeWithChildren();
1058 updateLink(); // This update is needed if the scene is resized
1059 // due to excessive moving of a FIO
1061 alignRelativeTo ( QPointF (absPos.x(),
1062 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1063 //FIXME-2 qSort (branch.begin(),branch.end(), isAbove);
1064 positionBBox(); // Reposition bbox and contents
1067 // This is only important for moving branches:
1068 // For editing a branch it isn't called...
1069 alignRelativeTo ( QPointF (absPos.x(),
1070 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1074 void BranchObj::unsetAllRepositionRequests()
1076 repositionRequest=false;
1077 for (int i=0; i<treeItem->branchCount(); ++i)
1078 treeItem->getBranchObjNum(i)->unsetAllRepositionRequests();
1082 QPolygonF BranchObj::shape()
1086 QRectF r=getTotalBBox();
1087 if (orientation==LinkableMapObj::LeftOfCenter)
1090 <<QPointF (bbox.topLeft().x(), r.topLeft().y() )
1092 <<bbox.bottomRight()
1093 <<QPointF (bbox.bottomLeft().x(), r.bottomLeft().y() ) ;
1097 <<QPointF (bbox.topRight().x(), r.topRight().y() )
1100 <<QPointF (bbox.bottomRight().x(), r.bottomRight().y() ) ;
1104 QRectF BranchObj::getTotalBBox()
1108 if ( ((BranchItem*)treeItem)->isScrolled() ) return r;
1110 for (int i=0; i<treeItem->branchCount(); ++i)
1111 if (!treeItem->getBranchNum(i)->isHidden())
1112 r=addBBox(treeItem->getBranchObjNum(i)->getTotalBBox(),r);
1114 /* FIXME-3 lots of occurences of treeItem->getBranchObjNum(i) in branchobj.cpp
1115 better check if they are not NULL and maybe simplify...
1116 (have been NULL at least in calcBBoxSizeWithChilds...)
1120 FIXME-1 for (int i=0; i<floatimage.size(); ++i)
1121 if (!floatimage.at(i)->isHidden())
1122 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1127 QRectF BranchObj::getBBoxSizeWithChildren()
1132 void BranchObj::calcBBoxSizeWithChildren()
1134 // This is initially called only from reposition and
1135 // and only for mapcenter. So it won't be
1136 // called more than once for a single user
1140 // Calculate size of LMO including all children (to align them later)
1141 bboxTotal.setX(bbox.x() );
1142 bboxTotal.setY(bbox.y() );
1144 // if branch is scrolled, ignore children, but still consider floatimages
1145 BranchItem *bi=(BranchItem*)treeItem;
1146 if ( bi->isScrolled() )
1148 bboxTotal.setWidth (bbox.width());
1149 bboxTotal.setHeight(bbox.height());
1155 bboxTotal.setWidth (0);
1156 bboxTotal.setHeight(0);
1159 bboxTotal.setX (parObj->x());
1160 bboxTotal.setY (parObj->y());
1163 bboxTotal.setX (bbox.x());
1164 bboxTotal.setY (bbox.y());
1171 // Now calculate recursivly
1173 // maximum of widths
1175 for (int i=0; i<treeItem->branchCount(); i++)
1177 if (!bi->getBranchNum(i)->isHidden())
1179 bi->getBranchObjNum(i)->calcBBoxSizeWithChildren();
1180 br=bi->getBranchObjNum(i)->getBBoxSizeWithChildren();
1181 r.setWidth( max (br.width(), r.width() ));
1182 r.setHeight(br.height() + r.height() );
1183 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1186 // Add myself and also
1187 // add width of link to sum if necessary
1188 if (bi->branchCount()<1)
1189 bboxTotal.setWidth (bbox.width() + r.width() );
1191 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1193 bboxTotal.setHeight(max (r.height(), bbox.height()));
1197 void BranchObj::select() // FIXME-4 try to get rid of this in BO completely
1199 cout << "BO::select()\n";
1200 textEditor->setText(treeItem->getNoteObj().getNote() );
1201 QString fnh=treeItem->getNoteObj().getFilenameHint();
1203 textEditor->setFilenameHint(treeItem->getNoteObj().getFilenameHint() );
1205 textEditor->setFilenameHint(getHeading() );
1206 textEditor->setFontHint (treeItem->getNoteObj().getFontHint() );
1207 //isNoteInEditor=true;
1209 // set selected and visible
1210 LinkableMapObj::select();
1212 //if (po) po->setLastSelectedBranch(this); needed?
1214 // temporary unscroll, if we have scrolled parents somewhere
1215 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1217 //moved to vymmodel or vymview...
1218 // Show URL and link in statusbar
1220 if (!url.isEmpty()) status+="URL: "+url+" ";
1221 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1222 if (!status.isEmpty()) mainWindow->statusMessage (status);
1225 updateFlagsToolbar();
1228 model->updateActions();
1233 void BranchObj::unselect() //FIXME-4 should not be needed
1235 cout << "BO::unselect()\n";
1236 LinkableMapObj::unselect();
1237 // Delete any messages like vymLink in StatusBar
1238 mainWindow->statusMessage (""); //this causes segfault, when MainWindow is already gone in global destructor on quitting vym
1240 // Save current note
1241 if (isNoteInEditor) getNoteFromTextEditor();
1242 isNoteInEditor=false;
1244 // reset temporary unscroll, if we have scrolled parents somewhere
1245 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1247 // Erase content of editor
1248 textEditor->setInactive();
1250 // unselect all buttons in toolbar
1251 standardFlagsDefault->updateToolbar();
1255 QString BranchObj::getSelectString()
1257 return model->getSelectString (this);
1260 void BranchObj::setAnimation(const AnimPoint &ap)
1265 bool BranchObj::animate()
1268 if ( anim.isAnimated() )
1273 parObj->reposition(); // we might have been relinked meanwhile