branchobj.cpp
author insilmaril
Thu, 03 Dec 2009 22:32:24 +0000
changeset 814 31de6677aa96
parent 804 14f2b1b15242
child 815 2881c4424190
permissions -rw-r--r--
Feature: Better handling of xLinks
     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 (QGraphicsScene* s,TreeItem *ti):OrnamentedObj (s)
    17 {
    18 //    cout << "Const BranchObj (s)  \n";
    19     scene=s;
    20 	treeItem=ti;
    21 	BranchItem *pi=(BranchItem*)(ti->parent());
    22 	if (pi && pi!=ti->getModel()->getRootItem() )
    23 		parObj=pi->getLMO();
    24 	else
    25 		parObj=NULL;
    26 	init();
    27 }
    28 
    29 /*
    30 BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)// FIXME-3 needed at all?
    31 {
    32 //    cout << "Const BranchObj (s,p)\n";
    33     scene=s;
    34     setParObj (p);	
    35 	if (treeItem->depth()==1)	// FIXME-3 needed to recursively calc depth?
    36 		// Calc angle to mapCenter if I am a mainbranch
    37 		// needed for reordering the mainbranches clockwise 
    38 		// around mapcenter 
    39 		angle=getAngle (QPointF (x() - parObj->getChildPos().x() , 
    40 								(y() - parObj->getChildPos().y() ) ) );
    41     init();
    42 }
    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* dst, QPointF m, int off)	//FIXME-1 when moving a mainbranch to a branch it still has relPos, not moved as child
   119 {
   120 	// Temporary link to dst
   121 	// m is position of mouse pointer 
   122 	// offset 0: default 1: below dst   -1 above dst  (if possible)
   123 
   124 	BranchItem *dsti=(BranchItem*)(dst->getTreeItem());
   125 
   126 	BranchItem *pi=(BranchItem*)(dsti->parent());
   127 	int pi_depth=pi->depth();
   128 	BranchObj* bo=(BranchObj*)dst;
   129 
   130 	if (!tmpParent) 
   131 	{
   132 		tmpParent=true;
   133 		parObjTmpBuf=parObj;
   134 	}
   135 
   136 	if (pi_depth<2) off=0;
   137 	if (off==0)
   138 		link2ParPos=false;
   139 	else
   140 		link2ParPos=true;
   141 	parObj=bo;
   142 
   143 	setLinkStyle (dst->getDefLinkStyle (dsti));
   144  
   145 	// Move temporary to new position at destination
   146 	// Usually the positioning would be done by reposition(),
   147 	// but then also the destination branch would "Jump" around...
   148 	// Better just do it approximately
   149 	cout << "BO::setTmp  d="<<dsti->depth();
   150 	if (dsti->depth()==0)	
   151 	{	// new parent is a mapcenter
   152 		Vector v= ( m - bo->getChildPos());
   153 		if (v.x()<0) v.setX( v.x()-bbox.width() );
   154 		v.normalize();
   155 		v.scale (100);
   156 		move2RelPos (v.toQPointF());
   157 		cout << "  v="<<v<<endl;
   158 	} else
   159 	{	
   160 		qreal y;
   161 		if (off==0)
   162 		{
   163 			// new parent is just a branch, link to it
   164 			QRectF t=bo->getBBoxSizeWithChildren();
   165 			if (dsti->getLastBranch())
   166 				y=t.y() + t.height() ;
   167 			else
   168 				y=t.y();
   169 
   170 		} else
   171 		{
   172 			if (off<0)
   173 				// we want to link above dst
   174 				y=bo->y() - height() + 5;
   175 			else	
   176 				// we want to link below dst
   177 				// Bottom of sel should be 5 pixels above
   178 				// the bottom of the branch _below_ the target:
   179 				// Don't try to find that branch, guess 12 pixels
   180 				y=bo->getChildPos().y()  -height() + 12; 
   181 		}	
   182 		if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
   183 			move ( bo->getChildPos().x() - linkwidth, y );
   184 		else	
   185 			move (bo->getChildPos().x() + linkwidth, y );
   186 	}	
   187 
   188 	// updateLinkGeometry is called implicitly in move
   189 	requestReposition();	
   190 }
   191 
   192 void BranchObj::unsetParObjTmp()
   193 {
   194 	if (tmpParent) 
   195 	{
   196 		tmpParent=false;
   197 		link2ParPos=false;
   198 		parObj=parObjTmpBuf;
   199 		parObjTmpBuf=NULL;
   200 		setLinkStyle (getDefLinkStyle(treeItem->parent() ) );
   201 		updateLinkGeometry();
   202 	}		
   203 }
   204 
   205 void BranchObj::setVisibility(bool v, int toDepth)
   206 {
   207 	BranchItem *bi=(BranchItem*)treeItem;
   208     if (bi->depth() <= toDepth)
   209     {
   210 		frame->setVisibility(v);
   211 		heading->setVisibility(v);
   212 		systemFlags->setVisibility(v);
   213 		standardFlags->setVisibility(v);
   214 		LinkableMapObj::setVisibility (v);
   215 		int i;
   216 		for (i=0; i<treeItem->imageCount(); ++i)
   217 			treeItem->getImageObjNum(i)->setVisibility (v);
   218 		for (i=0; i<treeItem->xlinkCount(); ++i)	
   219 			treeItem->getXLinkObjNum(i)->setVisibility ();	
   220 
   221 		// Only change children, if I am not scrolled
   222 		if (! bi->isScrolled() && (bi->depth() < toDepth))
   223 		{
   224 			// Now go recursivly through all children //FIXME-3 are there multiple calls for lower level items???
   225 			for (i=0; i<treeItem->branchCount(); ++i)
   226 				treeItem->getBranchObjNum(i)->setVisibility (v,toDepth);	
   227 		}
   228     } // depth <= toDepth	
   229 	requestReposition();
   230 }	
   231 
   232 void BranchObj::setVisibility(bool v)
   233 {
   234     setVisibility (v,MAX_DEPTH);
   235 }
   236 
   237 
   238 void BranchObj::setLinkColor ()
   239 {
   240 	// Overloaded from LinkableMapObj
   241 	// BranchObj can use color of heading
   242 
   243 	VymModel *model=treeItem->getModel();
   244 	if (model)
   245 	{
   246 		if (model->getMapLinkColorHint()==HeadingColor)
   247 			LinkableMapObj::setLinkColor (heading->getColor() );
   248 		else	
   249 			LinkableMapObj::setLinkColor ();
   250 	}		
   251 }
   252 
   253 void BranchObj::updateContentSize()
   254 {
   255 	calcBBoxSize();
   256 	positionBBox();
   257 	requestReposition();
   258 }
   259 
   260 void BranchObj::positionContents()
   261 {
   262 	for (int i=0; i<treeItem->imageCount(); ++i)
   263 		treeItem->getImageObjNum(i)->reposition();
   264 	OrnamentedObj::positionContents();
   265 }
   266 
   267 void BranchObj::move (double x, double y)
   268 {
   269 	OrnamentedObj::move (x,y);
   270     positionBBox();
   271 }
   272 
   273 void BranchObj::move (QPointF p)
   274 {
   275 	move (p.x(), p.y());
   276 }
   277 
   278 void BranchObj::moveBy (double x, double y)
   279 {
   280 	OrnamentedObj::moveBy (x,y);
   281 	for (int i=0; i<treeItem->branchCount(); ++i)
   282 		treeItem->getBranchObjNum(i)->moveBy (x,y);
   283     positionBBox();
   284 }
   285 	
   286 void BranchObj::moveBy (QPointF p)
   287 {
   288 	moveBy (p.x(), p.y());
   289 }
   290 
   291 
   292 void BranchObj::positionBBox()
   293 {
   294 	QPointF ap=getAbsPos();
   295 	bbox.moveTopLeft (ap);
   296 	positionContents();
   297 
   298 	// set the frame
   299 	frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
   300 
   301 	//Update links to other branches
   302 	XLinkObj *xlo;
   303 	for (int i=0; i<treeItem->xlinkCount(); ++i)	
   304 	{
   305 		xlo=treeItem->getXLinkObjNum(i);
   306 		if (xlo) xlo->updateXLink();
   307 	}	
   308 }
   309 
   310 void BranchObj::calcBBoxSize()
   311 {
   312     QSizeF heading_r=heading->getSize();
   313     qreal heading_w=(qreal) heading_r.width() ;
   314     qreal heading_h=(qreal) heading_r.height() ;
   315     QSizeF sysflags_r=systemFlags->getSize();
   316 	qreal sysflags_h=sysflags_r.height();
   317 	qreal sysflags_w=sysflags_r.width();
   318     QSizeF stanflags_r=standardFlags->getSize();
   319 	qreal stanflags_h=stanflags_r.height();
   320 	qreal stanflags_w=stanflags_r.width();
   321     qreal w;
   322     qreal h;
   323 
   324 	// set width to sum of all widths
   325 	w=heading_w + sysflags_w + stanflags_w;
   326 	// set height to maximum needed height
   327 	h=max (sysflags_h,stanflags_h);
   328 	h=max (h,heading_h);
   329 
   330 	// Save the dimension of flags and heading
   331 	ornamentsBBox.setSize ( QSizeF(w,h));
   332 
   333 	// clickBox includes Flags and Heading
   334     clickBox.setSize (ornamentsBBox.size() );
   335 
   336 	// Floatimages 
   337 	QPointF rp;
   338 
   339 	topPad=botPad=leftPad=rightPad=0;
   340 	bool incV=((BranchItem*)treeItem)->getIncludeImagesVer();
   341 	bool incH=((BranchItem*)treeItem)->getIncludeImagesHor();
   342 	if (incH || incV)
   343 	{
   344 		FloatImageObj *fio;
   345 		for (int i=0; i<treeItem->imageCount(); ++i )	
   346 		{
   347 			fio=treeItem->getImageObjNum(i);
   348 			rp=fio->getRelPos();
   349 			if (incV)
   350 			{
   351 				if (rp.y() < 0) 
   352 					topPad=max (topPad,-rp.y()-h);
   353 				if (rp.y()+fio->height() > 0)
   354 					botPad=max (botPad,rp.y()+fio->height());
   355 			}		
   356 			if (incH)
   357 			{
   358 				if (orientation==LinkableMapObj::RightOfCenter)
   359 				{
   360 					if (-rp.x()-w > 0) 
   361 						leftPad=max (leftPad,-rp.x()-w);
   362 					if (rp.x()+fio->width() > 0)
   363 						rightPad=max (rightPad,rp.x()+fio->width());
   364 				} else
   365 				{
   366 					if (rp.x()< 0) 
   367 						leftPad=max (leftPad,-rp.x());
   368 					if (rp.x()+fio->width() > w)
   369 						rightPad=max (rightPad,rp.x()+fio->width()-w);
   370 				}
   371 			}		
   372 		}	
   373 		h+=topPad+botPad;
   374 		w+=leftPad+rightPad;
   375 	}
   376 
   377 	// Frame thickness
   378     w+=frame->getPadding();
   379     h+=frame->getPadding();
   380 	
   381 	// Finally set size
   382     bbox.setSize (QSizeF (w,h));
   383 }
   384 
   385 void BranchObj::setDockPos()
   386 {
   387 	if (treeItem->getType()==TreeItem::MapCenter)
   388 	{
   389 		// set childPos to middle of MapCenterObj
   390 		childPos.setX( clickBox.topLeft().x() + clickBox.width()/2 );
   391 		childPos.setY( clickBox.topLeft().y() + clickBox.height()/2 );
   392 		parPos=childPos;		
   393 		for (int i=0; i<treeItem->branchCount(); ++i)
   394 			treeItem->getBranchObjNum(i)->updateLinkGeometry();
   395 
   396 	} else
   397 	{
   398 		// Sets childpos and parpos depending on orientation
   399 		if (getOrientation()==LinkableMapObj::LeftOfCenter )
   400 		{
   401 			childPos=QPointF (
   402 				ornamentsBBox.bottomLeft().x(), 
   403 				bottomlineY);
   404 			parPos=QPointF (
   405 				ornamentsBBox.bottomRight().x(),
   406 				bottomlineY);
   407 		} else
   408 		{
   409 			childPos=QPointF (
   410 				ornamentsBBox.bottomRight().x(), 
   411 				bottomlineY);
   412 			parPos=QPointF (
   413 				ornamentsBBox.bottomLeft().x(),
   414 				bottomlineY);
   415 		}
   416 	}
   417 }
   418 
   419 void BranchObj::updateData()
   420 {
   421 	bool changed=false;
   422 	if (!treeItem)
   423 	{
   424 		qWarning ("BranchObj::udpateHeading treeItem==NULL");
   425 		return;
   426 	}
   427 	QString s=treeItem->getHeading();
   428 	if (s!=heading->text())
   429 	{
   430 		heading->setText (s);
   431 		changed=true;
   432 	}
   433 	QStringList TIactiveFlags=treeItem->activeStandardFlagNames();
   434 
   435 	// Add missing standard flags active in TreeItem
   436 	for (int i=0;i<=TIactiveFlags.size()-1;i++)
   437 	{	
   438 		if (!standardFlags->isActive (TIactiveFlags.at(i) ))
   439 		{
   440 			Flag *f=standardFlagsMaster->getFlag(TIactiveFlags.at(i));
   441 			if (f) standardFlags->activate (f);
   442 			changed=true;
   443 		}
   444 	}
   445 	// Remove standard flags no longer active in TreeItem
   446 	QStringList BOactiveFlags=standardFlags->activeFlagNames();
   447 	for (int i=0;i<BOactiveFlags.size();++i)
   448 		if (!TIactiveFlags.contains (BOactiveFlags.at(i)))
   449 		{
   450 			standardFlags->deactivate (BOactiveFlags.at(i));
   451 			changed=true;
   452 		}	
   453 
   454 	// Add missing system flags active in TreeItem
   455 	TIactiveFlags=treeItem->activeSystemFlagNames();
   456 	for (int i=0;i<TIactiveFlags.size();++i)
   457 	{	
   458 		if (!systemFlags->isActive (TIactiveFlags.at(i) ))
   459 		{
   460 			Flag *f=systemFlagsMaster->getFlag(TIactiveFlags.at(i));
   461 			if (f) systemFlags->activate (f);
   462 			changed=true;
   463 		}
   464 	}
   465 	// Remove system flags no longer active in TreeItem
   466 	BOactiveFlags=systemFlags->activeFlagNames();
   467 	for (int i=0;i<BOactiveFlags.size();++i)
   468 	{
   469 		if (!TIactiveFlags.contains (BOactiveFlags.at(i)))
   470 		{
   471 			systemFlags->deactivate (BOactiveFlags.at(i));
   472 			changed=true;
   473 		}	
   474 	}
   475 	updateContentSize();
   476 }
   477 
   478 void BranchObj::savePosInAngle ()
   479 {
   480 	// Save position in angle
   481 	for (int i=0; i<treeItem->branchCount(); ++i)
   482 		treeItem->getBranchObjNum(i)->angle=i;
   483 }
   484 
   485 void BranchObj::setDefAttr (BranchModification mod)
   486 {
   487 	int fontsize;
   488 	switch (treeItem->depth())
   489 	{
   490 		case 0: 
   491 			fontsize=16; 
   492 			setFrameType (FrameObj::Rectangle);
   493 			break;
   494 		case 1: 
   495 			fontsize=14; 
   496 			setFrameType (FrameObj::NoFrame);
   497 			break;
   498 		case 2: 
   499 			fontsize=12; 
   500 			setFrameType (FrameObj::NoFrame);
   501 			break;
   502 		default: 
   503 			fontsize=10; 
   504 			setFrameType (FrameObj::NoFrame);
   505 			break;
   506 	}	
   507 	setLinkStyle(getDefLinkStyle(treeItem->parent() ));
   508 	setLinkColor ();
   509 	QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
   510 	font.setPointSize(fontsize);
   511 	heading->setFont(font );
   512 
   513 	if (mod==NewBranch)
   514 		setColor (treeItem->getHeadingColor() );
   515 	else
   516 		// Also set styles for children
   517 		for (int i=0; i<treeItem->branchCount(); ++i)
   518 			treeItem->getBranchObjNum(i)->setDefAttr(MovedBranch);
   519 	calcBBoxSize();
   520 }
   521 
   522 void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
   523 {
   524 	qreal th = bboxTotal.height();	
   525 	int depth=treeItem->depth();	// FIXME-3 needed to recursively calc depth?
   526 // TODO testing
   527 /*
   528 
   529 	QString h=QString (depth,' ');
   530 	h+=treeItem->getHeading();
   531 	h+=QString (15,' ');
   532 	h.truncate (15);
   533 	QPointF pp; if (parObj) pp=parObj->getChildPos();
   534 	cout << "BO::alignRelTo ";
   535 	cout<<h.toStdString();
   536 	cout << "    d="<<depth<<
   537 //cout<<  "  ref="<<ref<<
   538       	"  bbox.tL="<<bboxTotal.topLeft()<<
   539 		"  absPos="<<absPos<<
   540 		"  relPos="<<relPos<<
   541 //		"  parPos="<<pp<<
   542 //		"  w="<<bbox.width()<<
   543 //		"  h="<<bbox.height()<<
   544 //		"  orient="<<orientation<<
   545 //		"  alignSelf="<<alignSelf<<
   546 //		"  scrolled="<<((BranchItem*)treeItem)->isScrolled()<<
   547 //		"  pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
   548 //		"  hidden="<<hidden<<
   549 		"  th="<<th<<
   550 		endl;
   551 */
   552 
   553 	setOrientation();
   554 	//updateLinkGeometry();
   555 
   556 	if (depth==1 && parObj)
   557 	{
   558 		// Position relatively, if needed
   559 		//if (useRelPos) move2RelPos (relPos.x(), relPos.y());
   560 
   561 		// Calc angle to mapCenter if I am a mainbranch
   562 		// needed for reordering the mainbranches clockwise 
   563 		// around mapcenter 
   564 		angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ), 
   565 								(int)(y() - parObj->getChildPos().y() ) ) );
   566 	}							
   567 	if (depth==1)
   568 	{
   569 		move2RelPos (getRelPos() );
   570 	}
   571 	if (depth>1)
   572     {
   573 		// Align myself depending on orientation and parent, but
   574 		// only if I am not a mainbranch or mapcenter itself
   575 
   576 		if (anim.isAnimated())
   577 		{
   578 			move2RelPos(anim);
   579 		} else
   580 		{
   581 			LinkableMapObj::Orientation o;
   582 			o=parObj->getOrientation();
   583 			if (alignSelf)
   584 				switch (orientation) 
   585 				{
   586 					case LinkableMapObj::LeftOfCenter:
   587 						move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
   588 						//move (ref.x() , ref.y() + (th-bbox.height())/2 );
   589 					break;
   590 					case LinkableMapObj::RightOfCenter:	
   591 						move (ref.x() , ref.y() + (th-bbox.height())/2  );
   592 					break;
   593 					default:
   594 						qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
   595 					break;
   596 			}
   597 		}
   598     }		
   599 
   600 	if ( ((BranchItem*)treeItem)->isScrolled() ) return;
   601 
   602     // Set reference point for alignment of children
   603     QPointF ref2;
   604     if (orientation==LinkableMapObj::LeftOfCenter)
   605 		ref2.setX(bbox.topLeft().x() - linkwidth);
   606     else	
   607 		ref2.setX(bbox.topRight().x() + linkwidth);
   608 
   609 	if (depth==1)
   610 		ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
   611 	else	
   612 		ref2.setY(ref.y() );	
   613 
   614     // Align the children depending on reference point 
   615 	for (int i=0; i<treeItem->branchCount(); ++i)
   616     {	
   617 		if (!treeItem->getBranchNum(i)->isHidden())
   618 		{
   619 			treeItem->getBranchObjNum(i)->alignRelativeTo (ref2,true);
   620 
   621 			// append next branch below current one
   622 			ref2.setY(ref2.y() + treeItem->getBranchObjNum(i)->getBBoxSizeWithChildren().height() );
   623 		}
   624     }
   625 }
   626 
   627 
   628 void BranchObj::reposition()
   629 {	
   630 /* TODO testing only
   631 	if (!treeItem->getHeading().isEmpty())
   632 		cout << "BO::reposition  "<<qPrintable(treeItem->getHeading())<<endl;
   633 	else	
   634 		cout << "BO::reposition  ???"<<endl;
   635 //	cout << "  orient="<<orientation<<endl;
   636 */		
   637 
   638 	if (treeItem->depth()==0)
   639 	{
   640 		// only calculate the sizes once. If the deepest LMO 
   641 		// changes its height,
   642 		// all upper LMOs have to change, too.
   643 		calcBBoxSizeWithChildren();
   644 		updateLinkGeometry();	// This update is needed if the scene is resized 
   645 						// due to excessive moving of a FIO
   646 
   647 	    alignRelativeTo ( QPointF (absPos.x(),
   648 			absPos.y()-(bboxTotal.height()-bbox.height())/2) );
   649 		//FIXME-2 qSort (branch.begin(),branch.end(), isAbove);
   650 		positionBBox();	// Reposition bbox and contents
   651 	} else
   652 	{
   653 		// This is only important for moving branches:
   654 		// For editing a branch it isn't called...
   655 	    alignRelativeTo ( QPointF (absPos.x(),
   656 							absPos.y()-(bboxTotal.height()-bbox.height())/2) );
   657 	}
   658 }
   659 
   660 void BranchObj::unsetAllRepositionRequests()
   661 {
   662 	repositionRequest=false;
   663 	for (int i=0; i<treeItem->branchCount(); ++i)
   664 		treeItem->getBranchObjNum(i)->unsetAllRepositionRequests();
   665 }
   666 
   667 
   668 QRectF BranchObj::getTotalBBox()
   669 {
   670 	QRectF r=bbox;
   671 
   672 	if ( ((BranchItem*)treeItem)->isScrolled() ) return r;
   673 
   674 	for (int i=0; i<treeItem->branchCount(); ++i)
   675 		if (!treeItem->getBranchNum(i)->isHidden())
   676 			r=addBBox(treeItem->getBranchObjNum(i)->getTotalBBox(),r);
   677 
   678 /* FIXME-3 lots of occurences of treeItem->getBranchObjNum(i) in branchobj.cpp
   679             better check if they are not NULL and maybe simplify...
   680 			(have been NULL at least in calcBBoxSizeWithChilds...)
   681 */			
   682 
   683 	for (int i=0; i<treeItem->imageCount(); ++i)
   684 		if (!treeItem->isHidden())
   685 			r=addBBox(treeItem->getImageObjNum(i)->getTotalBBox(),r);
   686 	return r;
   687 }
   688 
   689 QRectF BranchObj::getBBoxSizeWithChildren()
   690 {
   691 	return bboxTotal;
   692 }
   693 
   694 ConvexPolygon BranchObj::getBoundingPolygon()	
   695 {
   696 /*
   697 	if (!pi)	//FIXME-3 Testing only
   698 	{
   699 		pi=scene->addPolygon(MapObj::getBoundingPolygon() );
   700 		pi->setPen(Qt::NoPen);
   701 		pi->setBrush( QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8) );
   702 		pi->setZValue(Z_BBOX);
   703 	}
   704 	*/
   705 
   706 	if (treeItem->branchCount()==0 || treeItem->depth()==0)
   707 	{
   708 		if (pi) pi->setPolygon (MapObj::getBoundingPolygon() );
   709 		return MapObj::getBoundingPolygon();
   710 	}
   711 
   712 	calcBBoxSizeWithChildren();	//FIXME-3 really needed?
   713 	QPolygonF p;
   714 	p<<bboxTotal.topLeft();
   715 	p<<bboxTotal.topRight();
   716 	p<<bboxTotal.bottomRight();
   717 	p<<bboxTotal.bottomLeft();
   718 	//cout << "BO::getBP (total)  "<<treeItem->getHeadingStd()<<"  tL="<<bboxTotal.topLeft()<<"  bR="<<bboxTotal.bottomRight()<<endl;
   719 	//cout << "                   "<<"  tL="<<bbox.topLeft()<<"  bR="<<bbox.bottomRight()<<endl;
   720 	if (pi) pi->setPolygon (p );
   721 	return p;
   722 }
   723 
   724 void BranchObj::calcBBoxSizeWithChildren()
   725 {	
   726 	// This is initially called only from reposition and
   727 	// and only for mapcenter. So it won't be
   728 	// called more than once for a single user 
   729 	// action
   730 	
   731 
   732 	// Calculate size of LMO including all children (to align them later)
   733 	bboxTotal.setX(bbox.x() );
   734 	bboxTotal.setY(bbox.y() );
   735 
   736 	// if branch is scrolled, ignore children, but still consider floatimages
   737 	BranchItem *bi=(BranchItem*)treeItem;
   738 	if ( bi->isScrolled() ) 
   739 	{
   740 		bboxTotal.setWidth (bbox.width());
   741 		bboxTotal.setHeight(bbox.height());
   742 		return;
   743 	}
   744 	
   745 	if (bi->isHidden())
   746 	{
   747 		bboxTotal.setWidth (0);
   748 		bboxTotal.setHeight(0);
   749 		if (parObj)
   750 		{
   751 			bboxTotal.setX (parObj->x());
   752 			bboxTotal.setY (parObj->y());
   753 		} else
   754 		{
   755 			bboxTotal.setX (bbox.x());
   756 			bboxTotal.setY (bbox.y());
   757 		}
   758 		return;
   759 	}
   760 	
   761 	QRectF r(0,0,0,0);
   762 	QRectF br;
   763 	// Now calculate recursivly
   764 	// sum of heights 
   765 	// maximum of widths 
   766 	// minimum of y
   767 	for (int i=0; i<treeItem->branchCount(); i++)
   768 	{
   769 		if (!bi->getBranchNum(i)->isHidden())
   770 		{
   771 			bi->getBranchObjNum(i)->calcBBoxSizeWithChildren();
   772 			br=bi->getBranchObjNum(i)->getBBoxSizeWithChildren();
   773 			r.setWidth( max (br.width(), r.width() ));
   774 			r.setHeight(br.height() + r.height() );
   775 			if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
   776 			if (br.x()<bboxTotal.x()) bboxTotal.setX(br.x());
   777 		}
   778 	}
   779 	// Add myself and also
   780 	// add width of link to sum if necessary
   781 	if (bi->branchCount()<1)
   782 		bboxTotal.setWidth (bbox.width() + r.width() );
   783 	else	
   784 		bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
   785 	
   786 	bboxTotal.setHeight(max (r.height(),  bbox.height()));
   787 }
   788 
   789 QString BranchObj::getSelectString()
   790 {
   791 	VymModel *model=treeItem->getModel();
   792 	if (model)
   793 		return model->getSelectString (this);
   794 	else
   795 		return QString();
   796 }
   797 
   798 void BranchObj::setAnimation(const AnimPoint &ap)
   799 {
   800 	anim=ap;
   801 }
   802 
   803 bool BranchObj::animate()
   804 {
   805 	anim.animate ();
   806 	if ( anim.isAnimated() )
   807 	{
   808 		setRelPos (anim);
   809 		return true;
   810 	}
   811 	parObj->reposition();	// we might have been relinked meanwhile
   812 	return false;
   813 }
   814