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