3 // #include "texteditor.h"
5 #include "mainwindow.h"
10 extern TextEditor *textEditor;
11 extern Main *mainWindow;
12 extern FlagRowObj *standardFlagsDefault;
15 /////////////////////////////////////////////////////////////////
17 /////////////////////////////////////////////////////////////////
19 BranchObj* BranchObj::itLast=NULL;
20 BranchObj* BranchObj::itFirst=NULL;
23 BranchObj::BranchObj () :OrnamentedObj()
25 // cout << "Const BranchObj ()\n";
31 BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s)
33 // cout << "Const BranchObj (s) called from MapCenterObj (s)\n";
38 BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)
40 // cout << "Const BranchObj (s,p)\n";
43 depth=p->getDepth()+1;
45 // Calc angle to mapCenter if I am a mainbranch
46 // needed for reordering the mainbranches clockwise
48 angle=getAngle (QPointF (x() - parObj->getChildPos().x() ,
49 (y() - parObj->getChildPos().y() ) ) );
53 BranchObj::~BranchObj ()
55 //cout << "Destr BranchObj of "<<this<<endl;
56 // Check, if this branch was the last child to be deleted
57 // If so, unset the scrolled flags
59 BranchObj *po=(BranchObj*)parObj;
63 bo=((BranchObj*)parObj)->getLastBranch();
64 if (bo) po->unScroll();
69 bool BranchObj::operator< ( const BranchObj & other )
71 return angle < other.angle;
74 bool BranchObj::operator== ( const BranchObj & other )
76 return angle == other.angle;
79 void BranchObj::init ()
84 absPos+=parObj->getChildPos();
94 includeImagesVer=false;
95 includeImagesHor=false;
98 void BranchObj::copy (BranchObj* other)
100 OrnamentedObj::copy(other);
103 for (int i=0; i<other->branch.size(); ++i)
104 // Make deep copy of b
105 // Because addBranch again calls copy for the childs,
106 // Those will get a deep copy, too
107 addBranch(other->branch.at(i) );
109 for (int i=0; i<other->floatimage.size(); ++i)
110 addFloatImage (other->floatimage.at(i));
111 scrolled=other->scrolled;
112 tmpUnscrolled=other->tmpUnscrolled;
113 setVisibility (other->visible);
120 void BranchObj::clear()
122 setVisibility (true);
124 while (!floatimage.isEmpty())
125 delete floatimage.takeFirst();
127 while (!xlink.isEmpty())
128 delete xlink.takeFirst();
130 while (!branch.isEmpty())
131 delete branch.takeFirst();
134 bool isAbove (BranchObj* a, BranchObj *b)
136 if (a->angle < b->angle)
142 int BranchObj::getNum()
145 return ((BranchObj*)parObj)->getNum (this);
150 int BranchObj::getNum(BranchObj *bo)
152 return branch.indexOf (bo);
155 int BranchObj::getFloatImageNum(FloatImageObj *fio)
157 return floatimage.indexOf(fio);
160 int BranchObj::countBranches()
162 return branch.count();
165 int BranchObj::countFloatImages()
167 return floatimage.count();
170 int BranchObj::countXLinks()
172 return xlink.count();
175 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
177 // Temporary link to lmo
178 // m is position of mouse pointer
179 // offset 0: default 1: below lmo -1 above lmo (if possible)
182 BranchObj* o=(BranchObj*)(lmo);
186 // ignore mapcenter and mainbranch
187 if (lmo->getDepth()<2) off=0;
194 depth=parObj->getDepth()+1;
196 // setLinkStyle calls updateLink, only set it once
197 if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
199 // Move temporary to new position at destination
200 // Usually the positioning would be done by reposition(),
201 // but then also the destination branch would "Jump" around...
202 // Better just do it approximately
204 { // new parent is the mapcenter itself
206 QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
207 m.y() - o->getChildPos().y() ));
208 if (p.x()<0) p.setX( p.x()-bbox.width() );
215 // new parent is just a branch, link to it
216 QRectF t=o->getBBoxSizeWithChilds();
217 if (o->getLastBranch())
218 y=t.y() + t.height() ;
225 // we want to link above lmo
226 y=o->y() - height() + 5;
228 // we want to link below lmo
229 // Bottom of sel should be 5 pixels above
230 // the bottom of the branch _below_ the target:
231 // Don't try to find that branch, guess 12 pixels
232 y=o->getChildPos().y() -height() + 12;
234 if (o->getOrientation()==LinkableMapObj::LeftOfCenter)
235 move ( o->getChildPos().x() - linkwidth, y );
237 move (o->getChildPos().x() + linkwidth, y );
240 // updateLink is called implicitly in move
244 void BranchObj::unsetParObjTmp()
251 depth=parObj->getDepth()+1;
252 setLinkStyle (getDefLinkStyle() );
257 void BranchObj::unScroll()
259 if (tmpUnscrolled) resetTmpUnscroll();
260 if (scrolled) toggleScroll();
263 void BranchObj::toggleScroll()
268 systemFlags->deactivate("scrolledright");
269 for (int i=0; i<branch.size(); ++i)
270 branch.at(i)->setVisibility(true);
274 systemFlags->activate("scrolledright");
275 for (int i=0; i<branch.size(); ++i)
276 branch.at(i)->setVisibility(false);
280 move (absPos.x(), absPos.y() );
284 bool BranchObj::isScrolled()
289 bool BranchObj::hasScrolledParent(BranchObj *start)
291 // Calls parents recursivly to
292 // find out, if we are scrolled at all.
293 // But ignore myself, just look at parents.
295 if (this !=start && scrolled) return true;
297 BranchObj* bo=(BranchObj*)(parObj);
299 return bo->hasScrolledParent(start);
304 void BranchObj::tmpUnscroll()
306 // Unscroll parent (recursivly)
307 BranchObj* bo=(BranchObj*)(parObj);
308 if (bo) bo->tmpUnscroll();
314 systemFlags->activate("tmpUnscrolledright");
319 void BranchObj::resetTmpUnscroll()
321 // Unscroll parent (recursivly)
322 BranchObj* bo=(BranchObj*)(parObj);
324 bo->resetTmpUnscroll();
330 systemFlags->deactivate("tmpUnscrolledright");
335 void BranchObj::setVisibility(bool v, int toDepth)
337 if (depth <= toDepth)
339 frame->setVisibility(v);
340 heading->setVisibility(v);
341 systemFlags->setVisibility(v);
342 standardFlags->setVisibility(v);
343 LinkableMapObj::setVisibility (v);
345 // Only change childs, if I am not scrolled
346 if (!scrolled && (depth < toDepth))
348 // Now go recursivly through all childs
350 for (i=0; i<branch.size(); ++i)
351 branch.at(i)->setVisibility (v,toDepth);
352 for (i=0; i<floatimage.size(); ++i)
353 floatimage.at(i)->setVisibility (v);
354 for (i=0; i<xlink.size(); ++i)
355 xlink.at(i)->setVisibility ();
357 } // depth <= toDepth
361 void BranchObj::setVisibility(bool v)
363 setVisibility (v,MAX_DEPTH);
367 void BranchObj::setLinkColor ()
369 // Overloaded from LinkableMapObj
370 // BranchObj can use color of heading
374 if (mapEditor->getMapLinkColorHint()==HeadingColor)
375 LinkableMapObj::setLinkColor (heading->getColor() );
377 LinkableMapObj::setLinkColor ();
381 void BranchObj::setColorSubtree(QColor col)
384 for (int i=0; i<branch.size(); ++i)
385 branch.at(i)->setColorSubtree(col);
388 BranchObj* BranchObj::first()
395 BranchObj* BranchObj::next()
399 BranchObj *po=(BranchObj*)parObj;
401 if (branch.isEmpty())
408 // no itLast, we are just beginning
411 // we have childs, return first one
417 // No childs, so there is no next
425 { // We come from parent
428 // there are childs, go there
433 { // no childs, try to go up again
436 // go back to parent and try to find next there
445 // can't go up, I am mapCenter, no next
452 // We don't come from parent, but from brother or childs
454 // Try to find last child, where we came from, in my own childs
457 while (i<branch.size())
459 // Try to find itLast in my own childs
460 if (itLast==branch.at(i))
462 // ok, we come from my own childs
463 if (i<branch.size()-1)
473 { // found itLast in my childs
476 // found a brother of lastLMO
484 if (this==itFirst) return NULL; // Stop at starting point
493 // can't go up, I am mapCenter
500 // couldn't find last child, it must be a nephew of mine
503 // proceed with my first child
505 return branch.first();
509 // or go back to my parents
520 // can't go up, I am mapCenter
527 BranchObj* BranchObj::getLastIterator()
532 void BranchObj::setLastIterator(BranchObj* it)
537 void BranchObj::positionContents()
539 for (int i=0; i<floatimage.size(); ++i )
540 floatimage.at(i)->reposition();
541 OrnamentedObj::positionContents();
544 void BranchObj::move (double x, double y)
546 OrnamentedObj::move (x,y);
547 for (int i=0; i<floatimage.size(); ++i )
548 floatimage.at(i)->reposition();
552 void BranchObj::move (QPointF p)
557 void BranchObj::moveBy (double x, double y)
559 OrnamentedObj::moveBy (x,y);
560 for (int i=0; i<branch.size(); ++i)
561 branch.at(i)->moveBy (x,y);
565 void BranchObj::moveBy (QPointF p)
567 moveBy (p.x(), p.y());
571 void BranchObj::positionBBox()
573 QPointF ap=getAbsPos();
574 bbox.moveTopLeft (ap);
578 frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
580 // Update links to other branches
581 for (int i=0; i<xlink.size(); ++i)
582 xlink.at(i)->updateXLink();
585 void BranchObj::calcBBoxSize()
587 QSizeF heading_r=heading->getSize();
588 qreal heading_w=(qreal) heading_r.width() ;
589 qreal heading_h=(qreal) heading_r.height() ;
590 QSizeF sysflags_r=systemFlags->getSize();
591 qreal sysflags_h=sysflags_r.height();
592 qreal sysflags_w=sysflags_r.width();
593 QSizeF stanflags_r=standardFlags->getSize();
594 qreal stanflags_h=stanflags_r.height();
595 qreal stanflags_w=stanflags_r.width();
599 // set width to sum of all widths
600 w=heading_w + sysflags_w + stanflags_w;
601 // set height to maximum needed height
602 h=max (sysflags_h,stanflags_h);
605 // Save the dimension of flags and heading
606 ornamentsBBox.setSize ( QSizeF(w,h));
608 // clickBox includes Flags and Heading
609 clickBox.setSize (ornamentsBBox.size() );
614 topPad=botPad=leftPad=rightPad=0;
615 if (includeImagesVer || includeImagesHor)
617 if (countFloatImages()>0)
619 for (int i=0; i<floatimage.size(); ++i )
621 rp=floatimage.at(i)->getRelPos();
622 if (includeImagesVer)
625 topPad=max (topPad,-rp.y()-h);
626 if (rp.y()+floatimage.at(i)->height() > 0)
627 botPad=max (botPad,rp.y()+floatimage.at(i)->height());
629 if (includeImagesHor)
631 if (orientation==LinkableMapObj::RightOfCenter)
634 leftPad=max (leftPad,-rp.x()-w);
635 if (rp.x()+floatimage.at(i)->width() > 0)
636 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
640 leftPad=max (leftPad,-rp.x());
641 if (rp.x()+floatimage.at(i)->width() > w)
642 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
652 w+=frame->getPadding();
653 h+=frame->getPadding();
656 bbox.setSize (QSizeF (w,h));
659 void BranchObj::setDockPos()
661 // Sets childpos and parpos depending on orientation
662 if (getOrientation()==LinkableMapObj::LeftOfCenter )
665 ornamentsBBox.bottomLeft().x(),
668 ornamentsBBox.bottomRight().x(),
673 ornamentsBBox.bottomRight().x(),
676 ornamentsBBox.bottomLeft().x(),
681 LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
685 for (int i=0; i<branch.size(); ++i)
687 lmo=branch.at(i)->findMapObj(p, excludeLMO);
688 if (lmo != NULL) return lmo;
693 if (inBox (p) && (this != excludeLMO) && isVisibleObj() )
696 // Search float images
697 for (int i=0; i<floatimage.size(); ++i )
698 if (floatimage.at(i)->inBox(p) &&
699 (floatimage.at(i) != excludeLMO) &&
700 floatimage.at(i)->getParObj()!= excludeLMO &&
701 floatimage.at(i)->isVisibleObj()
702 ) return floatimage.at(i);
707 LinkableMapObj* BranchObj::findID (QString sid)
711 for (int i=0; i<branch.size(); ++i)
713 lmo=branch.at(i)->findID (sid);
714 if (lmo != NULL) return lmo;
718 if (sid==objID) return this;
722 // Search float images
723 for (int i=0; i<floatimage.size(); ++i )
724 if (floatimage.at(i)->inBox(p) &&
725 (floatimage.at(i) != excludeLMO) &&
726 floatimage.at(i)->getParObj()!= excludeLMO &&
727 floatimage.at(i)->isVisibleObj()
728 ) return floatimage.at(i);
733 void BranchObj::setHeading(QString s)
735 heading->setText(s); // set new heading
736 calcBBoxSize(); // recalculate bbox
737 positionBBox(); // rearrange contents
741 void BranchObj::setHideTmp (HideTmpMode mode)
743 if (mode==HideExport && (hideExport|| hasHiddenExportParent() ) )
745 // Hide stuff according to hideExport flag and parents
746 setVisibility (false);
750 // Do not hide, but still take care of scrolled status
751 if (hasScrolledParent(this))
752 setVisibility (false);
754 setVisibility (true);
758 // And take care of my childs
759 for (int i=0; i<branch.size(); ++i)
760 branch.at(i)->setHideTmp (mode);
763 bool BranchObj::hasHiddenExportParent()
765 // Calls parents recursivly to
766 // find out, if we or parents are temp. hidden
768 if (hidden || hideExport) return true;
770 BranchObj* bo=(BranchObj*)parObj;
772 return bo->hasHiddenExportParent();
777 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
779 // Cloudy stuff can be hidden during exports
780 if (hidden) return "";
782 // Update of note is usually done while unselecting a branch
783 if (isNoteInEditor) getNoteFromTextEditor();
786 QString scrolledAttr;
788 scrolledAttr=attribut ("scrolled","yes");
792 // save area, if not scrolled
794 if (!((BranchObj*)(parObj))->isScrolled() )
797 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
798 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
799 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
800 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
805 // Providing an ID for a branch makes export to XHTML easier
808 idAttr=attribut ("id",getSelectString());
812 s=beginElement ("branch"
817 +getIncludeImageAttr() );
821 s+=valueElement("heading", getHeading(),
822 attribut ("textColor",QColor(heading->getColor()).name()));
825 if (frame->getFrameType()!=FrameObj::NoFrame)
826 s+=frame->saveToDir ();
828 // save names of flags set
829 s+=standardFlags->saveToDir(tmpdir,prefix,0);
832 for (int i=0; i<floatimage.size(); ++i)
833 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
836 if (!note.isEmpty() )
840 for (int i=0; i<branch.size(); ++i)
841 s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
844 QString ol; // old link
845 QString cl; // current link
846 for (int i=0; i<xlink.size(); ++i)
848 cl=xlink.at(i)->saveToDir();
855 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
860 s+=endElement ("branch");
864 void BranchObj::addXLink (XLinkObj *xlo)
870 void BranchObj::removeXLinkRef (XLinkObj *xlo)
872 xlink.removeAt (xlink.indexOf(xlo));
875 void BranchObj::deleteXLink(XLinkObj *xlo)
878 if (!xlo->isUsed()) delete (xlo);
881 void BranchObj::deleteXLinkAt (int i)
883 XLinkObj *xlo=xlink.at(i);
885 if (!xlo->isUsed()) delete(xlo);
888 XLinkObj* BranchObj::XLinkAt (int i)
893 int BranchObj::countXLink()
895 return xlink.count();
899 BranchObj* BranchObj::XLinkTargetAt (int i)
901 if (i>=0 && i<xlink.size())
904 return xlink.at(i)->otherBranch (this);
909 void BranchObj::setIncludeImagesVer(bool b)
917 bool BranchObj::getIncludeImagesVer()
919 return includeImagesVer;
922 void BranchObj::setIncludeImagesHor(bool b)
930 bool BranchObj::getIncludeImagesHor()
932 return includeImagesHor;
935 QString BranchObj::getIncludeImageAttr()
938 if (includeImagesVer)
939 a=attribut ("incImgV","true");
941 a=attribut ("incImgV","false");
942 if (includeImagesHor)
943 a+=attribut ("incImgH","true");
945 a+=attribut ("incImgH","false");
949 FloatImageObj* BranchObj::addFloatImage ()
951 FloatImageObj *newfi=new FloatImageObj (scene,this);
952 floatimage.append (newfi);
953 if (hasScrolledParent(this) )
954 newfi->setVisibility (false);
956 newfi->setVisibility(visible);
965 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
967 FloatImageObj *newfi=new FloatImageObj (scene,this);
968 floatimage.append (newfi);
970 if (hasScrolledParent(this) )
971 newfi->setVisibility (false);
973 newfi->setVisibility(visible);
982 FloatImageObj* BranchObj::getFirstFloatImage ()
984 return floatimage.first();
987 FloatImageObj* BranchObj::getLastFloatImage ()
989 return floatimage.last();
992 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
994 return floatimage.at(i);
997 void BranchObj::removeFloatImage (FloatImageObj *fio)
999 int i=floatimage.indexOf (fio);
1000 if (i>-1) delete (floatimage.takeAt (i));
1003 requestReposition();
1006 void BranchObj::savePosInAngle ()
1008 // Save position in angle
1009 for (int i=0; i<branch.size(); ++i)
1010 branch.at(i)->angle=i;
1013 void BranchObj::setDefAttr (BranchModification mod)
1018 case 0: fontsize=16; break;
1019 case 1: fontsize=12; break;
1020 default: fontsize=10; break;
1024 setLinkStyle(getDefLinkStyle());
1025 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
1026 font.setPointSize(fontsize);
1027 heading->setFont(font );
1030 setColor (((BranchObj*)(parObj))->getColor());
1035 BranchObj* BranchObj::addBranch()
1037 BranchObj* newbo=new BranchObj(scene,this);
1038 branch.append (newbo);
1039 newbo->setParObj(this);
1040 newbo->setDefAttr(NewBranch);
1041 newbo->setHeading ("new");
1043 newbo->setVisibility (false);
1045 newbo->setVisibility(visible);
1046 newbo->updateLink();
1047 requestReposition();
1051 BranchObj* BranchObj::addBranch(BranchObj* bo)
1053 BranchObj* newbo=new BranchObj(scene,this);
1054 branch.append (newbo);
1056 newbo->setParObj(this);
1057 newbo->setDefAttr(MovedBranch);
1059 newbo->setVisibility (false);
1061 newbo->setVisibility(bo->visible);
1062 newbo->updateLink();
1063 requestReposition();
1067 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
1070 bo->setParObj (this);
1072 bo->setDefAttr(MovedBranch);
1073 if (scrolled) tmpUnscroll();
1074 setLastSelectedBranch (bo);
1078 BranchObj* BranchObj::insertBranch(int pos)
1081 // Add new bo and resort branches
1082 BranchObj *newbo=addBranch ();
1083 newbo->angle=pos-0.5;
1084 qSort (branch.begin(),branch.end(), isAbove);
1088 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
1091 // Add new bo and resort branches
1093 BranchObj *newbo=addBranch (bo);
1094 qSort (branch.begin(),branch.end(), isAbove);
1098 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
1101 // Add new bo and resort branches
1104 bo->setParObj (this);
1106 bo->setDefAttr (MovedBranch);
1107 if (scrolled) tmpUnscroll();
1108 setLastSelectedBranch (bo);
1109 qSort (branch.begin(),branch.end(), isAbove);
1113 void BranchObj::removeBranchHere(BranchObj* borem)
1115 // This removes the branch bo from list, but
1116 // inserts its childs at the place of bo
1118 bo=borem->getLastBranch();
1119 int pos=borem->getNum();
1122 bo->linkTo (this,pos+1);
1123 bo=borem->getLastBranch();
1125 removeBranch (borem);
1128 void BranchObj::removeChilds()
1133 void BranchObj::removeBranch(BranchObj* bo)
1135 // if bo is not in branch remove returns false, we
1138 int i=branch.indexOf(bo);
1142 branch.removeAt (i);
1144 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
1145 requestReposition();
1148 void BranchObj::removeBranchPtr(BranchObj* bo)
1150 int i=branch.indexOf(bo);
1153 branch.removeAt (i);
1155 qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
1156 requestReposition();
1159 void BranchObj::setLastSelectedBranch (BranchObj* bo)
1161 lastSelectedBranch=branch.indexOf(bo);
1164 BranchObj* BranchObj::getLastSelectedBranch ()
1166 if (lastSelectedBranch>=0)
1168 if ( branch.size()>lastSelectedBranch)
1169 return branch.at(lastSelectedBranch);
1170 if (branch.size()>0)
1171 return branch.last();
1176 BranchObj* BranchObj::getFirstBranch ()
1178 if (branch.size()>0)
1179 return branch.first();
1184 BranchObj* BranchObj::getLastBranch ()
1186 if (branch.size()>0)
1187 return branch.last();
1192 BranchObj* BranchObj::getBranchNum (int i)
1194 if (i>=0 && i<branch.size())
1195 return branch.at(i);
1200 bool BranchObj::canMoveBranchUp()
1202 if (!parObj || depth==1) return false;
1203 BranchObj* par=(BranchObj*)parObj;
1204 if (this==par->getFirstBranch())
1210 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
1213 int i=branch.indexOf(bo1);
1215 { // -1 if bo1 not found
1216 branch.at(i)->angle--;
1217 branch.at(i-1)->angle++;
1218 qSort (branch.begin(),branch.end(), isAbove);
1219 return branch.at(i);
1224 bool BranchObj::canMoveBranchDown()
1226 if (!parObj|| depth==1) return false;
1227 BranchObj* par=(BranchObj*)parObj;
1228 if (this==par->getLastBranch())
1234 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
1237 int i=branch.indexOf(bo1);
1239 if (i <branch.size())
1242 branch.at(i)->angle++;
1243 branch.at(j)->angle--;
1244 qSort (branch.begin(),branch.end(), isAbove);
1245 return branch.at(i);
1250 void BranchObj::sortChildren()
1252 int childCount=branch.count();
1254 bool madeChanges=false;
1258 for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
1259 BranchObj* curChild=(BranchObj*)branch.at(curChildIndex);
1260 BranchObj* prevChild=(BranchObj*)branch.at(curChildIndex-1);
1261 if(prevChild->heading->text().compare(curChild->heading->text())>0)
1263 this->moveBranchUp(curChild);
1267 }while(madeChanges);
1271 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
1273 // Find current parent and
1274 // remove pointer to myself there
1275 if (!dst) return NULL;
1276 BranchObj *par=(BranchObj*)parObj;
1278 par->removeBranchPtr (this);
1282 // Create new pointer to myself at dst
1283 if (pos<0||dst->getDepth()==0)
1285 // links myself as last branch at dst
1286 dst->addBranchPtr (this);
1291 // inserts me at pos in parent of dst
1294 BranchObj *bo=dst->insertBranchPtr (this,pos);
1295 bo->setDefAttr(MovedBranch);
1304 void BranchObj::alignRelativeTo (QPointF ref)
1306 qreal th = bboxTotal.height();
1309 cout << "BO::alignRelTo "<<getHeading().ascii()<<endl;
1310 cout << " d="<<depth<<
1312 // " bbox.topLeft="<<bboxTotal.topLeft()<<
1313 " absPos="<<absPos<<
1314 " relPos="<<relPos<<
1315 " orient="<<orientation<<
1316 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
1317 // " hidden="<<hidden<<
1329 // Position relatively, if needed
1330 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
1332 // Calc angle to mapCenter if I am a mainbranch
1333 // needed for reordering the mainbranches clockwise
1335 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
1336 (int)(y() - parObj->getChildPos().y() ) ) );
1341 // Align myself depending on orientation and parent, but
1342 // only if I am not a mainbranch or mapcenter itself
1343 LinkableMapObj::Orientation o;
1344 o=parObj->getOrientation();
1345 switch (orientation)
1347 case LinkableMapObj::LeftOfCenter:
1348 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1350 case LinkableMapObj::RightOfCenter:
1351 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1354 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1359 if (scrolled) return;
1361 // Set reference point for alignment of childs
1363 if (orientation==LinkableMapObj::LeftOfCenter)
1364 ref2.setX(bbox.topLeft().x() - linkwidth);
1366 ref2.setX(bbox.topRight().x() + linkwidth);
1369 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1371 ref2.setY(ref.y() );
1373 // Align the childs depending on reference point
1374 for (int i=0; i<branch.size(); ++i)
1376 if (!branch.at(i)->isHidden())
1378 branch.at(i)->alignRelativeTo (ref2);
1379 ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChilds().height() );
1385 void BranchObj::reposition()
1387 /* TODO testing only
1388 if (!getHeading().isEmpty())
1389 cout << "BO::reposition "<<getHeading().ascii()<<endl;
1391 cout << "BO::reposition ???"<<endl;
1393 cout << " orient="<<orientation<<endl;
1398 // only calculate the sizes once. If the deepest LMO
1399 // changes its height,
1400 // all upper LMOs have to change, too.
1401 calcBBoxSizeWithChilds();
1402 updateLink(); // This update is needed if the scene is resized
1403 // due to excessive moving of a FIO
1405 alignRelativeTo ( QPointF (absPos.x(),
1406 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1407 qSort (branch.begin(),branch.end(), isAbove);
1408 positionBBox(); // Reposition bbox and contents
1411 // This is only important for moving branches:
1412 // For editing a branch it isn't called...
1413 alignRelativeTo ( QPointF (absPos.x(),
1414 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1418 void BranchObj::unsetAllRepositionRequests()
1420 repositionRequest=false;
1421 for (int i=0; i<branch.size(); ++i)
1422 branch.at(i)->unsetAllRepositionRequests();
1426 QRectF BranchObj::getTotalBBox()
1430 if (scrolled) return r;
1432 for (int i=0; i<branch.size(); ++i)
1433 if (!branch.at(i)->isHidden())
1434 r=addBBox(branch.at(i)->getTotalBBox(),r);
1436 for (int i=0; i<floatimage.size(); ++i)
1437 if (!floatimage.at(i)->isHidden())
1438 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1443 QRectF BranchObj::getBBoxSizeWithChilds()
1448 void BranchObj::calcBBoxSizeWithChilds()
1450 // This is initially called only from reposition and
1451 // and only for mapcenter. So it won't be
1452 // called more than once for a single user
1456 // Calculate size of LMO including all childs (to align them later)
1457 bboxTotal.setX(bbox.x() );
1458 bboxTotal.setY(bbox.y() );
1460 // if branch is scrolled, ignore childs, but still consider floatimages
1463 bboxTotal.setWidth (bbox.width());
1464 bboxTotal.setHeight(bbox.height());
1470 bboxTotal.setWidth (0);
1471 bboxTotal.setHeight(0);
1474 bboxTotal.setX (parObj->x());
1475 bboxTotal.setY (parObj->y());
1478 bboxTotal.setX (bbox.x());
1479 bboxTotal.setY (bbox.y());
1486 // Now calculate recursivly
1488 // maximum of widths
1490 for (int i=0; i<branch.size(); ++i)
1492 if (!branch.at(i)->isHidden())
1494 branch.at(i)->calcBBoxSizeWithChilds();
1495 br=branch.at(i)->getBBoxSizeWithChilds();
1496 r.setWidth( max (br.width(), r.width() ));
1497 r.setHeight(br.height() + r.height() );
1498 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1501 // Add myself and also
1502 // add width of link to sum if necessary
1503 if (branch.isEmpty())
1504 bboxTotal.setWidth (bbox.width() + r.width() );
1506 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1508 bboxTotal.setHeight(max (r.height(), bbox.height()));
1511 void BranchObj::select()
1513 // update NoteEditor
1514 textEditor->setText(note.getNote() );
1515 QString fnh=note.getFilenameHint();
1517 textEditor->setFilenameHint(note.getFilenameHint() );
1519 textEditor->setFilenameHint(getHeading() );
1520 textEditor->setFontHint (note.getFontHint() );
1521 isNoteInEditor=true;
1523 // set selected and visible
1524 LinkableMapObj::select();
1526 // Tell parent that I am selected now:
1527 BranchObj* po=(BranchObj*)(parObj);
1528 if (po) // TODO Try to get rid of this cast...
1529 po->setLastSelectedBranch(this);
1531 // temporary unscroll, if we have scrolled parents somewhere
1532 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1534 // Show URL and link in statusbar
1536 if (!url.isEmpty()) status+="URL: "+url+" ";
1537 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1538 if (!status.isEmpty()) mainWindow->statusMessage (status);
1541 updateFlagsToolbar();
1544 mapEditor->updateActions();
1547 void BranchObj::unselect()
1549 LinkableMapObj::unselect();
1550 // Delete any messages like vymLink in StatusBar
1551 mainWindow->statusMessage ("");
1553 // Save current note
1554 if (isNoteInEditor) getNoteFromTextEditor();
1555 isNoteInEditor=false;
1557 // reset temporary unscroll, if we have scrolled parents somewhere
1558 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1560 // Erase content of editor
1561 textEditor->setInactive();
1563 // unselect all buttons in toolbar
1564 standardFlagsDefault->updateToolbar();
1567 QString BranchObj::getSelectString()
1573 s= "bo:" + QString("%1").arg(getNum());
1575 s= ((BranchObj*)(parObj))->getSelectString() + ",bo:" + QString("%1").arg(getNum());
1582 void BranchObj::animate()
1585 cout << "BO::animate x,y="<<relPos.x()<<","<<relPos.y()<<endl;