2 #include "texteditor.h"
4 #include "mainwindow.h"
6 extern TextEditor *textEditor;
7 extern Main *mainWindow;
8 extern FlagRowObj *standardFlagsDefault;
9 extern QAction *actionEditOpenURL;
12 /////////////////////////////////////////////////////////////////
14 /////////////////////////////////////////////////////////////////
16 BranchObj* BranchObj::itLast=NULL;
19 BranchObj::BranchObj () :OrnamentedObj()
21 // cout << "Const BranchObj ()\n";
27 BranchObj::BranchObj (QCanvas* c):OrnamentedObj (c)
29 // cout << "Const BranchObj (c) called from MapCenterObj (c)\n";
34 BranchObj::BranchObj (QCanvas* c, LinkableMapObj* p):OrnamentedObj (c)
36 // cout << "Const BranchObj (c,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 (QPoint ((int)(x() - parObj->getChildPos().x() ),
45 (int)(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 int BranchObjPtrList::compareItems ( QPtrCollection::Item i, QPtrCollection::Item j)
77 // Make sure PtrList::find works
80 if ( ((BranchObj*)(i))->angle > ((BranchObj*)(j))->angle )
86 void BranchObj::init ()
88 branch.setAutoDelete (false);
89 floatimage.setAutoDelete (true);
90 xlink.setAutoDelete (false);
95 absPos+=parObj->getChildPos();
98 lastSelectedBranch=-1;
105 includeImagesVer=false;
106 includeImagesHor=false;
112 void BranchObj::copy (BranchObj* other)
114 OrnamentedObj::copy(other);
118 for (b=other->branch.first(); b;b=other->branch.next() )
119 // Make deep copy of b
120 // Because addBranch again calls copy for the childs,
121 // Those will get a deep copy, too
125 for (fi=other->floatimage.first(); fi;fi=other->floatimage.next() )
128 scrolled=other->scrolled;
129 tmpUnscrolled=other->tmpUnscrolled;
130 setVisibility (other->visible);
133 vymLink=other->vymLink;
140 void BranchObj::clear()
143 while (!xlink.isEmpty())
144 deleteXLink (xlink.first() );
147 while (!branch.isEmpty())
150 branch.removeFirst();
155 int BranchObj::getNum()
158 return ((BranchObj*)(parObj))->getNum ((BranchObj*)(this));
163 int BranchObj::getNum(BranchObj *bo)
165 // keep current pointer in branch,
166 // otherwise save might fail
168 int ind=branch.findRef (bo);
173 int BranchObj::getFloatImageNum(FloatImageObj *fio)
175 return floatimage.findRef (fio);
178 int BranchObj::countBranches()
180 return branch.count();
183 int BranchObj::countFloatImages()
185 return floatimage.count();
188 int BranchObj::countXLinks()
190 return xlink.count();
193 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPoint m, int off)
195 // Temporary link to lmo
196 // m is position of mouse pointer
197 // offset 0: default 1: below lmo -1 above lmo (if possible)
200 BranchObj* o=(BranchObj*)(lmo);
204 // ignore mapcenter and mainbranch
205 if (lmo->getDepth()<2) off=0;
212 depth=parObj->getDepth()+1;
214 // setLinkStyle calls updateLink, only set it once
215 if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
217 // Move temporary to new position at destination
218 // Usually the positioning would be done by reposition(),
219 // but then also the destination branch would "Jump" around...
220 // Better just do it approximately
222 { // new parent is the mapcenter itself
224 QPoint p= normalise ( QPoint (m.x() - o->getChildPos().x(),
225 m.y() - o->getChildPos().y() ));
226 if (p.x()<0) p.setX( p.x()-bbox.width() );
233 // new parent is just a branch, link to it
234 QRect t=o->getBBoxSizeWithChilds();
235 if (o->getLastBranch())
236 y=t.y() + t.height() ;
243 // we want to link above lmo
244 y=o->y() - height() + 5;
246 // we want to link below lmo
247 // Bottom of sel should be 5 pixels above
248 // the bottom of the branch _below_ the target:
249 // Don't try to find that branch, guess 12 pixels
250 y=o->getChildPos().y() -height() + 12;
252 if (o->getOrientation()==OrientLeftOfCenter)
253 move ( o->getChildPos().x() - linkwidth, y );
255 move (o->getChildPos().x() + linkwidth, y );
258 // updateLink is called implicitly in move
259 reposition(); // FIXME shouldn't be this a request?
262 void BranchObj::unsetParObjTmp()
269 depth=parObj->getDepth()+1;
270 setLinkStyle (getDefLinkStyle() );
275 void BranchObj::unScroll()
277 if (tmpUnscrolled) resetTmpUnscroll();
278 if (scrolled) toggleScroll();
281 void BranchObj::toggleScroll()
287 systemFlags->deactivate("scrolledright");
288 for (bo=branch.first(); bo; bo=branch.next() )
290 bo->setVisibility(true);
295 systemFlags->activate("scrolledright");
296 for (bo=branch.first(); bo; bo=branch.next() )
298 bo->setVisibility(false);
303 move (absPos.x(), absPos.y() );
307 bool BranchObj::isScrolled()
312 bool BranchObj::hasScrolledParent(BranchObj *start)
314 // Calls parents recursivly to
315 // find out, if we are scrolled at all.
316 // But ignore myself, just look at parents.
318 if (this !=start && scrolled) return true;
320 BranchObj* bo=(BranchObj*)(parObj);
322 return bo->hasScrolledParent(start);
327 void BranchObj::tmpUnscroll()
329 // Unscroll parent (recursivly)
330 BranchObj* bo=(BranchObj*)(parObj);
331 if (bo) bo->tmpUnscroll();
337 systemFlags->activate("tmpUnscrolledright");
342 void BranchObj::resetTmpUnscroll()
344 // Unscroll parent (recursivly)
345 BranchObj* bo=(BranchObj*)(parObj);
347 bo->resetTmpUnscroll();
353 systemFlags->deactivate("tmpUnscrolledright");
358 void BranchObj::setVisibility(bool v, int toDepth)
360 if (depth <= toDepth)
362 frame->setVisibility(v);
363 heading->setVisibility(v);
364 systemFlags->setVisibility(v);
365 standardFlags->setVisibility(v);
366 LinkableMapObj::setVisibility (v);
368 if (!scrolled && (depth < toDepth))
370 // Now go recursivly through all childs
372 for (b=branch.first(); b;b=branch.next() )
373 b->setVisibility (v,toDepth);
375 for (fio=floatimage.first(); fio; fio=floatimage.next())
376 fio->setVisibility (v);
378 for (xlo=xlink.first(); xlo;xlo=xlink.next() )
379 xlo->setVisibility ();
381 } // depth <= toDepth
385 void BranchObj::setVisibility(bool v)
387 setVisibility (v,MAX_DEPTH);
391 void BranchObj::setLinkColor ()
393 // Overloaded from LinkableMapObj
394 // BranchObj can use color of heading
397 if (mapEditor->getLinkColorHint()==HeadingColor)
398 LinkableMapObj::setLinkColor (heading->getColor() );
400 LinkableMapObj::setLinkColor ();
403 void BranchObj::setColor (QColor col, bool colorChilds)
405 heading->setColor(col);
410 for (bo=branch.first(); bo; bo=branch.next() )
411 bo->setColor(col,colorChilds);
415 QColor BranchObj::getColor()
417 return heading->getColor();
420 BranchObj* BranchObj::first()
426 BranchObj* BranchObj::next()
429 BranchObj *bo=branch.first();
430 BranchObj *po=(BranchObj*)(parObj);
433 { // We are just beginning at the mapCenter
447 { // We come from above
450 // there are childs, go there
455 { // no childs, try to go up again
467 // can't go up, I am mapCenter
474 // Try to find last child, we came from, in my own childs
476 while (bo && searching)
478 if (itLast==bo) searching=false;
482 { // found lastLMO in my childs
485 // found a brother of lastLMO
501 // can't go up, I am mapCenter
508 // couldn't find last child, it must be a nephew of mine
512 // proceed with my first child
518 // or go back to my parents
529 // can't go up, I am mapCenter
536 BranchObj* BranchObj::getLastIterator()
541 void BranchObj::setLastIterator(BranchObj* it)
547 void BranchObj::move (double x, double y)
549 OrnamentedObj::move (x,y);
551 for (fio=floatimage.first(); fio; fio=floatimage.next() )
556 void BranchObj::move (QPoint p)
561 void BranchObj::moveBy (double x, double y)
563 OrnamentedObj::moveBy (x,y);
566 for (b=branch.first(); b;b=branch.next() )
570 void BranchObj::moveBy (QPoint p)
572 moveBy (p.x(), p.y());
576 void BranchObj::positionBBox()
578 QPoint ap=getAbsPos();
579 bbox.moveTopLeft (ap);
584 frame->setRect(QRect(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
586 // Update links to other branches
588 for (xlo=xlink.first(); xlo; xlo=xlink.next() )
592 void BranchObj::calcBBoxSize()
594 QSize heading_r=heading->getSize();
595 int heading_w=(int) heading_r.width() ;
596 int heading_h=(int) heading_r.height() ;
597 QSize sysflags_r=systemFlags->getSize();
598 int sysflags_h=sysflags_r.height();
599 int sysflags_w=sysflags_r.width();
600 QSize stanflags_r=standardFlags->getSize();
601 int stanflags_h=stanflags_r.height();
602 int 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 ( QSize(w,h));
615 // clickBox includes Flags and Heading
616 clickBox.setSize (ornamentsBBox.size() );
622 topPad=botPad=leftPad=rightPad=0;
623 if (includeImagesVer || includeImagesHor)
625 if (countFloatImages()>0)
627 for (foi=floatimage.first(); foi; foi=floatimage.next() )
630 if (includeImagesVer)
633 topPad=max (topPad,-rp.y()-h);
634 if (rp.y()+foi->height() > 0)
635 botPad=max (botPad,rp.y()+foi->height());
637 if (includeImagesHor)
639 if (orientation==OrientRightOfCenter)
642 leftPad=max (leftPad,-rp.x()-w);
643 if (rp.x()+foi->width() > 0)
644 rightPad=max (rightPad,rp.x()+foi->width());
648 leftPad=max (leftPad,-rp.x());
649 if (rp.x()+foi->width() > w)
650 rightPad=max (rightPad,rp.x()+foi->width()-w);
660 w+=frame->getBorder();
661 h+=frame->getBorder();
664 bbox.setSize (QSize (w,h));
667 void BranchObj::setDockPos()
669 if (getOrientation()==OrientLeftOfCenter )
671 childPos=QPoint (ornamentsBBox.bottomLeft().x(), ornamentsBBox.bottomLeft().y() );
672 parPos=QPoint (ornamentsBBox.bottomRight().x(),ornamentsBBox.bottomRight().y() );
675 childPos=QPoint (ornamentsBBox.bottomRight().x(), ornamentsBBox.bottomRight().y() );
676 parPos=QPoint (ornamentsBBox.bottomLeft().x(),ornamentsBBox.bottomLeft().y() );
679 LinkableMapObj* BranchObj::findMapObj(QPoint p, LinkableMapObj* excludeLMO)
684 for (b=branch.first(); b; b=branch.next() )
686 lmo=b->findMapObj(p, excludeLMO);
687 if (lmo != NULL) return lmo;
691 if (inBox (p) && (this != excludeLMO) && isVisibleObj() )
694 // Search float images
696 for (foi=floatimage.first(); foi; foi=floatimage.next() )
698 (foi != excludeLMO) &&
699 foi->getParObj()!= excludeLMO &&
706 void BranchObj::setHeading(QString s)
708 heading->setText(s); // set new heading
709 calcBBoxSize(); // recalculate bbox
710 positionBBox(); // rearrange contents
714 void BranchObj::setURL(QString s)
718 systemFlags->activate("url");
720 systemFlags->deactivate("url");
721 calcBBoxSize(); // recalculate bbox
722 positionBBox(); // rearrange contents
726 QString BranchObj::getURL()
731 void BranchObj::setVymLink(QString s)
735 // We need the relative (from loading)
736 // or absolute path (from User event)
737 // and build the absolute path.
738 // Note: If we have relative, use path of
739 // current map to build absolute path
741 if (!d.path().startsWith ("/"))
743 QString p=mapEditor->getDestPath();
744 int i=p.findRev("/",-1);
745 d.setPath(p.left(i)+"/"+s);
749 systemFlags->activate("vymLink");
753 systemFlags->deactivate("vymLink");
756 calcBBoxSize(); // recalculate bbox
757 positionBBox(); // rearrange contents
761 QString BranchObj::getVymLink()
766 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPoint& offset)
769 QString scrolledAttr;
771 scrolledAttr=attribut ("scrolled","yes");
776 if (depth<2) posAttr=
777 attribut("absPosX",QString().setNum(absPos.x(),10)) +
778 attribut("absPosY",QString().setNum(absPos.y(),10));
782 QString linkAttr=getLinkAttr()+" "+getIncludeImageAttr();
787 urlAttr=attribut ("url",url);
790 if (!vymLink.isEmpty())
791 vymLinkAttr=attribut ("vymLink",convertToRel(mapEditor->getDestPath(),vymLink) );
794 if (frame->getFrameType()!=NoFrame)
795 frameAttr=attribut ("frameType",frame->getFrameTypeName());
799 // save area, if not scrolled
801 if (!((BranchObj*)(parObj))->isScrolled() )
804 attribut("x1",QString().setNum(absPos.x()-offset.x(),10)) +
805 attribut("y1",QString().setNum(absPos.y()-offset.y(),10)) +
806 attribut("x2",QString().setNum(absPos.x()+width()-offset.x(),10)) +
807 attribut("y2",QString().setNum(absPos.y()+height()-offset.y(),10));
812 // Providing an ID for a branch makes export to XHTML easier
815 idAttr=attribut ("id",getSelectString());
819 s=beginElement ("branch" +scrolledAttr +posAttr +linkAttr +urlAttr +vymLinkAttr +frameAttr +areaAttr +idAttr);
823 s+=valueElement("heading", getHeading(),
824 attribut ("textColor",QColor(heading->getColor()).name()));
826 // save names of flags set
827 s+=standardFlags->saveToDir(tmpdir,prefix,0);
830 if (!note.isEmpty() )
835 for (bo=branch.first(); bo; bo=branch.next() )
836 s+=bo->saveToDir(tmpdir,prefix,offset);
840 for (fio=floatimage.first(); fio; fio=floatimage.next() )
841 s+=fio->saveToDir (tmpdir,prefix,offset);
845 for (xlo=xlink.first(); xlo; xlo=xlink.next() )
849 s+=endElement ("branch");
853 void BranchObj::addXLink (XLinkObj *xlo)
859 void BranchObj::removeXLinkRef (XLinkObj *xlo)
864 void BranchObj::deleteXLink(XLinkObj *xlo)
867 if (!xlo->isUsed()) delete (xlo);
870 void BranchObj::deleteXLinkAt (int i)
872 XLinkObj *xlo=xlink.at(i);
874 if (!xlo->isUsed()) delete(xlo);
877 XLinkObj* BranchObj::XLinkAt (int i)
882 int BranchObj::countXLink()
884 return xlink.count();
888 BranchObj* BranchObj::XLinkTargetAt (int i)
891 return xlink.at(i)->otherBranch (this);
896 void BranchObj::setIncludeImagesVer(bool b)
905 bool BranchObj::getIncludeImagesVer()
907 return includeImagesVer;
910 void BranchObj::setIncludeImagesHor(bool b)
919 bool BranchObj::getIncludeImagesHor()
921 return includeImagesHor;
924 QString BranchObj::getIncludeImageAttr()
927 if (includeImagesVer)
928 a=attribut ("incImgV","true");
930 a=attribut ("incImgV","false");
931 if (includeImagesHor)
932 a+=attribut ("incImgH","true");
934 a+=attribut ("incImgH","false");
938 LinkableMapObj* BranchObj::addFloatImage ()
940 FloatImageObj *newfi=new FloatImageObj (canvas,this);
941 floatimage.append (newfi);
942 if (hasScrolledParent(this) )
943 newfi->setVisibility (false);
945 newfi->setVisibility(visible);
953 LinkableMapObj* BranchObj::addFloatImage (FloatImageObj *fio)
955 FloatImageObj *newfi=new FloatImageObj (canvas,this);
956 floatimage.append (newfi);
958 if (hasScrolledParent(this) )
959 newfi->setVisibility (false);
961 newfi->setVisibility(visible);
969 FloatImageObj* BranchObj::getFirstFloatImage ()
971 return floatimage.first();
974 FloatImageObj* BranchObj::getLastFloatImage ()
976 return floatimage.last();
979 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
981 return floatimage.at(i);
984 void BranchObj::removeFloatImage (FloatImageObj *fio)
986 floatimage.remove (fio);
993 void BranchObj::savePosInAngle ()
995 // Save position in angle
998 for (b=branch.first(); b; b=branch.next() )
1005 void BranchObj::setDefAttr (BranchModification mod)
1010 case 0: fontsize=16; break;
1011 case 1: fontsize=12; break;
1012 default: fontsize=10; break;
1016 setLinkStyle(getDefLinkStyle());
1017 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
1018 font.setPointSize(fontsize);
1019 heading->setFont(font );
1022 setColor (((BranchObj*)(parObj))->getColor(),false);
1027 BranchObj* BranchObj::addBranch()
1029 BranchObj* newbo=new BranchObj(canvas,this);
1030 branch.append (newbo);
1031 newbo->setParObj(this);
1032 newbo->setDefAttr(NewBranch);
1033 newbo->setHeading ("new");
1035 newbo->setVisibility (false);
1037 newbo->setVisibility(visible);
1038 newbo->updateLink();
1039 requestReposition();
1043 BranchObj* BranchObj::addBranch(BranchObj* bo)
1045 BranchObj* newbo=new BranchObj(canvas,this);
1046 branch.append (newbo);
1048 newbo->setParObj(this);
1049 newbo->setDefAttr(MovedBranch);
1051 newbo->setVisibility (false);
1053 newbo->setVisibility(bo->visible);
1054 newbo->updateLink();
1055 requestReposition();
1059 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
1062 bo->setParObj (this);
1064 bo->setDefAttr(MovedBranch);
1065 if (scrolled) tmpUnscroll();
1066 setLastSelectedBranch (bo);
1070 BranchObj* BranchObj::insertBranch(int pos)
1073 // Add new bo and resort branches
1074 BranchObj *newbo=addBranch ();
1075 newbo->angle=pos-0.5;
1080 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
1083 // Add new bo and resort branches
1085 BranchObj *newbo=addBranch (bo);
1090 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
1093 // Add new bo and resort branches
1096 bo->setParObj (this);
1098 bo->setDefAttr (MovedBranch);
1099 if (scrolled) tmpUnscroll();
1100 setLastSelectedBranch (bo);
1105 void BranchObj::removeBranchHere(BranchObj* borem)
1107 // This removes the branch bo from list, but
1108 // inserts its childs at the place of bo
1110 bo=borem->getLastBranch();
1111 int pos=borem->getNum();
1114 bo->moveBranchTo (this,pos+1);
1115 bo=borem->getLastBranch();
1117 removeBranch (borem);
1120 void BranchObj::removeChilds()
1125 void BranchObj::removeBranch(BranchObj* bo)
1127 // if bo is not in branch remove returns false, we
1130 if (branch.remove (bo))
1133 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
1134 requestReposition();
1137 void BranchObj::removeBranchPtr(BranchObj* bo)
1140 requestReposition();
1143 void BranchObj::setLastSelectedBranch (BranchObj* bo)
1145 lastSelectedBranch=branch.find(bo);
1148 BranchObj* BranchObj::getLastSelectedBranch ()
1150 if (lastSelectedBranch>=0)
1152 BranchObj* bo=branch.at(lastSelectedBranch);
1155 return branch.first();
1158 BranchObj* BranchObj::getFirstBranch ()
1160 return branch.first();
1163 BranchObj* BranchObj::getLastBranch ()
1165 return branch.last();
1168 BranchObj* BranchObj::getBranchNum (const uint &i)
1170 return branch.at(i);
1174 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // move a branch up (modify myself)
1177 int i=branch.find(bo1);
1179 { // -1 if bo1 not found
1180 branch.at(i)->angle--;
1181 branch.at(i-1)->angle++;
1183 return branch.at(i-1);
1185 return branch.at(i);
1188 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)
1191 int i=branch.find(bo1);
1196 branch.at(i)->angle++;
1197 branch.at(j)->angle--;
1199 return branch.at(j);
1201 return branch.at(i);
1204 BranchObj* BranchObj::moveBranchTo (BranchObj* dst, int pos)
1206 // Find current parent and
1207 // remove pointer to myself there
1208 if (!dst) return NULL;
1209 BranchObj *par=(BranchObj*)(parObj);
1211 par->removeBranchPtr (this);
1215 // Create new pointer to myself at dst
1216 if (pos<0||dst->getDepth()==0)
1218 // links myself as last branch at dst
1219 dst->addBranchPtr (this);
1224 // inserts me at pos in parent of dst
1227 BranchObj *bo=dst->insertBranchPtr (this,pos);
1228 bo->setDefAttr(MovedBranch);
1237 void BranchObj::alignRelativeTo (QPoint ref)
1239 int th = bboxTotal.height();
1242 cout << "BO::alignRelTo "<<getHeading()<<endl;
1243 cout << " d="<<depth<<
1245 " bbTot="<<bboxTotal.topLeft()<<
1246 " absPos="<<absPos<<
1247 " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
1251 // If I am the mapcenter or a mainbranch, reposition heading
1253 { //FIXME optimize this move for MCO needed to initially position text in box...
1256 move (absPos.x(),absPos.y());
1257 // Calc angle to mapCenter if I am a mainbranch
1258 // needed for reordering the mainbranches clockwise
1260 angle=getAngle (QPoint ((int)(x() - parObj->getChildPos().x() ),
1261 (int)(y() - parObj->getChildPos().y() ) ) );
1266 // Align myself depending on orientation and parent, but
1267 // only if I am not the mainbranch or mapcenter itself
1268 switch (orientation)
1270 case OrientLeftOfCenter:
1271 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1273 case OrientRightOfCenter:
1274 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1277 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1282 if (scrolled) return;
1284 // Set reference point for alignment of childs
1286 if (orientation==OrientLeftOfCenter)
1287 ref2.setX(bbox.topLeft().x() - linkwidth);
1289 ref2.setX(bbox.topRight().x() + linkwidth);
1292 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1294 ref2.setY(ref.y() );
1296 // Align the childs depending on reference point
1298 for (b=branch.first(); b; b=branch.next() )
1300 b->alignRelativeTo (ref2);
1301 ref2.setY(ref2.y() + b->getBBoxSizeWithChilds().height() );
1306 void BranchObj::reposition()
1308 /* TODO testing only
1309 if (!getHeading().isEmpty())
1310 cout << "BO::reposition "<<getHeading()<<endl;
1312 cout << "BO::reposition ???"<<endl;
1316 // only calculate the sizes once. If the deepest LMO
1317 // changes its height,
1318 // all upper LMOs have to change, too.
1319 calcBBoxSizeWithChilds();
1320 alignRelativeTo ( QPoint (absPos.x(),
1321 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1323 updateLink(); // This update is needed if the canvas is resized
1324 // due to excessive moving of a FIO
1326 // After load, the floats might be at wrong position, force
1327 // them to move, too
1328 //move (absPos); // FIXME really still needed to position floats?
1331 // This is only important for moving branches:
1332 // For editing a branch it isn't called...
1333 alignRelativeTo ( QPoint (absPos.x(),
1334 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1339 QRect BranchObj::getTotalBBox()
1343 if (scrolled) return r;
1346 for (b=branch.first();b ;b=branch.next() )
1347 r=addBBox(b->getTotalBBox(),r);
1350 for (fio=floatimage.first();fio ;fio=floatimage.next() )
1351 r=addBBox(fio->getTotalBBox(),r);
1356 QRect BranchObj::getBBoxSizeWithChilds()
1361 void BranchObj::calcBBoxSizeWithChilds()
1363 // This is initially called only from reposition and
1364 // and only for mapcenter. So it won't be
1365 // called more than once for a single user
1369 // Calculate size of LMO including all childs (to align them later)
1370 bboxTotal.setX(bbox.x() );
1371 bboxTotal.setY(bbox.y() );
1373 // if branch is scrolled, ignore childs, but still consider floatimages
1376 bboxTotal.setWidth (bbox.width());
1377 bboxTotal.setHeight(bbox.height());
1383 // Now calculate recursivly
1385 // maximum of widths
1388 for (b=branch.first();b ;b=branch.next() )
1390 b->calcBBoxSizeWithChilds();
1391 br=b->getBBoxSizeWithChilds();
1392 r.setWidth( max (br.width(), r.width() ));
1393 r.setHeight(br.height() + r.height() );
1394 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1396 // Add myself and also
1397 // add width of link to sum if necessary
1398 if (branch.isEmpty())
1399 bboxTotal.setWidth (bbox.width() + r.width() );
1401 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1403 bboxTotal.setHeight(max (r.height(), bbox.height()));
1404 // frame->setRect(QRect(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
1408 void BranchObj::select()
1410 // set Text in Editor
1411 textEditor->setText(note.getNote() );
1412 QString fnh=note.getFilenameHint();
1414 textEditor->setFilenameHint(note.getFilenameHint() );
1416 textEditor->setFilenameHint(getHeading() );
1417 textEditor->setFontHint (note.getFontHint() );
1419 LinkableMapObj::select();
1420 // Tell parent that I am selected now:
1421 BranchObj* po=(BranchObj*)(parObj);
1422 if (po) // TODO Try to get rid of this cast...
1423 po->setLastSelectedBranch(this);
1425 // temporary unscroll, if we have scrolled parents somewhere
1426 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1428 // Show URL and link in statusbar
1430 if (!url.isEmpty()) status+="URL: "+url+" ";
1431 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1432 if (!status.isEmpty()) mainWindow->statusMessage (status);
1435 standardFlags->updateToolbar();
1437 // Update Browserbutton
1439 actionEditOpenURL->setEnabled (true);
1441 actionEditOpenURL->setEnabled (false);
1443 // Update actions in mapeditor
1444 mapEditor->updateActions();
1447 void BranchObj::unselect()
1449 LinkableMapObj::unselect();
1450 // Delete any messages like vymLink in StatusBar
1451 mainWindow->statusMessage ("");
1453 // save note from editor and set flag
1454 // text is done by updateNoteFlag(), just save
1456 note.setFilenameHint (textEditor->getFilename());
1458 // reset temporary unscroll, if we have scrolled parents somewhere
1459 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1461 // Erase content of editor
1462 textEditor->setInactive();
1464 // unselect all buttons in toolbar
1465 standardFlagsDefault->updateToolbar();
1468 QString BranchObj::getSelectString()
1474 s= "bo:" + QString("%1").arg(getNum());
1476 s= ((BranchObj*)(parObj))->getSelectString() + ",bo:" + QString("%1").arg(getNum());