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);
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==OrientRightOfCenter)
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->getBorder();
653 h+=frame->getBorder();
656 bbox.setSize (QSizeF (w,h));
659 void BranchObj::setDockPos()
661 // Sets childpos and parpos depending on orientation
662 if (getOrientation()==OrientLeftOfCenter )
664 childPos=QPointF (ornamentsBBox.bottomLeft().x(), ornamentsBBox.bottomLeft().y() );
665 parPos=QPointF (ornamentsBBox.bottomRight().x(),ornamentsBBox.bottomRight().y() );
668 childPos=QPointF (ornamentsBBox.bottomRight().x(), ornamentsBBox.bottomRight().y() );
669 parPos=QPointF (ornamentsBBox.bottomLeft().x(),ornamentsBBox.bottomLeft().y() );
673 LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
677 for (int i=0; i<branch.size(); ++i)
679 lmo=branch.at(i)->findMapObj(p, excludeLMO);
680 if (lmo != NULL) return lmo;
684 if (inBox (p) && (this != excludeLMO) && isVisibleObj() )
687 // Search float images
688 for (int i=0; i<floatimage.size(); ++i )
689 if (floatimage.at(i)->inBox(p) &&
690 (floatimage.at(i) != excludeLMO) &&
691 floatimage.at(i)->getParObj()!= excludeLMO &&
692 floatimage.at(i)->isVisibleObj()
693 ) return floatimage.at(i);
698 void BranchObj::setHeading(QString s)
700 heading->setText(s); // set new heading
701 calcBBoxSize(); // recalculate bbox
702 positionBBox(); // rearrange contents
706 void BranchObj::setHideTmp (HideTmpMode mode)
708 if (mode==HideExport && hasHiddenExportParent(this))
710 setVisibility (false);
714 if (hasScrolledParent(this))
715 setVisibility (false);
717 setVisibility (true);
721 for (int i=0; i<branch.size(); ++i)
722 branch.at(i)->setHideTmp (mode);
725 bool BranchObj::hasHiddenExportParent(BranchObj *start)
727 // Calls parents recursivly to
728 // find out, if we are temp. hidden
730 if (hideExport) return true;
732 BranchObj* bo=(BranchObj*)(parObj);
734 return bo->hasHiddenExportParent(start);
739 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
741 // Cloudy stuff can be hidden during exports
742 if (hidden) return "";
744 // Update of note is usually done while unselecting a branch
745 if (isNoteInEditor) getNoteFromTextEditor();
748 QString scrolledAttr;
750 scrolledAttr=attribut ("scrolled","yes");
754 // save area, if not scrolled
756 if (!((BranchObj*)(parObj))->isScrolled() )
759 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
760 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
761 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
762 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
767 // Providing an ID for a branch makes export to XHTML easier
770 idAttr=attribut ("id",getSelectString());
774 s=beginElement ("branch"
779 +getIncludeImageAttr() );
783 s+=valueElement("heading", getHeading(),
784 attribut ("textColor",QColor(heading->getColor()).name()));
787 if (frame->getFrameType()!=NoFrame)
788 s+=frame->saveToDir ();
790 // save names of flags set
791 s+=standardFlags->saveToDir(tmpdir,prefix,0);
794 for (int i=0; i<floatimage.size(); ++i)
795 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
798 if (!note.isEmpty() )
802 for (int i=0; i<branch.size(); ++i)
803 s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
806 QString ol; // old link
807 QString cl; // current link
808 for (int i=0; i<xlink.size(); ++i)
810 cl=xlink.at(i)->saveToDir();
817 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
822 s+=endElement ("branch");
826 void BranchObj::addXLink (XLinkObj *xlo)
832 void BranchObj::removeXLinkRef (XLinkObj *xlo)
834 xlink.removeAt (xlink.indexOf(xlo));
837 void BranchObj::deleteXLink(XLinkObj *xlo)
840 if (!xlo->isUsed()) delete (xlo);
843 void BranchObj::deleteXLinkAt (int i)
845 XLinkObj *xlo=xlink.at(i);
847 if (!xlo->isUsed()) delete(xlo);
850 XLinkObj* BranchObj::XLinkAt (int i)
855 int BranchObj::countXLink()
857 return xlink.count();
861 BranchObj* BranchObj::XLinkTargetAt (int i)
863 if (i>=0 && i<xlink.size())
866 return xlink.at(i)->otherBranch (this);
871 void BranchObj::setIncludeImagesVer(bool b)
879 bool BranchObj::getIncludeImagesVer()
881 return includeImagesVer;
884 void BranchObj::setIncludeImagesHor(bool b)
892 bool BranchObj::getIncludeImagesHor()
894 return includeImagesHor;
897 QString BranchObj::getIncludeImageAttr()
900 if (includeImagesVer)
901 a=attribut ("incImgV","true");
903 a=attribut ("incImgV","false");
904 if (includeImagesHor)
905 a+=attribut ("incImgH","true");
907 a+=attribut ("incImgH","false");
911 FloatImageObj* BranchObj::addFloatImage ()
913 FloatImageObj *newfi=new FloatImageObj (scene,this);
914 floatimage.append (newfi);
915 if (hasScrolledParent(this) )
916 newfi->setVisibility (false);
918 newfi->setVisibility(visible);
927 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
929 FloatImageObj *newfi=new FloatImageObj (scene,this);
930 floatimage.append (newfi);
932 if (hasScrolledParent(this) )
933 newfi->setVisibility (false);
935 newfi->setVisibility(visible);
944 FloatImageObj* BranchObj::getFirstFloatImage ()
946 return floatimage.first();
949 FloatImageObj* BranchObj::getLastFloatImage ()
951 return floatimage.last();
954 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
956 return floatimage.at(i);
959 void BranchObj::removeFloatImage (FloatImageObj *fio)
961 int i=floatimage.indexOf (fio);
962 if (i>-1) delete (floatimage.takeAt (i));
968 void BranchObj::savePosInAngle ()
970 // Save position in angle
971 for (int i=0; i<branch.size(); ++i)
972 branch.at(i)->angle=i;
975 void BranchObj::setDefAttr (BranchModification mod)
980 case 0: fontsize=16; break;
981 case 1: fontsize=12; break;
982 default: fontsize=10; break;
986 setLinkStyle(getDefLinkStyle());
987 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
988 font.setPointSize(fontsize);
989 heading->setFont(font );
992 setColor (((BranchObj*)(parObj))->getColor());
997 BranchObj* BranchObj::addBranch()
999 BranchObj* newbo=new BranchObj(scene,this);
1000 branch.append (newbo);
1001 newbo->setParObj(this);
1002 newbo->setDefAttr(NewBranch);
1003 newbo->setHeading ("new");
1005 newbo->setVisibility (false);
1007 newbo->setVisibility(visible);
1008 newbo->updateLink();
1009 requestReposition();
1013 BranchObj* BranchObj::addBranch(BranchObj* bo)
1015 BranchObj* newbo=new BranchObj(scene,this);
1016 branch.append (newbo);
1018 newbo->setParObj(this);
1019 newbo->setDefAttr(MovedBranch);
1021 newbo->setVisibility (false);
1023 newbo->setVisibility(bo->visible);
1024 newbo->updateLink();
1025 requestReposition();
1029 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
1032 bo->setParObj (this);
1034 bo->setDefAttr(MovedBranch);
1035 if (scrolled) tmpUnscroll();
1036 setLastSelectedBranch (bo);
1040 BranchObj* BranchObj::insertBranch(int pos)
1043 // Add new bo and resort branches
1044 BranchObj *newbo=addBranch ();
1045 newbo->angle=pos-0.5;
1046 qSort (branch.begin(),branch.end(), isAbove);
1050 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
1053 // Add new bo and resort branches
1055 BranchObj *newbo=addBranch (bo);
1056 qSort (branch.begin(),branch.end(), isAbove);
1060 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
1063 // Add new bo and resort branches
1066 bo->setParObj (this);
1068 bo->setDefAttr (MovedBranch);
1069 if (scrolled) tmpUnscroll();
1070 setLastSelectedBranch (bo);
1071 qSort (branch.begin(),branch.end(), isAbove);
1075 void BranchObj::removeBranchHere(BranchObj* borem)
1077 // This removes the branch bo from list, but
1078 // inserts its childs at the place of bo
1080 bo=borem->getLastBranch();
1081 int pos=borem->getNum();
1084 bo->linkTo (this,pos+1);
1085 bo=borem->getLastBranch();
1087 removeBranch (borem);
1090 void BranchObj::removeChilds()
1095 void BranchObj::removeBranch(BranchObj* bo)
1097 // if bo is not in branch remove returns false, we
1100 int i=branch.indexOf(bo);
1104 branch.removeAt (i);
1106 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
1107 requestReposition();
1110 void BranchObj::removeBranchPtr(BranchObj* bo)
1112 int i=branch.indexOf(bo);
1115 branch.removeAt (i);
1117 qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
1118 requestReposition();
1121 void BranchObj::setLastSelectedBranch (BranchObj* bo)
1123 lastSelectedBranch=branch.indexOf(bo);
1126 BranchObj* BranchObj::getLastSelectedBranch ()
1128 if (lastSelectedBranch>=0)
1130 if ( branch.size()>lastSelectedBranch)
1131 return branch.at(lastSelectedBranch);
1132 if (branch.size()>0)
1133 return branch.last();
1138 BranchObj* BranchObj::getFirstBranch ()
1140 if (branch.size()>0)
1141 return branch.first();
1146 BranchObj* BranchObj::getLastBranch ()
1148 if (branch.size()>0)
1149 return branch.last();
1154 BranchObj* BranchObj::getBranchNum (int i)
1156 if (i>=0 && i<branch.size())
1157 return branch.at(i);
1162 bool BranchObj::canMoveBranchUp()
1164 if (!parObj || depth==1) return false;
1165 BranchObj* par=(BranchObj*)parObj;
1166 if (this==par->getFirstBranch())
1172 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
1175 int i=branch.indexOf(bo1);
1177 { // -1 if bo1 not found
1178 branch.at(i)->angle--;
1179 branch.at(i-1)->angle++;
1180 qSort (branch.begin(),branch.end(), isAbove);
1181 return branch.at(i);
1186 bool BranchObj::canMoveBranchDown()
1188 if (!parObj|| depth==1) return false;
1189 BranchObj* par=(BranchObj*)parObj;
1190 if (this==par->getLastBranch())
1196 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
1199 int i=branch.indexOf(bo1);
1201 if (i <branch.size())
1204 branch.at(i)->angle++;
1205 branch.at(j)->angle--;
1206 qSort (branch.begin(),branch.end(), isAbove);
1207 return branch.at(i);
1212 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
1214 // Find current parent and
1215 // remove pointer to myself there
1216 if (!dst) return NULL;
1217 BranchObj *par=(BranchObj*)parObj;
1219 par->removeBranchPtr (this);
1223 // Create new pointer to myself at dst
1224 if (pos<0||dst->getDepth()==0)
1226 // links myself as last branch at dst
1227 dst->addBranchPtr (this);
1232 // inserts me at pos in parent of dst
1235 BranchObj *bo=dst->insertBranchPtr (this,pos);
1236 bo->setDefAttr(MovedBranch);
1245 void BranchObj::alignRelativeTo (QPointF ref)
1247 qreal th = bboxTotal.height();
1250 cout << "BO::alignRelTo "<<getHeading().ascii()<<endl;
1251 cout << " d="<<depth<<
1253 // " bbox.topLeft="<<bboxTotal.topLeft()<<
1254 " absPos="<<absPos<<
1255 " relPos="<<relPos<<
1256 " orient="<<orientation<<
1257 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
1258 // " hidden="<<hidden<<
1270 // Position relatively, if needed
1271 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
1273 // Calc angle to mapCenter if I am a mainbranch
1274 // needed for reordering the mainbranches clockwise
1276 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
1277 (int)(y() - parObj->getChildPos().y() ) ) );
1282 // Align myself depending on orientation and parent, but
1283 // only if I am not a mainbranch or mapcenter itself
1285 o=parObj->getOrientation();
1286 switch (orientation)
1288 case OrientLeftOfCenter:
1289 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1291 case OrientRightOfCenter:
1292 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1295 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1300 if (scrolled) return;
1302 // Set reference point for alignment of childs
1304 if (orientation==OrientLeftOfCenter)
1305 ref2.setX(bbox.topLeft().x() - linkwidth);
1307 ref2.setX(bbox.topRight().x() + linkwidth);
1310 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1312 ref2.setY(ref.y() );
1314 // Align the childs depending on reference point
1315 for (int i=0; i<branch.size(); ++i)
1317 if (!branch.at(i)->isHidden())
1319 branch.at(i)->alignRelativeTo (ref2);
1320 ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChilds().height() );
1326 void BranchObj::reposition()
1328 /* TODO testing only
1329 if (!getHeading().isEmpty())
1330 cout << "BO::reposition "<<getHeading().ascii()<<endl;
1332 cout << "BO::reposition ???"<<endl;
1334 cout << " orient="<<orientation<<endl;
1339 // only calculate the sizes once. If the deepest LMO
1340 // changes its height,
1341 // all upper LMOs have to change, too.
1342 calcBBoxSizeWithChilds();
1343 updateLink(); // This update is needed if the scene is resized
1344 // due to excessive moving of a FIO
1346 alignRelativeTo ( QPointF (absPos.x(),
1347 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1348 qSort (branch.begin(),branch.end(), isAbove);
1349 positionBBox(); // Reposition bbox and contents
1352 // This is only important for moving branches:
1353 // For editing a branch it isn't called...
1354 alignRelativeTo ( QPointF (absPos.x(),
1355 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1359 void BranchObj::unsetAllRepositionRequests()
1361 repositionRequest=false;
1362 for (int i=0; i<branch.size(); ++i)
1363 branch.at(i)->unsetAllRepositionRequests();
1367 QRectF BranchObj::getTotalBBox()
1371 if (scrolled) return r;
1373 for (int i=0; i<branch.size(); ++i)
1374 if (!branch.at(i)->isHidden())
1375 r=addBBox(branch.at(i)->getTotalBBox(),r);
1377 for (int i=0; i<floatimage.size(); ++i)
1378 if (!floatimage.at(i)->isHidden())
1379 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1384 QRectF BranchObj::getBBoxSizeWithChilds()
1389 void BranchObj::calcBBoxSizeWithChilds()
1391 // This is initially called only from reposition and
1392 // and only for mapcenter. So it won't be
1393 // called more than once for a single user
1397 // Calculate size of LMO including all childs (to align them later)
1398 bboxTotal.setX(bbox.x() );
1399 bboxTotal.setY(bbox.y() );
1401 // if branch is scrolled, ignore childs, but still consider floatimages
1404 bboxTotal.setWidth (bbox.width());
1405 bboxTotal.setHeight(bbox.height());
1411 bboxTotal.setWidth (0);
1412 bboxTotal.setHeight(0);
1415 bboxTotal.setX (parObj->x());
1416 bboxTotal.setY (parObj->y());
1419 bboxTotal.setX (bbox.x());
1420 bboxTotal.setY (bbox.y());
1427 // Now calculate recursivly
1429 // maximum of widths
1431 for (int i=0; i<branch.size(); ++i)
1433 if (!branch.at(i)->isHidden())
1435 branch.at(i)->calcBBoxSizeWithChilds();
1436 br=branch.at(i)->getBBoxSizeWithChilds();
1437 r.setWidth( max (br.width(), r.width() ));
1438 r.setHeight(br.height() + r.height() );
1439 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1442 // Add myself and also
1443 // add width of link to sum if necessary
1444 if (branch.isEmpty())
1445 bboxTotal.setWidth (bbox.width() + r.width() );
1447 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1449 bboxTotal.setHeight(max (r.height(), bbox.height()));
1452 void BranchObj::select()
1454 // set Text in Editor
1455 textEditor->setText(note.getNote() );
1456 QString fnh=note.getFilenameHint();
1458 textEditor->setFilenameHint(note.getFilenameHint() );
1460 textEditor->setFilenameHint(getHeading() );
1461 textEditor->setFontHint (note.getFontHint() );
1462 isNoteInEditor=true;
1464 LinkableMapObj::select();
1465 // Tell parent that I am selected now:
1466 BranchObj* po=(BranchObj*)(parObj);
1467 if (po) // TODO Try to get rid of this cast...
1468 po->setLastSelectedBranch(this);
1470 // temporary unscroll, if we have scrolled parents somewhere
1471 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1473 // Show URL and link in statusbar
1475 if (!url.isEmpty()) status+="URL: "+url+" ";
1476 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1477 if (!status.isEmpty()) mainWindow->statusMessage (status);
1480 updateFlagsToolbar();
1483 mapEditor->updateActions();
1486 void BranchObj::unselect()
1488 LinkableMapObj::unselect();
1489 // Delete any messages like vymLink in StatusBar
1490 mainWindow->statusMessage ("");
1492 // Save current note
1493 if (isNoteInEditor) getNoteFromTextEditor();
1494 isNoteInEditor=false;
1496 // reset temporary unscroll, if we have scrolled parents somewhere
1497 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1499 // Erase content of editor
1500 textEditor->setInactive();
1502 // unselect all buttons in toolbar
1503 standardFlagsDefault->updateToolbar();
1506 QString BranchObj::getSelectString()
1512 s= "bo:" + QString("%1").arg(getNum());
1514 s= ((BranchObj*)(parObj))->getSelectString() + ",bo:" + QString("%1").arg(getNum());