branchobj.cpp
author insilmaril
Wed, 25 Nov 2009 15:27:22 +0000
changeset 808 b163492fda17
parent 804 14f2b1b15242
child 814 31de6677aa96
permissions -rw-r--r--
First version of new FindWidget instead of extra floating dialog
     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 	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=14; 
   494 			setFrameType (FrameObj::NoFrame);
   495 			break;
   496 		case 2: 
   497 			fontsize=12; 
   498 			setFrameType (FrameObj::NoFrame);
   499 			break;
   500 		default: 
   501 			fontsize=10; 
   502 			setFrameType (FrameObj::NoFrame);
   503 			break;
   504 	}	
   505 	setLinkStyle(getDefLinkStyle(treeItem->parent() ));
   506 	setLinkColor ();
   507 	QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
   508 	font.setPointSize(fontsize);
   509 	heading->setFont(font );
   510 
   511 	if (mod==NewBranch)
   512 		setColor (treeItem->getHeadingColor() );
   513 	else
   514 		// Also set styles for children
   515 		for (int i=0; i<treeItem->branchCount(); ++i)
   516 			treeItem->getBranchObjNum(i)->setDefAttr(MovedBranch);
   517 	calcBBoxSize();
   518 }
   519 
   520 void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
   521 {
   522 	qreal th = bboxTotal.height();	
   523 	int depth=treeItem->depth();	// FIXME-3 needed to recursively calc depth?
   524 // TODO testing
   525 /*
   526 
   527 	QString h=QString (depth,' ');
   528 	h+=treeItem->getHeading();
   529 	h+=QString (15,' ');
   530 	h.truncate (15);
   531 	QPointF pp; if (parObj) pp=parObj->getChildPos();
   532 	cout << "BO::alignRelTo ";
   533 	cout<<h.toStdString();
   534 	cout << "    d="<<depth<<
   535 //cout<<  "  ref="<<ref<<
   536       	"  bbox.tL="<<bboxTotal.topLeft()<<
   537 		"  absPos="<<absPos<<
   538 		"  relPos="<<relPos<<
   539 //		"  parPos="<<pp<<
   540 //		"  w="<<bbox.width()<<
   541 //		"  h="<<bbox.height()<<
   542 //		"  orient="<<orientation<<
   543 //		"  alignSelf="<<alignSelf<<
   544 //		"  scrolled="<<((BranchItem*)treeItem)->isScrolled()<<
   545 //		"  pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
   546 //		"  hidden="<<hidden<<
   547 		"  th="<<th<<
   548 		endl;
   549 */
   550 
   551 	setOrientation();
   552 	//updateLinkGeometry();
   553 
   554 	if (depth==1 && parObj)
   555 	{
   556 		// Position relatively, if needed
   557 		//if (useRelPos) move2RelPos (relPos.x(), relPos.y());
   558 
   559 		// Calc angle to mapCenter if I am a mainbranch
   560 		// needed for reordering the mainbranches clockwise 
   561 		// around mapcenter 
   562 		angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ), 
   563 								(int)(y() - parObj->getChildPos().y() ) ) );
   564 	}							
   565 	if (depth==1)
   566 	{
   567 		move2RelPos (getRelPos() );
   568 	}
   569 	if (depth>1)
   570     {
   571 		// Align myself depending on orientation and parent, but
   572 		// only if I am not a mainbranch or mapcenter itself
   573 
   574 		if (anim.isAnimated())
   575 		{
   576 			move2RelPos(anim);
   577 		} else
   578 		{
   579 			LinkableMapObj::Orientation o;
   580 			o=parObj->getOrientation();
   581 			if (alignSelf)
   582 				switch (orientation) 
   583 				{
   584 					case LinkableMapObj::LeftOfCenter:
   585 						move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
   586 						//move (ref.x() , ref.y() + (th-bbox.height())/2 );
   587 					break;
   588 					case LinkableMapObj::RightOfCenter:	
   589 						move (ref.x() , ref.y() + (th-bbox.height())/2  );
   590 					break;
   591 					default:
   592 						qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
   593 					break;
   594 			}
   595 		}
   596     }		
   597 
   598 	if ( ((BranchItem*)treeItem)->isScrolled() ) return;
   599 
   600     // Set reference point for alignment of children
   601     QPointF ref2;
   602     if (orientation==LinkableMapObj::LeftOfCenter)
   603 		ref2.setX(bbox.topLeft().x() - linkwidth);
   604     else	
   605 		ref2.setX(bbox.topRight().x() + linkwidth);
   606 
   607 	if (depth==1)
   608 		ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
   609 	else	
   610 		ref2.setY(ref.y() );	
   611 
   612     // Align the children depending on reference point 
   613 	for (int i=0; i<treeItem->branchCount(); ++i)
   614     {	
   615 		if (!treeItem->getBranchNum(i)->isHidden())
   616 		{
   617 			treeItem->getBranchObjNum(i)->alignRelativeTo (ref2,true);
   618 
   619 			// append next branch below current one
   620 			ref2.setY(ref2.y() + treeItem->getBranchObjNum(i)->getBBoxSizeWithChildren().height() );
   621 		}
   622     }
   623 }
   624 
   625 
   626 void BranchObj::reposition()
   627 {	
   628 /* TODO testing only
   629 	if (!treeItem->getHeading().isEmpty())
   630 		cout << "BO::reposition  "<<qPrintable(treeItem->getHeading())<<endl;
   631 	else	
   632 		cout << "BO::reposition  ???"<<endl;
   633 //	cout << "  orient="<<orientation<<endl;
   634 */		
   635 
   636 	if (treeItem->depth()==0)
   637 	{
   638 		// only calculate the sizes once. If the deepest LMO 
   639 		// changes its height,
   640 		// all upper LMOs have to change, too.
   641 		calcBBoxSizeWithChildren();
   642 		updateLinkGeometry();	// This update is needed if the scene is resized 
   643 						// due to excessive moving of a FIO
   644 
   645 	    alignRelativeTo ( QPointF (absPos.x(),
   646 			absPos.y()-(bboxTotal.height()-bbox.height())/2) );
   647 		//FIXME-2 qSort (branch.begin(),branch.end(), isAbove);
   648 		positionBBox();	// Reposition bbox and contents
   649 	} else
   650 	{
   651 		// This is only important for moving branches:
   652 		// For editing a branch it isn't called...
   653 	    alignRelativeTo ( QPointF (absPos.x(),
   654 							absPos.y()-(bboxTotal.height()-bbox.height())/2) );
   655 	}
   656 }
   657 
   658 void BranchObj::unsetAllRepositionRequests()
   659 {
   660 	repositionRequest=false;
   661 	for (int i=0; i<treeItem->branchCount(); ++i)
   662 		treeItem->getBranchObjNum(i)->unsetAllRepositionRequests();
   663 }
   664 
   665 
   666 QRectF BranchObj::getTotalBBox()
   667 {
   668 	QRectF r=bbox;
   669 
   670 	if ( ((BranchItem*)treeItem)->isScrolled() ) return r;
   671 
   672 	for (int i=0; i<treeItem->branchCount(); ++i)
   673 		if (!treeItem->getBranchNum(i)->isHidden())
   674 			r=addBBox(treeItem->getBranchObjNum(i)->getTotalBBox(),r);
   675 
   676 /* FIXME-3 lots of occurences of treeItem->getBranchObjNum(i) in branchobj.cpp
   677             better check if they are not NULL and maybe simplify...
   678 			(have been NULL at least in calcBBoxSizeWithChilds...)
   679 */			
   680 
   681 	for (int i=0; i<treeItem->imageCount(); ++i)
   682 		if (!treeItem->isHidden())
   683 			r=addBBox(treeItem->getImageObjNum(i)->getTotalBBox(),r);
   684 	return r;
   685 }
   686 
   687 QRectF BranchObj::getBBoxSizeWithChildren()
   688 {
   689 	return bboxTotal;
   690 }
   691 
   692 ConvexPolygon BranchObj::getBoundingPolygon()	
   693 {
   694 /*
   695 	if (!pi)	//FIXME-3 Testing only
   696 	{
   697 		pi=scene->addPolygon(MapObj::getBoundingPolygon() );
   698 		pi->setPen(Qt::NoPen);
   699 		pi->setBrush( QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8) );
   700 		pi->setZValue(Z_BBOX);
   701 	}
   702 	*/
   703 
   704 	if (treeItem->branchCount()==0 || treeItem->depth()==0)
   705 	{
   706 		if (pi) pi->setPolygon (MapObj::getBoundingPolygon() );
   707 		return MapObj::getBoundingPolygon();
   708 	}
   709 
   710 	calcBBoxSizeWithChildren();	//FIXME-3 really needed?
   711 	QPolygonF p;
   712 	p<<bboxTotal.topLeft();
   713 	p<<bboxTotal.topRight();
   714 	p<<bboxTotal.bottomRight();
   715 	p<<bboxTotal.bottomLeft();
   716 	//cout << "BO::getBP (total)  "<<treeItem->getHeadingStd()<<"  tL="<<bboxTotal.topLeft()<<"  bR="<<bboxTotal.bottomRight()<<endl;
   717 	//cout << "                   "<<"  tL="<<bbox.topLeft()<<"  bR="<<bbox.bottomRight()<<endl;
   718 	if (pi) pi->setPolygon (p );
   719 	return p;
   720 }
   721 
   722 void BranchObj::calcBBoxSizeWithChildren()
   723 {	
   724 	// This is initially called only from reposition and
   725 	// and only for mapcenter. So it won't be
   726 	// called more than once for a single user 
   727 	// action
   728 	
   729 
   730 	// Calculate size of LMO including all children (to align them later)
   731 	bboxTotal.setX(bbox.x() );
   732 	bboxTotal.setY(bbox.y() );
   733 
   734 	// if branch is scrolled, ignore children, but still consider floatimages
   735 	BranchItem *bi=(BranchItem*)treeItem;
   736 	if ( bi->isScrolled() ) 
   737 	{
   738 		bboxTotal.setWidth (bbox.width());
   739 		bboxTotal.setHeight(bbox.height());
   740 		return;
   741 	}
   742 	
   743 	if (bi->isHidden())
   744 	{
   745 		bboxTotal.setWidth (0);
   746 		bboxTotal.setHeight(0);
   747 		if (parObj)
   748 		{
   749 			bboxTotal.setX (parObj->x());
   750 			bboxTotal.setY (parObj->y());
   751 		} else
   752 		{
   753 			bboxTotal.setX (bbox.x());
   754 			bboxTotal.setY (bbox.y());
   755 		}
   756 		return;
   757 	}
   758 	
   759 	QRectF r(0,0,0,0);
   760 	QRectF br;
   761 	// Now calculate recursivly
   762 	// sum of heights 
   763 	// maximum of widths 
   764 	// minimum of y
   765 	for (int i=0; i<treeItem->branchCount(); i++)
   766 	{
   767 		if (!bi->getBranchNum(i)->isHidden())
   768 		{
   769 			bi->getBranchObjNum(i)->calcBBoxSizeWithChildren();
   770 			br=bi->getBranchObjNum(i)->getBBoxSizeWithChildren();
   771 			r.setWidth( max (br.width(), r.width() ));
   772 			r.setHeight(br.height() + r.height() );
   773 			if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
   774 			if (br.x()<bboxTotal.x()) bboxTotal.setX(br.x());
   775 		}
   776 	}
   777 	// Add myself and also
   778 	// add width of link to sum if necessary
   779 	if (bi->branchCount()<1)
   780 		bboxTotal.setWidth (bbox.width() + r.width() );
   781 	else	
   782 		bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
   783 	
   784 	bboxTotal.setHeight(max (r.height(),  bbox.height()));
   785 }
   786 
   787 QString BranchObj::getSelectString()
   788 {
   789 	VymModel *model=treeItem->getModel();
   790 	if (model)
   791 		return model->getSelectString (this);
   792 	else
   793 		return QString();
   794 }
   795 
   796 void BranchObj::setAnimation(const AnimPoint &ap)
   797 {
   798 	anim=ap;
   799 }
   800 
   801 bool BranchObj::animate()
   802 {
   803 	anim.animate ();
   804 	if ( anim.isAnimated() )
   805 	{
   806 		setRelPos (anim);
   807 		return true;
   808 	}
   809 	parObj->reposition();	// we might have been relinked meanwhile
   810 	return false;
   811 }
   812