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