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();
142 if (scrolled) unScroll();
145 bool isAbove (BranchObj* a, BranchObj *b)
147 if (a->angle < b->angle)
153 int BranchObj::getNum()
156 return ((BranchObj*)parObj)->getNum (this);
161 int BranchObj::getNum(BranchObj *bo)
163 return branch.indexOf (bo);
166 int BranchObj::getFloatImageNum(FloatImageObj *fio)
168 return floatimage.indexOf(fio);
171 int BranchObj::countBranches()
173 return branch.count();
176 int BranchObj::countFloatImages()
178 return floatimage.count();
181 int BranchObj::countXLinks()
183 return xlink.count();
186 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
188 // Temporary link to lmo
189 // m is position of mouse pointer
190 // offset 0: default 1: below lmo -1 above lmo (if possible)
193 BranchObj* o=(BranchObj*)(lmo);
197 // ignore mapcenter and mainbranch
198 if (lmo->getDepth()<2) off=0;
205 depth=parObj->getDepth()+1;
207 // setLinkStyle calls updateLink, only set it once
208 if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
210 // Move temporary to new position at destination
211 // Usually the positioning would be done by reposition(),
212 // but then also the destination branch would "Jump" around...
213 // Better just do it approximately
215 { // new parent is the mapcenter itself
217 QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
218 m.y() - o->getChildPos().y() ));
219 if (p.x()<0) p.setX( p.x()-bbox.width() );
226 // new parent is just a branch, link to it
227 QRectF t=o->getBBoxSizeWithChilds();
228 if (o->getLastBranch())
229 y=t.y() + t.height() ;
236 // we want to link above lmo
237 y=o->y() - height() + 5;
239 // we want to link below lmo
240 // Bottom of sel should be 5 pixels above
241 // the bottom of the branch _below_ the target:
242 // Don't try to find that branch, guess 12 pixels
243 y=o->getChildPos().y() -height() + 12;
245 if (o->getOrientation()==LinkableMapObj::LeftOfCenter)
246 move ( o->getChildPos().x() - linkwidth, y );
248 move (o->getChildPos().x() + linkwidth, y );
251 // updateLink is called implicitly in move
255 void BranchObj::unsetParObjTmp()
262 depth=parObj->getDepth()+1;
263 setLinkStyle (getDefLinkStyle() );
268 void BranchObj::unScroll()
270 if (tmpUnscrolled) resetTmpUnscroll();
271 if (scrolled) toggleScroll();
274 void BranchObj::toggleScroll()
279 systemFlags->deactivate("scrolledright");
280 for (int i=0; i<branch.size(); ++i)
281 branch.at(i)->setVisibility(true);
285 systemFlags->activate("scrolledright");
286 for (int i=0; i<branch.size(); ++i)
287 branch.at(i)->setVisibility(false);
291 move (absPos.x(), absPos.y() );
295 bool BranchObj::isScrolled()
300 bool BranchObj::hasScrolledParent(BranchObj *start)
302 // Calls parents recursivly to
303 // find out, if we are scrolled at all.
304 // But ignore myself, just look at parents.
306 if (this !=start && scrolled) return true;
308 BranchObj* bo=(BranchObj*)(parObj);
310 return bo->hasScrolledParent(start);
315 void BranchObj::tmpUnscroll()
317 // Unscroll parent (recursivly)
318 BranchObj* bo=(BranchObj*)(parObj);
319 if (bo) bo->tmpUnscroll();
325 systemFlags->activate("tmpUnscrolledright");
330 void BranchObj::resetTmpUnscroll()
332 // Unscroll parent (recursivly)
333 BranchObj* bo=(BranchObj*)(parObj);
335 bo->resetTmpUnscroll();
341 systemFlags->deactivate("tmpUnscrolledright");
346 void BranchObj::setVisibility(bool v, int toDepth)
348 if (depth <= toDepth)
350 frame->setVisibility(v);
351 heading->setVisibility(v);
352 systemFlags->setVisibility(v);
353 standardFlags->setVisibility(v);
354 LinkableMapObj::setVisibility (v);
357 for (i=0; i<floatimage.size(); ++i)
358 floatimage.at(i)->setVisibility (v);
359 for (i=0; i<xlink.size(); ++i)
360 xlink.at(i)->setVisibility ();
362 // Only change childs, if I am not scrolled
363 if (!scrolled && (depth < toDepth))
365 // Now go recursivly through all childs
366 for (i=0; i<branch.size(); ++i)
367 branch.at(i)->setVisibility (v,toDepth);
369 } // depth <= toDepth
373 void BranchObj::setVisibility(bool v)
375 setVisibility (v,MAX_DEPTH);
379 void BranchObj::setLinkColor ()
381 // Overloaded from LinkableMapObj
382 // BranchObj can use color of heading
386 if (mapEditor->getMapLinkColorHint()==HeadingColor)
387 LinkableMapObj::setLinkColor (heading->getColor() );
389 LinkableMapObj::setLinkColor ();
393 void BranchObj::setColorSubtree(QColor col)
396 for (int i=0; i<branch.size(); ++i)
397 branch.at(i)->setColorSubtree(col);
400 BranchObj* BranchObj::first()
407 BranchObj* BranchObj::next()
411 BranchObj *po=(BranchObj*)parObj;
413 if (branch.isEmpty())
420 // no itLast, we are just beginning
423 // we have childs, return first one
429 // No childs, so there is no next
437 { // We come from parent
440 // there are childs, go there
445 { // no childs, try to go up again
448 // go back to parent and try to find next there
457 // can't go up, I am mapCenter, no next
464 // We don't come from parent, but from brother or childs
466 // Try to find last child, where we came from, in my own childs
469 while (i<branch.size())
471 // Try to find itLast in my own childs
472 if (itLast==branch.at(i))
474 // ok, we come from my own childs
475 if (i<branch.size()-1)
485 { // found itLast in my childs
488 // found a brother of lastLMO
496 if (this==itFirst) return NULL; // Stop at starting point
505 // can't go up, I am mapCenter
512 // couldn't find last child, it must be a nephew of mine
515 // proceed with my first child
517 return branch.first();
521 // or go back to my parents
532 // can't go up, I am mapCenter
539 BranchObj* BranchObj::getLastIterator()
544 void BranchObj::setLastIterator(BranchObj* it)
549 void BranchObj::positionContents()
551 for (int i=0; i<floatimage.size(); ++i )
552 floatimage.at(i)->reposition();
553 OrnamentedObj::positionContents();
556 void BranchObj::move (double x, double y)
558 OrnamentedObj::move (x,y);
559 for (int i=0; i<floatimage.size(); ++i )
560 floatimage.at(i)->reposition();
564 void BranchObj::move (QPointF p)
569 void BranchObj::moveBy (double x, double y)
571 OrnamentedObj::moveBy (x,y);
572 for (int i=0; i<branch.size(); ++i)
573 branch.at(i)->moveBy (x,y);
577 void BranchObj::moveBy (QPointF p)
579 moveBy (p.x(), p.y());
583 void BranchObj::positionBBox()
585 QPointF ap=getAbsPos();
586 bbox.moveTopLeft (ap);
590 frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
592 // Update links to other branches
593 for (int i=0; i<xlink.size(); ++i)
594 xlink.at(i)->updateXLink();
597 void BranchObj::calcBBoxSize()
599 QSizeF heading_r=heading->getSize();
600 qreal heading_w=(qreal) heading_r.width() ;
601 qreal heading_h=(qreal) heading_r.height() ;
602 QSizeF sysflags_r=systemFlags->getSize();
603 qreal sysflags_h=sysflags_r.height();
604 qreal sysflags_w=sysflags_r.width();
605 QSizeF stanflags_r=standardFlags->getSize();
606 qreal stanflags_h=stanflags_r.height();
607 qreal stanflags_w=stanflags_r.width();
611 // set width to sum of all widths
612 w=heading_w + sysflags_w + stanflags_w;
613 // set height to maximum needed height
614 h=max (sysflags_h,stanflags_h);
617 // Save the dimension of flags and heading
618 ornamentsBBox.setSize ( QSizeF(w,h));
620 // clickBox includes Flags and Heading
621 clickBox.setSize (ornamentsBBox.size() );
626 topPad=botPad=leftPad=rightPad=0;
627 if (includeImagesVer || includeImagesHor)
629 if (countFloatImages()>0)
631 for (int i=0; i<floatimage.size(); ++i )
633 rp=floatimage.at(i)->getRelPos();
634 if (includeImagesVer)
637 topPad=max (topPad,-rp.y()-h);
638 if (rp.y()+floatimage.at(i)->height() > 0)
639 botPad=max (botPad,rp.y()+floatimage.at(i)->height());
641 if (includeImagesHor)
643 if (orientation==LinkableMapObj::RightOfCenter)
646 leftPad=max (leftPad,-rp.x()-w);
647 if (rp.x()+floatimage.at(i)->width() > 0)
648 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
652 leftPad=max (leftPad,-rp.x());
653 if (rp.x()+floatimage.at(i)->width() > w)
654 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
664 w+=frame->getPadding();
665 h+=frame->getPadding();
668 bbox.setSize (QSizeF (w,h));
671 void BranchObj::setDockPos()
673 // Sets childpos and parpos depending on orientation
674 if (getOrientation()==LinkableMapObj::LeftOfCenter )
677 ornamentsBBox.bottomLeft().x(),
680 ornamentsBBox.bottomRight().x(),
685 ornamentsBBox.bottomRight().x(),
688 ornamentsBBox.bottomLeft().x(),
693 LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
697 for (int i=0; i<branch.size(); ++i)
699 lmo=branch.at(i)->findMapObj(p, excludeLMO);
700 if (lmo != NULL) return lmo;
705 if (inBox (p,clickBox) && (this != excludeLMO) && isVisibleObj() )
708 // Search float images
709 for (int i=0; i<floatimage.size(); ++i )
710 if (inBox(p,floatimage.at(i)->getClickBox()) &&
711 (floatimage.at(i) != excludeLMO) &&
712 floatimage.at(i)->getParObj()!= excludeLMO &&
713 floatimage.at(i)->isVisibleObj()
714 ) return floatimage.at(i);
719 LinkableMapObj* BranchObj::findID (QString sid)
723 for (int i=0; i<branch.size(); ++i)
725 lmo=branch.at(i)->findID (sid);
726 if (lmo != NULL) return lmo;
730 if (sid==objID) return this;
734 // Search float images
735 for (int i=0; i<floatimage.size(); ++i )
736 if (floatimage.at(i)->inBox(p) &&
737 (floatimage.at(i) != excludeLMO) &&
738 floatimage.at(i)->getParObj()!= excludeLMO &&
739 floatimage.at(i)->isVisibleObj()
740 ) return floatimage.at(i);
745 void BranchObj::setHeading(QString s)
747 heading->setText(s); // set new heading
748 calcBBoxSize(); // recalculate bbox
749 positionBBox(); // rearrange contents
753 void BranchObj::setHideTmp (HideTmpMode mode)
755 if (mode==HideExport && (hideExport|| hasHiddenExportParent() ) )
757 // Hide stuff according to hideExport flag and parents
758 setVisibility (false);
762 // Do not hide, but still take care of scrolled status
763 if (hasScrolledParent(this))
764 setVisibility (false);
766 setVisibility (true);
770 // And take care of my childs
771 for (int i=0; i<branch.size(); ++i)
772 branch.at(i)->setHideTmp (mode);
775 bool BranchObj::hasHiddenExportParent()
777 // Calls parents recursivly to
778 // find out, if we or parents are temp. hidden
780 if (hidden || hideExport) return true;
782 BranchObj* bo=(BranchObj*)parObj;
784 return bo->hasHiddenExportParent();
789 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
791 // Cloudy stuff can be hidden during exports
792 if (hidden) return "";
794 // Update of note is usually done while unselecting a branch
795 if (isNoteInEditor) getNoteFromTextEditor();
798 QString scrolledAttr;
800 scrolledAttr=attribut ("scrolled","yes");
804 // save area, if not scrolled
806 if (!((BranchObj*)(parObj))->isScrolled() )
809 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
810 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
811 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
812 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
817 // Providing an ID for a branch makes export to XHTML easier
820 idAttr=attribut ("id",mapEditor->getModel()->getSelectString(this)); //TODO directly access model
824 s=beginElement ("branch"
829 +getIncludeImageAttr() );
833 s+=valueElement("heading", getHeading(),
834 attribut ("textColor",QColor(heading->getColor()).name()));
837 if (frame->getFrameType()!=FrameObj::NoFrame)
838 s+=frame->saveToDir ();
840 // save names of flags set
841 s+=standardFlags->saveToDir(tmpdir,prefix,0);
844 for (int i=0; i<floatimage.size(); ++i)
845 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
848 if (!note.isEmpty() )
852 for (int i=0; i<branch.size(); ++i)
853 s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
856 QString ol; // old link
857 QString cl; // current link
858 for (int i=0; i<xlink.size(); ++i)
860 cl=xlink.at(i)->saveToDir();
867 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
872 s+=endElement ("branch");
876 void BranchObj::addXLink (XLinkObj *xlo)
882 void BranchObj::removeXLinkRef (XLinkObj *xlo)
884 xlink.removeAt (xlink.indexOf(xlo));
887 void BranchObj::deleteXLink(XLinkObj *xlo)
890 if (!xlo->isUsed()) delete (xlo);
893 void BranchObj::deleteXLinkAt (int i)
895 XLinkObj *xlo=xlink.at(i);
897 if (!xlo->isUsed()) delete(xlo);
900 XLinkObj* BranchObj::XLinkAt (int i)
905 int BranchObj::countXLink()
907 return xlink.count();
911 BranchObj* BranchObj::XLinkTargetAt (int i)
913 if (i>=0 && i<xlink.size())
916 return xlink.at(i)->otherBranch (this);
921 void BranchObj::setIncludeImagesVer(bool b)
929 bool BranchObj::getIncludeImagesVer()
931 return includeImagesVer;
934 void BranchObj::setIncludeImagesHor(bool b)
942 bool BranchObj::getIncludeImagesHor()
944 return includeImagesHor;
947 QString BranchObj::getIncludeImageAttr()
950 if (includeImagesVer)
951 a=attribut ("incImgV","true");
953 a=attribut ("incImgV","false");
954 if (includeImagesHor)
955 a+=attribut ("incImgH","true");
957 a+=attribut ("incImgH","false");
961 FloatImageObj* BranchObj::addFloatImage ()
963 FloatImageObj *newfi=new FloatImageObj (scene,this);
964 floatimage.append (newfi);
965 if (hasScrolledParent(this) )
966 newfi->setVisibility (false);
968 newfi->setVisibility(visible);
977 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
979 FloatImageObj *newfi=new FloatImageObj (scene,this);
980 floatimage.append (newfi);
982 if (hasScrolledParent(this) )
983 newfi->setVisibility (false);
985 newfi->setVisibility(visible);
994 FloatImageObj* BranchObj::getFirstFloatImage ()
996 return floatimage.first();
999 FloatImageObj* BranchObj::getLastFloatImage ()
1001 return floatimage.last();
1004 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
1006 return floatimage.at(i);
1009 void BranchObj::removeFloatImage (FloatImageObj *fio)
1011 int i=floatimage.indexOf (fio);
1012 if (i>-1) delete (floatimage.takeAt (i));
1015 requestReposition();
1018 void BranchObj::savePosInAngle ()
1020 // Save position in angle
1021 for (int i=0; i<branch.size(); ++i)
1022 branch.at(i)->angle=i;
1025 void BranchObj::setDefAttr (BranchModification mod)
1030 case 0: fontsize=16; break;
1031 case 1: fontsize=12; break;
1032 default: fontsize=10; break;
1036 setLinkStyle(getDefLinkStyle());
1037 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
1038 font.setPointSize(fontsize);
1039 heading->setFont(font );
1042 setColor (((BranchObj*)(parObj))->getColor());
1047 BranchObj* BranchObj::addBranch()
1049 BranchObj* newbo=new BranchObj(scene,this);
1050 branch.append (newbo);
1051 newbo->setParObj(this);
1052 newbo->setDefAttr(NewBranch);
1053 newbo->setHeading ("new");
1055 newbo->setVisibility (false);
1057 newbo->setVisibility(visible);
1058 newbo->updateLink();
1059 requestReposition();
1063 BranchObj* BranchObj::addBranch(BranchObj* bo)
1065 BranchObj* newbo=new BranchObj(scene,this);
1066 branch.append (newbo);
1068 newbo->setParObj(this);
1069 newbo->setDefAttr(MovedBranch);
1071 newbo->setVisibility (false);
1073 newbo->setVisibility(bo->visible);
1074 newbo->updateLink();
1075 requestReposition();
1079 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
1082 bo->setParObj (this);
1084 bo->setDefAttr(MovedBranch);
1085 if (scrolled) tmpUnscroll();
1086 setLastSelectedBranch (bo);
1090 BranchObj* BranchObj::insertBranch(int pos)
1093 // Add new bo and resort branches
1094 BranchObj *newbo=addBranch ();
1095 newbo->angle=pos-0.5;
1096 qSort (branch.begin(),branch.end(), isAbove);
1100 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
1103 // Add new bo and resort branches
1105 BranchObj *newbo=addBranch (bo);
1106 qSort (branch.begin(),branch.end(), isAbove);
1110 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
1113 // Add new bo and resort branches
1116 bo->setParObj (this);
1118 bo->setDefAttr (MovedBranch);
1119 if (scrolled) tmpUnscroll();
1120 setLastSelectedBranch (bo);
1121 qSort (branch.begin(),branch.end(), isAbove);
1125 void BranchObj::removeBranchHere(BranchObj* borem)
1127 // This removes the branch bo from list, but
1128 // inserts its childs at the place of bo
1130 bo=borem->getLastBranch();
1131 int pos=borem->getNum();
1134 bo->linkTo (this,pos+1);
1135 bo=borem->getLastBranch();
1137 removeBranch (borem);
1140 void BranchObj::removeChilds()
1145 void BranchObj::removeBranch(BranchObj* bo)
1147 // if bo is not in branch remove returns false, we
1150 int i=branch.indexOf(bo);
1154 branch.removeAt (i);
1156 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
1157 requestReposition();
1160 void BranchObj::removeBranchPtr(BranchObj* bo)
1162 int i=branch.indexOf(bo);
1165 branch.removeAt (i);
1167 qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
1168 requestReposition();
1171 void BranchObj::setLastSelectedBranch (BranchObj* bo)
1173 lastSelectedBranch=branch.indexOf(bo);
1176 BranchObj* BranchObj::getLastSelectedBranch ()
1178 if (lastSelectedBranch>=0)
1180 if ( branch.size()>lastSelectedBranch)
1181 return branch.at(lastSelectedBranch);
1182 if (branch.size()>0)
1183 return branch.last();
1188 BranchObj* BranchObj::getFirstBranch ()
1190 if (branch.size()>0)
1191 return branch.first();
1196 BranchObj* BranchObj::getLastBranch ()
1198 if (branch.size()>0)
1199 return branch.last();
1204 BranchObj* BranchObj::getBranchNum (int i)
1206 if (i>=0 && i<branch.size())
1207 return branch.at(i);
1212 bool BranchObj::canMoveBranchUp()
1214 if (!parObj || depth==1) return false;
1215 BranchObj* par=(BranchObj*)parObj;
1216 if (this==par->getFirstBranch())
1222 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
1225 int i=branch.indexOf(bo1);
1227 { // -1 if bo1 not found
1228 branch.at(i)->angle--;
1229 branch.at(i-1)->angle++;
1230 qSort (branch.begin(),branch.end(), isAbove);
1231 return branch.at(i);
1236 bool BranchObj::canMoveBranchDown()
1238 if (!parObj|| depth==1) return false;
1239 BranchObj* par=(BranchObj*)parObj;
1240 if (this==par->getLastBranch())
1246 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
1249 int i=branch.indexOf(bo1);
1251 if (i <branch.size())
1254 branch.at(i)->angle++;
1255 branch.at(j)->angle--;
1256 qSort (branch.begin(),branch.end(), isAbove);
1257 return branch.at(i);
1262 void BranchObj::sortChildren()
1264 int childCount=branch.count();
1266 bool madeChanges=false;
1270 for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
1271 BranchObj* curChild=(BranchObj*)branch.at(curChildIndex);
1272 BranchObj* prevChild=(BranchObj*)branch.at(curChildIndex-1);
1273 if(prevChild->heading->text().compare(curChild->heading->text())>0)
1275 this->moveBranchUp(curChild);
1279 }while(madeChanges);
1283 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
1285 // Find current parent and
1286 // remove pointer to myself there
1287 if (!dst) return NULL;
1288 BranchObj *par=(BranchObj*)parObj;
1290 par->removeBranchPtr (this);
1294 // Create new pointer to myself at dst
1295 if (pos<0||dst->getDepth()==0)
1297 // links myself as last branch at dst
1298 dst->addBranchPtr (this);
1303 // inserts me at pos in parent of dst
1306 BranchObj *bo=dst->insertBranchPtr (this,pos);
1307 bo->setDefAttr(MovedBranch);
1315 void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
1317 qreal th = bboxTotal.height();
1320 QPointF pp; if (parObj) pp=parObj->getChildPos();
1321 cout << "BO::alignRelTo "<<qPrintable (getHeading());
1322 cout << " d="<<depth<<
1324 // " bbox.topLeft="<<bboxTotal.topLeft()<<
1325 " absPos="<<absPos<<
1326 " relPos="<<relPos<<
1328 " orient="<<orientation<<
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 );
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 childs
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 childs 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);
1400 ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChilds().height() );
1406 void BranchObj::reposition()
1408 /* TODO testing only
1409 if (!getHeading().isEmpty())
1410 cout << "BO::reposition "<<qPrintable(getHeading())<<endl;
1412 cout << "BO::reposition ???"<<endl;
1414 cout << " orient="<<orientation<<endl;
1419 // only calculate the sizes once. If the deepest LMO
1420 // changes its height,
1421 // all upper LMOs have to change, too.
1422 calcBBoxSizeWithChilds();
1423 updateLink(); // This update is needed if the scene is resized
1424 // due to excessive moving of a FIO
1426 alignRelativeTo ( QPointF (absPos.x(),
1427 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1428 qSort (branch.begin(),branch.end(), isAbove);
1429 positionBBox(); // Reposition bbox and contents
1432 // This is only important for moving branches:
1433 // For editing a branch it isn't called...
1434 alignRelativeTo ( QPointF (absPos.x(),
1435 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1439 void BranchObj::unsetAllRepositionRequests()
1441 repositionRequest=false;
1442 for (int i=0; i<branch.size(); ++i)
1443 branch.at(i)->unsetAllRepositionRequests();
1447 QPolygonF BranchObj::shape()
1451 QRectF r=getTotalBBox();
1452 if (orientation==LinkableMapObj::LeftOfCenter)
1455 <<QPointF (bbox.topLeft().x(), r.topLeft().y() )
1457 <<bbox.bottomRight()
1458 <<QPointF (bbox.bottomLeft().x(), r.bottomLeft().y() ) ;
1462 <<QPointF (bbox.topRight().x(), r.topRight().y() )
1465 <<QPointF (bbox.bottomRight().x(), r.bottomRight().y() ) ;
1469 QRectF BranchObj::getTotalBBox()
1473 if (scrolled) return r;
1475 for (int i=0; i<branch.size(); ++i)
1476 if (!branch.at(i)->isHidden())
1477 r=addBBox(branch.at(i)->getTotalBBox(),r);
1479 for (int i=0; i<floatimage.size(); ++i)
1480 if (!floatimage.at(i)->isHidden())
1481 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1486 QRectF BranchObj::getBBoxSizeWithChilds()
1491 void BranchObj::calcBBoxSizeWithChilds()
1493 // This is initially called only from reposition and
1494 // and only for mapcenter. So it won't be
1495 // called more than once for a single user
1499 // Calculate size of LMO including all childs (to align them later)
1500 bboxTotal.setX(bbox.x() );
1501 bboxTotal.setY(bbox.y() );
1503 // if branch is scrolled, ignore childs, but still consider floatimages
1506 bboxTotal.setWidth (bbox.width());
1507 bboxTotal.setHeight(bbox.height());
1513 bboxTotal.setWidth (0);
1514 bboxTotal.setHeight(0);
1517 bboxTotal.setX (parObj->x());
1518 bboxTotal.setY (parObj->y());
1521 bboxTotal.setX (bbox.x());
1522 bboxTotal.setY (bbox.y());
1529 // Now calculate recursivly
1531 // maximum of widths
1533 for (int i=0; i<branch.size(); ++i)
1535 if (!branch.at(i)->isHidden())
1537 branch.at(i)->calcBBoxSizeWithChilds();
1538 br=branch.at(i)->getBBoxSizeWithChilds();
1539 r.setWidth( max (br.width(), r.width() ));
1540 r.setHeight(br.height() + r.height() );
1541 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1544 // Add myself and also
1545 // add width of link to sum if necessary
1546 if (branch.isEmpty())
1547 bboxTotal.setWidth (bbox.width() + r.width() );
1549 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1551 bboxTotal.setHeight(max (r.height(), bbox.height()));
1554 void BranchObj::select()
1556 // update NoteEditor
1557 textEditor->setText(note.getNote() );
1558 QString fnh=note.getFilenameHint();
1560 textEditor->setFilenameHint(note.getFilenameHint() );
1562 textEditor->setFilenameHint(getHeading() );
1563 textEditor->setFontHint (note.getFontHint() );
1564 isNoteInEditor=true;
1566 // set selected and visible
1567 LinkableMapObj::select();
1569 // Tell parent that I am selected now:
1570 BranchObj* po=(BranchObj*)(parObj);
1571 if (po) // TODO Try to get rid of this cast...
1572 po->setLastSelectedBranch(this);
1574 // temporary unscroll, if we have scrolled parents somewhere
1575 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1577 // Show URL and link in statusbar
1579 if (!url.isEmpty()) status+="URL: "+url+" ";
1580 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1581 if (!status.isEmpty()) mainWindow->statusMessage (status);
1584 updateFlagsToolbar();
1587 mapEditor->updateActions();
1590 void BranchObj::unselect()
1592 LinkableMapObj::unselect();
1593 // Delete any messages like vymLink in StatusBar
1594 mainWindow->statusMessage ("");
1596 // Save current note
1597 if (isNoteInEditor) getNoteFromTextEditor();
1598 isNoteInEditor=false;
1600 // reset temporary unscroll, if we have scrolled parents somewhere
1601 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1603 // Erase content of editor
1604 textEditor->setInactive();
1606 // unselect all buttons in toolbar
1607 standardFlagsDefault->updateToolbar();
1610 QString BranchObj::getSelectString()
1612 return mapEditor->getModel()->getSelectString (this);
1615 void BranchObj::setAnimation(const AnimPoint &ap)
1620 bool BranchObj::animate()
1623 if ( anim.isAnimated() )
1628 parObj->reposition(); // object might have been relinked meanwhile