branchobj.cpp
author insilmaril
Thu Nov 08 15:28:03 2007 +0000 (2007-11-08)
changeset 619 b48f072a347a
parent 611 a1ae877b438d
child 628 d7d0708b1c60
permissions -rw-r--r--
1.11.2 split up of xml helper functions. started to work on attributes
     1 #include "branchobj.h"
     2 
     3 // #include "texteditor.h"
     4 #include "mapeditor.h"
     5 #include "mainwindow.h"
     6 #include "misc.h"
     7 
     8 class TextEditor;
     9 
    10 extern TextEditor *textEditor;
    11 extern Main *mainWindow;
    12 extern FlagRowObj *standardFlagsDefault;
    13 
    14 
    15 /////////////////////////////////////////////////////////////////
    16 // BranchObj
    17 /////////////////////////////////////////////////////////////////
    18 
    19 BranchObj* BranchObj::itLast=NULL;
    20 BranchObj* BranchObj::itFirst=NULL;
    21 
    22 
    23 BranchObj::BranchObj () :OrnamentedObj()
    24 {
    25 //    cout << "Const BranchObj ()\n";
    26     setParObj (this);	
    27     init();
    28     depth=-1;
    29 }
    30 
    31 BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s)
    32 {
    33 //    cout << "Const BranchObj (s)  called from MapCenterObj (s)\n";
    34 	parObj=NULL;
    35     scene=s;
    36 }
    37 
    38 BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)
    39 {
    40 //    cout << "Const BranchObj (s,p)\n";
    41     scene=s;
    42     setParObj (p);	
    43     depth=p->getDepth()+1;
    44 	if (depth==1)
    45 		// Calc angle to mapCenter if I am a mainbranch
    46 		// needed for reordering the mainbranches clockwise 
    47 		// around mapcenter 
    48 		angle=getAngle (QPointF (x() - parObj->getChildPos().x() , 
    49 								(y() - parObj->getChildPos().y() ) ) );
    50     init();
    51 }
    52 
    53 BranchObj::~BranchObj ()
    54 {
    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
    58 
    59 	BranchObj *po=(BranchObj*)parObj;
    60 	BranchObj *bo;
    61 	if (po)
    62 	{
    63 		bo=((BranchObj*)parObj)->getLastBranch();
    64 		if (bo) po->unScroll();
    65 	}
    66 	clear();
    67 }
    68 
    69 bool BranchObj::operator< ( const BranchObj & other )
    70 {
    71     return  angle < other.angle;
    72 }
    73 
    74 bool BranchObj::operator== ( const BranchObj & other )
    75 {
    76     return angle == other.angle;
    77 }
    78 
    79 void BranchObj::init () 
    80 {
    81 	if (parObj)
    82 	{
    83 		absPos=getRandPos();
    84 		absPos+=parObj->getChildPos();
    85 	}
    86 
    87     lastSelectedBranch=0;
    88 
    89     setChildObj(this);
    90 
    91 	scrolled=false;
    92 	tmpUnscrolled=false;
    93 
    94 	includeImagesVer=false;
    95 	includeImagesHor=false;
    96 }
    97 
    98 void BranchObj::copy (BranchObj* other)
    99 {
   100     OrnamentedObj::copy(other);
   101 
   102 	branch.clear();
   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) );	
   108 
   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);
   114 
   115 	angle=other->angle;
   116 
   117     positionBBox();
   118 }
   119 
   120 void BranchObj::clear() 
   121 {
   122 	setVisibility (true);
   123 
   124 	while (!floatimage.isEmpty())
   125 		delete floatimage.takeFirst();
   126 
   127 	while (!xlink.isEmpty())
   128 		delete xlink.takeFirst();
   129 
   130 	while (!branch.isEmpty())
   131 		delete branch.takeFirst();
   132 }
   133 
   134 bool isAbove (BranchObj* a, BranchObj *b)
   135 {
   136 	if (a->angle < b->angle)
   137 		return true;
   138 	else	
   139 		return false;
   140 }
   141 
   142 int BranchObj::getNum()
   143 {
   144 	if (parObj)
   145 		return ((BranchObj*)parObj)->getNum (this);
   146 	else
   147 		return 0;
   148 }
   149 
   150 int BranchObj::getNum(BranchObj *bo)
   151 {
   152 	return branch.indexOf (bo);
   153 }
   154 
   155 int BranchObj::getFloatImageNum(FloatImageObj *fio)
   156 {
   157 	return floatimage.indexOf(fio);
   158 }
   159 
   160 int BranchObj::countBranches()
   161 {
   162 	return branch.count();
   163 }
   164 
   165 int BranchObj::countFloatImages()
   166 {
   167 	return floatimage.count();
   168 }
   169 
   170 int BranchObj::countXLinks()
   171 {
   172 	return xlink.count();
   173 }
   174 
   175 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
   176 {
   177 	// Temporary link to lmo
   178 	// m is position of mouse pointer 
   179 	// offset 0: default 1: below lmo   -1 above lmo  (if possible)
   180 
   181 
   182 	BranchObj* o=(BranchObj*)(lmo);
   183 	if (!parObjTmpBuf) 
   184 		parObjTmpBuf=parObj;
   185 
   186 	// ignore mapcenter and mainbranch
   187 	if (lmo->getDepth()<2) off=0;
   188 	if (off==0)
   189 		link2ParPos=false;
   190 	else
   191 		link2ParPos=true;
   192 	parObj=o;
   193 
   194 	depth=parObj->getDepth()+1;
   195 
   196 	// setLinkStyle calls updateLink, only set it once
   197 	if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
   198 
   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
   203 	if (depth==1)
   204 	{	// new parent is the mapcenter itself
   205 
   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() );
   209 		move2RelPos (p);
   210 	} else
   211 	{	
   212 		qreal y;
   213 		if (off==0)
   214 		{
   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() ;
   219 			else
   220 				y=t.y();
   221 
   222 		} else
   223 		{
   224 			if (off<0)
   225 				// we want to link above lmo
   226 				y=o->y() - height() + 5;
   227 			else	
   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; 
   233 		}	
   234 		if (o->getOrientation()==LinkableMapObj::LeftOfCenter)
   235 			move ( o->getChildPos().x() - linkwidth, y );
   236 		else	
   237 			move (o->getChildPos().x() + linkwidth, y );
   238 	}	
   239 
   240 	// updateLink is called implicitly in move
   241 	requestReposition();	
   242 }
   243 
   244 void BranchObj::unsetParObjTmp()
   245 {
   246 	if (parObjTmpBuf) 
   247 	{
   248 		link2ParPos=false;
   249 		parObj=parObjTmpBuf;
   250 		parObjTmpBuf=NULL;
   251 		depth=parObj->getDepth()+1;
   252 		setLinkStyle (getDefLinkStyle() );
   253 		updateLink();
   254 	}		
   255 }
   256 
   257 void BranchObj::unScroll()
   258 {
   259 	if (tmpUnscrolled) resetTmpUnscroll();
   260 	if (scrolled) toggleScroll();
   261 }
   262 
   263 void BranchObj::toggleScroll()
   264 {
   265 	if (scrolled)
   266 	{
   267 		scrolled=false;
   268 		systemFlags->deactivate("scrolledright");
   269 		for (int i=0; i<branch.size(); ++i)
   270 			branch.at(i)->setVisibility(true);
   271 	} else
   272 	{
   273 		scrolled=true;
   274 		systemFlags->activate("scrolledright");
   275 		for (int i=0; i<branch.size(); ++i)
   276 			branch.at(i)->setVisibility(false);
   277 	}
   278 	calcBBoxSize();
   279 	positionBBox();	
   280 	move (absPos.x(), absPos.y() );
   281 	forceReposition();
   282 }
   283 
   284 bool BranchObj::isScrolled()
   285 {
   286 	return scrolled;
   287 }
   288 
   289 bool BranchObj::hasScrolledParent(BranchObj *start)
   290 {
   291 	// Calls parents recursivly to
   292 	// find out, if we are scrolled at all.
   293 	// But ignore myself, just look at parents.
   294 
   295 	if (this !=start && scrolled) return true;
   296 
   297 	BranchObj* bo=(BranchObj*)(parObj);
   298 	if (bo) 
   299 		return bo->hasScrolledParent(start);
   300 	else
   301 		return false;
   302 }
   303 
   304 void BranchObj::tmpUnscroll()
   305 {
   306 	// Unscroll parent (recursivly)
   307 	BranchObj* bo=(BranchObj*)(parObj);
   308 	if (bo) bo->tmpUnscroll();
   309 		
   310 	// Unscroll myself
   311 	if (scrolled)
   312 	{
   313 		tmpUnscrolled=true;
   314 		systemFlags->activate("tmpUnscrolledright");
   315 		toggleScroll();
   316 	}	
   317 }
   318 
   319 void BranchObj::resetTmpUnscroll()
   320 {
   321 	// Unscroll parent (recursivly)
   322 	BranchObj* bo=(BranchObj*)(parObj);
   323 	if (bo)
   324 		bo->resetTmpUnscroll();
   325 		
   326 	// Unscroll myself
   327 	if (tmpUnscrolled)
   328 	{
   329 		tmpUnscrolled=false;
   330 		systemFlags->deactivate("tmpUnscrolledright");
   331 		toggleScroll();
   332 	}	
   333 }
   334 
   335 void BranchObj::setVisibility(bool v, int toDepth)
   336 {
   337     if (depth <= toDepth)
   338     {
   339 		frame->setVisibility(v);
   340 		heading->setVisibility(v);
   341 		systemFlags->setVisibility(v);
   342 		standardFlags->setVisibility(v);
   343 		LinkableMapObj::setVisibility (v);
   344 		
   345 		// Only change childs, if I am not scrolled
   346 		if (!scrolled && (depth < toDepth))
   347 		{
   348 			// Now go recursivly through all childs
   349 			int i;
   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 ();	
   356 		}
   357     } // depth <= toDepth	
   358 	requestReposition();
   359 }	
   360 
   361 void BranchObj::setVisibility(bool v)
   362 {
   363     setVisibility (v,MAX_DEPTH);
   364 }
   365 
   366 
   367 void BranchObj::setLinkColor ()
   368 {
   369 	// Overloaded from LinkableMapObj
   370 	// BranchObj can use color of heading
   371 
   372 	if (mapEditor)
   373 	{
   374 		if (mapEditor->getMapLinkColorHint()==HeadingColor)
   375 			LinkableMapObj::setLinkColor (heading->getColor() );
   376 		else	
   377 			LinkableMapObj::setLinkColor ();
   378 	}		
   379 }
   380 
   381 void BranchObj::setColorSubtree(QColor col)
   382 {
   383 	OrnamentedObj::setColor (col);
   384 	for (int i=0; i<branch.size(); ++i)
   385 		branch.at(i)->setColorSubtree(col);
   386 }
   387 
   388 BranchObj* BranchObj::first()
   389 {
   390 	itLast=NULL;	
   391 	itFirst=this;
   392 	return this; 
   393 }
   394 	
   395 BranchObj* BranchObj::next()
   396 {
   397 	BranchObj *bo;
   398 	BranchObj *lmo;
   399 	BranchObj *po=(BranchObj*)parObj;
   400 
   401 	if (branch.isEmpty())
   402 		bo=NULL;
   403 	else
   404 		bo=branch.first();
   405 
   406 	if (!itLast)
   407 	{
   408 		// no itLast, we are just beginning
   409 		if (bo) 
   410 		{
   411 			// we have childs, return first one
   412 			itLast=this;
   413 			return bo;
   414 		}	
   415 		else
   416 		{
   417 			// No childs, so there is no next
   418 			itLast=this;
   419 			return NULL;
   420 		}	
   421 	}
   422 
   423 	// We have an itLast
   424 	if (itLast==po)
   425 	{	// We come from parent
   426 		if (bo)
   427 		{
   428 			// there are childs, go there
   429 			itLast=this;
   430 			return bo;
   431 		}	
   432 		else
   433 		{	// no childs, try to go up again
   434 			if (po)
   435 			{
   436 				// go back to parent and try to find next there
   437 				itLast=this;
   438 				lmo=po->next();
   439 				itLast=this;
   440 				return lmo;
   441 
   442 			}	
   443 			else
   444 			{
   445 				// can't go up, I am mapCenter, no next
   446 				itLast=NULL;
   447 				return NULL;
   448 			}	
   449 		}
   450 	}
   451 
   452 	// We don't come from parent, but from brother or childs
   453 
   454 	// Try to find last child, where we came from, in my own childs
   455 	bool searching=true;
   456 	int i=0;
   457 	while (i<branch.size())
   458 	{
   459 		// Try to find itLast in my own childs
   460 		if (itLast==branch.at(i))
   461 		{
   462 			// ok, we come from my own childs
   463 			if (i<branch.size()-1)
   464 				bo=branch.at(i+1);
   465 			 else
   466 				bo=NULL;
   467 			searching=false;
   468 			i=branch.size();
   469 		} 	
   470 		++i;	
   471 	}
   472 	if (!searching)
   473 	{	// found itLast in my childs
   474 		if (bo)
   475 		{
   476 			// found a brother of lastLMO 
   477 			itLast=this;
   478 			return bo;
   479 		}	
   480 		else
   481 		{
   482 			if (po)
   483 			{
   484 				if (this==itFirst) return NULL;	// Stop at starting point
   485 				// go up
   486 				itLast=this;
   487 				lmo=po->next();
   488 				itLast=this;
   489 				return lmo;
   490 			}
   491 			else
   492 			{
   493 				// can't go up, I am mapCenter
   494 				itLast=NULL;
   495 				return NULL;
   496 			}	
   497 		}
   498 	}
   499 
   500 	// couldn't find last child, it must be a nephew of mine
   501 	if (branch.size()>0)
   502 	{
   503 		// proceed with my first child
   504 		itLast=this;	
   505 		return branch.first();
   506 	}	
   507 	else
   508 	{
   509 		// or go back to my parents
   510 		if (po)
   511 		{
   512 			// go up
   513 			itLast=this;
   514 			lmo=po->next();
   515 			itLast=this;
   516 			return lmo;
   517 		}	
   518 		else
   519 		{
   520 			// can't go up, I am mapCenter
   521 			itLast=NULL;
   522 			return NULL;
   523 		}	
   524 	}	
   525 }
   526 
   527 BranchObj* BranchObj::getLastIterator()
   528 {
   529 	return itLast;
   530 }
   531 
   532 void BranchObj::setLastIterator(BranchObj* it)
   533 {
   534 	itLast=it;
   535 }
   536 
   537 void BranchObj::positionContents()
   538 {
   539     for (int i=0; i<floatimage.size(); ++i )
   540 		floatimage.at(i)->reposition();
   541 	OrnamentedObj::positionContents();
   542 }
   543 
   544 void BranchObj::move (double x, double y)
   545 {
   546 	OrnamentedObj::move (x,y);
   547     for (int i=0; i<floatimage.size(); ++i )
   548 		floatimage.at(i)->reposition();
   549     positionBBox();
   550 }
   551 
   552 void BranchObj::move (QPointF p)
   553 {
   554 	move (p.x(), p.y());
   555 }
   556 
   557 void BranchObj::moveBy (double x, double y)
   558 {
   559 	OrnamentedObj::moveBy (x,y);
   560 	for (int i=0; i<branch.size(); ++i)
   561 		branch.at(i)->moveBy (x,y);
   562     positionBBox();
   563 }
   564 	
   565 void BranchObj::moveBy (QPointF p)
   566 {
   567 	moveBy (p.x(), p.y());
   568 }
   569 
   570 
   571 void BranchObj::positionBBox()
   572 {
   573 	QPointF ap=getAbsPos();
   574 	bbox.moveTopLeft (ap);
   575 	positionContents();
   576 
   577 	// set the frame
   578 	frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
   579 
   580 	// Update links to other branches
   581 	for (int i=0; i<xlink.size(); ++i)
   582 		xlink.at(i)->updateXLink();
   583 }
   584 
   585 void BranchObj::calcBBoxSize()
   586 {
   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();
   596     qreal w;
   597     qreal h;
   598 
   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);
   603 	h=max (h,heading_h);
   604 
   605 	// Save the dimension of flags and heading
   606 	ornamentsBBox.setSize ( QSizeF(w,h));
   607 
   608 	// clickBox includes Flags and Heading
   609     clickBox.setSize (ornamentsBBox.size() );
   610 
   611 	// Floatimages 
   612 	QPointF rp;
   613 
   614 	topPad=botPad=leftPad=rightPad=0;
   615 	if (includeImagesVer || includeImagesHor)
   616 	{
   617 		if (countFloatImages()>0)
   618 		{
   619 			for (int i=0; i<floatimage.size(); ++i )
   620 			{
   621 				rp=floatimage.at(i)->getRelPos();
   622 				if (includeImagesVer)
   623 				{
   624 					if (rp.y() < 0) 
   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());
   628 				}		
   629 				if (includeImagesHor)
   630 				{
   631 					if (orientation==LinkableMapObj::RightOfCenter)
   632 					{
   633 						if (-rp.x()-w > 0) 
   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());
   637 					} else
   638 					{
   639 						if (rp.x()< 0) 
   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);
   643 					}
   644 				}		
   645 			}	
   646 		}	
   647 		h+=topPad+botPad;
   648 		w+=leftPad+rightPad;
   649 	}
   650 
   651 	// Frame thickness
   652     w+=frame->getPadding();
   653     h+=frame->getPadding();
   654 	
   655 	// Finally set size
   656     bbox.setSize (QSizeF (w,h));
   657 }
   658 
   659 void BranchObj::setDockPos()
   660 {
   661 	// Sets childpos and parpos depending on orientation
   662 	if (getOrientation()==LinkableMapObj::LeftOfCenter )
   663     {
   664 		childPos=QPointF (
   665 			ornamentsBBox.bottomLeft().x(), 
   666 			bottomlineY);
   667 		parPos=QPointF (
   668 			ornamentsBBox.bottomRight().x(),
   669 			bottomlineY);
   670     } else
   671     {
   672 		childPos=QPointF (
   673 			ornamentsBBox.bottomRight().x(), 
   674 			bottomlineY);
   675 		parPos=QPointF (
   676 			ornamentsBBox.bottomLeft().x(),
   677 			bottomlineY);
   678     }
   679 }
   680 
   681 LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
   682 {
   683 	// Search branches
   684     LinkableMapObj *lmo;
   685 	for (int i=0; i<branch.size(); ++i)
   686     {	
   687 		lmo=branch.at(i)->findMapObj(p, excludeLMO);
   688 		if (lmo != NULL) return lmo;
   689     }
   690 	
   691 
   692 	// Search myself
   693     if (inBox (p) && (this != excludeLMO) && isVisibleObj() ) 
   694 		return this;
   695 
   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);
   703 
   704     return NULL;
   705 }
   706 
   707 LinkableMapObj* BranchObj::findID (QString sid)
   708 {
   709 	// Search branches
   710     LinkableMapObj *lmo;
   711 	for (int i=0; i<branch.size(); ++i)
   712     {	
   713 		lmo=branch.at(i)->findID (sid);
   714 		if (lmo != NULL) return lmo;
   715     }
   716 	
   717 	// Search myself
   718 	if (sid==objID) return this;
   719 
   720 
   721 /*
   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);
   729 */
   730     return NULL;
   731 }
   732 
   733 void BranchObj::setHeading(QString s)
   734 {
   735     heading->setText(s);	// set new heading
   736 	calcBBoxSize();			// recalculate bbox
   737     positionBBox();			// rearrange contents
   738 	requestReposition();
   739 }
   740 
   741 void BranchObj::setHideTmp (HideTmpMode mode)
   742 {
   743 	if (mode==HideExport && hasHiddenExportParent())
   744 	{
   745 		setVisibility (false);
   746 		hidden=true;
   747 	}else
   748 	{
   749 		if (hasScrolledParent(this))
   750 			setVisibility (false);
   751 		else
   752 			setVisibility (true);
   753 		hidden=false;
   754 	}	
   755 
   756 	for (int i=0; i<branch.size(); ++i)
   757 		branch.at(i)->setHideTmp (mode);
   758 }
   759 
   760 bool BranchObj::hasHiddenExportParent()
   761 {
   762 	// Calls parents recursivly to
   763 	// find out, if we are temp. hidden
   764 
   765 	if (hideExport) return true;
   766 
   767 	BranchObj* bo=(BranchObj*)parObj;
   768 	if (bo) 
   769 		return bo->hasHiddenExportParent();
   770 	else
   771 		return false;
   772 }
   773 
   774 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
   775 {
   776 	// Cloudy stuff can be hidden during exports
   777 	if (hidden) return "";
   778 
   779 	// Update of note is usually done while unselecting a branch
   780 	if (isNoteInEditor) getNoteFromTextEditor();
   781 	
   782     QString s,a;
   783 	QString scrolledAttr;
   784 	if (scrolled) 
   785 		scrolledAttr=attribut ("scrolled","yes");
   786 	else
   787 		scrolledAttr="";
   788 
   789 	// save area, if not scrolled
   790 	QString areaAttr;
   791 	if (!((BranchObj*)(parObj))->isScrolled() )
   792 	{
   793 		areaAttr=
   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()));
   798 
   799 	} else
   800 		areaAttr="";
   801 	
   802 	// Providing an ID for a branch makes export to XHTML easier
   803 	QString idAttr;
   804 	if (countXLinks()>0)
   805 		idAttr=attribut ("id",getSelectString());
   806 	else
   807 		idAttr="";
   808 
   809     s=beginElement ("branch" 
   810 		+getOrnAttr() 
   811 		+scrolledAttr 
   812 		+areaAttr 
   813 		+idAttr 
   814 		+getIncludeImageAttr() );
   815     incIndent();
   816 
   817 	// save heading
   818     s+=valueElement("heading", getHeading(),
   819 		attribut ("textColor",QColor(heading->getColor()).name()));
   820 
   821 	// Save frame
   822 	if (frame->getFrameType()!=FrameObj::NoFrame) 
   823 		s+=frame->saveToDir ();
   824 
   825 	// save names of flags set
   826 	s+=standardFlags->saveToDir(tmpdir,prefix,0);
   827 	
   828 	// Save FloatImages
   829 	for (int i=0; i<floatimage.size(); ++i)
   830 		s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
   831 
   832 	// save note
   833 	if (!note.isEmpty() )
   834 		s+=note.saveToDir();
   835 	
   836 	// Save branches
   837 	for (int i=0; i<branch.size(); ++i)
   838 		s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
   839 
   840 	// Save XLinks
   841 	QString ol;	// old link
   842 	QString cl;	// current link
   843 	for (int i=0; i<xlink.size(); ++i)
   844 	{
   845 		cl=xlink.at(i)->saveToDir();
   846 		if (cl!=ol)
   847 		{
   848 			s+=cl;
   849 			ol=cl;
   850 		} else
   851 		{
   852 			qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
   853 		}
   854 	}	
   855 
   856     decIndent();
   857     s+=endElement   ("branch");
   858     return s;
   859 }
   860 
   861 void BranchObj::addXLink (XLinkObj *xlo)
   862 {
   863 	xlink.append (xlo);
   864 	
   865 }
   866 
   867 void BranchObj::removeXLinkRef (XLinkObj *xlo)
   868 {
   869 	xlink.removeAt (xlink.indexOf(xlo));
   870 }
   871 
   872 void BranchObj::deleteXLink(XLinkObj *xlo)
   873 {
   874 	xlo->deactivate();
   875 	if (!xlo->isUsed()) delete (xlo);
   876 }
   877 
   878 void BranchObj::deleteXLinkAt (int i)
   879 {
   880 	XLinkObj *xlo=xlink.at(i);
   881 	xlo->deactivate();
   882 	if (!xlo->isUsed()) delete(xlo);
   883 }
   884 
   885 XLinkObj* BranchObj::XLinkAt (int i)
   886 {
   887 	return xlink.at(i);
   888 }
   889 
   890 int BranchObj::countXLink()
   891 {
   892 	return xlink.count();
   893 }
   894 
   895 
   896 BranchObj* BranchObj::XLinkTargetAt (int i)
   897 {
   898 	if (i>=0 && i<xlink.size())
   899 	{
   900 		if (xlink.at(i))
   901 			return xlink.at(i)->otherBranch (this);
   902 	}
   903 	return NULL;
   904 }
   905 
   906 void BranchObj::setIncludeImagesVer(bool b)
   907 {
   908 	includeImagesVer=b;
   909 	calcBBoxSize();
   910 	positionBBox();
   911 	requestReposition();
   912 }
   913 
   914 bool BranchObj::getIncludeImagesVer()
   915 {
   916 	return includeImagesVer;
   917 }
   918 
   919 void BranchObj::setIncludeImagesHor(bool b)
   920 {
   921 	includeImagesHor=b;
   922 	calcBBoxSize();
   923 	positionBBox();
   924 	requestReposition();
   925 }
   926 
   927 bool BranchObj::getIncludeImagesHor()
   928 {
   929 	return includeImagesHor;
   930 }
   931 
   932 QString BranchObj::getIncludeImageAttr()
   933 {
   934 	QString a;
   935 	if (includeImagesVer)
   936 		a=attribut ("incImgV","true");
   937 	else
   938 		a=attribut ("incImgV","false");
   939 	if (includeImagesHor)
   940 		a+=attribut ("incImgH","true");
   941 	else
   942 		a+=attribut ("incImgH","false");
   943 	return a;	
   944 }
   945 
   946 FloatImageObj* BranchObj::addFloatImage ()
   947 {
   948 	FloatImageObj *newfi=new FloatImageObj (scene,this);
   949 	floatimage.append (newfi);
   950 	if (hasScrolledParent(this) )
   951 		newfi->setVisibility (false);
   952 	else	
   953 		newfi->setVisibility(visible);
   954 		/*
   955 	calcBBoxSize();
   956 	positionBBox();
   957 	*/
   958 	requestReposition();
   959 	return newfi;
   960 }
   961 
   962 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
   963 {
   964 	FloatImageObj *newfi=new FloatImageObj (scene,this);
   965 	floatimage.append (newfi);
   966 	newfi->copy (fio);
   967 	if (hasScrolledParent(this) )
   968 		newfi->setVisibility (false);
   969 	else	
   970 		newfi->setVisibility(visible);
   971 		/*
   972 	calcBBoxSize();
   973 	positionBBox();
   974 	*/
   975 	requestReposition();
   976 	return newfi;
   977 }
   978 
   979 FloatImageObj* BranchObj::getFirstFloatImage ()
   980 {
   981     return floatimage.first();
   982 }
   983 
   984 FloatImageObj* BranchObj::getLastFloatImage ()
   985 {
   986     return floatimage.last();
   987 }
   988 
   989 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
   990 {
   991     return floatimage.at(i);
   992 }
   993 
   994 void BranchObj::removeFloatImage (FloatImageObj *fio)
   995 {
   996 	int i=floatimage.indexOf (fio);
   997 	if (i>-1) delete (floatimage.takeAt (i));
   998 	calcBBoxSize();
   999 	positionBBox();
  1000 	requestReposition();
  1001 }
  1002 
  1003 void BranchObj::savePosInAngle ()
  1004 {
  1005 	// Save position in angle
  1006 	for (int i=0; i<branch.size(); ++i)
  1007 		branch.at(i)->angle=i;
  1008 }
  1009 
  1010 void BranchObj::setDefAttr (BranchModification mod)
  1011 {
  1012 	int fontsize;
  1013 	switch (depth)
  1014 	{
  1015 		case 0: fontsize=16; break;
  1016 		case 1: fontsize=12; break;
  1017 		default: fontsize=10; break;
  1018 	}	
  1019 
  1020 	setLinkColor ();
  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 );
  1025 
  1026 	if (mod==NewBranch)
  1027 		setColor (((BranchObj*)(parObj))->getColor());
  1028 	
  1029 	calcBBoxSize();
  1030 }
  1031 
  1032 BranchObj* BranchObj::addBranch()
  1033 {
  1034     BranchObj* newbo=new BranchObj(scene,this);
  1035     branch.append (newbo);
  1036     newbo->setParObj(this);
  1037 	newbo->setDefAttr(NewBranch);
  1038     newbo->setHeading ("new");
  1039 	if (scrolled)
  1040 		newbo->setVisibility (false);
  1041 	else	
  1042 		newbo->setVisibility(visible);
  1043 	newbo->updateLink();	
  1044 	requestReposition();
  1045 	return newbo;
  1046 }
  1047 
  1048 BranchObj* BranchObj::addBranch(BranchObj* bo)
  1049 {
  1050     BranchObj* newbo=new BranchObj(scene,this);
  1051     branch.append (newbo);
  1052     newbo->copy(bo);
  1053     newbo->setParObj(this);
  1054 	newbo->setDefAttr(MovedBranch);
  1055 	if (scrolled)
  1056 		newbo->setVisibility (false);
  1057 	else	
  1058 		newbo->setVisibility(bo->visible);
  1059 	newbo->updateLink();	
  1060 	requestReposition();
  1061 	return newbo;
  1062 }
  1063 
  1064 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
  1065 {
  1066 	branch.append (bo);
  1067 	bo->setParObj (this);
  1068 	bo->depth=depth+1;
  1069 	bo->setDefAttr(MovedBranch);
  1070 	if (scrolled) tmpUnscroll();
  1071 	setLastSelectedBranch (bo);
  1072 	return bo;
  1073 }
  1074 
  1075 BranchObj* BranchObj::insertBranch(int pos)
  1076 {
  1077 	savePosInAngle();
  1078 	// Add new bo and resort branches
  1079 	BranchObj *newbo=addBranch ();
  1080 	newbo->angle=pos-0.5;
  1081 	qSort (branch.begin(),branch.end(), isAbove);
  1082 	return newbo;
  1083 }
  1084 
  1085 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
  1086 {
  1087 	savePosInAngle();
  1088 	// Add new bo and resort branches
  1089 	bo->angle=pos-0.5;
  1090 	BranchObj *newbo=addBranch (bo);
  1091 	qSort (branch.begin(),branch.end(), isAbove);
  1092 	return newbo;
  1093 }
  1094 
  1095 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
  1096 {
  1097 	savePosInAngle();
  1098 	// Add new bo and resort branches
  1099 	bo->angle=pos-0.5;
  1100 	branch.append (bo);
  1101 	bo->setParObj (this);
  1102 	bo->depth=depth+1;
  1103 	bo->setDefAttr (MovedBranch);
  1104 	if (scrolled) tmpUnscroll();
  1105 	setLastSelectedBranch (bo);
  1106 	qSort (branch.begin(),branch.end(), isAbove);
  1107 	return bo;
  1108 }
  1109 
  1110 void BranchObj::removeBranchHere(BranchObj* borem)
  1111 {
  1112 	// This removes the branch bo from list, but 
  1113 	// inserts its childs at the place of bo
  1114 	BranchObj *bo;
  1115 	bo=borem->getLastBranch();
  1116 	int pos=borem->getNum();
  1117 	while (bo)
  1118 	{
  1119 		bo->linkTo (this,pos+1);
  1120 		bo=borem->getLastBranch();
  1121 	}	
  1122 	removeBranch (borem);
  1123 }
  1124 
  1125 void BranchObj::removeChilds()
  1126 {
  1127 	clear();
  1128 }
  1129 
  1130 void BranchObj::removeBranch(BranchObj* bo)
  1131 {
  1132     // if bo is not in branch remove returns false, we
  1133     // don't care...
  1134 	
  1135 	int i=branch.indexOf(bo);
  1136     if (i>=0)
  1137 	{
  1138 		delete (bo);
  1139 		branch.removeAt (i);
  1140 	} else
  1141 		qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
  1142 	requestReposition();
  1143 }
  1144 
  1145 void BranchObj::removeBranchPtr(BranchObj* bo)
  1146 {
  1147 	int i=branch.indexOf(bo);
  1148 	
  1149 	if (i>=0)
  1150 		branch.removeAt (i);
  1151 	else	
  1152 		qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
  1153 	requestReposition();
  1154 }
  1155 
  1156 void BranchObj::setLastSelectedBranch (BranchObj* bo)
  1157 {
  1158     lastSelectedBranch=branch.indexOf(bo);
  1159 }
  1160 
  1161 BranchObj* BranchObj::getLastSelectedBranch ()
  1162 {
  1163     if (lastSelectedBranch>=0)
  1164 	{
  1165 		if ( branch.size()>lastSelectedBranch) 
  1166 			return branch.at(lastSelectedBranch);
  1167 		if (branch.size()>0)
  1168 			return branch.last();
  1169 	}	
  1170     return NULL;
  1171 }
  1172 
  1173 BranchObj* BranchObj::getFirstBranch ()
  1174 {
  1175 	if (branch.size()>0)
  1176 		return branch.first();
  1177 	else
  1178 		return NULL;
  1179 }
  1180 
  1181 BranchObj* BranchObj::getLastBranch ()
  1182 {
  1183 	if (branch.size()>0)
  1184 		return branch.last();
  1185 	else
  1186 		return NULL;
  1187 }
  1188 
  1189 BranchObj* BranchObj::getBranchNum (int i)
  1190 {
  1191 	if (i>=0 && i<branch.size())
  1192 		return branch.at(i);
  1193 	else	
  1194 		return	NULL;
  1195 }
  1196 
  1197 bool BranchObj::canMoveBranchUp() 
  1198 {
  1199 	if (!parObj || depth==1) return false;
  1200 	BranchObj* par=(BranchObj*)parObj;
  1201 	if (this==par->getFirstBranch())
  1202 		return false;
  1203 	else
  1204 		return true;
  1205 }
  1206 
  1207 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
  1208 {
  1209 	savePosInAngle();
  1210     int i=branch.indexOf(bo1);
  1211     if (i>0) 
  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);
  1217 	} else
  1218 		return NULL;
  1219 }
  1220 
  1221 bool BranchObj::canMoveBranchDown() 
  1222 {
  1223 	if (!parObj|| depth==1) return false;
  1224 	BranchObj* par=(BranchObj*)parObj;
  1225 	if (this==par->getLastBranch())
  1226 		return false;
  1227 	else
  1228 		return true;
  1229 }
  1230 
  1231 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
  1232 {
  1233 	savePosInAngle();
  1234     int i=branch.indexOf(bo1);
  1235 	int j;
  1236 	if (i <branch.size())
  1237 	{
  1238 		j = i+1;
  1239 		branch.at(i)->angle++;
  1240 		branch.at(j)->angle--;
  1241 		qSort (branch.begin(),branch.end(), isAbove);
  1242 		return branch.at(i);
  1243 	} else
  1244 		return NULL;
  1245 }
  1246 
  1247 void BranchObj::sortChildren()
  1248 {
  1249 	int childCount=branch.count();
  1250 	int curChildIndex;
  1251 	bool madeChanges=false;
  1252 	do
  1253 	{
  1254 		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)
  1259 			{
  1260 				this->moveBranchUp(curChild);
  1261 				madeChanges=true;
  1262 			}
  1263 		}
  1264 	}while(madeChanges);
  1265 }
  1266 
  1267 
  1268 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
  1269 {
  1270 	// Find current parent and 
  1271 	// remove pointer to myself there
  1272 	if (!dst) return NULL;
  1273 	BranchObj *par=(BranchObj*)parObj;
  1274 	if (par)
  1275 		par->removeBranchPtr (this);
  1276 	else
  1277 		return NULL;
  1278 
  1279 	// Create new pointer to myself at dst
  1280 	if (pos<0||dst->getDepth()==0)
  1281 	{	
  1282 		// links myself as last branch at dst
  1283 		dst->addBranchPtr (this);
  1284 		updateLink();
  1285 		return this;
  1286 	} else
  1287 	{
  1288 		// inserts me at pos in parent of dst
  1289 		if (par)
  1290 		{
  1291 			BranchObj *bo=dst->insertBranchPtr (this,pos);
  1292 			bo->setDefAttr(MovedBranch);
  1293 			updateLink();
  1294 			return bo;
  1295 
  1296 		} else
  1297 			return NULL;
  1298 	}	
  1299 }
  1300 
  1301 void BranchObj::alignRelativeTo (QPointF ref)
  1302 {
  1303 	qreal th = bboxTotal.height();	
  1304 // TODO testing
  1305 /*
  1306 	cout << "BO::alignRelTo "<<getHeading().ascii()<<endl;
  1307 	cout << "  d="<<depth<<
  1308 		"  ref="<<ref<<
  1309 //		"  bbox.topLeft="<<bboxTotal.topLeft()<<
  1310 		"  absPos="<<absPos<<
  1311 		"  relPos="<<relPos<<
  1312 		"  orient="<<orientation<<
  1313 //		"  pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
  1314 //		"  hidden="<<hidden<<
  1315 //		"  th="<<th<<
  1316 		endl;
  1317 */
  1318 
  1319 	setOrientation();
  1320 	//updateLink();
  1321 
  1322 	if (depth<2)
  1323 	{
  1324 		if (depth==1)
  1325 		{
  1326 			// Position relatively, if needed
  1327 			//if (useRelPos) move2RelPos (relPos.x(), relPos.y());
  1328 
  1329 			// Calc angle to mapCenter if I am a mainbranch
  1330 			// needed for reordering the mainbranches clockwise 
  1331 			// around mapcenter 
  1332 			angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ), 
  1333 									(int)(y() - parObj->getChildPos().y() ) ) );
  1334 		}							
  1335 	} 
  1336 	else
  1337     {
  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) 
  1343 		{
  1344 			case LinkableMapObj::LeftOfCenter:
  1345 				move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
  1346 			break;
  1347 			case LinkableMapObj::RightOfCenter:	
  1348 				move (ref.x() , ref.y() + (th-bbox.height())/2  );
  1349 			break;
  1350 			default:
  1351 				qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
  1352 			break;
  1353 		}		
  1354     }		
  1355 
  1356 	if (scrolled) return;
  1357 
  1358     // Set reference point for alignment of childs
  1359     QPointF ref2;
  1360     if (orientation==LinkableMapObj::LeftOfCenter)
  1361 		ref2.setX(bbox.topLeft().x() - linkwidth);
  1362     else	
  1363 		ref2.setX(bbox.topRight().x() + linkwidth);
  1364 
  1365 	if (depth==1)
  1366 		ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
  1367 	else	
  1368 		ref2.setY(ref.y() );	
  1369 
  1370     // Align the childs depending on reference point 
  1371 	for (int i=0; i<branch.size(); ++i)
  1372     {	
  1373 		if (!branch.at(i)->isHidden())
  1374 		{
  1375 			branch.at(i)->alignRelativeTo (ref2);
  1376 			ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChilds().height() );
  1377 		}
  1378     }
  1379 }
  1380 
  1381 
  1382 void BranchObj::reposition()
  1383 {	
  1384 /* TODO testing only
  1385 	if (!getHeading().isEmpty())
  1386 		cout << "BO::reposition  "<<getHeading().ascii()<<endl;
  1387 	else	
  1388 		cout << "BO::reposition  ???"<<endl;
  1389 
  1390 	cout << "  orient="<<orientation<<endl;
  1391 */		
  1392 
  1393 	if (depth==0)
  1394 	{
  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
  1401 
  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
  1406 	} else
  1407 	{
  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) );
  1412 	}
  1413 }
  1414 
  1415 void BranchObj::unsetAllRepositionRequests()
  1416 {
  1417 	repositionRequest=false;
  1418 	for (int i=0; i<branch.size(); ++i)
  1419 		branch.at(i)->unsetAllRepositionRequests();
  1420 }
  1421 
  1422 
  1423 QRectF BranchObj::getTotalBBox()
  1424 {
  1425 	QRectF r=bbox;
  1426 
  1427 	if (scrolled) return r;
  1428 
  1429 	for (int i=0; i<branch.size(); ++i)
  1430 		if (!branch.at(i)->isHidden())
  1431 			r=addBBox(branch.at(i)->getTotalBBox(),r);
  1432 
  1433 	for (int i=0; i<floatimage.size(); ++i)
  1434 		if (!floatimage.at(i)->isHidden())
  1435 			r=addBBox(floatimage.at(i)->getTotalBBox(),r);
  1436 		
  1437 	return r;
  1438 }
  1439 
  1440 QRectF BranchObj::getBBoxSizeWithChilds()
  1441 {
  1442 	return bboxTotal;
  1443 }
  1444 
  1445 void BranchObj::calcBBoxSizeWithChilds()
  1446 {	
  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 
  1450 	// action
  1451 	
  1452 
  1453 	// Calculate size of LMO including all childs (to align them later)
  1454 	bboxTotal.setX(bbox.x() );
  1455 	bboxTotal.setY(bbox.y() );
  1456 
  1457 	// if branch is scrolled, ignore childs, but still consider floatimages
  1458 	if (scrolled)
  1459 	{
  1460 		bboxTotal.setWidth (bbox.width());
  1461 		bboxTotal.setHeight(bbox.height());
  1462 		return;
  1463 	}
  1464 	
  1465 	if (hidden)
  1466 	{
  1467 		bboxTotal.setWidth (0);
  1468 		bboxTotal.setHeight(0);
  1469 		if (parObj)
  1470 		{
  1471 			bboxTotal.setX (parObj->x());
  1472 			bboxTotal.setY (parObj->y());
  1473 		} else
  1474 		{
  1475 			bboxTotal.setX (bbox.x());
  1476 			bboxTotal.setY (bbox.y());
  1477 		}
  1478 		return;
  1479 	}
  1480 	
  1481 	QRectF r(0,0,0,0);
  1482 	QRectF br;
  1483 	// Now calculate recursivly
  1484 	// sum of heights 
  1485 	// maximum of widths 
  1486 	// minimum of y
  1487 	for (int i=0; i<branch.size(); ++i)
  1488 	{
  1489 		if (!branch.at(i)->isHidden())
  1490 		{
  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());
  1496 		}
  1497 	}
  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() );
  1502 	else	
  1503 		bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
  1504 	
  1505 	bboxTotal.setHeight(max (r.height(),  bbox.height()));
  1506 }
  1507 
  1508 void BranchObj::select()
  1509 {
  1510 	// update NoteEditor
  1511 	textEditor->setText(note.getNote() );
  1512 	QString fnh=note.getFilenameHint();
  1513 	if (fnh!="")
  1514 		textEditor->setFilenameHint(note.getFilenameHint() );
  1515 	else	
  1516 		textEditor->setFilenameHint(getHeading() );
  1517 	textEditor->setFontHint (note.getFontHint() );
  1518 	isNoteInEditor=true;
  1519 
  1520 	// set selected and visible
  1521     LinkableMapObj::select();
  1522 
  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);
  1527 		
  1528 	// temporary unscroll, if we have scrolled parents somewhere
  1529 	if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
  1530 
  1531 	// Show URL and link in statusbar
  1532 	QString status;
  1533 	if (!url.isEmpty()) status+="URL: "+url+"  ";
  1534 	if (!vymLink.isEmpty()) status+="Link: "+vymLink;
  1535 	if (!status.isEmpty()) mainWindow->statusMessage (status);
  1536 
  1537 	// Update Toolbar
  1538 	updateFlagsToolbar();
  1539 
  1540 	// Update actions
  1541 	mapEditor->updateActions();
  1542 }
  1543 
  1544 void BranchObj::unselect()
  1545 {
  1546 	LinkableMapObj::unselect();
  1547 	// Delete any messages like vymLink in StatusBar
  1548 	mainWindow->statusMessage ("");
  1549 
  1550 	// Save current note
  1551 	if (isNoteInEditor) getNoteFromTextEditor();
  1552 	isNoteInEditor=false;
  1553 
  1554 	// reset temporary unscroll, if we have scrolled parents somewhere
  1555 	if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
  1556 
  1557 	// Erase content of editor 
  1558 	textEditor->setInactive();
  1559 
  1560 	// unselect all buttons in toolbar
  1561 	standardFlagsDefault->updateToolbar();
  1562 }
  1563 
  1564 QString BranchObj::getSelectString()
  1565 {
  1566 	QString s;
  1567 	if (parObj)
  1568 	{
  1569 		if (depth==1)
  1570 			s= "bo:" + QString("%1").arg(getNum());
  1571 		else	
  1572 			s= ((BranchObj*)(parObj))->getSelectString() + ",bo:" + QString("%1").arg(getNum());
  1573 	} else
  1574 		s="mc:";
  1575 	return s;
  1576 }
  1577 
  1578 
  1579 void BranchObj::animate()
  1580 {
  1581 	//relPos.animate();
  1582 	cout << "BO::animate  x,y="<<relPos.x()<<","<<relPos.y()<<endl;
  1583 }
  1584