3 // #include "texteditor.h"
4 #include "branchitem.h"
7 #include "mainwindow.h"
12 extern TextEditor *textEditor;
13 extern Main *mainWindow;
14 extern FlagRowObj *standardFlagsDefault;
17 /////////////////////////////////////////////////////////////////
19 /////////////////////////////////////////////////////////////////
21 BranchObj::BranchObj () :OrnamentedObj() // FIXME-3 needed at all?
23 // cout << "Const BranchObj ()\n";
29 BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s)
31 // cout << "Const BranchObj (s) called from MapCenterObj (s)\n";
36 BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)
38 // cout << "Const BranchObj (s,p)\n";
41 depth=p->getDepth()+1;
43 // Calc angle to mapCenter if I am a mainbranch
44 // needed for reordering the mainbranches clockwise
46 angle=getAngle (QPointF (x() - parObj->getChildPos().x() ,
47 (y() - parObj->getChildPos().y() ) ) );
51 BranchObj::~BranchObj ()
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 cout << "Destr BranchObj of "<<this<<" ("<<getHeading().toStdString()<<")"<<endl;
61 // Check, if this branch was the last child to be deleted
62 // If so, unset the scrolled flags in parent // FIXME-2 better do this in model?
65 BranchObj *po=(BranchObj*)parObj;
69 bo=((BranchObj*)parObj)->getLastBranch();
70 if (bo) po->unScroll();
76 bool BranchObj::operator< ( const BranchObj & other )
78 return angle < other.angle;
81 bool BranchObj::operator== ( const BranchObj & other )
83 return angle == other.angle;
86 void BranchObj::init ()
91 absPos+=parObj->getChildPos();
96 includeImagesVer=false;
97 includeImagesHor=false;
100 void BranchObj::copy (BranchObj* other)
102 OrnamentedObj::copy(other);
105 for (int i=0; i<other->treeItem->branchCount(); ++i)
106 // Make deep copy of b
107 // Because addBranch again calls copy for the children,
108 // Those will get a deep copy, too
109 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();
131 while (!branch.isEmpty())
132 delete branch.takeFirst();
135 bool isAbove (BranchObj* a, BranchObj *b)
137 if (a->angle < b->angle)
143 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
145 // Temporary link to lmo
146 // m is position of mouse pointer
147 // offset 0: default 1: below lmo -1 above lmo (if possible)
150 BranchObj* o=(BranchObj*)(lmo);
154 // ignore mapcenter and mainbranch
155 if (lmo->getDepth()<2) off=0;
162 depth=parObj->getDepth()+1;
164 // setLinkStyle calls updateLink, only set it once
165 if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
167 // Move temporary to new position at destination
168 // Usually the positioning would be done by reposition(),
169 // but then also the destination branch would "Jump" around...
170 // Better just do it approximately
172 { // new parent is the mapcenter itself
174 QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
175 m.y() - o->getChildPos().y() ));
176 if (p.x()<0) p.setX( p.x()-bbox.width() );
183 // new parent is just a branch, link to it
184 QRectF t=o->getBBoxSizeWithChildren();
185 if (o->getTreeItem()->getLastBranch())
186 y=t.y() + t.height() ;
193 // we want to link above lmo
194 y=o->y() - height() + 5;
196 // we want to link below lmo
197 // Bottom of sel should be 5 pixels above
198 // the bottom of the branch _below_ the target:
199 // Don't try to find that branch, guess 12 pixels
200 y=o->getChildPos().y() -height() + 12;
202 if (o->getOrientation()==LinkableMapObj::LeftOfCenter)
203 move ( o->getChildPos().x() - linkwidth, y );
205 move (o->getChildPos().x() + linkwidth, y );
208 // updateLink is called implicitly in move
212 void BranchObj::unsetParObjTmp()
219 depth=parObj->getDepth()+1;
220 setLinkStyle (getDefLinkStyle() );
225 void BranchObj::setVisibility(bool v, int toDepth)
227 BranchItem *bi=(BranchItem*)treeItem;
228 if (depth <= toDepth)
230 frame->setVisibility(v);
231 heading->setVisibility(v);
232 systemFlags->setVisibility(v);
233 standardFlags->setVisibility(v);
234 LinkableMapObj::setVisibility (v);
236 for (i=0; i<floatimage.size(); ++i)
237 floatimage.at(i)->setVisibility (v);
238 for (i=0; i<xlink.size(); ++i)
239 xlink.at(i)->setVisibility ();
241 // Only change children, if I am not scrolled
242 if (! bi->isScrolled() && (bi->depth() < toDepth))
244 // Now go recursivly through all children
245 for (i=0; i<treeItem->branchCount(); ++i)
246 branch.at(i)->setVisibility (v,toDepth);
248 } // depth <= toDepth
252 void BranchObj::setVisibility(bool v)
254 setVisibility (v,MAX_DEPTH);
258 void BranchObj::setLinkColor ()
260 // Overloaded from LinkableMapObj
261 // BranchObj can use color of heading
265 if (model->getMapLinkColorHint()==HeadingColor)
266 LinkableMapObj::setLinkColor (heading->getColor() );
268 LinkableMapObj::setLinkColor ();
272 void BranchObj::setColorSubtree(QColor col)
275 for (int i=0; i<treeItem->branchCount(); ++i)
276 branch.at(i)->setColorSubtree(col);
279 void BranchObj::positionContents()
281 for (int i=0; i<floatimage.size(); ++i )
282 floatimage.at(i)->reposition();
283 OrnamentedObj::positionContents();
286 void BranchObj::move (double x, double y)
288 OrnamentedObj::move (x,y);
289 for (int i=0; i<floatimage.size(); ++i )
290 floatimage.at(i)->reposition();
294 void BranchObj::move (QPointF p)
299 void BranchObj::moveBy (double x, double y)
301 OrnamentedObj::moveBy (x,y);
302 for (int i=0; i<treeItem->branchCount(); ++i)
303 branch.at(i)->moveBy (x,y);
307 void BranchObj::moveBy (QPointF p)
309 moveBy (p.x(), p.y());
313 void BranchObj::positionBBox()
315 QPointF ap=getAbsPos();
316 bbox.moveTopLeft (ap);
320 frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
322 // Update links to other branches
323 for (int i=0; i<xlink.size(); ++i)
324 xlink.at(i)->updateXLink();
327 void BranchObj::calcBBoxSize()
329 QSizeF heading_r=heading->getSize();
330 qreal heading_w=(qreal) heading_r.width() ;
331 qreal heading_h=(qreal) heading_r.height() ;
332 QSizeF sysflags_r=systemFlags->getSize();
333 qreal sysflags_h=sysflags_r.height();
334 qreal sysflags_w=sysflags_r.width();
335 QSizeF stanflags_r=standardFlags->getSize();
336 qreal stanflags_h=stanflags_r.height();
337 qreal stanflags_w=stanflags_r.width();
341 // set width to sum of all widths
342 w=heading_w + sysflags_w + stanflags_w;
343 // set height to maximum needed height
344 h=max (sysflags_h,stanflags_h);
347 // Save the dimension of flags and heading
348 ornamentsBBox.setSize ( QSizeF(w,h));
350 // clickBox includes Flags and Heading
351 clickBox.setSize (ornamentsBBox.size() );
356 topPad=botPad=leftPad=rightPad=0;
357 if (includeImagesVer || includeImagesHor)
359 if (treeItem->imageCount()>0)
361 for (int i=0; i<floatimage.size(); ++i )
363 rp=floatimage.at(i)->getRelPos();
364 if (includeImagesVer)
367 topPad=max (topPad,-rp.y()-h);
368 if (rp.y()+floatimage.at(i)->height() > 0)
369 botPad=max (botPad,rp.y()+floatimage.at(i)->height());
371 if (includeImagesHor)
373 if (orientation==LinkableMapObj::RightOfCenter)
376 leftPad=max (leftPad,-rp.x()-w);
377 if (rp.x()+floatimage.at(i)->width() > 0)
378 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
382 leftPad=max (leftPad,-rp.x());
383 if (rp.x()+floatimage.at(i)->width() > w)
384 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
394 w+=frame->getPadding();
395 h+=frame->getPadding();
398 bbox.setSize (QSizeF (w,h));
401 void BranchObj::setDockPos()
403 // Sets childpos and parpos depending on orientation
404 if (getOrientation()==LinkableMapObj::LeftOfCenter )
407 ornamentsBBox.bottomLeft().x(),
410 ornamentsBBox.bottomRight().x(),
415 ornamentsBBox.bottomRight().x(),
418 ornamentsBBox.bottomLeft().x(),
423 LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
427 for (int i=0; i<treeItem->branchCount(); ++i)
429 lmo=branch.at(i)->findMapObj(p, excludeLMO);
430 if (lmo != NULL) return lmo;
435 if (inBox (p,clickBox) && (this != excludeLMO) && isVisibleObj() )
438 // Search float images
439 for (int i=0; i<floatimage.size(); ++i )
440 if (inBox(p,floatimage.at(i)->getClickBox()) &&
441 (floatimage.at(i) != excludeLMO) &&
442 floatimage.at(i)->getParObj()!= excludeLMO &&
443 floatimage.at(i)->isVisibleObj()
444 ) return floatimage.at(i);
449 LinkableMapObj* BranchObj::findID (QString sid)
453 for (int i=0; i<treeItem->branchCount(); ++i)
455 lmo=branch.at(i)->findID (sid);
456 if (lmo != NULL) return lmo;
460 if (sid==objID) return this;
464 // Search float images
465 for (int i=0; i<floatimage.size(); ++i )
466 if (floatimage.at(i)->inBox(p) &&
467 (floatimage.at(i) != excludeLMO) &&
468 floatimage.at(i)->getParObj()!= excludeLMO &&
469 floatimage.at(i)->isVisibleObj()
470 ) return floatimage.at(i);
475 void BranchObj::setHeading(QString s)
477 heading->setText(s); // set new heading
478 calcBBoxSize(); // recalculate bbox
479 positionBBox(); // rearrange contents
483 void BranchObj::setHideTmp (HideTmpMode mode)
485 if (mode==HideExport && (hideExport|| hasHiddenExportParent() ) )
487 // Hide stuff according to hideExport flag and parents
488 setVisibility (false);
492 // Do not hide, but still take care of scrolled status
493 if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem))
494 setVisibility (false);
496 setVisibility (true);
500 // And take care of my children
501 for (int i=0; i<treeItem->branchCount(); ++i)
502 branch.at(i)->setHideTmp (mode);
505 bool BranchObj::hasHiddenExportParent()
507 // Calls parents recursivly to
508 // find out, if we or parents are temp. hidden
510 if (hidden || hideExport) return true;
512 BranchObj* bo=(BranchObj*)parObj;
514 return bo->hasHiddenExportParent();
519 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
521 // Cloudy stuff can be hidden during exports
522 if (hidden) return "";
524 // Update of note is usually done while unselecting a branch
525 // if (isNoteInEditor) getNoteFromTextEditor(); //FIXME-2 moved to TreeItem
528 QString scrolledAttr;
529 if ( ((BranchItem*)treeItem)->isScrolled() )
530 scrolledAttr=attribut ("scrolled","yes");
534 // save area, if not scrolled
536 if (!((BranchItem*) (treeItem->parent()) )->isScrolled() )
539 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
540 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
541 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
542 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
547 // Providing an ID for a branch makes export to XHTML easier
549 if (treeItem->xlinkCount()>0)
550 idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
554 s=beginElement ("branch"
559 +getIncludeImageAttr() );
563 s+=valueElement("heading", getHeading(),
564 attribut ("textColor",QColor(heading->getColor()).name()));
567 if (frame->getFrameType()!=FrameObj::NoFrame)
568 s+=frame->saveToDir ();
570 // save names of flags set
571 s+=standardFlags->saveToDir(tmpdir,prefix,0);
574 for (int i=0; i<floatimage.size(); ++i)
575 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
578 if (!treeItem->getNoteObj().isEmpty() )
579 s+=treeItem->getNoteObj().saveToDir();
582 for (int i=0; i<treeItem->branchCount(); ++i)
583 s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
586 QString ol; // old link
587 QString cl; // current link
588 for (int i=0; i<xlink.size(); ++i)
590 cl=xlink.at(i)->saveToDir();
597 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
602 s+=endElement ("branch");
606 void BranchObj::addXLink (XLinkObj *xlo)
612 void BranchObj::removeXLinkRef (XLinkObj *xlo)
614 xlink.removeAt (xlink.indexOf(xlo));
617 void BranchObj::deleteXLink(XLinkObj *xlo)
620 if (!xlo->isUsed()) delete (xlo);
623 void BranchObj::deleteXLinkAt (int i)
625 XLinkObj *xlo=xlink.at(i);
627 if (!xlo->isUsed()) delete(xlo);
630 XLinkObj* BranchObj::XLinkAt (int i)
635 BranchObj* BranchObj::XLinkTargetAt (int i)
637 if (i>=0 && i<xlink.size())
640 return xlink.at(i)->otherBranch (this);
645 void BranchObj::setIncludeImagesVer(bool b)
653 bool BranchObj::getIncludeImagesVer()
655 return includeImagesVer;
658 void BranchObj::setIncludeImagesHor(bool b)
666 bool BranchObj::getIncludeImagesHor()
668 return includeImagesHor;
671 QString BranchObj::getIncludeImageAttr()
674 if (includeImagesVer)
675 a=attribut ("incImgV","true");
677 a=attribut ("incImgV","false");
678 if (includeImagesHor)
679 a+=attribut ("incImgH","true");
681 a+=attribut ("incImgH","false");
685 FloatImageObj* BranchObj::addFloatImage ()
687 FloatImageObj *newfi=new FloatImageObj (scene,this);
688 floatimage.append (newfi);
689 if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
690 newfi->setVisibility (false);
692 newfi->setVisibility(visible);
701 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
703 FloatImageObj *newfi=new FloatImageObj (scene,this);
704 floatimage.append (newfi);
706 if (((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
707 newfi->setVisibility (false);
709 newfi->setVisibility(visible);
718 FloatImageObj* BranchObj::getFirstFloatImage ()
720 return floatimage.first();
723 FloatImageObj* BranchObj::getLastFloatImage ()
725 return floatimage.last();
728 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
730 return floatimage.at(i);
733 void BranchObj::removeFloatImage (FloatImageObj *fio)
735 int i=floatimage.indexOf (fio);
736 if (i>-1) delete (floatimage.takeAt (i));
742 void BranchObj::savePosInAngle ()
744 // Save position in angle
745 for (int i=0; i<treeItem->branchCount(); ++i)
746 branch.at(i)->angle=i;
749 void BranchObj::setDefAttr (BranchModification mod)
754 case 0: fontsize=16; break;
755 case 1: fontsize=12; break;
756 default: fontsize=10; break;
760 setLinkStyle(getDefLinkStyle());
761 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
762 font.setPointSize(fontsize);
763 heading->setFont(font );
766 setColor (((BranchObj*)(parObj))->getColor());
771 BranchObj* BranchObj::addBranch()
773 BranchObj* newbo=new BranchObj(scene,this);
774 branch.append (newbo);
775 newbo->setParObj(this);
776 newbo->setDefAttr(NewBranch);
777 newbo->setHeading ("new");
778 /* FIXME-2 treeItem not set yet!!!
779 if ( ((BranchItem*)treeItem)->isScrolled() )
780 newbo->setVisibility (false);
782 newbo->setVisibility(visible);
789 BranchObj* BranchObj::addBranch(BranchObj* bo)
791 BranchObj* newbo=new BranchObj(scene,this);
792 branch.append (newbo);
794 newbo->setParObj(this);
795 newbo->setDefAttr(MovedBranch);
796 if ( ((BranchItem*)treeItem)->isScrolled() )
797 newbo->setVisibility (false);
799 newbo->setVisibility(bo->visible);
805 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
808 bo->setParObj (this);
810 bo->setDefAttr(MovedBranch);
811 BranchItem *bi=(BranchItem*)treeItem;
812 if ( bi->isScrolled() ) bi->tmpUnscroll();
813 //setLastSelectedBranch (bo); //FIXME-3 needed?
817 BranchObj* BranchObj::insertBranch(int pos)
820 // Add new bo and resort branches
821 BranchObj *newbo=addBranch ();
822 newbo->angle=pos-0.5;
823 qSort (branch.begin(),branch.end(), isAbove);
827 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
830 // Add new bo and resort branches
832 BranchObj *newbo=addBranch (bo);
833 qSort (branch.begin(),branch.end(), isAbove);
837 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
840 // Add new bo and resort branches
843 bo->setParObj (this);
845 bo->setDefAttr (MovedBranch);
846 BranchItem *bi=(BranchItem*)treeItem;
847 if ( bi->isScrolled() ) bi->tmpUnscroll();
848 //setLastSelectedBranch (bo); //FIXME-3 needed?
849 qSort (branch.begin(),branch.end(), isAbove);
853 void BranchObj::removeBranchHere(BranchObj* borem) // FIXME-1 getNum no longer available
856 // This removes the branch bo from list, but
857 // inserts its children at the place of bo
859 bo=borem->getLastBranch();
860 int pos=borem->getNum();
863 bo->linkTo (this,pos+1);
864 bo=borem->getLastBranch();
866 removeBranch (borem);
870 void BranchObj::removeChildren()
875 void BranchObj::removeBranch(BranchObj* bo)
877 // if bo is not in branch remove returns false, we
880 int i=branch.indexOf(bo);
886 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
890 void BranchObj::removeBranchPtr(BranchObj* bo)
892 int i=branch.indexOf(bo);
897 qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
901 bool BranchObj::canMoveBranchUp()
903 /* FIXME-1 move to BranchItem
904 if (!parObj || depth==1) return false;
905 BranchObj* par=(BranchObj*)parObj;
906 if (this==par->getTreeItem()->getFirstBranch())
914 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
917 int i=branch.indexOf(bo1);
919 { // -1 if bo1 not found
920 branch.at(i)->angle--;
921 branch.at(i-1)->angle++;
922 qSort (branch.begin(),branch.end(), isAbove);
928 bool BranchObj::canMoveBranchDown()
930 /* FIXME-1 move to BranchItem
931 if (!parObj|| depth==1) return false;
932 BranchObj* par=(BranchObj*)parObj;
933 if (this==par->getTreeItem()->getLastBranch())
941 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
944 int i=branch.indexOf(bo1);
946 if (i <treeItem->branchCount())
949 branch.at(i)->angle++;
950 branch.at(j)->angle--;
951 qSort (branch.begin(),branch.end(), isAbove);
957 void BranchObj::sortChildren() //FIXME-1
960 int childCount=branch.count();
962 bool madeChanges=false;
966 for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
967 BranchObj* curChild=(BranchObj*)branch.at(curChildIndex);
968 BranchObj* prevChild=(BranchObj*)branch.at(curChildIndex-1);
969 if(prevChild->heading->text().compare(curChild->heading->text())>0)
971 this->moveBranchUp(curChild);
980 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
982 // Find current parent and
983 // remove pointer to myself there
984 if (!dst) return NULL;
985 BranchObj *par=(BranchObj*)parObj;
987 par->removeBranchPtr (this);
991 // Create new pointer to myself at dst
992 if (pos<0||dst->getDepth()==0)
994 // links myself as last branch at dst
995 dst->addBranchPtr (this);
1000 // inserts me at pos in parent of dst
1003 BranchObj *bo=dst->insertBranchPtr (this,pos);
1004 bo->setDefAttr(MovedBranch);
1013 void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
1015 qreal th = bboxTotal.height();
1018 QPointF pp; if (parObj) pp=parObj->getChildPos();
1019 cout << "BO::alignRelTo "<<qPrintable (getHeading());
1020 cout << " d="<<depth<<
1022 // " bbox.topLeft="<<bboxTotal.topLeft()<<
1023 " absPos="<<absPos<<
1024 // " relPos="<<relPos<<
1026 " width="<<bbox.width()<<
1027 " orient="<<orientation<<
1028 " alignSelf="<<alignSelf<<
1029 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
1030 // " hidden="<<hidden<<
1042 // Position relatively, if needed
1043 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
1045 // Calc angle to mapCenter if I am a mainbranch
1046 // needed for reordering the mainbranches clockwise
1048 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
1049 (int)(y() - parObj->getChildPos().y() ) ) );
1054 // Align myself depending on orientation and parent, but
1055 // only if I am not a mainbranch or mapcenter itself
1057 if (anim.isAnimated())
1062 LinkableMapObj::Orientation o;
1063 o=parObj->getOrientation();
1065 switch (orientation)
1067 case LinkableMapObj::LeftOfCenter:
1068 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1069 //move (ref.x() , ref.y() + (th-bbox.height())/2 );
1071 case LinkableMapObj::RightOfCenter:
1072 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1075 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1081 if ( ((BranchItem*)treeItem)->isScrolled() ) return;
1083 // Set reference point for alignment of children
1085 if (orientation==LinkableMapObj::LeftOfCenter)
1086 ref2.setX(bbox.topLeft().x() - linkwidth);
1088 ref2.setX(bbox.topRight().x() + linkwidth);
1091 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1093 ref2.setY(ref.y() );
1095 // Align the children depending on reference point
1096 for (int i=0; i<treeItem->branchCount(); ++i)
1098 if (!branch.at(i)->isHidden())
1100 branch.at(i)->alignRelativeTo (ref2,true);
1102 // append next branch below current one
1103 ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChildren().height() );
1109 void BranchObj::reposition()
1111 /* TODO testing only
1112 if (!getHeading().isEmpty())
1113 cout << "BO::reposition "<<qPrintable(getHeading())<<endl;
1115 cout << "BO::reposition ???"<<endl;
1117 cout << " orient="<<orientation<<endl;
1122 // only calculate the sizes once. If the deepest LMO
1123 // changes its height,
1124 // all upper LMOs have to change, too.
1125 calcBBoxSizeWithChildren();
1126 updateLink(); // This update is needed if the scene is resized
1127 // due to excessive moving of a FIO
1129 alignRelativeTo ( QPointF (absPos.x(),
1130 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1131 qSort (branch.begin(),branch.end(), isAbove);
1132 positionBBox(); // Reposition bbox and contents
1135 // This is only important for moving branches:
1136 // For editing a branch it isn't called...
1137 alignRelativeTo ( QPointF (absPos.x(),
1138 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1142 void BranchObj::unsetAllRepositionRequests()
1144 repositionRequest=false;
1145 for (int i=0; i<treeItem->branchCount(); ++i)
1146 branch.at(i)->unsetAllRepositionRequests();
1150 QPolygonF BranchObj::shape()
1154 QRectF r=getTotalBBox();
1155 if (orientation==LinkableMapObj::LeftOfCenter)
1158 <<QPointF (bbox.topLeft().x(), r.topLeft().y() )
1160 <<bbox.bottomRight()
1161 <<QPointF (bbox.bottomLeft().x(), r.bottomLeft().y() ) ;
1165 <<QPointF (bbox.topRight().x(), r.topRight().y() )
1168 <<QPointF (bbox.bottomRight().x(), r.bottomRight().y() ) ;
1172 QRectF BranchObj::getTotalBBox()
1176 if ( ((BranchItem*)treeItem)->isScrolled() ) return r;
1178 for (int i=0; i<treeItem->branchCount(); ++i)
1179 if (!branch.at(i)->isHidden())
1180 r=addBBox(branch.at(i)->getTotalBBox(),r);
1182 for (int i=0; i<floatimage.size(); ++i)
1183 if (!floatimage.at(i)->isHidden())
1184 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1189 QRectF BranchObj::getBBoxSizeWithChildren()
1194 void BranchObj::calcBBoxSizeWithChildren()
1196 // This is initially called only from reposition and
1197 // and only for mapcenter. So it won't be
1198 // called more than once for a single user
1202 // Calculate size of LMO including all children (to align them later)
1203 bboxTotal.setX(bbox.x() );
1204 bboxTotal.setY(bbox.y() );
1206 // if branch is scrolled, ignore children, but still consider floatimages
1207 if ( ((BranchItem*)treeItem)->isScrolled() )
1209 bboxTotal.setWidth (bbox.width());
1210 bboxTotal.setHeight(bbox.height());
1216 bboxTotal.setWidth (0);
1217 bboxTotal.setHeight(0);
1220 bboxTotal.setX (parObj->x());
1221 bboxTotal.setY (parObj->y());
1224 bboxTotal.setX (bbox.x());
1225 bboxTotal.setY (bbox.y());
1232 // Now calculate recursivly
1234 // maximum of widths
1236 for (int i=0; i<treeItem->branchCount(); ++i)
1238 if (!branch.at(i)->isHidden())
1240 branch.at(i)->calcBBoxSizeWithChildren();
1241 br=branch.at(i)->getBBoxSizeWithChildren();
1242 r.setWidth( max (br.width(), r.width() ));
1243 r.setHeight(br.height() + r.height() );
1244 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1247 // Add myself and also
1248 // add width of link to sum if necessary
1249 if (branch.isEmpty())
1250 bboxTotal.setWidth (bbox.width() + r.width() );
1252 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1254 bboxTotal.setHeight(max (r.height(), bbox.height()));
1258 void BranchObj::select() // FIXME-2 try to get rid of this in BO completely
1260 cout << "BO::select()\n";
1261 textEditor->setText(treeItem->getNoteObj().getNote() );
1262 QString fnh=treeItem->getNoteObj().getFilenameHint();
1264 textEditor->setFilenameHint(treeItem->getNoteObj().getFilenameHint() );
1266 textEditor->setFilenameHint(getHeading() );
1267 textEditor->setFontHint (treeItem->getNoteObj().getFontHint() );
1268 //isNoteInEditor=true;
1270 // set selected and visible
1271 LinkableMapObj::select();
1273 //if (po) po->setLastSelectedBranch(this); needed?
1275 // temporary unscroll, if we have scrolled parents somewhere
1276 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1278 //moved to vymmodel or vymview...
1279 // Show URL and link in statusbar
1281 if (!url.isEmpty()) status+="URL: "+url+" ";
1282 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1283 if (!status.isEmpty()) mainWindow->statusMessage (status);
1286 updateFlagsToolbar();
1289 model->updateActions();
1294 void BranchObj::unselect() //FIXME-3 should not be needed
1296 cout << "BO::unselect()\n";
1297 LinkableMapObj::unselect();
1298 // Delete any messages like vymLink in StatusBar
1299 mainWindow->statusMessage (""); //this causes segfault, when MainWindow is already gone in global destructor on quitting vym
1301 // Save current note
1302 if (isNoteInEditor) getNoteFromTextEditor();
1303 isNoteInEditor=false;
1305 // reset temporary unscroll, if we have scrolled parents somewhere
1306 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1308 // Erase content of editor
1309 textEditor->setInactive();
1311 // unselect all buttons in toolbar
1312 standardFlagsDefault->updateToolbar();
1316 QString BranchObj::getSelectString()
1318 return model->getSelectString (this);
1321 void BranchObj::setAnimation(const AnimPoint &ap)
1326 bool BranchObj::animate()
1329 if ( anim.isAnimated() )
1334 parObj->reposition(); // we might have been relinked meanwhile