3 // #include "texteditor.h"
6 #include "mainwindow.h"
11 extern TextEditor *textEditor;
12 extern Main *mainWindow;
13 extern FlagRowObj *standardFlagsDefault;
16 /////////////////////////////////////////////////////////////////
18 /////////////////////////////////////////////////////////////////
20 BranchObj* BranchObj::itLast=NULL;
21 BranchObj* BranchObj::itFirst=NULL;
24 BranchObj::BranchObj () :OrnamentedObj() // FIXME needed at all?
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 // If I'm animated, I need to un-animate myself first
57 if (anim.isAnimated() )
59 anim.setAnimated (false);
60 model->stopAnimation (this);
63 //cout << "Destr BranchObj of "<<this<<endl;
64 // Check, if this branch was the last child to be deleted
65 // If so, unset the scrolled flags
67 BranchObj *po=(BranchObj*)parObj;
71 bo=((BranchObj*)parObj)->getLastBranch();
72 if (bo) po->unScroll();
77 bool BranchObj::operator< ( const BranchObj & other )
79 return angle < other.angle;
82 bool BranchObj::operator== ( const BranchObj & other )
84 return angle == other.angle;
87 void BranchObj::init ()
92 absPos+=parObj->getChildPos();
100 includeImagesVer=false;
101 includeImagesHor=false;
104 void BranchObj::copy (BranchObj* other)
106 OrnamentedObj::copy(other);
109 for (int i=0; i<other->branch.size(); ++i)
110 // Make deep copy of b
111 // Because addBranch again calls copy for the children,
112 // Those will get a deep copy, too
113 addBranch(other->branch.at(i) );
115 for (int i=0; i<other->floatimage.size(); ++i)
116 addFloatImage (other->floatimage.at(i));
117 scrolled=other->scrolled;
118 tmpUnscrolled=other->tmpUnscrolled;
119 setVisibility (other->visible);
126 void BranchObj::clear()
128 setVisibility (true);
130 while (!floatimage.isEmpty())
131 delete floatimage.takeFirst();
133 while (!xlink.isEmpty())
134 delete xlink.takeFirst();
136 while (!branch.isEmpty())
137 delete branch.takeFirst();
140 bool isAbove (BranchObj* a, BranchObj *b)
142 if (a->angle < b->angle)
148 int BranchObj::getNum()
151 return ((BranchObj*)parObj)->getNum (this);
156 int BranchObj::getNum(BranchObj *bo)
158 return branch.indexOf (bo);
161 int BranchObj::getFloatImageNum(FloatImageObj *fio)
163 return floatimage.indexOf(fio);
166 int BranchObj::countBranches()
168 return branch.count();
171 int BranchObj::countFloatImages()
173 return floatimage.count();
176 int BranchObj::countXLinks()
178 return xlink.count();
181 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
183 // Temporary link to lmo
184 // m is position of mouse pointer
185 // offset 0: default 1: below lmo -1 above lmo (if possible)
188 BranchObj* o=(BranchObj*)(lmo);
192 // ignore mapcenter and mainbranch
193 if (lmo->getDepth()<2) off=0;
200 depth=parObj->getDepth()+1;
202 // setLinkStyle calls updateLink, only set it once
203 if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
205 // Move temporary to new position at destination
206 // Usually the positioning would be done by reposition(),
207 // but then also the destination branch would "Jump" around...
208 // Better just do it approximately
210 { // new parent is the mapcenter itself
212 QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
213 m.y() - o->getChildPos().y() ));
214 if (p.x()<0) p.setX( p.x()-bbox.width() );
221 // new parent is just a branch, link to it
222 QRectF t=o->getBBoxSizeWithChildren();
223 if (o->getLastBranch())
224 y=t.y() + t.height() ;
231 // we want to link above lmo
232 y=o->y() - height() + 5;
234 // we want to link below lmo
235 // Bottom of sel should be 5 pixels above
236 // the bottom of the branch _below_ the target:
237 // Don't try to find that branch, guess 12 pixels
238 y=o->getChildPos().y() -height() + 12;
240 if (o->getOrientation()==LinkableMapObj::LeftOfCenter)
241 move ( o->getChildPos().x() - linkwidth, y );
243 move (o->getChildPos().x() + linkwidth, y );
246 // updateLink is called implicitly in move
250 void BranchObj::unsetParObjTmp()
257 depth=parObj->getDepth()+1;
258 setLinkStyle (getDefLinkStyle() );
263 void BranchObj::unScroll()
265 if (tmpUnscrolled) resetTmpUnscroll();
266 if (scrolled) toggleScroll();
269 void BranchObj::toggleScroll()
274 systemFlags->deactivate("scrolledright");
275 for (int i=0; i<branch.size(); ++i)
276 branch.at(i)->setVisibility(true);
280 systemFlags->activate("scrolledright");
281 for (int i=0; i<branch.size(); ++i)
282 branch.at(i)->setVisibility(false);
286 move (absPos.x(), absPos.y() );
290 bool BranchObj::isScrolled()
295 bool BranchObj::hasScrolledParent(BranchObj *start)
297 // Calls parents recursivly to
298 // find out, if we are scrolled at all.
299 // But ignore myself, just look at parents.
301 if (this !=start && scrolled) return true;
303 BranchObj* bo=(BranchObj*)(parObj);
305 return bo->hasScrolledParent(start);
310 void BranchObj::tmpUnscroll()
312 // Unscroll parent (recursivly)
313 BranchObj* bo=(BranchObj*)(parObj);
314 if (bo) bo->tmpUnscroll();
320 systemFlags->activate("tmpUnscrolledright");
325 void BranchObj::resetTmpUnscroll()
327 // Unscroll parent (recursivly)
328 BranchObj* bo=(BranchObj*)(parObj);
330 bo->resetTmpUnscroll();
336 systemFlags->deactivate("tmpUnscrolledright");
341 void BranchObj::setVisibility(bool v, int toDepth)
343 if (depth <= toDepth)
345 frame->setVisibility(v);
346 heading->setVisibility(v);
347 systemFlags->setVisibility(v);
348 standardFlags->setVisibility(v);
349 LinkableMapObj::setVisibility (v);
352 for (i=0; i<floatimage.size(); ++i)
353 floatimage.at(i)->setVisibility (v);
354 for (i=0; i<xlink.size(); ++i)
355 xlink.at(i)->setVisibility ();
357 // Only change children, if I am not scrolled
358 if (!scrolled && (depth < toDepth))
360 // Now go recursivly through all children
361 for (i=0; i<branch.size(); ++i)
362 branch.at(i)->setVisibility (v,toDepth);
364 } // depth <= toDepth
368 void BranchObj::setVisibility(bool v)
370 setVisibility (v,MAX_DEPTH);
374 void BranchObj::setLinkColor ()
376 // Overloaded from LinkableMapObj
377 // BranchObj can use color of heading
381 if (model->getMapLinkColorHint()==HeadingColor)
382 LinkableMapObj::setLinkColor (heading->getColor() );
384 LinkableMapObj::setLinkColor ();
388 void BranchObj::setColorSubtree(QColor col)
391 for (int i=0; i<branch.size(); ++i)
392 branch.at(i)->setColorSubtree(col);
395 BranchObj* BranchObj::first()
402 BranchObj* BranchObj::next()
406 BranchObj *po=(BranchObj*)parObj;
408 if (branch.isEmpty())
415 // no itLast, we are just beginning
418 // we have children, return first one
424 // No children, so there is no next
432 { // We come from parent
435 // there are children, go there
440 { // no children, try to go up again
443 // go back to parent and try to find next there
452 // can't go up, I am mapCenter, no next
459 // We don't come from parent, but from brother or children
461 // Try to find last child, where we came from, in my own children
464 while (i<branch.size())
466 // Try to find itLast in my own children
467 if (itLast==branch.at(i))
469 // ok, we come from my own children
470 if (i<branch.size()-1)
480 { // found itLast in my children
483 // found a brother of lastLMO
491 if (this==itFirst) return NULL; // Stop at starting point
500 // can't go up, I am mapCenter
507 // couldn't find last child, it must be a nephew of mine
510 // proceed with my first child
512 return branch.first();
516 // or go back to my parents
527 // can't go up, I am mapCenter
534 BranchObj* BranchObj::getLastIterator()
539 void BranchObj::setLastIterator(BranchObj* it)
544 void BranchObj::positionContents()
546 for (int i=0; i<floatimage.size(); ++i )
547 floatimage.at(i)->reposition();
548 OrnamentedObj::positionContents();
551 void BranchObj::move (double x, double y)
553 OrnamentedObj::move (x,y);
554 for (int i=0; i<floatimage.size(); ++i )
555 floatimage.at(i)->reposition();
559 void BranchObj::move (QPointF p)
564 void BranchObj::moveBy (double x, double y)
566 OrnamentedObj::moveBy (x,y);
567 for (int i=0; i<branch.size(); ++i)
568 branch.at(i)->moveBy (x,y);
572 void BranchObj::moveBy (QPointF p)
574 moveBy (p.x(), p.y());
578 void BranchObj::positionBBox()
580 QPointF ap=getAbsPos();
581 bbox.moveTopLeft (ap);
585 frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
587 // Update links to other branches
588 for (int i=0; i<xlink.size(); ++i)
589 xlink.at(i)->updateXLink();
592 void BranchObj::calcBBoxSize()
594 QSizeF heading_r=heading->getSize();
595 qreal heading_w=(qreal) heading_r.width() ;
596 qreal heading_h=(qreal) heading_r.height() ;
597 QSizeF sysflags_r=systemFlags->getSize();
598 qreal sysflags_h=sysflags_r.height();
599 qreal sysflags_w=sysflags_r.width();
600 QSizeF stanflags_r=standardFlags->getSize();
601 qreal stanflags_h=stanflags_r.height();
602 qreal stanflags_w=stanflags_r.width();
606 // set width to sum of all widths
607 w=heading_w + sysflags_w + stanflags_w;
608 // set height to maximum needed height
609 h=max (sysflags_h,stanflags_h);
612 // Save the dimension of flags and heading
613 ornamentsBBox.setSize ( QSizeF(w,h));
615 // clickBox includes Flags and Heading
616 clickBox.setSize (ornamentsBBox.size() );
621 topPad=botPad=leftPad=rightPad=0;
622 if (includeImagesVer || includeImagesHor)
624 if (countFloatImages()>0)
626 for (int i=0; i<floatimage.size(); ++i )
628 rp=floatimage.at(i)->getRelPos();
629 if (includeImagesVer)
632 topPad=max (topPad,-rp.y()-h);
633 if (rp.y()+floatimage.at(i)->height() > 0)
634 botPad=max (botPad,rp.y()+floatimage.at(i)->height());
636 if (includeImagesHor)
638 if (orientation==LinkableMapObj::RightOfCenter)
641 leftPad=max (leftPad,-rp.x()-w);
642 if (rp.x()+floatimage.at(i)->width() > 0)
643 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
647 leftPad=max (leftPad,-rp.x());
648 if (rp.x()+floatimage.at(i)->width() > w)
649 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
659 w+=frame->getPadding();
660 h+=frame->getPadding();
663 bbox.setSize (QSizeF (w,h));
666 void BranchObj::setDockPos()
668 // Sets childpos and parpos depending on orientation
669 if (getOrientation()==LinkableMapObj::LeftOfCenter )
672 ornamentsBBox.bottomLeft().x(),
675 ornamentsBBox.bottomRight().x(),
680 ornamentsBBox.bottomRight().x(),
683 ornamentsBBox.bottomLeft().x(),
688 LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
692 for (int i=0; i<branch.size(); ++i)
694 lmo=branch.at(i)->findMapObj(p, excludeLMO);
695 if (lmo != NULL) return lmo;
700 if (inBox (p,clickBox) && (this != excludeLMO) && isVisibleObj() )
703 // Search float images
704 for (int i=0; i<floatimage.size(); ++i )
705 if (inBox(p,floatimage.at(i)->getClickBox()) &&
706 (floatimage.at(i) != excludeLMO) &&
707 floatimage.at(i)->getParObj()!= excludeLMO &&
708 floatimage.at(i)->isVisibleObj()
709 ) return floatimage.at(i);
714 LinkableMapObj* BranchObj::findID (QString sid)
718 for (int i=0; i<branch.size(); ++i)
720 lmo=branch.at(i)->findID (sid);
721 if (lmo != NULL) return lmo;
725 if (sid==objID) return this;
729 // Search float images
730 for (int i=0; i<floatimage.size(); ++i )
731 if (floatimage.at(i)->inBox(p) &&
732 (floatimage.at(i) != excludeLMO) &&
733 floatimage.at(i)->getParObj()!= excludeLMO &&
734 floatimage.at(i)->isVisibleObj()
735 ) return floatimage.at(i);
740 void BranchObj::setHeading(QString s)
742 heading->setText(s); // set new heading
743 calcBBoxSize(); // recalculate bbox
744 positionBBox(); // rearrange contents
748 void BranchObj::setHideTmp (HideTmpMode mode)
750 if (mode==HideExport && (hideExport|| hasHiddenExportParent() ) )
752 // Hide stuff according to hideExport flag and parents
753 setVisibility (false);
757 // Do not hide, but still take care of scrolled status
758 if (hasScrolledParent(this))
759 setVisibility (false);
761 setVisibility (true);
765 // And take care of my children
766 for (int i=0; i<branch.size(); ++i)
767 branch.at(i)->setHideTmp (mode);
770 bool BranchObj::hasHiddenExportParent()
772 // Calls parents recursivly to
773 // find out, if we or parents are temp. hidden
775 if (hidden || hideExport) return true;
777 BranchObj* bo=(BranchObj*)parObj;
779 return bo->hasHiddenExportParent();
784 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
786 // Cloudy stuff can be hidden during exports
787 if (hidden) return "";
789 // Update of note is usually done while unselecting a branch
790 if (isNoteInEditor) getNoteFromTextEditor();
793 QString scrolledAttr;
795 scrolledAttr=attribut ("scrolled","yes");
799 // save area, if not scrolled
801 if (!((BranchObj*)(parObj))->isScrolled() )
804 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
805 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
806 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
807 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
812 // Providing an ID for a branch makes export to XHTML easier
815 idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
819 s=beginElement ("branch"
824 +getIncludeImageAttr() );
828 s+=valueElement("heading", getHeading(),
829 attribut ("textColor",QColor(heading->getColor()).name()));
832 if (frame->getFrameType()!=FrameObj::NoFrame)
833 s+=frame->saveToDir ();
835 // save names of flags set
836 s+=standardFlags->saveToDir(tmpdir,prefix,0);
839 for (int i=0; i<floatimage.size(); ++i)
840 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
843 if (!note.isEmpty() )
847 for (int i=0; i<branch.size(); ++i)
848 s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
851 QString ol; // old link
852 QString cl; // current link
853 for (int i=0; i<xlink.size(); ++i)
855 cl=xlink.at(i)->saveToDir();
862 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
867 s+=endElement ("branch");
871 void BranchObj::addXLink (XLinkObj *xlo)
877 void BranchObj::removeXLinkRef (XLinkObj *xlo)
879 xlink.removeAt (xlink.indexOf(xlo));
882 void BranchObj::deleteXLink(XLinkObj *xlo)
885 if (!xlo->isUsed()) delete (xlo);
888 void BranchObj::deleteXLinkAt (int i)
890 XLinkObj *xlo=xlink.at(i);
892 if (!xlo->isUsed()) delete(xlo);
895 XLinkObj* BranchObj::XLinkAt (int i)
900 int BranchObj::countXLink()
902 return xlink.count();
906 BranchObj* BranchObj::XLinkTargetAt (int i)
908 if (i>=0 && i<xlink.size())
911 return xlink.at(i)->otherBranch (this);
916 void BranchObj::setIncludeImagesVer(bool b)
924 bool BranchObj::getIncludeImagesVer()
926 return includeImagesVer;
929 void BranchObj::setIncludeImagesHor(bool b)
937 bool BranchObj::getIncludeImagesHor()
939 return includeImagesHor;
942 QString BranchObj::getIncludeImageAttr()
945 if (includeImagesVer)
946 a=attribut ("incImgV","true");
948 a=attribut ("incImgV","false");
949 if (includeImagesHor)
950 a+=attribut ("incImgH","true");
952 a+=attribut ("incImgH","false");
956 FloatImageObj* BranchObj::addFloatImage ()
958 FloatImageObj *newfi=new FloatImageObj (scene,this);
959 floatimage.append (newfi);
960 if (hasScrolledParent(this) )
961 newfi->setVisibility (false);
963 newfi->setVisibility(visible);
972 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
974 FloatImageObj *newfi=new FloatImageObj (scene,this);
975 floatimage.append (newfi);
977 if (hasScrolledParent(this) )
978 newfi->setVisibility (false);
980 newfi->setVisibility(visible);
989 FloatImageObj* BranchObj::getFirstFloatImage ()
991 return floatimage.first();
994 FloatImageObj* BranchObj::getLastFloatImage ()
996 return floatimage.last();
999 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
1001 return floatimage.at(i);
1004 void BranchObj::removeFloatImage (FloatImageObj *fio)
1006 int i=floatimage.indexOf (fio);
1007 if (i>-1) delete (floatimage.takeAt (i));
1010 requestReposition();
1013 void BranchObj::savePosInAngle ()
1015 // Save position in angle
1016 for (int i=0; i<branch.size(); ++i)
1017 branch.at(i)->angle=i;
1020 void BranchObj::setDefAttr (BranchModification mod)
1025 case 0: fontsize=16; break;
1026 case 1: fontsize=12; break;
1027 default: fontsize=10; break;
1031 setLinkStyle(getDefLinkStyle());
1032 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
1033 font.setPointSize(fontsize);
1034 heading->setFont(font );
1037 setColor (((BranchObj*)(parObj))->getColor());
1042 BranchObj* BranchObj::addBranch()
1044 BranchObj* newbo=new BranchObj(scene,this);
1045 branch.append (newbo);
1046 newbo->setParObj(this);
1047 newbo->setDefAttr(NewBranch);
1048 newbo->setHeading ("new");
1050 newbo->setVisibility (false);
1052 newbo->setVisibility(visible);
1053 newbo->updateLink();
1054 requestReposition();
1058 BranchObj* BranchObj::addBranch(BranchObj* bo)
1060 BranchObj* newbo=new BranchObj(scene,this);
1061 branch.append (newbo);
1063 newbo->setParObj(this);
1064 newbo->setDefAttr(MovedBranch);
1066 newbo->setVisibility (false);
1068 newbo->setVisibility(bo->visible);
1069 newbo->updateLink();
1070 requestReposition();
1074 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
1077 bo->setParObj (this);
1079 bo->setDefAttr(MovedBranch);
1080 if (scrolled) tmpUnscroll();
1081 //setLastSelectedBranch (bo); //FIXME needed?
1085 BranchObj* BranchObj::insertBranch(int pos)
1088 // Add new bo and resort branches
1089 BranchObj *newbo=addBranch ();
1090 newbo->angle=pos-0.5;
1091 qSort (branch.begin(),branch.end(), isAbove);
1095 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
1098 // Add new bo and resort branches
1100 BranchObj *newbo=addBranch (bo);
1101 qSort (branch.begin(),branch.end(), isAbove);
1105 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
1108 // Add new bo and resort branches
1111 bo->setParObj (this);
1113 bo->setDefAttr (MovedBranch);
1114 if (scrolled) tmpUnscroll();
1115 //setLastSelectedBranch (bo); //FIXME needed?
1116 qSort (branch.begin(),branch.end(), isAbove);
1120 void BranchObj::removeBranchHere(BranchObj* borem)
1122 // This removes the branch bo from list, but
1123 // inserts its children at the place of bo
1125 bo=borem->getLastBranch();
1126 int pos=borem->getNum();
1129 bo->linkTo (this,pos+1);
1130 bo=borem->getLastBranch();
1132 removeBranch (borem);
1135 void BranchObj::removeChildren()
1140 void BranchObj::removeBranch(BranchObj* bo)
1142 // if bo is not in branch remove returns false, we
1145 int i=branch.indexOf(bo);
1149 branch.removeAt (i);
1151 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
1152 requestReposition();
1155 void BranchObj::removeBranchPtr(BranchObj* bo)
1157 int i=branch.indexOf(bo);
1160 branch.removeAt (i);
1162 qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
1163 requestReposition();
1166 BranchObj* BranchObj::getFirstBranch ()
1168 if (branch.size()>0)
1169 return branch.first();
1174 BranchObj* BranchObj::getLastBranch ()
1176 if (branch.size()>0)
1177 return branch.last();
1182 BranchObj* BranchObj::getBranchNum (int i)
1184 if (i>=0 && i<branch.size())
1185 return branch.at(i);
1190 bool BranchObj::canMoveBranchUp()
1192 if (!parObj || depth==1) return false;
1193 BranchObj* par=(BranchObj*)parObj;
1194 if (this==par->getFirstBranch())
1200 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
1203 int i=branch.indexOf(bo1);
1205 { // -1 if bo1 not found
1206 branch.at(i)->angle--;
1207 branch.at(i-1)->angle++;
1208 qSort (branch.begin(),branch.end(), isAbove);
1209 return branch.at(i);
1214 bool BranchObj::canMoveBranchDown()
1216 if (!parObj|| depth==1) return false;
1217 BranchObj* par=(BranchObj*)parObj;
1218 if (this==par->getLastBranch())
1224 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
1227 int i=branch.indexOf(bo1);
1229 if (i <branch.size())
1232 branch.at(i)->angle++;
1233 branch.at(j)->angle--;
1234 qSort (branch.begin(),branch.end(), isAbove);
1235 return branch.at(i);
1240 void BranchObj::sortChildren()
1242 int childCount=branch.count();
1244 bool madeChanges=false;
1248 for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
1249 BranchObj* curChild=(BranchObj*)branch.at(curChildIndex);
1250 BranchObj* prevChild=(BranchObj*)branch.at(curChildIndex-1);
1251 if(prevChild->heading->text().compare(curChild->heading->text())>0)
1253 this->moveBranchUp(curChild);
1257 }while(madeChanges);
1261 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
1263 // Find current parent and
1264 // remove pointer to myself there
1265 if (!dst) return NULL;
1266 BranchObj *par=(BranchObj*)parObj;
1268 par->removeBranchPtr (this);
1272 // Create new pointer to myself at dst
1273 if (pos<0||dst->getDepth()==0)
1275 // links myself as last branch at dst
1276 dst->addBranchPtr (this);
1281 // inserts me at pos in parent of dst
1284 BranchObj *bo=dst->insertBranchPtr (this,pos);
1285 bo->setDefAttr(MovedBranch);
1294 void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
1296 qreal th = bboxTotal.height();
1299 QPointF pp; if (parObj) pp=parObj->getChildPos();
1300 cout << "BO::alignRelTo "<<qPrintable (getHeading());
1301 cout << " d="<<depth<<
1303 // " bbox.topLeft="<<bboxTotal.topLeft()<<
1304 " absPos="<<absPos<<
1305 // " relPos="<<relPos<<
1307 " width="<<bbox.width()<<
1308 " orient="<<orientation<<
1309 " alignSelf="<<alignSelf<<
1310 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
1311 // " hidden="<<hidden<<
1323 // Position relatively, if needed
1324 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
1326 // Calc angle to mapCenter if I am a mainbranch
1327 // needed for reordering the mainbranches clockwise
1329 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
1330 (int)(y() - parObj->getChildPos().y() ) ) );
1335 // Align myself depending on orientation and parent, but
1336 // only if I am not a mainbranch or mapcenter itself
1338 if (anim.isAnimated())
1343 LinkableMapObj::Orientation o;
1344 o=parObj->getOrientation();
1346 switch (orientation)
1348 case LinkableMapObj::LeftOfCenter:
1349 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1350 //move (ref.x() , ref.y() + (th-bbox.height())/2 );
1352 case LinkableMapObj::RightOfCenter:
1353 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1356 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1362 if (scrolled) return;
1364 // Set reference point for alignment of children
1366 if (orientation==LinkableMapObj::LeftOfCenter)
1367 ref2.setX(bbox.topLeft().x() - linkwidth);
1369 ref2.setX(bbox.topRight().x() + linkwidth);
1372 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1374 ref2.setY(ref.y() );
1376 // Align the children depending on reference point
1377 for (int i=0; i<branch.size(); ++i)
1379 if (!branch.at(i)->isHidden())
1381 branch.at(i)->alignRelativeTo (ref2,true);
1383 // append next branch below current one
1384 ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChildren().height() );
1390 void BranchObj::reposition()
1392 /* TODO testing only
1393 if (!getHeading().isEmpty())
1394 cout << "BO::reposition "<<qPrintable(getHeading())<<endl;
1396 cout << "BO::reposition ???"<<endl;
1398 cout << " orient="<<orientation<<endl;
1403 // only calculate the sizes once. If the deepest LMO
1404 // changes its height,
1405 // all upper LMOs have to change, too.
1406 calcBBoxSizeWithChildren();
1407 updateLink(); // This update is needed if the scene is resized
1408 // due to excessive moving of a FIO
1410 alignRelativeTo ( QPointF (absPos.x(),
1411 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1412 qSort (branch.begin(),branch.end(), isAbove);
1413 positionBBox(); // Reposition bbox and contents
1416 // This is only important for moving branches:
1417 // For editing a branch it isn't called...
1418 alignRelativeTo ( QPointF (absPos.x(),
1419 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1423 void BranchObj::unsetAllRepositionRequests()
1425 repositionRequest=false;
1426 for (int i=0; i<branch.size(); ++i)
1427 branch.at(i)->unsetAllRepositionRequests();
1431 QPolygonF BranchObj::shape()
1435 QRectF r=getTotalBBox();
1436 if (orientation==LinkableMapObj::LeftOfCenter)
1439 <<QPointF (bbox.topLeft().x(), r.topLeft().y() )
1441 <<bbox.bottomRight()
1442 <<QPointF (bbox.bottomLeft().x(), r.bottomLeft().y() ) ;
1446 <<QPointF (bbox.topRight().x(), r.topRight().y() )
1449 <<QPointF (bbox.bottomRight().x(), r.bottomRight().y() ) ;
1453 QRectF BranchObj::getTotalBBox()
1457 if (scrolled) return r;
1459 for (int i=0; i<branch.size(); ++i)
1460 if (!branch.at(i)->isHidden())
1461 r=addBBox(branch.at(i)->getTotalBBox(),r);
1463 for (int i=0; i<floatimage.size(); ++i)
1464 if (!floatimage.at(i)->isHidden())
1465 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1470 QRectF BranchObj::getBBoxSizeWithChildren()
1475 void BranchObj::calcBBoxSizeWithChildren()
1477 // This is initially called only from reposition and
1478 // and only for mapcenter. So it won't be
1479 // called more than once for a single user
1483 // Calculate size of LMO including all children (to align them later)
1484 bboxTotal.setX(bbox.x() );
1485 bboxTotal.setY(bbox.y() );
1487 // if branch is scrolled, ignore children, but still consider floatimages
1490 bboxTotal.setWidth (bbox.width());
1491 bboxTotal.setHeight(bbox.height());
1497 bboxTotal.setWidth (0);
1498 bboxTotal.setHeight(0);
1501 bboxTotal.setX (parObj->x());
1502 bboxTotal.setY (parObj->y());
1505 bboxTotal.setX (bbox.x());
1506 bboxTotal.setY (bbox.y());
1513 // Now calculate recursivly
1515 // maximum of widths
1517 for (int i=0; i<branch.size(); ++i)
1519 if (!branch.at(i)->isHidden())
1521 branch.at(i)->calcBBoxSizeWithChildren();
1522 br=branch.at(i)->getBBoxSizeWithChildren();
1523 r.setWidth( max (br.width(), r.width() ));
1524 r.setHeight(br.height() + r.height() );
1525 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1528 // Add myself and also
1529 // add width of link to sum if necessary
1530 if (branch.isEmpty())
1531 bboxTotal.setWidth (bbox.width() + r.width() );
1533 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1535 bboxTotal.setHeight(max (r.height(), bbox.height()));
1538 void BranchObj::select() // FIXME try to get rid of this in BO completely
1540 cout << "BO::select()\n";
1541 // update NoteEditor FIXME do this via VymView::changeSelection
1542 textEditor->setText(note.getNote() );
1543 QString fnh=note.getFilenameHint();
1545 textEditor->setFilenameHint(note.getFilenameHint() );
1547 textEditor->setFilenameHint(getHeading() );
1548 textEditor->setFontHint (note.getFontHint() );
1549 isNoteInEditor=true;
1551 // set selected and visible
1552 LinkableMapObj::select();
1554 //if (po) po->setLastSelectedBranch(this); FIXME needed?
1556 // temporary unscroll, if we have scrolled parents somewhere
1557 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1559 /* FIXME moved to vymmodel or vymview...
1560 // Show URL and link in statusbar
1562 if (!url.isEmpty()) status+="URL: "+url+" ";
1563 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1564 if (!status.isEmpty()) mainWindow->statusMessage (status);
1567 updateFlagsToolbar();
1570 model->updateActions();
1574 void BranchObj::unselect()
1576 LinkableMapObj::unselect();
1577 // Delete any messages like vymLink in StatusBar
1578 mainWindow->statusMessage (""); //FIXME this causes segfault, when MainWindow is already gone in global destructor on quitting vym
1580 // Save current note
1581 if (isNoteInEditor) getNoteFromTextEditor();
1582 isNoteInEditor=false;
1584 // reset temporary unscroll, if we have scrolled parents somewhere
1585 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1587 // Erase content of editor
1588 textEditor->setInactive();
1590 // unselect all buttons in toolbar
1591 standardFlagsDefault->updateToolbar();
1594 QString BranchObj::getSelectString()
1596 return model->getSelectString (this);
1599 void BranchObj::setAnimation(const AnimPoint &ap)
1604 bool BranchObj::animate()
1607 if ( anim.isAnimated() )
1612 parObj->reposition(); // we might have been relinked meanwhile