1.11.2 split up of xml helper functions. started to work on attributes
3 // #include "texteditor.h"
5 #include "mainwindow.h"
10 extern TextEditor *textEditor;
11 extern Main *mainWindow;
12 extern FlagRowObj *standardFlagsDefault;
15 /////////////////////////////////////////////////////////////////
17 /////////////////////////////////////////////////////////////////
19 BranchObj* BranchObj::itLast=NULL;
20 BranchObj* BranchObj::itFirst=NULL;
23 BranchObj::BranchObj () :OrnamentedObj()
25 // cout << "Const BranchObj ()\n";
31 BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s)
33 // cout << "Const BranchObj (s) called from MapCenterObj (s)\n";
38 BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)
40 // cout << "Const BranchObj (s,p)\n";
43 depth=p->getDepth()+1;
45 // Calc angle to mapCenter if I am a mainbranch
46 // needed for reordering the mainbranches clockwise
48 angle=getAngle (QPointF (x() - parObj->getChildPos().x() ,
49 (y() - parObj->getChildPos().y() ) ) );
53 BranchObj::~BranchObj ()
55 //cout << "Destr BranchObj of "<<this<<endl;
56 // Check, if this branch was the last child to be deleted
57 // If so, unset the scrolled flags
59 BranchObj *po=(BranchObj*)parObj;
63 bo=((BranchObj*)parObj)->getLastBranch();
64 if (bo) po->unScroll();
69 bool BranchObj::operator< ( const BranchObj & other )
71 return angle < other.angle;
74 bool BranchObj::operator== ( const BranchObj & other )
76 return angle == other.angle;
79 void BranchObj::init ()
84 absPos+=parObj->getChildPos();
94 includeImagesVer=false;
95 includeImagesHor=false;
98 void BranchObj::copy (BranchObj* other)
100 OrnamentedObj::copy(other);
103 for (int i=0; i<other->branch.size(); ++i)
104 // Make deep copy of b
105 // Because addBranch again calls copy for the childs,
106 // Those will get a deep copy, too
107 addBranch(other->branch.at(i) );
109 for (int i=0; i<other->floatimage.size(); ++i)
110 addFloatImage (other->floatimage.at(i));
111 scrolled=other->scrolled;
112 tmpUnscrolled=other->tmpUnscrolled;
113 setVisibility (other->visible);
120 void BranchObj::clear()
122 setVisibility (true);
124 while (!floatimage.isEmpty())
125 delete floatimage.takeFirst();
127 while (!xlink.isEmpty())
128 delete xlink.takeFirst();
130 while (!branch.isEmpty())
131 delete branch.takeFirst();
134 bool isAbove (BranchObj* a, BranchObj *b)
136 if (a->angle < b->angle)
142 int BranchObj::getNum()
145 return ((BranchObj*)parObj)->getNum (this);
150 int BranchObj::getNum(BranchObj *bo)
152 return branch.indexOf (bo);
155 int BranchObj::getFloatImageNum(FloatImageObj *fio)
157 return floatimage.indexOf(fio);
160 int BranchObj::countBranches()
162 return branch.count();
165 int BranchObj::countFloatImages()
167 return floatimage.count();
170 int BranchObj::countXLinks()
172 return xlink.count();
175 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
177 // Temporary link to lmo
178 // m is position of mouse pointer
179 // offset 0: default 1: below lmo -1 above lmo (if possible)
182 BranchObj* o=(BranchObj*)(lmo);
186 // ignore mapcenter and mainbranch
187 if (lmo->getDepth()<2) off=0;
194 depth=parObj->getDepth()+1;
196 // setLinkStyle calls updateLink, only set it once
197 if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
199 // Move temporary to new position at destination
200 // Usually the positioning would be done by reposition(),
201 // but then also the destination branch would "Jump" around...
202 // Better just do it approximately
204 { // new parent is the mapcenter itself
206 QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
207 m.y() - o->getChildPos().y() ));
208 if (p.x()<0) p.setX( p.x()-bbox.width() );
215 // new parent is just a branch, link to it
216 QRectF t=o->getBBoxSizeWithChilds();
217 if (o->getLastBranch())
218 y=t.y() + t.height() ;
225 // we want to link above lmo
226 y=o->y() - height() + 5;
228 // we want to link below lmo
229 // Bottom of sel should be 5 pixels above
230 // the bottom of the branch _below_ the target:
231 // Don't try to find that branch, guess 12 pixels
232 y=o->getChildPos().y() -height() + 12;
234 if (o->getOrientation()==LinkableMapObj::LeftOfCenter)
235 move ( o->getChildPos().x() - linkwidth, y );
237 move (o->getChildPos().x() + linkwidth, y );
240 // updateLink is called implicitly in move
244 void BranchObj::unsetParObjTmp()
251 depth=parObj->getDepth()+1;
252 setLinkStyle (getDefLinkStyle() );
257 void BranchObj::unScroll()
259 if (tmpUnscrolled) resetTmpUnscroll();
260 if (scrolled) toggleScroll();
263 void BranchObj::toggleScroll()
268 systemFlags->deactivate("scrolledright");
269 for (int i=0; i<branch.size(); ++i)
270 branch.at(i)->setVisibility(true);
274 systemFlags->activate("scrolledright");
275 for (int i=0; i<branch.size(); ++i)
276 branch.at(i)->setVisibility(false);
280 move (absPos.x(), absPos.y() );
284 bool BranchObj::isScrolled()
289 bool BranchObj::hasScrolledParent(BranchObj *start)
291 // Calls parents recursivly to
292 // find out, if we are scrolled at all.
293 // But ignore myself, just look at parents.
295 if (this !=start && scrolled) return true;
297 BranchObj* bo=(BranchObj*)(parObj);
299 return bo->hasScrolledParent(start);
304 void BranchObj::tmpUnscroll()
306 // Unscroll parent (recursivly)
307 BranchObj* bo=(BranchObj*)(parObj);
308 if (bo) bo->tmpUnscroll();
314 systemFlags->activate("tmpUnscrolledright");
319 void BranchObj::resetTmpUnscroll()
321 // Unscroll parent (recursivly)
322 BranchObj* bo=(BranchObj*)(parObj);
324 bo->resetTmpUnscroll();
330 systemFlags->deactivate("tmpUnscrolledright");
335 void BranchObj::setVisibility(bool v, int toDepth)
337 if (depth <= toDepth)
339 frame->setVisibility(v);
340 heading->setVisibility(v);
341 systemFlags->setVisibility(v);
342 standardFlags->setVisibility(v);
343 LinkableMapObj::setVisibility (v);
345 // Only change childs, if I am not scrolled
346 if (!scrolled && (depth < toDepth))
348 // Now go recursivly through all childs
350 for (i=0; i<branch.size(); ++i)
351 branch.at(i)->setVisibility (v,toDepth);
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 } // depth <= toDepth
361 void BranchObj::setVisibility(bool v)
363 setVisibility (v,MAX_DEPTH);
367 void BranchObj::setLinkColor ()
369 // Overloaded from LinkableMapObj
370 // BranchObj can use color of heading
374 if (mapEditor->getMapLinkColorHint()==HeadingColor)
375 LinkableMapObj::setLinkColor (heading->getColor() );
377 LinkableMapObj::setLinkColor ();
381 void BranchObj::setColorSubtree(QColor col)
383 OrnamentedObj::setColor (col);
384 for (int i=0; i<branch.size(); ++i)
385 branch.at(i)->setColorSubtree(col);
388 BranchObj* BranchObj::first()
395 BranchObj* BranchObj::next()
399 BranchObj *po=(BranchObj*)parObj;
401 if (branch.isEmpty())
408 // no itLast, we are just beginning
411 // we have childs, return first one
417 // No childs, so there is no next
425 { // We come from parent
428 // there are childs, go there
433 { // no childs, try to go up again
436 // go back to parent and try to find next there
445 // can't go up, I am mapCenter, no next
452 // We don't come from parent, but from brother or childs
454 // Try to find last child, where we came from, in my own childs
457 while (i<branch.size())
459 // Try to find itLast in my own childs
460 if (itLast==branch.at(i))
462 // ok, we come from my own childs
463 if (i<branch.size()-1)
473 { // found itLast in my childs
476 // found a brother of lastLMO
484 if (this==itFirst) return NULL; // Stop at starting point
493 // can't go up, I am mapCenter
500 // couldn't find last child, it must be a nephew of mine
503 // proceed with my first child
505 return branch.first();
509 // or go back to my parents
520 // can't go up, I am mapCenter
527 BranchObj* BranchObj::getLastIterator()
532 void BranchObj::setLastIterator(BranchObj* it)
537 void BranchObj::positionContents()
539 for (int i=0; i<floatimage.size(); ++i )
540 floatimage.at(i)->reposition();
541 OrnamentedObj::positionContents();
544 void BranchObj::move (double x, double y)
546 OrnamentedObj::move (x,y);
547 for (int i=0; i<floatimage.size(); ++i )
548 floatimage.at(i)->reposition();
552 void BranchObj::move (QPointF p)
557 void BranchObj::moveBy (double x, double y)
559 OrnamentedObj::moveBy (x,y);
560 for (int i=0; i<branch.size(); ++i)
561 branch.at(i)->moveBy (x,y);
565 void BranchObj::moveBy (QPointF p)
567 moveBy (p.x(), p.y());
571 void BranchObj::positionBBox()
573 QPointF ap=getAbsPos();
574 bbox.moveTopLeft (ap);
578 frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
580 // Update links to other branches
581 for (int i=0; i<xlink.size(); ++i)
582 xlink.at(i)->updateXLink();
585 void BranchObj::calcBBoxSize()
587 QSizeF heading_r=heading->getSize();
588 qreal heading_w=(qreal) heading_r.width() ;
589 qreal heading_h=(qreal) heading_r.height() ;
590 QSizeF sysflags_r=systemFlags->getSize();
591 qreal sysflags_h=sysflags_r.height();
592 qreal sysflags_w=sysflags_r.width();
593 QSizeF stanflags_r=standardFlags->getSize();
594 qreal stanflags_h=stanflags_r.height();
595 qreal stanflags_w=stanflags_r.width();
599 // set width to sum of all widths
600 w=heading_w + sysflags_w + stanflags_w;
601 // set height to maximum needed height
602 h=max (sysflags_h,stanflags_h);
605 // Save the dimension of flags and heading
606 ornamentsBBox.setSize ( QSizeF(w,h));
608 // clickBox includes Flags and Heading
609 clickBox.setSize (ornamentsBBox.size() );
614 topPad=botPad=leftPad=rightPad=0;
615 if (includeImagesVer || includeImagesHor)
617 if (countFloatImages()>0)
619 for (int i=0; i<floatimage.size(); ++i )
621 rp=floatimage.at(i)->getRelPos();
622 if (includeImagesVer)
625 topPad=max (topPad,-rp.y()-h);
626 if (rp.y()+floatimage.at(i)->height() > 0)
627 botPad=max (botPad,rp.y()+floatimage.at(i)->height());
629 if (includeImagesHor)
631 if (orientation==LinkableMapObj::RightOfCenter)
634 leftPad=max (leftPad,-rp.x()-w);
635 if (rp.x()+floatimage.at(i)->width() > 0)
636 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
640 leftPad=max (leftPad,-rp.x());
641 if (rp.x()+floatimage.at(i)->width() > w)
642 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
652 w+=frame->getPadding();
653 h+=frame->getPadding();
656 bbox.setSize (QSizeF (w,h));
659 void BranchObj::setDockPos()
661 // Sets childpos and parpos depending on orientation
662 if (getOrientation()==LinkableMapObj::LeftOfCenter )
665 ornamentsBBox.bottomLeft().x(),
668 ornamentsBBox.bottomRight().x(),
673 ornamentsBBox.bottomRight().x(),
676 ornamentsBBox.bottomLeft().x(),
681 LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
685 for (int i=0; i<branch.size(); ++i)
687 lmo=branch.at(i)->findMapObj(p, excludeLMO);
688 if (lmo != NULL) return lmo;
693 if (inBox (p) && (this != excludeLMO) && isVisibleObj() )
696 // Search float images
697 for (int i=0; i<floatimage.size(); ++i )
698 if (floatimage.at(i)->inBox(p) &&
699 (floatimage.at(i) != excludeLMO) &&
700 floatimage.at(i)->getParObj()!= excludeLMO &&
701 floatimage.at(i)->isVisibleObj()
702 ) return floatimage.at(i);
707 LinkableMapObj* BranchObj::findID (QString sid)
711 for (int i=0; i<branch.size(); ++i)
713 lmo=branch.at(i)->findID (sid);
714 if (lmo != NULL) return lmo;
718 if (sid==objID) return this;
722 // Search float images
723 for (int i=0; i<floatimage.size(); ++i )
724 if (floatimage.at(i)->inBox(p) &&
725 (floatimage.at(i) != excludeLMO) &&
726 floatimage.at(i)->getParObj()!= excludeLMO &&
727 floatimage.at(i)->isVisibleObj()
728 ) return floatimage.at(i);
733 void BranchObj::setHeading(QString s)
735 heading->setText(s); // set new heading
736 calcBBoxSize(); // recalculate bbox
737 positionBBox(); // rearrange contents
741 void BranchObj::setHideTmp (HideTmpMode mode)
743 if (mode==HideExport && hasHiddenExportParent())
745 setVisibility (false);
749 if (hasScrolledParent(this))
750 setVisibility (false);
752 setVisibility (true);
756 for (int i=0; i<branch.size(); ++i)
757 branch.at(i)->setHideTmp (mode);
760 bool BranchObj::hasHiddenExportParent()
762 // Calls parents recursivly to
763 // find out, if we are temp. hidden
765 if (hideExport) return true;
767 BranchObj* bo=(BranchObj*)parObj;
769 return bo->hasHiddenExportParent();
774 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
776 // Cloudy stuff can be hidden during exports
777 if (hidden) return "";
779 // Update of note is usually done while unselecting a branch
780 if (isNoteInEditor) getNoteFromTextEditor();
783 QString scrolledAttr;
785 scrolledAttr=attribut ("scrolled","yes");
789 // save area, if not scrolled
791 if (!((BranchObj*)(parObj))->isScrolled() )
794 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
795 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
796 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
797 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
802 // Providing an ID for a branch makes export to XHTML easier
805 idAttr=attribut ("id",getSelectString());
809 s=beginElement ("branch"
814 +getIncludeImageAttr() );
818 s+=valueElement("heading", getHeading(),
819 attribut ("textColor",QColor(heading->getColor()).name()));
822 if (frame->getFrameType()!=FrameObj::NoFrame)
823 s+=frame->saveToDir ();
825 // save names of flags set
826 s+=standardFlags->saveToDir(tmpdir,prefix,0);
829 for (int i=0; i<floatimage.size(); ++i)
830 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
833 if (!note.isEmpty() )
837 for (int i=0; i<branch.size(); ++i)
838 s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
841 QString ol; // old link
842 QString cl; // current link
843 for (int i=0; i<xlink.size(); ++i)
845 cl=xlink.at(i)->saveToDir();
852 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
857 s+=endElement ("branch");
861 void BranchObj::addXLink (XLinkObj *xlo)
867 void BranchObj::removeXLinkRef (XLinkObj *xlo)
869 xlink.removeAt (xlink.indexOf(xlo));
872 void BranchObj::deleteXLink(XLinkObj *xlo)
875 if (!xlo->isUsed()) delete (xlo);
878 void BranchObj::deleteXLinkAt (int i)
880 XLinkObj *xlo=xlink.at(i);
882 if (!xlo->isUsed()) delete(xlo);
885 XLinkObj* BranchObj::XLinkAt (int i)
890 int BranchObj::countXLink()
892 return xlink.count();
896 BranchObj* BranchObj::XLinkTargetAt (int i)
898 if (i>=0 && i<xlink.size())
901 return xlink.at(i)->otherBranch (this);
906 void BranchObj::setIncludeImagesVer(bool b)
914 bool BranchObj::getIncludeImagesVer()
916 return includeImagesVer;
919 void BranchObj::setIncludeImagesHor(bool b)
927 bool BranchObj::getIncludeImagesHor()
929 return includeImagesHor;
932 QString BranchObj::getIncludeImageAttr()
935 if (includeImagesVer)
936 a=attribut ("incImgV","true");
938 a=attribut ("incImgV","false");
939 if (includeImagesHor)
940 a+=attribut ("incImgH","true");
942 a+=attribut ("incImgH","false");
946 FloatImageObj* BranchObj::addFloatImage ()
948 FloatImageObj *newfi=new FloatImageObj (scene,this);
949 floatimage.append (newfi);
950 if (hasScrolledParent(this) )
951 newfi->setVisibility (false);
953 newfi->setVisibility(visible);
962 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
964 FloatImageObj *newfi=new FloatImageObj (scene,this);
965 floatimage.append (newfi);
967 if (hasScrolledParent(this) )
968 newfi->setVisibility (false);
970 newfi->setVisibility(visible);
979 FloatImageObj* BranchObj::getFirstFloatImage ()
981 return floatimage.first();
984 FloatImageObj* BranchObj::getLastFloatImage ()
986 return floatimage.last();
989 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
991 return floatimage.at(i);
994 void BranchObj::removeFloatImage (FloatImageObj *fio)
996 int i=floatimage.indexOf (fio);
997 if (i>-1) delete (floatimage.takeAt (i));
1000 requestReposition();
1003 void BranchObj::savePosInAngle ()
1005 // Save position in angle
1006 for (int i=0; i<branch.size(); ++i)
1007 branch.at(i)->angle=i;
1010 void BranchObj::setDefAttr (BranchModification mod)
1015 case 0: fontsize=16; break;
1016 case 1: fontsize=12; break;
1017 default: fontsize=10; break;
1021 setLinkStyle(getDefLinkStyle());
1022 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
1023 font.setPointSize(fontsize);
1024 heading->setFont(font );
1027 setColor (((BranchObj*)(parObj))->getColor());
1032 BranchObj* BranchObj::addBranch()
1034 BranchObj* newbo=new BranchObj(scene,this);
1035 branch.append (newbo);
1036 newbo->setParObj(this);
1037 newbo->setDefAttr(NewBranch);
1038 newbo->setHeading ("new");
1040 newbo->setVisibility (false);
1042 newbo->setVisibility(visible);
1043 newbo->updateLink();
1044 requestReposition();
1048 BranchObj* BranchObj::addBranch(BranchObj* bo)
1050 BranchObj* newbo=new BranchObj(scene,this);
1051 branch.append (newbo);
1053 newbo->setParObj(this);
1054 newbo->setDefAttr(MovedBranch);
1056 newbo->setVisibility (false);
1058 newbo->setVisibility(bo->visible);
1059 newbo->updateLink();
1060 requestReposition();
1064 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
1067 bo->setParObj (this);
1069 bo->setDefAttr(MovedBranch);
1070 if (scrolled) tmpUnscroll();
1071 setLastSelectedBranch (bo);
1075 BranchObj* BranchObj::insertBranch(int pos)
1078 // Add new bo and resort branches
1079 BranchObj *newbo=addBranch ();
1080 newbo->angle=pos-0.5;
1081 qSort (branch.begin(),branch.end(), isAbove);
1085 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
1088 // Add new bo and resort branches
1090 BranchObj *newbo=addBranch (bo);
1091 qSort (branch.begin(),branch.end(), isAbove);
1095 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
1098 // Add new bo and resort branches
1101 bo->setParObj (this);
1103 bo->setDefAttr (MovedBranch);
1104 if (scrolled) tmpUnscroll();
1105 setLastSelectedBranch (bo);
1106 qSort (branch.begin(),branch.end(), isAbove);
1110 void BranchObj::removeBranchHere(BranchObj* borem)
1112 // This removes the branch bo from list, but
1113 // inserts its childs at the place of bo
1115 bo=borem->getLastBranch();
1116 int pos=borem->getNum();
1119 bo->linkTo (this,pos+1);
1120 bo=borem->getLastBranch();
1122 removeBranch (borem);
1125 void BranchObj::removeChilds()
1130 void BranchObj::removeBranch(BranchObj* bo)
1132 // if bo is not in branch remove returns false, we
1135 int i=branch.indexOf(bo);
1139 branch.removeAt (i);
1141 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
1142 requestReposition();
1145 void BranchObj::removeBranchPtr(BranchObj* bo)
1147 int i=branch.indexOf(bo);
1150 branch.removeAt (i);
1152 qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
1153 requestReposition();
1156 void BranchObj::setLastSelectedBranch (BranchObj* bo)
1158 lastSelectedBranch=branch.indexOf(bo);
1161 BranchObj* BranchObj::getLastSelectedBranch ()
1163 if (lastSelectedBranch>=0)
1165 if ( branch.size()>lastSelectedBranch)
1166 return branch.at(lastSelectedBranch);
1167 if (branch.size()>0)
1168 return branch.last();
1173 BranchObj* BranchObj::getFirstBranch ()
1175 if (branch.size()>0)
1176 return branch.first();
1181 BranchObj* BranchObj::getLastBranch ()
1183 if (branch.size()>0)
1184 return branch.last();
1189 BranchObj* BranchObj::getBranchNum (int i)
1191 if (i>=0 && i<branch.size())
1192 return branch.at(i);
1197 bool BranchObj::canMoveBranchUp()
1199 if (!parObj || depth==1) return false;
1200 BranchObj* par=(BranchObj*)parObj;
1201 if (this==par->getFirstBranch())
1207 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
1210 int i=branch.indexOf(bo1);
1212 { // -1 if bo1 not found
1213 branch.at(i)->angle--;
1214 branch.at(i-1)->angle++;
1215 qSort (branch.begin(),branch.end(), isAbove);
1216 return branch.at(i);
1221 bool BranchObj::canMoveBranchDown()
1223 if (!parObj|| depth==1) return false;
1224 BranchObj* par=(BranchObj*)parObj;
1225 if (this==par->getLastBranch())
1231 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
1234 int i=branch.indexOf(bo1);
1236 if (i <branch.size())
1239 branch.at(i)->angle++;
1240 branch.at(j)->angle--;
1241 qSort (branch.begin(),branch.end(), isAbove);
1242 return branch.at(i);
1247 void BranchObj::sortChildren()
1249 int childCount=branch.count();
1251 bool madeChanges=false;
1255 for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
1256 BranchObj* curChild=(BranchObj*)branch.at(curChildIndex);
1257 BranchObj* prevChild=(BranchObj*)branch.at(curChildIndex-1);
1258 if(prevChild->heading->text().compare(curChild->heading->text())>0)
1260 this->moveBranchUp(curChild);
1264 }while(madeChanges);
1268 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
1270 // Find current parent and
1271 // remove pointer to myself there
1272 if (!dst) return NULL;
1273 BranchObj *par=(BranchObj*)parObj;
1275 par->removeBranchPtr (this);
1279 // Create new pointer to myself at dst
1280 if (pos<0||dst->getDepth()==0)
1282 // links myself as last branch at dst
1283 dst->addBranchPtr (this);
1288 // inserts me at pos in parent of dst
1291 BranchObj *bo=dst->insertBranchPtr (this,pos);
1292 bo->setDefAttr(MovedBranch);
1301 void BranchObj::alignRelativeTo (QPointF ref)
1303 qreal th = bboxTotal.height();
1306 cout << "BO::alignRelTo "<<getHeading().ascii()<<endl;
1307 cout << " d="<<depth<<
1309 // " bbox.topLeft="<<bboxTotal.topLeft()<<
1310 " absPos="<<absPos<<
1311 " relPos="<<relPos<<
1312 " orient="<<orientation<<
1313 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
1314 // " hidden="<<hidden<<
1326 // Position relatively, if needed
1327 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
1329 // Calc angle to mapCenter if I am a mainbranch
1330 // needed for reordering the mainbranches clockwise
1332 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
1333 (int)(y() - parObj->getChildPos().y() ) ) );
1338 // Align myself depending on orientation and parent, but
1339 // only if I am not a mainbranch or mapcenter itself
1340 LinkableMapObj::Orientation o;
1341 o=parObj->getOrientation();
1342 switch (orientation)
1344 case LinkableMapObj::LeftOfCenter:
1345 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1347 case LinkableMapObj::RightOfCenter:
1348 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1351 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1356 if (scrolled) return;
1358 // Set reference point for alignment of childs
1360 if (orientation==LinkableMapObj::LeftOfCenter)
1361 ref2.setX(bbox.topLeft().x() - linkwidth);
1363 ref2.setX(bbox.topRight().x() + linkwidth);
1366 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1368 ref2.setY(ref.y() );
1370 // Align the childs depending on reference point
1371 for (int i=0; i<branch.size(); ++i)
1373 if (!branch.at(i)->isHidden())
1375 branch.at(i)->alignRelativeTo (ref2);
1376 ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChilds().height() );
1382 void BranchObj::reposition()
1384 /* TODO testing only
1385 if (!getHeading().isEmpty())
1386 cout << "BO::reposition "<<getHeading().ascii()<<endl;
1388 cout << "BO::reposition ???"<<endl;
1390 cout << " orient="<<orientation<<endl;
1395 // only calculate the sizes once. If the deepest LMO
1396 // changes its height,
1397 // all upper LMOs have to change, too.
1398 calcBBoxSizeWithChilds();
1399 updateLink(); // This update is needed if the scene is resized
1400 // due to excessive moving of a FIO
1402 alignRelativeTo ( QPointF (absPos.x(),
1403 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1404 qSort (branch.begin(),branch.end(), isAbove);
1405 positionBBox(); // Reposition bbox and contents
1408 // This is only important for moving branches:
1409 // For editing a branch it isn't called...
1410 alignRelativeTo ( QPointF (absPos.x(),
1411 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1415 void BranchObj::unsetAllRepositionRequests()
1417 repositionRequest=false;
1418 for (int i=0; i<branch.size(); ++i)
1419 branch.at(i)->unsetAllRepositionRequests();
1423 QRectF BranchObj::getTotalBBox()
1427 if (scrolled) return r;
1429 for (int i=0; i<branch.size(); ++i)
1430 if (!branch.at(i)->isHidden())
1431 r=addBBox(branch.at(i)->getTotalBBox(),r);
1433 for (int i=0; i<floatimage.size(); ++i)
1434 if (!floatimage.at(i)->isHidden())
1435 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1440 QRectF BranchObj::getBBoxSizeWithChilds()
1445 void BranchObj::calcBBoxSizeWithChilds()
1447 // This is initially called only from reposition and
1448 // and only for mapcenter. So it won't be
1449 // called more than once for a single user
1453 // Calculate size of LMO including all childs (to align them later)
1454 bboxTotal.setX(bbox.x() );
1455 bboxTotal.setY(bbox.y() );
1457 // if branch is scrolled, ignore childs, but still consider floatimages
1460 bboxTotal.setWidth (bbox.width());
1461 bboxTotal.setHeight(bbox.height());
1467 bboxTotal.setWidth (0);
1468 bboxTotal.setHeight(0);
1471 bboxTotal.setX (parObj->x());
1472 bboxTotal.setY (parObj->y());
1475 bboxTotal.setX (bbox.x());
1476 bboxTotal.setY (bbox.y());
1483 // Now calculate recursivly
1485 // maximum of widths
1487 for (int i=0; i<branch.size(); ++i)
1489 if (!branch.at(i)->isHidden())
1491 branch.at(i)->calcBBoxSizeWithChilds();
1492 br=branch.at(i)->getBBoxSizeWithChilds();
1493 r.setWidth( max (br.width(), r.width() ));
1494 r.setHeight(br.height() + r.height() );
1495 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1498 // Add myself and also
1499 // add width of link to sum if necessary
1500 if (branch.isEmpty())
1501 bboxTotal.setWidth (bbox.width() + r.width() );
1503 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1505 bboxTotal.setHeight(max (r.height(), bbox.height()));
1508 void BranchObj::select()
1510 // update NoteEditor
1511 textEditor->setText(note.getNote() );
1512 QString fnh=note.getFilenameHint();
1514 textEditor->setFilenameHint(note.getFilenameHint() );
1516 textEditor->setFilenameHint(getHeading() );
1517 textEditor->setFontHint (note.getFontHint() );
1518 isNoteInEditor=true;
1520 // set selected and visible
1521 LinkableMapObj::select();
1523 // Tell parent that I am selected now:
1524 BranchObj* po=(BranchObj*)(parObj);
1525 if (po) // TODO Try to get rid of this cast...
1526 po->setLastSelectedBranch(this);
1528 // temporary unscroll, if we have scrolled parents somewhere
1529 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1531 // Show URL and link in statusbar
1533 if (!url.isEmpty()) status+="URL: "+url+" ";
1534 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1535 if (!status.isEmpty()) mainWindow->statusMessage (status);
1538 updateFlagsToolbar();
1541 mapEditor->updateActions();
1544 void BranchObj::unselect()
1546 LinkableMapObj::unselect();
1547 // Delete any messages like vymLink in StatusBar
1548 mainWindow->statusMessage ("");
1550 // Save current note
1551 if (isNoteInEditor) getNoteFromTextEditor();
1552 isNoteInEditor=false;
1554 // reset temporary unscroll, if we have scrolled parents somewhere
1555 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1557 // Erase content of editor
1558 textEditor->setInactive();
1560 // unselect all buttons in toolbar
1561 standardFlagsDefault->updateToolbar();
1564 QString BranchObj::getSelectString()
1570 s= "bo:" + QString("%1").arg(getNum());
1572 s= ((BranchObj*)(parObj))->getSelectString() + ",bo:" + QString("%1").arg(getNum());
1579 void BranchObj::animate()
1582 cout << "BO::animate x,y="<<relPos.x()<<","<<relPos.y()<<endl;