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::itLast=NULL;
21 BranchObj* BranchObj::itFirst=NULL;
24 BranchObj::BranchObj () :OrnamentedObj() // FIXME needed at all?
26 // cout << "Const BranchObj ()\n";
32 BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s)
34 // cout << "Const BranchObj (s) called from MapCenterObj (s)\n";
39 BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)
41 // cout << "Const BranchObj (s,p)\n";
44 depth=p->getDepth()+1;
46 // Calc angle to mapCenter if I am a mainbranch
47 // needed for reordering the mainbranches clockwise
49 angle=getAngle (QPointF (x() - parObj->getChildPos().x() ,
50 (y() - parObj->getChildPos().y() ) ) );
54 BranchObj::~BranchObj ()
56 // If I'm animated, I need to un-animate myself first
57 if (anim.isAnimated() )
59 anim.setAnimated (false);
60 model->stopAnimation (this);
63 //cout << "Destr BranchObj of "<<this<<endl;
64 // Check, if this branch was the last child to be deleted
65 // If so, unset the scrolled flags
67 BranchObj *po=(BranchObj*)parObj;
71 bo=((BranchObj*)parObj)->getLastBranch();
72 if (bo) po->unScroll();
77 bool BranchObj::operator< ( const BranchObj & other )
79 return angle < other.angle;
82 bool BranchObj::operator== ( const BranchObj & other )
84 return angle == other.angle;
87 void BranchObj::init ()
92 absPos+=parObj->getChildPos();
102 includeImagesVer=false;
103 includeImagesHor=false;
106 void BranchObj::copy (BranchObj* other)
108 OrnamentedObj::copy(other);
111 for (int i=0; i<other->branch.size(); ++i)
112 // Make deep copy of b
113 // Because addBranch again calls copy for the children,
114 // Those will get a deep copy, too
115 addBranch(other->branch.at(i) );
117 for (int i=0; i<other->floatimage.size(); ++i)
118 addFloatImage (other->floatimage.at(i));
119 scrolled=other->scrolled;
120 tmpUnscrolled=other->tmpUnscrolled;
121 setVisibility (other->visible);
128 void BranchObj::clear()
130 setVisibility (true);
132 while (!floatimage.isEmpty())
133 delete floatimage.takeFirst();
135 while (!xlink.isEmpty())
136 delete xlink.takeFirst();
138 while (!branch.isEmpty())
139 delete branch.takeFirst();
142 bool isAbove (BranchObj* a, BranchObj *b)
144 if (a->angle < b->angle)
150 int BranchObj::getNum()
153 return ((BranchObj*)parObj)->getNum (this);
158 int BranchObj::getNum(BranchObj *bo)
160 return branch.indexOf (bo);
163 int BranchObj::getFloatImageNum(FloatImageObj *fio)
165 return floatimage.indexOf(fio);
168 int BranchObj::countBranches()
170 return branch.count();
173 int BranchObj::countFloatImages()
175 return floatimage.count();
178 int BranchObj::countXLinks()
180 return xlink.count();
183 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
185 // Temporary link to lmo
186 // m is position of mouse pointer
187 // offset 0: default 1: below lmo -1 above lmo (if possible)
190 BranchObj* o=(BranchObj*)(lmo);
194 // ignore mapcenter and mainbranch
195 if (lmo->getDepth()<2) off=0;
202 depth=parObj->getDepth()+1;
204 // setLinkStyle calls updateLink, only set it once
205 if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
207 // Move temporary to new position at destination
208 // Usually the positioning would be done by reposition(),
209 // but then also the destination branch would "Jump" around...
210 // Better just do it approximately
212 { // new parent is the mapcenter itself
214 QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
215 m.y() - o->getChildPos().y() ));
216 if (p.x()<0) p.setX( p.x()-bbox.width() );
223 // new parent is just a branch, link to it
224 QRectF t=o->getBBoxSizeWithChildren();
225 if (o->getLastBranch())
226 y=t.y() + t.height() ;
233 // we want to link above lmo
234 y=o->y() - height() + 5;
236 // we want to link below lmo
237 // Bottom of sel should be 5 pixels above
238 // the bottom of the branch _below_ the target:
239 // Don't try to find that branch, guess 12 pixels
240 y=o->getChildPos().y() -height() + 12;
242 if (o->getOrientation()==LinkableMapObj::LeftOfCenter)
243 move ( o->getChildPos().x() - linkwidth, y );
245 move (o->getChildPos().x() + linkwidth, y );
248 // updateLink is called implicitly in move
252 void BranchObj::unsetParObjTmp()
259 depth=parObj->getDepth()+1;
260 setLinkStyle (getDefLinkStyle() );
265 void BranchObj::unScroll()
267 if (tmpUnscrolled) resetTmpUnscroll();
268 if (scrolled) toggleScroll();
271 void BranchObj::toggleScroll()
276 systemFlags->deactivate("scrolledright");
277 for (int i=0; i<branch.size(); ++i)
278 branch.at(i)->setVisibility(true);
282 systemFlags->activate("scrolledright");
283 for (int i=0; i<branch.size(); ++i)
284 branch.at(i)->setVisibility(false);
288 move (absPos.x(), absPos.y() );
292 bool BranchObj::isScrolled()
297 bool BranchObj::hasScrolledParent(BranchObj *start)
299 // Calls parents recursivly to
300 // find out, if we are scrolled at all.
301 // But ignore myself, just look at parents.
303 if (this !=start && scrolled) return true;
305 BranchObj* bo=(BranchObj*)(parObj);
307 return bo->hasScrolledParent(start);
312 void BranchObj::tmpUnscroll()
314 // Unscroll parent (recursivly)
315 BranchObj* bo=(BranchObj*)(parObj);
316 if (bo) bo->tmpUnscroll();
322 systemFlags->activate("tmpUnscrolledright");
327 void BranchObj::resetTmpUnscroll()
329 // Unscroll parent (recursivly)
330 BranchObj* bo=(BranchObj*)(parObj);
332 bo->resetTmpUnscroll();
338 systemFlags->deactivate("tmpUnscrolledright");
343 void BranchObj::setVisibility(bool v, int toDepth)
345 if (depth <= toDepth)
347 frame->setVisibility(v);
348 heading->setVisibility(v);
349 systemFlags->setVisibility(v);
350 standardFlags->setVisibility(v);
351 LinkableMapObj::setVisibility (v);
353 // Only change children, if I am not scrolled
354 if (!scrolled && (depth < toDepth))
356 // Now go recursivly through all children
358 for (i=0; i<branch.size(); ++i)
359 branch.at(i)->setVisibility (v,toDepth);
360 for (i=0; i<floatimage.size(); ++i)
361 floatimage.at(i)->setVisibility (v);
362 for (i=0; i<xlink.size(); ++i)
363 xlink.at(i)->setVisibility ();
365 } // depth <= toDepth
369 void BranchObj::setVisibility(bool v)
371 setVisibility (v,MAX_DEPTH);
375 void BranchObj::setLinkColor ()
377 // Overloaded from LinkableMapObj
378 // BranchObj can use color of heading
382 if (model->getMapLinkColorHint()==HeadingColor)
383 LinkableMapObj::setLinkColor (heading->getColor() );
385 LinkableMapObj::setLinkColor ();
389 void BranchObj::setColorSubtree(QColor col)
392 for (int i=0; i<branch.size(); ++i)
393 branch.at(i)->setColorSubtree(col);
396 BranchObj* BranchObj::first()
403 BranchObj* BranchObj::next()
407 BranchObj *po=(BranchObj*)parObj;
409 if (branch.isEmpty())
416 // no itLast, we are just beginning
419 // we have children, return first one
425 // No children, so there is no next
433 { // We come from parent
436 // there are children, go there
441 { // no children, try to go up again
444 // go back to parent and try to find next there
453 // can't go up, I am mapCenter, no next
460 // We don't come from parent, but from brother or children
462 // Try to find last child, where we came from, in my own children
465 while (i<branch.size())
467 // Try to find itLast in my own children
468 if (itLast==branch.at(i))
470 // ok, we come from my own children
471 if (i<branch.size()-1)
481 { // found itLast in my children
484 // found a brother of lastLMO
492 if (this==itFirst) return NULL; // Stop at starting point
501 // can't go up, I am mapCenter
508 // couldn't find last child, it must be a nephew of mine
511 // proceed with my first child
513 return branch.first();
517 // or go back to my parents
528 // can't go up, I am mapCenter
535 BranchObj* BranchObj::getLastIterator()
540 void BranchObj::setLastIterator(BranchObj* it)
545 void BranchObj::positionContents()
547 for (int i=0; i<floatimage.size(); ++i )
548 floatimage.at(i)->reposition();
549 OrnamentedObj::positionContents();
552 void BranchObj::move (double x, double y)
554 OrnamentedObj::move (x,y);
555 for (int i=0; i<floatimage.size(); ++i )
556 floatimage.at(i)->reposition();
560 void BranchObj::move (QPointF p)
565 void BranchObj::moveBy (double x, double y)
567 OrnamentedObj::moveBy (x,y);
568 for (int i=0; i<branch.size(); ++i)
569 branch.at(i)->moveBy (x,y);
573 void BranchObj::moveBy (QPointF p)
575 moveBy (p.x(), p.y());
579 void BranchObj::positionBBox()
581 QPointF ap=getAbsPos();
582 bbox.moveTopLeft (ap);
586 frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
588 // Update links to other branches
589 for (int i=0; i<xlink.size(); ++i)
590 xlink.at(i)->updateXLink();
593 void BranchObj::calcBBoxSize()
595 QSizeF heading_r=heading->getSize();
596 qreal heading_w=(qreal) heading_r.width() ;
597 qreal heading_h=(qreal) heading_r.height() ;
598 QSizeF sysflags_r=systemFlags->getSize();
599 qreal sysflags_h=sysflags_r.height();
600 qreal sysflags_w=sysflags_r.width();
601 QSizeF stanflags_r=standardFlags->getSize();
602 qreal stanflags_h=stanflags_r.height();
603 qreal stanflags_w=stanflags_r.width();
607 // set width to sum of all widths
608 w=heading_w + sysflags_w + stanflags_w;
609 // set height to maximum needed height
610 h=max (sysflags_h,stanflags_h);
613 // Save the dimension of flags and heading
614 ornamentsBBox.setSize ( QSizeF(w,h));
616 // clickBox includes Flags and Heading
617 clickBox.setSize (ornamentsBBox.size() );
622 topPad=botPad=leftPad=rightPad=0;
623 if (includeImagesVer || includeImagesHor)
625 if (countFloatImages()>0)
627 for (int i=0; i<floatimage.size(); ++i )
629 rp=floatimage.at(i)->getRelPos();
630 if (includeImagesVer)
633 topPad=max (topPad,-rp.y()-h);
634 if (rp.y()+floatimage.at(i)->height() > 0)
635 botPad=max (botPad,rp.y()+floatimage.at(i)->height());
637 if (includeImagesHor)
639 if (orientation==LinkableMapObj::RightOfCenter)
642 leftPad=max (leftPad,-rp.x()-w);
643 if (rp.x()+floatimage.at(i)->width() > 0)
644 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
648 leftPad=max (leftPad,-rp.x());
649 if (rp.x()+floatimage.at(i)->width() > w)
650 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
660 w+=frame->getPadding();
661 h+=frame->getPadding();
664 bbox.setSize (QSizeF (w,h));
667 void BranchObj::setDockPos()
669 // Sets childpos and parpos depending on orientation
670 if (getOrientation()==LinkableMapObj::LeftOfCenter )
673 ornamentsBBox.bottomLeft().x(),
676 ornamentsBBox.bottomRight().x(),
681 ornamentsBBox.bottomRight().x(),
684 ornamentsBBox.bottomLeft().x(),
689 LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
693 for (int i=0; i<branch.size(); ++i)
695 lmo=branch.at(i)->findMapObj(p, excludeLMO);
696 if (lmo != NULL) return lmo;
701 if (inBox (p,clickBox) && (this != excludeLMO) && isVisibleObj() )
704 // Search float images
705 for (int i=0; i<floatimage.size(); ++i )
706 if (inBox(p,floatimage.at(i)->getClickBox()) &&
707 (floatimage.at(i) != excludeLMO) &&
708 floatimage.at(i)->getParObj()!= excludeLMO &&
709 floatimage.at(i)->isVisibleObj()
710 ) return floatimage.at(i);
715 LinkableMapObj* BranchObj::findID (QString sid)
719 for (int i=0; i<branch.size(); ++i)
721 lmo=branch.at(i)->findID (sid);
722 if (lmo != NULL) return lmo;
726 if (sid==objID) return this;
730 // Search float images
731 for (int i=0; i<floatimage.size(); ++i )
732 if (floatimage.at(i)->inBox(p) &&
733 (floatimage.at(i) != excludeLMO) &&
734 floatimage.at(i)->getParObj()!= excludeLMO &&
735 floatimage.at(i)->isVisibleObj()
736 ) return floatimage.at(i);
741 void BranchObj::setHeading(QString s)
743 heading->setText(s); // set new heading
744 calcBBoxSize(); // recalculate bbox
745 positionBBox(); // rearrange contents
749 void BranchObj::setHideTmp (HideTmpMode mode)
751 if (mode==HideExport && (hideExport|| hasHiddenExportParent() ) )
753 // Hide stuff according to hideExport flag and parents
754 setVisibility (false);
758 // Do not hide, but still take care of scrolled status
759 if (hasScrolledParent(this))
760 setVisibility (false);
762 setVisibility (true);
766 // And take care of my children
767 for (int i=0; i<branch.size(); ++i)
768 branch.at(i)->setHideTmp (mode);
771 bool BranchObj::hasHiddenExportParent()
773 // Calls parents recursivly to
774 // find out, if we or parents are temp. hidden
776 if (hidden || hideExport) return true;
778 BranchObj* bo=(BranchObj*)parObj;
780 return bo->hasHiddenExportParent();
785 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
787 // Cloudy stuff can be hidden during exports
788 if (hidden) return "";
790 // Update of note is usually done while unselecting a branch
791 if (isNoteInEditor) getNoteFromTextEditor();
794 QString scrolledAttr;
796 scrolledAttr=attribut ("scrolled","yes");
800 // save area, if not scrolled
802 if (!((BranchObj*)(parObj))->isScrolled() )
805 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
806 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
807 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
808 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
813 // Providing an ID for a branch makes export to XHTML easier
816 idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
820 s=beginElement ("branch"
825 +getIncludeImageAttr() );
829 s+=valueElement("heading", getHeading(),
830 attribut ("textColor",QColor(heading->getColor()).name()));
833 if (frame->getFrameType()!=FrameObj::NoFrame)
834 s+=frame->saveToDir ();
836 // save names of flags set
837 s+=standardFlags->saveToDir(tmpdir,prefix,0);
840 for (int i=0; i<floatimage.size(); ++i)
841 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
844 if (!note.isEmpty() )
848 for (int i=0; i<branch.size(); ++i)
849 s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
852 QString ol; // old link
853 QString cl; // current link
854 for (int i=0; i<xlink.size(); ++i)
856 cl=xlink.at(i)->saveToDir();
863 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
868 s+=endElement ("branch");
872 void BranchObj::addXLink (XLinkObj *xlo)
878 void BranchObj::removeXLinkRef (XLinkObj *xlo)
880 xlink.removeAt (xlink.indexOf(xlo));
883 void BranchObj::deleteXLink(XLinkObj *xlo)
886 if (!xlo->isUsed()) delete (xlo);
889 void BranchObj::deleteXLinkAt (int i)
891 XLinkObj *xlo=xlink.at(i);
893 if (!xlo->isUsed()) delete(xlo);
896 XLinkObj* BranchObj::XLinkAt (int i)
901 int BranchObj::countXLink()
903 return xlink.count();
907 BranchObj* BranchObj::XLinkTargetAt (int i)
909 if (i>=0 && i<xlink.size())
912 return xlink.at(i)->otherBranch (this);
917 void BranchObj::setIncludeImagesVer(bool b)
925 bool BranchObj::getIncludeImagesVer()
927 return includeImagesVer;
930 void BranchObj::setIncludeImagesHor(bool b)
938 bool BranchObj::getIncludeImagesHor()
940 return includeImagesHor;
943 QString BranchObj::getIncludeImageAttr()
946 if (includeImagesVer)
947 a=attribut ("incImgV","true");
949 a=attribut ("incImgV","false");
950 if (includeImagesHor)
951 a+=attribut ("incImgH","true");
953 a+=attribut ("incImgH","false");
957 FloatImageObj* BranchObj::addFloatImage ()
959 FloatImageObj *newfi=new FloatImageObj (scene,this);
960 floatimage.append (newfi);
961 if (hasScrolledParent(this) )
962 newfi->setVisibility (false);
964 newfi->setVisibility(visible);
973 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
975 FloatImageObj *newfi=new FloatImageObj (scene,this);
976 floatimage.append (newfi);
978 if (hasScrolledParent(this) )
979 newfi->setVisibility (false);
981 newfi->setVisibility(visible);
990 FloatImageObj* BranchObj::getFirstFloatImage ()
992 return floatimage.first();
995 FloatImageObj* BranchObj::getLastFloatImage ()
997 return floatimage.last();
1000 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
1002 return floatimage.at(i);
1005 void BranchObj::removeFloatImage (FloatImageObj *fio)
1007 int i=floatimage.indexOf (fio);
1008 if (i>-1) delete (floatimage.takeAt (i));
1011 requestReposition();
1014 void BranchObj::savePosInAngle ()
1016 // Save position in angle
1017 for (int i=0; i<branch.size(); ++i)
1018 branch.at(i)->angle=i;
1021 void BranchObj::setDefAttr (BranchModification mod)
1026 case 0: fontsize=16; break;
1027 case 1: fontsize=12; break;
1028 default: fontsize=10; break;
1032 setLinkStyle(getDefLinkStyle());
1033 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
1034 font.setPointSize(fontsize);
1035 heading->setFont(font );
1038 setColor (((BranchObj*)(parObj))->getColor());
1043 BranchObj* BranchObj::addBranch()
1045 BranchObj* newbo=new BranchObj(scene,this);
1046 branch.append (newbo);
1047 newbo->setParObj(this);
1048 newbo->setDefAttr(NewBranch);
1049 newbo->setHeading ("new");
1051 newbo->setVisibility (false);
1053 newbo->setVisibility(visible);
1054 newbo->updateLink();
1055 requestReposition();
1059 BranchObj* BranchObj::addBranch(BranchObj* bo)
1061 BranchObj* newbo=new BranchObj(scene,this);
1062 branch.append (newbo);
1064 newbo->setParObj(this);
1065 newbo->setDefAttr(MovedBranch);
1067 newbo->setVisibility (false);
1069 newbo->setVisibility(bo->visible);
1070 newbo->updateLink();
1071 requestReposition();
1075 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
1078 bo->setParObj (this);
1080 bo->setDefAttr(MovedBranch);
1081 if (scrolled) tmpUnscroll();
1082 setLastSelectedBranch (bo);
1086 BranchObj* BranchObj::insertBranch(int pos)
1089 // Add new bo and resort branches
1090 BranchObj *newbo=addBranch ();
1091 newbo->angle=pos-0.5;
1092 qSort (branch.begin(),branch.end(), isAbove);
1096 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
1099 // Add new bo and resort branches
1101 BranchObj *newbo=addBranch (bo);
1102 qSort (branch.begin(),branch.end(), isAbove);
1106 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
1109 // Add new bo and resort branches
1112 bo->setParObj (this);
1114 bo->setDefAttr (MovedBranch);
1115 if (scrolled) tmpUnscroll();
1116 setLastSelectedBranch (bo);
1117 qSort (branch.begin(),branch.end(), isAbove);
1121 void BranchObj::removeBranchHere(BranchObj* borem)
1123 // This removes the branch bo from list, but
1124 // inserts its children at the place of bo
1126 bo=borem->getLastBranch();
1127 int pos=borem->getNum();
1130 bo->linkTo (this,pos+1);
1131 bo=borem->getLastBranch();
1133 removeBranch (borem);
1136 void BranchObj::removeChildren()
1141 void BranchObj::removeBranch(BranchObj* bo)
1143 // if bo is not in branch remove returns false, we
1146 int i=branch.indexOf(bo);
1150 branch.removeAt (i);
1152 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
1153 requestReposition();
1156 void BranchObj::removeBranchPtr(BranchObj* bo)
1158 int i=branch.indexOf(bo);
1161 branch.removeAt (i);
1163 qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
1164 requestReposition();
1167 void BranchObj::setLastSelectedBranch (BranchObj* bo)
1169 lastSelectedBranch=branch.indexOf(bo);
1172 BranchObj* BranchObj::getLastSelectedBranch ()
1174 if (lastSelectedBranch>=0)
1176 if ( branch.size()>lastSelectedBranch)
1177 return branch.at(lastSelectedBranch);
1178 if (branch.size()>0)
1179 return branch.last();
1184 BranchObj* BranchObj::getFirstBranch ()
1186 if (branch.size()>0)
1187 return branch.first();
1192 BranchObj* BranchObj::getLastBranch ()
1194 if (branch.size()>0)
1195 return branch.last();
1200 BranchObj* BranchObj::getBranchNum (int i)
1202 if (i>=0 && i<branch.size())
1203 return branch.at(i);
1208 bool BranchObj::canMoveBranchUp()
1210 if (!parObj || depth==1) return false;
1211 BranchObj* par=(BranchObj*)parObj;
1212 if (this==par->getFirstBranch())
1218 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
1221 int i=branch.indexOf(bo1);
1223 { // -1 if bo1 not found
1224 branch.at(i)->angle--;
1225 branch.at(i-1)->angle++;
1226 qSort (branch.begin(),branch.end(), isAbove);
1227 return branch.at(i);
1232 bool BranchObj::canMoveBranchDown()
1234 if (!parObj|| depth==1) return false;
1235 BranchObj* par=(BranchObj*)parObj;
1236 if (this==par->getLastBranch())
1242 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
1245 int i=branch.indexOf(bo1);
1247 if (i <branch.size())
1250 branch.at(i)->angle++;
1251 branch.at(j)->angle--;
1252 qSort (branch.begin(),branch.end(), isAbove);
1253 return branch.at(i);
1258 void BranchObj::sortChildren()
1260 int childCount=branch.count();
1262 bool madeChanges=false;
1266 for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
1267 BranchObj* curChild=(BranchObj*)branch.at(curChildIndex);
1268 BranchObj* prevChild=(BranchObj*)branch.at(curChildIndex-1);
1269 if(prevChild->heading->text().compare(curChild->heading->text())>0)
1271 this->moveBranchUp(curChild);
1275 }while(madeChanges);
1279 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
1281 // Find current parent and
1282 // remove pointer to myself there
1283 if (!dst) return NULL;
1284 BranchObj *par=(BranchObj*)parObj;
1286 par->removeBranchPtr (this);
1290 // Create new pointer to myself at dst
1291 if (pos<0||dst->getDepth()==0)
1293 // links myself as last branch at dst
1294 dst->addBranchPtr (this);
1299 // inserts me at pos in parent of dst
1302 BranchObj *bo=dst->insertBranchPtr (this,pos);
1303 bo->setDefAttr(MovedBranch);
1312 void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
1314 qreal th = bboxTotal.height();
1317 QPointF pp; if (parObj) pp=parObj->getChildPos();
1318 cout << "BO::alignRelTo "<<qPrintable (getHeading());
1319 cout << " d="<<depth<<
1321 // " bbox.topLeft="<<bboxTotal.topLeft()<<
1322 " absPos="<<absPos<<
1323 // " relPos="<<relPos<<
1325 " width="<<bbox.width()<<
1326 " orient="<<orientation<<
1327 " alignSelf="<<alignSelf<<
1328 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
1329 // " hidden="<<hidden<<
1341 // Position relatively, if needed
1342 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
1344 // Calc angle to mapCenter if I am a mainbranch
1345 // needed for reordering the mainbranches clockwise
1347 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
1348 (int)(y() - parObj->getChildPos().y() ) ) );
1353 // Align myself depending on orientation and parent, but
1354 // only if I am not a mainbranch or mapcenter itself
1356 if (anim.isAnimated())
1361 LinkableMapObj::Orientation o;
1362 o=parObj->getOrientation();
1364 switch (orientation)
1366 case LinkableMapObj::LeftOfCenter:
1367 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1368 //move (ref.x() , ref.y() + (th-bbox.height())/2 );
1370 case LinkableMapObj::RightOfCenter:
1371 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1374 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1380 if (scrolled) return;
1382 // Set reference point for alignment of children
1384 if (orientation==LinkableMapObj::LeftOfCenter)
1385 ref2.setX(bbox.topLeft().x() - linkwidth);
1387 ref2.setX(bbox.topRight().x() + linkwidth);
1390 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1392 ref2.setY(ref.y() );
1394 // Align the children depending on reference point
1395 for (int i=0; i<branch.size(); ++i)
1397 if (!branch.at(i)->isHidden())
1399 branch.at(i)->alignRelativeTo (ref2,true);
1401 // append next branch below current one
1402 ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChildren().height() );
1408 void BranchObj::reposition()
1410 /* TODO testing only
1411 if (!getHeading().isEmpty())
1412 cout << "BO::reposition "<<qPrintable(getHeading())<<endl;
1414 cout << "BO::reposition ???"<<endl;
1416 cout << " orient="<<orientation<<endl;
1421 // only calculate the sizes once. If the deepest LMO
1422 // changes its height,
1423 // all upper LMOs have to change, too.
1424 calcBBoxSizeWithChildren();
1425 updateLink(); // This update is needed if the scene is resized
1426 // due to excessive moving of a FIO
1428 alignRelativeTo ( QPointF (absPos.x(),
1429 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1430 qSort (branch.begin(),branch.end(), isAbove);
1431 positionBBox(); // Reposition bbox and contents
1434 // This is only important for moving branches:
1435 // For editing a branch it isn't called...
1436 alignRelativeTo ( QPointF (absPos.x(),
1437 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1441 void BranchObj::unsetAllRepositionRequests()
1443 repositionRequest=false;
1444 for (int i=0; i<branch.size(); ++i)
1445 branch.at(i)->unsetAllRepositionRequests();
1449 QPolygonF BranchObj::shape()
1453 QRectF r=getTotalBBox();
1454 if (orientation==LinkableMapObj::LeftOfCenter)
1457 <<QPointF (bbox.topLeft().x(), r.topLeft().y() )
1459 <<bbox.bottomRight()
1460 <<QPointF (bbox.bottomLeft().x(), r.bottomLeft().y() ) ;
1464 <<QPointF (bbox.topRight().x(), r.topRight().y() )
1467 <<QPointF (bbox.bottomRight().x(), r.bottomRight().y() ) ;
1471 QRectF BranchObj::getTotalBBox()
1475 if (scrolled) return r;
1477 for (int i=0; i<branch.size(); ++i)
1478 if (!branch.at(i)->isHidden())
1479 r=addBBox(branch.at(i)->getTotalBBox(),r);
1481 for (int i=0; i<floatimage.size(); ++i)
1482 if (!floatimage.at(i)->isHidden())
1483 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1488 QRectF BranchObj::getBBoxSizeWithChildren()
1493 void BranchObj::calcBBoxSizeWithChildren()
1495 // This is initially called only from reposition and
1496 // and only for mapcenter. So it won't be
1497 // called more than once for a single user
1501 // Calculate size of LMO including all children (to align them later)
1502 bboxTotal.setX(bbox.x() );
1503 bboxTotal.setY(bbox.y() );
1505 // if branch is scrolled, ignore children, but still consider floatimages
1508 bboxTotal.setWidth (bbox.width());
1509 bboxTotal.setHeight(bbox.height());
1515 bboxTotal.setWidth (0);
1516 bboxTotal.setHeight(0);
1519 bboxTotal.setX (parObj->x());
1520 bboxTotal.setY (parObj->y());
1523 bboxTotal.setX (bbox.x());
1524 bboxTotal.setY (bbox.y());
1531 // Now calculate recursivly
1533 // maximum of widths
1535 for (int i=0; i<branch.size(); ++i)
1537 if (!branch.at(i)->isHidden())
1539 branch.at(i)->calcBBoxSizeWithChildren();
1540 br=branch.at(i)->getBBoxSizeWithChildren();
1541 r.setWidth( max (br.width(), r.width() ));
1542 r.setHeight(br.height() + r.height() );
1543 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1546 // Add myself and also
1547 // add width of link to sum if necessary
1548 if (branch.isEmpty())
1549 bboxTotal.setWidth (bbox.width() + r.width() );
1551 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1553 bboxTotal.setHeight(max (r.height(), bbox.height()));
1556 void BranchObj::select()
1558 // update NoteEditor
1559 textEditor->setText(note.getNote() );
1560 QString fnh=note.getFilenameHint();
1562 textEditor->setFilenameHint(note.getFilenameHint() );
1564 textEditor->setFilenameHint(getHeading() );
1565 textEditor->setFontHint (note.getFontHint() );
1566 isNoteInEditor=true;
1568 // set selected and visible
1569 LinkableMapObj::select();
1571 // Tell parent that I am selected now:
1572 BranchObj* po=(BranchObj*)(parObj);
1573 if (po) // TODO Try to get rid of this cast...
1574 po->setLastSelectedBranch(this);
1576 // temporary unscroll, if we have scrolled parents somewhere
1577 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1579 // Show URL and link in statusbar
1581 if (!url.isEmpty()) status+="URL: "+url+" ";
1582 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1583 if (!status.isEmpty()) mainWindow->statusMessage (status);
1586 updateFlagsToolbar();
1589 model->updateActions();
1592 void BranchObj::unselect()
1594 LinkableMapObj::unselect();
1595 // Delete any messages like vymLink in StatusBar
1596 mainWindow->statusMessage (""); //FIXME this causes segfault, when MainWindow is already gone in global destructor on quitting vym
1598 // Save current note
1599 if (isNoteInEditor) getNoteFromTextEditor();
1600 isNoteInEditor=false;
1602 // reset temporary unscroll, if we have scrolled parents somewhere
1603 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1605 // Erase content of editor
1606 textEditor->setInactive();
1608 // unselect all buttons in toolbar
1609 standardFlagsDefault->updateToolbar();
1612 QString BranchObj::getSelectString()
1614 return model->getSelectString (this);
1617 void BranchObj::setAnimation(const AnimPoint &ap)
1622 bool BranchObj::animate()
1625 if ( anim.isAnimated() )
1630 parObj->reposition(); // we might have been relinked meanwhile