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