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