3 // #include "texteditor.h"
6 #include "mainwindow.h"
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<<endl;
60 // Check, if this branch was the last child to be deleted
61 // If so, unset the scrolled flags
63 BranchObj *po=(BranchObj*)parObj;
67 bo=((BranchObj*)parObj)->getLastBranch();
68 if (bo) po->unScroll();
73 bool BranchObj::operator< ( const BranchObj & other )
75 return angle < other.angle;
78 bool BranchObj::operator== ( const BranchObj & other )
80 return angle == other.angle;
83 void BranchObj::init ()
88 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));
113 scrolled=other->scrolled;
114 tmpUnscrolled=other->tmpUnscrolled;
115 setVisibility (other->visible);
122 void BranchObj::clear()
124 setVisibility (true);
126 while (!floatimage.isEmpty())
127 delete floatimage.takeFirst();
129 while (!xlink.isEmpty())
130 delete xlink.takeFirst();
132 while (!branch.isEmpty())
133 delete branch.takeFirst();
136 bool isAbove (BranchObj* a, BranchObj *b)
138 if (a->angle < b->angle)
144 int BranchObj::getNum()
147 return ((BranchObj*)parObj)->getNum (this);
152 int BranchObj::getNum(BranchObj *bo)
154 return branch.indexOf (bo);
157 int BranchObj::getFloatImageNum(FloatImageObj *fio)
159 return floatimage.indexOf(fio);
162 int BranchObj::countBranches()
164 return branch.count();
167 int BranchObj::countFloatImages()
169 return floatimage.count();
172 int BranchObj::countXLinks()
174 return xlink.count();
177 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
179 // Temporary link to lmo
180 // m is position of mouse pointer
181 // offset 0: default 1: below lmo -1 above lmo (if possible)
184 BranchObj* o=(BranchObj*)(lmo);
188 // ignore mapcenter and mainbranch
189 if (lmo->getDepth()<2) off=0;
196 depth=parObj->getDepth()+1;
198 // setLinkStyle calls updateLink, only set it once
199 if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
201 // Move temporary to new position at destination
202 // Usually the positioning would be done by reposition(),
203 // but then also the destination branch would "Jump" around...
204 // Better just do it approximately
206 { // new parent is the mapcenter itself
208 QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
209 m.y() - o->getChildPos().y() ));
210 if (p.x()<0) p.setX( p.x()-bbox.width() );
217 // new parent is just a branch, link to it
218 QRectF t=o->getBBoxSizeWithChildren();
219 if (o->getLastBranch())
220 y=t.y() + t.height() ;
227 // we want to link above lmo
228 y=o->y() - height() + 5;
230 // we want to link below lmo
231 // Bottom of sel should be 5 pixels above
232 // the bottom of the branch _below_ the target:
233 // Don't try to find that branch, guess 12 pixels
234 y=o->getChildPos().y() -height() + 12;
236 if (o->getOrientation()==LinkableMapObj::LeftOfCenter)
237 move ( o->getChildPos().x() - linkwidth, y );
239 move (o->getChildPos().x() + linkwidth, y );
242 // updateLink is called implicitly in move
246 void BranchObj::unsetParObjTmp()
253 depth=parObj->getDepth()+1;
254 setLinkStyle (getDefLinkStyle() );
259 void BranchObj::unScroll()
261 if (tmpUnscrolled) resetTmpUnscroll();
262 if (scrolled) toggleScroll();
265 void BranchObj::toggleScroll()
270 systemFlags->deactivate("scrolledright");
271 for (int i=0; i<branch.size(); ++i)
272 branch.at(i)->setVisibility(true);
276 systemFlags->activate("scrolledright");
277 for (int i=0; i<branch.size(); ++i)
278 branch.at(i)->setVisibility(false);
282 move (absPos.x(), absPos.y() );
286 bool BranchObj::isScrolled()
291 bool BranchObj::hasScrolledParent(BranchObj *start)
293 // Calls parents recursivly to
294 // find out, if we are scrolled at all.
295 // But ignore myself, just look at parents.
297 if (this !=start && scrolled) return true;
299 BranchObj* bo=(BranchObj*)(parObj);
301 return bo->hasScrolledParent(start);
306 void BranchObj::tmpUnscroll()
308 // Unscroll parent (recursivly)
309 BranchObj* bo=(BranchObj*)(parObj);
310 if (bo) bo->tmpUnscroll();
316 systemFlags->activate("tmpUnscrolledright");
321 void BranchObj::resetTmpUnscroll()
323 // Unscroll parent (recursivly)
324 BranchObj* bo=(BranchObj*)(parObj);
326 bo->resetTmpUnscroll();
332 systemFlags->deactivate("tmpUnscrolledright");
337 void BranchObj::setVisibility(bool v, int toDepth)
339 if (depth <= toDepth)
341 frame->setVisibility(v);
342 heading->setVisibility(v);
343 systemFlags->setVisibility(v);
344 standardFlags->setVisibility(v);
345 LinkableMapObj::setVisibility (v);
348 for (i=0; i<floatimage.size(); ++i)
349 floatimage.at(i)->setVisibility (v);
350 for (i=0; i<xlink.size(); ++i)
351 xlink.at(i)->setVisibility ();
353 // Only change children, if I am not scrolled
354 if (!scrolled && (depth < toDepth))
356 // Now go recursivly through all children
357 for (i=0; i<branch.size(); ++i)
358 branch.at(i)->setVisibility (v,toDepth);
360 } // depth <= toDepth
364 void BranchObj::setVisibility(bool v)
366 setVisibility (v,MAX_DEPTH);
370 void BranchObj::setLinkColor ()
372 // Overloaded from LinkableMapObj
373 // BranchObj can use color of heading
377 if (model->getMapLinkColorHint()==HeadingColor)
378 LinkableMapObj::setLinkColor (heading->getColor() );
380 LinkableMapObj::setLinkColor ();
384 void BranchObj::setColorSubtree(QColor col)
387 for (int i=0; i<branch.size(); ++i)
388 branch.at(i)->setColorSubtree(col);
391 void BranchObj::positionContents()
393 for (int i=0; i<floatimage.size(); ++i )
394 floatimage.at(i)->reposition();
395 OrnamentedObj::positionContents();
398 void BranchObj::move (double x, double y)
400 OrnamentedObj::move (x,y);
401 for (int i=0; i<floatimage.size(); ++i )
402 floatimage.at(i)->reposition();
406 void BranchObj::move (QPointF p)
411 void BranchObj::moveBy (double x, double y)
413 OrnamentedObj::moveBy (x,y);
414 for (int i=0; i<branch.size(); ++i)
415 branch.at(i)->moveBy (x,y);
419 void BranchObj::moveBy (QPointF p)
421 moveBy (p.x(), p.y());
425 void BranchObj::positionBBox()
427 QPointF ap=getAbsPos();
428 bbox.moveTopLeft (ap);
432 frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
434 // Update links to other branches
435 for (int i=0; i<xlink.size(); ++i)
436 xlink.at(i)->updateXLink();
439 void BranchObj::calcBBoxSize()
441 QSizeF heading_r=heading->getSize();
442 qreal heading_w=(qreal) heading_r.width() ;
443 qreal heading_h=(qreal) heading_r.height() ;
444 QSizeF sysflags_r=systemFlags->getSize();
445 qreal sysflags_h=sysflags_r.height();
446 qreal sysflags_w=sysflags_r.width();
447 QSizeF stanflags_r=standardFlags->getSize();
448 qreal stanflags_h=stanflags_r.height();
449 qreal stanflags_w=stanflags_r.width();
453 // set width to sum of all widths
454 w=heading_w + sysflags_w + stanflags_w;
455 // set height to maximum needed height
456 h=max (sysflags_h,stanflags_h);
459 // Save the dimension of flags and heading
460 ornamentsBBox.setSize ( QSizeF(w,h));
462 // clickBox includes Flags and Heading
463 clickBox.setSize (ornamentsBBox.size() );
468 topPad=botPad=leftPad=rightPad=0;
469 if (includeImagesVer || includeImagesHor)
471 if (countFloatImages()>0)
473 for (int i=0; i<floatimage.size(); ++i )
475 rp=floatimage.at(i)->getRelPos();
476 if (includeImagesVer)
479 topPad=max (topPad,-rp.y()-h);
480 if (rp.y()+floatimage.at(i)->height() > 0)
481 botPad=max (botPad,rp.y()+floatimage.at(i)->height());
483 if (includeImagesHor)
485 if (orientation==LinkableMapObj::RightOfCenter)
488 leftPad=max (leftPad,-rp.x()-w);
489 if (rp.x()+floatimage.at(i)->width() > 0)
490 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
494 leftPad=max (leftPad,-rp.x());
495 if (rp.x()+floatimage.at(i)->width() > w)
496 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
506 w+=frame->getPadding();
507 h+=frame->getPadding();
510 bbox.setSize (QSizeF (w,h));
513 void BranchObj::setDockPos()
515 // Sets childpos and parpos depending on orientation
516 if (getOrientation()==LinkableMapObj::LeftOfCenter )
519 ornamentsBBox.bottomLeft().x(),
522 ornamentsBBox.bottomRight().x(),
527 ornamentsBBox.bottomRight().x(),
530 ornamentsBBox.bottomLeft().x(),
535 LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
539 for (int i=0; i<branch.size(); ++i)
541 lmo=branch.at(i)->findMapObj(p, excludeLMO);
542 if (lmo != NULL) return lmo;
547 if (inBox (p,clickBox) && (this != excludeLMO) && isVisibleObj() )
550 // Search float images
551 for (int i=0; i<floatimage.size(); ++i )
552 if (inBox(p,floatimage.at(i)->getClickBox()) &&
553 (floatimage.at(i) != excludeLMO) &&
554 floatimage.at(i)->getParObj()!= excludeLMO &&
555 floatimage.at(i)->isVisibleObj()
556 ) return floatimage.at(i);
561 LinkableMapObj* BranchObj::findID (QString sid)
565 for (int i=0; i<branch.size(); ++i)
567 lmo=branch.at(i)->findID (sid);
568 if (lmo != NULL) return lmo;
572 if (sid==objID) return this;
576 // Search float images
577 for (int i=0; i<floatimage.size(); ++i )
578 if (floatimage.at(i)->inBox(p) &&
579 (floatimage.at(i) != excludeLMO) &&
580 floatimage.at(i)->getParObj()!= excludeLMO &&
581 floatimage.at(i)->isVisibleObj()
582 ) return floatimage.at(i);
587 void BranchObj::setHeading(QString s)
589 heading->setText(s); // set new heading
590 calcBBoxSize(); // recalculate bbox
591 positionBBox(); // rearrange contents
595 void BranchObj::setHideTmp (HideTmpMode mode)
597 if (mode==HideExport && (hideExport|| hasHiddenExportParent() ) )
599 // Hide stuff according to hideExport flag and parents
600 setVisibility (false);
604 // Do not hide, but still take care of scrolled status
605 if (hasScrolledParent(this))
606 setVisibility (false);
608 setVisibility (true);
612 // And take care of my children
613 for (int i=0; i<branch.size(); ++i)
614 branch.at(i)->setHideTmp (mode);
617 bool BranchObj::hasHiddenExportParent()
619 // Calls parents recursivly to
620 // find out, if we or parents are temp. hidden
622 if (hidden || hideExport) return true;
624 BranchObj* bo=(BranchObj*)parObj;
626 return bo->hasHiddenExportParent();
631 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
633 // Cloudy stuff can be hidden during exports
634 if (hidden) return "";
636 // Update of note is usually done while unselecting a branch
637 // if (isNoteInEditor) getNoteFromTextEditor(); //FIXME-2 moved to TreeItem
640 QString scrolledAttr;
642 scrolledAttr=attribut ("scrolled","yes");
646 // save area, if not scrolled
648 if (!((BranchObj*)(parObj))->isScrolled() )
651 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
652 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
653 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
654 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
659 // Providing an ID for a branch makes export to XHTML easier
662 idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
666 s=beginElement ("branch"
671 +getIncludeImageAttr() );
675 s+=valueElement("heading", getHeading(),
676 attribut ("textColor",QColor(heading->getColor()).name()));
679 if (frame->getFrameType()!=FrameObj::NoFrame)
680 s+=frame->saveToDir ();
682 // save names of flags set
683 s+=standardFlags->saveToDir(tmpdir,prefix,0);
686 for (int i=0; i<floatimage.size(); ++i)
687 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
690 if (!treeItem->getNoteObj().isEmpty() )
691 s+=treeItem->getNoteObj().saveToDir();
694 for (int i=0; i<branch.size(); ++i)
695 s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
698 QString ol; // old link
699 QString cl; // current link
700 for (int i=0; i<xlink.size(); ++i)
702 cl=xlink.at(i)->saveToDir();
709 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
714 s+=endElement ("branch");
718 void BranchObj::addXLink (XLinkObj *xlo)
724 void BranchObj::removeXLinkRef (XLinkObj *xlo)
726 xlink.removeAt (xlink.indexOf(xlo));
729 void BranchObj::deleteXLink(XLinkObj *xlo)
732 if (!xlo->isUsed()) delete (xlo);
735 void BranchObj::deleteXLinkAt (int i)
737 XLinkObj *xlo=xlink.at(i);
739 if (!xlo->isUsed()) delete(xlo);
742 XLinkObj* BranchObj::XLinkAt (int i)
747 int BranchObj::countXLink()
749 return xlink.count();
753 BranchObj* BranchObj::XLinkTargetAt (int i)
755 if (i>=0 && i<xlink.size())
758 return xlink.at(i)->otherBranch (this);
763 void BranchObj::setIncludeImagesVer(bool b)
771 bool BranchObj::getIncludeImagesVer()
773 return includeImagesVer;
776 void BranchObj::setIncludeImagesHor(bool b)
784 bool BranchObj::getIncludeImagesHor()
786 return includeImagesHor;
789 QString BranchObj::getIncludeImageAttr()
792 if (includeImagesVer)
793 a=attribut ("incImgV","true");
795 a=attribut ("incImgV","false");
796 if (includeImagesHor)
797 a+=attribut ("incImgH","true");
799 a+=attribut ("incImgH","false");
803 FloatImageObj* BranchObj::addFloatImage ()
805 FloatImageObj *newfi=new FloatImageObj (scene,this);
806 floatimage.append (newfi);
807 if (hasScrolledParent(this) )
808 newfi->setVisibility (false);
810 newfi->setVisibility(visible);
819 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
821 FloatImageObj *newfi=new FloatImageObj (scene,this);
822 floatimage.append (newfi);
824 if (hasScrolledParent(this) )
825 newfi->setVisibility (false);
827 newfi->setVisibility(visible);
836 FloatImageObj* BranchObj::getFirstFloatImage ()
838 return floatimage.first();
841 FloatImageObj* BranchObj::getLastFloatImage ()
843 return floatimage.last();
846 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
848 return floatimage.at(i);
851 void BranchObj::removeFloatImage (FloatImageObj *fio)
853 int i=floatimage.indexOf (fio);
854 if (i>-1) delete (floatimage.takeAt (i));
860 void BranchObj::savePosInAngle ()
862 // Save position in angle
863 for (int i=0; i<branch.size(); ++i)
864 branch.at(i)->angle=i;
867 void BranchObj::setDefAttr (BranchModification mod)
872 case 0: fontsize=16; break;
873 case 1: fontsize=12; break;
874 default: fontsize=10; break;
878 setLinkStyle(getDefLinkStyle());
879 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
880 font.setPointSize(fontsize);
881 heading->setFont(font );
884 setColor (((BranchObj*)(parObj))->getColor());
889 BranchObj* BranchObj::addBranch()
891 BranchObj* newbo=new BranchObj(scene,this);
892 branch.append (newbo);
893 newbo->setParObj(this);
894 newbo->setDefAttr(NewBranch);
895 newbo->setHeading ("new");
897 newbo->setVisibility (false);
899 newbo->setVisibility(visible);
905 BranchObj* BranchObj::addBranch(BranchObj* bo)
907 BranchObj* newbo=new BranchObj(scene,this);
908 branch.append (newbo);
910 newbo->setParObj(this);
911 newbo->setDefAttr(MovedBranch);
913 newbo->setVisibility (false);
915 newbo->setVisibility(bo->visible);
921 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
924 bo->setParObj (this);
926 bo->setDefAttr(MovedBranch);
927 if (scrolled) tmpUnscroll();
928 //setLastSelectedBranch (bo); //FIXME-3 needed?
932 BranchObj* BranchObj::insertBranch(int pos)
935 // Add new bo and resort branches
936 BranchObj *newbo=addBranch ();
937 newbo->angle=pos-0.5;
938 qSort (branch.begin(),branch.end(), isAbove);
942 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
945 // Add new bo and resort branches
947 BranchObj *newbo=addBranch (bo);
948 qSort (branch.begin(),branch.end(), isAbove);
952 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
955 // Add new bo and resort branches
958 bo->setParObj (this);
960 bo->setDefAttr (MovedBranch);
961 if (scrolled) tmpUnscroll();
962 //setLastSelectedBranch (bo); //FIXME-3 needed?
963 qSort (branch.begin(),branch.end(), isAbove);
967 void BranchObj::removeBranchHere(BranchObj* borem)
969 // This removes the branch bo from list, but
970 // inserts its children at the place of bo
972 bo=borem->getLastBranch();
973 int pos=borem->getNum();
976 bo->linkTo (this,pos+1);
977 bo=borem->getLastBranch();
979 removeBranch (borem);
982 void BranchObj::removeChildren()
987 void BranchObj::removeBranch(BranchObj* bo)
989 // if bo is not in branch remove returns false, we
992 int i=branch.indexOf(bo);
998 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
1002 void BranchObj::removeBranchPtr(BranchObj* bo)
1004 int i=branch.indexOf(bo);
1007 branch.removeAt (i);
1009 qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
1010 requestReposition();
1013 BranchObj* BranchObj::getFirstBranch ()
1015 if (branch.size()>0)
1016 return branch.first();
1021 BranchObj* BranchObj::getLastBranch ()
1023 if (branch.size()>0)
1024 return branch.last();
1029 BranchObj* BranchObj::getBranchNum (int i)
1031 if (i>=0 && i<branch.size())
1032 return branch.at(i);
1037 bool BranchObj::canMoveBranchUp()
1039 if (!parObj || depth==1) return false;
1040 BranchObj* par=(BranchObj*)parObj;
1041 if (this==par->getFirstBranch())
1047 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
1050 int i=branch.indexOf(bo1);
1052 { // -1 if bo1 not found
1053 branch.at(i)->angle--;
1054 branch.at(i-1)->angle++;
1055 qSort (branch.begin(),branch.end(), isAbove);
1056 return branch.at(i);
1061 bool BranchObj::canMoveBranchDown()
1063 if (!parObj|| depth==1) return false;
1064 BranchObj* par=(BranchObj*)parObj;
1065 if (this==par->getLastBranch())
1071 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
1074 int i=branch.indexOf(bo1);
1076 if (i <branch.size())
1079 branch.at(i)->angle++;
1080 branch.at(j)->angle--;
1081 qSort (branch.begin(),branch.end(), isAbove);
1082 return branch.at(i);
1087 void BranchObj::sortChildren()
1089 int childCount=branch.count();
1091 bool madeChanges=false;
1095 for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
1096 BranchObj* curChild=(BranchObj*)branch.at(curChildIndex);
1097 BranchObj* prevChild=(BranchObj*)branch.at(curChildIndex-1);
1098 if(prevChild->heading->text().compare(curChild->heading->text())>0)
1100 this->moveBranchUp(curChild);
1104 }while(madeChanges);
1108 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
1110 // Find current parent and
1111 // remove pointer to myself there
1112 if (!dst) return NULL;
1113 BranchObj *par=(BranchObj*)parObj;
1115 par->removeBranchPtr (this);
1119 // Create new pointer to myself at dst
1120 if (pos<0||dst->getDepth()==0)
1122 // links myself as last branch at dst
1123 dst->addBranchPtr (this);
1128 // inserts me at pos in parent of dst
1131 BranchObj *bo=dst->insertBranchPtr (this,pos);
1132 bo->setDefAttr(MovedBranch);
1141 void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
1143 qreal th = bboxTotal.height();
1146 QPointF pp; if (parObj) pp=parObj->getChildPos();
1147 cout << "BO::alignRelTo "<<qPrintable (getHeading());
1148 cout << " d="<<depth<<
1150 // " bbox.topLeft="<<bboxTotal.topLeft()<<
1151 " absPos="<<absPos<<
1152 // " relPos="<<relPos<<
1154 " width="<<bbox.width()<<
1155 " orient="<<orientation<<
1156 " alignSelf="<<alignSelf<<
1157 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
1158 // " hidden="<<hidden<<
1170 // Position relatively, if needed
1171 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
1173 // Calc angle to mapCenter if I am a mainbranch
1174 // needed for reordering the mainbranches clockwise
1176 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
1177 (int)(y() - parObj->getChildPos().y() ) ) );
1182 // Align myself depending on orientation and parent, but
1183 // only if I am not a mainbranch or mapcenter itself
1185 if (anim.isAnimated())
1190 LinkableMapObj::Orientation o;
1191 o=parObj->getOrientation();
1193 switch (orientation)
1195 case LinkableMapObj::LeftOfCenter:
1196 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1197 //move (ref.x() , ref.y() + (th-bbox.height())/2 );
1199 case LinkableMapObj::RightOfCenter:
1200 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1203 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1209 if (scrolled) return;
1211 // Set reference point for alignment of children
1213 if (orientation==LinkableMapObj::LeftOfCenter)
1214 ref2.setX(bbox.topLeft().x() - linkwidth);
1216 ref2.setX(bbox.topRight().x() + linkwidth);
1219 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1221 ref2.setY(ref.y() );
1223 // Align the children depending on reference point
1224 for (int i=0; i<branch.size(); ++i)
1226 if (!branch.at(i)->isHidden())
1228 branch.at(i)->alignRelativeTo (ref2,true);
1230 // append next branch below current one
1231 ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChildren().height() );
1237 void BranchObj::reposition()
1239 /* TODO testing only
1240 if (!getHeading().isEmpty())
1241 cout << "BO::reposition "<<qPrintable(getHeading())<<endl;
1243 cout << "BO::reposition ???"<<endl;
1245 cout << " orient="<<orientation<<endl;
1250 // only calculate the sizes once. If the deepest LMO
1251 // changes its height,
1252 // all upper LMOs have to change, too.
1253 calcBBoxSizeWithChildren();
1254 updateLink(); // This update is needed if the scene is resized
1255 // due to excessive moving of a FIO
1257 alignRelativeTo ( QPointF (absPos.x(),
1258 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1259 qSort (branch.begin(),branch.end(), isAbove);
1260 positionBBox(); // Reposition bbox and contents
1263 // This is only important for moving branches:
1264 // For editing a branch it isn't called...
1265 alignRelativeTo ( QPointF (absPos.x(),
1266 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1270 void BranchObj::unsetAllRepositionRequests()
1272 repositionRequest=false;
1273 for (int i=0; i<branch.size(); ++i)
1274 branch.at(i)->unsetAllRepositionRequests();
1278 QPolygonF BranchObj::shape()
1282 QRectF r=getTotalBBox();
1283 if (orientation==LinkableMapObj::LeftOfCenter)
1286 <<QPointF (bbox.topLeft().x(), r.topLeft().y() )
1288 <<bbox.bottomRight()
1289 <<QPointF (bbox.bottomLeft().x(), r.bottomLeft().y() ) ;
1293 <<QPointF (bbox.topRight().x(), r.topRight().y() )
1296 <<QPointF (bbox.bottomRight().x(), r.bottomRight().y() ) ;
1300 QRectF BranchObj::getTotalBBox()
1304 if (scrolled) return r;
1306 for (int i=0; i<branch.size(); ++i)
1307 if (!branch.at(i)->isHidden())
1308 r=addBBox(branch.at(i)->getTotalBBox(),r);
1310 for (int i=0; i<floatimage.size(); ++i)
1311 if (!floatimage.at(i)->isHidden())
1312 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1317 QRectF BranchObj::getBBoxSizeWithChildren()
1322 void BranchObj::calcBBoxSizeWithChildren()
1324 // This is initially called only from reposition and
1325 // and only for mapcenter. So it won't be
1326 // called more than once for a single user
1330 // Calculate size of LMO including all children (to align them later)
1331 bboxTotal.setX(bbox.x() );
1332 bboxTotal.setY(bbox.y() );
1334 // if branch is scrolled, ignore children, but still consider floatimages
1337 bboxTotal.setWidth (bbox.width());
1338 bboxTotal.setHeight(bbox.height());
1344 bboxTotal.setWidth (0);
1345 bboxTotal.setHeight(0);
1348 bboxTotal.setX (parObj->x());
1349 bboxTotal.setY (parObj->y());
1352 bboxTotal.setX (bbox.x());
1353 bboxTotal.setY (bbox.y());
1360 // Now calculate recursivly
1362 // maximum of widths
1364 for (int i=0; i<branch.size(); ++i)
1366 if (!branch.at(i)->isHidden())
1368 branch.at(i)->calcBBoxSizeWithChildren();
1369 br=branch.at(i)->getBBoxSizeWithChildren();
1370 r.setWidth( max (br.width(), r.width() ));
1371 r.setHeight(br.height() + r.height() );
1372 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1375 // Add myself and also
1376 // add width of link to sum if necessary
1377 if (branch.isEmpty())
1378 bboxTotal.setWidth (bbox.width() + r.width() );
1380 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1382 bboxTotal.setHeight(max (r.height(), bbox.height()));
1385 void BranchObj::select() // FIXME-2 try to get rid of this in BO completely
1387 cout << "BO::select()\n";
1388 textEditor->setText(treeItem->getNoteObj().getNote() );
1389 QString fnh=treeItem->getNoteObj().getFilenameHint();
1391 textEditor->setFilenameHint(treeItem->getNoteObj().getFilenameHint() );
1393 textEditor->setFilenameHint(getHeading() );
1394 textEditor->setFontHint (treeItem->getNoteObj().getFontHint() );
1395 //isNoteInEditor=true;
1397 // set selected and visible
1398 LinkableMapObj::select();
1400 //if (po) po->setLastSelectedBranch(this); needed?
1402 // temporary unscroll, if we have scrolled parents somewhere
1403 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1405 /* moved to vymmodel or vymview...
1406 // Show URL and link in statusbar
1408 if (!url.isEmpty()) status+="URL: "+url+" ";
1409 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1410 if (!status.isEmpty()) mainWindow->statusMessage (status);
1413 updateFlagsToolbar();
1416 model->updateActions();
1420 void BranchObj::unselect() //FIXME-3 should not be needed
1422 LinkableMapObj::unselect();
1423 // Delete any messages like vymLink in StatusBar
1424 mainWindow->statusMessage (""); //this causes segfault, when MainWindow is already gone in global destructor on quitting vym
1427 // Save current note
1428 if (isNoteInEditor) getNoteFromTextEditor();
1429 isNoteInEditor=false;
1432 // reset temporary unscroll, if we have scrolled parents somewhere
1433 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1435 // Erase content of editor
1436 textEditor->setInactive();
1438 // unselect all buttons in toolbar
1439 standardFlagsDefault->updateToolbar();
1442 QString BranchObj::getSelectString()
1444 return model->getSelectString (this);
1447 void BranchObj::setAnimation(const AnimPoint &ap)
1452 bool BranchObj::animate()
1455 if ( anim.isAnimated() )
1460 parObj->reposition(); // we might have been relinked meanwhile