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