2 #include "texteditor.h"
4 #include "mainwindow.h"
6 extern TextEditor *textEditor;
7 extern Main *mainWindow;
8 extern FlagRowObj *standardFlagsDefault;
11 /* FIXME not needed any longer in QT4
12 int BranchObjPointrList::compareItems ( Q3PtrCollection::Item i, Q3PtrCollection::Item j)
14 // Make sure PtrList::find works
17 if ( ((BranchObj*)(i))->angle > ((BranchObj*)(j))->angle )
24 /////////////////////////////////////////////////////////////////
26 /////////////////////////////////////////////////////////////////
28 BranchObj* BranchObj::itLast=NULL;
29 BranchObj* BranchObj::itFirst=NULL;
32 BranchObj::BranchObj () :OrnamentedObj()
34 // cout << "Const BranchObj ()\n";
40 BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s)
42 // cout << "Const BranchObj (s) called from MapCenterObj (s)\n";
47 BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)
49 // cout << "Const BranchObj (s,p)\n";
52 depth=p->getDepth()+1;
54 // Calc angle to mapCenter if I am a mainbranch
55 // needed for reordering the mainbranches clockwise
57 angle=getAngle (QPointF (x() - parObj->getChildPos().x() ,
58 (y() - parObj->getChildPos().y() ) ) );
62 BranchObj::~BranchObj ()
64 // cout << "Destr BranchObj of "<<this<<endl;
65 // Check, if this branch was the last child to be deleted
66 // If so, unset the scrolled flags
68 BranchObj *po=(BranchObj*)(parObj);
72 bo=((BranchObj*)(parObj))->getLastBranch();
73 if (!bo) po->unScroll();
78 bool BranchObj::operator< ( const BranchObj & other )
80 return angle < other.angle;
83 bool BranchObj::operator== ( const BranchObj & other )
85 return angle == other.angle;
88 void BranchObj::init ()
93 absPos+=parObj->getChildPos();
103 includeImagesVer=false;
104 includeImagesHor=false;
107 void BranchObj::copy (BranchObj* other)
109 OrnamentedObj::copy(other);
112 for (int i=0; i<other->branch.size(); ++i)
113 // Make deep copy of b
114 // Because addBranch again calls copy for the childs,
115 // Those will get a deep copy, too
116 addBranch(other->branch.at(i) );
118 for (int i=0; i<other->floatimage.size(); ++i)
119 addFloatImage (other->floatimage.at(i));
120 scrolled=other->scrolled;
121 tmpUnscrolled=other->tmpUnscrolled;
122 setVisibility (other->visible);
129 void BranchObj::clear()
131 while (!floatimage.isEmpty())
132 delete floatimage.takeFirst();
134 while (!xlink.isEmpty())
135 delete xlink.takeFirst();
137 while (!branch.isEmpty())
138 delete branch.takeFirst();
141 int BranchObj::getNum()
144 return ((BranchObj*)parObj)->getNum (this);
149 int BranchObj::getNum(BranchObj *bo)
151 return branch.indexOf (bo);
154 int BranchObj::getFloatImageNum(FloatImageObj *fio)
156 return floatimage.indexOf(fio);
159 int BranchObj::countBranches()
161 return branch.count();
164 int BranchObj::countFloatImages()
166 return floatimage.count();
169 int BranchObj::countXLinks()
171 return xlink.count();
174 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
176 // Temporary link to lmo
177 // m is position of mouse pointer
178 // offset 0: default 1: below lmo -1 above lmo (if possible)
181 BranchObj* o=(BranchObj*)(lmo);
185 // ignore mapcenter and mainbranch
186 if (lmo->getDepth()<2) off=0;
193 depth=parObj->getDepth()+1;
195 // setLinkStyle calls updateLink, only set it once
196 if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
198 // Move temporary to new position at destination
199 // Usually the positioning would be done by reposition(),
200 // but then also the destination branch would "Jump" around...
201 // Better just do it approximately
203 { // new parent is the mapcenter itself
205 QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
206 m.y() - o->getChildPos().y() ));
207 if (p.x()<0) p.setX( p.x()-bbox.width() );
214 // new parent is just a branch, link to it
215 QRectF t=o->getBBoxSizeWithChilds();
216 if (o->getLastBranch())
217 y=t.y() + t.height() ;
224 // we want to link above lmo
225 y=o->y() - height() + 5;
227 // we want to link below lmo
228 // Bottom of sel should be 5 pixels above
229 // the bottom of the branch _below_ the target:
230 // Don't try to find that branch, guess 12 pixels
231 y=o->getChildPos().y() -height() + 12;
233 if (o->getOrientation()==OrientLeftOfCenter)
234 move ( o->getChildPos().x() - linkwidth, y );
236 move (o->getChildPos().x() + linkwidth, y );
239 // updateLink is called implicitly in move
240 reposition(); // FIXME shouldn't be this a request?
243 void BranchObj::unsetParObjTmp()
250 depth=parObj->getDepth()+1;
251 setLinkStyle (getDefLinkStyle() );
256 void BranchObj::unScroll()
258 if (tmpUnscrolled) resetTmpUnscroll();
259 if (scrolled) toggleScroll();
262 void BranchObj::toggleScroll()
267 systemFlags->deactivate("scrolledright");
268 for (int i=0; i<branch.size(); ++i)
269 branch.at(i)->setVisibility(true);
273 systemFlags->activate("scrolledright");
274 for (int i=0; i<branch.size(); ++i)
275 branch.at(i)->setVisibility(false);
279 move (absPos.x(), absPos.y() );
283 bool BranchObj::isScrolled()
288 bool BranchObj::hasScrolledParent(BranchObj *start)
290 // Calls parents recursivly to
291 // find out, if we are scrolled at all.
292 // But ignore myself, just look at parents.
294 if (this !=start && scrolled) return true;
296 BranchObj* bo=(BranchObj*)(parObj);
298 return bo->hasScrolledParent(start);
303 void BranchObj::tmpUnscroll()
305 // Unscroll parent (recursivly)
306 BranchObj* bo=(BranchObj*)(parObj);
307 if (bo) bo->tmpUnscroll();
313 systemFlags->activate("tmpUnscrolledright");
318 void BranchObj::resetTmpUnscroll()
320 // Unscroll parent (recursivly)
321 BranchObj* bo=(BranchObj*)(parObj);
323 bo->resetTmpUnscroll();
329 systemFlags->deactivate("tmpUnscrolledright");
334 void BranchObj::setVisibility(bool v, int toDepth)
336 if (depth <= toDepth)
338 frame->setVisibility(v);
339 heading->setVisibility(v);
340 systemFlags->setVisibility(v);
341 standardFlags->setVisibility(v);
342 LinkableMapObj::setVisibility (v);
344 // Only change childs, if I am not scrolled
345 if (!scrolled && (depth < toDepth))
347 // Now go recursivly through all childs
349 for (i=0; i<branch.size(); ++i)
350 branch.at(i)->setVisibility (v,toDepth);
351 for (i=0; i<floatimage.size(); ++i)
352 floatimage.at(i)->setVisibility (v);
353 for (i=0; i<xlink.size(); ++i)
354 xlink.at(i)->setVisibility ();
356 } // depth <= toDepth
360 void BranchObj::setVisibility(bool v)
362 setVisibility (v,MAX_DEPTH);
366 void BranchObj::setLinkColor ()
368 // Overloaded from LinkableMapObj
369 // BranchObj can use color of heading
372 if (mapEditor->getMapLinkColorHint()==HeadingColor)
373 LinkableMapObj::setLinkColor (heading->getColor() );
375 LinkableMapObj::setLinkColor ();
378 void BranchObj::setColorChilds (QColor col)
380 OrnamentedObj::setColor (col);
381 for (int i=0; i<branch.size(); ++i)
382 branch.at(i)->setColorChilds(col);
385 BranchObj* BranchObj::first()
392 BranchObj* BranchObj::next()
396 BranchObj *po=(BranchObj*)parObj;
398 if (branch.isEmpty())
405 // no itLast, we are just beginning
408 // we have childs, return first one
414 // No childs, so there is no next
422 { // We come from parent
425 // there are childs, go there
430 { // no childs, try to go up again
433 // go back to parent and try to find next there
442 // can't go up, I am mapCenter, no next
449 // We don't come from parent, but from brother or childs
451 // Try to find last child, where we came from, in my own childs
454 while (i<branch.size())
456 // Try to find itLast in my own childs
457 if (itLast==branch.at(i))
459 // ok, we come from my own childs
460 //xyz //FIXME need to proceed to NEXT child or up again
461 if (i<branch.size()-1)
471 { // found itLast in my childs
474 // found a brother of lastLMO
482 if (this==itFirst) return NULL; // Stop at starting point
491 // can't go up, I am mapCenter
498 // couldn't find last child, it must be a nephew of mine
501 // proceed with my first child
503 return branch.first();
507 // or go back to my parents
518 // can't go up, I am mapCenter
525 BranchObj* BranchObj::getLastIterator()
530 void BranchObj::setLastIterator(BranchObj* it)
535 void BranchObj::positionContents()
537 for (int i=0; i<floatimage.size(); ++i )
538 floatimage.at(i)->reposition();
539 OrnamentedObj::positionContents();
542 void BranchObj::move (double x, double y)
544 OrnamentedObj::move (x,y);
545 for (int i=0; i<floatimage.size(); ++i )
546 floatimage.at(i)->reposition();
550 void BranchObj::move (QPointF p)
555 void BranchObj::moveBy (double x, double y)
557 OrnamentedObj::moveBy (x,y);
558 for (int i=0; i<branch.size(); ++i)
559 branch.at(i)->moveBy (x,y);
563 void BranchObj::moveBy (QPointF p)
565 moveBy (p.x(), p.y());
569 void BranchObj::positionBBox()
571 QPointF ap=getAbsPos();
572 bbox.moveTopLeft (ap);
577 frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
579 // Update links to other branches
580 for (int i=0; i<xlink.size(); ++i)
581 xlink.at(i)->updateXLink();
584 void BranchObj::calcBBoxSize()
586 QSizeF heading_r=heading->getSize();
587 qreal heading_w=(qreal) heading_r.width() ;
588 qreal heading_h=(qreal) heading_r.height() ;
589 QSizeF sysflags_r=systemFlags->getSize();
590 qreal sysflags_h=sysflags_r.height();
591 qreal sysflags_w=sysflags_r.width();
592 QSizeF stanflags_r=standardFlags->getSize();
593 qreal stanflags_h=stanflags_r.height();
594 qreal stanflags_w=stanflags_r.width();
598 // set width to sum of all widths
599 w=heading_w + sysflags_w + stanflags_w;
600 // set height to maximum needed height
601 h=max (sysflags_h,stanflags_h);
604 // Save the dimension of flags and heading
605 ornamentsBBox.setSize ( QSizeF(w,h));
607 // clickBox includes Flags and Heading
608 clickBox.setSize (ornamentsBBox.size() );
613 topPad=botPad=leftPad=rightPad=0;
614 if (includeImagesVer || includeImagesHor)
616 if (countFloatImages()>0)
618 for (int i=0; i<floatimage.size(); ++i )
620 rp=floatimage.at(i)->getRelPos();
621 if (includeImagesVer)
624 topPad=max (topPad,-rp.y()-h);
625 if (rp.y()+floatimage.at(i)->height() > 0)
626 botPad=max (botPad,rp.y()+floatimage.at(i)->height());
628 if (includeImagesHor)
630 if (orientation==OrientRightOfCenter)
633 leftPad=max (leftPad,-rp.x()-w);
634 if (rp.x()+floatimage.at(i)->width() > 0)
635 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
639 leftPad=max (leftPad,-rp.x());
640 if (rp.x()+floatimage.at(i)->width() > w)
641 rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
651 w+=frame->getBorder();
652 h+=frame->getBorder();
655 bbox.setSize (QSizeF (w,h));
658 void BranchObj::setDockPos()
660 // Sets childpos and parpos depending on orientation
661 if (getOrientation()==OrientLeftOfCenter )
663 childPos=QPointF (ornamentsBBox.bottomLeft().x(), ornamentsBBox.bottomLeft().y() );
664 parPos=QPointF (ornamentsBBox.bottomRight().x(),ornamentsBBox.bottomRight().y() );
667 childPos=QPointF (ornamentsBBox.bottomRight().x(), ornamentsBBox.bottomRight().y() );
668 parPos=QPointF (ornamentsBBox.bottomLeft().x(),ornamentsBBox.bottomLeft().y() );
672 LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
676 for (int i=0; i<branch.size(); ++i)
678 lmo=branch.at(i)->findMapObj(p, excludeLMO);
679 if (lmo != NULL) return lmo;
683 if (inBox (p) && (this != excludeLMO) && isVisibleObj() )
686 // Search float images
687 for (int i=0; i<floatimage.size(); ++i )
688 if (floatimage.at(i)->inBox(p) &&
689 (floatimage.at(i) != excludeLMO) &&
690 floatimage.at(i)->getParObj()!= excludeLMO &&
691 floatimage.at(i)->isVisibleObj()
692 ) return floatimage.at(i);
697 void BranchObj::setHeading(QString s)
699 heading->setText(s); // set new heading
700 calcBBoxSize(); // recalculate bbox
701 positionBBox(); // rearrange contents
705 void BranchObj::setHideTmp (HideTmpMode mode)
707 if (mode==HideExport && hasHiddenExportParent(this))
709 setVisibility (false);
713 if (hasScrolledParent(this))
714 setVisibility (false);
716 setVisibility (true);
720 for (int i=0; i<branch.size(); ++i)
721 branch.at(i)->setHideTmp (mode);
724 bool BranchObj::hasHiddenExportParent(BranchObj *start)
726 // Calls parents recursivly to
727 // find out, if we are temp. hidden
729 if (hideExport) return true;
731 BranchObj* bo=(BranchObj*)(parObj);
733 return bo->hasHiddenExportParent(start);
738 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
740 if (hidden) return "";
743 QString scrolledAttr;
745 scrolledAttr=attribut ("scrolled","yes");
750 if (frame->getFrameType()!=NoFrame)
751 frameAttr=attribut ("frameType",frame->getFrameTypeName());
755 // save area, if not scrolled
757 if (!((BranchObj*)(parObj))->isScrolled() )
760 attribut("x1",QString().setNum(absPos.x()-offset.x())) +
761 attribut("y1",QString().setNum(absPos.y()-offset.y())) +
762 attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
763 attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
768 // Providing an ID for a branch makes export to XHTML easier
771 idAttr=attribut ("id",getSelectString());
775 s=beginElement ("branch"
781 +getIncludeImageAttr() );
785 for (int i=1; i<depth;i++) cout << " ";
786 cout <<getHeading().ascii()<<endl;
790 s+=valueElement("heading", getHeading(),
791 attribut ("textColor",QColor(heading->getColor()).name()));
793 // save names of flags set
794 s+=standardFlags->saveToDir(tmpdir,prefix,0);
797 for (int i=0; i<floatimage.size(); ++i)
798 s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
801 if (!note.isEmpty() )
805 for (int i=0; i<branch.size(); ++i)
806 s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
809 QString ol; // old link
810 QString cl; // current link
811 for (int i=0; i<xlink.size(); ++i)
813 cl=xlink.at(i)->saveToDir();
820 qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
825 s+=endElement ("branch");
829 void BranchObj::addXLink (XLinkObj *xlo)
835 void BranchObj::removeXLinkRef (XLinkObj *xlo)
837 xlink.removeAt (xlink.indexOf(xlo));
840 void BranchObj::deleteXLink(XLinkObj *xlo)
843 if (!xlo->isUsed()) delete (xlo);
846 void BranchObj::deleteXLinkAt (int i)
848 XLinkObj *xlo=xlink.at(i);
850 if (!xlo->isUsed()) delete(xlo);
853 XLinkObj* BranchObj::XLinkAt (int i)
858 int BranchObj::countXLink()
860 return xlink.count();
864 BranchObj* BranchObj::XLinkTargetAt (int i)
866 if (i>=0 && i<xlink.size())
869 return xlink.at(i)->otherBranch (this);
874 void BranchObj::setIncludeImagesVer(bool b)
882 bool BranchObj::getIncludeImagesVer()
884 return includeImagesVer;
887 void BranchObj::setIncludeImagesHor(bool b)
895 bool BranchObj::getIncludeImagesHor()
897 return includeImagesHor;
900 QString BranchObj::getIncludeImageAttr()
903 if (includeImagesVer)
904 a=attribut ("incImgV","true");
906 a=attribut ("incImgV","false");
907 if (includeImagesHor)
908 a+=attribut ("incImgH","true");
910 a+=attribut ("incImgH","false");
914 FloatImageObj* BranchObj::addFloatImage ()
916 FloatImageObj *newfi=new FloatImageObj (scene,this);
917 floatimage.append (newfi);
918 if (hasScrolledParent(this) )
919 newfi->setVisibility (false);
921 newfi->setVisibility(visible);
930 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
932 FloatImageObj *newfi=new FloatImageObj (scene,this);
933 floatimage.append (newfi);
935 if (hasScrolledParent(this) )
936 newfi->setVisibility (false);
938 newfi->setVisibility(visible);
947 FloatImageObj* BranchObj::getFirstFloatImage ()
949 return floatimage.first();
952 FloatImageObj* BranchObj::getLastFloatImage ()
954 return floatimage.last();
957 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
959 return floatimage.at(i);
962 void BranchObj::removeFloatImage (FloatImageObj *fio)
964 int i=floatimage.indexOf (fio);
965 if (i!=-1) floatimage.takeAt (i);
972 void BranchObj::savePosInAngle ()
974 // Save position in angle
975 for (int i=0; i<branch.size(); ++i)
976 branch.at(i)->angle=i;
979 void BranchObj::setDefAttr (BranchModification mod)
984 case 0: fontsize=16; break;
985 case 1: fontsize=12; break;
986 default: fontsize=10; break;
990 setLinkStyle(getDefLinkStyle());
991 QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
992 font.setPointSize(fontsize);
993 heading->setFont(font );
996 setColor (((BranchObj*)(parObj))->getColor());
1001 BranchObj* BranchObj::addBranch()
1003 BranchObj* newbo=new BranchObj(scene,this);
1004 branch.append (newbo);
1005 newbo->setParObj(this);
1006 newbo->setDefAttr(NewBranch);
1007 newbo->setHeading ("new");
1009 newbo->setVisibility (false);
1011 newbo->setVisibility(visible);
1012 newbo->updateLink();
1013 requestReposition();
1017 BranchObj* BranchObj::addBranch(BranchObj* bo)
1019 BranchObj* newbo=new BranchObj(scene,this);
1020 branch.append (newbo);
1022 newbo->setParObj(this);
1023 newbo->setDefAttr(MovedBranch);
1025 newbo->setVisibility (false);
1027 newbo->setVisibility(bo->visible);
1028 newbo->updateLink();
1029 requestReposition();
1033 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
1036 bo->setParObj (this);
1038 bo->setDefAttr(MovedBranch);
1039 if (scrolled) tmpUnscroll();
1040 setLastSelectedBranch (bo);
1044 BranchObj* BranchObj::insertBranch(int pos)
1047 // Add new bo and resort branches
1048 BranchObj *newbo=addBranch ();
1049 newbo->angle=pos-0.5;
1050 //FIXME branch.sort();
1054 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
1057 // Add new bo and resort branches
1059 BranchObj *newbo=addBranch (bo);
1060 //FIXME branch.sort();
1064 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
1067 // Add new bo and resort branches
1070 bo->setParObj (this);
1072 bo->setDefAttr (MovedBranch);
1073 if (scrolled) tmpUnscroll();
1074 setLastSelectedBranch (bo);
1075 //FIXME branch.sort();
1079 void BranchObj::removeBranchHere(BranchObj* borem)
1081 // This removes the branch bo from list, but
1082 // inserts its childs at the place of bo
1084 bo=borem->getLastBranch();
1085 int pos=borem->getNum();
1088 bo->moveBranchTo (this,pos+1);
1089 bo=borem->getLastBranch();
1091 removeBranch (borem);
1094 void BranchObj::removeChilds()
1099 void BranchObj::removeBranch(BranchObj* bo)
1101 // if bo is not in branch remove returns false, we
1104 int i=branch.indexOf(bo);
1108 branch.removeAt (i);
1110 qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
1111 requestReposition();
1114 void BranchObj::removeBranchPtr(BranchObj* bo)
1116 int i=branch.indexOf(bo);
1119 branch.removeAt (i);
1121 qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
1122 requestReposition();
1125 void BranchObj::setLastSelectedBranch (BranchObj* bo)
1127 lastSelectedBranch=branch.indexOf(bo);
1130 BranchObj* BranchObj::getLastSelectedBranch ()
1132 if (lastSelectedBranch>=0 && branch.size()>0)
1133 return branch.at(lastSelectedBranch);
1137 BranchObj* BranchObj::getFirstBranch ()
1139 if (branch.size()>0)
1140 return branch.first();
1145 BranchObj* BranchObj::getLastBranch ()
1147 if (branch.size()>0)
1148 return branch.last();
1153 BranchObj* BranchObj::getBranchNum (int i)
1155 if (i>=0 && i<branch.size())
1156 return branch.at(i);
1161 bool BranchObj::canMoveBranchUp()
1163 if (!parObj || depth==1) return false;
1164 BranchObj* par=(BranchObj*)parObj;
1165 if (this==par->getFirstBranch())
1171 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
1174 int i=branch.indexOf(bo1);
1176 { // -1 if bo1 not found
1177 branch.at(i)->angle--;
1178 branch.at(i-1)->angle++;
1179 //FIXME branch.sort();
1180 return branch.at(i);
1185 bool BranchObj::canMoveBranchDown()
1187 if (!parObj|| depth==1) return false;
1188 BranchObj* par=(BranchObj*)parObj;
1189 if (this==par->getLastBranch())
1195 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
1198 int i=branch.indexOf(bo1);
1200 if (i <branch.size())
1203 branch.at(i)->angle++;
1204 branch.at(j)->angle--;
1205 //FIXME branch.sort();
1206 return branch.at(i);
1211 BranchObj* BranchObj::moveBranchTo (BranchObj* dst, int pos)
1213 // Find current parent and
1214 // remove pointer to myself there
1215 if (!dst) return NULL;
1216 BranchObj *par=(BranchObj*)parObj;
1218 par->removeBranchPtr (this);
1222 // Create new pointer to myself at dst
1223 if (pos<0||dst->getDepth()==0)
1225 // links myself as last branch at dst
1226 dst->addBranchPtr (this);
1231 // inserts me at pos in parent of dst
1234 BranchObj *bo=dst->insertBranchPtr (this,pos);
1235 bo->setDefAttr(MovedBranch);
1244 void BranchObj::alignRelativeTo (QPointF ref)
1246 qreal th = bboxTotal.height();
1249 cout << "BO::alignRelTo "<<getHeading().ascii()<<endl;
1250 cout << " d="<<depth<<
1252 // " bbox.topLeft="<<bboxTotal.topLeft()<<
1253 " absPos="<<absPos<<
1254 " relPos="<<relPos<<
1255 " orient="<<orientation<<
1256 // " pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
1257 // " hidden="<<hidden<<
1269 // Position relatively, if needed
1270 //if (useRelPos) move2RelPos (relPos.x(), relPos.y());
1272 // Calc angle to mapCenter if I am a mainbranch
1273 // needed for reordering the mainbranches clockwise
1275 angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ),
1276 (int)(y() - parObj->getChildPos().y() ) ) );
1281 // Align myself depending on orientation and parent, but
1282 // only if I am not a mainbranch or mapcenter itself
1284 o=parObj->getOrientation();
1285 switch (orientation)
1287 case OrientLeftOfCenter:
1288 move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
1290 case OrientRightOfCenter:
1291 move (ref.x() , ref.y() + (th-bbox.height())/2 );
1294 qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
1299 if (scrolled) return;
1301 // Set reference point for alignment of childs
1303 if (orientation==OrientLeftOfCenter)
1304 ref2.setX(bbox.topLeft().x() - linkwidth);
1306 ref2.setX(bbox.topRight().x() + linkwidth);
1309 ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
1311 ref2.setY(ref.y() );
1313 // Align the childs depending on reference point
1314 for (int i=0; i<branch.size(); ++i)
1316 if (!branch.at(i)->isHidden())
1318 branch.at(i)->alignRelativeTo (ref2);
1319 ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChilds().height() );
1325 void BranchObj::reposition()
1327 /* TODO testing only
1328 if (!getHeading().isEmpty())
1329 cout << "BO::reposition "<<getHeading().ascii()<<endl;
1331 cout << "BO::reposition ???"<<endl;
1333 cout << " orient="<<orientation<<endl;
1338 // only calculate the sizes once. If the deepest LMO
1339 // changes its height,
1340 // all upper LMOs have to change, too.
1341 calcBBoxSizeWithChilds();
1342 updateLink(); // This update is needed if the scene is resized
1343 // due to excessive moving of a FIO
1344 // FIXME really needed? reposition is also called from updateLink...
1346 alignRelativeTo ( QPointF (absPos.x(),
1347 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1348 //FIXME branch.sort();
1349 positionBBox(); // Reposition bbox and contents
1352 // This is only important for moving branches:
1353 // For editing a branch it isn't called...
1354 alignRelativeTo ( QPointF (absPos.x(),
1355 absPos.y()-(bboxTotal.height()-bbox.height())/2) );
1359 void BranchObj::unsetAllRepositionRequests()
1361 repositionRequest=false;
1362 for (int i=0; i<branch.size(); ++i)
1363 branch.at(i)->unsetAllRepositionRequests();
1367 QRectF BranchObj::getTotalBBox()
1371 if (scrolled) return r;
1373 for (int i=0; i<branch.size(); ++i)
1374 if (!branch.at(i)->isHidden())
1375 r=addBBox(branch.at(i)->getTotalBBox(),r);
1377 for (int i=0; i<floatimage.size(); ++i)
1378 if (!floatimage.at(i)->isHidden())
1379 r=addBBox(floatimage.at(i)->getTotalBBox(),r);
1384 QRectF BranchObj::getBBoxSizeWithChilds()
1389 void BranchObj::calcBBoxSizeWithChilds()
1391 // This is initially called only from reposition and
1392 // and only for mapcenter. So it won't be
1393 // called more than once for a single user
1397 // Calculate size of LMO including all childs (to align them later)
1398 bboxTotal.setX(bbox.x() );
1399 bboxTotal.setY(bbox.y() );
1401 // if branch is scrolled, ignore childs, but still consider floatimages
1404 bboxTotal.setWidth (bbox.width());
1405 bboxTotal.setHeight(bbox.height());
1411 bboxTotal.setWidth (0);
1412 bboxTotal.setHeight(0);
1415 bboxTotal.setX (parObj->x());
1416 bboxTotal.setY (parObj->y());
1419 bboxTotal.setX (bbox.x());
1420 bboxTotal.setY (bbox.y());
1427 // Now calculate recursivly
1429 // maximum of widths
1431 for (int i=0; i<branch.size(); ++i)
1433 if (!branch.at(i)->isHidden())
1435 branch.at(i)->calcBBoxSizeWithChilds();
1436 br=branch.at(i)->getBBoxSizeWithChilds();
1437 r.setWidth( max (br.width(), r.width() ));
1438 r.setHeight(br.height() + r.height() );
1439 if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
1442 // Add myself and also
1443 // add width of link to sum if necessary
1444 if (branch.isEmpty())
1445 bboxTotal.setWidth (bbox.width() + r.width() );
1447 bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
1449 bboxTotal.setHeight(max (r.height(), bbox.height()));
1452 void BranchObj::select()
1454 // set Text in Editor
1455 textEditor->setText(note.getNote() );
1456 QString fnh=note.getFilenameHint();
1458 textEditor->setFilenameHint(note.getFilenameHint() );
1460 textEditor->setFilenameHint(getHeading() );
1461 textEditor->setFontHint (note.getFontHint() );
1463 LinkableMapObj::select();
1464 // Tell parent that I am selected now:
1465 BranchObj* po=(BranchObj*)(parObj);
1466 if (po) // TODO Try to get rid of this cast...
1467 po->setLastSelectedBranch(this);
1469 // temporary unscroll, if we have scrolled parents somewhere
1470 if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
1472 // Show URL and link in statusbar
1474 if (!url.isEmpty()) status+="URL: "+url+" ";
1475 if (!vymLink.isEmpty()) status+="Link: "+vymLink;
1476 if (!status.isEmpty()) mainWindow->statusMessage (status);
1479 updateFlagsToolbar();
1482 mapEditor->updateActions();
1485 void BranchObj::unselect()
1487 LinkableMapObj::unselect();
1488 // Delete any messages like vymLink in StatusBar
1489 mainWindow->statusMessage ("");
1491 // save note from editor and set flag
1492 // text is done by updateNoteFlag(), just save
1494 note.setFilenameHint (textEditor->getFilename());
1496 // reset temporary unscroll, if we have scrolled parents somewhere
1497 if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
1499 // Erase content of editor
1500 textEditor->setInactive();
1502 // unselect all buttons in toolbar
1503 standardFlagsDefault->updateToolbar();
1506 QString BranchObj::getSelectString()
1512 s= "bo:" + QString("%1").arg(getNum());
1514 s= ((BranchObj*)(parObj))->getSelectString() + ",bo:" + QString("%1").arg(getNum());