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->branch.size(); ++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->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<branch.size(); ++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<branch.size(); ++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<branch.size(); ++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<branch.size(); ++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<branch.size(); ++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<branch.size(); ++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<branch.size(); ++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<branch.size(); ++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 BranchObj* BranchObj::getFirstBranch ()
904 return branch.first();
909 BranchObj* BranchObj::getLastBranch ()
912 return branch.last();
917 BranchObj* BranchObj::getBranchNum (int i)
919 if (i>=0 && i<branch.size())
925 bool BranchObj::canMoveBranchUp()
927 if (!parObj || depth==1) return false;
928 BranchObj* par=(BranchObj*)parObj;
929 if (this==par->getFirstBranch())
935 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
938 int i=branch.indexOf(bo1);
940 { // -1 if bo1 not found
941 branch.at(i)->angle--;
942 branch.at(i-1)->angle++;
943 qSort (branch.begin(),branch.end(), isAbove);
949 bool BranchObj::canMoveBranchDown()
951 if (!parObj|| depth==1) return false;
952 BranchObj* par=(BranchObj*)parObj;
953 if (this==par->getLastBranch())
959 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
962 int i=branch.indexOf(bo1);
964 if (i <branch.size())
967 branch.at(i)->angle++;
968 branch.at(j)->angle--;
969 qSort (branch.begin(),branch.end(), isAbove);
975 void BranchObj::sortChildren() //FIXME-1
978 int childCount=branch.count();
980 bool madeChanges=false;
984 for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
985 BranchObj* curChild=(BranchObj*)branch.at(curChildIndex);
986 BranchObj* prevChild=(BranchObj*)branch.at(curChildIndex-1);
987 if(prevChild->heading->text().compare(curChild->heading->text())>0)
989 this->moveBranchUp(curChild);
998 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
1000 // Find current parent and
1001 // remove pointer to myself there
1002 if (!dst) return NULL;
1003 BranchObj *par=(BranchObj*)parObj;
1005 par->removeBranchPtr (this);
1009 // Create new pointer to myself at dst
1010 if (pos<0||dst->getDepth()==0)
1012 // links myself as last branch at dst
1013 dst->addBranchPtr (this);
1018 // inserts me at pos in parent of dst
1021 BranchObj *bo=dst->insertBranchPtr (this,pos);
1022 bo->setDefAttr(MovedBranch);
1031 void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
1033 qreal th = bboxTotal.height();
1036 QPointF pp; if (parObj) pp=parObj->getChildPos();
1037 cout << "BO::alignRelTo "<<qPrintable (getHeading());
1038 cout << " d="<<depth<<
1040 // " bbox.topLeft="<<bboxTotal.topLeft()<<
1041 " absPos="<<absPos<<
1042 // " relPos="<<relPos<<
1044 " width="<<bbox.width()<<
1045 " orient="<<orientation<<
1046 " alignSelf="<<alignSelf<<
1047 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
1048 // " hidden="<<hidden<<
1060 // Position relatively, if needed
1061 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
1063 // Calc angle to mapCenter if I am a mainbranch
1064 // needed for reordering the mainbranches clockwise
1066 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
1067 (int)(y() - parObj->getChildPos().y() ) ) );
1072 // Align myself depending on orientation and parent, but
1073 // only if I am not a mainbranch or mapcenter itself
1075 if (anim.isAnimated())
1080 LinkableMapObj::Orientation o;
1081 o=parObj->getOrientation();
1083 switch (orientation)
1085 case LinkableMapObj::LeftOfCenter:
1086 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1087 //move (ref.x() , ref.y() + (th-bbox.height())/2 );
1089 case LinkableMapObj::RightOfCenter:
1090 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1093 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1099 if ( ((BranchItem*)treeItem)->isScrolled() ) return;
1101 // Set reference point for alignment of children
1103 if (orientation==LinkableMapObj::LeftOfCenter)
1104 ref2.setX(bbox.topLeft().x() - linkwidth);
1106 ref2.setX(bbox.topRight().x() + linkwidth);
1109 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1111 ref2.setY(ref.y() );
1113 // Align the children depending on reference point
1114 for (int i=0; i<branch.size(); ++i)
1116 if (!branch.at(i)->isHidden())
1118 branch.at(i)->alignRelativeTo (ref2,true);
1120 // append next branch below current one
1121 ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChildren().height() );
1127 void BranchObj::reposition()
1129 /* TODO testing only
1130 if (!getHeading().isEmpty())
1131 cout << "BO::reposition "<<qPrintable(getHeading())<<endl;
1133 cout << "BO::reposition ???"<<endl;
1135 cout << " orient="<<orientation<<endl;
1140 // only calculate the sizes once. If the deepest LMO
1141 // changes its height,
1142 // all upper LMOs have to change, too.
1143 calcBBoxSizeWithChildren();
1144 updateLink(); // This update is needed if the scene is resized
1145 // due to excessive moving of a FIO
1147 alignRelativeTo ( QPointF (absPos.x(),
1148 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1149 qSort (branch.begin(),branch.end(), isAbove);
1150 positionBBox(); // Reposition bbox and contents
1153 // This is only important for moving branches:
1154 // For editing a branch it isn't called...
1155 alignRelativeTo ( QPointF (absPos.x(),
1156 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1160 void BranchObj::unsetAllRepositionRequests()
1162 repositionRequest=false;
1163 for (int i=0; i<branch.size(); ++i)
1164 branch.at(i)->unsetAllRepositionRequests();
1168 QPolygonF BranchObj::shape()
1172 QRectF r=getTotalBBox();
1173 if (orientation==LinkableMapObj::LeftOfCenter)
1176 <<QPointF (bbox.topLeft().x(), r.topLeft().y() )
1178 <<bbox.bottomRight()
1179 <<QPointF (bbox.bottomLeft().x(), r.bottomLeft().y() ) ;
1183 <<QPointF (bbox.topRight().x(), r.topRight().y() )
1186 <<QPointF (bbox.bottomRight().x(), r.bottomRight().y() ) ;
1190 QRectF BranchObj::getTotalBBox()
1194 if ( ((BranchItem*)treeItem)->isScrolled() ) return r;
1196 for (int i=0; i<branch.size(); ++i)
1197 if (!branch.at(i)->isHidden())
1198 r=addBBox(branch.at(i)->getTotalBBox(),r);
1200 for (int i=0; i<floatimage.size(); ++i)
1201 if (!floatimage.at(i)->isHidden())
1202 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1207 QRectF BranchObj::getBBoxSizeWithChildren()
1212 void BranchObj::calcBBoxSizeWithChildren()
1214 // This is initially called only from reposition and
1215 // and only for mapcenter. So it won't be
1216 // called more than once for a single user
1220 // Calculate size of LMO including all children (to align them later)
1221 bboxTotal.setX(bbox.x() );
1222 bboxTotal.setY(bbox.y() );
1224 // if branch is scrolled, ignore children, but still consider floatimages
1225 if ( ((BranchItem*)treeItem)->isScrolled() )
1227 bboxTotal.setWidth (bbox.width());
1228 bboxTotal.setHeight(bbox.height());
1234 bboxTotal.setWidth (0);
1235 bboxTotal.setHeight(0);
1238 bboxTotal.setX (parObj->x());
1239 bboxTotal.setY (parObj->y());
1242 bboxTotal.setX (bbox.x());
1243 bboxTotal.setY (bbox.y());
1250 // Now calculate recursivly
1252 // maximum of widths
1254 for (int i=0; i<branch.size(); ++i)
1256 if (!branch.at(i)->isHidden())
1258 branch.at(i)->calcBBoxSizeWithChildren();
1259 br=branch.at(i)->getBBoxSizeWithChildren();
1260 r.setWidth( max (br.width(), r.width() ));
1261 r.setHeight(br.height() + r.height() );
1262 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1265 // Add myself and also
1266 // add width of link to sum if necessary
1267 if (branch.isEmpty())
1268 bboxTotal.setWidth (bbox.width() + r.width() );
1270 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1272 bboxTotal.setHeight(max (r.height(), bbox.height()));
1276 void BranchObj::select() // FIXME-2 try to get rid of this in BO completely
1278 cout << "BO::select()\n";
1279 textEditor->setText(treeItem->getNoteObj().getNote() );
1280 QString fnh=treeItem->getNoteObj().getFilenameHint();
1282 textEditor->setFilenameHint(treeItem->getNoteObj().getFilenameHint() );
1284 textEditor->setFilenameHint(getHeading() );
1285 textEditor->setFontHint (treeItem->getNoteObj().getFontHint() );
1286 //isNoteInEditor=true;
1288 // set selected and visible
1289 LinkableMapObj::select();
1291 //if (po) po->setLastSelectedBranch(this); needed?
1293 // temporary unscroll, if we have scrolled parents somewhere
1294 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1296 //moved to vymmodel or vymview...
1297 // Show URL and link in statusbar
1299 if (!url.isEmpty()) status+="URL: "+url+" ";
1300 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1301 if (!status.isEmpty()) mainWindow->statusMessage (status);
1304 updateFlagsToolbar();
1307 model->updateActions();
1312 void BranchObj::unselect() //FIXME-3 should not be needed
1314 cout << "BO::unselect()\n";
1315 LinkableMapObj::unselect();
1316 // Delete any messages like vymLink in StatusBar
1317 mainWindow->statusMessage (""); //this causes segfault, when MainWindow is already gone in global destructor on quitting vym
1319 // Save current note
1320 if (isNoteInEditor) getNoteFromTextEditor();
1321 isNoteInEditor=false;
1323 // reset temporary unscroll, if we have scrolled parents somewhere
1324 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1326 // Erase content of editor
1327 textEditor->setInactive();
1329 // unselect all buttons in toolbar
1330 standardFlagsDefault->updateToolbar();
1334 QString BranchObj::getSelectString()
1336 return model->getSelectString (this);
1339 void BranchObj::setAnimation(const AnimPoint &ap)
1344 bool BranchObj::animate()
1347 if ( anim.isAnimated() )
1352 parObj->reposition(); // we might have been relinked meanwhile