branchobj.cpp
author insilmaril
Mon, 22 Oct 2007 09:50:09 +0000
changeset 610 ff98aee6fb99
parent 604 f2aab2a9b6cb
child 611 a1ae877b438d
permissions -rw-r--r--
Various patches: Better windows support, branch sorting, Freedesktop support
     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 
   686 	// Search myself
   687     if (inBox (p) && (this != excludeLMO) && isVisibleObj() ) 
   688 		return this;
   689 
   690 	// Search float images
   691     for (int i=0; i<floatimage.size(); ++i )
   692 		if (floatimage.at(i)->inBox(p) && 
   693 			(floatimage.at(i) != excludeLMO) && 
   694 			floatimage.at(i)->getParObj()!= excludeLMO &&
   695 			floatimage.at(i)->isVisibleObj() 
   696 		) return floatimage.at(i);
   697 
   698     return NULL;
   699 }
   700 
   701 LinkableMapObj* BranchObj::findID (QString sid)
   702 {
   703 	// Search branches
   704     LinkableMapObj *lmo;
   705 	for (int i=0; i<branch.size(); ++i)
   706     {	
   707 		lmo=branch.at(i)->findID (sid);
   708 		if (lmo != NULL) return lmo;
   709     }
   710 	
   711 	// Search myself
   712 	if (sid==objID) return this;
   713 
   714 
   715 /*
   716 	// Search float images
   717     for (int i=0; i<floatimage.size(); ++i )
   718 		if (floatimage.at(i)->inBox(p) && 
   719 			(floatimage.at(i) != excludeLMO) && 
   720 			floatimage.at(i)->getParObj()!= excludeLMO &&
   721 			floatimage.at(i)->isVisibleObj() 
   722 		) return floatimage.at(i);
   723 */
   724     return NULL;
   725 }
   726 
   727 void BranchObj::setHeading(QString s)
   728 {
   729     heading->setText(s);	// set new heading
   730 	calcBBoxSize();			// recalculate bbox
   731     positionBBox();			// rearrange contents
   732 	requestReposition();
   733 }
   734 
   735 void BranchObj::setHideTmp (HideTmpMode mode)
   736 {
   737 	if (mode==HideExport && hasHiddenExportParent())
   738 	{
   739 		setVisibility (false);
   740 		hidden=true;
   741 	}else
   742 	{
   743 		if (hasScrolledParent(this))
   744 			setVisibility (false);
   745 		else
   746 			setVisibility (true);
   747 		hidden=false;
   748 	}	
   749 
   750 	for (int i=0; i<branch.size(); ++i)
   751 		branch.at(i)->setHideTmp (mode);
   752 }
   753 
   754 bool BranchObj::hasHiddenExportParent()
   755 {
   756 	// Calls parents recursivly to
   757 	// find out, if we are temp. hidden
   758 
   759 	if (hideExport) return true;
   760 
   761 	BranchObj* bo=(BranchObj*)parObj;
   762 	if (bo) 
   763 		return bo->hasHiddenExportParent();
   764 	else
   765 		return false;
   766 }
   767 
   768 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
   769 {
   770 	// Cloudy stuff can be hidden during exports
   771 	if (hidden) return "";
   772 
   773 	// Update of note is usually done while unselecting a branch
   774 	if (isNoteInEditor) getNoteFromTextEditor();
   775 	
   776     QString s,a;
   777 	QString scrolledAttr;
   778 	if (scrolled) 
   779 		scrolledAttr=attribut ("scrolled","yes");
   780 	else
   781 		scrolledAttr="";
   782 
   783 	// save area, if not scrolled
   784 	QString areaAttr;
   785 	if (!((BranchObj*)(parObj))->isScrolled() )
   786 	{
   787 		areaAttr=
   788 			attribut("x1",QString().setNum(absPos.x()-offset.x())) +
   789 			attribut("y1",QString().setNum(absPos.y()-offset.y())) +
   790 			attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
   791 			attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
   792 
   793 	} else
   794 		areaAttr="";
   795 	
   796 	// Providing an ID for a branch makes export to XHTML easier
   797 	QString idAttr;
   798 	if (countXLinks()>0)
   799 		idAttr=attribut ("id",getSelectString());
   800 	else
   801 		idAttr="";
   802 
   803     s=beginElement ("branch" 
   804 		+getOrnAttr() 
   805 		+scrolledAttr 
   806 		+areaAttr 
   807 		+idAttr 
   808 		+getIncludeImageAttr() );
   809     incIndent();
   810 
   811 	// save heading
   812     s+=valueElement("heading", getHeading(),
   813 		attribut ("textColor",QColor(heading->getColor()).name()));
   814 
   815 	// Save frame
   816 	if (frame->getFrameType()!=FrameObj::NoFrame) 
   817 		s+=frame->saveToDir ();
   818 
   819 	// save names of flags set
   820 	s+=standardFlags->saveToDir(tmpdir,prefix,0);
   821 	
   822 	// Save FloatImages
   823 	for (int i=0; i<floatimage.size(); ++i)
   824 		s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
   825 
   826 	// save note
   827 	if (!note.isEmpty() )
   828 		s+=note.saveToDir();
   829 	
   830 	// Save branches
   831 	for (int i=0; i<branch.size(); ++i)
   832 		s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
   833 
   834 	// Save XLinks
   835 	QString ol;	// old link
   836 	QString cl;	// current link
   837 	for (int i=0; i<xlink.size(); ++i)
   838 	{
   839 		cl=xlink.at(i)->saveToDir();
   840 		if (cl!=ol)
   841 		{
   842 			s+=cl;
   843 			ol=cl;
   844 		} else
   845 		{
   846 			qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
   847 		}
   848 	}	
   849 
   850     decIndent();
   851     s+=endElement   ("branch");
   852     return s;
   853 }
   854 
   855 void BranchObj::addXLink (XLinkObj *xlo)
   856 {
   857 	xlink.append (xlo);
   858 	
   859 }
   860 
   861 void BranchObj::removeXLinkRef (XLinkObj *xlo)
   862 {
   863 	xlink.removeAt (xlink.indexOf(xlo));
   864 }
   865 
   866 void BranchObj::deleteXLink(XLinkObj *xlo)
   867 {
   868 	xlo->deactivate();
   869 	if (!xlo->isUsed()) delete (xlo);
   870 }
   871 
   872 void BranchObj::deleteXLinkAt (int i)
   873 {
   874 	XLinkObj *xlo=xlink.at(i);
   875 	xlo->deactivate();
   876 	if (!xlo->isUsed()) delete(xlo);
   877 }
   878 
   879 XLinkObj* BranchObj::XLinkAt (int i)
   880 {
   881 	return xlink.at(i);
   882 }
   883 
   884 int BranchObj::countXLink()
   885 {
   886 	return xlink.count();
   887 }
   888 
   889 
   890 BranchObj* BranchObj::XLinkTargetAt (int i)
   891 {
   892 	if (i>=0 && i<xlink.size())
   893 	{
   894 		if (xlink.at(i))
   895 			return xlink.at(i)->otherBranch (this);
   896 	}
   897 	return NULL;
   898 }
   899 
   900 void BranchObj::setIncludeImagesVer(bool b)
   901 {
   902 	includeImagesVer=b;
   903 	calcBBoxSize();
   904 	positionBBox();
   905 	requestReposition();
   906 }
   907 
   908 bool BranchObj::getIncludeImagesVer()
   909 {
   910 	return includeImagesVer;
   911 }
   912 
   913 void BranchObj::setIncludeImagesHor(bool b)
   914 {
   915 	includeImagesHor=b;
   916 	calcBBoxSize();
   917 	positionBBox();
   918 	requestReposition();
   919 }
   920 
   921 bool BranchObj::getIncludeImagesHor()
   922 {
   923 	return includeImagesHor;
   924 }
   925 
   926 QString BranchObj::getIncludeImageAttr()
   927 {
   928 	QString a;
   929 	if (includeImagesVer)
   930 		a=attribut ("incImgV","true");
   931 	else
   932 		a=attribut ("incImgV","false");
   933 	if (includeImagesHor)
   934 		a+=attribut ("incImgH","true");
   935 	else
   936 		a+=attribut ("incImgH","false");
   937 	return a;	
   938 }
   939 
   940 FloatImageObj* BranchObj::addFloatImage ()
   941 {
   942 	FloatImageObj *newfi=new FloatImageObj (scene,this);
   943 	floatimage.append (newfi);
   944 	if (hasScrolledParent(this) )
   945 		newfi->setVisibility (false);
   946 	else	
   947 		newfi->setVisibility(visible);
   948 		/*
   949 	calcBBoxSize();
   950 	positionBBox();
   951 	*/
   952 	requestReposition();
   953 	return newfi;
   954 }
   955 
   956 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
   957 {
   958 	FloatImageObj *newfi=new FloatImageObj (scene,this);
   959 	floatimage.append (newfi);
   960 	newfi->copy (fio);
   961 	if (hasScrolledParent(this) )
   962 		newfi->setVisibility (false);
   963 	else	
   964 		newfi->setVisibility(visible);
   965 		/*
   966 	calcBBoxSize();
   967 	positionBBox();
   968 	*/
   969 	requestReposition();
   970 	return newfi;
   971 }
   972 
   973 FloatImageObj* BranchObj::getFirstFloatImage ()
   974 {
   975     return floatimage.first();
   976 }
   977 
   978 FloatImageObj* BranchObj::getLastFloatImage ()
   979 {
   980     return floatimage.last();
   981 }
   982 
   983 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
   984 {
   985     return floatimage.at(i);
   986 }
   987 
   988 void BranchObj::removeFloatImage (FloatImageObj *fio)
   989 {
   990 	int i=floatimage.indexOf (fio);
   991 	if (i>-1) delete (floatimage.takeAt (i));
   992 	calcBBoxSize();
   993 	positionBBox();
   994 	requestReposition();
   995 }
   996 
   997 void BranchObj::savePosInAngle ()
   998 {
   999 	// Save position in angle
  1000 	for (int i=0; i<branch.size(); ++i)
  1001 		branch.at(i)->angle=i;
  1002 }
  1003 
  1004 void BranchObj::setDefAttr (BranchModification mod)
  1005 {
  1006 	int fontsize;
  1007 	switch (depth)
  1008 	{
  1009 		case 0: fontsize=16; break;
  1010 		case 1: fontsize=12; break;
  1011 		default: fontsize=10; break;
  1012 	}	
  1013 
  1014 	setLinkColor ();
  1015 	setLinkStyle(getDefLinkStyle());
  1016 	QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
  1017 	font.setPointSize(fontsize);
  1018 	heading->setFont(font );
  1019 
  1020 	if (mod==NewBranch)
  1021 		setColor (((BranchObj*)(parObj))->getColor());
  1022 	
  1023 	calcBBoxSize();
  1024 }
  1025 
  1026 BranchObj* BranchObj::addBranch()
  1027 {
  1028     BranchObj* newbo=new BranchObj(scene,this);
  1029     branch.append (newbo);
  1030     newbo->setParObj(this);
  1031 	newbo->setDefAttr(NewBranch);
  1032     newbo->setHeading ("new");
  1033 	if (scrolled)
  1034 		newbo->setVisibility (false);
  1035 	else	
  1036 		newbo->setVisibility(visible);
  1037 	newbo->updateLink();	
  1038 	requestReposition();
  1039 	return newbo;
  1040 }
  1041 
  1042 BranchObj* BranchObj::addBranch(BranchObj* bo)
  1043 {
  1044     BranchObj* newbo=new BranchObj(scene,this);
  1045     branch.append (newbo);
  1046     newbo->copy(bo);
  1047     newbo->setParObj(this);
  1048 	newbo->setDefAttr(MovedBranch);
  1049 	if (scrolled)
  1050 		newbo->setVisibility (false);
  1051 	else	
  1052 		newbo->setVisibility(bo->visible);
  1053 	newbo->updateLink();	
  1054 	requestReposition();
  1055 	return newbo;
  1056 }
  1057 
  1058 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
  1059 {
  1060 	branch.append (bo);
  1061 	bo->setParObj (this);
  1062 	bo->depth=depth+1;
  1063 	bo->setDefAttr(MovedBranch);
  1064 	if (scrolled) tmpUnscroll();
  1065 	setLastSelectedBranch (bo);
  1066 	return bo;
  1067 }
  1068 
  1069 BranchObj* BranchObj::insertBranch(int pos)
  1070 {
  1071 	savePosInAngle();
  1072 	// Add new bo and resort branches
  1073 	BranchObj *newbo=addBranch ();
  1074 	newbo->angle=pos-0.5;
  1075 	qSort (branch.begin(),branch.end(), isAbove);
  1076 	return newbo;
  1077 }
  1078 
  1079 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
  1080 {
  1081 	savePosInAngle();
  1082 	// Add new bo and resort branches
  1083 	bo->angle=pos-0.5;
  1084 	BranchObj *newbo=addBranch (bo);
  1085 	qSort (branch.begin(),branch.end(), isAbove);
  1086 	return newbo;
  1087 }
  1088 
  1089 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
  1090 {
  1091 	savePosInAngle();
  1092 	// Add new bo and resort branches
  1093 	bo->angle=pos-0.5;
  1094 	branch.append (bo);
  1095 	bo->setParObj (this);
  1096 	bo->depth=depth+1;
  1097 	bo->setDefAttr (MovedBranch);
  1098 	if (scrolled) tmpUnscroll();
  1099 	setLastSelectedBranch (bo);
  1100 	qSort (branch.begin(),branch.end(), isAbove);
  1101 	return bo;
  1102 }
  1103 
  1104 void BranchObj::removeBranchHere(BranchObj* borem)
  1105 {
  1106 	// This removes the branch bo from list, but 
  1107 	// inserts its childs at the place of bo
  1108 	BranchObj *bo;
  1109 	bo=borem->getLastBranch();
  1110 	int pos=borem->getNum();
  1111 	while (bo)
  1112 	{
  1113 		bo->linkTo (this,pos+1);
  1114 		bo=borem->getLastBranch();
  1115 	}	
  1116 	removeBranch (borem);
  1117 }
  1118 
  1119 void BranchObj::removeChilds()
  1120 {
  1121 	clear();
  1122 }
  1123 
  1124 void BranchObj::removeBranch(BranchObj* bo)
  1125 {
  1126     // if bo is not in branch remove returns false, we
  1127     // don't care...
  1128 	
  1129 	int i=branch.indexOf(bo);
  1130     if (i>=0)
  1131 	{
  1132 		delete (bo);
  1133 		branch.removeAt (i);
  1134 	} else
  1135 		qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
  1136 	requestReposition();
  1137 }
  1138 
  1139 void BranchObj::removeBranchPtr(BranchObj* bo)
  1140 {
  1141 	int i=branch.indexOf(bo);
  1142 	
  1143 	if (i>=0)
  1144 		branch.removeAt (i);
  1145 	else	
  1146 		qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
  1147 	requestReposition();
  1148 }
  1149 
  1150 void BranchObj::setLastSelectedBranch (BranchObj* bo)
  1151 {
  1152     lastSelectedBranch=branch.indexOf(bo);
  1153 }
  1154 
  1155 BranchObj* BranchObj::getLastSelectedBranch ()
  1156 {
  1157     if (lastSelectedBranch>=0)
  1158 	{
  1159 		if ( branch.size()>lastSelectedBranch) 
  1160 			return branch.at(lastSelectedBranch);
  1161 		if (branch.size()>0)
  1162 			return branch.last();
  1163 	}	
  1164     return NULL;
  1165 }
  1166 
  1167 BranchObj* BranchObj::getFirstBranch ()
  1168 {
  1169 	if (branch.size()>0)
  1170 		return branch.first();
  1171 	else
  1172 		return NULL;
  1173 }
  1174 
  1175 BranchObj* BranchObj::getLastBranch ()
  1176 {
  1177 	if (branch.size()>0)
  1178 		return branch.last();
  1179 	else
  1180 		return NULL;
  1181 }
  1182 
  1183 BranchObj* BranchObj::getBranchNum (int i)
  1184 {
  1185 	if (i>=0 && i<branch.size())
  1186 		return branch.at(i);
  1187 	else	
  1188 		return	NULL;
  1189 }
  1190 
  1191 bool BranchObj::canMoveBranchUp() 
  1192 {
  1193 	if (!parObj || depth==1) return false;
  1194 	BranchObj* par=(BranchObj*)parObj;
  1195 	if (this==par->getFirstBranch())
  1196 		return false;
  1197 	else
  1198 		return true;
  1199 }
  1200 
  1201 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
  1202 {
  1203 	savePosInAngle();
  1204     int i=branch.indexOf(bo1);
  1205     if (i>0) 
  1206 	{	// -1 if bo1 not found 
  1207 		branch.at(i)->angle--;
  1208 		branch.at(i-1)->angle++;
  1209 		qSort (branch.begin(),branch.end(), isAbove);
  1210 		return branch.at(i);
  1211 	} else
  1212 		return NULL;
  1213 }
  1214 
  1215 bool BranchObj::canMoveBranchDown() 
  1216 {
  1217 	if (!parObj|| depth==1) return false;
  1218 	BranchObj* par=(BranchObj*)parObj;
  1219 	if (this==par->getLastBranch())
  1220 		return false;
  1221 	else
  1222 		return true;
  1223 }
  1224 
  1225 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
  1226 {
  1227 	savePosInAngle();
  1228     int i=branch.indexOf(bo1);
  1229 	int j;
  1230 	if (i <branch.size())
  1231 	{
  1232 		j = i+1;
  1233 		branch.at(i)->angle++;
  1234 		branch.at(j)->angle--;
  1235 		qSort (branch.begin(),branch.end(), isAbove);
  1236 		return branch.at(i);
  1237 	} else
  1238 		return NULL;
  1239 }
  1240 
  1241 void BranchObj::sortChildren()
  1242 {
  1243 	int childCount=branch.count();
  1244 	int curChildIndex;
  1245 	bool madeChanges=false;
  1246 	do
  1247 	{
  1248 		madeChanges=false;
  1249 		for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
  1250 			BranchObj* curChild=(BranchObj*)branch.at(curChildIndex);
  1251 			BranchObj* prevChild=(BranchObj*)branch.at(curChildIndex-1);
  1252 			if(prevChild->heading->text().compare(curChild->heading->text())>0)
  1253 			{
  1254 				this->moveBranchUp(curChild);
  1255 				madeChanges=true;
  1256 			}
  1257 		}
  1258 	}while(madeChanges);
  1259 }
  1260 
  1261 
  1262 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
  1263 {
  1264 	// Find current parent and 
  1265 	// remove pointer to myself there
  1266 	if (!dst) return NULL;
  1267 	BranchObj *par=(BranchObj*)parObj;
  1268 	if (par)
  1269 		par->removeBranchPtr (this);
  1270 	else
  1271 		return NULL;
  1272 
  1273 	// Create new pointer to myself at dst
  1274 	if (pos<0||dst->getDepth()==0)
  1275 	{	
  1276 		// links myself as last branch at dst
  1277 		dst->addBranchPtr (this);
  1278 		updateLink();
  1279 		return this;
  1280 	} else
  1281 	{
  1282 		// inserts me at pos in parent of dst
  1283 		if (par)
  1284 		{
  1285 			BranchObj *bo=dst->insertBranchPtr (this,pos);
  1286 			bo->setDefAttr(MovedBranch);
  1287 			updateLink();
  1288 			return bo;
  1289 
  1290 		} else
  1291 			return NULL;
  1292 	}	
  1293 }
  1294 
  1295 void BranchObj::alignRelativeTo (QPointF ref)
  1296 {
  1297 	qreal th = bboxTotal.height();	
  1298 // TODO testing
  1299 /*
  1300 	cout << "BO::alignRelTo "<<getHeading().ascii()<<endl;
  1301 	cout << "  d="<<depth<<
  1302 		"  ref="<<ref<<
  1303 //		"  bbox.topLeft="<<bboxTotal.topLeft()<<
  1304 		"  absPos="<<absPos<<
  1305 		"  relPos="<<relPos<<
  1306 		"  orient="<<orientation<<
  1307 //		"  pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
  1308 //		"  hidden="<<hidden<<
  1309 //		"  th="<<th<<
  1310 		endl;
  1311 */
  1312 
  1313 	setOrientation();
  1314 	//updateLink();
  1315 
  1316 	if (depth<2)
  1317 	{
  1318 		if (depth==1)
  1319 		{
  1320 			// Position relatively, if needed
  1321 			//if (useRelPos) move2RelPos (relPos.x(), relPos.y());
  1322 
  1323 			// Calc angle to mapCenter if I am a mainbranch
  1324 			// needed for reordering the mainbranches clockwise 
  1325 			// around mapcenter 
  1326 			angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ), 
  1327 									(int)(y() - parObj->getChildPos().y() ) ) );
  1328 		}							
  1329 	} 
  1330 	else
  1331     {
  1332 		// Align myself depending on orientation and parent, but
  1333 		// only if I am not a mainbranch or mapcenter itself
  1334 		LinkableMapObj::Orientation o;
  1335 		o=parObj->getOrientation();
  1336 		switch (orientation) 
  1337 		{
  1338 			case LinkableMapObj::LeftOfCenter:
  1339 				move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
  1340 			break;
  1341 			case LinkableMapObj::RightOfCenter:	
  1342 				move (ref.x() , ref.y() + (th-bbox.height())/2  );
  1343 			break;
  1344 			default:
  1345 				qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
  1346 			break;
  1347 		}		
  1348     }		
  1349 
  1350 	if (scrolled) return;
  1351 
  1352     // Set reference point for alignment of childs
  1353     QPointF ref2;
  1354     if (orientation==LinkableMapObj::LeftOfCenter)
  1355 		ref2.setX(bbox.topLeft().x() - linkwidth);
  1356     else	
  1357 		ref2.setX(bbox.topRight().x() + linkwidth);
  1358 
  1359 	if (depth==1)
  1360 		ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
  1361 	else	
  1362 		ref2.setY(ref.y() );	
  1363 
  1364     // Align the childs depending on reference point 
  1365 	for (int i=0; i<branch.size(); ++i)
  1366     {	
  1367 		if (!branch.at(i)->isHidden())
  1368 		{
  1369 			branch.at(i)->alignRelativeTo (ref2);
  1370 			ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChilds().height() );
  1371 		}
  1372     }
  1373 }
  1374 
  1375 
  1376 void BranchObj::reposition()
  1377 {	
  1378 /* TODO testing only
  1379 	if (!getHeading().isEmpty())
  1380 		cout << "BO::reposition  "<<getHeading().ascii()<<endl;
  1381 	else	
  1382 		cout << "BO::reposition  ???"<<endl;
  1383 
  1384 	cout << "  orient="<<orientation<<endl;
  1385 */		
  1386 
  1387 	if (depth==0)
  1388 	{
  1389 		// only calculate the sizes once. If the deepest LMO 
  1390 		// changes its height,
  1391 		// all upper LMOs have to change, too.
  1392 		calcBBoxSizeWithChilds();
  1393 		updateLink();	// This update is needed if the scene is resized 
  1394 						// due to excessive moving of a FIO
  1395 
  1396 	    alignRelativeTo ( QPointF (absPos.x(),
  1397 			absPos.y()-(bboxTotal.height()-bbox.height())/2) );
  1398 		qSort (branch.begin(),branch.end(), isAbove);
  1399 		positionBBox();	// Reposition bbox and contents
  1400 	} else
  1401 	{
  1402 		// This is only important for moving branches:
  1403 		// For editing a branch it isn't called...
  1404 	    alignRelativeTo ( QPointF (absPos.x(),
  1405 							absPos.y()-(bboxTotal.height()-bbox.height())/2) );
  1406 	}
  1407 }
  1408 
  1409 void BranchObj::unsetAllRepositionRequests()
  1410 {
  1411 	repositionRequest=false;
  1412 	for (int i=0; i<branch.size(); ++i)
  1413 		branch.at(i)->unsetAllRepositionRequests();
  1414 }
  1415 
  1416 
  1417 QRectF BranchObj::getTotalBBox()
  1418 {
  1419 	QRectF r=bbox;
  1420 
  1421 	if (scrolled) return r;
  1422 
  1423 	for (int i=0; i<branch.size(); ++i)
  1424 		if (!branch.at(i)->isHidden())
  1425 			r=addBBox(branch.at(i)->getTotalBBox(),r);
  1426 
  1427 	for (int i=0; i<floatimage.size(); ++i)
  1428 		if (!floatimage.at(i)->isHidden())
  1429 			r=addBBox(floatimage.at(i)->getTotalBBox(),r);
  1430 		
  1431 	return r;
  1432 }
  1433 
  1434 QRectF BranchObj::getBBoxSizeWithChilds()
  1435 {
  1436 	return bboxTotal;
  1437 }
  1438 
  1439 void BranchObj::calcBBoxSizeWithChilds()
  1440 {	
  1441 	// This is initially called only from reposition and
  1442 	// and only for mapcenter. So it won't be
  1443 	// called more than once for a single user 
  1444 	// action
  1445 	
  1446 
  1447 	// Calculate size of LMO including all childs (to align them later)
  1448 	bboxTotal.setX(bbox.x() );
  1449 	bboxTotal.setY(bbox.y() );
  1450 
  1451 	// if branch is scrolled, ignore childs, but still consider floatimages
  1452 	if (scrolled)
  1453 	{
  1454 		bboxTotal.setWidth (bbox.width());
  1455 		bboxTotal.setHeight(bbox.height());
  1456 		return;
  1457 	}
  1458 	
  1459 	if (hidden)
  1460 	{
  1461 		bboxTotal.setWidth (0);
  1462 		bboxTotal.setHeight(0);
  1463 		if (parObj)
  1464 		{
  1465 			bboxTotal.setX (parObj->x());
  1466 			bboxTotal.setY (parObj->y());
  1467 		} else
  1468 		{
  1469 			bboxTotal.setX (bbox.x());
  1470 			bboxTotal.setY (bbox.y());
  1471 		}
  1472 		return;
  1473 	}
  1474 	
  1475 	QRectF r(0,0,0,0);
  1476 	QRectF br;
  1477 	// Now calculate recursivly
  1478 	// sum of heights 
  1479 	// maximum of widths 
  1480 	// minimum of y
  1481 	for (int i=0; i<branch.size(); ++i)
  1482 	{
  1483 		if (!branch.at(i)->isHidden())
  1484 		{
  1485 			branch.at(i)->calcBBoxSizeWithChilds();
  1486 			br=branch.at(i)->getBBoxSizeWithChilds();
  1487 			r.setWidth( max (br.width(), r.width() ));
  1488 			r.setHeight(br.height() + r.height() );
  1489 			if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
  1490 		}
  1491 	}
  1492 	// Add myself and also
  1493 	// add width of link to sum if necessary
  1494 	if (branch.isEmpty())
  1495 		bboxTotal.setWidth (bbox.width() + r.width() );
  1496 	else	
  1497 		bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
  1498 	
  1499 	bboxTotal.setHeight(max (r.height(),  bbox.height()));
  1500 }
  1501 
  1502 void BranchObj::select()
  1503 {
  1504 	// update NoteEditor
  1505 	textEditor->setText(note.getNote() );
  1506 	QString fnh=note.getFilenameHint();
  1507 	if (fnh!="")
  1508 		textEditor->setFilenameHint(note.getFilenameHint() );
  1509 	else	
  1510 		textEditor->setFilenameHint(getHeading() );
  1511 	textEditor->setFontHint (note.getFontHint() );
  1512 	isNoteInEditor=true;
  1513 
  1514 	// set selected and visible
  1515     LinkableMapObj::select();
  1516 
  1517 	// Tell parent that I am selected now:
  1518 	BranchObj* po=(BranchObj*)(parObj);
  1519     if (po)	// TODO	    Try to get rid of this cast...
  1520         po->setLastSelectedBranch(this);
  1521 		
  1522 	// temporary unscroll, if we have scrolled parents somewhere
  1523 	if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
  1524 
  1525 	// Show URL and link in statusbar
  1526 	QString status;
  1527 	if (!url.isEmpty()) status+="URL: "+url+"  ";
  1528 	if (!vymLink.isEmpty()) status+="Link: "+vymLink;
  1529 	if (!status.isEmpty()) mainWindow->statusMessage (status);
  1530 
  1531 	// Update Toolbar
  1532 	updateFlagsToolbar();
  1533 
  1534 	// Update actions
  1535 	mapEditor->updateActions();
  1536 }
  1537 
  1538 void BranchObj::unselect()
  1539 {
  1540 	LinkableMapObj::unselect();
  1541 	// Delete any messages like vymLink in StatusBar
  1542 	mainWindow->statusMessage ("");
  1543 
  1544 	// Save current note
  1545 	if (isNoteInEditor) getNoteFromTextEditor();
  1546 	isNoteInEditor=false;
  1547 
  1548 	// reset temporary unscroll, if we have scrolled parents somewhere
  1549 	if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
  1550 
  1551 	// Erase content of editor 
  1552 	textEditor->setInactive();
  1553 
  1554 	// unselect all buttons in toolbar
  1555 	standardFlagsDefault->updateToolbar();
  1556 }
  1557 
  1558 QString BranchObj::getSelectString()
  1559 {
  1560 	QString s;
  1561 	if (parObj)
  1562 	{
  1563 		if (depth==1)
  1564 			s= "bo:" + QString("%1").arg(getNum());
  1565 		else	
  1566 			s= ((BranchObj*)(parObj))->getSelectString() + ",bo:" + QString("%1").arg(getNum());
  1567 	} else
  1568 		s="mc:";
  1569 	return s;
  1570 }
  1571 
  1572 
  1573 void BranchObj::animate()
  1574 {
  1575 	//relPos.animate();
  1576 	cout << "BO::animate  x,y="<<relPos.x()<<","<<relPos.y()<<endl;
  1577 }
  1578