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 LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
431 for (int i=0; i<treeItem->branchCount(); ++i)
433 lmo=treeItem->getBranchObjNum(i)->findMapObj(p, excludeLMO);
434 if (lmo != NULL) return lmo;
439 if (inBox (p,clickBox) && (this != excludeLMO) && isVisibleObj() )
442 // Search float images
443 for (int i=0; i<floatimage.size(); ++i )
444 if (inBox(p,floatimage.at(i)->getClickBox()) &&
445 (floatimage.at(i) != excludeLMO) &&
446 floatimage.at(i)->getParObj()!= excludeLMO &&
447 floatimage.at(i)->isVisibleObj()
448 ) return floatimage.at(i);
453 LinkableMapObj* BranchObj::findID (QString sid)
457 for (int i=0; i<treeItem->branchCount(); ++i)
459 lmo=treeItem->getBranchObjNum(i)->findID (sid);
460 if (lmo != NULL) return lmo;
464 if (sid==objID) return this;
468 // Search float images
469 for (int i=0; i<floatimage.size(); ++i )
470 if (floatimage.at(i)->inBox(p) &&
471 (floatimage.at(i) != excludeLMO) &&
472 floatimage.at(i)->getParObj()!= excludeLMO &&
473 floatimage.at(i)->isVisibleObj()
474 ) return floatimage.at(i);
479 void BranchObj::updateHeading()
483 qWarning ("BranchObj::udpateHeading treeItem==NULL");
486 cout << "BO::updateHeading: "<<treeItem->getHeading().toStdString()<<endl;
487 heading->setText (treeItem->getHeading() );
491 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
493 // Cloudy stuff can be hidden during exports
494 // FIXME-1 if (hidden) return "";
496 // Update of note is usually done while unselecting a branch
497 // if (isNoteInEditor) getNoteFromTextEditor(); //FIXME-2 moved to TreeItem
500 QString scrolledAttr;
501 if ( ((BranchItem*)treeItem)->isScrolled() )
502 scrolledAttr=attribut ("scrolled","yes");
506 // save area, if not scrolled
508 if (!((BranchItem*) (treeItem->parent()) )->isScrolled() )
511 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
512 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
513 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
514 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
519 // Providing an ID for a branch makes export to XHTML easier
521 if (treeItem->xlinkCount()>0)
522 idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
526 s=beginElement ("branch"
531 +getIncludeImageAttr() );
535 s+=valueElement("heading", treeItem->getHeading(),
536 attribut ("textColor",QColor(heading->getColor()).name()));
539 if (frame->getFrameType()!=FrameObj::NoFrame)
540 s+=frame->saveToDir ();
542 // save names of flags set
543 s+=standardFlags->saveToDir(tmpdir,prefix,0);
546 for (int i=0; i<floatimage.size(); ++i)
547 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
550 if (!treeItem->getNoteObj().isEmpty() )
551 s+=treeItem->getNoteObj().saveToDir();
554 for (int i=0; i<treeItem->branchCount(); ++i)
555 s+=treeItem->getBranchObjNum(i)->saveToDir(tmpdir,prefix,offset);
558 QString ol; // old link
559 QString cl; // current link
560 for (int i=0; i<xlink.size(); ++i)
562 cl=xlink.at(i)->saveToDir();
569 qWarning (QString("Ignoring of duplicate xLink in %1").arg(treeItem->getHeading()));
574 s+=endElement ("branch");
578 void BranchObj::addXLink (XLinkObj *xlo)
584 void BranchObj::removeXLinkRef (XLinkObj *xlo)
586 xlink.removeAt (xlink.indexOf(xlo));
589 void BranchObj::deleteXLink(XLinkObj *xlo)
592 if (!xlo->isUsed()) delete (xlo);
595 void BranchObj::deleteXLinkAt (int i)
597 XLinkObj *xlo=xlink.at(i);
599 if (!xlo->isUsed()) delete(xlo);
602 XLinkObj* BranchObj::XLinkAt (int i)
607 BranchObj* BranchObj::XLinkTargetAt (int i)
609 if (i>=0 && i<xlink.size())
612 return xlink.at(i)->otherBranch (this);
617 void BranchObj::setIncludeImagesVer(bool b)
625 bool BranchObj::getIncludeImagesVer()
627 return includeImagesVer;
630 void BranchObj::setIncludeImagesHor(bool b)
638 bool BranchObj::getIncludeImagesHor()
640 return includeImagesHor;
643 QString BranchObj::getIncludeImageAttr()
646 if (includeImagesVer)
647 a=attribut ("incImgV","true");
649 a=attribut ("incImgV","false");
650 if (includeImagesHor)
651 a+=attribut ("incImgH","true");
653 a+=attribut ("incImgH","false");
657 FloatImageObj* BranchObj::addFloatImage ()
659 FloatImageObj *newfi=new FloatImageObj (scene,this);
660 floatimage.append (newfi);
661 if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
662 newfi->setVisibility (false);
664 newfi->setVisibility(visible);
673 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
675 FloatImageObj *newfi=new FloatImageObj (scene,this);
676 floatimage.append (newfi);
678 if (((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
679 newfi->setVisibility (false);
681 newfi->setVisibility(visible);
690 FloatImageObj* BranchObj::getFirstFloatImage ()
692 return floatimage.first();
695 FloatImageObj* BranchObj::getLastFloatImage ()
697 return floatimage.last();
700 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
702 return floatimage.at(i);
705 void BranchObj::removeFloatImage (FloatImageObj *fio)
707 int i=floatimage.indexOf (fio);
708 if (i>-1) delete (floatimage.takeAt (i));
714 void BranchObj::savePosInAngle ()
716 // Save position in angle
717 for (int i=0; i<treeItem->branchCount(); ++i)
718 treeItem->getBranchObjNum(i)->angle=i;
721 void BranchObj::setDefAttr (BranchModification mod)
726 case 0: fontsize=16; break;
727 case 1: fontsize=12; break;
728 default: fontsize=10; break;
732 setLinkStyle(getDefLinkStyle());
733 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
734 font.setPointSize(fontsize);
735 heading->setFont(font );
738 setColor (((BranchObj*)(parObj))->getColor());
743 BranchObj* BranchObj::addBranch()
745 BranchObj* newbo=new BranchObj(scene,this);
746 //FIXME-1 branch.append (newbo);
747 newbo->setParObj(this);
748 newbo->setDefAttr(NewBranch);
749 /* FIXME-2 treeItem not set yet!!!
750 if ( ((BranchItem*)treeItem)->isScrolled() )
751 newbo->setVisibility (false);
753 newbo->setVisibility(visible);
760 BranchObj* BranchObj::addBranch(BranchObj* bo)
762 BranchObj* newbo=new BranchObj(scene,this);
763 //FIXME-1 branch.append (newbo);
765 newbo->setParObj(this);
766 newbo->setDefAttr(MovedBranch);
767 if ( ((BranchItem*)treeItem)->isScrolled() )
768 newbo->setVisibility (false);
770 newbo->setVisibility(bo->visible);
776 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
778 //FIXME-1 branch.append (bo);
779 bo->setParObj (this);
781 bo->setDefAttr(MovedBranch);
782 BranchItem *bi=(BranchItem*)treeItem;
783 if ( bi->isScrolled() ) bi->tmpUnscroll();
784 //setLastSelectedBranch (bo); //FIXME-3 needed?
788 BranchObj* BranchObj::insertBranch(int pos)
791 // Add new bo and resort branches
792 BranchObj *newbo=addBranch ();
793 newbo->angle=pos-0.5;
794 //FIXME-1 qSort (branch.begin(),branch.end(), isAbove);
798 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
801 // Add new bo and resort branches
803 BranchObj *newbo=addBranch (bo);
804 //FIXME-1 qSort (branch.begin(),branch.end(), isAbove);
808 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
811 // Add new bo and resort branches
813 //FIXME-1 branch.append (bo);
814 bo->setParObj (this);
816 bo->setDefAttr (MovedBranch);
817 BranchItem *bi=(BranchItem*)treeItem;
818 if ( bi->isScrolled() ) bi->tmpUnscroll();
819 //setLastSelectedBranch (bo); //FIXME-3 needed?
820 //FIXME-1 qSort (branch.begin(),branch.end(), isAbove);
824 void BranchObj::removeBranchHere(BranchObj* borem) // FIXME-1 getNum no longer available
827 // This removes the branch bo from list, but
828 // inserts its children at the place of bo
830 bo=borem->getLastBranch();
831 int pos=borem->getNum();
834 bo->linkTo (this,pos+1);
835 bo=borem->getLastBranch();
837 removeBranch (borem);
841 void BranchObj::removeChildren()
846 void BranchObj::removeBranch(BranchObj* bo) // FIXME-1 not needed here
849 // if bo is not in branch remove returns false, we
852 int i=branch.indexOf(bo);
858 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
863 void BranchObj::removeBranchPtr(BranchObj* bo) // FIXME-1 not needed here
866 int i=branch.indexOf(bo);
871 qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
876 bool BranchObj::canMoveBranchUp()
878 /* FIXME-1 move to BranchItem
879 if (!parObj || depth==1) return false;
880 BranchObj* par=(BranchObj*)parObj;
881 if (this==par->getTreeItem()->getFirstBranch())
889 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // FIXME-1
893 int i=branch.indexOf(bo1);
895 { // -1 if bo1 not found
896 treeItem->getBranchObjNum(i)->angle--;
897 treeItem->getBranchObjNum(i-1)->angle++;
898 qSort (branch.begin(),branch.end(), isAbove);
899 return treeItem->getBranchObjNum(i);
905 bool BranchObj::canMoveBranchDown()
907 /* FIXME-1 move to BranchItem
908 if (!parObj|| depth==1) return false;
909 BranchObj* par=(BranchObj*)parObj;
910 if (this==par->getTreeItem()->getLastBranch())
918 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// FIXME-1
922 int i=branch.indexOf(bo1);
924 if (i <treeItem->branchCount())
927 treeItem->getBranchObjNum(i)->angle++;
928 treeItem->getBranchObjNum(j)->angle--;
929 qSort (branch.begin(),branch.end(), isAbove);
930 return treeItem->getBranchObjNum(i);
936 void BranchObj::sortChildren() //FIXME-1
939 int childCount=branch.count();
941 bool madeChanges=false;
945 for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
946 BranchObj* curChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex);
947 BranchObj* prevChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex-1);
948 if(prevChild->heading->text().compare(curChild->heading->text())>0)
950 this->moveBranchUp(curChild);
959 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
961 // Find current parent and
962 // remove pointer to myself there
963 if (!dst) return NULL;
964 BranchObj *par=(BranchObj*)parObj;
966 par->removeBranchPtr (this);
970 // Create new pointer to myself at dst
971 if (pos<0||dst->getDepth()==0)
973 // links myself as last branch at dst
974 dst->addBranchPtr (this);
979 // inserts me at pos in parent of dst
982 BranchObj *bo=dst->insertBranchPtr (this,pos);
983 bo->setDefAttr(MovedBranch);
992 void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
994 qreal th = bboxTotal.height();
997 QString h=QString (treeItem->depth(),' ');
998 h+=treeItem->getHeading();
1001 QPointF pp; if (parObj) pp=parObj->getChildPos();
1002 cout << "BO::alignRelTo ";
1003 cout<<h.toStdString();
1004 // cout << " d="<<treeItem->depth()<<
1005 cout<< " ref="<<ref<<
1006 " bbox.tL="<<bboxTotal.topLeft()<<
1007 " absPos="<<absPos<<
1008 // " relPos="<<relPos<<
1010 " w="<<bbox.width()<<
1011 " h="<<bbox.height()<<
1012 // " orient="<<orientation<<
1013 // " alignSelf="<<alignSelf<<
1014 // " scrolled="<<((BranchItem*)treeItem)->isScrolled()<<
1015 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
1016 // " hidden="<<hidden<<
1026 // Position relatively, if needed
1027 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
1029 // Calc angle to mapCenter if I am a mainbranch
1030 // needed for reordering the mainbranches clockwise
1032 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
1033 (int)(y() - parObj->getChildPos().y() ) ) );
1037 // Align myself depending on orientation and parent, but
1038 // only if I am not a mainbranch or mapcenter itself
1040 if (anim.isAnimated())
1045 LinkableMapObj::Orientation o;
1046 o=parObj->getOrientation();
1048 switch (orientation)
1050 case LinkableMapObj::LeftOfCenter:
1051 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1052 //move (ref.x() , ref.y() + (th-bbox.height())/2 );
1054 case LinkableMapObj::RightOfCenter:
1055 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1058 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1064 if ( ((BranchItem*)treeItem)->isScrolled() ) return;
1066 // Set reference point for alignment of children
1068 if (orientation==LinkableMapObj::LeftOfCenter)
1069 ref2.setX(bbox.topLeft().x() - linkwidth);
1071 ref2.setX(bbox.topRight().x() + linkwidth);
1074 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1076 ref2.setY(ref.y() );
1078 // Align the children depending on reference point
1079 for (int i=0; i<treeItem->branchCount(); ++i)
1081 if (!treeItem->getBranchNum(i)->isHidden())
1083 treeItem->getBranchObjNum(i)->alignRelativeTo (ref2,true);
1085 // append next branch below current one
1086 ref2.setY(ref2.y() + treeItem->getBranchObjNum(i)->getBBoxSizeWithChildren().height() );
1092 void BranchObj::reposition()
1094 /* TODO testing only
1095 if (!treeItem->getHeading().isEmpty())
1096 cout << "BO::reposition "<<qPrintable(treeItem->getHeading())<<endl;
1098 cout << "BO::reposition ???"<<endl;
1099 // cout << " orient="<<orientation<<endl;
1104 // only calculate the sizes once. If the deepest LMO
1105 // changes its height,
1106 // all upper LMOs have to change, too.
1107 calcBBoxSizeWithChildren();
1108 updateLink(); // This update is needed if the scene is resized
1109 // due to excessive moving of a FIO
1111 alignRelativeTo ( QPointF (absPos.x(),
1112 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1113 //FIXME-2 qSort (branch.begin(),branch.end(), isAbove);
1114 positionBBox(); // Reposition bbox and contents
1117 // This is only important for moving branches:
1118 // For editing a branch it isn't called...
1119 alignRelativeTo ( QPointF (absPos.x(),
1120 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1124 void BranchObj::unsetAllRepositionRequests()
1126 repositionRequest=false;
1127 for (int i=0; i<treeItem->branchCount(); ++i)
1128 treeItem->getBranchObjNum(i)->unsetAllRepositionRequests();
1132 QPolygonF BranchObj::shape()
1136 QRectF r=getTotalBBox();
1137 if (orientation==LinkableMapObj::LeftOfCenter)
1140 <<QPointF (bbox.topLeft().x(), r.topLeft().y() )
1142 <<bbox.bottomRight()
1143 <<QPointF (bbox.bottomLeft().x(), r.bottomLeft().y() ) ;
1147 <<QPointF (bbox.topRight().x(), r.topRight().y() )
1150 <<QPointF (bbox.bottomRight().x(), r.bottomRight().y() ) ;
1154 QRectF BranchObj::getTotalBBox()
1158 if ( ((BranchItem*)treeItem)->isScrolled() ) return r;
1160 for (int i=0; i<treeItem->branchCount(); ++i)
1161 if (!treeItem->getBranchNum(i)->isHidden())
1162 r=addBBox(treeItem->getBranchObjNum(i)->getTotalBBox(),r);
1165 FIXME-1 for (int i=0; i<floatimage.size(); ++i)
1166 if (!floatimage.at(i)->isHidden())
1167 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1172 QRectF BranchObj::getBBoxSizeWithChildren()
1177 void BranchObj::calcBBoxSizeWithChildren()
1179 // This is initially called only from reposition and
1180 // and only for mapcenter. So it won't be
1181 // called more than once for a single user
1185 // Calculate size of LMO including all children (to align them later)
1186 bboxTotal.setX(bbox.x() );
1187 bboxTotal.setY(bbox.y() );
1189 // if branch is scrolled, ignore children, but still consider floatimages
1190 BranchItem *bi=(BranchItem*)treeItem;
1191 if ( bi->isScrolled() )
1193 bboxTotal.setWidth (bbox.width());
1194 bboxTotal.setHeight(bbox.height());
1200 bboxTotal.setWidth (0);
1201 bboxTotal.setHeight(0);
1204 bboxTotal.setX (parObj->x());
1205 bboxTotal.setY (parObj->y());
1208 bboxTotal.setX (bbox.x());
1209 bboxTotal.setY (bbox.y());
1216 // Now calculate recursivly
1218 // maximum of widths
1220 for (int i=0; i<treeItem->branchCount(); ++i)
1222 if (!bi->getBranchNum(i)->isHidden())
1224 bi->getBranchObjNum(i)->calcBBoxSizeWithChildren();
1225 br=bi->getBranchObjNum(i)->getBBoxSizeWithChildren();
1226 r.setWidth( max (br.width(), r.width() ));
1227 r.setHeight(br.height() + r.height() );
1228 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1231 // Add myself and also
1232 // add width of link to sum if necessary
1233 if (bi->branchCount()<1)
1234 bboxTotal.setWidth (bbox.width() + r.width() );
1236 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1238 bboxTotal.setHeight(max (r.height(), bbox.height()));
1242 void BranchObj::select() // FIXME-4 try to get rid of this in BO completely
1244 cout << "BO::select()\n";
1245 textEditor->setText(treeItem->getNoteObj().getNote() );
1246 QString fnh=treeItem->getNoteObj().getFilenameHint();
1248 textEditor->setFilenameHint(treeItem->getNoteObj().getFilenameHint() );
1250 textEditor->setFilenameHint(getHeading() );
1251 textEditor->setFontHint (treeItem->getNoteObj().getFontHint() );
1252 //isNoteInEditor=true;
1254 // set selected and visible
1255 LinkableMapObj::select();
1257 //if (po) po->setLastSelectedBranch(this); needed?
1259 // temporary unscroll, if we have scrolled parents somewhere
1260 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1262 //moved to vymmodel or vymview...
1263 // Show URL and link in statusbar
1265 if (!url.isEmpty()) status+="URL: "+url+" ";
1266 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1267 if (!status.isEmpty()) mainWindow->statusMessage (status);
1270 updateFlagsToolbar();
1273 model->updateActions();
1278 void BranchObj::unselect() //FIXME-4 should not be needed
1280 cout << "BO::unselect()\n";
1281 LinkableMapObj::unselect();
1282 // Delete any messages like vymLink in StatusBar
1283 mainWindow->statusMessage (""); //this causes segfault, when MainWindow is already gone in global destructor on quitting vym
1285 // Save current note
1286 if (isNoteInEditor) getNoteFromTextEditor();
1287 isNoteInEditor=false;
1289 // reset temporary unscroll, if we have scrolled parents somewhere
1290 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1292 // Erase content of editor
1293 textEditor->setInactive();
1295 // unselect all buttons in toolbar
1296 standardFlagsDefault->updateToolbar();
1300 QString BranchObj::getSelectString()
1302 return model->getSelectString (this);
1305 void BranchObj::setAnimation(const AnimPoint &ap)
1310 bool BranchObj::animate()
1313 if ( anim.isAnimated() )
1318 parObj->reposition(); // we might have been relinked meanwhile