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