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);
354 // Only change childs, if I am not scrolled
355 if (!scrolled && (depth < toDepth))
357 // Now go recursivly through all childs
359 for (i=0; i<branch.size(); ++i)
360 branch.at(i)->setVisibility (v,toDepth);
361 for (i=0; i<floatimage.size(); ++i)
362 floatimage.at(i)->setVisibility (v);
363 for (i=0; i<xlink.size(); ++i)
364 xlink.at(i)->setVisibility ();
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 (mapEditor->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 childs, return first one
426 // No childs, so there is no next
434 { // We come from parent
437 // there are childs, go there
442 { // no childs, 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 childs
463 // Try to find last child, where we came from, in my own childs
466 while (i<branch.size())
468 // Try to find itLast in my own childs
469 if (itLast==branch.at(i))
471 // ok, we come from my own childs
472 if (i<branch.size()-1)
482 { // found itLast in my childs
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 childs
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",mapEditor->getModel()->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 childs 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::removeChilds()
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 " orient="<<orientation<<
1327 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
1328 // " hidden="<<hidden<<
1340 // Position relatively, if needed
1341 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
1343 // Calc angle to mapCenter if I am a mainbranch
1344 // needed for reordering the mainbranches clockwise
1346 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
1347 (int)(y() - parObj->getChildPos().y() ) ) );
1352 // Align myself depending on orientation and parent, but
1353 // only if I am not a mainbranch or mapcenter itself
1355 if (anim.isAnimated())
1360 LinkableMapObj::Orientation o;
1361 o=parObj->getOrientation();
1363 switch (orientation)
1365 case LinkableMapObj::LeftOfCenter:
1366 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1368 case LinkableMapObj::RightOfCenter:
1369 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1372 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1378 if (scrolled) return;
1380 // Set reference point for alignment of childs
1382 if (orientation==LinkableMapObj::LeftOfCenter)
1383 ref2.setX(bbox.topLeft().x() - linkwidth);
1385 ref2.setX(bbox.topRight().x() + linkwidth);
1388 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1390 ref2.setY(ref.y() );
1392 // Align the childs depending on reference point
1393 for (int i=0; i<branch.size(); ++i)
1395 if (!branch.at(i)->isHidden())
1397 branch.at(i)->alignRelativeTo (ref2,true);
1398 ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChilds().height() );
1404 void BranchObj::reposition()
1406 /* TODO testing only
1407 if (!getHeading().isEmpty())
1408 cout << "BO::reposition "<<qPrintable(getHeading())<<endl;
1410 cout << "BO::reposition ???"<<endl;
1412 cout << " orient="<<orientation<<endl;
1417 // only calculate the sizes once. If the deepest LMO
1418 // changes its height,
1419 // all upper LMOs have to change, too.
1420 calcBBoxSizeWithChilds();
1421 updateLink(); // This update is needed if the scene is resized
1422 // due to excessive moving of a FIO
1424 alignRelativeTo ( QPointF (absPos.x(),
1425 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1426 qSort (branch.begin(),branch.end(), isAbove);
1427 positionBBox(); // Reposition bbox and contents
1430 // This is only important for moving branches:
1431 // For editing a branch it isn't called...
1432 alignRelativeTo ( QPointF (absPos.x(),
1433 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1437 void BranchObj::unsetAllRepositionRequests()
1439 repositionRequest=false;
1440 for (int i=0; i<branch.size(); ++i)
1441 branch.at(i)->unsetAllRepositionRequests();
1445 QPolygonF BranchObj::shape()
1449 QRectF r=getTotalBBox();
1450 if (orientation==LinkableMapObj::LeftOfCenter)
1453 <<QPointF (bbox.topLeft().x(), r.topLeft().y() )
1455 <<bbox.bottomRight()
1456 <<QPointF (bbox.bottomLeft().x(), r.bottomLeft().y() ) ;
1460 <<QPointF (bbox.topRight().x(), r.topRight().y() )
1463 <<QPointF (bbox.bottomRight().x(), r.bottomRight().y() ) ;
1467 QRectF BranchObj::getTotalBBox()
1471 if (scrolled) return r;
1473 for (int i=0; i<branch.size(); ++i)
1474 if (!branch.at(i)->isHidden())
1475 r=addBBox(branch.at(i)->getTotalBBox(),r);
1477 for (int i=0; i<floatimage.size(); ++i)
1478 if (!floatimage.at(i)->isHidden())
1479 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1484 QRectF BranchObj::getBBoxSizeWithChilds()
1489 void BranchObj::calcBBoxSizeWithChilds()
1491 // This is initially called only from reposition and
1492 // and only for mapcenter. So it won't be
1493 // called more than once for a single user
1497 // Calculate size of LMO including all childs (to align them later)
1498 bboxTotal.setX(bbox.x() );
1499 bboxTotal.setY(bbox.y() );
1501 // if branch is scrolled, ignore childs, but still consider floatimages
1504 bboxTotal.setWidth (bbox.width());
1505 bboxTotal.setHeight(bbox.height());
1511 bboxTotal.setWidth (0);
1512 bboxTotal.setHeight(0);
1515 bboxTotal.setX (parObj->x());
1516 bboxTotal.setY (parObj->y());
1519 bboxTotal.setX (bbox.x());
1520 bboxTotal.setY (bbox.y());
1527 // Now calculate recursivly
1529 // maximum of widths
1531 for (int i=0; i<branch.size(); ++i)
1533 if (!branch.at(i)->isHidden())
1535 branch.at(i)->calcBBoxSizeWithChilds();
1536 br=branch.at(i)->getBBoxSizeWithChilds();
1537 r.setWidth( max (br.width(), r.width() ));
1538 r.setHeight(br.height() + r.height() );
1539 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1542 // Add myself and also
1543 // add width of link to sum if necessary
1544 if (branch.isEmpty())
1545 bboxTotal.setWidth (bbox.width() + r.width() );
1547 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1549 bboxTotal.setHeight(max (r.height(), bbox.height()));
1552 void BranchObj::select()
1554 // update NoteEditor
1555 textEditor->setText(note.getNote() );
1556 QString fnh=note.getFilenameHint();
1558 textEditor->setFilenameHint(note.getFilenameHint() );
1560 textEditor->setFilenameHint(getHeading() );
1561 textEditor->setFontHint (note.getFontHint() );
1562 isNoteInEditor=true;
1564 // set selected and visible
1565 LinkableMapObj::select();
1567 // Tell parent that I am selected now:
1568 BranchObj* po=(BranchObj*)(parObj);
1569 if (po) // TODO Try to get rid of this cast...
1570 po->setLastSelectedBranch(this);
1572 // temporary unscroll, if we have scrolled parents somewhere
1573 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1575 // Show URL and link in statusbar
1577 if (!url.isEmpty()) status+="URL: "+url+" ";
1578 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1579 if (!status.isEmpty()) mainWindow->statusMessage (status);
1582 updateFlagsToolbar();
1585 mapEditor->updateActions();
1588 void BranchObj::unselect()
1590 LinkableMapObj::unselect();
1591 // Delete any messages like vymLink in StatusBar
1592 mainWindow->statusMessage ("");
1594 // Save current note
1595 if (isNoteInEditor) getNoteFromTextEditor();
1596 isNoteInEditor=false;
1598 // reset temporary unscroll, if we have scrolled parents somewhere
1599 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1601 // Erase content of editor
1602 textEditor->setInactive();
1604 // unselect all buttons in toolbar
1605 standardFlagsDefault->updateToolbar();
1608 QString BranchObj::getSelectString()
1610 return mapEditor->getModel()->getSelectString (this);
1613 void BranchObj::setAnimation(const AnimPoint &ap)
1618 bool BranchObj::animate()
1621 if ( anim.isAnimated() )