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()
26 // cout << "Const BranchObj ()\n";
32 BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s)
34 // cout << "Const BranchObj (s) called from MapCenterObj (s)\n";
39 BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)
41 // cout << "Const BranchObj (s,p)\n";
44 depth=p->getDepth()+1;
46 // Calc angle to mapCenter if I am a mainbranch
47 // needed for reordering the mainbranches clockwise
49 angle=getAngle (QPointF (x() - parObj->getChildPos().x() ,
50 (y() - parObj->getChildPos().y() ) ) );
54 BranchObj::~BranchObj ()
56 //cout << "Destr BranchObj of "<<this<<endl;
57 // Check, if this branch was the last child to be deleted
58 // If so, unset the scrolled flags
60 BranchObj *po=(BranchObj*)parObj;
64 bo=((BranchObj*)parObj)->getLastBranch();
65 if (bo) po->unScroll();
70 bool BranchObj::operator< ( const BranchObj & other )
72 return angle < other.angle;
75 bool BranchObj::operator== ( const BranchObj & other )
77 return angle == other.angle;
80 void BranchObj::init ()
85 absPos+=parObj->getChildPos();
95 includeImagesVer=false;
96 includeImagesHor=false;
99 void BranchObj::copy (BranchObj* other)
101 OrnamentedObj::copy(other);
104 for (int i=0; i<other->branch.size(); ++i)
105 // Make deep copy of b
106 // Because addBranch again calls copy for the childs,
107 // Those will get a deep copy, too
108 addBranch(other->branch.at(i) );
110 for (int i=0; i<other->floatimage.size(); ++i)
111 addFloatImage (other->floatimage.at(i));
112 scrolled=other->scrolled;
113 tmpUnscrolled=other->tmpUnscrolled;
114 setVisibility (other->visible);
121 void BranchObj::clear()
123 setVisibility (true);
125 while (!floatimage.isEmpty())
126 delete floatimage.takeFirst();
128 while (!xlink.isEmpty())
129 delete xlink.takeFirst();
131 while (!branch.isEmpty())
132 delete branch.takeFirst();
135 bool isAbove (BranchObj* a, BranchObj *b)
137 if (a->angle < b->angle)
143 int BranchObj::getNum()
146 return ((BranchObj*)parObj)->getNum (this);
151 int BranchObj::getNum(BranchObj *bo)
153 return branch.indexOf (bo);
156 int BranchObj::getFloatImageNum(FloatImageObj *fio)
158 return floatimage.indexOf(fio);
161 int BranchObj::countBranches()
163 return branch.count();
166 int BranchObj::countFloatImages()
168 return floatimage.count();
171 int BranchObj::countXLinks()
173 return xlink.count();
176 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
178 // Temporary link to lmo
179 // m is position of mouse pointer
180 // offset 0: default 1: below lmo -1 above lmo (if possible)
183 BranchObj* o=(BranchObj*)(lmo);
187 // ignore mapcenter and mainbranch
188 if (lmo->getDepth()<2) off=0;
195 depth=parObj->getDepth()+1;
197 // setLinkStyle calls updateLink, only set it once
198 if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
200 // Move temporary to new position at destination
201 // Usually the positioning would be done by reposition(),
202 // but then also the destination branch would "Jump" around...
203 // Better just do it approximately
205 { // new parent is the mapcenter itself
207 QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
208 m.y() - o->getChildPos().y() ));
209 if (p.x()<0) p.setX( p.x()-bbox.width() );
216 // new parent is just a branch, link to it
217 QRectF t=o->getBBoxSizeWithChilds();
218 if (o->getLastBranch())
219 y=t.y() + t.height() ;
226 // we want to link above lmo
227 y=o->y() - height() + 5;
229 // we want to link below lmo
230 // Bottom of sel should be 5 pixels above
231 // the bottom of the branch _below_ the target:
232 // Don't try to find that branch, guess 12 pixels
233 y=o->getChildPos().y() -height() + 12;
235 if (o->getOrientation()==LinkableMapObj::LeftOfCenter)
236 move ( o->getChildPos().x() - linkwidth, y );
238 move (o->getChildPos().x() + linkwidth, y );
241 // updateLink is called implicitly in move
245 void BranchObj::unsetParObjTmp()
252 depth=parObj->getDepth()+1;
253 setLinkStyle (getDefLinkStyle() );
258 void BranchObj::unScroll()
260 if (tmpUnscrolled) resetTmpUnscroll();
261 if (scrolled) toggleScroll();
264 void BranchObj::toggleScroll()
269 systemFlags->deactivate("scrolledright");
270 for (int i=0; i<branch.size(); ++i)
271 branch.at(i)->setVisibility(true);
275 systemFlags->activate("scrolledright");
276 for (int i=0; i<branch.size(); ++i)
277 branch.at(i)->setVisibility(false);
281 move (absPos.x(), absPos.y() );
285 bool BranchObj::isScrolled()
290 bool BranchObj::hasScrolledParent(BranchObj *start)
292 // Calls parents recursivly to
293 // find out, if we are scrolled at all.
294 // But ignore myself, just look at parents.
296 if (this !=start && scrolled) return true;
298 BranchObj* bo=(BranchObj*)(parObj);
300 return bo->hasScrolledParent(start);
305 void BranchObj::tmpUnscroll()
307 // Unscroll parent (recursivly)
308 BranchObj* bo=(BranchObj*)(parObj);
309 if (bo) bo->tmpUnscroll();
315 systemFlags->activate("tmpUnscrolledright");
320 void BranchObj::resetTmpUnscroll()
322 // Unscroll parent (recursivly)
323 BranchObj* bo=(BranchObj*)(parObj);
325 bo->resetTmpUnscroll();
331 systemFlags->deactivate("tmpUnscrolledright");
336 void BranchObj::setVisibility(bool v, int toDepth)
338 if (depth <= toDepth)
340 frame->setVisibility(v);
341 heading->setVisibility(v);
342 systemFlags->setVisibility(v);
343 standardFlags->setVisibility(v);
344 LinkableMapObj::setVisibility (v);
346 // Only change childs, if I am not scrolled
347 if (!scrolled && (depth < toDepth))
349 // Now go recursivly through all childs
351 for (i=0; i<branch.size(); ++i)
352 branch.at(i)->setVisibility (v,toDepth);
353 for (i=0; i<floatimage.size(); ++i)
354 floatimage.at(i)->setVisibility (v);
355 for (i=0; i<xlink.size(); ++i)
356 xlink.at(i)->setVisibility ();
358 } // depth <= toDepth
362 void BranchObj::setVisibility(bool v)
364 setVisibility (v,MAX_DEPTH);
368 void BranchObj::setLinkColor ()
370 // Overloaded from LinkableMapObj
371 // BranchObj can use color of heading
375 if (mapEditor->getMapLinkColorHint()==HeadingColor)
376 LinkableMapObj::setLinkColor (heading->getColor() );
378 LinkableMapObj::setLinkColor ();
382 void BranchObj::setColorSubtree(QColor col)
385 for (int i=0; i<branch.size(); ++i)
386 branch.at(i)->setColorSubtree(col);
389 BranchObj* BranchObj::first()
396 BranchObj* BranchObj::next()
400 BranchObj *po=(BranchObj*)parObj;
402 if (branch.isEmpty())
409 // no itLast, we are just beginning
412 // we have childs, return first one
418 // No childs, so there is no next
426 { // We come from parent
429 // there are childs, go there
434 { // no childs, try to go up again
437 // go back to parent and try to find next there
446 // can't go up, I am mapCenter, no next
453 // We don't come from parent, but from brother or childs
455 // Try to find last child, where we came from, in my own childs
458 while (i<branch.size())
460 // Try to find itLast in my own childs
461 if (itLast==branch.at(i))
463 // ok, we come from my own childs
464 if (i<branch.size()-1)
474 { // found itLast in my childs
477 // found a brother of lastLMO
485 if (this==itFirst) return NULL; // Stop at starting point
494 // can't go up, I am mapCenter
501 // couldn't find last child, it must be a nephew of mine
504 // proceed with my first child
506 return branch.first();
510 // or go back to my parents
521 // can't go up, I am mapCenter
528 BranchObj* BranchObj::getLastIterator()
533 void BranchObj::setLastIterator(BranchObj* it)
538 void BranchObj::positionContents()
540 for (int i=0; i<floatimage.size(); ++i )
541 floatimage.at(i)->reposition();
542 OrnamentedObj::positionContents();
545 void BranchObj::move (double x, double y)
547 OrnamentedObj::move (x,y);
548 for (int i=0; i<floatimage.size(); ++i )
549 floatimage.at(i)->reposition();
553 void BranchObj::move (QPointF p)
558 void BranchObj::moveBy (double x, double y)
560 OrnamentedObj::moveBy (x,y);
561 for (int i=0; i<branch.size(); ++i)
562 branch.at(i)->moveBy (x,y);
566 void BranchObj::moveBy (QPointF p)
568 moveBy (p.x(), p.y());
572 void BranchObj::positionBBox()
574 QPointF ap=getAbsPos();
575 bbox.moveTopLeft (ap);
579 frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
581 // Update links to other branches
582 for (int i=0; i<xlink.size(); ++i)
583 xlink.at(i)->updateXLink();
586 void BranchObj::calcBBoxSize()
588 QSizeF heading_r=heading->getSize();
589 qreal heading_w=(qreal) heading_r.width() ;
590 qreal heading_h=(qreal) heading_r.height() ;
591 QSizeF sysflags_r=systemFlags->getSize();
592 qreal sysflags_h=sysflags_r.height();
593 qreal sysflags_w=sysflags_r.width();
594 QSizeF stanflags_r=standardFlags->getSize();
595 qreal stanflags_h=stanflags_r.height();
596 qreal stanflags_w=stanflags_r.width();
600 // set width to sum of all widths
601 w=heading_w + sysflags_w + stanflags_w;
602 // set height to maximum needed height
603 h=max (sysflags_h,stanflags_h);
606 // Save the dimension of flags and heading
607 ornamentsBBox.setSize ( QSizeF(w,h));
609 // clickBox includes Flags and Heading
610 clickBox.setSize (ornamentsBBox.size() );
615 topPad=botPad=leftPad=rightPad=0;
616 if (includeImagesVer || includeImagesHor)
618 if (countFloatImages()>0)
620 for (int i=0; i<floatimage.size(); ++i )
622 rp=floatimage.at(i)->getRelPos();
623 if (includeImagesVer)
626 topPad=max (topPad,-rp.y()-h);
627 if (rp.y()+floatimage.at(i)->height() > 0)
628 botPad=max (botPad,rp.y()+floatimage.at(i)->height());
630 if (includeImagesHor)
632 if (orientation==LinkableMapObj::RightOfCenter)
635 leftPad=max (leftPad,-rp.x()-w);
636 if (rp.x()+floatimage.at(i)->width() > 0)
637 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
641 leftPad=max (leftPad,-rp.x());
642 if (rp.x()+floatimage.at(i)->width() > w)
643 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
653 w+=frame->getPadding();
654 h+=frame->getPadding();
657 bbox.setSize (QSizeF (w,h));
660 void BranchObj::setDockPos()
662 // Sets childpos and parpos depending on orientation
663 if (getOrientation()==LinkableMapObj::LeftOfCenter )
666 ornamentsBBox.bottomLeft().x(),
669 ornamentsBBox.bottomRight().x(),
674 ornamentsBBox.bottomRight().x(),
677 ornamentsBBox.bottomLeft().x(),
682 LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
686 for (int i=0; i<branch.size(); ++i)
688 lmo=branch.at(i)->findMapObj(p, excludeLMO);
689 if (lmo != NULL) return lmo;
694 if (inBox (p,clickBox) && (this != excludeLMO) && isVisibleObj() )
697 // Search float images
698 for (int i=0; i<floatimage.size(); ++i )
699 if (inBox(p,floatimage.at(i)->getClickBox()) &&
700 (floatimage.at(i) != excludeLMO) &&
701 floatimage.at(i)->getParObj()!= excludeLMO &&
702 floatimage.at(i)->isVisibleObj()
703 ) return floatimage.at(i);
708 LinkableMapObj* BranchObj::findID (QString sid)
712 for (int i=0; i<branch.size(); ++i)
714 lmo=branch.at(i)->findID (sid);
715 if (lmo != NULL) return lmo;
719 if (sid==objID) return this;
723 // Search float images
724 for (int i=0; i<floatimage.size(); ++i )
725 if (floatimage.at(i)->inBox(p) &&
726 (floatimage.at(i) != excludeLMO) &&
727 floatimage.at(i)->getParObj()!= excludeLMO &&
728 floatimage.at(i)->isVisibleObj()
729 ) return floatimage.at(i);
734 void BranchObj::setHeading(QString s)
736 heading->setText(s); // set new heading
737 calcBBoxSize(); // recalculate bbox
738 positionBBox(); // rearrange contents
742 void BranchObj::setHideTmp (HideTmpMode mode)
744 if (mode==HideExport && (hideExport|| hasHiddenExportParent() ) )
746 // Hide stuff according to hideExport flag and parents
747 setVisibility (false);
751 // Do not hide, but still take care of scrolled status
752 if (hasScrolledParent(this))
753 setVisibility (false);
755 setVisibility (true);
759 // And take care of my childs
760 for (int i=0; i<branch.size(); ++i)
761 branch.at(i)->setHideTmp (mode);
764 bool BranchObj::hasHiddenExportParent()
766 // Calls parents recursivly to
767 // find out, if we or parents are temp. hidden
769 if (hidden || hideExport) return true;
771 BranchObj* bo=(BranchObj*)parObj;
773 return bo->hasHiddenExportParent();
778 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
780 // Cloudy stuff can be hidden during exports
781 if (hidden) return "";
783 // Update of note is usually done while unselecting a branch
784 if (isNoteInEditor) getNoteFromTextEditor();
787 QString scrolledAttr;
789 scrolledAttr=attribut ("scrolled","yes");
793 // save area, if not scrolled
795 if (!((BranchObj*)(parObj))->isScrolled() )
798 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
799 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
800 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
801 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
806 // Providing an ID for a branch makes export to XHTML easier
809 idAttr=attribut ("id",getSelectString());
813 s=beginElement ("branch"
818 +getIncludeImageAttr() );
822 s+=valueElement("heading", getHeading(),
823 attribut ("textColor",QColor(heading->getColor()).name()));
826 if (frame->getFrameType()!=FrameObj::NoFrame)
827 s+=frame->saveToDir ();
829 // save names of flags set
830 s+=standardFlags->saveToDir(tmpdir,prefix,0);
833 for (int i=0; i<floatimage.size(); ++i)
834 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
837 if (!note.isEmpty() )
841 for (int i=0; i<branch.size(); ++i)
842 s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
845 QString ol; // old link
846 QString cl; // current link
847 for (int i=0; i<xlink.size(); ++i)
849 cl=xlink.at(i)->saveToDir();
856 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
861 s+=endElement ("branch");
865 void BranchObj::addXLink (XLinkObj *xlo)
871 void BranchObj::removeXLinkRef (XLinkObj *xlo)
873 xlink.removeAt (xlink.indexOf(xlo));
876 void BranchObj::deleteXLink(XLinkObj *xlo)
879 if (!xlo->isUsed()) delete (xlo);
882 void BranchObj::deleteXLinkAt (int i)
884 XLinkObj *xlo=xlink.at(i);
886 if (!xlo->isUsed()) delete(xlo);
889 XLinkObj* BranchObj::XLinkAt (int i)
894 int BranchObj::countXLink()
896 return xlink.count();
900 BranchObj* BranchObj::XLinkTargetAt (int i)
902 if (i>=0 && i<xlink.size())
905 return xlink.at(i)->otherBranch (this);
910 void BranchObj::setIncludeImagesVer(bool b)
918 bool BranchObj::getIncludeImagesVer()
920 return includeImagesVer;
923 void BranchObj::setIncludeImagesHor(bool b)
931 bool BranchObj::getIncludeImagesHor()
933 return includeImagesHor;
936 QString BranchObj::getIncludeImageAttr()
939 if (includeImagesVer)
940 a=attribut ("incImgV","true");
942 a=attribut ("incImgV","false");
943 if (includeImagesHor)
944 a+=attribut ("incImgH","true");
946 a+=attribut ("incImgH","false");
950 FloatImageObj* BranchObj::addFloatImage ()
952 FloatImageObj *newfi=new FloatImageObj (scene,this);
953 floatimage.append (newfi);
954 if (hasScrolledParent(this) )
955 newfi->setVisibility (false);
957 newfi->setVisibility(visible);
966 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
968 FloatImageObj *newfi=new FloatImageObj (scene,this);
969 floatimage.append (newfi);
971 if (hasScrolledParent(this) )
972 newfi->setVisibility (false);
974 newfi->setVisibility(visible);
983 FloatImageObj* BranchObj::getFirstFloatImage ()
985 return floatimage.first();
988 FloatImageObj* BranchObj::getLastFloatImage ()
990 return floatimage.last();
993 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
995 return floatimage.at(i);
998 void BranchObj::removeFloatImage (FloatImageObj *fio)
1000 int i=floatimage.indexOf (fio);
1001 if (i>-1) delete (floatimage.takeAt (i));
1004 requestReposition();
1007 void BranchObj::savePosInAngle ()
1009 // Save position in angle
1010 for (int i=0; i<branch.size(); ++i)
1011 branch.at(i)->angle=i;
1014 void BranchObj::setDefAttr (BranchModification mod)
1019 case 0: fontsize=16; break;
1020 case 1: fontsize=12; break;
1021 default: fontsize=10; break;
1025 setLinkStyle(getDefLinkStyle());
1026 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
1027 font.setPointSize(fontsize);
1028 heading->setFont(font );
1031 setColor (((BranchObj*)(parObj))->getColor());
1036 BranchObj* BranchObj::addBranch()
1038 BranchObj* newbo=new BranchObj(scene,this);
1039 branch.append (newbo);
1040 newbo->setParObj(this);
1041 newbo->setDefAttr(NewBranch);
1042 newbo->setHeading ("new");
1044 newbo->setVisibility (false);
1046 newbo->setVisibility(visible);
1047 newbo->updateLink();
1048 requestReposition();
1052 BranchObj* BranchObj::addBranch(BranchObj* bo)
1054 BranchObj* newbo=new BranchObj(scene,this);
1055 branch.append (newbo);
1057 newbo->setParObj(this);
1058 newbo->setDefAttr(MovedBranch);
1060 newbo->setVisibility (false);
1062 newbo->setVisibility(bo->visible);
1063 newbo->updateLink();
1064 requestReposition();
1068 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
1071 bo->setParObj (this);
1073 bo->setDefAttr(MovedBranch);
1074 if (scrolled) tmpUnscroll();
1075 setLastSelectedBranch (bo);
1079 BranchObj* BranchObj::insertBranch(int pos)
1082 // Add new bo and resort branches
1083 BranchObj *newbo=addBranch ();
1084 newbo->angle=pos-0.5;
1085 qSort (branch.begin(),branch.end(), isAbove);
1089 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
1092 // Add new bo and resort branches
1094 BranchObj *newbo=addBranch (bo);
1095 qSort (branch.begin(),branch.end(), isAbove);
1099 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
1102 // Add new bo and resort branches
1105 bo->setParObj (this);
1107 bo->setDefAttr (MovedBranch);
1108 if (scrolled) tmpUnscroll();
1109 setLastSelectedBranch (bo);
1110 qSort (branch.begin(),branch.end(), isAbove);
1114 void BranchObj::removeBranchHere(BranchObj* borem)
1116 // This removes the branch bo from list, but
1117 // inserts its childs at the place of bo
1119 bo=borem->getLastBranch();
1120 int pos=borem->getNum();
1123 bo->linkTo (this,pos+1);
1124 bo=borem->getLastBranch();
1126 removeBranch (borem);
1129 void BranchObj::removeChilds()
1134 void BranchObj::removeBranch(BranchObj* bo)
1136 // if bo is not in branch remove returns false, we
1139 int i=branch.indexOf(bo);
1143 branch.removeAt (i);
1145 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
1146 requestReposition();
1149 void BranchObj::removeBranchPtr(BranchObj* bo)
1151 int i=branch.indexOf(bo);
1154 branch.removeAt (i);
1156 qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
1157 requestReposition();
1160 void BranchObj::setLastSelectedBranch (BranchObj* bo)
1162 lastSelectedBranch=branch.indexOf(bo);
1165 BranchObj* BranchObj::getLastSelectedBranch ()
1167 if (lastSelectedBranch>=0)
1169 if ( branch.size()>lastSelectedBranch)
1170 return branch.at(lastSelectedBranch);
1171 if (branch.size()>0)
1172 return branch.last();
1177 BranchObj* BranchObj::getFirstBranch ()
1179 if (branch.size()>0)
1180 return branch.first();
1185 BranchObj* BranchObj::getLastBranch ()
1187 if (branch.size()>0)
1188 return branch.last();
1193 BranchObj* BranchObj::getBranchNum (int i)
1195 if (i>=0 && i<branch.size())
1196 return branch.at(i);
1201 bool BranchObj::canMoveBranchUp()
1203 if (!parObj || depth==1) return false;
1204 BranchObj* par=(BranchObj*)parObj;
1205 if (this==par->getFirstBranch())
1211 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
1214 int i=branch.indexOf(bo1);
1216 { // -1 if bo1 not found
1217 branch.at(i)->angle--;
1218 branch.at(i-1)->angle++;
1219 qSort (branch.begin(),branch.end(), isAbove);
1220 return branch.at(i);
1225 bool BranchObj::canMoveBranchDown()
1227 if (!parObj|| depth==1) return false;
1228 BranchObj* par=(BranchObj*)parObj;
1229 if (this==par->getLastBranch())
1235 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
1238 int i=branch.indexOf(bo1);
1240 if (i <branch.size())
1243 branch.at(i)->angle++;
1244 branch.at(j)->angle--;
1245 qSort (branch.begin(),branch.end(), isAbove);
1246 return branch.at(i);
1251 void BranchObj::sortChildren()
1253 int childCount=branch.count();
1255 bool madeChanges=false;
1259 for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
1260 BranchObj* curChild=(BranchObj*)branch.at(curChildIndex);
1261 BranchObj* prevChild=(BranchObj*)branch.at(curChildIndex-1);
1262 if(prevChild->heading->text().compare(curChild->heading->text())>0)
1264 this->moveBranchUp(curChild);
1268 }while(madeChanges);
1272 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
1274 // Find current parent and
1275 // remove pointer to myself there
1276 if (!dst) return NULL;
1277 BranchObj *par=(BranchObj*)parObj;
1279 par->removeBranchPtr (this);
1283 // Create new pointer to myself at dst
1284 if (pos<0||dst->getDepth()==0)
1286 // links myself as last branch at dst
1287 dst->addBranchPtr (this);
1292 // inserts me at pos in parent of dst
1295 BranchObj *bo=dst->insertBranchPtr (this,pos);
1296 bo->setDefAttr(MovedBranch);
1305 void BranchObj::alignRelativeTo (QPointF ref)
1307 qreal th = bboxTotal.height();
1310 cout << "BO::alignRelTo "<<qPrintable (getHeading())<<endl;
1311 cout << " d="<<depth<<
1313 // " bbox.topLeft="<<bboxTotal.topLeft()<<
1314 " absPos="<<absPos<<
1315 " relPos="<<relPos<<
1316 " orient="<<orientation<<
1317 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
1318 // " hidden="<<hidden<<
1330 // Position relatively, if needed
1331 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
1333 // Calc angle to mapCenter if I am a mainbranch
1334 // needed for reordering the mainbranches clockwise
1336 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
1337 (int)(y() - parObj->getChildPos().y() ) ) );
1342 // Align myself depending on orientation and parent, but
1343 // only if I am not a mainbranch or mapcenter itself
1344 LinkableMapObj::Orientation o;
1345 o=parObj->getOrientation();
1346 switch (orientation)
1348 case LinkableMapObj::LeftOfCenter:
1349 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1351 case LinkableMapObj::RightOfCenter:
1352 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1355 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1360 if (scrolled) return;
1362 // Set reference point for alignment of childs
1364 if (orientation==LinkableMapObj::LeftOfCenter)
1365 ref2.setX(bbox.topLeft().x() - linkwidth);
1367 ref2.setX(bbox.topRight().x() + linkwidth);
1370 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1372 ref2.setY(ref.y() );
1374 // Align the childs depending on reference point
1375 for (int i=0; i<branch.size(); ++i)
1377 if (!branch.at(i)->isHidden())
1379 branch.at(i)->alignRelativeTo (ref2);
1380 ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChilds().height() );
1386 void BranchObj::reposition()
1388 /* TODO testing only
1389 if (!getHeading().isEmpty())
1390 cout << "BO::reposition "<<qPrintable(getHeading())<<endl;
1392 cout << "BO::reposition ???"<<endl;
1394 cout << " orient="<<orientation<<endl;
1399 // only calculate the sizes once. If the deepest LMO
1400 // changes its height,
1401 // all upper LMOs have to change, too.
1402 calcBBoxSizeWithChilds();
1403 updateLink(); // This update is needed if the scene is resized
1404 // due to excessive moving of a FIO
1406 alignRelativeTo ( QPointF (absPos.x(),
1407 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1408 qSort (branch.begin(),branch.end(), isAbove);
1409 positionBBox(); // Reposition bbox and contents
1412 // This is only important for moving branches:
1413 // For editing a branch it isn't called...
1414 alignRelativeTo ( QPointF (absPos.x(),
1415 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1419 void BranchObj::unsetAllRepositionRequests()
1421 repositionRequest=false;
1422 for (int i=0; i<branch.size(); ++i)
1423 branch.at(i)->unsetAllRepositionRequests();
1427 QPolygonF BranchObj::shape()
1431 QRectF r=getTotalBBox();
1432 if (orientation==LinkableMapObj::LeftOfCenter)
1435 <<QPointF (bbox.topLeft().x(), r.topLeft().y() )
1437 <<bbox.bottomRight()
1438 <<QPointF (bbox.bottomLeft().x(), r.bottomLeft().y() ) ;
1442 <<QPointF (bbox.topRight().x(), r.topRight().y() )
1445 <<QPointF (bbox.bottomRight().x(), r.bottomRight().y() ) ;
1449 QRectF BranchObj::getTotalBBox()
1453 if (scrolled) return r;
1455 for (int i=0; i<branch.size(); ++i)
1456 if (!branch.at(i)->isHidden())
1457 r=addBBox(branch.at(i)->getTotalBBox(),r);
1459 for (int i=0; i<floatimage.size(); ++i)
1460 if (!floatimage.at(i)->isHidden())
1461 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1466 QRectF BranchObj::getBBoxSizeWithChilds()
1471 void BranchObj::calcBBoxSizeWithChilds()
1473 // This is initially called only from reposition and
1474 // and only for mapcenter. So it won't be
1475 // called more than once for a single user
1479 // Calculate size of LMO including all childs (to align them later)
1480 bboxTotal.setX(bbox.x() );
1481 bboxTotal.setY(bbox.y() );
1483 // if branch is scrolled, ignore childs, but still consider floatimages
1486 bboxTotal.setWidth (bbox.width());
1487 bboxTotal.setHeight(bbox.height());
1493 bboxTotal.setWidth (0);
1494 bboxTotal.setHeight(0);
1497 bboxTotal.setX (parObj->x());
1498 bboxTotal.setY (parObj->y());
1501 bboxTotal.setX (bbox.x());
1502 bboxTotal.setY (bbox.y());
1509 // Now calculate recursivly
1511 // maximum of widths
1513 for (int i=0; i<branch.size(); ++i)
1515 if (!branch.at(i)->isHidden())
1517 branch.at(i)->calcBBoxSizeWithChilds();
1518 br=branch.at(i)->getBBoxSizeWithChilds();
1519 r.setWidth( max (br.width(), r.width() ));
1520 r.setHeight(br.height() + r.height() );
1521 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1524 // Add myself and also
1525 // add width of link to sum if necessary
1526 if (branch.isEmpty())
1527 bboxTotal.setWidth (bbox.width() + r.width() );
1529 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1531 bboxTotal.setHeight(max (r.height(), bbox.height()));
1534 void BranchObj::select()
1536 // update NoteEditor
1537 textEditor->setText(note.getNote() );
1538 QString fnh=note.getFilenameHint();
1540 textEditor->setFilenameHint(note.getFilenameHint() );
1542 textEditor->setFilenameHint(getHeading() );
1543 textEditor->setFontHint (note.getFontHint() );
1544 isNoteInEditor=true;
1546 // set selected and visible
1547 LinkableMapObj::select();
1549 // Tell parent that I am selected now:
1550 BranchObj* po=(BranchObj*)(parObj);
1551 if (po) // TODO Try to get rid of this cast...
1552 po->setLastSelectedBranch(this);
1554 // temporary unscroll, if we have scrolled parents somewhere
1555 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1557 // Show URL and link in statusbar
1559 if (!url.isEmpty()) status+="URL: "+url+" ";
1560 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1561 if (!status.isEmpty()) mainWindow->statusMessage (status);
1564 updateFlagsToolbar();
1567 mapEditor->updateActions();
1570 void BranchObj::unselect()
1572 LinkableMapObj::unselect();
1573 // Delete any messages like vymLink in StatusBar
1574 mainWindow->statusMessage ("");
1576 // Save current note
1577 if (isNoteInEditor) getNoteFromTextEditor();
1578 isNoteInEditor=false;
1580 // reset temporary unscroll, if we have scrolled parents somewhere
1581 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1583 // Erase content of editor
1584 textEditor->setInactive();
1586 // unselect all buttons in toolbar
1587 standardFlagsDefault->updateToolbar();
1590 QString BranchObj::getSelectString()
1596 s= "bo:" + QString("%1").arg(getNum());
1598 s= ((BranchObj*)(parObj))->getSelectString() + ",bo:" + QString("%1").arg(getNum());
1605 void BranchObj::animate()
1608 cout << "BO::animate x,y="<<relPos.x()<<","<<relPos.y()<<endl;