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