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 BranchObj::BranchObj () :OrnamentedObj()
21 // cout << "Const BranchObj ()\n";
27 BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s)
29 // cout << "Const BranchObj (s) called from MapCenterObj (s)\n";
34 BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)
36 // cout << "Const BranchObj (s,p)\n";
39 depth=p->getDepth()+1;
41 // Calc angle to mapCenter if I am a mainbranch
42 // needed for reordering the mainbranches clockwise
44 angle=getAngle (QPointF (x() - parObj->getChildPos().x() ,
45 (y() - parObj->getChildPos().y() ) ) );
49 BranchObj::~BranchObj ()
51 // cout << "Destr BranchObj of "<<this<<endl;
52 // Check, if this branch was the last child to be deleted
53 // If so, unset the scrolled flags
55 BranchObj *po=(BranchObj*)(parObj);
59 bo=((BranchObj*)(parObj))->getLastBranch();
60 if (!bo) po->unScroll();
65 bool BranchObj::operator< ( const BranchObj & other )
67 return angle < other.angle;
70 bool BranchObj::operator== ( const BranchObj & other )
72 return angle == other.angle;
75 void BranchObj::init ()
80 absPos+=parObj->getChildPos();
90 includeImagesVer=false;
91 includeImagesHor=false;
94 void BranchObj::copy (BranchObj* other)
96 OrnamentedObj::copy(other);
99 for (int i=0; i<other->branch.size(); ++i)
100 // Make deep copy of b
101 // Because addBranch again calls copy for the childs,
102 // Those will get a deep copy, too
103 addBranch(other->branch.at(i) );
105 for (int i=0; i<other->floatimage.size(); ++i)
106 addFloatImage (other->floatimage.at(i));
107 scrolled=other->scrolled;
108 tmpUnscrolled=other->tmpUnscrolled;
109 setVisibility (other->visible);
116 void BranchObj::clear()
118 while (!floatimage.isEmpty())
119 delete floatimage.takeFirst();
121 while (!xlink.isEmpty())
122 delete xlink.takeFirst();
124 while (!branch.isEmpty())
125 delete branch.takeFirst();
128 bool isAbove (BranchObj* a, BranchObj *b)
130 if (a->angle < b->angle)
136 int BranchObj::getNum()
139 return ((BranchObj*)parObj)->getNum (this);
144 int BranchObj::getNum(BranchObj *bo)
146 return branch.indexOf (bo);
149 int BranchObj::getFloatImageNum(FloatImageObj *fio)
151 return floatimage.indexOf(fio);
154 int BranchObj::countBranches()
156 return branch.count();
159 int BranchObj::countFloatImages()
161 return floatimage.count();
164 int BranchObj::countXLinks()
166 return xlink.count();
169 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
171 // Temporary link to lmo
172 // m is position of mouse pointer
173 // offset 0: default 1: below lmo -1 above lmo (if possible)
176 BranchObj* o=(BranchObj*)(lmo);
180 // ignore mapcenter and mainbranch
181 if (lmo->getDepth()<2) off=0;
188 depth=parObj->getDepth()+1;
190 // setLinkStyle calls updateLink, only set it once
191 if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
193 // Move temporary to new position at destination
194 // Usually the positioning would be done by reposition(),
195 // but then also the destination branch would "Jump" around...
196 // Better just do it approximately
198 { // new parent is the mapcenter itself
200 QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
201 m.y() - o->getChildPos().y() ));
202 if (p.x()<0) p.setX( p.x()-bbox.width() );
209 // new parent is just a branch, link to it
210 QRectF t=o->getBBoxSizeWithChilds();
211 if (o->getLastBranch())
212 y=t.y() + t.height() ;
219 // we want to link above lmo
220 y=o->y() - height() + 5;
222 // we want to link below lmo
223 // Bottom of sel should be 5 pixels above
224 // the bottom of the branch _below_ the target:
225 // Don't try to find that branch, guess 12 pixels
226 y=o->getChildPos().y() -height() + 12;
228 if (o->getOrientation()==OrientLeftOfCenter)
229 move ( o->getChildPos().x() - linkwidth, y );
231 move (o->getChildPos().x() + linkwidth, y );
234 // updateLink is called implicitly in move
238 void BranchObj::unsetParObjTmp()
245 depth=parObj->getDepth()+1;
246 setLinkStyle (getDefLinkStyle() );
251 void BranchObj::unScroll()
253 if (tmpUnscrolled) resetTmpUnscroll();
254 if (scrolled) toggleScroll();
257 void BranchObj::toggleScroll()
262 systemFlags->deactivate("scrolledright");
263 for (int i=0; i<branch.size(); ++i)
264 branch.at(i)->setVisibility(true);
268 systemFlags->activate("scrolledright");
269 for (int i=0; i<branch.size(); ++i)
270 branch.at(i)->setVisibility(false);
274 move (absPos.x(), absPos.y() );
278 bool BranchObj::isScrolled()
283 bool BranchObj::hasScrolledParent(BranchObj *start)
285 // Calls parents recursivly to
286 // find out, if we are scrolled at all.
287 // But ignore myself, just look at parents.
289 if (this !=start && scrolled) return true;
291 BranchObj* bo=(BranchObj*)(parObj);
293 return bo->hasScrolledParent(start);
298 void BranchObj::tmpUnscroll()
300 // Unscroll parent (recursivly)
301 BranchObj* bo=(BranchObj*)(parObj);
302 if (bo) bo->tmpUnscroll();
308 systemFlags->activate("tmpUnscrolledright");
313 void BranchObj::resetTmpUnscroll()
315 // Unscroll parent (recursivly)
316 BranchObj* bo=(BranchObj*)(parObj);
318 bo->resetTmpUnscroll();
324 systemFlags->deactivate("tmpUnscrolledright");
329 void BranchObj::setVisibility(bool v, int toDepth)
331 if (depth <= toDepth)
333 frame->setVisibility(v);
334 heading->setVisibility(v);
335 systemFlags->setVisibility(v);
336 standardFlags->setVisibility(v);
337 LinkableMapObj::setVisibility (v);
339 // Only change childs, if I am not scrolled
340 if (!scrolled && (depth < toDepth))
342 // Now go recursivly through all childs
344 for (i=0; i<branch.size(); ++i)
345 branch.at(i)->setVisibility (v,toDepth);
346 for (i=0; i<floatimage.size(); ++i)
347 floatimage.at(i)->setVisibility (v);
348 for (i=0; i<xlink.size(); ++i)
349 xlink.at(i)->setVisibility ();
351 } // depth <= toDepth
355 void BranchObj::setVisibility(bool v)
357 setVisibility (v,MAX_DEPTH);
361 void BranchObj::setLinkColor ()
363 // Overloaded from LinkableMapObj
364 // BranchObj can use color of heading
367 if (mapEditor->getMapLinkColorHint()==HeadingColor)
368 LinkableMapObj::setLinkColor (heading->getColor() );
370 LinkableMapObj::setLinkColor ();
373 void BranchObj::setColorSubtree(QColor col)
375 OrnamentedObj::setColor (col);
376 for (int i=0; i<branch.size(); ++i)
377 branch.at(i)->setColorSubtree(col);
380 BranchObj* BranchObj::first()
387 BranchObj* BranchObj::next()
391 BranchObj *po=(BranchObj*)parObj;
393 if (branch.isEmpty())
400 // no itLast, we are just beginning
403 // we have childs, return first one
409 // No childs, so there is no next
417 { // We come from parent
420 // there are childs, go there
425 { // no childs, try to go up again
428 // go back to parent and try to find next there
437 // can't go up, I am mapCenter, no next
444 // We don't come from parent, but from brother or childs
446 // Try to find last child, where we came from, in my own childs
449 while (i<branch.size())
451 // Try to find itLast in my own childs
452 if (itLast==branch.at(i))
454 // ok, we come from my own childs
455 if (i<branch.size()-1)
465 { // found itLast in my childs
468 // found a brother of lastLMO
476 if (this==itFirst) return NULL; // Stop at starting point
485 // can't go up, I am mapCenter
492 // couldn't find last child, it must be a nephew of mine
495 // proceed with my first child
497 return branch.first();
501 // or go back to my parents
512 // can't go up, I am mapCenter
519 BranchObj* BranchObj::getLastIterator()
524 void BranchObj::setLastIterator(BranchObj* it)
529 void BranchObj::positionContents()
531 for (int i=0; i<floatimage.size(); ++i )
532 floatimage.at(i)->reposition();
533 OrnamentedObj::positionContents();
536 void BranchObj::move (double x, double y)
538 OrnamentedObj::move (x,y);
539 for (int i=0; i<floatimage.size(); ++i )
540 floatimage.at(i)->reposition();
544 void BranchObj::move (QPointF p)
549 void BranchObj::moveBy (double x, double y)
551 OrnamentedObj::moveBy (x,y);
552 for (int i=0; i<branch.size(); ++i)
553 branch.at(i)->moveBy (x,y);
557 void BranchObj::moveBy (QPointF p)
559 moveBy (p.x(), p.y());
563 void BranchObj::positionBBox()
565 QPointF ap=getAbsPos();
566 bbox.moveTopLeft (ap);
571 frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
573 // Update links to other branches
574 for (int i=0; i<xlink.size(); ++i)
575 xlink.at(i)->updateXLink();
578 void BranchObj::calcBBoxSize()
580 QSizeF heading_r=heading->getSize();
581 qreal heading_w=(qreal) heading_r.width() ;
582 qreal heading_h=(qreal) heading_r.height() ;
583 QSizeF sysflags_r=systemFlags->getSize();
584 qreal sysflags_h=sysflags_r.height();
585 qreal sysflags_w=sysflags_r.width();
586 QSizeF stanflags_r=standardFlags->getSize();
587 qreal stanflags_h=stanflags_r.height();
588 qreal stanflags_w=stanflags_r.width();
592 // set width to sum of all widths
593 w=heading_w + sysflags_w + stanflags_w;
594 // set height to maximum needed height
595 h=max (sysflags_h,stanflags_h);
598 // Save the dimension of flags and heading
599 ornamentsBBox.setSize ( QSizeF(w,h));
601 // clickBox includes Flags and Heading
602 clickBox.setSize (ornamentsBBox.size() );
607 topPad=botPad=leftPad=rightPad=0;
608 if (includeImagesVer || includeImagesHor)
610 if (countFloatImages()>0)
612 for (int i=0; i<floatimage.size(); ++i )
614 rp=floatimage.at(i)->getRelPos();
615 if (includeImagesVer)
618 topPad=max (topPad,-rp.y()-h);
619 if (rp.y()+floatimage.at(i)->height() > 0)
620 botPad=max (botPad,rp.y()+floatimage.at(i)->height());
622 if (includeImagesHor)
624 if (orientation==OrientRightOfCenter)
627 leftPad=max (leftPad,-rp.x()-w);
628 if (rp.x()+floatimage.at(i)->width() > 0)
629 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
633 leftPad=max (leftPad,-rp.x());
634 if (rp.x()+floatimage.at(i)->width() > w)
635 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
645 w+=frame->getBorder();
646 h+=frame->getBorder();
649 bbox.setSize (QSizeF (w,h));
652 void BranchObj::setDockPos()
654 // Sets childpos and parpos depending on orientation
655 if (getOrientation()==OrientLeftOfCenter )
657 childPos=QPointF (ornamentsBBox.bottomLeft().x(), ornamentsBBox.bottomLeft().y() );
658 parPos=QPointF (ornamentsBBox.bottomRight().x(),ornamentsBBox.bottomRight().y() );
661 childPos=QPointF (ornamentsBBox.bottomRight().x(), ornamentsBBox.bottomRight().y() );
662 parPos=QPointF (ornamentsBBox.bottomLeft().x(),ornamentsBBox.bottomLeft().y() );
666 LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
670 for (int i=0; i<branch.size(); ++i)
672 lmo=branch.at(i)->findMapObj(p, excludeLMO);
673 if (lmo != NULL) return lmo;
677 if (inBox (p) && (this != excludeLMO) && isVisibleObj() )
680 // Search float images
681 for (int i=0; i<floatimage.size(); ++i )
682 if (floatimage.at(i)->inBox(p) &&
683 (floatimage.at(i) != excludeLMO) &&
684 floatimage.at(i)->getParObj()!= excludeLMO &&
685 floatimage.at(i)->isVisibleObj()
686 ) return floatimage.at(i);
691 void BranchObj::setHeading(QString s)
693 heading->setText(s); // set new heading
694 calcBBoxSize(); // recalculate bbox
695 positionBBox(); // rearrange contents
699 void BranchObj::setHideTmp (HideTmpMode mode)
701 if (mode==HideExport && hasHiddenExportParent(this))
703 setVisibility (false);
707 if (hasScrolledParent(this))
708 setVisibility (false);
710 setVisibility (true);
714 for (int i=0; i<branch.size(); ++i)
715 branch.at(i)->setHideTmp (mode);
718 bool BranchObj::hasHiddenExportParent(BranchObj *start)
720 // Calls parents recursivly to
721 // find out, if we are temp. hidden
723 if (hideExport) return true;
725 BranchObj* bo=(BranchObj*)(parObj);
727 return bo->hasHiddenExportParent(start);
732 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
734 // Cloudy stuff can be hidden during exports
735 if (hidden) return "";
737 // Update of note is usually done while unselecting a branch
738 if (isNoteInEditor) getNoteFromTextEditor();
741 QString scrolledAttr;
743 scrolledAttr=attribut ("scrolled","yes");
748 if (frame->getFrameType()!=NoFrame)
749 frameAttr=attribut ("frameType",frame->getFrameTypeName());
753 // save area, if not scrolled
755 if (!((BranchObj*)(parObj))->isScrolled() )
758 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
759 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
760 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
761 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
766 // Providing an ID for a branch makes export to XHTML easier
769 idAttr=attribut ("id",getSelectString());
773 s=beginElement ("branch"
779 +getIncludeImageAttr() );
783 for (int i=1; i<depth;i++) cout << " ";
784 cout <<getHeading().ascii()<<endl;
788 s+=valueElement("heading", getHeading(),
789 attribut ("textColor",QColor(heading->getColor()).name()));
791 // save names of flags set
792 s+=standardFlags->saveToDir(tmpdir,prefix,0);
795 for (int i=0; i<floatimage.size(); ++i)
796 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
799 if (!note.isEmpty() )
803 for (int i=0; i<branch.size(); ++i)
804 s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
807 QString ol; // old link
808 QString cl; // current link
809 for (int i=0; i<xlink.size(); ++i)
811 cl=xlink.at(i)->saveToDir();
818 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
823 s+=endElement ("branch");
827 void BranchObj::addXLink (XLinkObj *xlo)
833 void BranchObj::removeXLinkRef (XLinkObj *xlo)
835 xlink.removeAt (xlink.indexOf(xlo));
838 void BranchObj::deleteXLink(XLinkObj *xlo)
841 if (!xlo->isUsed()) delete (xlo);
844 void BranchObj::deleteXLinkAt (int i)
846 XLinkObj *xlo=xlink.at(i);
848 if (!xlo->isUsed()) delete(xlo);
851 XLinkObj* BranchObj::XLinkAt (int i)
856 int BranchObj::countXLink()
858 return xlink.count();
862 BranchObj* BranchObj::XLinkTargetAt (int i)
864 if (i>=0 && i<xlink.size())
867 return xlink.at(i)->otherBranch (this);
872 void BranchObj::setIncludeImagesVer(bool b)
880 bool BranchObj::getIncludeImagesVer()
882 return includeImagesVer;
885 void BranchObj::setIncludeImagesHor(bool b)
893 bool BranchObj::getIncludeImagesHor()
895 return includeImagesHor;
898 QString BranchObj::getIncludeImageAttr()
901 if (includeImagesVer)
902 a=attribut ("incImgV","true");
904 a=attribut ("incImgV","false");
905 if (includeImagesHor)
906 a+=attribut ("incImgH","true");
908 a+=attribut ("incImgH","false");
912 FloatImageObj* BranchObj::addFloatImage ()
914 FloatImageObj *newfi=new FloatImageObj (scene,this);
915 floatimage.append (newfi);
916 if (hasScrolledParent(this) )
917 newfi->setVisibility (false);
919 newfi->setVisibility(visible);
928 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
930 FloatImageObj *newfi=new FloatImageObj (scene,this);
931 floatimage.append (newfi);
933 if (hasScrolledParent(this) )
934 newfi->setVisibility (false);
936 newfi->setVisibility(visible);
945 FloatImageObj* BranchObj::getFirstFloatImage ()
947 return floatimage.first();
950 FloatImageObj* BranchObj::getLastFloatImage ()
952 return floatimage.last();
955 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
957 return floatimage.at(i);
960 void BranchObj::removeFloatImage (FloatImageObj *fio)
962 int i=floatimage.indexOf (fio);
963 if (i>-1) delete (floatimage.takeAt (i));
969 void BranchObj::savePosInAngle ()
971 // Save position in angle
972 for (int i=0; i<branch.size(); ++i)
973 branch.at(i)->angle=i;
976 void BranchObj::setDefAttr (BranchModification mod)
981 case 0: fontsize=16; break;
982 case 1: fontsize=12; break;
983 default: fontsize=10; break;
987 setLinkStyle(getDefLinkStyle());
988 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
989 font.setPointSize(fontsize);
990 heading->setFont(font );
993 setColor (((BranchObj*)(parObj))->getColor());
998 BranchObj* BranchObj::addBranch()
1000 BranchObj* newbo=new BranchObj(scene,this);
1001 branch.append (newbo);
1002 newbo->setParObj(this);
1003 newbo->setDefAttr(NewBranch);
1004 newbo->setHeading ("new");
1006 newbo->setVisibility (false);
1008 newbo->setVisibility(visible);
1009 newbo->updateLink();
1010 requestReposition();
1014 BranchObj* BranchObj::addBranch(BranchObj* bo)
1016 BranchObj* newbo=new BranchObj(scene,this);
1017 branch.append (newbo);
1019 newbo->setParObj(this);
1020 newbo->setDefAttr(MovedBranch);
1022 newbo->setVisibility (false);
1024 newbo->setVisibility(bo->visible);
1025 newbo->updateLink();
1026 requestReposition();
1030 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
1033 bo->setParObj (this);
1035 bo->setDefAttr(MovedBranch);
1036 if (scrolled) tmpUnscroll();
1037 setLastSelectedBranch (bo);
1041 BranchObj* BranchObj::insertBranch(int pos)
1044 // Add new bo and resort branches
1045 BranchObj *newbo=addBranch ();
1046 newbo->angle=pos-0.5;
1047 qSort (branch.begin(),branch.end(), isAbove);
1051 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
1054 // Add new bo and resort branches
1056 BranchObj *newbo=addBranch (bo);
1057 qSort (branch.begin(),branch.end(), isAbove);
1061 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
1064 // Add new bo and resort branches
1067 bo->setParObj (this);
1069 bo->setDefAttr (MovedBranch);
1070 if (scrolled) tmpUnscroll();
1071 setLastSelectedBranch (bo);
1072 qSort (branch.begin(),branch.end(), isAbove);
1076 void BranchObj::removeBranchHere(BranchObj* borem)
1078 // This removes the branch bo from list, but
1079 // inserts its childs at the place of bo
1081 bo=borem->getLastBranch();
1082 int pos=borem->getNum();
1085 bo->moveBranchTo (this,pos+1);
1086 bo=borem->getLastBranch();
1088 removeBranch (borem);
1091 void BranchObj::removeChilds()
1096 void BranchObj::removeBranch(BranchObj* bo)
1098 // if bo is not in branch remove returns false, we
1101 int i=branch.indexOf(bo);
1105 branch.removeAt (i);
1107 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
1108 requestReposition();
1111 void BranchObj::removeBranchPtr(BranchObj* bo)
1113 int i=branch.indexOf(bo);
1116 branch.removeAt (i);
1118 qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
1119 requestReposition();
1122 void BranchObj::setLastSelectedBranch (BranchObj* bo)
1124 lastSelectedBranch=branch.indexOf(bo);
1127 BranchObj* BranchObj::getLastSelectedBranch ()
1129 if (lastSelectedBranch>=0)
1131 if ( branch.size()>lastSelectedBranch)
1132 return branch.at(lastSelectedBranch);
1133 if (branch.size()>0)
1134 return branch.last();
1139 BranchObj* BranchObj::getFirstBranch ()
1141 if (branch.size()>0)
1142 return branch.first();
1147 BranchObj* BranchObj::getLastBranch ()
1149 if (branch.size()>0)
1150 return branch.last();
1155 BranchObj* BranchObj::getBranchNum (int i)
1157 if (i>=0 && i<branch.size())
1158 return branch.at(i);
1163 bool BranchObj::canMoveBranchUp()
1165 if (!parObj || depth==1) return false;
1166 BranchObj* par=(BranchObj*)parObj;
1167 if (this==par->getFirstBranch())
1173 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
1176 int i=branch.indexOf(bo1);
1178 { // -1 if bo1 not found
1179 branch.at(i)->angle--;
1180 branch.at(i-1)->angle++;
1181 qSort (branch.begin(),branch.end(), isAbove);
1182 return branch.at(i);
1187 bool BranchObj::canMoveBranchDown()
1189 if (!parObj|| depth==1) return false;
1190 BranchObj* par=(BranchObj*)parObj;
1191 if (this==par->getLastBranch())
1197 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
1200 int i=branch.indexOf(bo1);
1202 if (i <branch.size())
1205 branch.at(i)->angle++;
1206 branch.at(j)->angle--;
1207 qSort (branch.begin(),branch.end(), isAbove);
1208 return branch.at(i);
1213 BranchObj* BranchObj::moveBranchTo (BranchObj* dst, int pos)
1215 // Find current parent and
1216 // remove pointer to myself there
1217 if (!dst) return NULL;
1218 BranchObj *par=(BranchObj*)parObj;
1220 par->removeBranchPtr (this);
1224 // Create new pointer to myself at dst
1225 if (pos<0||dst->getDepth()==0)
1227 // links myself as last branch at dst
1228 dst->addBranchPtr (this);
1233 // inserts me at pos in parent of dst
1236 BranchObj *bo=dst->insertBranchPtr (this,pos);
1237 bo->setDefAttr(MovedBranch);
1246 void BranchObj::alignRelativeTo (QPointF ref)
1248 qreal th = bboxTotal.height();
1251 cout << "BO::alignRelTo "<<getHeading().ascii()<<endl;
1252 cout << " d="<<depth<<
1254 // " bbox.topLeft="<<bboxTotal.topLeft()<<
1255 " absPos="<<absPos<<
1256 " relPos="<<relPos<<
1257 " orient="<<orientation<<
1258 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
1259 // " hidden="<<hidden<<
1271 // Position relatively, if needed
1272 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
1274 // Calc angle to mapCenter if I am a mainbranch
1275 // needed for reordering the mainbranches clockwise
1277 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
1278 (int)(y() - parObj->getChildPos().y() ) ) );
1283 // Align myself depending on orientation and parent, but
1284 // only if I am not a mainbranch or mapcenter itself
1286 o=parObj->getOrientation();
1287 switch (orientation)
1289 case OrientLeftOfCenter:
1290 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1292 case OrientRightOfCenter:
1293 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1296 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1301 if (scrolled) return;
1303 // Set reference point for alignment of childs
1305 if (orientation==OrientLeftOfCenter)
1306 ref2.setX(bbox.topLeft().x() - linkwidth);
1308 ref2.setX(bbox.topRight().x() + linkwidth);
1311 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1313 ref2.setY(ref.y() );
1315 // Align the childs depending on reference point
1316 for (int i=0; i<branch.size(); ++i)
1318 if (!branch.at(i)->isHidden())
1320 branch.at(i)->alignRelativeTo (ref2);
1321 ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChilds().height() );
1327 void BranchObj::reposition()
1329 /* TODO testing only
1330 if (!getHeading().isEmpty())
1331 cout << "BO::reposition "<<getHeading().ascii()<<endl;
1333 cout << "BO::reposition ???"<<endl;
1335 cout << " orient="<<orientation<<endl;
1340 // only calculate the sizes once. If the deepest LMO
1341 // changes its height,
1342 // all upper LMOs have to change, too.
1343 calcBBoxSizeWithChilds();
1344 updateLink(); // This update is needed if the scene is resized
1345 // due to excessive moving of a FIO
1347 alignRelativeTo ( QPointF (absPos.x(),
1348 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1349 qSort (branch.begin(),branch.end(), isAbove);
1350 positionBBox(); // Reposition bbox and contents
1353 // This is only important for moving branches:
1354 // For editing a branch it isn't called...
1355 alignRelativeTo ( QPointF (absPos.x(),
1356 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1360 void BranchObj::unsetAllRepositionRequests()
1362 repositionRequest=false;
1363 for (int i=0; i<branch.size(); ++i)
1364 branch.at(i)->unsetAllRepositionRequests();
1368 QRectF BranchObj::getTotalBBox()
1372 if (scrolled) return r;
1374 for (int i=0; i<branch.size(); ++i)
1375 if (!branch.at(i)->isHidden())
1376 r=addBBox(branch.at(i)->getTotalBBox(),r);
1378 for (int i=0; i<floatimage.size(); ++i)
1379 if (!floatimage.at(i)->isHidden())
1380 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1385 QRectF BranchObj::getBBoxSizeWithChilds()
1390 void BranchObj::calcBBoxSizeWithChilds()
1392 // This is initially called only from reposition and
1393 // and only for mapcenter. So it won't be
1394 // called more than once for a single user
1398 // Calculate size of LMO including all childs (to align them later)
1399 bboxTotal.setX(bbox.x() );
1400 bboxTotal.setY(bbox.y() );
1402 // if branch is scrolled, ignore childs, but still consider floatimages
1405 bboxTotal.setWidth (bbox.width());
1406 bboxTotal.setHeight(bbox.height());
1412 bboxTotal.setWidth (0);
1413 bboxTotal.setHeight(0);
1416 bboxTotal.setX (parObj->x());
1417 bboxTotal.setY (parObj->y());
1420 bboxTotal.setX (bbox.x());
1421 bboxTotal.setY (bbox.y());
1428 // Now calculate recursivly
1430 // maximum of widths
1432 for (int i=0; i<branch.size(); ++i)
1434 if (!branch.at(i)->isHidden())
1436 branch.at(i)->calcBBoxSizeWithChilds();
1437 br=branch.at(i)->getBBoxSizeWithChilds();
1438 r.setWidth( max (br.width(), r.width() ));
1439 r.setHeight(br.height() + r.height() );
1440 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1443 // Add myself and also
1444 // add width of link to sum if necessary
1445 if (branch.isEmpty())
1446 bboxTotal.setWidth (bbox.width() + r.width() );
1448 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1450 bboxTotal.setHeight(max (r.height(), bbox.height()));
1453 void BranchObj::select()
1455 // set Text in Editor
1456 textEditor->setText(note.getNote() );
1457 QString fnh=note.getFilenameHint();
1459 textEditor->setFilenameHint(note.getFilenameHint() );
1461 textEditor->setFilenameHint(getHeading() );
1462 textEditor->setFontHint (note.getFontHint() );
1463 isNoteInEditor=true;
1465 LinkableMapObj::select();
1466 // Tell parent that I am selected now:
1467 BranchObj* po=(BranchObj*)(parObj);
1468 if (po) // TODO Try to get rid of this cast...
1469 po->setLastSelectedBranch(this);
1471 // temporary unscroll, if we have scrolled parents somewhere
1472 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1474 // Show URL and link in statusbar
1476 if (!url.isEmpty()) status+="URL: "+url+" ";
1477 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1478 if (!status.isEmpty()) mainWindow->statusMessage (status);
1481 updateFlagsToolbar();
1484 mapEditor->updateActions();
1487 void BranchObj::unselect()
1489 LinkableMapObj::unselect();
1490 // Delete any messages like vymLink in StatusBar
1491 mainWindow->statusMessage ("");
1493 // Save current note
1494 if (isNoteInEditor) getNoteFromTextEditor();
1495 isNoteInEditor=false;
1497 // reset temporary unscroll, if we have scrolled parents somewhere
1498 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1500 // Erase content of editor
1501 textEditor->setInactive();
1503 // unselect all buttons in toolbar
1504 standardFlagsDefault->updateToolbar();
1507 QString BranchObj::getSelectString()
1513 s= "bo:" + QString("%1").arg(getNum());
1515 s= ((BranchObj*)(parObj))->getSelectString() + ",bo:" + QString("%1").arg(getNum());