2 #include "texteditor.h"
4 #include "mainwindow.h"
6 extern TextEditor *textEditor;
7 extern Main *mainWindow;
8 extern FlagRowObj *standardFlagsDefault;
11 /////////////////////////////////////////////////////////////////
13 /////////////////////////////////////////////////////////////////
15 BranchObj* BranchObj::itLast=NULL;
16 BranchObj* BranchObj::itFirst=NULL;
19 HeadingObj* BranchObj::getHO() //FIXME testing only
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 //cout << "Destr BranchObj of "<<this<<endl;
57 // Check, if this branch was the last child to be deleted
58 // If so, unset the scrolled flags
60 BranchObj *po=(BranchObj*)parObj;
64 bo=((BranchObj*)parObj)->getLastBranch();
65 if (bo) po->unScroll();
70 bool BranchObj::operator< ( const BranchObj & other )
72 return angle < other.angle;
75 bool BranchObj::operator== ( const BranchObj & other )
77 return angle == other.angle;
80 void BranchObj::init ()
85 absPos+=parObj->getChildPos();
95 includeImagesVer=false;
96 includeImagesHor=false;
99 void BranchObj::copy (BranchObj* other)
101 OrnamentedObj::copy(other);
104 for (int i=0; i<other->branch.size(); ++i)
105 // Make deep copy of b
106 // Because addBranch again calls copy for the childs,
107 // Those will get a deep copy, too
108 addBranch(other->branch.at(i) );
110 for (int i=0; i<other->floatimage.size(); ++i)
111 addFloatImage (other->floatimage.at(i));
112 scrolled=other->scrolled;
113 tmpUnscrolled=other->tmpUnscrolled;
114 setVisibility (other->visible);
121 void BranchObj::clear()
123 setVisibility (true);
125 while (!floatimage.isEmpty())
126 delete floatimage.takeFirst();
128 while (!xlink.isEmpty())
129 delete xlink.takeFirst();
131 while (!branch.isEmpty())
132 delete branch.takeFirst();
135 bool isAbove (BranchObj* a, BranchObj *b)
137 if (a->angle < b->angle)
143 int BranchObj::getNum()
146 return ((BranchObj*)parObj)->getNum (this);
151 int BranchObj::getNum(BranchObj *bo)
153 return branch.indexOf (bo);
156 int BranchObj::getFloatImageNum(FloatImageObj *fio)
158 return floatimage.indexOf(fio);
161 int BranchObj::countBranches()
163 return branch.count();
166 int BranchObj::countFloatImages()
168 return floatimage.count();
171 int BranchObj::countXLinks()
173 return xlink.count();
176 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
178 // Temporary link to lmo
179 // m is position of mouse pointer
180 // offset 0: default 1: below lmo -1 above lmo (if possible)
183 BranchObj* o=(BranchObj*)(lmo);
187 // ignore mapcenter and mainbranch
188 if (lmo->getDepth()<2) off=0;
195 depth=parObj->getDepth()+1;
197 // setLinkStyle calls updateLink, only set it once
198 if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
200 // Move temporary to new position at destination
201 // Usually the positioning would be done by reposition(),
202 // but then also the destination branch would "Jump" around...
203 // Better just do it approximately
205 { // new parent is the mapcenter itself
207 QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
208 m.y() - o->getChildPos().y() ));
209 if (p.x()<0) p.setX( p.x()-bbox.width() );
216 // new parent is just a branch, link to it
217 QRectF t=o->getBBoxSizeWithChilds();
218 if (o->getLastBranch())
219 y=t.y() + t.height() ;
226 // we want to link above lmo
227 y=o->y() - height() + 5;
229 // we want to link below lmo
230 // Bottom of sel should be 5 pixels above
231 // the bottom of the branch _below_ the target:
232 // Don't try to find that branch, guess 12 pixels
233 y=o->getChildPos().y() -height() + 12;
235 if (o->getOrientation()==OrientLeftOfCenter)
236 move ( o->getChildPos().x() - linkwidth, y );
238 move (o->getChildPos().x() + linkwidth, y );
241 // updateLink is called implicitly in move
245 void BranchObj::unsetParObjTmp()
252 depth=parObj->getDepth()+1;
253 setLinkStyle (getDefLinkStyle() );
258 void BranchObj::unScroll()
260 if (tmpUnscrolled) resetTmpUnscroll();
261 if (scrolled) toggleScroll();
264 void BranchObj::toggleScroll()
269 systemFlags->deactivate("scrolledright");
270 for (int i=0; i<branch.size(); ++i)
271 branch.at(i)->setVisibility(true);
275 systemFlags->activate("scrolledright");
276 for (int i=0; i<branch.size(); ++i)
277 branch.at(i)->setVisibility(false);
281 move (absPos.x(), absPos.y() );
285 bool BranchObj::isScrolled()
290 bool BranchObj::hasScrolledParent(BranchObj *start)
292 // Calls parents recursivly to
293 // find out, if we are scrolled at all.
294 // But ignore myself, just look at parents.
296 if (this !=start && scrolled) return true;
298 BranchObj* bo=(BranchObj*)(parObj);
300 return bo->hasScrolledParent(start);
305 void BranchObj::tmpUnscroll()
307 // Unscroll parent (recursivly)
308 BranchObj* bo=(BranchObj*)(parObj);
309 if (bo) bo->tmpUnscroll();
315 systemFlags->activate("tmpUnscrolledright");
320 void BranchObj::resetTmpUnscroll()
322 // Unscroll parent (recursivly)
323 BranchObj* bo=(BranchObj*)(parObj);
325 bo->resetTmpUnscroll();
331 systemFlags->deactivate("tmpUnscrolledright");
336 void BranchObj::setVisibility(bool v, int toDepth)
338 if (depth <= toDepth)
340 frame->setVisibility(v);
341 heading->setVisibility(v);
342 systemFlags->setVisibility(v);
343 standardFlags->setVisibility(v);
344 LinkableMapObj::setVisibility (v);
346 // Only change childs, if I am not scrolled
347 if (!scrolled && (depth < toDepth))
349 // Now go recursivly through all childs
351 for (i=0; i<branch.size(); ++i)
352 branch.at(i)->setVisibility (v,toDepth);
353 for (i=0; i<floatimage.size(); ++i)
354 floatimage.at(i)->setVisibility (v);
355 for (i=0; i<xlink.size(); ++i)
356 xlink.at(i)->setVisibility ();
358 } // depth <= toDepth
362 void BranchObj::setVisibility(bool v)
364 setVisibility (v,MAX_DEPTH);
368 void BranchObj::setLinkColor ()
370 // Overloaded from LinkableMapObj
371 // BranchObj can use color of heading
374 if (mapEditor->getMapLinkColorHint()==HeadingColor)
375 LinkableMapObj::setLinkColor (heading->getColor() );
377 LinkableMapObj::setLinkColor ();
380 void BranchObj::setColorSubtree(QColor col)
382 OrnamentedObj::setColor (col);
383 for (int i=0; i<branch.size(); ++i)
384 branch.at(i)->setColorSubtree(col);
387 BranchObj* BranchObj::first()
394 BranchObj* BranchObj::next()
398 BranchObj *po=(BranchObj*)parObj;
400 if (branch.isEmpty())
407 // no itLast, we are just beginning
410 // we have childs, return first one
416 // No childs, so there is no next
424 { // We come from parent
427 // there are childs, go there
432 { // no childs, try to go up again
435 // go back to parent and try to find next there
444 // can't go up, I am mapCenter, no next
451 // We don't come from parent, but from brother or childs
453 // Try to find last child, where we came from, in my own childs
456 while (i<branch.size())
458 // Try to find itLast in my own childs
459 if (itLast==branch.at(i))
461 // ok, we come from my own childs
462 if (i<branch.size()-1)
472 { // found itLast in my childs
475 // found a brother of lastLMO
483 if (this==itFirst) return NULL; // Stop at starting point
492 // can't go up, I am mapCenter
499 // couldn't find last child, it must be a nephew of mine
502 // proceed with my first child
504 return branch.first();
508 // or go back to my parents
519 // can't go up, I am mapCenter
526 BranchObj* BranchObj::getLastIterator()
531 void BranchObj::setLastIterator(BranchObj* it)
536 void BranchObj::positionContents()
538 for (int i=0; i<floatimage.size(); ++i )
539 floatimage.at(i)->reposition();
540 OrnamentedObj::positionContents();
543 void BranchObj::move (double x, double y)
545 OrnamentedObj::move (x,y);
546 for (int i=0; i<floatimage.size(); ++i )
547 floatimage.at(i)->reposition();
551 void BranchObj::move (QPointF p)
556 void BranchObj::moveBy (double x, double y)
558 OrnamentedObj::moveBy (x,y);
559 for (int i=0; i<branch.size(); ++i)
560 branch.at(i)->moveBy (x,y);
564 void BranchObj::moveBy (QPointF p)
566 moveBy (p.x(), p.y());
570 void BranchObj::positionBBox()
572 QPointF ap=getAbsPos();
573 bbox.moveTopLeft (ap);
577 frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
579 // Update links to other branches
580 for (int i=0; i<xlink.size(); ++i)
581 xlink.at(i)->updateXLink();
584 void BranchObj::calcBBoxSize()
586 QSizeF heading_r=heading->getSize();
587 qreal heading_w=(qreal) heading_r.width() ;
588 qreal heading_h=(qreal) heading_r.height() ;
589 QSizeF sysflags_r=systemFlags->getSize();
590 qreal sysflags_h=sysflags_r.height();
591 qreal sysflags_w=sysflags_r.width();
592 QSizeF stanflags_r=standardFlags->getSize();
593 qreal stanflags_h=stanflags_r.height();
594 qreal stanflags_w=stanflags_r.width();
598 // set width to sum of all widths
599 w=heading_w + sysflags_w + stanflags_w;
600 // set height to maximum needed height
601 h=max (sysflags_h,stanflags_h);
604 // Save the dimension of flags and heading
605 ornamentsBBox.setSize ( QSizeF(w,h));
607 // clickBox includes Flags and Heading
608 clickBox.setSize (ornamentsBBox.size() );
613 topPad=botPad=leftPad=rightPad=0;
614 if (includeImagesVer || includeImagesHor)
616 if (countFloatImages()>0)
618 for (int i=0; i<floatimage.size(); ++i )
620 rp=floatimage.at(i)->getRelPos();
621 if (includeImagesVer)
624 topPad=max (topPad,-rp.y()-h);
625 if (rp.y()+floatimage.at(i)->height() > 0)
626 botPad=max (botPad,rp.y()+floatimage.at(i)->height());
628 if (includeImagesHor)
630 if (orientation==OrientRightOfCenter)
633 leftPad=max (leftPad,-rp.x()-w);
634 if (rp.x()+floatimage.at(i)->width() > 0)
635 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
639 leftPad=max (leftPad,-rp.x());
640 if (rp.x()+floatimage.at(i)->width() > w)
641 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
651 w+=frame->getBorder();
652 h+=frame->getBorder();
655 bbox.setSize (QSizeF (w,h));
658 void BranchObj::setDockPos()
660 // Sets childpos and parpos depending on orientation
661 if (getOrientation()==OrientLeftOfCenter )
664 ornamentsBBox.bottomLeft().x(),
667 ornamentsBBox.bottomRight().x(),
672 ornamentsBBox.bottomRight().x(),
675 ornamentsBBox.bottomLeft().x(),
680 LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
684 for (int i=0; i<branch.size(); ++i)
686 lmo=branch.at(i)->findMapObj(p, excludeLMO);
687 if (lmo != NULL) return lmo;
691 if (inBox (p) && (this != excludeLMO) && isVisibleObj() )
694 // Search float images
695 for (int i=0; i<floatimage.size(); ++i )
696 if (floatimage.at(i)->inBox(p) &&
697 (floatimage.at(i) != excludeLMO) &&
698 floatimage.at(i)->getParObj()!= excludeLMO &&
699 floatimage.at(i)->isVisibleObj()
700 ) return floatimage.at(i);
705 void BranchObj::setHeading(QString s)
707 heading->setText(s); // set new heading
708 calcBBoxSize(); // recalculate bbox
709 positionBBox(); // rearrange contents
713 void BranchObj::setHideTmp (HideTmpMode mode)
715 if (mode==HideExport && hasHiddenExportParent(this))
717 setVisibility (false);
721 if (hasScrolledParent(this))
722 setVisibility (false);
724 setVisibility (true);
728 for (int i=0; i<branch.size(); ++i)
729 branch.at(i)->setHideTmp (mode);
732 bool BranchObj::hasHiddenExportParent(BranchObj *start)
734 // Calls parents recursivly to
735 // find out, if we are temp. hidden
737 if (hideExport) return true;
739 BranchObj* bo=(BranchObj*)(parObj);
741 return bo->hasHiddenExportParent(start);
746 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
748 // Cloudy stuff can be hidden during exports
749 if (hidden) return "";
751 // Update of note is usually done while unselecting a branch
752 if (isNoteInEditor) getNoteFromTextEditor();
755 QString scrolledAttr;
757 scrolledAttr=attribut ("scrolled","yes");
761 // save area, if not scrolled
763 if (!((BranchObj*)(parObj))->isScrolled() )
766 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
767 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
768 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
769 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
774 // Providing an ID for a branch makes export to XHTML easier
777 idAttr=attribut ("id",getSelectString());
781 s=beginElement ("branch"
786 +getIncludeImageAttr() );
790 s+=valueElement("heading", getHeading(),
791 attribut ("textColor",QColor(heading->getColor()).name()));
794 if (frame->getFrameType()!=NoFrame)
795 s+=frame->saveToDir ();
797 // save names of flags set
798 s+=standardFlags->saveToDir(tmpdir,prefix,0);
801 for (int i=0; i<floatimage.size(); ++i)
802 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
805 if (!note.isEmpty() )
809 for (int i=0; i<branch.size(); ++i)
810 s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
813 QString ol; // old link
814 QString cl; // current link
815 for (int i=0; i<xlink.size(); ++i)
817 cl=xlink.at(i)->saveToDir();
824 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
829 s+=endElement ("branch");
833 void BranchObj::addXLink (XLinkObj *xlo)
839 void BranchObj::removeXLinkRef (XLinkObj *xlo)
841 xlink.removeAt (xlink.indexOf(xlo));
844 void BranchObj::deleteXLink(XLinkObj *xlo)
847 if (!xlo->isUsed()) delete (xlo);
850 void BranchObj::deleteXLinkAt (int i)
852 XLinkObj *xlo=xlink.at(i);
854 if (!xlo->isUsed()) delete(xlo);
857 XLinkObj* BranchObj::XLinkAt (int i)
862 int BranchObj::countXLink()
864 return xlink.count();
868 BranchObj* BranchObj::XLinkTargetAt (int i)
870 if (i>=0 && i<xlink.size())
873 return xlink.at(i)->otherBranch (this);
878 void BranchObj::setIncludeImagesVer(bool b)
886 bool BranchObj::getIncludeImagesVer()
888 return includeImagesVer;
891 void BranchObj::setIncludeImagesHor(bool b)
899 bool BranchObj::getIncludeImagesHor()
901 return includeImagesHor;
904 QString BranchObj::getIncludeImageAttr()
907 if (includeImagesVer)
908 a=attribut ("incImgV","true");
910 a=attribut ("incImgV","false");
911 if (includeImagesHor)
912 a+=attribut ("incImgH","true");
914 a+=attribut ("incImgH","false");
918 FloatImageObj* BranchObj::addFloatImage ()
920 FloatImageObj *newfi=new FloatImageObj (scene,this);
921 floatimage.append (newfi);
922 if (hasScrolledParent(this) )
923 newfi->setVisibility (false);
925 newfi->setVisibility(visible);
934 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
936 FloatImageObj *newfi=new FloatImageObj (scene,this);
937 floatimage.append (newfi);
939 if (hasScrolledParent(this) )
940 newfi->setVisibility (false);
942 newfi->setVisibility(visible);
951 FloatImageObj* BranchObj::getFirstFloatImage ()
953 return floatimage.first();
956 FloatImageObj* BranchObj::getLastFloatImage ()
958 return floatimage.last();
961 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
963 return floatimage.at(i);
966 void BranchObj::removeFloatImage (FloatImageObj *fio)
968 int i=floatimage.indexOf (fio);
969 if (i>-1) delete (floatimage.takeAt (i));
975 void BranchObj::savePosInAngle ()
977 // Save position in angle
978 for (int i=0; i<branch.size(); ++i)
979 branch.at(i)->angle=i;
982 void BranchObj::setDefAttr (BranchModification mod)
987 case 0: fontsize=16; break;
988 case 1: fontsize=12; break;
989 default: fontsize=10; break;
993 setLinkStyle(getDefLinkStyle());
994 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
995 font.setPointSize(fontsize);
996 heading->setFont(font );
999 setColor (((BranchObj*)(parObj))->getColor());
1004 BranchObj* BranchObj::addBranch()
1006 BranchObj* newbo=new BranchObj(scene,this);
1007 branch.append (newbo);
1008 newbo->setParObj(this);
1009 newbo->setDefAttr(NewBranch);
1010 newbo->setHeading ("new");
1012 newbo->setVisibility (false);
1014 newbo->setVisibility(visible);
1015 newbo->updateLink();
1016 requestReposition();
1020 BranchObj* BranchObj::addBranch(BranchObj* bo)
1022 BranchObj* newbo=new BranchObj(scene,this);
1023 branch.append (newbo);
1025 newbo->setParObj(this);
1026 newbo->setDefAttr(MovedBranch);
1028 newbo->setVisibility (false);
1030 newbo->setVisibility(bo->visible);
1031 newbo->updateLink();
1032 requestReposition();
1036 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
1039 bo->setParObj (this);
1041 bo->setDefAttr(MovedBranch);
1042 if (scrolled) tmpUnscroll();
1043 setLastSelectedBranch (bo);
1047 BranchObj* BranchObj::insertBranch(int pos)
1050 // Add new bo and resort branches
1051 BranchObj *newbo=addBranch ();
1052 newbo->angle=pos-0.5;
1053 qSort (branch.begin(),branch.end(), isAbove);
1057 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
1060 // Add new bo and resort branches
1062 BranchObj *newbo=addBranch (bo);
1063 qSort (branch.begin(),branch.end(), isAbove);
1067 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
1070 // Add new bo and resort branches
1073 bo->setParObj (this);
1075 bo->setDefAttr (MovedBranch);
1076 if (scrolled) tmpUnscroll();
1077 setLastSelectedBranch (bo);
1078 qSort (branch.begin(),branch.end(), isAbove);
1082 void BranchObj::removeBranchHere(BranchObj* borem)
1084 // This removes the branch bo from list, but
1085 // inserts its childs at the place of bo
1087 bo=borem->getLastBranch();
1088 int pos=borem->getNum();
1091 bo->linkTo (this,pos+1);
1092 bo=borem->getLastBranch();
1094 removeBranch (borem);
1097 void BranchObj::removeChilds()
1102 void BranchObj::removeBranch(BranchObj* bo)
1104 // if bo is not in branch remove returns false, we
1107 int i=branch.indexOf(bo);
1111 branch.removeAt (i);
1113 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
1114 requestReposition();
1117 void BranchObj::removeBranchPtr(BranchObj* bo)
1119 int i=branch.indexOf(bo);
1122 branch.removeAt (i);
1124 qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
1125 requestReposition();
1128 void BranchObj::setLastSelectedBranch (BranchObj* bo)
1130 lastSelectedBranch=branch.indexOf(bo);
1133 BranchObj* BranchObj::getLastSelectedBranch ()
1135 if (lastSelectedBranch>=0)
1137 if ( branch.size()>lastSelectedBranch)
1138 return branch.at(lastSelectedBranch);
1139 if (branch.size()>0)
1140 return branch.last();
1145 BranchObj* BranchObj::getFirstBranch ()
1147 if (branch.size()>0)
1148 return branch.first();
1153 BranchObj* BranchObj::getLastBranch ()
1155 if (branch.size()>0)
1156 return branch.last();
1161 BranchObj* BranchObj::getBranchNum (int i)
1163 if (i>=0 && i<branch.size())
1164 return branch.at(i);
1169 bool BranchObj::canMoveBranchUp()
1171 if (!parObj || depth==1) return false;
1172 BranchObj* par=(BranchObj*)parObj;
1173 if (this==par->getFirstBranch())
1179 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
1182 int i=branch.indexOf(bo1);
1184 { // -1 if bo1 not found
1185 branch.at(i)->angle--;
1186 branch.at(i-1)->angle++;
1187 qSort (branch.begin(),branch.end(), isAbove);
1188 return branch.at(i);
1193 bool BranchObj::canMoveBranchDown()
1195 if (!parObj|| depth==1) return false;
1196 BranchObj* par=(BranchObj*)parObj;
1197 if (this==par->getLastBranch())
1203 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
1206 int i=branch.indexOf(bo1);
1208 if (i <branch.size())
1211 branch.at(i)->angle++;
1212 branch.at(j)->angle--;
1213 qSort (branch.begin(),branch.end(), isAbove);
1214 return branch.at(i);
1219 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
1221 // Find current parent and
1222 // remove pointer to myself there
1223 if (!dst) return NULL;
1224 BranchObj *par=(BranchObj*)parObj;
1226 par->removeBranchPtr (this);
1230 // Create new pointer to myself at dst
1231 if (pos<0||dst->getDepth()==0)
1233 // links myself as last branch at dst
1234 dst->addBranchPtr (this);
1239 // inserts me at pos in parent of dst
1242 BranchObj *bo=dst->insertBranchPtr (this,pos);
1243 bo->setDefAttr(MovedBranch);
1252 void BranchObj::alignRelativeTo (QPointF ref)
1254 qreal th = bboxTotal.height();
1257 cout << "BO::alignRelTo "<<getHeading().ascii()<<endl;
1258 cout << " d="<<depth<<
1260 // " bbox.topLeft="<<bboxTotal.topLeft()<<
1261 " absPos="<<absPos<<
1262 " relPos="<<relPos<<
1263 " orient="<<orientation<<
1264 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
1265 // " hidden="<<hidden<<
1277 // Position relatively, if needed
1278 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
1280 // Calc angle to mapCenter if I am a mainbranch
1281 // needed for reordering the mainbranches clockwise
1283 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
1284 (int)(y() - parObj->getChildPos().y() ) ) );
1289 // Align myself depending on orientation and parent, but
1290 // only if I am not a mainbranch or mapcenter itself
1292 o=parObj->getOrientation();
1293 switch (orientation)
1295 case OrientLeftOfCenter:
1296 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1298 case OrientRightOfCenter:
1299 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1302 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1307 if (scrolled) return;
1309 // Set reference point for alignment of childs
1311 if (orientation==OrientLeftOfCenter)
1312 ref2.setX(bbox.topLeft().x() - linkwidth);
1314 ref2.setX(bbox.topRight().x() + linkwidth);
1317 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1319 ref2.setY(ref.y() );
1321 // Align the childs depending on reference point
1322 for (int i=0; i<branch.size(); ++i)
1324 if (!branch.at(i)->isHidden())
1326 branch.at(i)->alignRelativeTo (ref2);
1327 ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChilds().height() );
1333 void BranchObj::reposition()
1335 /* TODO testing only
1336 if (!getHeading().isEmpty())
1337 cout << "BO::reposition "<<getHeading().ascii()<<endl;
1339 cout << "BO::reposition ???"<<endl;
1341 cout << " orient="<<orientation<<endl;
1346 // only calculate the sizes once. If the deepest LMO
1347 // changes its height,
1348 // all upper LMOs have to change, too.
1349 calcBBoxSizeWithChilds();
1350 updateLink(); // This update is needed if the scene is resized
1351 // due to excessive moving of a FIO
1353 alignRelativeTo ( QPointF (absPos.x(),
1354 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1355 qSort (branch.begin(),branch.end(), isAbove);
1356 positionBBox(); // Reposition bbox and contents
1359 // This is only important for moving branches:
1360 // For editing a branch it isn't called...
1361 alignRelativeTo ( QPointF (absPos.x(),
1362 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1366 void BranchObj::unsetAllRepositionRequests()
1368 repositionRequest=false;
1369 for (int i=0; i<branch.size(); ++i)
1370 branch.at(i)->unsetAllRepositionRequests();
1374 QRectF BranchObj::getTotalBBox()
1378 if (scrolled) return r;
1380 for (int i=0; i<branch.size(); ++i)
1381 if (!branch.at(i)->isHidden())
1382 r=addBBox(branch.at(i)->getTotalBBox(),r);
1384 for (int i=0; i<floatimage.size(); ++i)
1385 if (!floatimage.at(i)->isHidden())
1386 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1391 QRectF BranchObj::getBBoxSizeWithChilds()
1396 void BranchObj::calcBBoxSizeWithChilds()
1398 // This is initially called only from reposition and
1399 // and only for mapcenter. So it won't be
1400 // called more than once for a single user
1404 // Calculate size of LMO including all childs (to align them later)
1405 bboxTotal.setX(bbox.x() );
1406 bboxTotal.setY(bbox.y() );
1408 // if branch is scrolled, ignore childs, but still consider floatimages
1411 bboxTotal.setWidth (bbox.width());
1412 bboxTotal.setHeight(bbox.height());
1418 bboxTotal.setWidth (0);
1419 bboxTotal.setHeight(0);
1422 bboxTotal.setX (parObj->x());
1423 bboxTotal.setY (parObj->y());
1426 bboxTotal.setX (bbox.x());
1427 bboxTotal.setY (bbox.y());
1434 // Now calculate recursivly
1436 // maximum of widths
1438 for (int i=0; i<branch.size(); ++i)
1440 if (!branch.at(i)->isHidden())
1442 branch.at(i)->calcBBoxSizeWithChilds();
1443 br=branch.at(i)->getBBoxSizeWithChilds();
1444 r.setWidth( max (br.width(), r.width() ));
1445 r.setHeight(br.height() + r.height() );
1446 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1449 // Add myself and also
1450 // add width of link to sum if necessary
1451 if (branch.isEmpty())
1452 bboxTotal.setWidth (bbox.width() + r.width() );
1454 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1456 bboxTotal.setHeight(max (r.height(), bbox.height()));
1459 void BranchObj::select()
1461 // update NoteEditor
1462 textEditor->setText(note.getNote() );
1463 QString fnh=note.getFilenameHint();
1465 textEditor->setFilenameHint(note.getFilenameHint() );
1467 textEditor->setFilenameHint(getHeading() );
1468 textEditor->setFontHint (note.getFontHint() );
1469 isNoteInEditor=true;
1471 // set selected and visible
1472 LinkableMapObj::select();
1474 // Tell parent that I am selected now:
1475 BranchObj* po=(BranchObj*)(parObj);
1476 if (po) // TODO Try to get rid of this cast...
1477 po->setLastSelectedBranch(this);
1479 // temporary unscroll, if we have scrolled parents somewhere
1480 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1482 // Show URL and link in statusbar
1484 if (!url.isEmpty()) status+="URL: "+url+" ";
1485 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1486 if (!status.isEmpty()) mainWindow->statusMessage (status);
1489 updateFlagsToolbar();
1492 mapEditor->updateActions();
1495 void BranchObj::unselect()
1497 LinkableMapObj::unselect();
1498 // Delete any messages like vymLink in StatusBar
1499 mainWindow->statusMessage ("");
1501 // Save current note
1502 if (isNoteInEditor) getNoteFromTextEditor();
1503 isNoteInEditor=false;
1505 // reset temporary unscroll, if we have scrolled parents somewhere
1506 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1508 // Erase content of editor
1509 textEditor->setInactive();
1511 // unselect all buttons in toolbar
1512 standardFlagsDefault->updateToolbar();
1515 QString BranchObj::getSelectString()
1521 s= "bo:" + QString("%1").arg(getNum());
1523 s= ((BranchObj*)(parObj))->getSelectString() + ",bo:" + QString("%1").arg(getNum());