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