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 while (!floatimage.isEmpty())
124 delete floatimage.takeFirst();
126 while (!xlink.isEmpty())
127 delete xlink.takeFirst();
129 while (!branch.isEmpty())
130 delete branch.takeFirst();
133 bool isAbove (BranchObj* a, BranchObj *b)
135 if (a->angle < b->angle)
141 int BranchObj::getNum()
144 return ((BranchObj*)parObj)->getNum (this);
149 int BranchObj::getNum(BranchObj *bo)
151 return branch.indexOf (bo);
154 int BranchObj::getFloatImageNum(FloatImageObj *fio)
156 return floatimage.indexOf(fio);
159 int BranchObj::countBranches()
161 return branch.count();
164 int BranchObj::countFloatImages()
166 return floatimage.count();
169 int BranchObj::countXLinks()
171 return xlink.count();
174 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
176 // Temporary link to lmo
177 // m is position of mouse pointer
178 // offset 0: default 1: below lmo -1 above lmo (if possible)
181 BranchObj* o=(BranchObj*)(lmo);
185 // ignore mapcenter and mainbranch
186 if (lmo->getDepth()<2) off=0;
193 depth=parObj->getDepth()+1;
195 // setLinkStyle calls updateLink, only set it once
196 if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
198 // Move temporary to new position at destination
199 // Usually the positioning would be done by reposition(),
200 // but then also the destination branch would "Jump" around...
201 // Better just do it approximately
203 { // new parent is the mapcenter itself
205 QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
206 m.y() - o->getChildPos().y() ));
207 if (p.x()<0) p.setX( p.x()-bbox.width() );
214 // new parent is just a branch, link to it
215 QRectF t=o->getBBoxSizeWithChilds();
216 if (o->getLastBranch())
217 y=t.y() + t.height() ;
224 // we want to link above lmo
225 y=o->y() - height() + 5;
227 // we want to link below lmo
228 // Bottom of sel should be 5 pixels above
229 // the bottom of the branch _below_ the target:
230 // Don't try to find that branch, guess 12 pixels
231 y=o->getChildPos().y() -height() + 12;
233 if (o->getOrientation()==OrientLeftOfCenter)
234 move ( o->getChildPos().x() - linkwidth, y );
236 move (o->getChildPos().x() + linkwidth, y );
239 // updateLink is called implicitly in move
243 void BranchObj::unsetParObjTmp()
250 depth=parObj->getDepth()+1;
251 setLinkStyle (getDefLinkStyle() );
256 void BranchObj::unScroll()
258 if (tmpUnscrolled) resetTmpUnscroll();
259 if (scrolled) toggleScroll();
262 void BranchObj::toggleScroll()
267 systemFlags->deactivate("scrolledright");
268 for (int i=0; i<branch.size(); ++i)
269 branch.at(i)->setVisibility(true);
273 systemFlags->activate("scrolledright");
274 for (int i=0; i<branch.size(); ++i)
275 branch.at(i)->setVisibility(false);
279 move (absPos.x(), absPos.y() );
283 bool BranchObj::isScrolled()
288 bool BranchObj::hasScrolledParent(BranchObj *start)
290 // Calls parents recursivly to
291 // find out, if we are scrolled at all.
292 // But ignore myself, just look at parents.
294 if (this !=start && scrolled) return true;
296 BranchObj* bo=(BranchObj*)(parObj);
298 return bo->hasScrolledParent(start);
303 void BranchObj::tmpUnscroll()
305 // Unscroll parent (recursivly)
306 BranchObj* bo=(BranchObj*)(parObj);
307 if (bo) bo->tmpUnscroll();
313 systemFlags->activate("tmpUnscrolledright");
318 void BranchObj::resetTmpUnscroll()
320 // Unscroll parent (recursivly)
321 BranchObj* bo=(BranchObj*)(parObj);
323 bo->resetTmpUnscroll();
329 systemFlags->deactivate("tmpUnscrolledright");
334 void BranchObj::setVisibility(bool v, int toDepth)
336 if (depth <= toDepth)
338 frame->setVisibility(v);
339 heading->setVisibility(v);
340 systemFlags->setVisibility(v);
341 standardFlags->setVisibility(v);
342 LinkableMapObj::setVisibility (v);
344 // Only change childs, if I am not scrolled
345 if (!scrolled && (depth < toDepth))
347 // Now go recursivly through all childs
349 for (i=0; i<branch.size(); ++i)
350 branch.at(i)->setVisibility (v,toDepth);
351 for (i=0; i<floatimage.size(); ++i)
352 floatimage.at(i)->setVisibility (v);
353 for (i=0; i<xlink.size(); ++i)
354 xlink.at(i)->setVisibility ();
356 } // depth <= toDepth
360 void BranchObj::setVisibility(bool v)
362 setVisibility (v,MAX_DEPTH);
366 void BranchObj::setLinkColor ()
368 // Overloaded from LinkableMapObj
369 // BranchObj can use color of heading
372 if (mapEditor->getMapLinkColorHint()==HeadingColor)
373 LinkableMapObj::setLinkColor (heading->getColor() );
375 LinkableMapObj::setLinkColor ();
378 void BranchObj::setColorSubtree(QColor col)
380 OrnamentedObj::setColor (col);
381 for (int i=0; i<branch.size(); ++i)
382 branch.at(i)->setColorSubtree(col);
385 BranchObj* BranchObj::first()
392 BranchObj* BranchObj::next()
396 BranchObj *po=(BranchObj*)parObj;
398 if (branch.isEmpty())
405 // no itLast, we are just beginning
408 // we have childs, return first one
414 // No childs, so there is no next
422 { // We come from parent
425 // there are childs, go there
430 { // no childs, try to go up again
433 // go back to parent and try to find next there
442 // can't go up, I am mapCenter, no next
449 // We don't come from parent, but from brother or childs
451 // Try to find last child, where we came from, in my own childs
454 while (i<branch.size())
456 // Try to find itLast in my own childs
457 if (itLast==branch.at(i))
459 // ok, we come from my own childs
460 if (i<branch.size()-1)
470 { // found itLast in my childs
473 // found a brother of lastLMO
481 if (this==itFirst) return NULL; // Stop at starting point
490 // can't go up, I am mapCenter
497 // couldn't find last child, it must be a nephew of mine
500 // proceed with my first child
502 return branch.first();
506 // or go back to my parents
517 // can't go up, I am mapCenter
524 BranchObj* BranchObj::getLastIterator()
529 void BranchObj::setLastIterator(BranchObj* it)
534 void BranchObj::positionContents()
536 for (int i=0; i<floatimage.size(); ++i )
537 floatimage.at(i)->reposition();
538 OrnamentedObj::positionContents();
541 void BranchObj::move (double x, double y)
543 OrnamentedObj::move (x,y);
544 for (int i=0; i<floatimage.size(); ++i )
545 floatimage.at(i)->reposition();
549 void BranchObj::move (QPointF p)
554 void BranchObj::moveBy (double x, double y)
556 OrnamentedObj::moveBy (x,y);
557 for (int i=0; i<branch.size(); ++i)
558 branch.at(i)->moveBy (x,y);
562 void BranchObj::moveBy (QPointF p)
564 moveBy (p.x(), p.y());
568 void BranchObj::positionBBox()
570 QPointF ap=getAbsPos();
571 bbox.moveTopLeft (ap);
576 frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
578 // Update links to other branches
579 for (int i=0; i<xlink.size(); ++i)
580 xlink.at(i)->updateXLink();
583 void BranchObj::calcBBoxSize()
585 QSizeF heading_r=heading->getSize();
586 qreal heading_w=(qreal) heading_r.width() ;
587 qreal heading_h=(qreal) heading_r.height() ;
588 QSizeF sysflags_r=systemFlags->getSize();
589 qreal sysflags_h=sysflags_r.height();
590 qreal sysflags_w=sysflags_r.width();
591 QSizeF stanflags_r=standardFlags->getSize();
592 qreal stanflags_h=stanflags_r.height();
593 qreal stanflags_w=stanflags_r.width();
597 // set width to sum of all widths
598 w=heading_w + sysflags_w + stanflags_w;
599 // set height to maximum needed height
600 h=max (sysflags_h,stanflags_h);
603 // Save the dimension of flags and heading
604 ornamentsBBox.setSize ( QSizeF(w,h));
606 // clickBox includes Flags and Heading
607 clickBox.setSize (ornamentsBBox.size() );
612 topPad=botPad=leftPad=rightPad=0;
613 if (includeImagesVer || includeImagesHor)
615 if (countFloatImages()>0)
617 for (int i=0; i<floatimage.size(); ++i )
619 rp=floatimage.at(i)->getRelPos();
620 if (includeImagesVer)
623 topPad=max (topPad,-rp.y()-h);
624 if (rp.y()+floatimage.at(i)->height() > 0)
625 botPad=max (botPad,rp.y()+floatimage.at(i)->height());
627 if (includeImagesHor)
629 if (orientation==OrientRightOfCenter)
632 leftPad=max (leftPad,-rp.x()-w);
633 if (rp.x()+floatimage.at(i)->width() > 0)
634 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
638 leftPad=max (leftPad,-rp.x());
639 if (rp.x()+floatimage.at(i)->width() > w)
640 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
650 w+=frame->getBorder();
651 h+=frame->getBorder();
654 bbox.setSize (QSizeF (w,h));
657 void BranchObj::setDockPos()
659 // Sets childpos and parpos depending on orientation
660 if (getOrientation()==OrientLeftOfCenter )
662 childPos=QPointF (ornamentsBBox.bottomLeft().x(), ornamentsBBox.bottomLeft().y() );
663 parPos=QPointF (ornamentsBBox.bottomRight().x(),ornamentsBBox.bottomRight().y() );
666 childPos=QPointF (ornamentsBBox.bottomRight().x(), ornamentsBBox.bottomRight().y() );
667 parPos=QPointF (ornamentsBBox.bottomLeft().x(),ornamentsBBox.bottomLeft().y() );
671 LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
675 for (int i=0; i<branch.size(); ++i)
677 lmo=branch.at(i)->findMapObj(p, excludeLMO);
678 if (lmo != NULL) return lmo;
682 if (inBox (p) && (this != excludeLMO) && isVisibleObj() )
685 // Search float images
686 for (int i=0; i<floatimage.size(); ++i )
687 if (floatimage.at(i)->inBox(p) &&
688 (floatimage.at(i) != excludeLMO) &&
689 floatimage.at(i)->getParObj()!= excludeLMO &&
690 floatimage.at(i)->isVisibleObj()
691 ) return floatimage.at(i);
696 void BranchObj::setHeading(QString s)
698 heading->setText(s); // set new heading
699 calcBBoxSize(); // recalculate bbox
700 positionBBox(); // rearrange contents
704 void BranchObj::setHideTmp (HideTmpMode mode)
706 if (mode==HideExport && hasHiddenExportParent(this))
708 setVisibility (false);
712 if (hasScrolledParent(this))
713 setVisibility (false);
715 setVisibility (true);
719 for (int i=0; i<branch.size(); ++i)
720 branch.at(i)->setHideTmp (mode);
723 bool BranchObj::hasHiddenExportParent(BranchObj *start)
725 // Calls parents recursivly to
726 // find out, if we are temp. hidden
728 if (hideExport) return true;
730 BranchObj* bo=(BranchObj*)(parObj);
732 return bo->hasHiddenExportParent(start);
737 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
739 // Cloudy stuff can be hidden during exports
740 if (hidden) return "";
742 // Update of note is usually done while unselecting a branch
743 if (isNoteInEditor) getNoteFromTextEditor();
746 QString scrolledAttr;
748 scrolledAttr=attribut ("scrolled","yes");
752 // save area, if not scrolled
754 if (!((BranchObj*)(parObj))->isScrolled() )
757 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
758 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
759 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
760 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
765 // Providing an ID for a branch makes export to XHTML easier
768 idAttr=attribut ("id",getSelectString());
772 s=beginElement ("branch"
777 +getIncludeImageAttr() );
781 s+=valueElement("heading", getHeading(),
782 attribut ("textColor",QColor(heading->getColor()).name()));
785 if (frame->getFrameType()!=NoFrame)
786 s+=frame->saveToDir ();
788 // save names of flags set
789 s+=standardFlags->saveToDir(tmpdir,prefix,0);
792 for (int i=0; i<floatimage.size(); ++i)
793 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
796 if (!note.isEmpty() )
800 for (int i=0; i<branch.size(); ++i)
801 s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
804 QString ol; // old link
805 QString cl; // current link
806 for (int i=0; i<xlink.size(); ++i)
808 cl=xlink.at(i)->saveToDir();
815 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
820 s+=endElement ("branch");
824 void BranchObj::addXLink (XLinkObj *xlo)
830 void BranchObj::removeXLinkRef (XLinkObj *xlo)
832 xlink.removeAt (xlink.indexOf(xlo));
835 void BranchObj::deleteXLink(XLinkObj *xlo)
838 if (!xlo->isUsed()) delete (xlo);
841 void BranchObj::deleteXLinkAt (int i)
843 XLinkObj *xlo=xlink.at(i);
845 if (!xlo->isUsed()) delete(xlo);
848 XLinkObj* BranchObj::XLinkAt (int i)
853 int BranchObj::countXLink()
855 return xlink.count();
859 BranchObj* BranchObj::XLinkTargetAt (int i)
861 if (i>=0 && i<xlink.size())
864 return xlink.at(i)->otherBranch (this);
869 void BranchObj::setIncludeImagesVer(bool b)
877 bool BranchObj::getIncludeImagesVer()
879 return includeImagesVer;
882 void BranchObj::setIncludeImagesHor(bool b)
890 bool BranchObj::getIncludeImagesHor()
892 return includeImagesHor;
895 QString BranchObj::getIncludeImageAttr()
898 if (includeImagesVer)
899 a=attribut ("incImgV","true");
901 a=attribut ("incImgV","false");
902 if (includeImagesHor)
903 a+=attribut ("incImgH","true");
905 a+=attribut ("incImgH","false");
909 FloatImageObj* BranchObj::addFloatImage ()
911 FloatImageObj *newfi=new FloatImageObj (scene,this);
912 floatimage.append (newfi);
913 if (hasScrolledParent(this) )
914 newfi->setVisibility (false);
916 newfi->setVisibility(visible);
925 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
927 FloatImageObj *newfi=new FloatImageObj (scene,this);
928 floatimage.append (newfi);
930 if (hasScrolledParent(this) )
931 newfi->setVisibility (false);
933 newfi->setVisibility(visible);
942 FloatImageObj* BranchObj::getFirstFloatImage ()
944 return floatimage.first();
947 FloatImageObj* BranchObj::getLastFloatImage ()
949 return floatimage.last();
952 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
954 return floatimage.at(i);
957 void BranchObj::removeFloatImage (FloatImageObj *fio)
959 int i=floatimage.indexOf (fio);
960 if (i>-1) delete (floatimage.takeAt (i));
966 void BranchObj::savePosInAngle ()
968 // Save position in angle
969 for (int i=0; i<branch.size(); ++i)
970 branch.at(i)->angle=i;
973 void BranchObj::setDefAttr (BranchModification mod)
978 case 0: fontsize=16; break;
979 case 1: fontsize=12; break;
980 default: fontsize=10; break;
984 setLinkStyle(getDefLinkStyle());
985 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
986 font.setPointSize(fontsize);
987 heading->setFont(font );
990 setColor (((BranchObj*)(parObj))->getColor());
995 BranchObj* BranchObj::addBranch()
997 BranchObj* newbo=new BranchObj(scene,this);
998 branch.append (newbo);
999 newbo->setParObj(this);
1000 newbo->setDefAttr(NewBranch);
1001 newbo->setHeading ("new");
1003 newbo->setVisibility (false);
1005 newbo->setVisibility(visible);
1006 newbo->updateLink();
1007 requestReposition();
1011 BranchObj* BranchObj::addBranch(BranchObj* bo)
1013 BranchObj* newbo=new BranchObj(scene,this);
1014 branch.append (newbo);
1016 newbo->setParObj(this);
1017 newbo->setDefAttr(MovedBranch);
1019 newbo->setVisibility (false);
1021 newbo->setVisibility(bo->visible);
1022 newbo->updateLink();
1023 requestReposition();
1027 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
1030 bo->setParObj (this);
1032 bo->setDefAttr(MovedBranch);
1033 if (scrolled) tmpUnscroll();
1034 setLastSelectedBranch (bo);
1038 BranchObj* BranchObj::insertBranch(int pos)
1041 // Add new bo and resort branches
1042 BranchObj *newbo=addBranch ();
1043 newbo->angle=pos-0.5;
1044 qSort (branch.begin(),branch.end(), isAbove);
1048 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
1051 // Add new bo and resort branches
1053 BranchObj *newbo=addBranch (bo);
1054 qSort (branch.begin(),branch.end(), isAbove);
1058 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
1061 // Add new bo and resort branches
1064 bo->setParObj (this);
1066 bo->setDefAttr (MovedBranch);
1067 if (scrolled) tmpUnscroll();
1068 setLastSelectedBranch (bo);
1069 qSort (branch.begin(),branch.end(), isAbove);
1073 void BranchObj::removeBranchHere(BranchObj* borem)
1075 // This removes the branch bo from list, but
1076 // inserts its childs at the place of bo
1078 bo=borem->getLastBranch();
1079 int pos=borem->getNum();
1082 bo->linkTo (this,pos+1);
1083 bo=borem->getLastBranch();
1085 removeBranch (borem);
1088 void BranchObj::removeChilds()
1093 void BranchObj::removeBranch(BranchObj* bo)
1095 // if bo is not in branch remove returns false, we
1098 int i=branch.indexOf(bo);
1102 branch.removeAt (i);
1104 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
1105 requestReposition();
1108 void BranchObj::removeBranchPtr(BranchObj* bo)
1110 int i=branch.indexOf(bo);
1113 branch.removeAt (i);
1115 qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
1116 requestReposition();
1119 void BranchObj::setLastSelectedBranch (BranchObj* bo)
1121 lastSelectedBranch=branch.indexOf(bo);
1124 BranchObj* BranchObj::getLastSelectedBranch ()
1126 if (lastSelectedBranch>=0)
1128 if ( branch.size()>lastSelectedBranch)
1129 return branch.at(lastSelectedBranch);
1130 if (branch.size()>0)
1131 return branch.last();
1136 BranchObj* BranchObj::getFirstBranch ()
1138 if (branch.size()>0)
1139 return branch.first();
1144 BranchObj* BranchObj::getLastBranch ()
1146 if (branch.size()>0)
1147 return branch.last();
1152 BranchObj* BranchObj::getBranchNum (int i)
1154 if (i>=0 && i<branch.size())
1155 return branch.at(i);
1160 bool BranchObj::canMoveBranchUp()
1162 if (!parObj || depth==1) return false;
1163 BranchObj* par=(BranchObj*)parObj;
1164 if (this==par->getFirstBranch())
1170 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
1173 int i=branch.indexOf(bo1);
1175 { // -1 if bo1 not found
1176 branch.at(i)->angle--;
1177 branch.at(i-1)->angle++;
1178 qSort (branch.begin(),branch.end(), isAbove);
1179 return branch.at(i);
1184 bool BranchObj::canMoveBranchDown()
1186 if (!parObj|| depth==1) return false;
1187 BranchObj* par=(BranchObj*)parObj;
1188 if (this==par->getLastBranch())
1194 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
1197 int i=branch.indexOf(bo1);
1199 if (i <branch.size())
1202 branch.at(i)->angle++;
1203 branch.at(j)->angle--;
1204 qSort (branch.begin(),branch.end(), isAbove);
1205 return branch.at(i);
1210 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
1212 // Find current parent and
1213 // remove pointer to myself there
1214 if (!dst) return NULL;
1215 BranchObj *par=(BranchObj*)parObj;
1217 par->removeBranchPtr (this);
1221 // Create new pointer to myself at dst
1222 if (pos<0||dst->getDepth()==0)
1224 // links myself as last branch at dst
1225 dst->addBranchPtr (this);
1230 // inserts me at pos in parent of dst
1233 BranchObj *bo=dst->insertBranchPtr (this,pos);
1234 bo->setDefAttr(MovedBranch);
1243 void BranchObj::alignRelativeTo (QPointF ref)
1245 qreal th = bboxTotal.height();
1248 cout << "BO::alignRelTo "<<getHeading().ascii()<<endl;
1249 cout << " d="<<depth<<
1251 // " bbox.topLeft="<<bboxTotal.topLeft()<<
1252 " absPos="<<absPos<<
1253 " relPos="<<relPos<<
1254 " orient="<<orientation<<
1255 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
1256 // " hidden="<<hidden<<
1268 // Position relatively, if needed
1269 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
1271 // Calc angle to mapCenter if I am a mainbranch
1272 // needed for reordering the mainbranches clockwise
1274 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
1275 (int)(y() - parObj->getChildPos().y() ) ) );
1280 // Align myself depending on orientation and parent, but
1281 // only if I am not a mainbranch or mapcenter itself
1283 o=parObj->getOrientation();
1284 switch (orientation)
1286 case OrientLeftOfCenter:
1287 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1289 case OrientRightOfCenter:
1290 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1293 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1298 if (scrolled) return;
1300 // Set reference point for alignment of childs
1302 if (orientation==OrientLeftOfCenter)
1303 ref2.setX(bbox.topLeft().x() - linkwidth);
1305 ref2.setX(bbox.topRight().x() + linkwidth);
1308 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1310 ref2.setY(ref.y() );
1312 // Align the childs depending on reference point
1313 for (int i=0; i<branch.size(); ++i)
1315 if (!branch.at(i)->isHidden())
1317 branch.at(i)->alignRelativeTo (ref2);
1318 ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChilds().height() );
1324 void BranchObj::reposition()
1326 /* TODO testing only
1327 if (!getHeading().isEmpty())
1328 cout << "BO::reposition "<<getHeading().ascii()<<endl;
1330 cout << "BO::reposition ???"<<endl;
1332 cout << " orient="<<orientation<<endl;
1337 // only calculate the sizes once. If the deepest LMO
1338 // changes its height,
1339 // all upper LMOs have to change, too.
1340 calcBBoxSizeWithChilds();
1341 updateLink(); // This update is needed if the scene is resized
1342 // due to excessive moving of a FIO
1344 alignRelativeTo ( QPointF (absPos.x(),
1345 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1346 qSort (branch.begin(),branch.end(), isAbove);
1347 positionBBox(); // Reposition bbox and contents
1350 // This is only important for moving branches:
1351 // For editing a branch it isn't called...
1352 alignRelativeTo ( QPointF (absPos.x(),
1353 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1357 void BranchObj::unsetAllRepositionRequests()
1359 repositionRequest=false;
1360 for (int i=0; i<branch.size(); ++i)
1361 branch.at(i)->unsetAllRepositionRequests();
1365 QRectF BranchObj::getTotalBBox()
1369 if (scrolled) return r;
1371 for (int i=0; i<branch.size(); ++i)
1372 if (!branch.at(i)->isHidden())
1373 r=addBBox(branch.at(i)->getTotalBBox(),r);
1375 for (int i=0; i<floatimage.size(); ++i)
1376 if (!floatimage.at(i)->isHidden())
1377 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1382 QRectF BranchObj::getBBoxSizeWithChilds()
1387 void BranchObj::calcBBoxSizeWithChilds()
1389 // This is initially called only from reposition and
1390 // and only for mapcenter. So it won't be
1391 // called more than once for a single user
1395 // Calculate size of LMO including all childs (to align them later)
1396 bboxTotal.setX(bbox.x() );
1397 bboxTotal.setY(bbox.y() );
1399 // if branch is scrolled, ignore childs, but still consider floatimages
1402 bboxTotal.setWidth (bbox.width());
1403 bboxTotal.setHeight(bbox.height());
1409 bboxTotal.setWidth (0);
1410 bboxTotal.setHeight(0);
1413 bboxTotal.setX (parObj->x());
1414 bboxTotal.setY (parObj->y());
1417 bboxTotal.setX (bbox.x());
1418 bboxTotal.setY (bbox.y());
1425 // Now calculate recursivly
1427 // maximum of widths
1429 for (int i=0; i<branch.size(); ++i)
1431 if (!branch.at(i)->isHidden())
1433 branch.at(i)->calcBBoxSizeWithChilds();
1434 br=branch.at(i)->getBBoxSizeWithChilds();
1435 r.setWidth( max (br.width(), r.width() ));
1436 r.setHeight(br.height() + r.height() );
1437 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1440 // Add myself and also
1441 // add width of link to sum if necessary
1442 if (branch.isEmpty())
1443 bboxTotal.setWidth (bbox.width() + r.width() );
1445 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1447 bboxTotal.setHeight(max (r.height(), bbox.height()));
1450 void BranchObj::select()
1452 // set Text in Editor
1453 textEditor->setText(note.getNote() );
1454 QString fnh=note.getFilenameHint();
1456 textEditor->setFilenameHint(note.getFilenameHint() );
1458 textEditor->setFilenameHint(getHeading() );
1459 textEditor->setFontHint (note.getFontHint() );
1460 isNoteInEditor=true;
1462 LinkableMapObj::select();
1463 // Tell parent that I am selected now:
1464 BranchObj* po=(BranchObj*)(parObj);
1465 if (po) // TODO Try to get rid of this cast...
1466 po->setLastSelectedBranch(this);
1468 // temporary unscroll, if we have scrolled parents somewhere
1469 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1471 // Show URL and link in statusbar
1473 if (!url.isEmpty()) status+="URL: "+url+" ";
1474 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1475 if (!status.isEmpty()) mainWindow->statusMessage (status);
1478 updateFlagsToolbar();
1481 mapEditor->updateActions();
1484 void BranchObj::unselect()
1486 LinkableMapObj::unselect();
1487 // Delete any messages like vymLink in StatusBar
1488 mainWindow->statusMessage ("");
1490 // Save current note
1491 if (isNoteInEditor) getNoteFromTextEditor();
1492 isNoteInEditor=false;
1494 // reset temporary unscroll, if we have scrolled parents somewhere
1495 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1497 // Erase content of editor
1498 textEditor->setInactive();
1500 // unselect all buttons in toolbar
1501 standardFlagsDefault->updateToolbar();
1504 QString BranchObj::getSelectString()
1510 s= "bo:" + QString("%1").arg(getNum());
1512 s= ((BranchObj*)(parObj))->getSelectString() + ",bo:" + QString("%1").arg(getNum());