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