branchobj.cpp
author insilmaril
Thu, 14 May 2009 12:42:58 +0000
changeset 768 382a444f5b0c
parent 767 6d2b32f305f9
child 771 01f2f6d6789d
permissions -rw-r--r--
flag of NoteEditor works again
     1 #include "branchobj.h"
     2 
     3 #include "branchitem.h"
     4 #include "geometry.h"
     5 #include "mapeditor.h"
     6 #include "mainwindow.h"
     7 #include "misc.h"
     8 
     9 extern FlagRow *standardFlagsMaster;
    10 extern FlagRow *systemFlagsMaster;
    11 
    12 /////////////////////////////////////////////////////////////////
    13 // BranchObj
    14 /////////////////////////////////////////////////////////////////
    15 
    16 BranchObj::BranchObj () :OrnamentedObj()	// FIXME-3 needed at all?
    17 {
    18 //    cout << "Const BranchObj ()\n";
    19     setParObj (this);	
    20     init();
    21 }
    22 
    23 BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s)// FIXME-3 needed at all?
    24 {
    25 //    cout << "Const BranchObj (s)  \n";
    26 	parObj=NULL;
    27     scene=s;
    28 	init();
    29 }
    30 
    31 BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)// FIXME-3 needed at all?
    32 {
    33 //    cout << "Const BranchObj (s,p)\n";
    34     scene=s;
    35     setParObj (p);	
    36 	if (treeItem->depth()==1)
    37 		// Calc angle to mapCenter if I am a mainbranch
    38 		// needed for reordering the mainbranches clockwise 
    39 		// around mapcenter 
    40 		angle=getAngle (QPointF (x() - parObj->getChildPos().x() , 
    41 								(y() - parObj->getChildPos().y() ) ) );
    42     init();
    43 }
    44 
    45 BranchObj::~BranchObj ()
    46 {
    47 //	cout << "Destr BranchObj of "<<this<<" ("<<treeItem->getHeading().toStdString()<<")"<<endl;
    48 
    49 	// If I'm animated, I need to un-animate myself first
    50 	if (anim.isAnimated() )
    51 	{
    52 		anim.setAnimated (false);
    53 		model->stopAnimation (this);
    54 	}
    55 
    56 	// Check, if this branch was the last child to be deleted
    57 	// If so, unset the scrolled flags in parent // FIXME-2 better do this in model?
    58 
    59 	/*
    60 	BranchObj *po=(BranchObj*)parObj;
    61 	BranchObj *bo;
    62 	if (po)
    63 	{
    64 		bo=((BranchObj*)parObj)->getLastBranch();
    65 		if (bo) po->unScroll();
    66 	}
    67 	*/
    68 	clear();
    69 }
    70 
    71 bool BranchObj::operator< ( const BranchObj & other )
    72 {
    73     return  angle < other.angle;
    74 }
    75 
    76 bool BranchObj::operator== ( const BranchObj & other )
    77 {
    78     return angle == other.angle;
    79 }
    80 
    81 void BranchObj::init () 
    82 {
    83 	if (parObj)
    84 	{
    85 		absPos=getRandPos();
    86 		absPos+=parObj->getChildPos();
    87 	}
    88 
    89     setChildObj(this);
    90 
    91 	includeImagesVer=false;
    92 	includeImagesHor=false;
    93 }
    94 
    95 void BranchObj::copy (BranchObj* other)
    96 {
    97     OrnamentedObj::copy(other);
    98 
    99 	for (int i=0; i<other->floatimage.size(); ++i)
   100 		addFloatImage  (other->floatimage.at(i));
   101 	
   102 	setVisibility (other->visible);
   103 
   104 	angle=other->angle;
   105 
   106     positionBBox();
   107 }
   108 
   109 void BranchObj::clear() 
   110 {
   111 	//setVisibility (true); //FIXME-4 needed?
   112 
   113 	while (!floatimage.isEmpty())
   114 		delete floatimage.takeFirst();
   115 
   116 	while (!xlink.isEmpty())
   117 		delete xlink.takeFirst();
   118 }
   119 
   120 bool isAbove (BranchObj* a, BranchObj *b)
   121 {
   122 	if (a->angle < b->angle)
   123 		return true;
   124 	else	
   125 		return false;
   126 }
   127 
   128 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
   129 {
   130 	// Temporary link to lmo
   131 	// m is position of mouse pointer 
   132 	// offset 0: default 1: below lmo   -1 above lmo  (if possible)
   133 
   134 
   135 	BranchObj* o=(BranchObj*)(lmo);
   136 	if (!parObjTmpBuf) 
   137 		parObjTmpBuf=parObj;
   138 
   139 	// ignore mapcenter and mainbranch
   140 	if (treeItem->depth()<2) off=0;
   141 	if (off==0)
   142 		link2ParPos=false;
   143 	else
   144 		link2ParPos=true;
   145 	parObj=o;
   146 
   147 	// FIXME-2 depth=parObj->getDepth()+1;
   148 
   149 	// setLinkStyle calls updateLink, only set it once
   150 	if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
   151 
   152 	// Move temporary to new position at destination
   153 	// Usually the positioning would be done by reposition(),
   154 	// but then also the destination branch would "Jump" around...
   155 	// Better just do it approximately
   156 	if (treeItem->depth()==1)
   157 	{	// new parent is the mapcenter itself
   158 
   159 		QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
   160 									  m.y() - o->getChildPos().y() ));
   161 		if (p.x()<0) p.setX( p.x()-bbox.width() );
   162 		move2RelPos (p);
   163 	} else
   164 	{	
   165 		qreal y;
   166 		if (off==0)
   167 		{
   168 			// new parent is just a branch, link to it
   169 			QRectF t=o->getBBoxSizeWithChildren();
   170 			if (o->getTreeItem()->getLastBranch())
   171 				y=t.y() + t.height() ;
   172 			else
   173 				y=t.y();
   174 
   175 		} else
   176 		{
   177 			if (off<0)
   178 				// we want to link above lmo
   179 				y=o->y() - height() + 5;
   180 			else	
   181 				// we want to link below lmo
   182 				// Bottom of sel should be 5 pixels above
   183 				// the bottom of the branch _below_ the target:
   184 				// Don't try to find that branch, guess 12 pixels
   185 				y=o->getChildPos().y()  -height() + 12; 
   186 		}	
   187 		if (o->getOrientation()==LinkableMapObj::LeftOfCenter)
   188 			move ( o->getChildPos().x() - linkwidth, y );
   189 		else	
   190 			move (o->getChildPos().x() + linkwidth, y );
   191 	}	
   192 
   193 	// updateLink is called implicitly in move
   194 	requestReposition();	
   195 }
   196 
   197 void BranchObj::unsetParObjTmp()
   198 {
   199 	if (parObjTmpBuf) 
   200 	{
   201 		link2ParPos=false;
   202 		parObj=parObjTmpBuf;
   203 		parObjTmpBuf=NULL;
   204 		//FIXME-2 depth=parObj->getDepth()+1;
   205 		setLinkStyle (getDefLinkStyle() );
   206 		updateLink();
   207 	}		
   208 }
   209 
   210 void BranchObj::setVisibility(bool v, int toDepth)
   211 {
   212 	BranchItem *bi=(BranchItem*)treeItem;
   213     if (bi->depth() <= toDepth)
   214     {
   215 		frame->setVisibility(v);
   216 		heading->setVisibility(v);
   217 		systemFlags->setVisibility(v);
   218 		standardFlags->setVisibility(v);
   219 		LinkableMapObj::setVisibility (v);
   220 		int i;
   221 		for (i=0; i<floatimage.size(); ++i)
   222 			floatimage.at(i)->setVisibility (v);
   223 		for (i=0; i<xlink.size(); ++i)	
   224 			xlink.at(i)->setVisibility ();	
   225 
   226 		// Only change children, if I am not scrolled
   227 		if (! bi->isScrolled() && (bi->depth() < toDepth))
   228 		{
   229 			// Now go recursivly through all children
   230 			for (i=0; i<treeItem->branchCount(); ++i)
   231 				treeItem->getBranchObjNum(i)->setVisibility (v,toDepth);	
   232 		}
   233     } // depth <= toDepth	
   234 	requestReposition();
   235 }	
   236 
   237 void BranchObj::setVisibility(bool v)
   238 {
   239     setVisibility (v,MAX_DEPTH);
   240 }
   241 
   242 
   243 void BranchObj::setLinkColor ()
   244 {
   245 	// Overloaded from LinkableMapObj
   246 	// BranchObj can use color of heading
   247 
   248 	if (model)
   249 	{
   250 		if (model->getMapLinkColorHint()==HeadingColor)
   251 			LinkableMapObj::setLinkColor (heading->getColor() );
   252 		else	
   253 			LinkableMapObj::setLinkColor ();
   254 	}		
   255 }
   256 
   257 void BranchObj::setColorSubtree(QColor col)
   258 {
   259 	setColor (col);
   260 	for (int i=0; i<treeItem->branchCount(); ++i)
   261 		treeItem->getBranchObjNum(i)->setColorSubtree(col);
   262 }
   263 
   264 void BranchObj::updateContentSize()
   265 {
   266 	calcBBoxSize();
   267 	positionBBox();
   268 	requestReposition();
   269 }
   270 
   271 void BranchObj::positionContents()
   272 {
   273     for (int i=0; i<floatimage.size(); ++i )
   274 		floatimage.at(i)->reposition();
   275 	OrnamentedObj::positionContents();
   276 }
   277 
   278 void BranchObj::move (double x, double y)
   279 {
   280 	OrnamentedObj::move (x,y);
   281     for (int i=0; i<floatimage.size(); ++i )
   282 		floatimage.at(i)->reposition();
   283     positionBBox();
   284 }
   285 
   286 void BranchObj::move (QPointF p)
   287 {
   288 	move (p.x(), p.y());
   289 }
   290 
   291 void BranchObj::moveBy (double x, double y)
   292 {
   293 	OrnamentedObj::moveBy (x,y);
   294 	for (int i=0; i<treeItem->branchCount(); ++i)
   295 		treeItem->getBranchObjNum(i)->moveBy (x,y);
   296     positionBBox();
   297 }
   298 	
   299 void BranchObj::moveBy (QPointF p)
   300 {
   301 	moveBy (p.x(), p.y());
   302 }
   303 
   304 
   305 void BranchObj::positionBBox()
   306 {
   307 	QPointF ap=getAbsPos();
   308 	bbox.moveTopLeft (ap);
   309 	positionContents();
   310 
   311 	// set the frame
   312 	frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
   313 
   314 	// Update links to other branches
   315 	for (int i=0; i<xlink.size(); ++i)
   316 		xlink.at(i)->updateXLink();
   317 }
   318 
   319 void BranchObj::calcBBoxSize()
   320 {
   321     QSizeF heading_r=heading->getSize();
   322     qreal heading_w=(qreal) heading_r.width() ;
   323     qreal heading_h=(qreal) heading_r.height() ;
   324     QSizeF sysflags_r=systemFlags->getSize();
   325 	qreal sysflags_h=sysflags_r.height();
   326 	qreal sysflags_w=sysflags_r.width();
   327     QSizeF stanflags_r=standardFlags->getSize();
   328 	qreal stanflags_h=stanflags_r.height();
   329 	qreal stanflags_w=stanflags_r.width();
   330     qreal w;
   331     qreal h;
   332 
   333 	// set width to sum of all widths
   334 	w=heading_w + sysflags_w + stanflags_w;
   335 	// set height to maximum needed height
   336 	h=max (sysflags_h,stanflags_h);
   337 	h=max (h,heading_h);
   338 
   339 	// Save the dimension of flags and heading
   340 	ornamentsBBox.setSize ( QSizeF(w,h));
   341 
   342 	// clickBox includes Flags and Heading
   343     clickBox.setSize (ornamentsBBox.size() );
   344 
   345 	// Floatimages 
   346 	QPointF rp;
   347 
   348 	topPad=botPad=leftPad=rightPad=0;
   349 	if (includeImagesVer || includeImagesHor)
   350 	{
   351 		if (treeItem->imageCount()>0)
   352 		{
   353 			for (int i=0; i<floatimage.size(); ++i )
   354 			{
   355 				rp=floatimage.at(i)->getRelPos();
   356 				if (includeImagesVer)
   357 				{
   358 					if (rp.y() < 0) 
   359 						topPad=max (topPad,-rp.y()-h);
   360 					if (rp.y()+floatimage.at(i)->height() > 0)
   361 						botPad=max (botPad,rp.y()+floatimage.at(i)->height());
   362 				}		
   363 				if (includeImagesHor)
   364 				{
   365 					if (orientation==LinkableMapObj::RightOfCenter)
   366 					{
   367 						if (-rp.x()-w > 0) 
   368 							leftPad=max (leftPad,-rp.x()-w);
   369 						if (rp.x()+floatimage.at(i)->width() > 0)
   370 							rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
   371 					} else
   372 					{
   373 						if (rp.x()< 0) 
   374 							leftPad=max (leftPad,-rp.x());
   375 						if (rp.x()+floatimage.at(i)->width() > w)
   376 							rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
   377 					}
   378 				}		
   379 			}	
   380 		}	
   381 		h+=topPad+botPad;
   382 		w+=leftPad+rightPad;
   383 	}
   384 
   385 	// Frame thickness
   386     w+=frame->getPadding();
   387     h+=frame->getPadding();
   388 	
   389 	// Finally set size
   390     bbox.setSize (QSizeF (w,h));
   391 }
   392 
   393 void BranchObj::setDockPos()
   394 {
   395 	// Sets childpos and parpos depending on orientation
   396 	if (getOrientation()==LinkableMapObj::LeftOfCenter )
   397     {
   398 		childPos=QPointF (
   399 			ornamentsBBox.bottomLeft().x(), 
   400 			bottomlineY);
   401 		parPos=QPointF (
   402 			ornamentsBBox.bottomRight().x(),
   403 			bottomlineY);
   404     } else
   405     {
   406 		childPos=QPointF (
   407 			ornamentsBBox.bottomRight().x(), 
   408 			bottomlineY);
   409 		parPos=QPointF (
   410 			ornamentsBBox.bottomLeft().x(),
   411 			bottomlineY);
   412     }
   413 }
   414 
   415 void BranchObj::updateData()
   416 {
   417 	bool changed=false;
   418 	if (!treeItem)
   419 	{
   420 		qWarning ("BranchObj::udpateHeading treeItem==NULL");
   421 		return;
   422 	}
   423 	QString s=treeItem->getHeading();
   424 	if (s!=heading->text())
   425 	{
   426 		heading->setText (s);
   427 		changed=true;
   428 	}
   429 	QStringList TIactiveFlags=treeItem->activeStandardFlagNames();
   430 
   431 	// Add missing standard flags active in TreeItem
   432 	for (int i=0;i<=TIactiveFlags.size()-1;i++)
   433 	{	
   434 		if (!standardFlags->isActive (TIactiveFlags.at(i) ))
   435 		{
   436 			Flag *f=standardFlagsMaster->getFlag(TIactiveFlags.at(i));
   437 			if (f) standardFlags->activate (f);
   438 			changed=true;
   439 		}
   440 	}
   441 	// Remove standard flags no longer active in TreeItem
   442 	QStringList BOactiveFlags=standardFlags->activeFlagNames();
   443 	for (int i=0;i<BOactiveFlags.size();++i)
   444 		if (!TIactiveFlags.contains (BOactiveFlags.at(i)))
   445 		{
   446 			standardFlags->deactivate (BOactiveFlags.at(i));
   447 			changed=true;
   448 		}	
   449 
   450 	// Add missing system flags active in TreeItem
   451 	TIactiveFlags=treeItem->activeSystemFlagNames();
   452 	for (int i=0;i<TIactiveFlags.size();++i)
   453 	{	
   454 		if (!systemFlags->isActive (TIactiveFlags.at(i) ))
   455 		{
   456 			Flag *f=systemFlagsMaster->getFlag(TIactiveFlags.at(i));
   457 			if (f) systemFlags->activate (f);
   458 			changed=true;
   459 		}
   460 	}
   461 	// Remove system flags no longer active in TreeItem
   462 	BOactiveFlags=systemFlags->activeFlagNames();
   463 	for (int i=0;i<BOactiveFlags.size();++i)
   464 	{
   465 		if (!TIactiveFlags.contains (BOactiveFlags.at(i)))
   466 		{
   467 			systemFlags->deactivate (BOactiveFlags.at(i));
   468 			changed=true;
   469 		}	
   470 	}
   471 
   472 	if (changed)
   473 		updateContentSize();
   474 }
   475 
   476 
   477 void BranchObj::addXLink (XLinkObj *xlo)
   478 {
   479 	xlink.append (xlo);
   480 	
   481 }
   482 
   483 void BranchObj::removeXLinkRef (XLinkObj *xlo)
   484 {
   485 	xlink.removeAt (xlink.indexOf(xlo));
   486 }
   487 
   488 void BranchObj::deleteXLink(XLinkObj *xlo)
   489 {
   490 	xlo->deactivate();
   491 	if (!xlo->isUsed()) delete (xlo);
   492 }
   493 
   494 void BranchObj::deleteXLinkAt (int i)
   495 {
   496 	XLinkObj *xlo=xlink.at(i);
   497 	xlo->deactivate();
   498 	if (!xlo->isUsed()) delete(xlo);
   499 }
   500 
   501 XLinkObj* BranchObj::XLinkAt (int i)
   502 {
   503 	return xlink.at(i);
   504 }
   505 
   506 BranchObj* BranchObj::XLinkTargetAt (int i)
   507 {
   508 	if (i>=0 && i<xlink.size())
   509 	{
   510 		if (xlink.at(i))
   511 			return xlink.at(i)->otherBranch (this);
   512 	}
   513 	return NULL;
   514 }
   515 
   516 void BranchObj::setIncludeImagesVer(bool b)
   517 {
   518 	includeImagesVer=b;
   519 	calcBBoxSize();
   520 	positionBBox();
   521 	requestReposition();
   522 }
   523 
   524 bool BranchObj::getIncludeImagesVer()
   525 {
   526 	return includeImagesVer;
   527 }
   528 
   529 void BranchObj::setIncludeImagesHor(bool b)
   530 {
   531 	includeImagesHor=b;
   532 	calcBBoxSize();
   533 	positionBBox();
   534 	requestReposition();
   535 }
   536 
   537 bool BranchObj::getIncludeImagesHor()
   538 {
   539 	return includeImagesHor;
   540 }
   541 
   542 QString BranchObj::getIncludeImageAttr()
   543 {
   544 	QString a;
   545 	if (includeImagesVer)
   546 		a=attribut ("incImgV","true");
   547 	else
   548 		a=attribut ("incImgV","false");
   549 	if (includeImagesHor)
   550 		a+=attribut ("incImgH","true");
   551 	else
   552 		a+=attribut ("incImgH","false");
   553 	return a;	
   554 }
   555 
   556 FloatImageObj* BranchObj::addFloatImage ()
   557 {
   558 	FloatImageObj *newfi=new FloatImageObj (scene,this);
   559 	floatimage.append (newfi);
   560 	if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
   561 		newfi->setVisibility (false);
   562 	else	
   563 		newfi->setVisibility(visible);
   564 		/*
   565 	calcBBoxSize();
   566 	positionBBox();
   567 	*/
   568 	requestReposition();
   569 	return newfi;
   570 }
   571 
   572 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
   573 {
   574 	FloatImageObj *newfi=new FloatImageObj (scene,this);
   575 	floatimage.append (newfi);
   576 	newfi->copy (fio);
   577 	if (((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
   578 		newfi->setVisibility (false);
   579 	else	
   580 		newfi->setVisibility(visible);
   581 		/*
   582 	calcBBoxSize();
   583 	positionBBox();
   584 	*/
   585 	requestReposition();
   586 	return newfi;
   587 }
   588 
   589 FloatImageObj* BranchObj::getFirstFloatImage ()
   590 {
   591     return floatimage.first();
   592 }
   593 
   594 FloatImageObj* BranchObj::getLastFloatImage ()
   595 {
   596     return floatimage.last();
   597 }
   598 
   599 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
   600 {
   601     return floatimage.at(i);
   602 }
   603 
   604 void BranchObj::removeFloatImage (FloatImageObj *fio)
   605 {
   606 	int i=floatimage.indexOf (fio);
   607 	if (i>-1) delete (floatimage.takeAt (i));
   608 	calcBBoxSize();
   609 	positionBBox();
   610 	requestReposition();
   611 }
   612 
   613 void BranchObj::savePosInAngle ()
   614 {
   615 	// Save position in angle
   616 	for (int i=0; i<treeItem->branchCount(); ++i)
   617 		treeItem->getBranchObjNum(i)->angle=i;
   618 }
   619 
   620 void BranchObj::setDefAttr (BranchModification mod)
   621 {
   622 	int fontsize;
   623 	switch (treeItem->depth())
   624 	{
   625 		case 0: fontsize=16; break;
   626 		case 1: fontsize=12; break;
   627 		default: fontsize=10; break;
   628 	}	
   629 
   630 	setLinkColor ();
   631 	setLinkStyle(getDefLinkStyle());
   632 	QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
   633 	font.setPointSize(fontsize);
   634 	heading->setFont(font );
   635 
   636 	if (mod==NewBranch)
   637 		setColor (treeItem->getHeadingColor() );
   638 	calcBBoxSize();
   639 }
   640 
   641 void BranchObj::removeBranchHere(BranchObj* borem)	// FIXME-2 getNum no longer available
   642 {
   643 /*
   644 	// This removes the branch bo from list, but 
   645 	// inserts its children at the place of bo
   646 	BranchObj *bo;
   647 	bo=borem->getLastBranch();
   648 	int pos=borem->getNum();
   649 	while (bo)
   650 	{
   651 		bo->linkTo (this,pos+1);
   652 		bo=borem->getLastBranch();
   653 	}	
   654 	removeBranch (borem);
   655 	*/
   656 }
   657 
   658 void BranchObj::removeChildren()	// FIXME-3 not needed here
   659 {
   660 	clear();
   661 }
   662 
   663 void BranchObj::removeBranch(BranchObj* bo)	// FIXME-2 not needed here
   664 {
   665 /*
   666     // if bo is not in branch remove returns false, we
   667     // don't care...
   668 	
   669 	int i=branch.indexOf(bo);
   670     if (i>=0)
   671 	{
   672 		delete (bo);
   673 		branch.removeAt (i);
   674 	} else
   675 		qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
   676 	requestReposition();
   677 	*/
   678 }
   679 
   680 void BranchObj::removeBranchPtr(BranchObj* bo)	// FIXME-3 not needed here
   681 {
   682 /*
   683 	int i=branch.indexOf(bo);
   684 	
   685 	if (i>=0)
   686 		branch.removeAt (i);
   687 	else	
   688 		qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
   689 	requestReposition();
   690 */	
   691 }
   692 
   693 void BranchObj::sortChildren() //FIXME-2  
   694 {
   695 /*
   696 	int childCount=branch.count(); 
   697 	int curChildIndex;
   698 	bool madeChanges=false;
   699 	do
   700 	{
   701 		madeChanges=false;
   702 		for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
   703 			BranchObj* curChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex);
   704 			BranchObj* prevChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex-1);
   705 			if(prevChild->heading->text().compare(curChild->heading->text())>0)
   706 			{
   707 				this->moveBranchUp(curChild);
   708 				madeChanges=true;
   709 			}
   710 		}
   711 	}while(madeChanges);
   712 */
   713 }
   714 
   715 void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
   716 {
   717 	qreal th = bboxTotal.height();	
   718 	int depth=treeItem->depth();
   719 // TODO testing
   720 /*
   721 
   722 	QString h=QString (depth,' ');
   723 	h+=treeItem->getHeading();
   724 	h+=QString (15,' ');
   725 	h.truncate (15);
   726 	QPointF pp; if (parObj) pp=parObj->getChildPos();
   727 	cout << "BO::alignRelTo ";
   728 	cout<<h.toStdString();
   729 	cout << "    d="<<depth<<
   730 //cout<<  "  ref="<<ref<<
   731       	"  bbox.tL="<<bboxTotal.topLeft()<<
   732 		"  absPos="<<absPos<<
   733 //		"  relPos="<<relPos<<
   734 //		"  parPos="<<pp<<
   735 		"  w="<<bbox.width()<<
   736 		"  h="<<bbox.height()<<
   737 //		"  orient="<<orientation<<
   738 //		"  alignSelf="<<alignSelf<<
   739 //		"  scrolled="<<((BranchItem*)treeItem)->isScrolled()<<
   740 //		"  pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
   741 //		"  hidden="<<hidden<<
   742 		"  th="<<th<<
   743 		endl;
   744 */
   745 
   746 	setOrientation();
   747 	//updateLink();
   748 
   749 	if (depth==1 && parObj)
   750 	{
   751 		// Position relatively, if needed
   752 		//if (useRelPos) move2RelPos (relPos.x(), relPos.y());
   753 
   754 		// Calc angle to mapCenter if I am a mainbranch
   755 		// needed for reordering the mainbranches clockwise 
   756 		// around mapcenter 
   757 		angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ), 
   758 								(int)(y() - parObj->getChildPos().y() ) ) );
   759 	}							
   760 	if (depth>1)
   761     {
   762 		// Align myself depending on orientation and parent, but
   763 		// only if I am not a mainbranch or mapcenter itself
   764 
   765 		if (anim.isAnimated())
   766 		{
   767 			move2RelPos(anim);
   768 		} else
   769 		{
   770 			LinkableMapObj::Orientation o;
   771 			o=parObj->getOrientation();
   772 			if (alignSelf)
   773 				switch (orientation) 
   774 				{
   775 					case LinkableMapObj::LeftOfCenter:
   776 						move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
   777 						//move (ref.x() , ref.y() + (th-bbox.height())/2 );
   778 					break;
   779 					case LinkableMapObj::RightOfCenter:	
   780 						move (ref.x() , ref.y() + (th-bbox.height())/2  );
   781 					break;
   782 					default:
   783 						qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
   784 					break;
   785 			}
   786 		}
   787     }		
   788 
   789 	if ( ((BranchItem*)treeItem)->isScrolled() ) return;
   790 
   791     // Set reference point for alignment of children
   792     QPointF ref2;
   793     if (orientation==LinkableMapObj::LeftOfCenter)
   794 		ref2.setX(bbox.topLeft().x() - linkwidth);
   795     else	
   796 		ref2.setX(bbox.topRight().x() + linkwidth);
   797 
   798 	if (depth==1)
   799 		ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
   800 	else	
   801 		ref2.setY(ref.y() );	
   802 
   803     // Align the children depending on reference point 
   804 	for (int i=0; i<treeItem->branchCount(); ++i)
   805     {	
   806 		if (!treeItem->getBranchNum(i)->isHidden())
   807 		{
   808 			treeItem->getBranchObjNum(i)->alignRelativeTo (ref2,true);
   809 
   810 			// append next branch below current one
   811 			ref2.setY(ref2.y() + treeItem->getBranchObjNum(i)->getBBoxSizeWithChildren().height() );
   812 		}
   813     }
   814 }
   815 
   816 
   817 void BranchObj::reposition()
   818 {	
   819 /* TODO testing only
   820 	if (!treeItem->getHeading().isEmpty())
   821 		cout << "BO::reposition  "<<qPrintable(treeItem->getHeading())<<endl;
   822 	else	
   823 		cout << "BO::reposition  ???"<<endl;
   824 //	cout << "  orient="<<orientation<<endl;
   825 */		
   826 
   827 	if (treeItem->depth()==0)
   828 	{
   829 		// only calculate the sizes once. If the deepest LMO 
   830 		// changes its height,
   831 		// all upper LMOs have to change, too.
   832 		calcBBoxSizeWithChildren();
   833 		updateLink();	// This update is needed if the scene is resized 
   834 						// due to excessive moving of a FIO
   835 
   836 	    alignRelativeTo ( QPointF (absPos.x(),
   837 			absPos.y()-(bboxTotal.height()-bbox.height())/2) );
   838 		//FIXME-2 qSort (branch.begin(),branch.end(), isAbove);
   839 		positionBBox();	// Reposition bbox and contents
   840 	} else
   841 	{
   842 		// This is only important for moving branches:
   843 		// For editing a branch it isn't called...
   844 	    alignRelativeTo ( QPointF (absPos.x(),
   845 							absPos.y()-(bboxTotal.height()-bbox.height())/2) );
   846 	}
   847 }
   848 
   849 void BranchObj::unsetAllRepositionRequests()
   850 {
   851 	repositionRequest=false;
   852 	for (int i=0; i<treeItem->branchCount(); ++i)
   853 		treeItem->getBranchObjNum(i)->unsetAllRepositionRequests();
   854 }
   855 
   856 
   857 QPolygonF BranchObj::shape()
   858 {
   859 	QPolygonF p;
   860 
   861 	QRectF r=getTotalBBox();
   862 	if (orientation==LinkableMapObj::LeftOfCenter)
   863 		p   <<r.bottomLeft()
   864 			<<r.topLeft()
   865 			<<QPointF (bbox.topLeft().x(), r.topLeft().y() )
   866 			<<bbox.topRight()
   867 			<<bbox.bottomRight()
   868 			<<QPointF (bbox.bottomLeft().x(), r.bottomLeft().y() ) ;
   869 	else		
   870 		p   <<r.bottomRight()
   871 			<<r.topRight()
   872 			<<QPointF (bbox.topRight().x(), r.topRight().y() )
   873 			<<bbox.topLeft()
   874 			<<bbox.bottomLeft()
   875 			<<QPointF (bbox.bottomRight().x(), r.bottomRight().y() ) ;
   876 	return p;
   877 }
   878 
   879 QRectF BranchObj::getTotalBBox()
   880 {
   881 	QRectF r=bbox;
   882 
   883 	if ( ((BranchItem*)treeItem)->isScrolled() ) return r;
   884 
   885 	for (int i=0; i<treeItem->branchCount(); ++i)
   886 		if (!treeItem->getBranchNum(i)->isHidden())
   887 			r=addBBox(treeItem->getBranchObjNum(i)->getTotalBBox(),r);
   888 
   889 /* FIXME-3 lots of occurences of treeItem->getBranchObjNum(i) in branchobj.cpp
   890             better check if they are not NULL and maybe simplify...
   891 			(have been NULL at least in calcBBoxSizeWithChilds...)
   892 */			
   893 
   894 /*
   895 	FIXME-1 for (int i=0; i<floatimage.size(); ++i)
   896 		if (!floatimage.at(i)->isHidden())
   897 			r=addBBox(floatimage.at(i)->getTotalBBox(),r);
   898 	*/	
   899 	return r;
   900 }
   901 
   902 QRectF BranchObj::getBBoxSizeWithChildren()
   903 {
   904 	return bboxTotal;
   905 }
   906 
   907 void BranchObj::calcBBoxSizeWithChildren()
   908 {	
   909 	// This is initially called only from reposition and
   910 	// and only for mapcenter. So it won't be
   911 	// called more than once for a single user 
   912 	// action
   913 	
   914 
   915 	// Calculate size of LMO including all children (to align them later)
   916 	bboxTotal.setX(bbox.x() );
   917 	bboxTotal.setY(bbox.y() );
   918 
   919 	// if branch is scrolled, ignore children, but still consider floatimages
   920 	BranchItem *bi=(BranchItem*)treeItem;
   921 	if ( bi->isScrolled() ) 
   922 	{
   923 		bboxTotal.setWidth (bbox.width());
   924 		bboxTotal.setHeight(bbox.height());
   925 		return;
   926 	}
   927 	
   928 	if (bi->isHidden())
   929 	{
   930 		bboxTotal.setWidth (0);
   931 		bboxTotal.setHeight(0);
   932 		if (parObj)
   933 		{
   934 			bboxTotal.setX (parObj->x());
   935 			bboxTotal.setY (parObj->y());
   936 		} else
   937 		{
   938 			bboxTotal.setX (bbox.x());
   939 			bboxTotal.setY (bbox.y());
   940 		}
   941 		return;
   942 	}
   943 	
   944 	QRectF r(0,0,0,0);
   945 	QRectF br;
   946 	// Now calculate recursivly
   947 	// sum of heights 
   948 	// maximum of widths 
   949 	// minimum of y
   950 	for (int i=0; i<treeItem->branchCount(); i++)
   951 	{
   952 		if (!bi->getBranchNum(i)->isHidden())
   953 		{
   954 			bi->getBranchObjNum(i)->calcBBoxSizeWithChildren();
   955 			br=bi->getBranchObjNum(i)->getBBoxSizeWithChildren();
   956 			r.setWidth( max (br.width(), r.width() ));
   957 			r.setHeight(br.height() + r.height() );
   958 			if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
   959 		}
   960 	}
   961 	// Add myself and also
   962 	// add width of link to sum if necessary
   963 	if (bi->branchCount()<1)
   964 		bboxTotal.setWidth (bbox.width() + r.width() );
   965 	else	
   966 		bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
   967 	
   968 	bboxTotal.setHeight(max (r.height(),  bbox.height()));
   969 }
   970 
   971 QString BranchObj::getSelectString()
   972 {
   973 	return model->getSelectString (this);
   974 }
   975 
   976 void BranchObj::setAnimation(const AnimPoint &ap)
   977 {
   978 	anim=ap;
   979 }
   980 
   981 bool BranchObj::animate()
   982 {
   983 	anim.animate ();
   984 	if ( anim.isAnimated() )
   985 	{
   986 		setRelPos (anim);
   987 		return true;
   988 	}
   989 	parObj->reposition();	// we might have been relinked meanwhile
   990 	return false;
   991 }
   992