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 // If I'm animated, I need to un-animate myself first
52 if (anim.isAnimated() )
54 anim.setAnimated (false);
55 model->stopAnimation (this);
58 cout << "Destr BranchObj of "<<this<<" ("<<treeItem->getHeading().toStdString()<<")"<<endl;
59 // Check, if this branch was the last child to be deleted
60 // If so, unset the scrolled flags in parent // FIXME-2 better do this in model?
63 BranchObj *po=(BranchObj*)parObj;
67 bo=((BranchObj*)parObj)->getLastBranch();
68 if (bo) po->unScroll();
74 bool BranchObj::operator< ( const BranchObj & other )
76 return angle < other.angle;
79 bool BranchObj::operator== ( const BranchObj & other )
81 return angle == other.angle;
84 void BranchObj::init ()
89 absPos+=parObj->getChildPos();
94 includeImagesVer=false;
95 includeImagesHor=false;
98 void BranchObj::copy (BranchObj* other)
100 OrnamentedObj::copy(other);
102 /* FIXME-3 not needed
103 for (int i=0; i<other->treeItem->branchCount(); ++i)
104 // Make deep copy of b
105 // Because addBranch again calls copy for the children,
106 // Those will get a deep copy, too
107 addBranch(other->branch.at(i) );
110 for (int i=0; i<other->floatimage.size(); ++i)
111 addFloatImage (other->floatimage.at(i));
113 setVisibility (other->visible);
120 void BranchObj::clear()
122 //setVisibility (true); //FIXME-4 needed?
124 while (!floatimage.isEmpty())
125 delete floatimage.takeFirst();
127 while (!xlink.isEmpty())
128 delete xlink.takeFirst();
131 bool isAbove (BranchObj* a, BranchObj *b)
133 if (a->angle < b->angle)
139 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
141 // Temporary link to lmo
142 // m is position of mouse pointer
143 // offset 0: default 1: below lmo -1 above lmo (if possible)
146 BranchObj* o=(BranchObj*)(lmo);
150 // ignore mapcenter and mainbranch
151 if (treeItem->depth()<2) off=0;
158 // FIXME-2 depth=parObj->getDepth()+1;
160 // setLinkStyle calls updateLink, only set it once
161 if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
163 // Move temporary to new position at destination
164 // Usually the positioning would be done by reposition(),
165 // but then also the destination branch would "Jump" around...
166 // Better just do it approximately
167 if (treeItem->depth()==1)
168 { // new parent is the mapcenter itself
170 QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
171 m.y() - o->getChildPos().y() ));
172 if (p.x()<0) p.setX( p.x()-bbox.width() );
179 // new parent is just a branch, link to it
180 QRectF t=o->getBBoxSizeWithChildren();
181 if (o->getTreeItem()->getLastBranch())
182 y=t.y() + t.height() ;
189 // we want to link above lmo
190 y=o->y() - height() + 5;
192 // we want to link below lmo
193 // Bottom of sel should be 5 pixels above
194 // the bottom of the branch _below_ the target:
195 // Don't try to find that branch, guess 12 pixels
196 y=o->getChildPos().y() -height() + 12;
198 if (o->getOrientation()==LinkableMapObj::LeftOfCenter)
199 move ( o->getChildPos().x() - linkwidth, y );
201 move (o->getChildPos().x() + linkwidth, y );
204 // updateLink is called implicitly in move
208 void BranchObj::unsetParObjTmp()
215 //FIXME-2 depth=parObj->getDepth()+1;
216 setLinkStyle (getDefLinkStyle() );
221 void BranchObj::setVisibility(bool v, int toDepth)
223 BranchItem *bi=(BranchItem*)treeItem;
224 if (bi->depth() <= toDepth)
226 frame->setVisibility(v);
227 heading->setVisibility(v);
228 systemFlags->setVisibility(v);
229 standardFlags->setVisibility(v);
230 LinkableMapObj::setVisibility (v);
232 for (i=0; i<floatimage.size(); ++i)
233 floatimage.at(i)->setVisibility (v);
234 for (i=0; i<xlink.size(); ++i)
235 xlink.at(i)->setVisibility ();
237 // Only change children, if I am not scrolled
238 if (! bi->isScrolled() && (bi->depth() < toDepth))
240 // Now go recursivly through all children
241 for (i=0; i<treeItem->branchCount(); ++i)
242 treeItem->getBranchObjNum(i)->setVisibility (v,toDepth);
244 } // depth <= toDepth
248 void BranchObj::setVisibility(bool v)
250 setVisibility (v,MAX_DEPTH);
254 void BranchObj::setLinkColor ()
256 // Overloaded from LinkableMapObj
257 // BranchObj can use color of heading
261 if (model->getMapLinkColorHint()==HeadingColor)
262 LinkableMapObj::setLinkColor (heading->getColor() );
264 LinkableMapObj::setLinkColor ();
268 void BranchObj::setColorSubtree(QColor col)
271 for (int i=0; i<treeItem->branchCount(); ++i)
272 treeItem->getBranchObjNum(i)->setColorSubtree(col);
275 void BranchObj::updateContentSize()
282 void BranchObj::positionContents()
284 for (int i=0; i<floatimage.size(); ++i )
285 floatimage.at(i)->reposition();
286 OrnamentedObj::positionContents();
289 void BranchObj::move (double x, double y)
291 OrnamentedObj::move (x,y);
292 for (int i=0; i<floatimage.size(); ++i )
293 floatimage.at(i)->reposition();
297 void BranchObj::move (QPointF p)
302 void BranchObj::moveBy (double x, double y)
304 OrnamentedObj::moveBy (x,y);
305 for (int i=0; i<treeItem->branchCount(); ++i)
306 treeItem->getBranchObjNum(i)->moveBy (x,y);
310 void BranchObj::moveBy (QPointF p)
312 moveBy (p.x(), p.y());
316 void BranchObj::positionBBox()
318 QPointF ap=getAbsPos();
319 bbox.moveTopLeft (ap);
323 frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
325 // Update links to other branches
326 for (int i=0; i<xlink.size(); ++i)
327 xlink.at(i)->updateXLink();
330 void BranchObj::calcBBoxSize()
332 QSizeF heading_r=heading->getSize();
333 qreal heading_w=(qreal) heading_r.width() ;
334 qreal heading_h=(qreal) heading_r.height() ;
335 QSizeF sysflags_r; //FIXME-1 =systemFlags->getSize();
336 qreal sysflags_h=0;//sysflags_r.height();
337 qreal sysflags_w=0;//sysflags_r.width();
338 QSizeF stanflags_r; //FIXME-1 =standardFlags->getSize();
339 qreal stanflags_h=0; //stanflags_r.height();
340 qreal stanflags_w=0; //stanflags_r.width();
344 // set width to sum of all widths
345 w=heading_w + sysflags_w + stanflags_w;
346 // set height to maximum needed height
347 h=max (sysflags_h,stanflags_h);
350 // Save the dimension of flags and heading
351 ornamentsBBox.setSize ( QSizeF(w,h));
353 // clickBox includes Flags and Heading
354 clickBox.setSize (ornamentsBBox.size() );
359 topPad=botPad=leftPad=rightPad=0;
360 if (includeImagesVer || includeImagesHor)
362 if (treeItem->imageCount()>0)
364 for (int i=0; i<floatimage.size(); ++i )
366 rp=floatimage.at(i)->getRelPos();
367 if (includeImagesVer)
370 topPad=max (topPad,-rp.y()-h);
371 if (rp.y()+floatimage.at(i)->height() > 0)
372 botPad=max (botPad,rp.y()+floatimage.at(i)->height());
374 if (includeImagesHor)
376 if (orientation==LinkableMapObj::RightOfCenter)
379 leftPad=max (leftPad,-rp.x()-w);
380 if (rp.x()+floatimage.at(i)->width() > 0)
381 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
385 leftPad=max (leftPad,-rp.x());
386 if (rp.x()+floatimage.at(i)->width() > w)
387 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
397 w+=frame->getPadding();
398 h+=frame->getPadding();
401 bbox.setSize (QSizeF (w,h));
404 void BranchObj::setDockPos()
406 // Sets childpos and parpos depending on orientation
407 if (getOrientation()==LinkableMapObj::LeftOfCenter )
410 ornamentsBBox.bottomLeft().x(),
413 ornamentsBBox.bottomRight().x(),
418 ornamentsBBox.bottomRight().x(),
421 ornamentsBBox.bottomLeft().x(),
426 void BranchObj::updateHeading()
430 qWarning ("BranchObj::udpateHeading treeItem==NULL");
433 heading->setText (treeItem->getHeading() );
437 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
439 // Cloudy stuff can be hidden during exports
440 // FIXME-1 if (hidden) return "";
442 // Update of note is usually done while unselecting a branch
443 // if (isNoteInEditor) getNoteFromTextEditor(); //FIXME-2 moved to TreeItem
446 QString scrolledAttr;
447 if ( ((BranchItem*)treeItem)->isScrolled() )
448 scrolledAttr=attribut ("scrolled","yes");
452 // save area, if not scrolled
454 if (!((BranchItem*) (treeItem->parent()) )->isScrolled() )
457 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
458 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
459 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
460 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
465 // Providing an ID for a branch makes export to XHTML easier
467 if (treeItem->xlinkCount()>0)
468 idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
472 s=beginElement ("branch"
477 +getIncludeImageAttr() );
481 s+=valueElement("heading", treeItem->getHeading(),
482 attribut ("textColor",QColor(heading->getColor()).name()));
485 if (frame->getFrameType()!=FrameObj::NoFrame)
486 s+=frame->saveToDir ();
488 // save names of flags set
489 s+=standardFlags->saveToDir(tmpdir,prefix,0);
492 for (int i=0; i<floatimage.size(); ++i)
493 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
496 if (!treeItem->getNoteObj().isEmpty() )
497 s+=treeItem->getNoteObj().saveToDir();
500 for (int i=0; i<treeItem->branchCount(); ++i)
501 s+=treeItem->getBranchObjNum(i)->saveToDir(tmpdir,prefix,offset);
504 QString ol; // old link
505 QString cl; // current link
506 for (int i=0; i<xlink.size(); ++i)
508 cl=xlink.at(i)->saveToDir();
515 qWarning (QString("Ignoring of duplicate xLink in %1").arg(treeItem->getHeading()));
520 s+=endElement ("branch");
524 void BranchObj::addXLink (XLinkObj *xlo)
530 void BranchObj::removeXLinkRef (XLinkObj *xlo)
532 xlink.removeAt (xlink.indexOf(xlo));
535 void BranchObj::deleteXLink(XLinkObj *xlo)
538 if (!xlo->isUsed()) delete (xlo);
541 void BranchObj::deleteXLinkAt (int i)
543 XLinkObj *xlo=xlink.at(i);
545 if (!xlo->isUsed()) delete(xlo);
548 XLinkObj* BranchObj::XLinkAt (int i)
553 BranchObj* BranchObj::XLinkTargetAt (int i)
555 if (i>=0 && i<xlink.size())
558 return xlink.at(i)->otherBranch (this);
563 void BranchObj::setIncludeImagesVer(bool b)
571 bool BranchObj::getIncludeImagesVer()
573 return includeImagesVer;
576 void BranchObj::setIncludeImagesHor(bool b)
584 bool BranchObj::getIncludeImagesHor()
586 return includeImagesHor;
589 QString BranchObj::getIncludeImageAttr()
592 if (includeImagesVer)
593 a=attribut ("incImgV","true");
595 a=attribut ("incImgV","false");
596 if (includeImagesHor)
597 a+=attribut ("incImgH","true");
599 a+=attribut ("incImgH","false");
603 FloatImageObj* BranchObj::addFloatImage ()
605 FloatImageObj *newfi=new FloatImageObj (scene,this);
606 floatimage.append (newfi);
607 if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
608 newfi->setVisibility (false);
610 newfi->setVisibility(visible);
619 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
621 FloatImageObj *newfi=new FloatImageObj (scene,this);
622 floatimage.append (newfi);
624 if (((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
625 newfi->setVisibility (false);
627 newfi->setVisibility(visible);
636 FloatImageObj* BranchObj::getFirstFloatImage ()
638 return floatimage.first();
641 FloatImageObj* BranchObj::getLastFloatImage ()
643 return floatimage.last();
646 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
648 return floatimage.at(i);
651 void BranchObj::removeFloatImage (FloatImageObj *fio)
653 int i=floatimage.indexOf (fio);
654 if (i>-1) delete (floatimage.takeAt (i));
660 void BranchObj::savePosInAngle ()
662 // Save position in angle
663 for (int i=0; i<treeItem->branchCount(); ++i)
664 treeItem->getBranchObjNum(i)->angle=i;
667 void BranchObj::setDefAttr (BranchModification mod)
670 switch (treeItem->depth())
672 case 0: fontsize=16; break;
673 case 1: fontsize=12; break;
674 default: fontsize=10; break;
678 setLinkStyle(getDefLinkStyle());
679 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
680 font.setPointSize(fontsize);
681 heading->setFont(font );
684 setColor (((BranchObj*)(parObj))->getColor());
689 BranchObj* BranchObj::addBranch() // FIXME-3 still needed?
691 BranchObj* newbo=new BranchObj(scene,this);
692 newbo->setParObj(this);
693 newbo->setDefAttr(NewBranch);
694 /* FIXME-2 treeItem not set yet!!!
695 if ( ((BranchItem*)treeItem)->isScrolled() )
696 newbo->setVisibility (false);
698 newbo->setVisibility(visible);
705 BranchObj* BranchObj::addBranch(BranchObj* bo)
707 BranchObj* newbo=new BranchObj(scene,this);
708 //FIXME-1 branch.append (newbo);
710 newbo->setParObj(this);
711 newbo->setDefAttr(MovedBranch);
712 if ( ((BranchItem*)treeItem)->isScrolled() )
713 newbo->setVisibility (false);
715 newbo->setVisibility(bo->visible);
721 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
723 //FIXME-1 branch.append (bo);
724 bo->setParObj (this);
725 //FIXME-2 bo->depth=depth+1;
726 bo->setDefAttr(MovedBranch);
727 BranchItem *bi=(BranchItem*)treeItem;
728 if ( bi->isScrolled() ) bi->tmpUnscroll();
729 //setLastSelectedBranch (bo); //FIXME-3 needed?
733 BranchObj* BranchObj::insertBranch(int pos)
736 // Add new bo and resort branches
737 BranchObj *newbo=addBranch ();
738 newbo->angle=pos-0.5;
739 //FIXME-1 qSort (branch.begin(),branch.end(), isAbove);
743 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
746 // Add new bo and resort branches
748 BranchObj *newbo=addBranch (bo);
749 //FIXME-1 qSort (branch.begin(),branch.end(), isAbove);
753 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
756 // Add new bo and resort branches
758 //FIXME-4 branch.append (bo);
759 bo->setParObj (this);
760 //FIXME-2 bo->depth=depth+1;
761 bo->setDefAttr (MovedBranch);
762 BranchItem *bi=(BranchItem*)treeItem;
763 if ( bi->isScrolled() ) bi->tmpUnscroll();
764 //setLastSelectedBranch (bo); //FIXME-3 needed?
765 //FIXME-2 qSort (branch.begin(),branch.end(), isAbove);
769 void BranchObj::removeBranchHere(BranchObj* borem) // FIXME-1 getNum no longer available
772 // This removes the branch bo from list, but
773 // inserts its children at the place of bo
775 bo=borem->getLastBranch();
776 int pos=borem->getNum();
779 bo->linkTo (this,pos+1);
780 bo=borem->getLastBranch();
782 removeBranch (borem);
786 void BranchObj::removeChildren() // FIXME-3 not needed here
791 void BranchObj::removeBranch(BranchObj* bo) // FIXME-1 not needed here
794 // if bo is not in branch remove returns false, we
797 int i=branch.indexOf(bo);
803 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
808 void BranchObj::removeBranchPtr(BranchObj* bo) // FIXME-1 not needed here
811 int i=branch.indexOf(bo);
816 qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
821 bool BranchObj::canMoveBranchUp()
823 /* FIXME-1 move to BranchItem
824 if (!parObj || depth==1) return false;
825 BranchObj* par=(BranchObj*)parObj;
826 if (this==par->getTreeItem()->getFirstBranch())
834 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // FIXME-1
838 int i=branch.indexOf(bo1);
840 { // -1 if bo1 not found
841 treeItem->getBranchObjNum(i)->angle--;
842 treeItem->getBranchObjNum(i-1)->angle++;
843 qSort (branch.begin(),branch.end(), isAbove);
844 return treeItem->getBranchObjNum(i);
850 bool BranchObj::canMoveBranchDown()
852 /* FIXME-1 move to BranchItem
853 if (!parObj|| depth==1) return false;
854 BranchObj* par=(BranchObj*)parObj;
855 if (this==par->getTreeItem()->getLastBranch())
863 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// FIXME-1
867 int i=branch.indexOf(bo1);
869 if (i <treeItem->branchCount())
872 treeItem->getBranchObjNum(i)->angle++;
873 treeItem->getBranchObjNum(j)->angle--;
874 qSort (branch.begin(),branch.end(), isAbove);
875 return treeItem->getBranchObjNum(i);
881 void BranchObj::sortChildren() //FIXME-1
884 int childCount=branch.count();
886 bool madeChanges=false;
890 for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
891 BranchObj* curChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex);
892 BranchObj* prevChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex-1);
893 if(prevChild->heading->text().compare(curChild->heading->text())>0)
895 this->moveBranchUp(curChild);
904 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
906 // Find current parent and
907 // remove pointer to myself there
908 if (!dst) return NULL;
909 BranchObj *par=(BranchObj*)parObj;
911 par->removeBranchPtr (this);
916 // Create new pointer to myself at dst
917 if (pos<0||dst->getDepth()==0)
919 // links myself as last branch at dst
920 dst->addBranchPtr (this);
925 // inserts me at pos in parent of dst
928 BranchObj *bo=dst->insertBranchPtr (this,pos);
929 bo->setDefAttr(MovedBranch);
939 void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
941 qreal th = bboxTotal.height();
942 int depth=treeItem->depth();
946 QString h=QString (depth,' ');
947 h+=treeItem->getHeading();
950 QPointF pp; if (parObj) pp=parObj->getChildPos();
951 cout << "BO::alignRelTo ";
952 cout<<h.toStdString();
953 cout << " d="<<depth<<
954 //cout<< " ref="<<ref<<
955 " bbox.tL="<<bboxTotal.topLeft()<<
957 // " relPos="<<relPos<<
959 " w="<<bbox.width()<<
960 " h="<<bbox.height()<<
961 // " orient="<<orientation<<
962 // " alignSelf="<<alignSelf<<
963 // " scrolled="<<((BranchItem*)treeItem)->isScrolled()<<
964 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
965 // " hidden="<<hidden<<
973 if (depth==1 && parObj)
975 // Position relatively, if needed
976 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
978 // Calc angle to mapCenter if I am a mainbranch
979 // needed for reordering the mainbranches clockwise
981 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
982 (int)(y() - parObj->getChildPos().y() ) ) );
986 // Align myself depending on orientation and parent, but
987 // only if I am not a mainbranch or mapcenter itself
989 if (anim.isAnimated())
994 LinkableMapObj::Orientation o;
995 o=parObj->getOrientation();
999 case LinkableMapObj::LeftOfCenter:
1000 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1001 //move (ref.x() , ref.y() + (th-bbox.height())/2 );
1003 case LinkableMapObj::RightOfCenter:
1004 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1007 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1013 if ( ((BranchItem*)treeItem)->isScrolled() ) return;
1015 // Set reference point for alignment of children
1017 if (orientation==LinkableMapObj::LeftOfCenter)
1018 ref2.setX(bbox.topLeft().x() - linkwidth);
1020 ref2.setX(bbox.topRight().x() + linkwidth);
1023 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1025 ref2.setY(ref.y() );
1027 // Align the children depending on reference point
1028 for (int i=0; i<treeItem->branchCount(); ++i)
1030 if (!treeItem->getBranchNum(i)->isHidden())
1032 treeItem->getBranchObjNum(i)->alignRelativeTo (ref2,true);
1034 // append next branch below current one
1035 ref2.setY(ref2.y() + treeItem->getBranchObjNum(i)->getBBoxSizeWithChildren().height() );
1041 void BranchObj::reposition()
1043 /* TODO testing only
1044 if (!treeItem->getHeading().isEmpty())
1045 cout << "BO::reposition "<<qPrintable(treeItem->getHeading())<<endl;
1047 cout << "BO::reposition ???"<<endl;
1048 // cout << " orient="<<orientation<<endl;
1051 if (treeItem->depth()==0)
1053 // only calculate the sizes once. If the deepest LMO
1054 // changes its height,
1055 // all upper LMOs have to change, too.
1056 calcBBoxSizeWithChildren();
1057 updateLink(); // This update is needed if the scene is resized
1058 // due to excessive moving of a FIO
1060 alignRelativeTo ( QPointF (absPos.x(),
1061 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1062 //FIXME-2 qSort (branch.begin(),branch.end(), isAbove);
1063 positionBBox(); // Reposition bbox and contents
1066 // This is only important for moving branches:
1067 // For editing a branch it isn't called...
1068 alignRelativeTo ( QPointF (absPos.x(),
1069 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1073 void BranchObj::unsetAllRepositionRequests()
1075 repositionRequest=false;
1076 for (int i=0; i<treeItem->branchCount(); ++i)
1077 treeItem->getBranchObjNum(i)->unsetAllRepositionRequests();
1081 QPolygonF BranchObj::shape()
1085 QRectF r=getTotalBBox();
1086 if (orientation==LinkableMapObj::LeftOfCenter)
1089 <<QPointF (bbox.topLeft().x(), r.topLeft().y() )
1091 <<bbox.bottomRight()
1092 <<QPointF (bbox.bottomLeft().x(), r.bottomLeft().y() ) ;
1096 <<QPointF (bbox.topRight().x(), r.topRight().y() )
1099 <<QPointF (bbox.bottomRight().x(), r.bottomRight().y() ) ;
1103 QRectF BranchObj::getTotalBBox()
1107 if ( ((BranchItem*)treeItem)->isScrolled() ) return r;
1109 for (int i=0; i<treeItem->branchCount(); ++i)
1110 if (!treeItem->getBranchNum(i)->isHidden())
1111 r=addBBox(treeItem->getBranchObjNum(i)->getTotalBBox(),r);
1113 /* FIXME-3 lots of occurences of treeItem->getBranchObjNum(i) in branchobj.cpp
1114 better check if they are not NULL and maybe simplify...
1115 (have been NULL at least in calcBBoxSizeWithChilds...)
1119 FIXME-1 for (int i=0; i<floatimage.size(); ++i)
1120 if (!floatimage.at(i)->isHidden())
1121 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1126 QRectF BranchObj::getBBoxSizeWithChildren()
1131 void BranchObj::calcBBoxSizeWithChildren()
1133 // This is initially called only from reposition and
1134 // and only for mapcenter. So it won't be
1135 // called more than once for a single user
1139 // Calculate size of LMO including all children (to align them later)
1140 bboxTotal.setX(bbox.x() );
1141 bboxTotal.setY(bbox.y() );
1143 // if branch is scrolled, ignore children, but still consider floatimages
1144 BranchItem *bi=(BranchItem*)treeItem;
1145 if ( bi->isScrolled() )
1147 bboxTotal.setWidth (bbox.width());
1148 bboxTotal.setHeight(bbox.height());
1154 bboxTotal.setWidth (0);
1155 bboxTotal.setHeight(0);
1158 bboxTotal.setX (parObj->x());
1159 bboxTotal.setY (parObj->y());
1162 bboxTotal.setX (bbox.x());
1163 bboxTotal.setY (bbox.y());
1170 // Now calculate recursivly
1172 // maximum of widths
1174 for (int i=0; i<treeItem->branchCount(); i++)
1176 if (!bi->getBranchNum(i)->isHidden())
1178 bi->getBranchObjNum(i)->calcBBoxSizeWithChildren();
1179 br=bi->getBranchObjNum(i)->getBBoxSizeWithChildren();
1180 r.setWidth( max (br.width(), r.width() ));
1181 r.setHeight(br.height() + r.height() );
1182 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1185 // Add myself and also
1186 // add width of link to sum if necessary
1187 if (bi->branchCount()<1)
1188 bboxTotal.setWidth (bbox.width() + r.width() );
1190 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1192 bboxTotal.setHeight(max (r.height(), bbox.height()));
1196 void BranchObj::select() // FIXME-4 try to get rid of this in BO completely
1198 cout << "BO::select()\n";
1199 textEditor->setText(treeItem->getNoteObj().getNote() );
1200 QString fnh=treeItem->getNoteObj().getFilenameHint();
1202 textEditor->setFilenameHint(treeItem->getNoteObj().getFilenameHint() );
1204 textEditor->setFilenameHint(getHeading() );
1205 textEditor->setFontHint (treeItem->getNoteObj().getFontHint() );
1206 //isNoteInEditor=true;
1208 // set selected and visible
1209 LinkableMapObj::select();
1211 //if (po) po->setLastSelectedBranch(this); needed?
1213 // temporary unscroll, if we have scrolled parents somewhere
1214 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1216 //moved to vymmodel or vymview...
1217 // Show URL and link in statusbar
1219 if (!url.isEmpty()) status+="URL: "+url+" ";
1220 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1221 if (!status.isEmpty()) mainWindow->statusMessage (status);
1224 updateFlagsToolbar();
1227 model->updateActions();
1232 void BranchObj::unselect() //FIXME-4 should not be needed
1234 cout << "BO::unselect()\n";
1235 LinkableMapObj::unselect();
1236 // Delete any messages like vymLink in StatusBar
1237 mainWindow->statusMessage (""); //this causes segfault, when MainWindow is already gone in global destructor on quitting vym
1239 // Save current note
1240 if (isNoteInEditor) getNoteFromTextEditor();
1241 isNoteInEditor=false;
1243 // reset temporary unscroll, if we have scrolled parents somewhere
1244 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1246 // Erase content of editor
1247 textEditor->setInactive();
1249 // unselect all buttons in toolbar
1250 standardFlagsDefault->updateToolbar();
1254 QString BranchObj::getSelectString()
1256 return model->getSelectString (this);
1259 void BranchObj::setAnimation(const AnimPoint &ap)
1264 bool BranchObj::animate()
1267 if ( anim.isAnimated() )
1272 parObj->reposition(); // we might have been relinked meanwhile