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()
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 mapEditor->getModel()->stopAnimation (this);
64 //cout << "Destr BranchObj of "<<this<<endl;
65 // Check, if this branch was the last child to be deleted
66 // If so, unset the scrolled flags
68 BranchObj *po=(BranchObj*)parObj;
72 bo=((BranchObj*)parObj)->getLastBranch();
73 if (bo) po->unScroll();
78 bool BranchObj::operator< ( const BranchObj & other )
80 return angle < other.angle;
83 bool BranchObj::operator== ( const BranchObj & other )
85 return angle == other.angle;
88 void BranchObj::init ()
93 absPos+=parObj->getChildPos();
103 includeImagesVer=false;
104 includeImagesHor=false;
107 void BranchObj::copy (BranchObj* other)
109 OrnamentedObj::copy(other);
112 for (int i=0; i<other->branch.size(); ++i)
113 // Make deep copy of b
114 // Because addBranch again calls copy for the childs,
115 // Those will get a deep copy, too
116 addBranch(other->branch.at(i) );
118 for (int i=0; i<other->floatimage.size(); ++i)
119 addFloatImage (other->floatimage.at(i));
120 scrolled=other->scrolled;
121 tmpUnscrolled=other->tmpUnscrolled;
122 setVisibility (other->visible);
129 void BranchObj::clear()
131 setVisibility (true);
133 while (!floatimage.isEmpty())
134 delete floatimage.takeFirst();
136 while (!xlink.isEmpty())
137 delete xlink.takeFirst();
139 while (!branch.isEmpty())
140 delete branch.takeFirst();
143 bool isAbove (BranchObj* a, BranchObj *b)
145 if (a->angle < b->angle)
151 int BranchObj::getNum()
154 return ((BranchObj*)parObj)->getNum (this);
159 int BranchObj::getNum(BranchObj *bo)
161 return branch.indexOf (bo);
164 int BranchObj::getFloatImageNum(FloatImageObj *fio)
166 return floatimage.indexOf(fio);
169 int BranchObj::countBranches()
171 return branch.count();
174 int BranchObj::countFloatImages()
176 return floatimage.count();
179 int BranchObj::countXLinks()
181 return xlink.count();
184 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
186 // Temporary link to lmo
187 // m is position of mouse pointer
188 // offset 0: default 1: below lmo -1 above lmo (if possible)
191 BranchObj* o=(BranchObj*)(lmo);
195 // ignore mapcenter and mainbranch
196 if (lmo->getDepth()<2) off=0;
203 depth=parObj->getDepth()+1;
205 // setLinkStyle calls updateLink, only set it once
206 if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
208 // Move temporary to new position at destination
209 // Usually the positioning would be done by reposition(),
210 // but then also the destination branch would "Jump" around...
211 // Better just do it approximately
213 { // new parent is the mapcenter itself
215 QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
216 m.y() - o->getChildPos().y() ));
217 if (p.x()<0) p.setX( p.x()-bbox.width() );
224 // new parent is just a branch, link to it
225 QRectF t=o->getBBoxSizeWithChilds();
226 if (o->getLastBranch())
227 y=t.y() + t.height() ;
234 // we want to link above lmo
235 y=o->y() - height() + 5;
237 // we want to link below lmo
238 // Bottom of sel should be 5 pixels above
239 // the bottom of the branch _below_ the target:
240 // Don't try to find that branch, guess 12 pixels
241 y=o->getChildPos().y() -height() + 12;
243 if (o->getOrientation()==LinkableMapObj::LeftOfCenter)
244 move ( o->getChildPos().x() - linkwidth, y );
246 move (o->getChildPos().x() + linkwidth, y );
249 // updateLink is called implicitly in move
253 void BranchObj::unsetParObjTmp()
260 depth=parObj->getDepth()+1;
261 setLinkStyle (getDefLinkStyle() );
266 void BranchObj::unScroll()
268 if (tmpUnscrolled) resetTmpUnscroll();
269 if (scrolled) toggleScroll();
272 void BranchObj::toggleScroll()
277 systemFlags->deactivate("scrolledright");
278 for (int i=0; i<branch.size(); ++i)
279 branch.at(i)->setVisibility(true);
283 systemFlags->activate("scrolledright");
284 for (int i=0; i<branch.size(); ++i)
285 branch.at(i)->setVisibility(false);
289 move (absPos.x(), absPos.y() );
293 bool BranchObj::isScrolled()
298 bool BranchObj::hasScrolledParent(BranchObj *start)
300 // Calls parents recursivly to
301 // find out, if we are scrolled at all.
302 // But ignore myself, just look at parents.
304 if (this !=start && scrolled) return true;
306 BranchObj* bo=(BranchObj*)(parObj);
308 return bo->hasScrolledParent(start);
313 void BranchObj::tmpUnscroll()
315 // Unscroll parent (recursivly)
316 BranchObj* bo=(BranchObj*)(parObj);
317 if (bo) bo->tmpUnscroll();
323 systemFlags->activate("tmpUnscrolledright");
328 void BranchObj::resetTmpUnscroll()
330 // Unscroll parent (recursivly)
331 BranchObj* bo=(BranchObj*)(parObj);
333 bo->resetTmpUnscroll();
339 systemFlags->deactivate("tmpUnscrolledright");
344 void BranchObj::setVisibility(bool v, int toDepth)
346 if (depth <= toDepth)
348 frame->setVisibility(v);
349 heading->setVisibility(v);
350 systemFlags->setVisibility(v);
351 standardFlags->setVisibility(v);
352 LinkableMapObj::setVisibility (v);
355 for (i=0; i<floatimage.size(); ++i)
356 floatimage.at(i)->setVisibility (v);
357 for (i=0; i<xlink.size(); ++i)
358 xlink.at(i)->setVisibility ();
360 // Only change childs, if I am not scrolled
361 if (!scrolled && (depth < toDepth))
363 // Now go recursivly through all childs
364 for (i=0; i<branch.size(); ++i)
365 branch.at(i)->setVisibility (v,toDepth);
367 } // depth <= toDepth
371 void BranchObj::setVisibility(bool v)
373 setVisibility (v,MAX_DEPTH);
377 void BranchObj::setLinkColor ()
379 // Overloaded from LinkableMapObj
380 // BranchObj can use color of heading
384 if (mapEditor->getMapLinkColorHint()==HeadingColor)
385 LinkableMapObj::setLinkColor (heading->getColor() );
387 LinkableMapObj::setLinkColor ();
391 void BranchObj::setColorSubtree(QColor col)
394 for (int i=0; i<branch.size(); ++i)
395 branch.at(i)->setColorSubtree(col);
398 BranchObj* BranchObj::first()
405 BranchObj* BranchObj::next()
409 BranchObj *po=(BranchObj*)parObj;
411 if (branch.isEmpty())
418 // no itLast, we are just beginning
421 // we have childs, return first one
427 // No childs, so there is no next
435 { // We come from parent
438 // there are childs, go there
443 { // no childs, try to go up again
446 // go back to parent and try to find next there
455 // can't go up, I am mapCenter, no next
462 // We don't come from parent, but from brother or childs
464 // Try to find last child, where we came from, in my own childs
467 while (i<branch.size())
469 // Try to find itLast in my own childs
470 if (itLast==branch.at(i))
472 // ok, we come from my own childs
473 if (i<branch.size()-1)
483 { // found itLast in my childs
486 // found a brother of lastLMO
494 if (this==itFirst) return NULL; // Stop at starting point
503 // can't go up, I am mapCenter
510 // couldn't find last child, it must be a nephew of mine
513 // proceed with my first child
515 return branch.first();
519 // or go back to my parents
530 // can't go up, I am mapCenter
537 BranchObj* BranchObj::getLastIterator()
542 void BranchObj::setLastIterator(BranchObj* it)
547 void BranchObj::positionContents()
549 for (int i=0; i<floatimage.size(); ++i )
550 floatimage.at(i)->reposition();
551 OrnamentedObj::positionContents();
554 void BranchObj::move (double x, double y)
556 OrnamentedObj::move (x,y);
557 for (int i=0; i<floatimage.size(); ++i )
558 floatimage.at(i)->reposition();
562 void BranchObj::move (QPointF p)
567 void BranchObj::moveBy (double x, double y)
569 OrnamentedObj::moveBy (x,y);
570 for (int i=0; i<branch.size(); ++i)
571 branch.at(i)->moveBy (x,y);
575 void BranchObj::moveBy (QPointF p)
577 moveBy (p.x(), p.y());
581 void BranchObj::positionBBox()
583 QPointF ap=getAbsPos();
584 bbox.moveTopLeft (ap);
588 frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
590 // Update links to other branches
591 for (int i=0; i<xlink.size(); ++i)
592 xlink.at(i)->updateXLink();
595 void BranchObj::calcBBoxSize()
597 QSizeF heading_r=heading->getSize();
598 qreal heading_w=(qreal) heading_r.width() ;
599 qreal heading_h=(qreal) heading_r.height() ;
600 QSizeF sysflags_r=systemFlags->getSize();
601 qreal sysflags_h=sysflags_r.height();
602 qreal sysflags_w=sysflags_r.width();
603 QSizeF stanflags_r=standardFlags->getSize();
604 qreal stanflags_h=stanflags_r.height();
605 qreal stanflags_w=stanflags_r.width();
609 // set width to sum of all widths
610 w=heading_w + sysflags_w + stanflags_w;
611 // set height to maximum needed height
612 h=max (sysflags_h,stanflags_h);
615 // Save the dimension of flags and heading
616 ornamentsBBox.setSize ( QSizeF(w,h));
618 // clickBox includes Flags and Heading
619 clickBox.setSize (ornamentsBBox.size() );
624 topPad=botPad=leftPad=rightPad=0;
625 if (includeImagesVer || includeImagesHor)
627 if (countFloatImages()>0)
629 for (int i=0; i<floatimage.size(); ++i )
631 rp=floatimage.at(i)->getRelPos();
632 if (includeImagesVer)
635 topPad=max (topPad,-rp.y()-h);
636 if (rp.y()+floatimage.at(i)->height() > 0)
637 botPad=max (botPad,rp.y()+floatimage.at(i)->height());
639 if (includeImagesHor)
641 if (orientation==LinkableMapObj::RightOfCenter)
644 leftPad=max (leftPad,-rp.x()-w);
645 if (rp.x()+floatimage.at(i)->width() > 0)
646 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
650 leftPad=max (leftPad,-rp.x());
651 if (rp.x()+floatimage.at(i)->width() > w)
652 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
662 w+=frame->getPadding();
663 h+=frame->getPadding();
666 bbox.setSize (QSizeF (w,h));
669 void BranchObj::setDockPos()
671 // Sets childpos and parpos depending on orientation
672 if (getOrientation()==LinkableMapObj::LeftOfCenter )
675 ornamentsBBox.bottomLeft().x(),
678 ornamentsBBox.bottomRight().x(),
683 ornamentsBBox.bottomRight().x(),
686 ornamentsBBox.bottomLeft().x(),
691 LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
695 for (int i=0; i<branch.size(); ++i)
697 lmo=branch.at(i)->findMapObj(p, excludeLMO);
698 if (lmo != NULL) return lmo;
703 if (inBox (p,clickBox) && (this != excludeLMO) && isVisibleObj() )
706 // Search float images
707 for (int i=0; i<floatimage.size(); ++i )
708 if (inBox(p,floatimage.at(i)->getClickBox()) &&
709 (floatimage.at(i) != excludeLMO) &&
710 floatimage.at(i)->getParObj()!= excludeLMO &&
711 floatimage.at(i)->isVisibleObj()
712 ) return floatimage.at(i);
717 LinkableMapObj* BranchObj::findID (QString sid)
721 for (int i=0; i<branch.size(); ++i)
723 lmo=branch.at(i)->findID (sid);
724 if (lmo != NULL) return lmo;
728 if (sid==objID) return this;
732 // Search float images
733 for (int i=0; i<floatimage.size(); ++i )
734 if (floatimage.at(i)->inBox(p) &&
735 (floatimage.at(i) != excludeLMO) &&
736 floatimage.at(i)->getParObj()!= excludeLMO &&
737 floatimage.at(i)->isVisibleObj()
738 ) return floatimage.at(i);
743 void BranchObj::setHeading(QString s)
745 heading->setText(s); // set new heading
746 calcBBoxSize(); // recalculate bbox
747 positionBBox(); // rearrange contents
751 void BranchObj::setHideTmp (HideTmpMode mode)
753 if (mode==HideExport && (hideExport|| hasHiddenExportParent() ) )
755 // Hide stuff according to hideExport flag and parents
756 setVisibility (false);
760 // Do not hide, but still take care of scrolled status
761 if (hasScrolledParent(this))
762 setVisibility (false);
764 setVisibility (true);
768 // And take care of my childs
769 for (int i=0; i<branch.size(); ++i)
770 branch.at(i)->setHideTmp (mode);
773 bool BranchObj::hasHiddenExportParent()
775 // Calls parents recursivly to
776 // find out, if we or parents are temp. hidden
778 if (hidden || hideExport) return true;
780 BranchObj* bo=(BranchObj*)parObj;
782 return bo->hasHiddenExportParent();
787 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
789 // Cloudy stuff can be hidden during exports
790 if (hidden) return "";
792 // Update of note is usually done while unselecting a branch
793 if (isNoteInEditor) getNoteFromTextEditor();
796 QString scrolledAttr;
798 scrolledAttr=attribut ("scrolled","yes");
802 // save area, if not scrolled
804 if (!((BranchObj*)(parObj))->isScrolled() )
807 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
808 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
809 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
810 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
815 // Providing an ID for a branch makes export to XHTML easier
818 idAttr=attribut ("id",mapEditor->getModel()->getSelectString(this)); //TODO directly access model
822 s=beginElement ("branch"
827 +getIncludeImageAttr() );
831 s+=valueElement("heading", getHeading(),
832 attribut ("textColor",QColor(heading->getColor()).name()));
835 if (frame->getFrameType()!=FrameObj::NoFrame)
836 s+=frame->saveToDir ();
838 // save names of flags set
839 s+=standardFlags->saveToDir(tmpdir,prefix,0);
842 for (int i=0; i<floatimage.size(); ++i)
843 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
846 if (!note.isEmpty() )
850 for (int i=0; i<branch.size(); ++i)
851 s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
854 QString ol; // old link
855 QString cl; // current link
856 for (int i=0; i<xlink.size(); ++i)
858 cl=xlink.at(i)->saveToDir();
865 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
870 s+=endElement ("branch");
874 void BranchObj::addXLink (XLinkObj *xlo)
880 void BranchObj::removeXLinkRef (XLinkObj *xlo)
882 xlink.removeAt (xlink.indexOf(xlo));
885 void BranchObj::deleteXLink(XLinkObj *xlo)
888 if (!xlo->isUsed()) delete (xlo);
891 void BranchObj::deleteXLinkAt (int i)
893 XLinkObj *xlo=xlink.at(i);
895 if (!xlo->isUsed()) delete(xlo);
898 XLinkObj* BranchObj::XLinkAt (int i)
903 int BranchObj::countXLink()
905 return xlink.count();
909 BranchObj* BranchObj::XLinkTargetAt (int i)
911 if (i>=0 && i<xlink.size())
914 return xlink.at(i)->otherBranch (this);
919 void BranchObj::setIncludeImagesVer(bool b)
927 bool BranchObj::getIncludeImagesVer()
929 return includeImagesVer;
932 void BranchObj::setIncludeImagesHor(bool b)
940 bool BranchObj::getIncludeImagesHor()
942 return includeImagesHor;
945 QString BranchObj::getIncludeImageAttr()
948 if (includeImagesVer)
949 a=attribut ("incImgV","true");
951 a=attribut ("incImgV","false");
952 if (includeImagesHor)
953 a+=attribut ("incImgH","true");
955 a+=attribut ("incImgH","false");
959 FloatImageObj* BranchObj::addFloatImage ()
961 FloatImageObj *newfi=new FloatImageObj (scene,this);
962 floatimage.append (newfi);
963 if (hasScrolledParent(this) )
964 newfi->setVisibility (false);
966 newfi->setVisibility(visible);
975 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
977 FloatImageObj *newfi=new FloatImageObj (scene,this);
978 floatimage.append (newfi);
980 if (hasScrolledParent(this) )
981 newfi->setVisibility (false);
983 newfi->setVisibility(visible);
992 FloatImageObj* BranchObj::getFirstFloatImage ()
994 return floatimage.first();
997 FloatImageObj* BranchObj::getLastFloatImage ()
999 return floatimage.last();
1002 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
1004 return floatimage.at(i);
1007 void BranchObj::removeFloatImage (FloatImageObj *fio)
1009 int i=floatimage.indexOf (fio);
1010 if (i>-1) delete (floatimage.takeAt (i));
1013 requestReposition();
1016 void BranchObj::savePosInAngle ()
1018 // Save position in angle
1019 for (int i=0; i<branch.size(); ++i)
1020 branch.at(i)->angle=i;
1023 void BranchObj::setDefAttr (BranchModification mod)
1028 case 0: fontsize=16; break;
1029 case 1: fontsize=12; break;
1030 default: fontsize=10; break;
1034 setLinkStyle(getDefLinkStyle());
1035 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
1036 font.setPointSize(fontsize);
1037 heading->setFont(font );
1040 setColor (((BranchObj*)(parObj))->getColor());
1045 BranchObj* BranchObj::addBranch()
1047 BranchObj* newbo=new BranchObj(scene,this);
1048 branch.append (newbo);
1049 newbo->setParObj(this);
1050 newbo->setDefAttr(NewBranch);
1051 newbo->setHeading ("new");
1053 newbo->setVisibility (false);
1055 newbo->setVisibility(visible);
1056 newbo->updateLink();
1057 requestReposition();
1061 BranchObj* BranchObj::addBranch(BranchObj* bo)
1063 BranchObj* newbo=new BranchObj(scene,this);
1064 branch.append (newbo);
1066 newbo->setParObj(this);
1067 newbo->setDefAttr(MovedBranch);
1069 newbo->setVisibility (false);
1071 newbo->setVisibility(bo->visible);
1072 newbo->updateLink();
1073 requestReposition();
1077 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
1080 bo->setParObj (this);
1082 bo->setDefAttr(MovedBranch);
1083 if (scrolled) tmpUnscroll();
1084 setLastSelectedBranch (bo);
1088 BranchObj* BranchObj::insertBranch(int pos)
1091 // Add new bo and resort branches
1092 BranchObj *newbo=addBranch ();
1093 newbo->angle=pos-0.5;
1094 qSort (branch.begin(),branch.end(), isAbove);
1098 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
1101 // Add new bo and resort branches
1103 BranchObj *newbo=addBranch (bo);
1104 qSort (branch.begin(),branch.end(), isAbove);
1108 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
1111 // Add new bo and resort branches
1114 bo->setParObj (this);
1116 bo->setDefAttr (MovedBranch);
1117 if (scrolled) tmpUnscroll();
1118 setLastSelectedBranch (bo);
1119 qSort (branch.begin(),branch.end(), isAbove);
1123 void BranchObj::removeBranchHere(BranchObj* borem)
1125 // This removes the branch bo from list, but
1126 // inserts its childs at the place of bo
1128 bo=borem->getLastBranch();
1129 int pos=borem->getNum();
1132 bo->linkTo (this,pos+1);
1133 bo=borem->getLastBranch();
1135 removeBranch (borem);
1138 void BranchObj::removeChilds()
1143 void BranchObj::removeBranch(BranchObj* bo)
1145 // if bo is not in branch remove returns false, we
1148 int i=branch.indexOf(bo);
1152 branch.removeAt (i);
1154 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
1155 requestReposition();
1158 void BranchObj::removeBranchPtr(BranchObj* bo)
1160 int i=branch.indexOf(bo);
1163 branch.removeAt (i);
1165 qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
1166 requestReposition();
1169 void BranchObj::setLastSelectedBranch (BranchObj* bo)
1171 lastSelectedBranch=branch.indexOf(bo);
1174 BranchObj* BranchObj::getLastSelectedBranch ()
1176 if (lastSelectedBranch>=0)
1178 if ( branch.size()>lastSelectedBranch)
1179 return branch.at(lastSelectedBranch);
1180 if (branch.size()>0)
1181 return branch.last();
1186 BranchObj* BranchObj::getFirstBranch ()
1188 if (branch.size()>0)
1189 return branch.first();
1194 BranchObj* BranchObj::getLastBranch ()
1196 if (branch.size()>0)
1197 return branch.last();
1202 BranchObj* BranchObj::getBranchNum (int i)
1204 if (i>=0 && i<branch.size())
1205 return branch.at(i);
1210 bool BranchObj::canMoveBranchUp()
1212 if (!parObj || depth==1) return false;
1213 BranchObj* par=(BranchObj*)parObj;
1214 if (this==par->getFirstBranch())
1220 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
1223 int i=branch.indexOf(bo1);
1225 { // -1 if bo1 not found
1226 branch.at(i)->angle--;
1227 branch.at(i-1)->angle++;
1228 qSort (branch.begin(),branch.end(), isAbove);
1229 return branch.at(i);
1234 bool BranchObj::canMoveBranchDown()
1236 if (!parObj|| depth==1) return false;
1237 BranchObj* par=(BranchObj*)parObj;
1238 if (this==par->getLastBranch())
1244 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
1247 int i=branch.indexOf(bo1);
1249 if (i <branch.size())
1252 branch.at(i)->angle++;
1253 branch.at(j)->angle--;
1254 qSort (branch.begin(),branch.end(), isAbove);
1255 return branch.at(i);
1260 void BranchObj::sortChildren()
1262 int childCount=branch.count();
1264 bool madeChanges=false;
1268 for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
1269 BranchObj* curChild=(BranchObj*)branch.at(curChildIndex);
1270 BranchObj* prevChild=(BranchObj*)branch.at(curChildIndex-1);
1271 if(prevChild->heading->text().compare(curChild->heading->text())>0)
1273 this->moveBranchUp(curChild);
1277 }while(madeChanges);
1281 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
1283 // Find current parent and
1284 // remove pointer to myself there
1285 if (!dst) return NULL;
1286 BranchObj *par=(BranchObj*)parObj;
1288 par->removeBranchPtr (this);
1292 // Create new pointer to myself at dst
1293 if (pos<0||dst->getDepth()==0)
1295 // links myself as last branch at dst
1296 dst->addBranchPtr (this);
1301 // inserts me at pos in parent of dst
1304 BranchObj *bo=dst->insertBranchPtr (this,pos);
1305 bo->setDefAttr(MovedBranch);
1314 void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
1316 qreal th = bboxTotal.height();
1319 QPointF pp; if (parObj) pp=parObj->getChildPos();
1320 cout << "BO::alignRelTo "<<qPrintable (getHeading());
1321 cout << " d="<<depth<<
1323 // " bbox.topLeft="<<bboxTotal.topLeft()<<
1324 " absPos="<<absPos<<
1325 " relPos="<<relPos<<
1327 " orient="<<orientation<<
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 );
1369 case LinkableMapObj::RightOfCenter:
1370 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1373 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1379 if (scrolled) return;
1381 // Set reference point for alignment of childs
1383 if (orientation==LinkableMapObj::LeftOfCenter)
1384 ref2.setX(bbox.topLeft().x() - linkwidth);
1386 ref2.setX(bbox.topRight().x() + linkwidth);
1389 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1391 ref2.setY(ref.y() );
1393 // Align the childs depending on reference point
1394 for (int i=0; i<branch.size(); ++i)
1396 if (!branch.at(i)->isHidden())
1398 branch.at(i)->alignRelativeTo (ref2,true);
1399 ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChilds().height() );
1405 void BranchObj::reposition()
1407 /* TODO testing only
1408 if (!getHeading().isEmpty())
1409 cout << "BO::reposition "<<qPrintable(getHeading())<<endl;
1411 cout << "BO::reposition ???"<<endl;
1413 cout << " orient="<<orientation<<endl;
1418 // only calculate the sizes once. If the deepest LMO
1419 // changes its height,
1420 // all upper LMOs have to change, too.
1421 calcBBoxSizeWithChilds();
1422 updateLink(); // This update is needed if the scene is resized
1423 // due to excessive moving of a FIO
1425 alignRelativeTo ( QPointF (absPos.x(),
1426 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1427 qSort (branch.begin(),branch.end(), isAbove);
1428 positionBBox(); // Reposition bbox and contents
1431 // This is only important for moving branches:
1432 // For editing a branch it isn't called...
1433 alignRelativeTo ( QPointF (absPos.x(),
1434 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1438 void BranchObj::unsetAllRepositionRequests()
1440 repositionRequest=false;
1441 for (int i=0; i<branch.size(); ++i)
1442 branch.at(i)->unsetAllRepositionRequests();
1446 QPolygonF BranchObj::shape()
1450 QRectF r=getTotalBBox();
1451 if (orientation==LinkableMapObj::LeftOfCenter)
1454 <<QPointF (bbox.topLeft().x(), r.topLeft().y() )
1456 <<bbox.bottomRight()
1457 <<QPointF (bbox.bottomLeft().x(), r.bottomLeft().y() ) ;
1461 <<QPointF (bbox.topRight().x(), r.topRight().y() )
1464 <<QPointF (bbox.bottomRight().x(), r.bottomRight().y() ) ;
1468 QRectF BranchObj::getTotalBBox()
1472 if (scrolled) return r;
1474 for (int i=0; i<branch.size(); ++i)
1475 if (!branch.at(i)->isHidden())
1476 r=addBBox(branch.at(i)->getTotalBBox(),r);
1478 for (int i=0; i<floatimage.size(); ++i)
1479 if (!floatimage.at(i)->isHidden())
1480 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1485 QRectF BranchObj::getBBoxSizeWithChilds()
1490 void BranchObj::calcBBoxSizeWithChilds()
1492 // This is initially called only from reposition and
1493 // and only for mapcenter. So it won't be
1494 // called more than once for a single user
1498 // Calculate size of LMO including all childs (to align them later)
1499 bboxTotal.setX(bbox.x() );
1500 bboxTotal.setY(bbox.y() );
1502 // if branch is scrolled, ignore childs, but still consider floatimages
1505 bboxTotal.setWidth (bbox.width());
1506 bboxTotal.setHeight(bbox.height());
1512 bboxTotal.setWidth (0);
1513 bboxTotal.setHeight(0);
1516 bboxTotal.setX (parObj->x());
1517 bboxTotal.setY (parObj->y());
1520 bboxTotal.setX (bbox.x());
1521 bboxTotal.setY (bbox.y());
1528 // Now calculate recursivly
1530 // maximum of widths
1532 for (int i=0; i<branch.size(); ++i)
1534 if (!branch.at(i)->isHidden())
1536 branch.at(i)->calcBBoxSizeWithChilds();
1537 br=branch.at(i)->getBBoxSizeWithChilds();
1538 r.setWidth( max (br.width(), r.width() ));
1539 r.setHeight(br.height() + r.height() );
1540 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1543 // Add myself and also
1544 // add width of link to sum if necessary
1545 if (branch.isEmpty())
1546 bboxTotal.setWidth (bbox.width() + r.width() );
1548 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1550 bboxTotal.setHeight(max (r.height(), bbox.height()));
1553 void BranchObj::select()
1555 // update NoteEditor
1556 textEditor->setText(note.getNote() );
1557 QString fnh=note.getFilenameHint();
1559 textEditor->setFilenameHint(note.getFilenameHint() );
1561 textEditor->setFilenameHint(getHeading() );
1562 textEditor->setFontHint (note.getFontHint() );
1563 isNoteInEditor=true;
1565 // set selected and visible
1566 LinkableMapObj::select();
1568 // Tell parent that I am selected now:
1569 BranchObj* po=(BranchObj*)(parObj);
1570 if (po) // TODO Try to get rid of this cast...
1571 po->setLastSelectedBranch(this);
1573 // temporary unscroll, if we have scrolled parents somewhere
1574 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1576 // Show URL and link in statusbar
1578 if (!url.isEmpty()) status+="URL: "+url+" ";
1579 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1580 if (!status.isEmpty()) mainWindow->statusMessage (status);
1583 updateFlagsToolbar();
1586 mapEditor->updateActions();
1589 void BranchObj::unselect()
1591 LinkableMapObj::unselect();
1592 // Delete any messages like vymLink in StatusBar
1593 mainWindow->statusMessage ("");
1595 // Save current note
1596 if (isNoteInEditor) getNoteFromTextEditor();
1597 isNoteInEditor=false;
1599 // reset temporary unscroll, if we have scrolled parents somewhere
1600 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1602 // Erase content of editor
1603 textEditor->setInactive();
1605 // unselect all buttons in toolbar
1606 standardFlagsDefault->updateToolbar();
1609 QString BranchObj::getSelectString()
1611 return mapEditor->getModel()->getSelectString (this);
1614 void BranchObj::setAnimation(const AnimPoint &ap)
1619 bool BranchObj::animate()
1622 if ( anim.isAnimated() )
1627 parObj->reposition(); // object might have been relinked meanwhile