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