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);
354 for (i=0; i<floatimage.size(); ++i)
355 floatimage.at(i)->setVisibility (v);
356 for (i=0; i<xlink.size(); ++i)
357 xlink.at(i)->setVisibility ();
359 // Only change children, if I am not scrolled
360 if (!scrolled && (depth < toDepth))
362 // Now go recursivly through all children
363 for (i=0; i<branch.size(); ++i)
364 branch.at(i)->setVisibility (v,toDepth);
366 } // depth <= toDepth
370 void BranchObj::setVisibility(bool v)
372 setVisibility (v,MAX_DEPTH);
376 void BranchObj::setLinkColor ()
378 // Overloaded from LinkableMapObj
379 // BranchObj can use color of heading
383 if (model->getMapLinkColorHint()==HeadingColor)
384 LinkableMapObj::setLinkColor (heading->getColor() );
386 LinkableMapObj::setLinkColor ();
390 void BranchObj::setColorSubtree(QColor col)
393 for (int i=0; i<branch.size(); ++i)
394 branch.at(i)->setColorSubtree(col);
397 BranchObj* BranchObj::first()
404 BranchObj* BranchObj::next()
408 BranchObj *po=(BranchObj*)parObj;
410 if (branch.isEmpty())
417 // no itLast, we are just beginning
420 // we have children, return first one
426 // No children, so there is no next
434 { // We come from parent
437 // there are children, go there
442 { // no children, try to go up again
445 // go back to parent and try to find next there
454 // can't go up, I am mapCenter, no next
461 // We don't come from parent, but from brother or children
463 // Try to find last child, where we came from, in my own children
466 while (i<branch.size())
468 // Try to find itLast in my own children
469 if (itLast==branch.at(i))
471 // ok, we come from my own children
472 if (i<branch.size()-1)
482 { // found itLast in my children
485 // found a brother of lastLMO
493 if (this==itFirst) return NULL; // Stop at starting point
502 // can't go up, I am mapCenter
509 // couldn't find last child, it must be a nephew of mine
512 // proceed with my first child
514 return branch.first();
518 // or go back to my parents
529 // can't go up, I am mapCenter
536 BranchObj* BranchObj::getLastIterator()
541 void BranchObj::setLastIterator(BranchObj* it)
546 void BranchObj::positionContents()
548 for (int i=0; i<floatimage.size(); ++i )
549 floatimage.at(i)->reposition();
550 OrnamentedObj::positionContents();
553 void BranchObj::move (double x, double y)
555 OrnamentedObj::move (x,y);
556 for (int i=0; i<floatimage.size(); ++i )
557 floatimage.at(i)->reposition();
561 void BranchObj::move (QPointF p)
566 void BranchObj::moveBy (double x, double y)
568 OrnamentedObj::moveBy (x,y);
569 for (int i=0; i<branch.size(); ++i)
570 branch.at(i)->moveBy (x,y);
574 void BranchObj::moveBy (QPointF p)
576 moveBy (p.x(), p.y());
580 void BranchObj::positionBBox()
582 QPointF ap=getAbsPos();
583 bbox.moveTopLeft (ap);
587 frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
589 // Update links to other branches
590 for (int i=0; i<xlink.size(); ++i)
591 xlink.at(i)->updateXLink();
594 void BranchObj::calcBBoxSize()
596 QSizeF heading_r=heading->getSize();
597 qreal heading_w=(qreal) heading_r.width() ;
598 qreal heading_h=(qreal) heading_r.height() ;
599 QSizeF sysflags_r=systemFlags->getSize();
600 qreal sysflags_h=sysflags_r.height();
601 qreal sysflags_w=sysflags_r.width();
602 QSizeF stanflags_r=standardFlags->getSize();
603 qreal stanflags_h=stanflags_r.height();
604 qreal stanflags_w=stanflags_r.width();
608 // set width to sum of all widths
609 w=heading_w + sysflags_w + stanflags_w;
610 // set height to maximum needed height
611 h=max (sysflags_h,stanflags_h);
614 // Save the dimension of flags and heading
615 ornamentsBBox.setSize ( QSizeF(w,h));
617 // clickBox includes Flags and Heading
618 clickBox.setSize (ornamentsBBox.size() );
623 topPad=botPad=leftPad=rightPad=0;
624 if (includeImagesVer || includeImagesHor)
626 if (countFloatImages()>0)
628 for (int i=0; i<floatimage.size(); ++i )
630 rp=floatimage.at(i)->getRelPos();
631 if (includeImagesVer)
634 topPad=max (topPad,-rp.y()-h);
635 if (rp.y()+floatimage.at(i)->height() > 0)
636 botPad=max (botPad,rp.y()+floatimage.at(i)->height());
638 if (includeImagesHor)
640 if (orientation==LinkableMapObj::RightOfCenter)
643 leftPad=max (leftPad,-rp.x()-w);
644 if (rp.x()+floatimage.at(i)->width() > 0)
645 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
649 leftPad=max (leftPad,-rp.x());
650 if (rp.x()+floatimage.at(i)->width() > w)
651 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
661 w+=frame->getPadding();
662 h+=frame->getPadding();
665 bbox.setSize (QSizeF (w,h));
668 void BranchObj::setDockPos()
670 // Sets childpos and parpos depending on orientation
671 if (getOrientation()==LinkableMapObj::LeftOfCenter )
674 ornamentsBBox.bottomLeft().x(),
677 ornamentsBBox.bottomRight().x(),
682 ornamentsBBox.bottomRight().x(),
685 ornamentsBBox.bottomLeft().x(),
690 LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
694 for (int i=0; i<branch.size(); ++i)
696 lmo=branch.at(i)->findMapObj(p, excludeLMO);
697 if (lmo != NULL) return lmo;
702 if (inBox (p,clickBox) && (this != excludeLMO) && isVisibleObj() )
705 // Search float images
706 for (int i=0; i<floatimage.size(); ++i )
707 if (inBox(p,floatimage.at(i)->getClickBox()) &&
708 (floatimage.at(i) != excludeLMO) &&
709 floatimage.at(i)->getParObj()!= excludeLMO &&
710 floatimage.at(i)->isVisibleObj()
711 ) return floatimage.at(i);
716 LinkableMapObj* BranchObj::findID (QString sid)
720 for (int i=0; i<branch.size(); ++i)
722 lmo=branch.at(i)->findID (sid);
723 if (lmo != NULL) return lmo;
727 if (sid==objID) return this;
731 // Search float images
732 for (int i=0; i<floatimage.size(); ++i )
733 if (floatimage.at(i)->inBox(p) &&
734 (floatimage.at(i) != excludeLMO) &&
735 floatimage.at(i)->getParObj()!= excludeLMO &&
736 floatimage.at(i)->isVisibleObj()
737 ) return floatimage.at(i);
742 void BranchObj::setHeading(QString s)
744 heading->setText(s); // set new heading
745 calcBBoxSize(); // recalculate bbox
746 positionBBox(); // rearrange contents
750 void BranchObj::setHideTmp (HideTmpMode mode)
752 if (mode==HideExport && (hideExport|| hasHiddenExportParent() ) )
754 // Hide stuff according to hideExport flag and parents
755 setVisibility (false);
759 // Do not hide, but still take care of scrolled status
760 if (hasScrolledParent(this))
761 setVisibility (false);
763 setVisibility (true);
767 // And take care of my children
768 for (int i=0; i<branch.size(); ++i)
769 branch.at(i)->setHideTmp (mode);
772 bool BranchObj::hasHiddenExportParent()
774 // Calls parents recursivly to
775 // find out, if we or parents are temp. hidden
777 if (hidden || hideExport) return true;
779 BranchObj* bo=(BranchObj*)parObj;
781 return bo->hasHiddenExportParent();
786 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
788 // Cloudy stuff can be hidden during exports
789 if (hidden) return "";
791 // Update of note is usually done while unselecting a branch
792 if (isNoteInEditor) getNoteFromTextEditor();
795 QString scrolledAttr;
797 scrolledAttr=attribut ("scrolled","yes");
801 // save area, if not scrolled
803 if (!((BranchObj*)(parObj))->isScrolled() )
806 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
807 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
808 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
809 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
814 // Providing an ID for a branch makes export to XHTML easier
817 idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
821 s=beginElement ("branch"
826 +getIncludeImageAttr() );
830 s+=valueElement("heading", getHeading(),
831 attribut ("textColor",QColor(heading->getColor()).name()));
834 if (frame->getFrameType()!=FrameObj::NoFrame)
835 s+=frame->saveToDir ();
837 // save names of flags set
838 s+=standardFlags->saveToDir(tmpdir,prefix,0);
841 for (int i=0; i<floatimage.size(); ++i)
842 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
845 if (!note.isEmpty() )
849 for (int i=0; i<branch.size(); ++i)
850 s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
853 QString ol; // old link
854 QString cl; // current link
855 for (int i=0; i<xlink.size(); ++i)
857 cl=xlink.at(i)->saveToDir();
864 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
869 s+=endElement ("branch");
873 void BranchObj::addXLink (XLinkObj *xlo)
879 void BranchObj::removeXLinkRef (XLinkObj *xlo)
881 xlink.removeAt (xlink.indexOf(xlo));
884 void BranchObj::deleteXLink(XLinkObj *xlo)
887 if (!xlo->isUsed()) delete (xlo);
890 void BranchObj::deleteXLinkAt (int i)
892 XLinkObj *xlo=xlink.at(i);
894 if (!xlo->isUsed()) delete(xlo);
897 XLinkObj* BranchObj::XLinkAt (int i)
902 int BranchObj::countXLink()
904 return xlink.count();
908 BranchObj* BranchObj::XLinkTargetAt (int i)
910 if (i>=0 && i<xlink.size())
913 return xlink.at(i)->otherBranch (this);
918 void BranchObj::setIncludeImagesVer(bool b)
926 bool BranchObj::getIncludeImagesVer()
928 return includeImagesVer;
931 void BranchObj::setIncludeImagesHor(bool b)
939 bool BranchObj::getIncludeImagesHor()
941 return includeImagesHor;
944 QString BranchObj::getIncludeImageAttr()
947 if (includeImagesVer)
948 a=attribut ("incImgV","true");
950 a=attribut ("incImgV","false");
951 if (includeImagesHor)
952 a+=attribut ("incImgH","true");
954 a+=attribut ("incImgH","false");
958 FloatImageObj* BranchObj::addFloatImage ()
960 FloatImageObj *newfi=new FloatImageObj (scene,this);
961 floatimage.append (newfi);
962 if (hasScrolledParent(this) )
963 newfi->setVisibility (false);
965 newfi->setVisibility(visible);
974 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
976 FloatImageObj *newfi=new FloatImageObj (scene,this);
977 floatimage.append (newfi);
979 if (hasScrolledParent(this) )
980 newfi->setVisibility (false);
982 newfi->setVisibility(visible);
991 FloatImageObj* BranchObj::getFirstFloatImage ()
993 return floatimage.first();
996 FloatImageObj* BranchObj::getLastFloatImage ()
998 return floatimage.last();
1001 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
1003 return floatimage.at(i);
1006 void BranchObj::removeFloatImage (FloatImageObj *fio)
1008 int i=floatimage.indexOf (fio);
1009 if (i>-1) delete (floatimage.takeAt (i));
1012 requestReposition();
1015 void BranchObj::savePosInAngle ()
1017 // Save position in angle
1018 for (int i=0; i<branch.size(); ++i)
1019 branch.at(i)->angle=i;
1022 void BranchObj::setDefAttr (BranchModification mod)
1027 case 0: fontsize=16; break;
1028 case 1: fontsize=12; break;
1029 default: fontsize=10; break;
1033 setLinkStyle(getDefLinkStyle());
1034 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
1035 font.setPointSize(fontsize);
1036 heading->setFont(font );
1039 setColor (((BranchObj*)(parObj))->getColor());
1044 BranchObj* BranchObj::addBranch()
1046 BranchObj* newbo=new BranchObj(scene,this);
1047 branch.append (newbo);
1048 newbo->setParObj(this);
1049 newbo->setDefAttr(NewBranch);
1050 newbo->setHeading ("new");
1052 newbo->setVisibility (false);
1054 newbo->setVisibility(visible);
1055 newbo->updateLink();
1056 requestReposition();
1060 BranchObj* BranchObj::addBranch(BranchObj* bo)
1062 BranchObj* newbo=new BranchObj(scene,this);
1063 branch.append (newbo);
1065 newbo->setParObj(this);
1066 newbo->setDefAttr(MovedBranch);
1068 newbo->setVisibility (false);
1070 newbo->setVisibility(bo->visible);
1071 newbo->updateLink();
1072 requestReposition();
1076 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
1079 bo->setParObj (this);
1081 bo->setDefAttr(MovedBranch);
1082 if (scrolled) tmpUnscroll();
1083 setLastSelectedBranch (bo);
1087 BranchObj* BranchObj::insertBranch(int pos)
1090 // Add new bo and resort branches
1091 BranchObj *newbo=addBranch ();
1092 newbo->angle=pos-0.5;
1093 qSort (branch.begin(),branch.end(), isAbove);
1097 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
1100 // Add new bo and resort branches
1102 BranchObj *newbo=addBranch (bo);
1103 qSort (branch.begin(),branch.end(), isAbove);
1107 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
1110 // Add new bo and resort branches
1113 bo->setParObj (this);
1115 bo->setDefAttr (MovedBranch);
1116 if (scrolled) tmpUnscroll();
1117 setLastSelectedBranch (bo);
1118 qSort (branch.begin(),branch.end(), isAbove);
1122 void BranchObj::removeBranchHere(BranchObj* borem)
1124 // This removes the branch bo from list, but
1125 // inserts its children at the place of bo
1127 bo=borem->getLastBranch();
1128 int pos=borem->getNum();
1131 bo->linkTo (this,pos+1);
1132 bo=borem->getLastBranch();
1134 removeBranch (borem);
1137 void BranchObj::removeChildren()
1142 void BranchObj::removeBranch(BranchObj* bo)
1144 // if bo is not in branch remove returns false, we
1147 int i=branch.indexOf(bo);
1151 branch.removeAt (i);
1153 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
1154 requestReposition();
1157 void BranchObj::removeBranchPtr(BranchObj* bo)
1159 int i=branch.indexOf(bo);
1162 branch.removeAt (i);
1164 qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
1165 requestReposition();
1168 void BranchObj::setLastSelectedBranch (BranchObj* bo)
1170 lastSelectedBranch=branch.indexOf(bo);
1173 BranchObj* BranchObj::getLastSelectedBranch ()
1175 if (lastSelectedBranch>=0)
1177 if ( branch.size()>lastSelectedBranch)
1178 return branch.at(lastSelectedBranch);
1179 if (branch.size()>0)
1180 return branch.last();
1185 BranchObj* BranchObj::getFirstBranch ()
1187 if (branch.size()>0)
1188 return branch.first();
1193 BranchObj* BranchObj::getLastBranch ()
1195 if (branch.size()>0)
1196 return branch.last();
1201 BranchObj* BranchObj::getBranchNum (int i)
1203 if (i>=0 && i<branch.size())
1204 return branch.at(i);
1209 bool BranchObj::canMoveBranchUp()
1211 if (!parObj || depth==1) return false;
1212 BranchObj* par=(BranchObj*)parObj;
1213 if (this==par->getFirstBranch())
1219 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
1222 int i=branch.indexOf(bo1);
1224 { // -1 if bo1 not found
1225 branch.at(i)->angle--;
1226 branch.at(i-1)->angle++;
1227 qSort (branch.begin(),branch.end(), isAbove);
1228 return branch.at(i);
1233 bool BranchObj::canMoveBranchDown()
1235 if (!parObj|| depth==1) return false;
1236 BranchObj* par=(BranchObj*)parObj;
1237 if (this==par->getLastBranch())
1243 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
1246 int i=branch.indexOf(bo1);
1248 if (i <branch.size())
1251 branch.at(i)->angle++;
1252 branch.at(j)->angle--;
1253 qSort (branch.begin(),branch.end(), isAbove);
1254 return branch.at(i);
1259 void BranchObj::sortChildren()
1261 int childCount=branch.count();
1263 bool madeChanges=false;
1267 for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
1268 BranchObj* curChild=(BranchObj*)branch.at(curChildIndex);
1269 BranchObj* prevChild=(BranchObj*)branch.at(curChildIndex-1);
1270 if(prevChild->heading->text().compare(curChild->heading->text())>0)
1272 this->moveBranchUp(curChild);
1276 }while(madeChanges);
1280 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
1282 // Find current parent and
1283 // remove pointer to myself there
1284 if (!dst) return NULL;
1285 BranchObj *par=(BranchObj*)parObj;
1287 par->removeBranchPtr (this);
1291 // Create new pointer to myself at dst
1292 if (pos<0||dst->getDepth()==0)
1294 // links myself as last branch at dst
1295 dst->addBranchPtr (this);
1300 // inserts me at pos in parent of dst
1303 BranchObj *bo=dst->insertBranchPtr (this,pos);
1304 bo->setDefAttr(MovedBranch);
1313 void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
1315 qreal th = bboxTotal.height();
1318 QPointF pp; if (parObj) pp=parObj->getChildPos();
1319 cout << "BO::alignRelTo "<<qPrintable (getHeading());
1320 cout << " d="<<depth<<
1322 // " bbox.topLeft="<<bboxTotal.topLeft()<<
1323 " absPos="<<absPos<<
1324 // " relPos="<<relPos<<
1326 " width="<<bbox.width()<<
1327 " orient="<<orientation<<
1328 " alignSelf="<<alignSelf<<
1329 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
1330 // " hidden="<<hidden<<
1342 // Position relatively, if needed
1343 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
1345 // Calc angle to mapCenter if I am a mainbranch
1346 // needed for reordering the mainbranches clockwise
1348 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
1349 (int)(y() - parObj->getChildPos().y() ) ) );
1354 // Align myself depending on orientation and parent, but
1355 // only if I am not a mainbranch or mapcenter itself
1357 if (anim.isAnimated())
1362 LinkableMapObj::Orientation o;
1363 o=parObj->getOrientation();
1365 switch (orientation)
1367 case LinkableMapObj::LeftOfCenter:
1368 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1369 //move (ref.x() , ref.y() + (th-bbox.height())/2 );
1371 case LinkableMapObj::RightOfCenter:
1372 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1375 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1381 if (scrolled) return;
1383 // Set reference point for alignment of children
1385 if (orientation==LinkableMapObj::LeftOfCenter)
1386 ref2.setX(bbox.topLeft().x() - linkwidth);
1388 ref2.setX(bbox.topRight().x() + linkwidth);
1391 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1393 ref2.setY(ref.y() );
1395 // Align the children depending on reference point
1396 for (int i=0; i<branch.size(); ++i)
1398 if (!branch.at(i)->isHidden())
1400 branch.at(i)->alignRelativeTo (ref2,true);
1402 // append next branch below current one
1403 ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChildren().height() );
1409 void BranchObj::reposition()
1411 /* TODO testing only
1412 if (!getHeading().isEmpty())
1413 cout << "BO::reposition "<<qPrintable(getHeading())<<endl;
1415 cout << "BO::reposition ???"<<endl;
1417 cout << " orient="<<orientation<<endl;
1422 // only calculate the sizes once. If the deepest LMO
1423 // changes its height,
1424 // all upper LMOs have to change, too.
1425 calcBBoxSizeWithChildren();
1426 updateLink(); // This update is needed if the scene is resized
1427 // due to excessive moving of a FIO
1429 alignRelativeTo ( QPointF (absPos.x(),
1430 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1431 qSort (branch.begin(),branch.end(), isAbove);
1432 positionBBox(); // Reposition bbox and contents
1435 // This is only important for moving branches:
1436 // For editing a branch it isn't called...
1437 alignRelativeTo ( QPointF (absPos.x(),
1438 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1442 void BranchObj::unsetAllRepositionRequests()
1444 repositionRequest=false;
1445 for (int i=0; i<branch.size(); ++i)
1446 branch.at(i)->unsetAllRepositionRequests();
1450 QPolygonF BranchObj::shape()
1454 QRectF r=getTotalBBox();
1455 if (orientation==LinkableMapObj::LeftOfCenter)
1458 <<QPointF (bbox.topLeft().x(), r.topLeft().y() )
1460 <<bbox.bottomRight()
1461 <<QPointF (bbox.bottomLeft().x(), r.bottomLeft().y() ) ;
1465 <<QPointF (bbox.topRight().x(), r.topRight().y() )
1468 <<QPointF (bbox.bottomRight().x(), r.bottomRight().y() ) ;
1472 QRectF BranchObj::getTotalBBox()
1476 if (scrolled) return r;
1478 for (int i=0; i<branch.size(); ++i)
1479 if (!branch.at(i)->isHidden())
1480 r=addBBox(branch.at(i)->getTotalBBox(),r);
1482 for (int i=0; i<floatimage.size(); ++i)
1483 if (!floatimage.at(i)->isHidden())
1484 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1489 QRectF BranchObj::getBBoxSizeWithChildren()
1494 void BranchObj::calcBBoxSizeWithChildren()
1496 // This is initially called only from reposition and
1497 // and only for mapcenter. So it won't be
1498 // called more than once for a single user
1502 // Calculate size of LMO including all children (to align them later)
1503 bboxTotal.setX(bbox.x() );
1504 bboxTotal.setY(bbox.y() );
1506 // if branch is scrolled, ignore children, but still consider floatimages
1509 bboxTotal.setWidth (bbox.width());
1510 bboxTotal.setHeight(bbox.height());
1516 bboxTotal.setWidth (0);
1517 bboxTotal.setHeight(0);
1520 bboxTotal.setX (parObj->x());
1521 bboxTotal.setY (parObj->y());
1524 bboxTotal.setX (bbox.x());
1525 bboxTotal.setY (bbox.y());
1532 // Now calculate recursivly
1534 // maximum of widths
1536 for (int i=0; i<branch.size(); ++i)
1538 if (!branch.at(i)->isHidden())
1540 branch.at(i)->calcBBoxSizeWithChildren();
1541 br=branch.at(i)->getBBoxSizeWithChildren();
1542 r.setWidth( max (br.width(), r.width() ));
1543 r.setHeight(br.height() + r.height() );
1544 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1547 // Add myself and also
1548 // add width of link to sum if necessary
1549 if (branch.isEmpty())
1550 bboxTotal.setWidth (bbox.width() + r.width() );
1552 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1554 bboxTotal.setHeight(max (r.height(), bbox.height()));
1557 void BranchObj::select()
1559 // update NoteEditor
1560 textEditor->setText(note.getNote() );
1561 QString fnh=note.getFilenameHint();
1563 textEditor->setFilenameHint(note.getFilenameHint() );
1565 textEditor->setFilenameHint(getHeading() );
1566 textEditor->setFontHint (note.getFontHint() );
1567 isNoteInEditor=true;
1569 // set selected and visible
1570 LinkableMapObj::select();
1572 // Tell parent that I am selected now:
1573 BranchObj* po=(BranchObj*)(parObj);
1574 if (po) // TODO Try to get rid of this cast...
1575 po->setLastSelectedBranch(this);
1577 // temporary unscroll, if we have scrolled parents somewhere
1578 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1580 // Show URL and link in statusbar
1582 if (!url.isEmpty()) status+="URL: "+url+" ";
1583 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1584 if (!status.isEmpty()) mainWindow->statusMessage (status);
1587 updateFlagsToolbar();
1590 model->updateActions();
1593 void BranchObj::unselect()
1595 LinkableMapObj::unselect();
1596 // Delete any messages like vymLink in StatusBar
1597 mainWindow->statusMessage (""); //FIXME this causes segfault, when MainWindow is already gone in global destructor on quitting vym
1599 // Save current note
1600 if (isNoteInEditor) getNoteFromTextEditor();
1601 isNoteInEditor=false;
1603 // reset temporary unscroll, if we have scrolled parents somewhere
1604 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1606 // Erase content of editor
1607 textEditor->setInactive();
1609 // unselect all buttons in toolbar
1610 standardFlagsDefault->updateToolbar();
1613 QString BranchObj::getSelectString()
1615 return model->getSelectString (this);
1618 void BranchObj::setAnimation(const AnimPoint &ap)
1623 bool BranchObj::animate()
1626 if ( anim.isAnimated() )
1631 parObj->reposition(); // we might have been relinked meanwhile