branchobj.cpp
author insilmaril
Mon, 03 Aug 2009 10:42:12 +0000
changeset 785 5987f9f15bac
parent 779 1fb50e79661c
child 786 6269016c9905
permissions -rw-r--r--
Fixed problem with images included in branches. Added missing adaptormodel.* files
     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 
    91 void BranchObj::copy (BranchObj* other)
    92 {
    93     OrnamentedObj::copy(other);
    94 
    95 	setVisibility (other->visible);
    96 
    97 	angle=other->angle;
    98 
    99     positionBBox();
   100 }
   101 
   102 void BranchObj::clear() 
   103 {
   104 	//setVisibility (true); //FIXME-4 needed?
   105 
   106 	while (!xlink.isEmpty())
   107 		delete xlink.takeFirst();
   108 }
   109 
   110 bool isAbove (BranchObj* a, BranchObj *b)
   111 {
   112 	if (a->angle < b->angle)
   113 		return true;
   114 	else	
   115 		return false;
   116 }
   117 
   118 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
   119 {
   120 	// Temporary link to lmo
   121 	// m is position of mouse pointer 
   122 	// offset 0: default 1: below lmo   -1 above lmo  (if possible)
   123 
   124 	BranchItem *pi=(BranchItem*)(lmo->getTreeItem()->parent());
   125 	int pi_depth=pi->depth();
   126 	BranchObj* o=(BranchObj*)(lmo);
   127 	if (!parObjTmpBuf) 
   128 		parObjTmpBuf=parObj;
   129 
   130 	// ignore mapcenter and mainbranch
   131 	if (pi_depth<2) off=0;
   132 	if (off==0)
   133 		link2ParPos=false;
   134 	else
   135 		link2ParPos=true;
   136 	parObj=o;
   137 
   138 	// FIXME-2 depth=parObj->getDepth()+1;
   139 
   140 	// setLinkStyle calls updateLinkGeometry, only set it once
   141 	if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
   142 
   143 	// Move temporary to new position at destination
   144 	// Usually the positioning would be done by reposition(),
   145 	// but then also the destination branch would "Jump" around...
   146 	// Better just do it approximately
   147 	if (treeItem->depth()==1)	// FIXME-3 needed to recursively calc depth?
   148 	{	// new parent is the mapcenter itself
   149 
   150 		QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
   151 									  m.y() - o->getChildPos().y() ));
   152 		if (p.x()<0) p.setX( p.x()-bbox.width() );
   153 		move2RelPos (p);
   154 	} else
   155 	{	
   156 		qreal y;
   157 		if (off==0)
   158 		{
   159 			// new parent is just a branch, link to it
   160 			QRectF t=o->getBBoxSizeWithChildren();
   161 			if (o->getTreeItem()->getLastBranch())
   162 				y=t.y() + t.height() ;
   163 			else
   164 				y=t.y();
   165 
   166 		} else
   167 		{
   168 			if (off<0)
   169 				// we want to link above lmo
   170 				y=o->y() - height() + 5;
   171 			else	
   172 				// we want to link below lmo
   173 				// Bottom of sel should be 5 pixels above
   174 				// the bottom of the branch _below_ the target:
   175 				// Don't try to find that branch, guess 12 pixels
   176 				y=o->getChildPos().y()  -height() + 12; 
   177 		}	
   178 		if (o->getOrientation()==LinkableMapObj::LeftOfCenter)
   179 			move ( o->getChildPos().x() - linkwidth, y );
   180 		else	
   181 			move (o->getChildPos().x() + linkwidth, y );
   182 	}	
   183 
   184 	// updateLinkGeometry is called implicitly in move
   185 	requestReposition();	
   186 }
   187 
   188 void BranchObj::unsetParObjTmp()
   189 {
   190 	if (parObjTmpBuf) 
   191 	{
   192 		link2ParPos=false;
   193 		parObj=parObjTmpBuf;
   194 		parObjTmpBuf=NULL;
   195 		//FIXME-2 depth=parObj->getDepth()+1;
   196 		setLinkStyle (getDefLinkStyle() );
   197 		updateLinkGeometry();
   198 	}		
   199 }
   200 
   201 void BranchObj::setVisibility(bool v, int toDepth)
   202 {
   203 	BranchItem *bi=(BranchItem*)treeItem;
   204     if (bi->depth() <= toDepth)
   205     {
   206 		frame->setVisibility(v);
   207 		heading->setVisibility(v);
   208 		systemFlags->setVisibility(v);
   209 		standardFlags->setVisibility(v);
   210 		LinkableMapObj::setVisibility (v);
   211 		int i;
   212 		for (i=0; i<treeItem->imageCount(); ++i)
   213 			treeItem->getImageObjNum(i)->setVisibility (v);
   214 		for (i=0; i<xlink.size(); ++i)	
   215 			xlink.at(i)->setVisibility ();	
   216 
   217 		// Only change children, if I am not scrolled
   218 		if (! bi->isScrolled() && (bi->depth() < toDepth))
   219 		{
   220 			// Now go recursivly through all children //FIXME-3 are there multiple calls for lower level items???
   221 			for (i=0; i<treeItem->branchCount(); ++i)
   222 				treeItem->getBranchObjNum(i)->setVisibility (v,toDepth);	
   223 		}
   224     } // depth <= toDepth	
   225 	requestReposition();
   226 }	
   227 
   228 void BranchObj::setVisibility(bool v)
   229 {
   230     setVisibility (v,MAX_DEPTH);
   231 }
   232 
   233 
   234 void BranchObj::setLinkColor ()
   235 {
   236 	// Overloaded from LinkableMapObj
   237 	// BranchObj can use color of heading
   238 
   239 	VymModel *model=treeItem->getModel();
   240 	if (model)
   241 	{
   242 		if (model->getMapLinkColorHint()==HeadingColor)
   243 			LinkableMapObj::setLinkColor (heading->getColor() );
   244 		else	
   245 			LinkableMapObj::setLinkColor ();
   246 	}		
   247 }
   248 
   249 void BranchObj::updateContentSize()
   250 {
   251 	calcBBoxSize();
   252 	positionBBox();
   253 	requestReposition();
   254 }
   255 
   256 void BranchObj::positionContents()
   257 {
   258 	for (int i=0; i<treeItem->imageCount(); ++i)
   259 		treeItem->getImageObjNum(i)->reposition();
   260 	OrnamentedObj::positionContents();
   261 }
   262 
   263 void BranchObj::move (double x, double y)
   264 {
   265 	OrnamentedObj::move (x,y);
   266 	FloatImageObj *fio;
   267     for (int i=0; i<treeItem->imageCount(); ++i )
   268 	{
   269 		fio=treeItem->getImageObjNum(i);
   270 		if (fio) fio->reposition();
   271 	}
   272     positionBBox();
   273 }
   274 
   275 void BranchObj::move (QPointF p)
   276 {
   277 	move (p.x(), p.y());
   278 }
   279 
   280 void BranchObj::moveBy (double x, double y)
   281 {
   282 	OrnamentedObj::moveBy (x,y);
   283 	for (int i=0; i<treeItem->branchCount(); ++i)
   284 		treeItem->getBranchObjNum(i)->moveBy (x,y);
   285     positionBBox();
   286 }
   287 	
   288 void BranchObj::moveBy (QPointF p)
   289 {
   290 	moveBy (p.x(), p.y());
   291 }
   292 
   293 
   294 void BranchObj::positionBBox()
   295 {
   296 	QPointF ap=getAbsPos();
   297 	bbox.moveTopLeft (ap);
   298 	positionContents();
   299 
   300 	// set the frame
   301 	frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
   302 
   303 	// Update links to other branches
   304 	for (int i=0; i<xlink.size(); ++i)
   305 		xlink.at(i)->updateXLink();
   306 }
   307 
   308 void BranchObj::calcBBoxSize()
   309 {
   310     QSizeF heading_r=heading->getSize();
   311     qreal heading_w=(qreal) heading_r.width() ;
   312     qreal heading_h=(qreal) heading_r.height() ;
   313     QSizeF sysflags_r=systemFlags->getSize();
   314 	qreal sysflags_h=sysflags_r.height();
   315 	qreal sysflags_w=sysflags_r.width();
   316     QSizeF stanflags_r=standardFlags->getSize();
   317 	qreal stanflags_h=stanflags_r.height();
   318 	qreal stanflags_w=stanflags_r.width();
   319     qreal w;
   320     qreal h;
   321 
   322 	// set width to sum of all widths
   323 	w=heading_w + sysflags_w + stanflags_w;
   324 	// set height to maximum needed height
   325 	h=max (sysflags_h,stanflags_h);
   326 	h=max (h,heading_h);
   327 
   328 	// Save the dimension of flags and heading
   329 	ornamentsBBox.setSize ( QSizeF(w,h));
   330 
   331 	// clickBox includes Flags and Heading
   332     clickBox.setSize (ornamentsBBox.size() );
   333 
   334 	// Floatimages 
   335 	QPointF rp;
   336 
   337 	topPad=botPad=leftPad=rightPad=0;
   338 	bool incV=((BranchItem*)treeItem)->getIncludeImagesVer();
   339 	bool incH=((BranchItem*)treeItem)->getIncludeImagesHor();
   340 	if (incH || incV)
   341 	{
   342 		FloatImageObj *fio;
   343 		for (int i=0; i<treeItem->imageCount(); ++i )	
   344 		{
   345 			fio=treeItem->getImageObjNum(i);
   346 			rp=fio->getRelPos();
   347 			if (incV)
   348 			{
   349 				if (rp.y() < 0) 
   350 					topPad=max (topPad,-rp.y()-h);
   351 				if (rp.y()+fio->height() > 0)
   352 					botPad=max (botPad,rp.y()+fio->height());
   353 			}		
   354 			if (incH)
   355 			{
   356 				if (orientation==LinkableMapObj::RightOfCenter)
   357 				{
   358 					if (-rp.x()-w > 0) 
   359 						leftPad=max (leftPad,-rp.x()-w);
   360 					if (rp.x()+fio->width() > 0)
   361 						rightPad=max (rightPad,rp.x()+fio->width());
   362 				} else
   363 				{
   364 					if (rp.x()< 0) 
   365 						leftPad=max (leftPad,-rp.x());
   366 					if (rp.x()+fio->width() > w)
   367 						rightPad=max (rightPad,rp.x()+fio->width()-w);
   368 				}
   369 			}		
   370 		}	
   371 		h+=topPad+botPad;
   372 		w+=leftPad+rightPad;
   373 	}
   374 
   375 	// Frame thickness
   376     w+=frame->getPadding();
   377     h+=frame->getPadding();
   378 	
   379 	// Finally set size
   380     bbox.setSize (QSizeF (w,h));
   381 }
   382 
   383 void BranchObj::setDockPos()
   384 {
   385 	if (treeItem->getType()==TreeItem::MapCenter)
   386 	{
   387 		// set childPos to middle of MapCenterObj
   388 		childPos.setX( clickBox.topLeft().x() + clickBox.width()/2 );
   389 		childPos.setY( clickBox.topLeft().y() + clickBox.height()/2 );
   390 		parPos=childPos;		
   391 		for (int i=0; i<treeItem->branchCount(); ++i)
   392 			treeItem->getBranchObjNum(i)->updateLinkGeometry();
   393 
   394 	} else
   395 	{
   396 		// Sets childpos and parpos depending on orientation
   397 		if (getOrientation()==LinkableMapObj::LeftOfCenter )
   398 		{
   399 			childPos=QPointF (
   400 				ornamentsBBox.bottomLeft().x(), 
   401 				bottomlineY);
   402 			parPos=QPointF (
   403 				ornamentsBBox.bottomRight().x(),
   404 				bottomlineY);
   405 		} else
   406 		{
   407 			childPos=QPointF (
   408 				ornamentsBBox.bottomRight().x(), 
   409 				bottomlineY);
   410 			parPos=QPointF (
   411 				ornamentsBBox.bottomLeft().x(),
   412 				bottomlineY);
   413 		}
   414 	}
   415 }
   416 
   417 void BranchObj::updateData()
   418 {
   419 	bool changed=false;
   420 	if (!treeItem)
   421 	{
   422 		qWarning ("BranchObj::udpateHeading treeItem==NULL");
   423 		return;
   424 	}
   425 	QString s=treeItem->getHeading();
   426 	if (s!=heading->text())
   427 	{
   428 		heading->setText (s);
   429 		changed=true;
   430 	}
   431 	QStringList TIactiveFlags=treeItem->activeStandardFlagNames();
   432 
   433 	// Add missing standard flags active in TreeItem
   434 	for (int i=0;i<=TIactiveFlags.size()-1;i++)
   435 	{	
   436 		if (!standardFlags->isActive (TIactiveFlags.at(i) ))
   437 		{
   438 			Flag *f=standardFlagsMaster->getFlag(TIactiveFlags.at(i));
   439 			if (f) standardFlags->activate (f);
   440 			changed=true;
   441 		}
   442 	}
   443 	// Remove standard flags no longer active in TreeItem
   444 	QStringList BOactiveFlags=standardFlags->activeFlagNames();
   445 	for (int i=0;i<BOactiveFlags.size();++i)
   446 		if (!TIactiveFlags.contains (BOactiveFlags.at(i)))
   447 		{
   448 			standardFlags->deactivate (BOactiveFlags.at(i));
   449 			changed=true;
   450 		}	
   451 
   452 	// Add missing system flags active in TreeItem
   453 	TIactiveFlags=treeItem->activeSystemFlagNames();
   454 	for (int i=0;i<TIactiveFlags.size();++i)
   455 	{	
   456 		if (!systemFlags->isActive (TIactiveFlags.at(i) ))
   457 		{
   458 			Flag *f=systemFlagsMaster->getFlag(TIactiveFlags.at(i));
   459 			if (f) systemFlags->activate (f);
   460 			changed=true;
   461 		}
   462 	}
   463 	// Remove system flags no longer active in TreeItem
   464 	BOactiveFlags=systemFlags->activeFlagNames();
   465 	for (int i=0;i<BOactiveFlags.size();++i)
   466 	{
   467 		if (!TIactiveFlags.contains (BOactiveFlags.at(i)))
   468 		{
   469 			systemFlags->deactivate (BOactiveFlags.at(i));
   470 			changed=true;
   471 		}	
   472 	}
   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  
   517 // FIXME-3 FloatImageObj* BranchObj::addFloatImage ()
   518 /*
   519 {
   520 	FloatImageObj *newfi=new FloatImageObj (scene,this);
   521 	floatimage.append (newfi);
   522 	if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
   523 		newfi->setVisibility (false);
   524 	else	
   525 		newfi->setVisibility(visible);
   526 	//calcBBoxSize();
   527 	//positionBBox();
   528 	requestReposition();
   529 	return newfi;
   530 }
   531 */
   532 
   533 //FIXME-3 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
   534 /*
   535 {
   536 	FloatImageObj *newfi=new FloatImageObj (scene,this);
   537 	floatimage.append (newfi);
   538 	newfi->copy (fio);
   539 	if (((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
   540 		newfi->setVisibility (false);
   541 	else	
   542 		newfi->setVisibility(visible);
   543 	//calcBBoxSize();
   544 	//positionBBox();
   545 	requestReposition();
   546 	return newfi;
   547 }
   548 */
   549 
   550 /* FIXME-3 FloatImageObj* BranchObj::getFirstFloatImage ()
   551 {
   552     return floatimage.first();
   553 }
   554 
   555 FloatImageObj* BranchObj::getLastFloatImage ()
   556 {
   557     return floatimage.last();
   558 }
   559 
   560 FIXME -3 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
   561 {
   562     return floatimage.at(i);
   563 }
   564 
   565 void BranchObj::removeFloatImage (FloatImageObj *fio)
   566 {
   567 	int i=floatimage.indexOf (fio);
   568 	if (i>-1) delete (floatimage.takeAt (i));
   569 	calcBBoxSize();
   570 	positionBBox();
   571 	requestReposition();
   572 }
   573 */
   574 
   575 void BranchObj::savePosInAngle ()
   576 {
   577 	// Save position in angle
   578 	for (int i=0; i<treeItem->branchCount(); ++i)
   579 		treeItem->getBranchObjNum(i)->angle=i;
   580 }
   581 
   582 void BranchObj::setDefAttr (BranchModification mod)
   583 {
   584 	int fontsize;
   585 	switch (treeItem->depth())
   586 	{
   587 		case 0: fontsize=16; break;
   588 		case 1: fontsize=12; break;
   589 		default: fontsize=10; break;
   590 	}	
   591 
   592 	setLinkColor ();
   593 	setLinkStyle(getDefLinkStyle());
   594 	QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
   595 	font.setPointSize(fontsize);
   596 	heading->setFont(font );
   597 
   598 	if (mod==NewBranch)
   599 		setColor (treeItem->getHeadingColor() );
   600 	calcBBoxSize();
   601 }
   602 
   603 void BranchObj::sortChildren() //FIXME-2  
   604 {
   605 /*
   606 	int childCount=branch.count(); 
   607 	int curChildIndex;
   608 	bool madeChanges=false;
   609 	do
   610 	{
   611 		madeChanges=false;
   612 		for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
   613 			BranchObj* curChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex);
   614 			BranchObj* prevChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex-1);
   615 			if(prevChild->heading->text().compare(curChild->heading->text())>0)
   616 			{
   617 				this->moveBranchUp(curChild);
   618 				madeChanges=true;
   619 			}
   620 		}
   621 	}while(madeChanges);
   622 */
   623 }
   624 
   625 void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
   626 {
   627 	qreal th = bboxTotal.height();	
   628 	int depth=treeItem->depth();	// FIXME-3 needed to recursively calc depth?
   629 // TODO testing
   630 /*
   631 
   632 	QString h=QString (depth,' ');
   633 	h+=treeItem->getHeading();
   634 	h+=QString (15,' ');
   635 	h.truncate (15);
   636 	QPointF pp; if (parObj) pp=parObj->getChildPos();
   637 	cout << "BO::alignRelTo ";
   638 	cout<<h.toStdString();
   639 	cout << "    d="<<depth<<
   640 //cout<<  "  ref="<<ref<<
   641       	"  bbox.tL="<<bboxTotal.topLeft()<<
   642 		"  absPos="<<absPos<<
   643 //		"  relPos="<<relPos<<
   644 //		"  parPos="<<pp<<
   645 		"  w="<<bbox.width()<<
   646 		"  h="<<bbox.height()<<
   647 //		"  orient="<<orientation<<
   648 //		"  alignSelf="<<alignSelf<<
   649 //		"  scrolled="<<((BranchItem*)treeItem)->isScrolled()<<
   650 //		"  pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
   651 //		"  hidden="<<hidden<<
   652 		"  th="<<th<<
   653 		endl;
   654 */
   655 
   656 	setOrientation();
   657 	//updateLinkGeometry();
   658 
   659 	if (depth==1 && parObj)
   660 	{
   661 		// Position relatively, if needed
   662 		//if (useRelPos) move2RelPos (relPos.x(), relPos.y());
   663 
   664 		// Calc angle to mapCenter if I am a mainbranch
   665 		// needed for reordering the mainbranches clockwise 
   666 		// around mapcenter 
   667 		angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ), 
   668 								(int)(y() - parObj->getChildPos().y() ) ) );
   669 	}							
   670 	if (depth>1)
   671     {
   672 		// Align myself depending on orientation and parent, but
   673 		// only if I am not a mainbranch or mapcenter itself
   674 
   675 		if (anim.isAnimated())
   676 		{
   677 			move2RelPos(anim);
   678 		} else
   679 		{
   680 			LinkableMapObj::Orientation o;
   681 			o=parObj->getOrientation();
   682 			if (alignSelf)
   683 				switch (orientation) 
   684 				{
   685 					case LinkableMapObj::LeftOfCenter:
   686 						move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
   687 						//move (ref.x() , ref.y() + (th-bbox.height())/2 );
   688 					break;
   689 					case LinkableMapObj::RightOfCenter:	
   690 						move (ref.x() , ref.y() + (th-bbox.height())/2  );
   691 					break;
   692 					default:
   693 						qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
   694 					break;
   695 			}
   696 		}
   697     }		
   698 
   699 	if ( ((BranchItem*)treeItem)->isScrolled() ) return;
   700 
   701     // Set reference point for alignment of children
   702     QPointF ref2;
   703     if (orientation==LinkableMapObj::LeftOfCenter)
   704 		ref2.setX(bbox.topLeft().x() - linkwidth);
   705     else	
   706 		ref2.setX(bbox.topRight().x() + linkwidth);
   707 
   708 	if (depth==1)
   709 		ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
   710 	else	
   711 		ref2.setY(ref.y() );	
   712 
   713     // Align the children depending on reference point 
   714 	for (int i=0; i<treeItem->branchCount(); ++i)
   715     {	
   716 		if (!treeItem->getBranchNum(i)->isHidden())
   717 		{
   718 			treeItem->getBranchObjNum(i)->alignRelativeTo (ref2,true);
   719 
   720 			// append next branch below current one
   721 			ref2.setY(ref2.y() + treeItem->getBranchObjNum(i)->getBBoxSizeWithChildren().height() );
   722 		}
   723     }
   724 }
   725 
   726 
   727 void BranchObj::reposition()
   728 {	
   729 /* TODO testing only
   730 	if (!treeItem->getHeading().isEmpty())
   731 		cout << "BO::reposition  "<<qPrintable(treeItem->getHeading())<<endl;
   732 	else	
   733 		cout << "BO::reposition  ???"<<endl;
   734 //	cout << "  orient="<<orientation<<endl;
   735 */		
   736 
   737 	if (treeItem->depth()==0)
   738 	{
   739 		// only calculate the sizes once. If the deepest LMO 
   740 		// changes its height,
   741 		// all upper LMOs have to change, too.
   742 		calcBBoxSizeWithChildren();
   743 		updateLinkGeometry();	// This update is needed if the scene is resized 
   744 						// due to excessive moving of a FIO
   745 
   746 	    alignRelativeTo ( QPointF (absPos.x(),
   747 			absPos.y()-(bboxTotal.height()-bbox.height())/2) );
   748 		//FIXME-2 qSort (branch.begin(),branch.end(), isAbove);
   749 		positionBBox();	// Reposition bbox and contents
   750 	} else
   751 	{
   752 		// This is only important for moving branches:
   753 		// For editing a branch it isn't called...
   754 	    alignRelativeTo ( QPointF (absPos.x(),
   755 							absPos.y()-(bboxTotal.height()-bbox.height())/2) );
   756 	}
   757 }
   758 
   759 void BranchObj::unsetAllRepositionRequests()
   760 {
   761 	repositionRequest=false;
   762 	for (int i=0; i<treeItem->branchCount(); ++i)
   763 		treeItem->getBranchObjNum(i)->unsetAllRepositionRequests();
   764 }
   765 
   766 
   767 QPolygonF BranchObj::shape()
   768 {
   769 	QPolygonF p;
   770 
   771 	QRectF r=getTotalBBox();
   772 	if (orientation==LinkableMapObj::LeftOfCenter)
   773 		p   <<r.bottomLeft()
   774 			<<r.topLeft()
   775 			<<QPointF (bbox.topLeft().x(), r.topLeft().y() )
   776 			<<bbox.topRight()
   777 			<<bbox.bottomRight()
   778 			<<QPointF (bbox.bottomLeft().x(), r.bottomLeft().y() ) ;
   779 	else		
   780 		p   <<r.bottomRight()
   781 			<<r.topRight()
   782 			<<QPointF (bbox.topRight().x(), r.topRight().y() )
   783 			<<bbox.topLeft()
   784 			<<bbox.bottomLeft()
   785 			<<QPointF (bbox.bottomRight().x(), r.bottomRight().y() ) ;
   786 	return p;
   787 }
   788 
   789 QRectF BranchObj::getTotalBBox()
   790 {
   791 	QRectF r=bbox;
   792 
   793 	if ( ((BranchItem*)treeItem)->isScrolled() ) return r;
   794 
   795 	for (int i=0; i<treeItem->branchCount(); ++i)
   796 		if (!treeItem->getBranchNum(i)->isHidden())
   797 			r=addBBox(treeItem->getBranchObjNum(i)->getTotalBBox(),r);
   798 
   799 /* FIXME-3 lots of occurences of treeItem->getBranchObjNum(i) in branchobj.cpp
   800             better check if they are not NULL and maybe simplify...
   801 			(have been NULL at least in calcBBoxSizeWithChilds...)
   802 */			
   803 
   804 	for (int i=0; i<treeItem->imageCount(); ++i)
   805 		if (!treeItem->isHidden())
   806 			r=addBBox(treeItem->getImageObjNum(i)->getTotalBBox(),r);
   807 	return r;
   808 }
   809 
   810 QRectF BranchObj::getBBoxSizeWithChildren()
   811 {
   812 	return bboxTotal;
   813 }
   814 
   815 void BranchObj::calcBBoxSizeWithChildren()
   816 {	
   817 	// This is initially called only from reposition and
   818 	// and only for mapcenter. So it won't be
   819 	// called more than once for a single user 
   820 	// action
   821 	
   822 
   823 	// Calculate size of LMO including all children (to align them later)
   824 	bboxTotal.setX(bbox.x() );
   825 	bboxTotal.setY(bbox.y() );
   826 
   827 	// if branch is scrolled, ignore children, but still consider floatimages
   828 	BranchItem *bi=(BranchItem*)treeItem;
   829 	if ( bi->isScrolled() ) 
   830 	{
   831 		bboxTotal.setWidth (bbox.width());
   832 		bboxTotal.setHeight(bbox.height());
   833 		return;
   834 	}
   835 	
   836 	if (bi->isHidden())
   837 	{
   838 		bboxTotal.setWidth (0);
   839 		bboxTotal.setHeight(0);
   840 		if (parObj)
   841 		{
   842 			bboxTotal.setX (parObj->x());
   843 			bboxTotal.setY (parObj->y());
   844 		} else
   845 		{
   846 			bboxTotal.setX (bbox.x());
   847 			bboxTotal.setY (bbox.y());
   848 		}
   849 		return;
   850 	}
   851 	
   852 	QRectF r(0,0,0,0);
   853 	QRectF br;
   854 	// Now calculate recursivly
   855 	// sum of heights 
   856 	// maximum of widths 
   857 	// minimum of y
   858 	for (int i=0; i<treeItem->branchCount(); i++)
   859 	{
   860 		if (!bi->getBranchNum(i)->isHidden())
   861 		{
   862 			bi->getBranchObjNum(i)->calcBBoxSizeWithChildren();
   863 			br=bi->getBranchObjNum(i)->getBBoxSizeWithChildren();
   864 			r.setWidth( max (br.width(), r.width() ));
   865 			r.setHeight(br.height() + r.height() );
   866 			if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
   867 		}
   868 	}
   869 	// Add myself and also
   870 	// add width of link to sum if necessary
   871 	if (bi->branchCount()<1)
   872 		bboxTotal.setWidth (bbox.width() + r.width() );
   873 	else	
   874 		bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
   875 	
   876 	bboxTotal.setHeight(max (r.height(),  bbox.height()));
   877 }
   878 
   879 QString BranchObj::getSelectString()
   880 {
   881 	VymModel *model=treeItem->getModel();
   882 	if (model)
   883 		return model->getSelectString (this);
   884 	else
   885 		return QString();
   886 }
   887 
   888 void BranchObj::setAnimation(const AnimPoint &ap)
   889 {
   890 	anim=ap;
   891 }
   892 
   893 bool BranchObj::animate()
   894 {
   895 	anim.animate ();
   896 	if ( anim.isAnimated() )
   897 	{
   898 		setRelPos (anim);
   899 		return true;
   900 	}
   901 	parObj->reposition();	// we might have been relinked meanwhile
   902 	return false;
   903 }
   904