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
370 if (mapEditor->getMapLinkColorHint()==HeadingColor)
371 LinkableMapObj::setLinkColor (heading->getColor() );
373 LinkableMapObj::setLinkColor ();
377 void BranchObj::setColorSubtree(QColor col)
379 OrnamentedObj::setColor (col);
380 for (int i=0; i<branch.size(); ++i)
381 branch.at(i)->setColorSubtree(col);
384 BranchObj* BranchObj::first()
391 BranchObj* BranchObj::next()
395 BranchObj *po=(BranchObj*)parObj;
397 if (branch.isEmpty())
404 // no itLast, we are just beginning
407 // we have childs, return first one
413 // No childs, so there is no next
421 { // We come from parent
424 // there are childs, go there
429 { // no childs, try to go up again
432 // go back to parent and try to find next there
441 // can't go up, I am mapCenter, no next
448 // We don't come from parent, but from brother or childs
450 // Try to find last child, where we came from, in my own childs
453 while (i<branch.size())
455 // Try to find itLast in my own childs
456 if (itLast==branch.at(i))
458 // ok, we come from my own childs
459 if (i<branch.size()-1)
469 { // found itLast in my childs
472 // found a brother of lastLMO
480 if (this==itFirst) return NULL; // Stop at starting point
489 // can't go up, I am mapCenter
496 // couldn't find last child, it must be a nephew of mine
499 // proceed with my first child
501 return branch.first();
505 // or go back to my parents
516 // can't go up, I am mapCenter
523 BranchObj* BranchObj::getLastIterator()
528 void BranchObj::setLastIterator(BranchObj* it)
533 void BranchObj::positionContents()
535 for (int i=0; i<floatimage.size(); ++i )
536 floatimage.at(i)->reposition();
537 OrnamentedObj::positionContents();
540 void BranchObj::move (double x, double y)
542 OrnamentedObj::move (x,y);
543 for (int i=0; i<floatimage.size(); ++i )
544 floatimage.at(i)->reposition();
548 void BranchObj::move (QPointF p)
553 void BranchObj::moveBy (double x, double y)
555 OrnamentedObj::moveBy (x,y);
556 for (int i=0; i<branch.size(); ++i)
557 branch.at(i)->moveBy (x,y);
561 void BranchObj::moveBy (QPointF p)
563 moveBy (p.x(), p.y());
567 void BranchObj::positionBBox()
569 QPointF ap=getAbsPos();
570 bbox.moveTopLeft (ap);
574 frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
576 // Update links to other branches
577 for (int i=0; i<xlink.size(); ++i)
578 xlink.at(i)->updateXLink();
581 void BranchObj::calcBBoxSize()
583 QSizeF heading_r=heading->getSize();
584 qreal heading_w=(qreal) heading_r.width() ;
585 qreal heading_h=(qreal) heading_r.height() ;
586 QSizeF sysflags_r=systemFlags->getSize();
587 qreal sysflags_h=sysflags_r.height();
588 qreal sysflags_w=sysflags_r.width();
589 QSizeF stanflags_r=standardFlags->getSize();
590 qreal stanflags_h=stanflags_r.height();
591 qreal stanflags_w=stanflags_r.width();
595 // set width to sum of all widths
596 w=heading_w + sysflags_w + stanflags_w;
597 // set height to maximum needed height
598 h=max (sysflags_h,stanflags_h);
601 // Save the dimension of flags and heading
602 ornamentsBBox.setSize ( QSizeF(w,h));
604 // clickBox includes Flags and Heading
605 clickBox.setSize (ornamentsBBox.size() );
610 topPad=botPad=leftPad=rightPad=0;
611 if (includeImagesVer || includeImagesHor)
613 if (countFloatImages()>0)
615 for (int i=0; i<floatimage.size(); ++i )
617 rp=floatimage.at(i)->getRelPos();
618 if (includeImagesVer)
621 topPad=max (topPad,-rp.y()-h);
622 if (rp.y()+floatimage.at(i)->height() > 0)
623 botPad=max (botPad,rp.y()+floatimage.at(i)->height());
625 if (includeImagesHor)
627 if (orientation==LinkableMapObj::RightOfCenter)
630 leftPad=max (leftPad,-rp.x()-w);
631 if (rp.x()+floatimage.at(i)->width() > 0)
632 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
636 leftPad=max (leftPad,-rp.x());
637 if (rp.x()+floatimage.at(i)->width() > w)
638 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
648 w+=frame->getPadding();
649 h+=frame->getPadding();
652 bbox.setSize (QSizeF (w,h));
655 void BranchObj::setDockPos()
657 // Sets childpos and parpos depending on orientation
658 if (getOrientation()==LinkableMapObj::LeftOfCenter )
661 ornamentsBBox.bottomLeft().x(),
664 ornamentsBBox.bottomRight().x(),
669 ornamentsBBox.bottomRight().x(),
672 ornamentsBBox.bottomLeft().x(),
677 LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
681 for (int i=0; i<branch.size(); ++i)
683 lmo=branch.at(i)->findMapObj(p, excludeLMO);
684 if (lmo != NULL) return lmo;
689 if (inBox (p) && (this != excludeLMO) && isVisibleObj() )
692 // Search float images
693 for (int i=0; i<floatimage.size(); ++i )
694 if (floatimage.at(i)->inBox(p) &&
695 (floatimage.at(i) != excludeLMO) &&
696 floatimage.at(i)->getParObj()!= excludeLMO &&
697 floatimage.at(i)->isVisibleObj()
698 ) return floatimage.at(i);
703 LinkableMapObj* BranchObj::findID (QString sid)
707 for (int i=0; i<branch.size(); ++i)
709 lmo=branch.at(i)->findID (sid);
710 if (lmo != NULL) return lmo;
714 if (sid==objID) return this;
718 // Search float images
719 for (int i=0; i<floatimage.size(); ++i )
720 if (floatimage.at(i)->inBox(p) &&
721 (floatimage.at(i) != excludeLMO) &&
722 floatimage.at(i)->getParObj()!= excludeLMO &&
723 floatimage.at(i)->isVisibleObj()
724 ) return floatimage.at(i);
729 void BranchObj::setHeading(QString s)
731 heading->setText(s); // set new heading
732 calcBBoxSize(); // recalculate bbox
733 positionBBox(); // rearrange contents
737 void BranchObj::setHideTmp (HideTmpMode mode)
739 if (mode==HideExport && hasHiddenExportParent())
741 setVisibility (false);
745 if (hasScrolledParent(this))
746 setVisibility (false);
748 setVisibility (true);
752 for (int i=0; i<branch.size(); ++i)
753 branch.at(i)->setHideTmp (mode);
756 bool BranchObj::hasHiddenExportParent()
758 // Calls parents recursivly to
759 // find out, if we are temp. hidden
761 if (hideExport) return true;
763 BranchObj* bo=(BranchObj*)parObj;
765 return bo->hasHiddenExportParent();
770 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
772 // Cloudy stuff can be hidden during exports
773 if (hidden) return "";
775 // Update of note is usually done while unselecting a branch
776 if (isNoteInEditor) getNoteFromTextEditor();
779 QString scrolledAttr;
781 scrolledAttr=attribut ("scrolled","yes");
785 // save area, if not scrolled
787 if (!((BranchObj*)(parObj))->isScrolled() )
790 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
791 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
792 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
793 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
798 // Providing an ID for a branch makes export to XHTML easier
801 idAttr=attribut ("id",getSelectString());
805 s=beginElement ("branch"
810 +getIncludeImageAttr() );
814 s+=valueElement("heading", getHeading(),
815 attribut ("textColor",QColor(heading->getColor()).name()));
818 if (frame->getFrameType()!=FrameObj::NoFrame)
819 s+=frame->saveToDir ();
821 // save names of flags set
822 s+=standardFlags->saveToDir(tmpdir,prefix,0);
825 for (int i=0; i<floatimage.size(); ++i)
826 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
829 if (!note.isEmpty() )
833 for (int i=0; i<branch.size(); ++i)
834 s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
837 QString ol; // old link
838 QString cl; // current link
839 for (int i=0; i<xlink.size(); ++i)
841 cl=xlink.at(i)->saveToDir();
848 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
853 s+=endElement ("branch");
857 void BranchObj::addXLink (XLinkObj *xlo)
863 void BranchObj::removeXLinkRef (XLinkObj *xlo)
865 xlink.removeAt (xlink.indexOf(xlo));
868 void BranchObj::deleteXLink(XLinkObj *xlo)
871 if (!xlo->isUsed()) delete (xlo);
874 void BranchObj::deleteXLinkAt (int i)
876 XLinkObj *xlo=xlink.at(i);
878 if (!xlo->isUsed()) delete(xlo);
881 XLinkObj* BranchObj::XLinkAt (int i)
886 int BranchObj::countXLink()
888 return xlink.count();
892 BranchObj* BranchObj::XLinkTargetAt (int i)
894 if (i>=0 && i<xlink.size())
897 return xlink.at(i)->otherBranch (this);
902 void BranchObj::setIncludeImagesVer(bool b)
910 bool BranchObj::getIncludeImagesVer()
912 return includeImagesVer;
915 void BranchObj::setIncludeImagesHor(bool b)
923 bool BranchObj::getIncludeImagesHor()
925 return includeImagesHor;
928 QString BranchObj::getIncludeImageAttr()
931 if (includeImagesVer)
932 a=attribut ("incImgV","true");
934 a=attribut ("incImgV","false");
935 if (includeImagesHor)
936 a+=attribut ("incImgH","true");
938 a+=attribut ("incImgH","false");
942 FloatImageObj* BranchObj::addFloatImage ()
944 FloatImageObj *newfi=new FloatImageObj (scene,this);
945 floatimage.append (newfi);
946 if (hasScrolledParent(this) )
947 newfi->setVisibility (false);
949 newfi->setVisibility(visible);
958 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
960 FloatImageObj *newfi=new FloatImageObj (scene,this);
961 floatimage.append (newfi);
963 if (hasScrolledParent(this) )
964 newfi->setVisibility (false);
966 newfi->setVisibility(visible);
975 FloatImageObj* BranchObj::getFirstFloatImage ()
977 return floatimage.first();
980 FloatImageObj* BranchObj::getLastFloatImage ()
982 return floatimage.last();
985 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
987 return floatimage.at(i);
990 void BranchObj::removeFloatImage (FloatImageObj *fio)
992 int i=floatimage.indexOf (fio);
993 if (i>-1) delete (floatimage.takeAt (i));
999 void BranchObj::savePosInAngle ()
1001 // Save position in angle
1002 for (int i=0; i<branch.size(); ++i)
1003 branch.at(i)->angle=i;
1006 void BranchObj::setDefAttr (BranchModification mod)
1011 case 0: fontsize=16; break;
1012 case 1: fontsize=12; break;
1013 default: fontsize=10; break;
1017 setLinkStyle(getDefLinkStyle());
1018 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
1019 font.setPointSize(fontsize);
1020 heading->setFont(font );
1023 setColor (((BranchObj*)(parObj))->getColor());
1028 BranchObj* BranchObj::addBranch()
1030 BranchObj* newbo=new BranchObj(scene,this);
1031 branch.append (newbo);
1032 newbo->setParObj(this);
1033 newbo->setDefAttr(NewBranch);
1034 newbo->setHeading ("new");
1036 newbo->setVisibility (false);
1038 newbo->setVisibility(visible);
1039 newbo->updateLink();
1040 requestReposition();
1044 BranchObj* BranchObj::addBranch(BranchObj* bo)
1046 BranchObj* newbo=new BranchObj(scene,this);
1047 branch.append (newbo);
1049 newbo->setParObj(this);
1050 newbo->setDefAttr(MovedBranch);
1052 newbo->setVisibility (false);
1054 newbo->setVisibility(bo->visible);
1055 newbo->updateLink();
1056 requestReposition();
1060 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
1063 bo->setParObj (this);
1065 bo->setDefAttr(MovedBranch);
1066 if (scrolled) tmpUnscroll();
1067 setLastSelectedBranch (bo);
1071 BranchObj* BranchObj::insertBranch(int pos)
1074 // Add new bo and resort branches
1075 BranchObj *newbo=addBranch ();
1076 newbo->angle=pos-0.5;
1077 qSort (branch.begin(),branch.end(), isAbove);
1081 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
1084 // Add new bo and resort branches
1086 BranchObj *newbo=addBranch (bo);
1087 qSort (branch.begin(),branch.end(), isAbove);
1091 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
1094 // Add new bo and resort branches
1097 bo->setParObj (this);
1099 bo->setDefAttr (MovedBranch);
1100 if (scrolled) tmpUnscroll();
1101 setLastSelectedBranch (bo);
1102 qSort (branch.begin(),branch.end(), isAbove);
1106 void BranchObj::removeBranchHere(BranchObj* borem)
1108 // This removes the branch bo from list, but
1109 // inserts its childs at the place of bo
1111 bo=borem->getLastBranch();
1112 int pos=borem->getNum();
1115 bo->linkTo (this,pos+1);
1116 bo=borem->getLastBranch();
1118 removeBranch (borem);
1121 void BranchObj::removeChilds()
1126 void BranchObj::removeBranch(BranchObj* bo)
1128 // if bo is not in branch remove returns false, we
1131 int i=branch.indexOf(bo);
1135 branch.removeAt (i);
1137 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
1138 requestReposition();
1141 void BranchObj::removeBranchPtr(BranchObj* bo)
1143 int i=branch.indexOf(bo);
1146 branch.removeAt (i);
1148 qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
1149 requestReposition();
1152 void BranchObj::setLastSelectedBranch (BranchObj* bo)
1154 lastSelectedBranch=branch.indexOf(bo);
1157 BranchObj* BranchObj::getLastSelectedBranch ()
1159 if (lastSelectedBranch>=0)
1161 if ( branch.size()>lastSelectedBranch)
1162 return branch.at(lastSelectedBranch);
1163 if (branch.size()>0)
1164 return branch.last();
1169 BranchObj* BranchObj::getFirstBranch ()
1171 if (branch.size()>0)
1172 return branch.first();
1177 BranchObj* BranchObj::getLastBranch ()
1179 if (branch.size()>0)
1180 return branch.last();
1185 BranchObj* BranchObj::getBranchNum (int i)
1187 if (i>=0 && i<branch.size())
1188 return branch.at(i);
1193 bool BranchObj::canMoveBranchUp()
1195 if (!parObj || depth==1) return false;
1196 BranchObj* par=(BranchObj*)parObj;
1197 if (this==par->getFirstBranch())
1203 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
1206 int i=branch.indexOf(bo1);
1208 { // -1 if bo1 not found
1209 branch.at(i)->angle--;
1210 branch.at(i-1)->angle++;
1211 qSort (branch.begin(),branch.end(), isAbove);
1212 return branch.at(i);
1217 bool BranchObj::canMoveBranchDown()
1219 if (!parObj|| depth==1) return false;
1220 BranchObj* par=(BranchObj*)parObj;
1221 if (this==par->getLastBranch())
1227 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
1230 int i=branch.indexOf(bo1);
1232 if (i <branch.size())
1235 branch.at(i)->angle++;
1236 branch.at(j)->angle--;
1237 qSort (branch.begin(),branch.end(), isAbove);
1238 return branch.at(i);
1243 void BranchObj::sortChildren()
1245 int childCount=branch.count();
1247 bool madeChanges=false;
1251 for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
1252 BranchObj* curChild=(BranchObj*)branch.at(curChildIndex);
1253 BranchObj* prevChild=(BranchObj*)branch.at(curChildIndex-1);
1254 if(prevChild->heading->text().compare(curChild->heading->text())>0)
1256 this->moveBranchUp(curChild);
1260 }while(madeChanges);
1264 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
1266 // Find current parent and
1267 // remove pointer to myself there
1268 if (!dst) return NULL;
1269 BranchObj *par=(BranchObj*)parObj;
1271 par->removeBranchPtr (this);
1275 // Create new pointer to myself at dst
1276 if (pos<0||dst->getDepth()==0)
1278 // links myself as last branch at dst
1279 dst->addBranchPtr (this);
1284 // inserts me at pos in parent of dst
1287 BranchObj *bo=dst->insertBranchPtr (this,pos);
1288 bo->setDefAttr(MovedBranch);
1297 void BranchObj::alignRelativeTo (QPointF ref)
1299 qreal th = bboxTotal.height();
1302 cout << "BO::alignRelTo "<<getHeading().ascii()<<endl;
1303 cout << " d="<<depth<<
1305 // " bbox.topLeft="<<bboxTotal.topLeft()<<
1306 " absPos="<<absPos<<
1307 " relPos="<<relPos<<
1308 " orient="<<orientation<<
1309 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
1310 // " hidden="<<hidden<<
1322 // Position relatively, if needed
1323 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
1325 // Calc angle to mapCenter if I am a mainbranch
1326 // needed for reordering the mainbranches clockwise
1328 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
1329 (int)(y() - parObj->getChildPos().y() ) ) );
1334 // Align myself depending on orientation and parent, but
1335 // only if I am not a mainbranch or mapcenter itself
1336 LinkableMapObj::Orientation o;
1337 o=parObj->getOrientation();
1338 switch (orientation)
1340 case LinkableMapObj::LeftOfCenter:
1341 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1343 case LinkableMapObj::RightOfCenter:
1344 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1347 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1352 if (scrolled) return;
1354 // Set reference point for alignment of childs
1356 if (orientation==LinkableMapObj::LeftOfCenter)
1357 ref2.setX(bbox.topLeft().x() - linkwidth);
1359 ref2.setX(bbox.topRight().x() + linkwidth);
1362 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1364 ref2.setY(ref.y() );
1366 // Align the childs depending on reference point
1367 for (int i=0; i<branch.size(); ++i)
1369 if (!branch.at(i)->isHidden())
1371 branch.at(i)->alignRelativeTo (ref2);
1372 ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChilds().height() );
1378 void BranchObj::reposition()
1380 /* TODO testing only
1381 if (!getHeading().isEmpty())
1382 cout << "BO::reposition "<<getHeading().ascii()<<endl;
1384 cout << "BO::reposition ???"<<endl;
1386 cout << " orient="<<orientation<<endl;
1391 // only calculate the sizes once. If the deepest LMO
1392 // changes its height,
1393 // all upper LMOs have to change, too.
1394 calcBBoxSizeWithChilds();
1395 updateLink(); // This update is needed if the scene is resized
1396 // due to excessive moving of a FIO
1398 alignRelativeTo ( QPointF (absPos.x(),
1399 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1400 qSort (branch.begin(),branch.end(), isAbove);
1401 positionBBox(); // Reposition bbox and contents
1404 // This is only important for moving branches:
1405 // For editing a branch it isn't called...
1406 alignRelativeTo ( QPointF (absPos.x(),
1407 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1411 void BranchObj::unsetAllRepositionRequests()
1413 repositionRequest=false;
1414 for (int i=0; i<branch.size(); ++i)
1415 branch.at(i)->unsetAllRepositionRequests();
1419 QRectF BranchObj::getTotalBBox()
1423 if (scrolled) return r;
1425 for (int i=0; i<branch.size(); ++i)
1426 if (!branch.at(i)->isHidden())
1427 r=addBBox(branch.at(i)->getTotalBBox(),r);
1429 for (int i=0; i<floatimage.size(); ++i)
1430 if (!floatimage.at(i)->isHidden())
1431 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1436 QRectF BranchObj::getBBoxSizeWithChilds()
1441 void BranchObj::calcBBoxSizeWithChilds()
1443 // This is initially called only from reposition and
1444 // and only for mapcenter. So it won't be
1445 // called more than once for a single user
1449 // Calculate size of LMO including all childs (to align them later)
1450 bboxTotal.setX(bbox.x() );
1451 bboxTotal.setY(bbox.y() );
1453 // if branch is scrolled, ignore childs, but still consider floatimages
1456 bboxTotal.setWidth (bbox.width());
1457 bboxTotal.setHeight(bbox.height());
1463 bboxTotal.setWidth (0);
1464 bboxTotal.setHeight(0);
1467 bboxTotal.setX (parObj->x());
1468 bboxTotal.setY (parObj->y());
1471 bboxTotal.setX (bbox.x());
1472 bboxTotal.setY (bbox.y());
1479 // Now calculate recursivly
1481 // maximum of widths
1483 for (int i=0; i<branch.size(); ++i)
1485 if (!branch.at(i)->isHidden())
1487 branch.at(i)->calcBBoxSizeWithChilds();
1488 br=branch.at(i)->getBBoxSizeWithChilds();
1489 r.setWidth( max (br.width(), r.width() ));
1490 r.setHeight(br.height() + r.height() );
1491 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1494 // Add myself and also
1495 // add width of link to sum if necessary
1496 if (branch.isEmpty())
1497 bboxTotal.setWidth (bbox.width() + r.width() );
1499 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1501 bboxTotal.setHeight(max (r.height(), bbox.height()));
1504 void BranchObj::select()
1506 // update NoteEditor
1507 textEditor->setText(note.getNote() );
1508 QString fnh=note.getFilenameHint();
1510 textEditor->setFilenameHint(note.getFilenameHint() );
1512 textEditor->setFilenameHint(getHeading() );
1513 textEditor->setFontHint (note.getFontHint() );
1514 isNoteInEditor=true;
1516 // set selected and visible
1517 LinkableMapObj::select();
1519 // Tell parent that I am selected now:
1520 BranchObj* po=(BranchObj*)(parObj);
1521 if (po) // TODO Try to get rid of this cast...
1522 po->setLastSelectedBranch(this);
1524 // temporary unscroll, if we have scrolled parents somewhere
1525 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1527 // Show URL and link in statusbar
1529 if (!url.isEmpty()) status+="URL: "+url+" ";
1530 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1531 if (!status.isEmpty()) mainWindow->statusMessage (status);
1534 updateFlagsToolbar();
1537 mapEditor->updateActions();
1540 void BranchObj::unselect()
1542 LinkableMapObj::unselect();
1543 // Delete any messages like vymLink in StatusBar
1544 mainWindow->statusMessage ("");
1546 // Save current note
1547 if (isNoteInEditor) getNoteFromTextEditor();
1548 isNoteInEditor=false;
1550 // reset temporary unscroll, if we have scrolled parents somewhere
1551 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1553 // Erase content of editor
1554 textEditor->setInactive();
1556 // unselect all buttons in toolbar
1557 standardFlagsDefault->updateToolbar();
1560 QString BranchObj::getSelectString()
1566 s= "bo:" + QString("%1").arg(getNum());
1568 s= ((BranchObj*)(parObj))->getSelectString() + ",bo:" + QString("%1").arg(getNum());
1575 void BranchObj::animate()
1578 cout << "BO::animate x,y="<<relPos.x()<<","<<relPos.y()<<endl;