branchobj.cpp
author insilmaril
Thu, 01 Oct 2009 13:23:20 +0000
changeset 800 959bd133cd1a
parent 798 d251c7b2de54
child 804 14f2b1b15242
permissions -rw-r--r--
preparing sortFilter
     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 after moving a mainbranch to a branch and away again mainbranch is no longer connected to mapcenter...
   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 	if (parObj->getTreeItem()->depth()==0)	
   150 	{	// new parent is a mapcenter
   151 		Vector v= ( m - bo->getChildPos());
   152 		if (v.x()<0) v.setX( v.x()-bbox.width() );
   153 		v.normalize();
   154 		v.scale (100);
   155 		move2RelPos (v.toQPointF());
   156 	} else
   157 	{	
   158 		qreal y;
   159 		if (off==0)
   160 		{
   161 			// new parent is just a branch, link to it
   162 			QRectF t=bo->getBBoxSizeWithChildren();
   163 			if (dsti->getLastBranch())
   164 				y=t.y() + t.height() ;
   165 			else
   166 				y=t.y();
   167 
   168 		} else
   169 		{
   170 			if (off<0)
   171 				// we want to link above dst
   172 				y=bo->y() - height() + 5;
   173 			else	
   174 				// we want to link below dst
   175 				// Bottom of sel should be 5 pixels above
   176 				// the bottom of the branch _below_ the target:
   177 				// Don't try to find that branch, guess 12 pixels
   178 				y=bo->getChildPos().y()  -height() + 12; 
   179 		}	
   180 		if (bo->getOrientation()==LinkableMapObj::LeftOfCenter)
   181 			move ( bo->getChildPos().x() - linkwidth, y );
   182 		else	
   183 			move (bo->getChildPos().x() + linkwidth, y );
   184 	}	
   185 
   186 	// updateLinkGeometry is called implicitly in move
   187 	requestReposition();	
   188 }
   189 
   190 void BranchObj::unsetParObjTmp()
   191 {
   192 	if (tmpParent) 
   193 	{
   194 		tmpParent=false;
   195 		link2ParPos=false;
   196 		parObj=parObjTmpBuf;
   197 		parObjTmpBuf=NULL;
   198 		setLinkStyle (getDefLinkStyle(treeItem->parent() ) );
   199 		updateLinkGeometry();
   200 	}		
   201 }
   202 
   203 void BranchObj::setVisibility(bool v, int toDepth)
   204 {
   205 	BranchItem *bi=(BranchItem*)treeItem;
   206     if (bi->depth() <= toDepth)
   207     {
   208 		frame->setVisibility(v);
   209 		heading->setVisibility(v);
   210 		systemFlags->setVisibility(v);
   211 		standardFlags->setVisibility(v);
   212 		LinkableMapObj::setVisibility (v);
   213 		int i;
   214 		for (i=0; i<treeItem->imageCount(); ++i)
   215 			treeItem->getImageObjNum(i)->setVisibility (v);
   216 		for (i=0; i<treeItem->xlinkCount(); ++i)	
   217 			treeItem->getXLinkObjNum(i)->setVisibility ();	
   218 
   219 		// Only change children, if I am not scrolled
   220 		if (! bi->isScrolled() && (bi->depth() < toDepth))
   221 		{
   222 			// Now go recursivly through all children //FIXME-3 are there multiple calls for lower level items???
   223 			for (i=0; i<treeItem->branchCount(); ++i)
   224 				treeItem->getBranchObjNum(i)->setVisibility (v,toDepth);	
   225 		}
   226     } // depth <= toDepth	
   227 	requestReposition();
   228 }	
   229 
   230 void BranchObj::setVisibility(bool v)
   231 {
   232     setVisibility (v,MAX_DEPTH);
   233 }
   234 
   235 
   236 void BranchObj::setLinkColor ()
   237 {
   238 	// Overloaded from LinkableMapObj
   239 	// BranchObj can use color of heading
   240 
   241 	VymModel *model=treeItem->getModel();
   242 	if (model)
   243 	{
   244 		if (model->getMapLinkColorHint()==HeadingColor)
   245 			LinkableMapObj::setLinkColor (heading->getColor() );
   246 		else	
   247 			LinkableMapObj::setLinkColor ();
   248 	}		
   249 }
   250 
   251 void BranchObj::updateContentSize()
   252 {
   253 	calcBBoxSize();
   254 	positionBBox();
   255 	requestReposition();
   256 }
   257 
   258 void BranchObj::positionContents()
   259 {
   260 	for (int i=0; i<treeItem->imageCount(); ++i)
   261 		treeItem->getImageObjNum(i)->reposition();
   262 	OrnamentedObj::positionContents();
   263 }
   264 
   265 void BranchObj::move (double x, double y)
   266 {
   267 	OrnamentedObj::move (x,y);
   268     positionBBox();
   269 }
   270 
   271 void BranchObj::move (QPointF p)
   272 {
   273 	move (p.x(), p.y());
   274 }
   275 
   276 void BranchObj::moveBy (double x, double y)
   277 {
   278 	OrnamentedObj::moveBy (x,y);
   279 	for (int i=0; i<treeItem->branchCount(); ++i)
   280 		treeItem->getBranchObjNum(i)->moveBy (x,y);
   281     positionBBox();
   282 }
   283 	
   284 void BranchObj::moveBy (QPointF p)
   285 {
   286 	moveBy (p.x(), p.y());
   287 }
   288 
   289 
   290 void BranchObj::positionBBox()
   291 {
   292 	QPointF ap=getAbsPos();
   293 	bbox.moveTopLeft (ap);
   294 	positionContents();
   295 
   296 	// set the frame
   297 	frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
   298 
   299 	//Update links to other branches
   300 	XLinkObj *xlo;
   301 	for (int i=0; i<treeItem->xlinkCount(); ++i)	
   302 	{
   303 		xlo=treeItem->getXLinkObjNum(i);
   304 		if (xlo) xlo->updateXLink();
   305 	}	
   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 void BranchObj::savePosInAngle ()
   477 {
   478 	// Save position in angle
   479 	for (int i=0; i<treeItem->branchCount(); ++i)
   480 		treeItem->getBranchObjNum(i)->angle=i;
   481 }
   482 
   483 void BranchObj::setDefAttr (BranchModification mod)
   484 {
   485 	int fontsize;
   486 	switch (treeItem->depth())
   487 	{
   488 		case 0: 
   489 			fontsize=16; 
   490 			setFrameType (FrameObj::Rectangle);
   491 			break;
   492 		case 1: 
   493 			fontsize=12; 
   494 			setFrameType (FrameObj::NoFrame);
   495 			break;
   496 		default: 
   497 			fontsize=10; 
   498 			setFrameType (FrameObj::NoFrame);
   499 			break;
   500 	}	
   501 	setLinkStyle(getDefLinkStyle(treeItem->parent() ));
   502 	setLinkColor ();
   503 	QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
   504 	font.setPointSize(fontsize);
   505 	heading->setFont(font );
   506 
   507 	if (mod==NewBranch)
   508 		setColor (treeItem->getHeadingColor() );
   509 	else
   510 		// Also set styles for children
   511 		for (int i=0; i<treeItem->branchCount(); ++i)
   512 			treeItem->getBranchObjNum(i)->setDefAttr(MovedBranch);
   513 	calcBBoxSize();
   514 }
   515 
   516 void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
   517 {
   518 	qreal th = bboxTotal.height();	
   519 	int depth=treeItem->depth();	// FIXME-3 needed to recursively calc depth?
   520 // TODO testing
   521 /*
   522 
   523 	QString h=QString (depth,' ');
   524 	h+=treeItem->getHeading();
   525 	h+=QString (15,' ');
   526 	h.truncate (15);
   527 	QPointF pp; if (parObj) pp=parObj->getChildPos();
   528 	cout << "BO::alignRelTo ";
   529 	cout<<h.toStdString();
   530 	cout << "    d="<<depth<<
   531 //cout<<  "  ref="<<ref<<
   532       	"  bbox.tL="<<bboxTotal.topLeft()<<
   533 		"  absPos="<<absPos<<
   534 		"  relPos="<<relPos<<
   535 //		"  parPos="<<pp<<
   536 //		"  w="<<bbox.width()<<
   537 //		"  h="<<bbox.height()<<
   538 //		"  orient="<<orientation<<
   539 //		"  alignSelf="<<alignSelf<<
   540 //		"  scrolled="<<((BranchItem*)treeItem)->isScrolled()<<
   541 //		"  pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
   542 //		"  hidden="<<hidden<<
   543 		"  th="<<th<<
   544 		endl;
   545 */
   546 
   547 	setOrientation();
   548 	//updateLinkGeometry();
   549 
   550 	if (depth==1 && parObj)
   551 	{
   552 		// Position relatively, if needed
   553 		//if (useRelPos) move2RelPos (relPos.x(), relPos.y());
   554 
   555 		// Calc angle to mapCenter if I am a mainbranch
   556 		// needed for reordering the mainbranches clockwise 
   557 		// around mapcenter 
   558 		angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ), 
   559 								(int)(y() - parObj->getChildPos().y() ) ) );
   560 	}							
   561 	if (depth==1)
   562 	{
   563 		move2RelPos (getRelPos() );
   564 	}
   565 	if (depth>1)
   566     {
   567 		// Align myself depending on orientation and parent, but
   568 		// only if I am not a mainbranch or mapcenter itself
   569 
   570 		if (anim.isAnimated())
   571 		{
   572 			move2RelPos(anim);
   573 		} else
   574 		{
   575 			LinkableMapObj::Orientation o;
   576 			o=parObj->getOrientation();
   577 			if (alignSelf)
   578 				switch (orientation) 
   579 				{
   580 					case LinkableMapObj::LeftOfCenter:
   581 						move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
   582 						//move (ref.x() , ref.y() + (th-bbox.height())/2 );
   583 					break;
   584 					case LinkableMapObj::RightOfCenter:	
   585 						move (ref.x() , ref.y() + (th-bbox.height())/2  );
   586 					break;
   587 					default:
   588 						qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
   589 					break;
   590 			}
   591 		}
   592     }		
   593 
   594 	if ( ((BranchItem*)treeItem)->isScrolled() ) return;
   595 
   596     // Set reference point for alignment of children
   597     QPointF ref2;
   598     if (orientation==LinkableMapObj::LeftOfCenter)
   599 		ref2.setX(bbox.topLeft().x() - linkwidth);
   600     else	
   601 		ref2.setX(bbox.topRight().x() + linkwidth);
   602 
   603 	if (depth==1)
   604 		ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
   605 	else	
   606 		ref2.setY(ref.y() );	
   607 
   608     // Align the children depending on reference point 
   609 	for (int i=0; i<treeItem->branchCount(); ++i)
   610     {	
   611 		if (!treeItem->getBranchNum(i)->isHidden())
   612 		{
   613 			treeItem->getBranchObjNum(i)->alignRelativeTo (ref2,true);
   614 
   615 			// append next branch below current one
   616 			ref2.setY(ref2.y() + treeItem->getBranchObjNum(i)->getBBoxSizeWithChildren().height() );
   617 		}
   618     }
   619 }
   620 
   621 
   622 void BranchObj::reposition()
   623 {	
   624 /* TODO testing only
   625 	if (!treeItem->getHeading().isEmpty())
   626 		cout << "BO::reposition  "<<qPrintable(treeItem->getHeading())<<endl;
   627 	else	
   628 		cout << "BO::reposition  ???"<<endl;
   629 //	cout << "  orient="<<orientation<<endl;
   630 */		
   631 
   632 	if (treeItem->depth()==0)
   633 	{
   634 		// only calculate the sizes once. If the deepest LMO 
   635 		// changes its height,
   636 		// all upper LMOs have to change, too.
   637 		calcBBoxSizeWithChildren();
   638 		updateLinkGeometry();	// This update is needed if the scene is resized 
   639 						// due to excessive moving of a FIO
   640 
   641 	    alignRelativeTo ( QPointF (absPos.x(),
   642 			absPos.y()-(bboxTotal.height()-bbox.height())/2) );
   643 		//FIXME-2 qSort (branch.begin(),branch.end(), isAbove);
   644 		positionBBox();	// Reposition bbox and contents
   645 	} else
   646 	{
   647 		// This is only important for moving branches:
   648 		// For editing a branch it isn't called...
   649 	    alignRelativeTo ( QPointF (absPos.x(),
   650 							absPos.y()-(bboxTotal.height()-bbox.height())/2) );
   651 	}
   652 }
   653 
   654 void BranchObj::unsetAllRepositionRequests()
   655 {
   656 	repositionRequest=false;
   657 	for (int i=0; i<treeItem->branchCount(); ++i)
   658 		treeItem->getBranchObjNum(i)->unsetAllRepositionRequests();
   659 }
   660 
   661 
   662 QRectF BranchObj::getTotalBBox()
   663 {
   664 	QRectF r=bbox;
   665 
   666 	if ( ((BranchItem*)treeItem)->isScrolled() ) return r;
   667 
   668 	for (int i=0; i<treeItem->branchCount(); ++i)
   669 		if (!treeItem->getBranchNum(i)->isHidden())
   670 			r=addBBox(treeItem->getBranchObjNum(i)->getTotalBBox(),r);
   671 
   672 /* FIXME-3 lots of occurences of treeItem->getBranchObjNum(i) in branchobj.cpp
   673             better check if they are not NULL and maybe simplify...
   674 			(have been NULL at least in calcBBoxSizeWithChilds...)
   675 */			
   676 
   677 	for (int i=0; i<treeItem->imageCount(); ++i)
   678 		if (!treeItem->isHidden())
   679 			r=addBBox(treeItem->getImageObjNum(i)->getTotalBBox(),r);
   680 	return r;
   681 }
   682 
   683 QRectF BranchObj::getBBoxSizeWithChildren()
   684 {
   685 	return bboxTotal;
   686 }
   687 
   688 ConvexPolygon BranchObj::getBoundingPolygon()	
   689 {
   690 /*
   691 	if (!pi)	//FIXME-3 Testing only
   692 	{
   693 		pi=scene->addPolygon(MapObj::getBoundingPolygon() );
   694 		pi->setPen(Qt::NoPen);
   695 		pi->setBrush( QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8) );
   696 		pi->setZValue(Z_BBOX);
   697 	}
   698 	*/
   699 
   700 	if (treeItem->branchCount()==0 || treeItem->depth()==0)
   701 	{
   702 		if (pi) pi->setPolygon (MapObj::getBoundingPolygon() );
   703 		return MapObj::getBoundingPolygon();
   704 	}
   705 
   706 	calcBBoxSizeWithChildren();	//FIXME-3 really needed?
   707 	QPolygonF p;
   708 	p<<bboxTotal.topLeft();
   709 	p<<bboxTotal.topRight();
   710 	p<<bboxTotal.bottomRight();
   711 	p<<bboxTotal.bottomLeft();
   712 	//cout << "BO::getBP (total)  "<<treeItem->getHeadingStd()<<"  tL="<<bboxTotal.topLeft()<<"  bR="<<bboxTotal.bottomRight()<<endl;
   713 	//cout << "                   "<<"  tL="<<bbox.topLeft()<<"  bR="<<bbox.bottomRight()<<endl;
   714 	if (pi) pi->setPolygon (p );
   715 	return p;
   716 }
   717 
   718 void BranchObj::calcBBoxSizeWithChildren()
   719 {	
   720 	// This is initially called only from reposition and
   721 	// and only for mapcenter. So it won't be
   722 	// called more than once for a single user 
   723 	// action
   724 	
   725 
   726 	// Calculate size of LMO including all children (to align them later)
   727 	bboxTotal.setX(bbox.x() );
   728 	bboxTotal.setY(bbox.y() );
   729 
   730 	// if branch is scrolled, ignore children, but still consider floatimages
   731 	BranchItem *bi=(BranchItem*)treeItem;
   732 	if ( bi->isScrolled() ) 
   733 	{
   734 		bboxTotal.setWidth (bbox.width());
   735 		bboxTotal.setHeight(bbox.height());
   736 		return;
   737 	}
   738 	
   739 	if (bi->isHidden())
   740 	{
   741 		bboxTotal.setWidth (0);
   742 		bboxTotal.setHeight(0);
   743 		if (parObj)
   744 		{
   745 			bboxTotal.setX (parObj->x());
   746 			bboxTotal.setY (parObj->y());
   747 		} else
   748 		{
   749 			bboxTotal.setX (bbox.x());
   750 			bboxTotal.setY (bbox.y());
   751 		}
   752 		return;
   753 	}
   754 	
   755 	QRectF r(0,0,0,0);
   756 	QRectF br;
   757 	// Now calculate recursivly
   758 	// sum of heights 
   759 	// maximum of widths 
   760 	// minimum of y
   761 	for (int i=0; i<treeItem->branchCount(); i++)
   762 	{
   763 		if (!bi->getBranchNum(i)->isHidden())
   764 		{
   765 			bi->getBranchObjNum(i)->calcBBoxSizeWithChildren();
   766 			br=bi->getBranchObjNum(i)->getBBoxSizeWithChildren();
   767 			r.setWidth( max (br.width(), r.width() ));
   768 			r.setHeight(br.height() + r.height() );
   769 			if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
   770 			if (br.x()<bboxTotal.x()) bboxTotal.setX(br.x());
   771 		}
   772 	}
   773 	// Add myself and also
   774 	// add width of link to sum if necessary
   775 	if (bi->branchCount()<1)
   776 		bboxTotal.setWidth (bbox.width() + r.width() );
   777 	else	
   778 		bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
   779 	
   780 	bboxTotal.setHeight(max (r.height(),  bbox.height()));
   781 }
   782 
   783 QString BranchObj::getSelectString()
   784 {
   785 	VymModel *model=treeItem->getModel();
   786 	if (model)
   787 		return model->getSelectString (this);
   788 	else
   789 		return QString();
   790 }
   791 
   792 void BranchObj::setAnimation(const AnimPoint &ap)
   793 {
   794 	anim=ap;
   795 }
   796 
   797 bool BranchObj::animate()
   798 {
   799 	anim.animate ();
   800 	if ( anim.isAnimated() )
   801 	{
   802 		setRelPos (anim);
   803 		return true;
   804 	}
   805 	parObj->reposition();	// we might have been relinked meanwhile
   806 	return false;
   807 }
   808