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 setVisibility (true);
120 while (!floatimage.isEmpty())
121 delete floatimage.takeFirst();
123 while (!xlink.isEmpty())
124 delete xlink.takeFirst();
126 while (!branch.isEmpty())
127 delete branch.takeFirst();
130 bool isAbove (BranchObj* a, BranchObj *b)
132 if (a->angle < b->angle)
138 int BranchObj::getNum()
141 return ((BranchObj*)parObj)->getNum (this);
146 int BranchObj::getNum(BranchObj *bo)
148 return branch.indexOf (bo);
151 int BranchObj::getFloatImageNum(FloatImageObj *fio)
153 return floatimage.indexOf(fio);
156 int BranchObj::countBranches()
158 return branch.count();
161 int BranchObj::countFloatImages()
163 return floatimage.count();
166 int BranchObj::countXLinks()
168 return xlink.count();
171 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
173 // Temporary link to lmo
174 // m is position of mouse pointer
175 // offset 0: default 1: below lmo -1 above lmo (if possible)
178 BranchObj* o=(BranchObj*)(lmo);
182 // ignore mapcenter and mainbranch
183 if (lmo->getDepth()<2) off=0;
190 depth=parObj->getDepth()+1;
192 // setLinkStyle calls updateLink, only set it once
193 if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
195 // Move temporary to new position at destination
196 // Usually the positioning would be done by reposition(),
197 // but then also the destination branch would "Jump" around...
198 // Better just do it approximately
200 { // new parent is the mapcenter itself
202 QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
203 m.y() - o->getChildPos().y() ));
204 if (p.x()<0) p.setX( p.x()-bbox.width() );
211 // new parent is just a branch, link to it
212 QRectF t=o->getBBoxSizeWithChilds();
213 if (o->getLastBranch())
214 y=t.y() + t.height() ;
221 // we want to link above lmo
222 y=o->y() - height() + 5;
224 // we want to link below lmo
225 // Bottom of sel should be 5 pixels above
226 // the bottom of the branch _below_ the target:
227 // Don't try to find that branch, guess 12 pixels
228 y=o->getChildPos().y() -height() + 12;
230 if (o->getOrientation()==LinkableMapObj::LeftOfCenter)
231 move ( o->getChildPos().x() - linkwidth, y );
233 move (o->getChildPos().x() + linkwidth, y );
236 // updateLink is called implicitly in move
240 void BranchObj::unsetParObjTmp()
247 depth=parObj->getDepth()+1;
248 setLinkStyle (getDefLinkStyle() );
253 void BranchObj::unScroll()
255 if (tmpUnscrolled) resetTmpUnscroll();
256 if (scrolled) toggleScroll();
259 void BranchObj::toggleScroll()
264 systemFlags->deactivate("scrolledright");
265 for (int i=0; i<branch.size(); ++i)
266 branch.at(i)->setVisibility(true);
270 systemFlags->activate("scrolledright");
271 for (int i=0; i<branch.size(); ++i)
272 branch.at(i)->setVisibility(false);
276 move (absPos.x(), absPos.y() );
280 bool BranchObj::isScrolled()
285 bool BranchObj::hasScrolledParent(BranchObj *start)
287 // Calls parents recursivly to
288 // find out, if we are scrolled at all.
289 // But ignore myself, just look at parents.
291 if (this !=start && scrolled) return true;
293 BranchObj* bo=(BranchObj*)(parObj);
295 return bo->hasScrolledParent(start);
300 void BranchObj::tmpUnscroll()
302 // Unscroll parent (recursivly)
303 BranchObj* bo=(BranchObj*)(parObj);
304 if (bo) bo->tmpUnscroll();
310 systemFlags->activate("tmpUnscrolledright");
315 void BranchObj::resetTmpUnscroll()
317 // Unscroll parent (recursivly)
318 BranchObj* bo=(BranchObj*)(parObj);
320 bo->resetTmpUnscroll();
326 systemFlags->deactivate("tmpUnscrolledright");
331 void BranchObj::setVisibility(bool v, int toDepth)
333 if (depth <= toDepth)
335 frame->setVisibility(v);
336 heading->setVisibility(v);
337 systemFlags->setVisibility(v);
338 standardFlags->setVisibility(v);
339 LinkableMapObj::setVisibility (v);
341 // Only change childs, if I am not scrolled
342 if (!scrolled && (depth < toDepth))
344 // Now go recursivly through all childs
346 for (i=0; i<branch.size(); ++i)
347 branch.at(i)->setVisibility (v,toDepth);
348 for (i=0; i<floatimage.size(); ++i)
349 floatimage.at(i)->setVisibility (v);
350 for (i=0; i<xlink.size(); ++i)
351 xlink.at(i)->setVisibility ();
353 } // depth <= toDepth
357 void BranchObj::setVisibility(bool v)
359 setVisibility (v,MAX_DEPTH);
363 void BranchObj::setLinkColor ()
365 // Overloaded from LinkableMapObj
366 // BranchObj can use color of heading
369 if (mapEditor->getMapLinkColorHint()==HeadingColor)
370 LinkableMapObj::setLinkColor (heading->getColor() );
372 LinkableMapObj::setLinkColor ();
375 void BranchObj::setColorSubtree(QColor col)
377 OrnamentedObj::setColor (col);
378 for (int i=0; i<branch.size(); ++i)
379 branch.at(i)->setColorSubtree(col);
382 BranchObj* BranchObj::first()
389 BranchObj* BranchObj::next()
393 BranchObj *po=(BranchObj*)parObj;
395 if (branch.isEmpty())
402 // no itLast, we are just beginning
405 // we have childs, return first one
411 // No childs, so there is no next
419 { // We come from parent
422 // there are childs, go there
427 { // no childs, try to go up again
430 // go back to parent and try to find next there
439 // can't go up, I am mapCenter, no next
446 // We don't come from parent, but from brother or childs
448 // Try to find last child, where we came from, in my own childs
451 while (i<branch.size())
453 // Try to find itLast in my own childs
454 if (itLast==branch.at(i))
456 // ok, we come from my own childs
457 if (i<branch.size()-1)
467 { // found itLast in my childs
470 // found a brother of lastLMO
478 if (this==itFirst) return NULL; // Stop at starting point
487 // can't go up, I am mapCenter
494 // couldn't find last child, it must be a nephew of mine
497 // proceed with my first child
499 return branch.first();
503 // or go back to my parents
514 // can't go up, I am mapCenter
521 BranchObj* BranchObj::getLastIterator()
526 void BranchObj::setLastIterator(BranchObj* it)
531 void BranchObj::positionContents()
533 for (int i=0; i<floatimage.size(); ++i )
534 floatimage.at(i)->reposition();
535 OrnamentedObj::positionContents();
538 void BranchObj::move (double x, double y)
540 OrnamentedObj::move (x,y);
541 for (int i=0; i<floatimage.size(); ++i )
542 floatimage.at(i)->reposition();
546 void BranchObj::move (QPointF p)
551 void BranchObj::moveBy (double x, double y)
553 OrnamentedObj::moveBy (x,y);
554 for (int i=0; i<branch.size(); ++i)
555 branch.at(i)->moveBy (x,y);
559 void BranchObj::moveBy (QPointF p)
561 moveBy (p.x(), p.y());
565 void BranchObj::positionBBox()
567 QPointF ap=getAbsPos();
568 bbox.moveTopLeft (ap);
572 frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
574 // Update links to other branches
575 for (int i=0; i<xlink.size(); ++i)
576 xlink.at(i)->updateXLink();
579 void BranchObj::calcBBoxSize()
581 QSizeF heading_r=heading->getSize();
582 qreal heading_w=(qreal) heading_r.width() ;
583 qreal heading_h=(qreal) heading_r.height() ;
584 QSizeF sysflags_r=systemFlags->getSize();
585 qreal sysflags_h=sysflags_r.height();
586 qreal sysflags_w=sysflags_r.width();
587 QSizeF stanflags_r=standardFlags->getSize();
588 qreal stanflags_h=stanflags_r.height();
589 qreal stanflags_w=stanflags_r.width();
593 // set width to sum of all widths
594 w=heading_w + sysflags_w + stanflags_w;
595 // set height to maximum needed height
596 h=max (sysflags_h,stanflags_h);
599 // Save the dimension of flags and heading
600 ornamentsBBox.setSize ( QSizeF(w,h));
602 // clickBox includes Flags and Heading
603 clickBox.setSize (ornamentsBBox.size() );
608 topPad=botPad=leftPad=rightPad=0;
609 if (includeImagesVer || includeImagesHor)
611 if (countFloatImages()>0)
613 for (int i=0; i<floatimage.size(); ++i )
615 rp=floatimage.at(i)->getRelPos();
616 if (includeImagesVer)
619 topPad=max (topPad,-rp.y()-h);
620 if (rp.y()+floatimage.at(i)->height() > 0)
621 botPad=max (botPad,rp.y()+floatimage.at(i)->height());
623 if (includeImagesHor)
625 if (orientation==LinkableMapObj::RightOfCenter)
628 leftPad=max (leftPad,-rp.x()-w);
629 if (rp.x()+floatimage.at(i)->width() > 0)
630 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
634 leftPad=max (leftPad,-rp.x());
635 if (rp.x()+floatimage.at(i)->width() > w)
636 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
646 w+=frame->getPadding();
647 h+=frame->getPadding();
650 bbox.setSize (QSizeF (w,h));
653 void BranchObj::setDockPos()
655 // Sets childpos and parpos depending on orientation
656 if (getOrientation()==LinkableMapObj::LeftOfCenter )
659 ornamentsBBox.bottomLeft().x(),
662 ornamentsBBox.bottomRight().x(),
667 ornamentsBBox.bottomRight().x(),
670 ornamentsBBox.bottomLeft().x(),
675 LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
679 for (int i=0; i<branch.size(); ++i)
681 lmo=branch.at(i)->findMapObj(p, excludeLMO);
682 if (lmo != NULL) return lmo;
686 if (inBox (p) && (this != excludeLMO) && isVisibleObj() )
689 // Search float images
690 for (int i=0; i<floatimage.size(); ++i )
691 if (floatimage.at(i)->inBox(p) &&
692 (floatimage.at(i) != excludeLMO) &&
693 floatimage.at(i)->getParObj()!= excludeLMO &&
694 floatimage.at(i)->isVisibleObj()
695 ) return floatimage.at(i);
700 void BranchObj::setHeading(QString s)
702 heading->setText(s); // set new heading
703 calcBBoxSize(); // recalculate bbox
704 positionBBox(); // rearrange contents
708 void BranchObj::setHideTmp (HideTmpMode mode)
710 if (mode==HideExport && hasHiddenExportParent(this))
712 setVisibility (false);
716 if (hasScrolledParent(this))
717 setVisibility (false);
719 setVisibility (true);
723 for (int i=0; i<branch.size(); ++i)
724 branch.at(i)->setHideTmp (mode);
727 bool BranchObj::hasHiddenExportParent(BranchObj *start)
729 // Calls parents recursivly to
730 // find out, if we are temp. hidden
732 if (hideExport) return true;
734 BranchObj* bo=(BranchObj*)(parObj);
736 return bo->hasHiddenExportParent(start);
741 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
743 // Cloudy stuff can be hidden during exports
744 if (hidden) return "";
746 // Update of note is usually done while unselecting a branch
747 if (isNoteInEditor) getNoteFromTextEditor();
750 QString scrolledAttr;
752 scrolledAttr=attribut ("scrolled","yes");
756 // save area, if not scrolled
758 if (!((BranchObj*)(parObj))->isScrolled() )
761 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
762 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
763 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
764 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
769 // Providing an ID for a branch makes export to XHTML easier
772 idAttr=attribut ("id",getSelectString());
776 s=beginElement ("branch"
781 +getIncludeImageAttr() );
785 s+=valueElement("heading", getHeading(),
786 attribut ("textColor",QColor(heading->getColor()).name()));
789 if (frame->getFrameType()!=FrameObj::NoFrame)
790 s+=frame->saveToDir ();
792 // save names of flags set
793 s+=standardFlags->saveToDir(tmpdir,prefix,0);
796 for (int i=0; i<floatimage.size(); ++i)
797 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
800 if (!note.isEmpty() )
804 for (int i=0; i<branch.size(); ++i)
805 s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
808 QString ol; // old link
809 QString cl; // current link
810 for (int i=0; i<xlink.size(); ++i)
812 cl=xlink.at(i)->saveToDir();
819 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
824 s+=endElement ("branch");
828 void BranchObj::addXLink (XLinkObj *xlo)
834 void BranchObj::removeXLinkRef (XLinkObj *xlo)
836 xlink.removeAt (xlink.indexOf(xlo));
839 void BranchObj::deleteXLink(XLinkObj *xlo)
842 if (!xlo->isUsed()) delete (xlo);
845 void BranchObj::deleteXLinkAt (int i)
847 XLinkObj *xlo=xlink.at(i);
849 if (!xlo->isUsed()) delete(xlo);
852 XLinkObj* BranchObj::XLinkAt (int i)
857 int BranchObj::countXLink()
859 return xlink.count();
863 BranchObj* BranchObj::XLinkTargetAt (int i)
865 if (i>=0 && i<xlink.size())
868 return xlink.at(i)->otherBranch (this);
873 void BranchObj::setIncludeImagesVer(bool b)
881 bool BranchObj::getIncludeImagesVer()
883 return includeImagesVer;
886 void BranchObj::setIncludeImagesHor(bool b)
894 bool BranchObj::getIncludeImagesHor()
896 return includeImagesHor;
899 QString BranchObj::getIncludeImageAttr()
902 if (includeImagesVer)
903 a=attribut ("incImgV","true");
905 a=attribut ("incImgV","false");
906 if (includeImagesHor)
907 a+=attribut ("incImgH","true");
909 a+=attribut ("incImgH","false");
913 FloatImageObj* BranchObj::addFloatImage ()
915 FloatImageObj *newfi=new FloatImageObj (scene,this);
916 floatimage.append (newfi);
917 if (hasScrolledParent(this) )
918 newfi->setVisibility (false);
920 newfi->setVisibility(visible);
929 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
931 FloatImageObj *newfi=new FloatImageObj (scene,this);
932 floatimage.append (newfi);
934 if (hasScrolledParent(this) )
935 newfi->setVisibility (false);
937 newfi->setVisibility(visible);
946 FloatImageObj* BranchObj::getFirstFloatImage ()
948 return floatimage.first();
951 FloatImageObj* BranchObj::getLastFloatImage ()
953 return floatimage.last();
956 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
958 return floatimage.at(i);
961 void BranchObj::removeFloatImage (FloatImageObj *fio)
963 int i=floatimage.indexOf (fio);
964 if (i>-1) delete (floatimage.takeAt (i));
970 void BranchObj::savePosInAngle ()
972 // Save position in angle
973 for (int i=0; i<branch.size(); ++i)
974 branch.at(i)->angle=i;
977 void BranchObj::setDefAttr (BranchModification mod)
982 case 0: fontsize=16; break;
983 case 1: fontsize=12; break;
984 default: fontsize=10; break;
988 setLinkStyle(getDefLinkStyle());
989 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
990 font.setPointSize(fontsize);
991 heading->setFont(font );
994 setColor (((BranchObj*)(parObj))->getColor());
999 BranchObj* BranchObj::addBranch()
1001 BranchObj* newbo=new BranchObj(scene,this);
1002 branch.append (newbo);
1003 newbo->setParObj(this);
1004 newbo->setDefAttr(NewBranch);
1005 newbo->setHeading ("new");
1007 newbo->setVisibility (false);
1009 newbo->setVisibility(visible);
1010 newbo->updateLink();
1011 requestReposition();
1015 BranchObj* BranchObj::addBranch(BranchObj* bo)
1017 BranchObj* newbo=new BranchObj(scene,this);
1018 branch.append (newbo);
1020 newbo->setParObj(this);
1021 newbo->setDefAttr(MovedBranch);
1023 newbo->setVisibility (false);
1025 newbo->setVisibility(bo->visible);
1026 newbo->updateLink();
1027 requestReposition();
1031 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
1034 bo->setParObj (this);
1036 bo->setDefAttr(MovedBranch);
1037 if (scrolled) tmpUnscroll();
1038 setLastSelectedBranch (bo);
1042 BranchObj* BranchObj::insertBranch(int pos)
1045 // Add new bo and resort branches
1046 BranchObj *newbo=addBranch ();
1047 newbo->angle=pos-0.5;
1048 qSort (branch.begin(),branch.end(), isAbove);
1052 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
1055 // Add new bo and resort branches
1057 BranchObj *newbo=addBranch (bo);
1058 qSort (branch.begin(),branch.end(), isAbove);
1062 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
1065 // Add new bo and resort branches
1068 bo->setParObj (this);
1070 bo->setDefAttr (MovedBranch);
1071 if (scrolled) tmpUnscroll();
1072 setLastSelectedBranch (bo);
1073 qSort (branch.begin(),branch.end(), isAbove);
1077 void BranchObj::removeBranchHere(BranchObj* borem)
1079 // This removes the branch bo from list, but
1080 // inserts its childs at the place of bo
1082 bo=borem->getLastBranch();
1083 int pos=borem->getNum();
1086 bo->linkTo (this,pos+1);
1087 bo=borem->getLastBranch();
1089 removeBranch (borem);
1092 void BranchObj::removeChilds()
1097 void BranchObj::removeBranch(BranchObj* bo)
1099 // if bo is not in branch remove returns false, we
1102 int i=branch.indexOf(bo);
1106 branch.removeAt (i);
1108 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
1109 requestReposition();
1112 void BranchObj::removeBranchPtr(BranchObj* bo)
1114 int i=branch.indexOf(bo);
1117 branch.removeAt (i);
1119 qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
1120 requestReposition();
1123 void BranchObj::setLastSelectedBranch (BranchObj* bo)
1125 lastSelectedBranch=branch.indexOf(bo);
1128 BranchObj* BranchObj::getLastSelectedBranch ()
1130 if (lastSelectedBranch>=0)
1132 if ( branch.size()>lastSelectedBranch)
1133 return branch.at(lastSelectedBranch);
1134 if (branch.size()>0)
1135 return branch.last();
1140 BranchObj* BranchObj::getFirstBranch ()
1142 if (branch.size()>0)
1143 return branch.first();
1148 BranchObj* BranchObj::getLastBranch ()
1150 if (branch.size()>0)
1151 return branch.last();
1156 BranchObj* BranchObj::getBranchNum (int i)
1158 if (i>=0 && i<branch.size())
1159 return branch.at(i);
1164 bool BranchObj::canMoveBranchUp()
1166 if (!parObj || depth==1) return false;
1167 BranchObj* par=(BranchObj*)parObj;
1168 if (this==par->getFirstBranch())
1174 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
1177 int i=branch.indexOf(bo1);
1179 { // -1 if bo1 not found
1180 branch.at(i)->angle--;
1181 branch.at(i-1)->angle++;
1182 qSort (branch.begin(),branch.end(), isAbove);
1183 return branch.at(i);
1188 bool BranchObj::canMoveBranchDown()
1190 if (!parObj|| depth==1) return false;
1191 BranchObj* par=(BranchObj*)parObj;
1192 if (this==par->getLastBranch())
1198 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
1201 int i=branch.indexOf(bo1);
1203 if (i <branch.size())
1206 branch.at(i)->angle++;
1207 branch.at(j)->angle--;
1208 qSort (branch.begin(),branch.end(), isAbove);
1209 return branch.at(i);
1214 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
1216 // Find current parent and
1217 // remove pointer to myself there
1218 if (!dst) return NULL;
1219 BranchObj *par=(BranchObj*)parObj;
1221 par->removeBranchPtr (this);
1225 // Create new pointer to myself at dst
1226 if (pos<0||dst->getDepth()==0)
1228 // links myself as last branch at dst
1229 dst->addBranchPtr (this);
1234 // inserts me at pos in parent of dst
1237 BranchObj *bo=dst->insertBranchPtr (this,pos);
1238 bo->setDefAttr(MovedBranch);
1247 void BranchObj::alignRelativeTo (QPointF ref)
1249 qreal th = bboxTotal.height();
1252 cout << "BO::alignRelTo "<<getHeading().ascii()<<endl;
1253 cout << " d="<<depth<<
1255 // " bbox.topLeft="<<bboxTotal.topLeft()<<
1256 " absPos="<<absPos<<
1257 " relPos="<<relPos<<
1258 " orient="<<orientation<<
1259 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
1260 // " hidden="<<hidden<<
1272 // Position relatively, if needed
1273 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
1275 // Calc angle to mapCenter if I am a mainbranch
1276 // needed for reordering the mainbranches clockwise
1278 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
1279 (int)(y() - parObj->getChildPos().y() ) ) );
1284 // Align myself depending on orientation and parent, but
1285 // only if I am not a mainbranch or mapcenter itself
1286 LinkableMapObj::Orientation o;
1287 o=parObj->getOrientation();
1288 switch (orientation)
1290 case LinkableMapObj::LeftOfCenter:
1291 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1293 case LinkableMapObj::RightOfCenter:
1294 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1297 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1302 if (scrolled) return;
1304 // Set reference point for alignment of childs
1306 if (orientation==LinkableMapObj::LeftOfCenter)
1307 ref2.setX(bbox.topLeft().x() - linkwidth);
1309 ref2.setX(bbox.topRight().x() + linkwidth);
1312 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1314 ref2.setY(ref.y() );
1316 // Align the childs depending on reference point
1317 for (int i=0; i<branch.size(); ++i)
1319 if (!branch.at(i)->isHidden())
1321 branch.at(i)->alignRelativeTo (ref2);
1322 ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChilds().height() );
1328 void BranchObj::reposition()
1330 /* TODO testing only
1331 if (!getHeading().isEmpty())
1332 cout << "BO::reposition "<<getHeading().ascii()<<endl;
1334 cout << "BO::reposition ???"<<endl;
1336 cout << " orient="<<orientation<<endl;
1341 // only calculate the sizes once. If the deepest LMO
1342 // changes its height,
1343 // all upper LMOs have to change, too.
1344 calcBBoxSizeWithChilds();
1345 updateLink(); // This update is needed if the scene is resized
1346 // due to excessive moving of a FIO
1348 alignRelativeTo ( QPointF (absPos.x(),
1349 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1350 qSort (branch.begin(),branch.end(), isAbove);
1351 positionBBox(); // Reposition bbox and contents
1354 // This is only important for moving branches:
1355 // For editing a branch it isn't called...
1356 alignRelativeTo ( QPointF (absPos.x(),
1357 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1361 void BranchObj::unsetAllRepositionRequests()
1363 repositionRequest=false;
1364 for (int i=0; i<branch.size(); ++i)
1365 branch.at(i)->unsetAllRepositionRequests();
1369 QRectF BranchObj::getTotalBBox()
1373 if (scrolled) return r;
1375 for (int i=0; i<branch.size(); ++i)
1376 if (!branch.at(i)->isHidden())
1377 r=addBBox(branch.at(i)->getTotalBBox(),r);
1379 for (int i=0; i<floatimage.size(); ++i)
1380 if (!floatimage.at(i)->isHidden())
1381 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1386 QRectF BranchObj::getBBoxSizeWithChilds()
1391 void BranchObj::calcBBoxSizeWithChilds()
1393 // This is initially called only from reposition and
1394 // and only for mapcenter. So it won't be
1395 // called more than once for a single user
1399 // Calculate size of LMO including all childs (to align them later)
1400 bboxTotal.setX(bbox.x() );
1401 bboxTotal.setY(bbox.y() );
1403 // if branch is scrolled, ignore childs, but still consider floatimages
1406 bboxTotal.setWidth (bbox.width());
1407 bboxTotal.setHeight(bbox.height());
1413 bboxTotal.setWidth (0);
1414 bboxTotal.setHeight(0);
1417 bboxTotal.setX (parObj->x());
1418 bboxTotal.setY (parObj->y());
1421 bboxTotal.setX (bbox.x());
1422 bboxTotal.setY (bbox.y());
1429 // Now calculate recursivly
1431 // maximum of widths
1433 for (int i=0; i<branch.size(); ++i)
1435 if (!branch.at(i)->isHidden())
1437 branch.at(i)->calcBBoxSizeWithChilds();
1438 br=branch.at(i)->getBBoxSizeWithChilds();
1439 r.setWidth( max (br.width(), r.width() ));
1440 r.setHeight(br.height() + r.height() );
1441 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1444 // Add myself and also
1445 // add width of link to sum if necessary
1446 if (branch.isEmpty())
1447 bboxTotal.setWidth (bbox.width() + r.width() );
1449 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1451 bboxTotal.setHeight(max (r.height(), bbox.height()));
1454 void BranchObj::select()
1456 // update NoteEditor
1457 textEditor->setText(note.getNote() );
1458 QString fnh=note.getFilenameHint();
1460 textEditor->setFilenameHint(note.getFilenameHint() );
1462 textEditor->setFilenameHint(getHeading() );
1463 textEditor->setFontHint (note.getFontHint() );
1464 isNoteInEditor=true;
1466 // set selected and visible
1467 LinkableMapObj::select();
1469 // Tell parent that I am selected now:
1470 BranchObj* po=(BranchObj*)(parObj);
1471 if (po) // TODO Try to get rid of this cast...
1472 po->setLastSelectedBranch(this);
1474 // temporary unscroll, if we have scrolled parents somewhere
1475 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1477 // Show URL and link in statusbar
1479 if (!url.isEmpty()) status+="URL: "+url+" ";
1480 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1481 if (!status.isEmpty()) mainWindow->statusMessage (status);
1484 updateFlagsToolbar();
1487 mapEditor->updateActions();
1490 void BranchObj::unselect()
1492 LinkableMapObj::unselect();
1493 // Delete any messages like vymLink in StatusBar
1494 mainWindow->statusMessage ("");
1496 // Save current note
1497 if (isNoteInEditor) getNoteFromTextEditor();
1498 isNoteInEditor=false;
1500 // reset temporary unscroll, if we have scrolled parents somewhere
1501 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1503 // Erase content of editor
1504 textEditor->setInactive();
1506 // unselect all buttons in toolbar
1507 standardFlagsDefault->updateToolbar();
1510 QString BranchObj::getSelectString()
1516 s= "bo:" + QString("%1").arg(getNum());
1518 s= ((BranchObj*)(parObj))->getSelectString() + ",bo:" + QString("%1").arg(getNum());
1525 void BranchObj::animate()
1528 cout << "BO::animate x,y="<<relPos.x()<<","<<relPos.y()<<endl;