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";
28 BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s)
30 // cout << "Const BranchObj (s) called from MapCenterObj (s)\n";
35 BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)
37 // cout << "Const BranchObj (s,p)\n";
40 depth=p->getDepth()+1;
42 // Calc angle to mapCenter if I am a mainbranch
43 // needed for reordering the mainbranches clockwise
45 angle=getAngle (QPointF (x() - parObj->getChildPos().x() ,
46 (y() - parObj->getChildPos().y() ) ) );
50 BranchObj::~BranchObj ()
52 // If I'm animated, I need to un-animate myself first
53 if (anim.isAnimated() )
55 anim.setAnimated (false);
56 model->stopAnimation (this);
59 cout << "Destr BranchObj of "<<this<<" ("<<treeItem->getHeading().toStdString()<<")"<<endl;
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);
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 (lmo->getDepth()<2) off=0;
159 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
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 depth=parObj->getDepth()+1;
217 setLinkStyle (getDefLinkStyle() );
222 void BranchObj::setVisibility(bool v, int toDepth)
224 BranchItem *bi=(BranchItem*)treeItem;
225 if (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 cout << "BO::updateHeading: "<<treeItem->getHeading().toStdString()<<endl;
435 heading->setText (treeItem->getHeading() );
439 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
441 // Cloudy stuff can be hidden during exports
442 // FIXME-1 if (hidden) return "";
444 // Update of note is usually done while unselecting a branch
445 // if (isNoteInEditor) getNoteFromTextEditor(); //FIXME-2 moved to TreeItem
448 QString scrolledAttr;
449 if ( ((BranchItem*)treeItem)->isScrolled() )
450 scrolledAttr=attribut ("scrolled","yes");
454 // save area, if not scrolled
456 if (!((BranchItem*) (treeItem->parent()) )->isScrolled() )
459 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
460 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
461 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
462 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
467 // Providing an ID for a branch makes export to XHTML easier
469 if (treeItem->xlinkCount()>0)
470 idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
474 s=beginElement ("branch"
479 +getIncludeImageAttr() );
483 s+=valueElement("heading", treeItem->getHeading(),
484 attribut ("textColor",QColor(heading->getColor()).name()));
487 if (frame->getFrameType()!=FrameObj::NoFrame)
488 s+=frame->saveToDir ();
490 // save names of flags set
491 s+=standardFlags->saveToDir(tmpdir,prefix,0);
494 for (int i=0; i<floatimage.size(); ++i)
495 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
498 if (!treeItem->getNoteObj().isEmpty() )
499 s+=treeItem->getNoteObj().saveToDir();
502 for (int i=0; i<treeItem->branchCount(); ++i)
503 s+=treeItem->getBranchObjNum(i)->saveToDir(tmpdir,prefix,offset);
506 QString ol; // old link
507 QString cl; // current link
508 for (int i=0; i<xlink.size(); ++i)
510 cl=xlink.at(i)->saveToDir();
517 qWarning (QString("Ignoring of duplicate xLink in %1").arg(treeItem->getHeading()));
522 s+=endElement ("branch");
526 void BranchObj::addXLink (XLinkObj *xlo)
532 void BranchObj::removeXLinkRef (XLinkObj *xlo)
534 xlink.removeAt (xlink.indexOf(xlo));
537 void BranchObj::deleteXLink(XLinkObj *xlo)
540 if (!xlo->isUsed()) delete (xlo);
543 void BranchObj::deleteXLinkAt (int i)
545 XLinkObj *xlo=xlink.at(i);
547 if (!xlo->isUsed()) delete(xlo);
550 XLinkObj* BranchObj::XLinkAt (int i)
555 BranchObj* BranchObj::XLinkTargetAt (int i)
557 if (i>=0 && i<xlink.size())
560 return xlink.at(i)->otherBranch (this);
565 void BranchObj::setIncludeImagesVer(bool b)
573 bool BranchObj::getIncludeImagesVer()
575 return includeImagesVer;
578 void BranchObj::setIncludeImagesHor(bool b)
586 bool BranchObj::getIncludeImagesHor()
588 return includeImagesHor;
591 QString BranchObj::getIncludeImageAttr()
594 if (includeImagesVer)
595 a=attribut ("incImgV","true");
597 a=attribut ("incImgV","false");
598 if (includeImagesHor)
599 a+=attribut ("incImgH","true");
601 a+=attribut ("incImgH","false");
605 FloatImageObj* BranchObj::addFloatImage ()
607 FloatImageObj *newfi=new FloatImageObj (scene,this);
608 floatimage.append (newfi);
609 if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
610 newfi->setVisibility (false);
612 newfi->setVisibility(visible);
621 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
623 FloatImageObj *newfi=new FloatImageObj (scene,this);
624 floatimage.append (newfi);
626 if (((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
627 newfi->setVisibility (false);
629 newfi->setVisibility(visible);
638 FloatImageObj* BranchObj::getFirstFloatImage ()
640 return floatimage.first();
643 FloatImageObj* BranchObj::getLastFloatImage ()
645 return floatimage.last();
648 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
650 return floatimage.at(i);
653 void BranchObj::removeFloatImage (FloatImageObj *fio)
655 int i=floatimage.indexOf (fio);
656 if (i>-1) delete (floatimage.takeAt (i));
662 void BranchObj::savePosInAngle ()
664 // Save position in angle
665 for (int i=0; i<treeItem->branchCount(); ++i)
666 treeItem->getBranchObjNum(i)->angle=i;
669 void BranchObj::setDefAttr (BranchModification mod)
674 case 0: fontsize=16; break;
675 case 1: fontsize=12; break;
676 default: fontsize=10; break;
680 setLinkStyle(getDefLinkStyle());
681 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
682 font.setPointSize(fontsize);
683 heading->setFont(font );
686 setColor (((BranchObj*)(parObj))->getColor());
691 BranchObj* BranchObj::addBranch()
693 BranchObj* newbo=new BranchObj(scene,this);
694 newbo->setParObj(this);
695 newbo->setDefAttr(NewBranch);
696 /* FIXME-2 treeItem not set yet!!!
697 if ( ((BranchItem*)treeItem)->isScrolled() )
698 newbo->setVisibility (false);
700 newbo->setVisibility(visible);
707 BranchObj* BranchObj::addBranch(BranchObj* bo)
709 BranchObj* newbo=new BranchObj(scene,this);
710 //FIXME-1 branch.append (newbo);
712 newbo->setParObj(this);
713 newbo->setDefAttr(MovedBranch);
714 if ( ((BranchItem*)treeItem)->isScrolled() )
715 newbo->setVisibility (false);
717 newbo->setVisibility(bo->visible);
723 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
725 //FIXME-1 branch.append (bo);
726 bo->setParObj (this);
728 bo->setDefAttr(MovedBranch);
729 BranchItem *bi=(BranchItem*)treeItem;
730 if ( bi->isScrolled() ) bi->tmpUnscroll();
731 //setLastSelectedBranch (bo); //FIXME-3 needed?
735 BranchObj* BranchObj::insertBranch(int pos)
738 // Add new bo and resort branches
739 BranchObj *newbo=addBranch ();
740 newbo->angle=pos-0.5;
741 //FIXME-1 qSort (branch.begin(),branch.end(), isAbove);
745 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
748 // Add new bo and resort branches
750 BranchObj *newbo=addBranch (bo);
751 //FIXME-1 qSort (branch.begin(),branch.end(), isAbove);
755 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
758 // Add new bo and resort branches
760 //FIXME-1 branch.append (bo);
761 bo->setParObj (this);
763 bo->setDefAttr (MovedBranch);
764 BranchItem *bi=(BranchItem*)treeItem;
765 if ( bi->isScrolled() ) bi->tmpUnscroll();
766 //setLastSelectedBranch (bo); //FIXME-3 needed?
767 //FIXME-1 qSort (branch.begin(),branch.end(), isAbove);
771 void BranchObj::removeBranchHere(BranchObj* borem) // FIXME-1 getNum no longer available
774 // This removes the branch bo from list, but
775 // inserts its children at the place of bo
777 bo=borem->getLastBranch();
778 int pos=borem->getNum();
781 bo->linkTo (this,pos+1);
782 bo=borem->getLastBranch();
784 removeBranch (borem);
788 void BranchObj::removeChildren()
793 void BranchObj::removeBranch(BranchObj* bo) // FIXME-1 not needed here
796 // if bo is not in branch remove returns false, we
799 int i=branch.indexOf(bo);
805 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
810 void BranchObj::removeBranchPtr(BranchObj* bo) // FIXME-1 not needed here
813 int i=branch.indexOf(bo);
818 qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
823 bool BranchObj::canMoveBranchUp()
825 /* FIXME-1 move to BranchItem
826 if (!parObj || depth==1) return false;
827 BranchObj* par=(BranchObj*)parObj;
828 if (this==par->getTreeItem()->getFirstBranch())
836 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // FIXME-1
840 int i=branch.indexOf(bo1);
842 { // -1 if bo1 not found
843 treeItem->getBranchObjNum(i)->angle--;
844 treeItem->getBranchObjNum(i-1)->angle++;
845 qSort (branch.begin(),branch.end(), isAbove);
846 return treeItem->getBranchObjNum(i);
852 bool BranchObj::canMoveBranchDown()
854 /* FIXME-1 move to BranchItem
855 if (!parObj|| depth==1) return false;
856 BranchObj* par=(BranchObj*)parObj;
857 if (this==par->getTreeItem()->getLastBranch())
865 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// FIXME-1
869 int i=branch.indexOf(bo1);
871 if (i <treeItem->branchCount())
874 treeItem->getBranchObjNum(i)->angle++;
875 treeItem->getBranchObjNum(j)->angle--;
876 qSort (branch.begin(),branch.end(), isAbove);
877 return treeItem->getBranchObjNum(i);
883 void BranchObj::sortChildren() //FIXME-1
886 int childCount=branch.count();
888 bool madeChanges=false;
892 for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
893 BranchObj* curChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex);
894 BranchObj* prevChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex-1);
895 if(prevChild->heading->text().compare(curChild->heading->text())>0)
897 this->moveBranchUp(curChild);
906 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
908 // Find current parent and
909 // remove pointer to myself there
910 if (!dst) return NULL;
911 BranchObj *par=(BranchObj*)parObj;
913 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);
939 void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
941 qreal th = bboxTotal.height();
944 QString h=QString (treeItem->depth(),' ');
945 h+=treeItem->getHeading();
948 QPointF pp; if (parObj) pp=parObj->getChildPos();
949 cout << "BO::alignRelTo ";
950 cout<<h.toStdString();
951 // cout << " d="<<treeItem->depth()<<
952 cout<< " ref="<<ref<<
953 " bbox.tL="<<bboxTotal.topLeft()<<
955 // " relPos="<<relPos<<
957 " w="<<bbox.width()<<
958 " h="<<bbox.height()<<
959 // " orient="<<orientation<<
960 // " alignSelf="<<alignSelf<<
961 // " scrolled="<<((BranchItem*)treeItem)->isScrolled()<<
962 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
963 // " hidden="<<hidden<<
973 // Position relatively, if needed
974 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
976 // Calc angle to mapCenter if I am a mainbranch
977 // needed for reordering the mainbranches clockwise
979 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
980 (int)(y() - parObj->getChildPos().y() ) ) );
984 // Align myself depending on orientation and parent, but
985 // only if I am not a mainbranch or mapcenter itself
987 if (anim.isAnimated())
992 LinkableMapObj::Orientation o;
993 o=parObj->getOrientation();
997 case LinkableMapObj::LeftOfCenter:
998 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
999 //move (ref.x() , ref.y() + (th-bbox.height())/2 );
1001 case LinkableMapObj::RightOfCenter:
1002 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1005 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1011 if ( ((BranchItem*)treeItem)->isScrolled() ) return;
1013 // Set reference point for alignment of children
1015 if (orientation==LinkableMapObj::LeftOfCenter)
1016 ref2.setX(bbox.topLeft().x() - linkwidth);
1018 ref2.setX(bbox.topRight().x() + linkwidth);
1021 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1023 ref2.setY(ref.y() );
1025 // Align the children depending on reference point
1026 for (int i=0; i<treeItem->branchCount(); ++i)
1028 if (!treeItem->getBranchNum(i)->isHidden())
1030 treeItem->getBranchObjNum(i)->alignRelativeTo (ref2,true);
1032 // append next branch below current one
1033 ref2.setY(ref2.y() + treeItem->getBranchObjNum(i)->getBBoxSizeWithChildren().height() );
1039 void BranchObj::reposition()
1041 /* TODO testing only
1042 if (!treeItem->getHeading().isEmpty())
1043 cout << "BO::reposition "<<qPrintable(treeItem->getHeading())<<endl;
1045 cout << "BO::reposition ???"<<endl;
1046 // cout << " orient="<<orientation<<endl;
1051 // only calculate the sizes once. If the deepest LMO
1052 // changes its height,
1053 // all upper LMOs have to change, too.
1054 calcBBoxSizeWithChildren();
1055 updateLink(); // This update is needed if the scene is resized
1056 // due to excessive moving of a FIO
1058 alignRelativeTo ( QPointF (absPos.x(),
1059 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1060 //FIXME-2 qSort (branch.begin(),branch.end(), isAbove);
1061 positionBBox(); // Reposition bbox and contents
1064 // This is only important for moving branches:
1065 // For editing a branch it isn't called...
1066 alignRelativeTo ( QPointF (absPos.x(),
1067 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1071 void BranchObj::unsetAllRepositionRequests()
1073 repositionRequest=false;
1074 for (int i=0; i<treeItem->branchCount(); ++i)
1075 treeItem->getBranchObjNum(i)->unsetAllRepositionRequests();
1079 QPolygonF BranchObj::shape()
1083 QRectF r=getTotalBBox();
1084 if (orientation==LinkableMapObj::LeftOfCenter)
1087 <<QPointF (bbox.topLeft().x(), r.topLeft().y() )
1089 <<bbox.bottomRight()
1090 <<QPointF (bbox.bottomLeft().x(), r.bottomLeft().y() ) ;
1094 <<QPointF (bbox.topRight().x(), r.topRight().y() )
1097 <<QPointF (bbox.bottomRight().x(), r.bottomRight().y() ) ;
1101 QRectF BranchObj::getTotalBBox()
1105 if ( ((BranchItem*)treeItem)->isScrolled() ) return r;
1107 for (int i=0; i<treeItem->branchCount(); ++i)
1108 if (!treeItem->getBranchNum(i)->isHidden())
1109 r=addBBox(treeItem->getBranchObjNum(i)->getTotalBBox(),r);
1112 FIXME-1 for (int i=0; i<floatimage.size(); ++i)
1113 if (!floatimage.at(i)->isHidden())
1114 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1119 QRectF BranchObj::getBBoxSizeWithChildren()
1124 void BranchObj::calcBBoxSizeWithChildren()
1126 // This is initially called only from reposition and
1127 // and only for mapcenter. So it won't be
1128 // called more than once for a single user
1132 // Calculate size of LMO including all children (to align them later)
1133 bboxTotal.setX(bbox.x() );
1134 bboxTotal.setY(bbox.y() );
1136 // if branch is scrolled, ignore children, but still consider floatimages
1137 BranchItem *bi=(BranchItem*)treeItem;
1138 if ( bi->isScrolled() )
1140 bboxTotal.setWidth (bbox.width());
1141 bboxTotal.setHeight(bbox.height());
1147 bboxTotal.setWidth (0);
1148 bboxTotal.setHeight(0);
1151 bboxTotal.setX (parObj->x());
1152 bboxTotal.setY (parObj->y());
1155 bboxTotal.setX (bbox.x());
1156 bboxTotal.setY (bbox.y());
1163 // Now calculate recursivly
1165 // maximum of widths
1167 for (int i=0; i<treeItem->branchCount(); ++i)
1169 if (!bi->getBranchNum(i)->isHidden())
1171 bi->getBranchObjNum(i)->calcBBoxSizeWithChildren();
1172 br=bi->getBranchObjNum(i)->getBBoxSizeWithChildren();
1173 r.setWidth( max (br.width(), r.width() ));
1174 r.setHeight(br.height() + r.height() );
1175 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1178 // Add myself and also
1179 // add width of link to sum if necessary
1180 if (bi->branchCount()<1)
1181 bboxTotal.setWidth (bbox.width() + r.width() );
1183 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1185 bboxTotal.setHeight(max (r.height(), bbox.height()));
1189 void BranchObj::select() // FIXME-4 try to get rid of this in BO completely
1191 cout << "BO::select()\n";
1192 textEditor->setText(treeItem->getNoteObj().getNote() );
1193 QString fnh=treeItem->getNoteObj().getFilenameHint();
1195 textEditor->setFilenameHint(treeItem->getNoteObj().getFilenameHint() );
1197 textEditor->setFilenameHint(getHeading() );
1198 textEditor->setFontHint (treeItem->getNoteObj().getFontHint() );
1199 //isNoteInEditor=true;
1201 // set selected and visible
1202 LinkableMapObj::select();
1204 //if (po) po->setLastSelectedBranch(this); needed?
1206 // temporary unscroll, if we have scrolled parents somewhere
1207 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1209 //moved to vymmodel or vymview...
1210 // Show URL and link in statusbar
1212 if (!url.isEmpty()) status+="URL: "+url+" ";
1213 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1214 if (!status.isEmpty()) mainWindow->statusMessage (status);
1217 updateFlagsToolbar();
1220 model->updateActions();
1225 void BranchObj::unselect() //FIXME-4 should not be needed
1227 cout << "BO::unselect()\n";
1228 LinkableMapObj::unselect();
1229 // Delete any messages like vymLink in StatusBar
1230 mainWindow->statusMessage (""); //this causes segfault, when MainWindow is already gone in global destructor on quitting vym
1232 // Save current note
1233 if (isNoteInEditor) getNoteFromTextEditor();
1234 isNoteInEditor=false;
1236 // reset temporary unscroll, if we have scrolled parents somewhere
1237 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1239 // Erase content of editor
1240 textEditor->setInactive();
1242 // unselect all buttons in toolbar
1243 standardFlagsDefault->updateToolbar();
1247 QString BranchObj::getSelectString()
1249 return model->getSelectString (this);
1252 void BranchObj::setAnimation(const AnimPoint &ap)
1257 bool BranchObj::animate()
1260 if ( anim.isAnimated() )
1265 parObj->reposition(); // we might have been relinked meanwhile