branchobj.cpp
author insilmaril
Mon, 27 Apr 2009 12:42:06 +0000
changeset 757 c6908bc17d78
parent 756 a8a5c7288f57
child 760 59614eaf5fbb
permissions -rw-r--r--
minor fixes and cleanups
     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 //class TextEditor; //FIXME-3
    10 
    11 //extern TextEditor *textEditor;
    12 //extern Main *mainWindow;
    13 //extern FlagRowObj *standardFlagsDefault;
    14 
    15 
    16 /////////////////////////////////////////////////////////////////
    17 // BranchObj
    18 /////////////////////////////////////////////////////////////////
    19 
    20 BranchObj::BranchObj () :OrnamentedObj()	// FIXME-3 needed at all?
    21 {
    22 //    cout << "Const BranchObj ()\n";
    23     setParObj (this);	
    24     init();
    25 }
    26 
    27 BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s)// FIXME-3 needed at all?
    28 {
    29 //    cout << "Const BranchObj (s)  \n";
    30 	parObj=NULL;
    31     scene=s;
    32 	init();
    33 }
    34 
    35 BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)// FIXME-3 needed at all?
    36 {
    37 //    cout << "Const BranchObj (s,p)\n";
    38     scene=s;
    39     setParObj (p);	
    40 	if (treeItem->depth()==1)
    41 		// Calc angle to mapCenter if I am a mainbranch
    42 		// needed for reordering the mainbranches clockwise 
    43 		// around mapcenter 
    44 		angle=getAngle (QPointF (x() - parObj->getChildPos().x() , 
    45 								(y() - parObj->getChildPos().y() ) ) );
    46     init();
    47 }
    48 
    49 BranchObj::~BranchObj ()
    50 {
    51 //	cout << "Destr BranchObj of "<<this<<" ("<<treeItem->getHeading().toStdString()<<")"<<endl;
    52 
    53 	// If I'm animated, I need to un-animate myself first
    54 	if (anim.isAnimated() )
    55 	{
    56 		anim.setAnimated (false);
    57 		model->stopAnimation (this);
    58 	}
    59 
    60 	// Check, if this branch was the last child to be deleted
    61 	// If so, unset the scrolled flags in parent // FIXME-2 better do this in model?
    62 
    63 	/*
    64 	BranchObj *po=(BranchObj*)parObj;
    65 	BranchObj *bo;
    66 	if (po)
    67 	{
    68 		bo=((BranchObj*)parObj)->getLastBranch();
    69 		if (bo) po->unScroll();
    70 	}
    71 	*/
    72 	clear();
    73 }
    74 
    75 bool BranchObj::operator< ( const BranchObj & other )
    76 {
    77     return  angle < other.angle;
    78 }
    79 
    80 bool BranchObj::operator== ( const BranchObj & other )
    81 {
    82     return angle == other.angle;
    83 }
    84 
    85 void BranchObj::init () 
    86 {
    87 	if (parObj)
    88 	{
    89 		absPos=getRandPos();
    90 		absPos+=parObj->getChildPos();
    91 	}
    92 
    93     setChildObj(this);
    94 
    95 	includeImagesVer=false;
    96 	includeImagesHor=false;
    97 }
    98 
    99 void BranchObj::copy (BranchObj* other)
   100 {
   101     OrnamentedObj::copy(other);
   102 
   103 /* FIXME-3 not needed
   104 	for (int i=0; i<other->treeItem->branchCount(); ++i)
   105 		// Make deep copy of b
   106 		// Because addBranch again calls copy for the children,
   107 		// Those will get a deep copy, too
   108 		addBranch(other->branch.at(i) );	
   109 */		
   110 
   111 	for (int i=0; i<other->floatimage.size(); ++i)
   112 		addFloatImage  (other->floatimage.at(i));
   113 	
   114 	setVisibility (other->visible);
   115 
   116 	angle=other->angle;
   117 
   118     positionBBox();
   119 }
   120 
   121 void BranchObj::clear() 
   122 {
   123 	//setVisibility (true); //FIXME-4 needed?
   124 
   125 	while (!floatimage.isEmpty())
   126 		delete floatimage.takeFirst();
   127 
   128 	while (!xlink.isEmpty())
   129 		delete xlink.takeFirst();
   130 }
   131 
   132 bool isAbove (BranchObj* a, BranchObj *b)
   133 {
   134 	if (a->angle < b->angle)
   135 		return true;
   136 	else	
   137 		return false;
   138 }
   139 
   140 void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
   141 {
   142 	// Temporary link to lmo
   143 	// m is position of mouse pointer 
   144 	// offset 0: default 1: below lmo   -1 above lmo  (if possible)
   145 
   146 
   147 	BranchObj* o=(BranchObj*)(lmo);
   148 	if (!parObjTmpBuf) 
   149 		parObjTmpBuf=parObj;
   150 
   151 	// ignore mapcenter and mainbranch
   152 	if (treeItem->depth()<2) off=0;
   153 	if (off==0)
   154 		link2ParPos=false;
   155 	else
   156 		link2ParPos=true;
   157 	parObj=o;
   158 
   159 	// FIXME-2 depth=parObj->getDepth()+1;
   160 
   161 	// setLinkStyle calls updateLink, only set it once
   162 	if (style!=getDefLinkStyle() ) setLinkStyle (getDefLinkStyle());
   163 
   164 	// Move temporary to new position at destination
   165 	// Usually the positioning would be done by reposition(),
   166 	// but then also the destination branch would "Jump" around...
   167 	// Better just do it approximately
   168 	if (treeItem->depth()==1)
   169 	{	// new parent is the mapcenter itself
   170 
   171 		QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
   172 									  m.y() - o->getChildPos().y() ));
   173 		if (p.x()<0) p.setX( p.x()-bbox.width() );
   174 		move2RelPos (p);
   175 	} else
   176 	{	
   177 		qreal y;
   178 		if (off==0)
   179 		{
   180 			// new parent is just a branch, link to it
   181 			QRectF t=o->getBBoxSizeWithChildren();
   182 			if (o->getTreeItem()->getLastBranch())
   183 				y=t.y() + t.height() ;
   184 			else
   185 				y=t.y();
   186 
   187 		} else
   188 		{
   189 			if (off<0)
   190 				// we want to link above lmo
   191 				y=o->y() - height() + 5;
   192 			else	
   193 				// we want to link below lmo
   194 				// Bottom of sel should be 5 pixels above
   195 				// the bottom of the branch _below_ the target:
   196 				// Don't try to find that branch, guess 12 pixels
   197 				y=o->getChildPos().y()  -height() + 12; 
   198 		}	
   199 		if (o->getOrientation()==LinkableMapObj::LeftOfCenter)
   200 			move ( o->getChildPos().x() - linkwidth, y );
   201 		else	
   202 			move (o->getChildPos().x() + linkwidth, y );
   203 	}	
   204 
   205 	// updateLink is called implicitly in move
   206 	requestReposition();	
   207 }
   208 
   209 void BranchObj::unsetParObjTmp()
   210 {
   211 	if (parObjTmpBuf) 
   212 	{
   213 		link2ParPos=false;
   214 		parObj=parObjTmpBuf;
   215 		parObjTmpBuf=NULL;
   216 		//FIXME-2 depth=parObj->getDepth()+1;
   217 		setLinkStyle (getDefLinkStyle() );
   218 		updateLink();
   219 	}		
   220 }
   221 
   222 void BranchObj::setVisibility(bool v, int toDepth)
   223 {
   224 	BranchItem *bi=(BranchItem*)treeItem;
   225     if (bi->depth() <= toDepth)
   226     {
   227 		frame->setVisibility(v);
   228 		heading->setVisibility(v);
   229 		systemFlags->setVisibility(v);
   230 		standardFlags->setVisibility(v);
   231 		LinkableMapObj::setVisibility (v);
   232 		int i;
   233 		for (i=0; i<floatimage.size(); ++i)
   234 			floatimage.at(i)->setVisibility (v);
   235 		for (i=0; i<xlink.size(); ++i)	
   236 			xlink.at(i)->setVisibility ();	
   237 
   238 		// Only change children, if I am not scrolled
   239 		if (! bi->isScrolled() && (bi->depth() < toDepth))
   240 		{
   241 			// Now go recursivly through all children
   242 			for (i=0; i<treeItem->branchCount(); ++i)
   243 				treeItem->getBranchObjNum(i)->setVisibility (v,toDepth);	
   244 		}
   245     } // depth <= toDepth	
   246 	requestReposition();
   247 }	
   248 
   249 void BranchObj::setVisibility(bool v)
   250 {
   251     setVisibility (v,MAX_DEPTH);
   252 }
   253 
   254 
   255 void BranchObj::setLinkColor ()
   256 {
   257 	// Overloaded from LinkableMapObj
   258 	// BranchObj can use color of heading
   259 
   260 	if (model)
   261 	{
   262 		if (model->getMapLinkColorHint()==HeadingColor)
   263 			LinkableMapObj::setLinkColor (heading->getColor() );
   264 		else	
   265 			LinkableMapObj::setLinkColor ();
   266 	}		
   267 }
   268 
   269 void BranchObj::setColorSubtree(QColor col)
   270 {
   271 	setColor (col);
   272 	for (int i=0; i<treeItem->branchCount(); ++i)
   273 		treeItem->getBranchObjNum(i)->setColorSubtree(col);
   274 }
   275 
   276 void BranchObj::updateContentSize()
   277 {
   278 	calcBBoxSize();
   279 	positionBBox();
   280 	requestReposition();
   281 }
   282 
   283 void BranchObj::positionContents()
   284 {
   285     for (int i=0; i<floatimage.size(); ++i )
   286 		floatimage.at(i)->reposition();
   287 	OrnamentedObj::positionContents();
   288 }
   289 
   290 void BranchObj::move (double x, double y)
   291 {
   292 	OrnamentedObj::move (x,y);
   293     for (int i=0; i<floatimage.size(); ++i )
   294 		floatimage.at(i)->reposition();
   295     positionBBox();
   296 }
   297 
   298 void BranchObj::move (QPointF p)
   299 {
   300 	move (p.x(), p.y());
   301 }
   302 
   303 void BranchObj::moveBy (double x, double y)
   304 {
   305 	OrnamentedObj::moveBy (x,y);
   306 	for (int i=0; i<treeItem->branchCount(); ++i)
   307 		treeItem->getBranchObjNum(i)->moveBy (x,y);
   308     positionBBox();
   309 }
   310 	
   311 void BranchObj::moveBy (QPointF p)
   312 {
   313 	moveBy (p.x(), p.y());
   314 }
   315 
   316 
   317 void BranchObj::positionBBox()
   318 {
   319 	QPointF ap=getAbsPos();
   320 	bbox.moveTopLeft (ap);
   321 	positionContents();
   322 
   323 	// set the frame
   324 	frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
   325 
   326 	// Update links to other branches
   327 	for (int i=0; i<xlink.size(); ++i)
   328 		xlink.at(i)->updateXLink();
   329 }
   330 
   331 void BranchObj::calcBBoxSize()
   332 {
   333     QSizeF heading_r=heading->getSize();
   334     qreal heading_w=(qreal) heading_r.width() ;
   335     qreal heading_h=(qreal) heading_r.height() ;
   336     QSizeF sysflags_r; //FIXME-1 =systemFlags->getSize();
   337 	qreal sysflags_h=0;//sysflags_r.height();
   338 	qreal sysflags_w=0;//sysflags_r.width();
   339     QSizeF stanflags_r; //FIXME-1 =standardFlags->getSize();
   340 	qreal stanflags_h=0; //stanflags_r.height();
   341 	qreal stanflags_w=0; //stanflags_r.width();
   342     qreal w;
   343     qreal h;
   344 
   345 	// set width to sum of all widths
   346 	w=heading_w + sysflags_w + stanflags_w;
   347 	// set height to maximum needed height
   348 	h=max (sysflags_h,stanflags_h);
   349 	h=max (h,heading_h);
   350 
   351 	// Save the dimension of flags and heading
   352 	ornamentsBBox.setSize ( QSizeF(w,h));
   353 
   354 	// clickBox includes Flags and Heading
   355     clickBox.setSize (ornamentsBBox.size() );
   356 
   357 	// Floatimages 
   358 	QPointF rp;
   359 
   360 	topPad=botPad=leftPad=rightPad=0;
   361 	if (includeImagesVer || includeImagesHor)
   362 	{
   363 		if (treeItem->imageCount()>0)
   364 		{
   365 			for (int i=0; i<floatimage.size(); ++i )
   366 			{
   367 				rp=floatimage.at(i)->getRelPos();
   368 				if (includeImagesVer)
   369 				{
   370 					if (rp.y() < 0) 
   371 						topPad=max (topPad,-rp.y()-h);
   372 					if (rp.y()+floatimage.at(i)->height() > 0)
   373 						botPad=max (botPad,rp.y()+floatimage.at(i)->height());
   374 				}		
   375 				if (includeImagesHor)
   376 				{
   377 					if (orientation==LinkableMapObj::RightOfCenter)
   378 					{
   379 						if (-rp.x()-w > 0) 
   380 							leftPad=max (leftPad,-rp.x()-w);
   381 						if (rp.x()+floatimage.at(i)->width() > 0)
   382 							rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
   383 					} else
   384 					{
   385 						if (rp.x()< 0) 
   386 							leftPad=max (leftPad,-rp.x());
   387 						if (rp.x()+floatimage.at(i)->width() > w)
   388 							rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
   389 					}
   390 				}		
   391 			}	
   392 		}	
   393 		h+=topPad+botPad;
   394 		w+=leftPad+rightPad;
   395 	}
   396 
   397 	// Frame thickness
   398     w+=frame->getPadding();
   399     h+=frame->getPadding();
   400 	
   401 	// Finally set size
   402     bbox.setSize (QSizeF (w,h));
   403 }
   404 
   405 void BranchObj::setDockPos()
   406 {
   407 	// Sets childpos and parpos depending on orientation
   408 	if (getOrientation()==LinkableMapObj::LeftOfCenter )
   409     {
   410 		childPos=QPointF (
   411 			ornamentsBBox.bottomLeft().x(), 
   412 			bottomlineY);
   413 		parPos=QPointF (
   414 			ornamentsBBox.bottomRight().x(),
   415 			bottomlineY);
   416     } else
   417     {
   418 		childPos=QPointF (
   419 			ornamentsBBox.bottomRight().x(), 
   420 			bottomlineY);
   421 		parPos=QPointF (
   422 			ornamentsBBox.bottomLeft().x(),
   423 			bottomlineY);
   424     }
   425 }
   426 
   427 void BranchObj::updateHeading()
   428 {
   429 	if (!treeItem)
   430 	{
   431 		qWarning ("BranchObj::udpateHeading treeItem==NULL");
   432 		return;
   433 	}
   434 	heading->setText (treeItem->getHeading() );
   435 	updateContentSize();
   436 }
   437 
   438 QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
   439 {
   440 	// Cloudy stuff can be hidden during exports
   441 	// FIXME-1 if (hidden) return "";
   442 
   443 	// Update of note is usually done while unselecting a branch
   444 	// if (isNoteInEditor) getNoteFromTextEditor();		//FIXME-2 moved to TreeItem
   445 	
   446     QString s,a;
   447 	QString scrolledAttr;
   448 	if ( ((BranchItem*)treeItem)->isScrolled() ) 
   449 		scrolledAttr=attribut ("scrolled","yes");
   450 	else
   451 		scrolledAttr="";
   452 
   453 	// save area, if not scrolled
   454 	QString areaAttr;
   455 	if (!((BranchItem*) (treeItem->parent()) )->isScrolled() )
   456 	{
   457 		areaAttr=
   458 			attribut("x1",QString().setNum(absPos.x()-offset.x())) +
   459 			attribut("y1",QString().setNum(absPos.y()-offset.y())) +
   460 			attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
   461 			attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
   462 
   463 	} else
   464 		areaAttr="";
   465 	
   466 	// Providing an ID for a branch makes export to XHTML easier
   467 	QString idAttr;
   468 	if (treeItem->xlinkCount()>0)
   469 		idAttr=attribut ("id",model->getSelectString(this)); //TODO directly access model
   470 	else
   471 		idAttr="";
   472 
   473     s=beginElement ("branch" 
   474 		+getOrnXMLAttr() 
   475 		+scrolledAttr 
   476 		+areaAttr 
   477 		+idAttr 
   478 		+getIncludeImageAttr() );
   479     incIndent();
   480 
   481 	// save heading
   482     s+=valueElement("heading", treeItem->getHeading(),
   483 		attribut ("textColor",QColor(heading->getColor()).name()));
   484 
   485 	// Save frame
   486 	if (frame->getFrameType()!=FrameObj::NoFrame) 
   487 		s+=frame->saveToDir ();
   488 
   489 	// save names of flags set
   490 	s+=standardFlags->saveToDir(tmpdir,prefix,0);
   491 	
   492 	// Save FloatImages
   493 	for (int i=0; i<floatimage.size(); ++i)
   494 		s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
   495 
   496 	// save note
   497 	if (!treeItem->getNoteObj().isEmpty() )
   498 		s+=treeItem->getNoteObj().saveToDir();
   499 	
   500 	// Save branches
   501 	for (int i=0; i<treeItem->branchCount(); ++i)
   502 		s+=treeItem->getBranchObjNum(i)->saveToDir(tmpdir,prefix,offset);
   503 
   504 	// Save XLinks
   505 	QString ol;	// old link
   506 	QString cl;	// current link
   507 	for (int i=0; i<xlink.size(); ++i)
   508 	{
   509 		cl=xlink.at(i)->saveToDir();
   510 		if (cl!=ol)
   511 		{
   512 			s+=cl;
   513 			ol=cl;
   514 		} else
   515 		{
   516 			qWarning (QString("Ignoring of duplicate xLink in %1").arg(treeItem->getHeading()));
   517 		}
   518 	}	
   519 
   520     decIndent();
   521     s+=endElement   ("branch");
   522     return s;
   523 }
   524 
   525 void BranchObj::addXLink (XLinkObj *xlo)
   526 {
   527 	xlink.append (xlo);
   528 	
   529 }
   530 
   531 void BranchObj::removeXLinkRef (XLinkObj *xlo)
   532 {
   533 	xlink.removeAt (xlink.indexOf(xlo));
   534 }
   535 
   536 void BranchObj::deleteXLink(XLinkObj *xlo)
   537 {
   538 	xlo->deactivate();
   539 	if (!xlo->isUsed()) delete (xlo);
   540 }
   541 
   542 void BranchObj::deleteXLinkAt (int i)
   543 {
   544 	XLinkObj *xlo=xlink.at(i);
   545 	xlo->deactivate();
   546 	if (!xlo->isUsed()) delete(xlo);
   547 }
   548 
   549 XLinkObj* BranchObj::XLinkAt (int i)
   550 {
   551 	return xlink.at(i);
   552 }
   553 
   554 BranchObj* BranchObj::XLinkTargetAt (int i)
   555 {
   556 	if (i>=0 && i<xlink.size())
   557 	{
   558 		if (xlink.at(i))
   559 			return xlink.at(i)->otherBranch (this);
   560 	}
   561 	return NULL;
   562 }
   563 
   564 void BranchObj::setIncludeImagesVer(bool b)
   565 {
   566 	includeImagesVer=b;
   567 	calcBBoxSize();
   568 	positionBBox();
   569 	requestReposition();
   570 }
   571 
   572 bool BranchObj::getIncludeImagesVer()
   573 {
   574 	return includeImagesVer;
   575 }
   576 
   577 void BranchObj::setIncludeImagesHor(bool b)
   578 {
   579 	includeImagesHor=b;
   580 	calcBBoxSize();
   581 	positionBBox();
   582 	requestReposition();
   583 }
   584 
   585 bool BranchObj::getIncludeImagesHor()
   586 {
   587 	return includeImagesHor;
   588 }
   589 
   590 QString BranchObj::getIncludeImageAttr()
   591 {
   592 	QString a;
   593 	if (includeImagesVer)
   594 		a=attribut ("incImgV","true");
   595 	else
   596 		a=attribut ("incImgV","false");
   597 	if (includeImagesHor)
   598 		a+=attribut ("incImgH","true");
   599 	else
   600 		a+=attribut ("incImgH","false");
   601 	return a;	
   602 }
   603 
   604 FloatImageObj* BranchObj::addFloatImage ()
   605 {
   606 	FloatImageObj *newfi=new FloatImageObj (scene,this);
   607 	floatimage.append (newfi);
   608 	if ( ((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
   609 		newfi->setVisibility (false);
   610 	else	
   611 		newfi->setVisibility(visible);
   612 		/*
   613 	calcBBoxSize();
   614 	positionBBox();
   615 	*/
   616 	requestReposition();
   617 	return newfi;
   618 }
   619 
   620 FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
   621 {
   622 	FloatImageObj *newfi=new FloatImageObj (scene,this);
   623 	floatimage.append (newfi);
   624 	newfi->copy (fio);
   625 	if (((BranchItem*)treeItem)->hasScrolledParent((BranchItem*)treeItem) )
   626 		newfi->setVisibility (false);
   627 	else	
   628 		newfi->setVisibility(visible);
   629 		/*
   630 	calcBBoxSize();
   631 	positionBBox();
   632 	*/
   633 	requestReposition();
   634 	return newfi;
   635 }
   636 
   637 FloatImageObj* BranchObj::getFirstFloatImage ()
   638 {
   639     return floatimage.first();
   640 }
   641 
   642 FloatImageObj* BranchObj::getLastFloatImage ()
   643 {
   644     return floatimage.last();
   645 }
   646 
   647 FloatImageObj* BranchObj::getFloatImageNum (const uint &i)
   648 {
   649     return floatimage.at(i);
   650 }
   651 
   652 void BranchObj::removeFloatImage (FloatImageObj *fio)
   653 {
   654 	int i=floatimage.indexOf (fio);
   655 	if (i>-1) delete (floatimage.takeAt (i));
   656 	calcBBoxSize();
   657 	positionBBox();
   658 	requestReposition();
   659 }
   660 
   661 void BranchObj::savePosInAngle ()
   662 {
   663 	// Save position in angle
   664 	for (int i=0; i<treeItem->branchCount(); ++i)
   665 		treeItem->getBranchObjNum(i)->angle=i;
   666 }
   667 
   668 void BranchObj::setDefAttr (BranchModification mod)
   669 {
   670 	int fontsize;
   671 	switch (treeItem->depth())
   672 	{
   673 		case 0: fontsize=16; break;
   674 		case 1: fontsize=12; break;
   675 		default: fontsize=10; break;
   676 	}	
   677 
   678 	setLinkColor ();
   679 	setLinkStyle(getDefLinkStyle());
   680 	QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
   681 	font.setPointSize(fontsize);
   682 	heading->setFont(font );
   683 
   684 	if (mod==NewBranch)
   685 		setColor (((BranchObj*)(parObj))->getColor());
   686 	
   687 	calcBBoxSize();
   688 }
   689 
   690 BranchObj* BranchObj::addBranch()	// FIXME-3 still needed?
   691 {
   692     BranchObj* newbo=new BranchObj(scene,this);
   693     newbo->setParObj(this);
   694 	newbo->setDefAttr(NewBranch);
   695 	/* FIXME-2 treeItem not set yet!!!
   696 	if ( ((BranchItem*)treeItem)->isScrolled() )
   697 		newbo->setVisibility (false);
   698 	else	
   699 		newbo->setVisibility(visible);
   700 	*/	
   701 	newbo->updateLink();	
   702 	requestReposition();
   703 	return newbo;
   704 }
   705 
   706 BranchObj* BranchObj::addBranch(BranchObj* bo)
   707 {
   708     BranchObj* newbo=new BranchObj(scene,this);
   709     //FIXME-1 branch.append (newbo);
   710     newbo->copy(bo);
   711     newbo->setParObj(this);
   712 	newbo->setDefAttr(MovedBranch);
   713 	if ( ((BranchItem*)treeItem)->isScrolled() )
   714 		newbo->setVisibility (false);
   715 	else	
   716 		newbo->setVisibility(bo->visible);
   717 	newbo->updateLink();	
   718 	requestReposition();
   719 	return newbo;
   720 }
   721 
   722 BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
   723 {
   724 	//FIXME-1 branch.append (bo);
   725 	bo->setParObj (this);
   726 	//FIXME-2 bo->depth=depth+1;
   727 	bo->setDefAttr(MovedBranch);
   728 	BranchItem *bi=(BranchItem*)treeItem;
   729 	if ( bi->isScrolled() ) bi->tmpUnscroll();
   730 	//setLastSelectedBranch (bo);	//FIXME-3 needed?
   731 	return bo;
   732 }
   733 
   734 BranchObj* BranchObj::insertBranch(int pos)
   735 {
   736 	savePosInAngle();
   737 	// Add new bo and resort branches
   738 	BranchObj *newbo=addBranch ();
   739 	newbo->angle=pos-0.5;
   740 	//FIXME-1 qSort (branch.begin(),branch.end(), isAbove);
   741 	return newbo;
   742 }
   743 
   744 BranchObj* BranchObj::insertBranch(BranchObj* bo, int pos)
   745 {
   746 	savePosInAngle();
   747 	// Add new bo and resort branches
   748 	bo->angle=pos-0.5;
   749 	BranchObj *newbo=addBranch (bo);
   750 	//FIXME-1 qSort (branch.begin(),branch.end(), isAbove);
   751 	return newbo;
   752 }
   753 
   754 BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
   755 {
   756 	savePosInAngle();
   757 	// Add new bo and resort branches
   758 	bo->angle=pos-0.5;
   759 	//FIXME-4 branch.append (bo);
   760 	bo->setParObj (this);
   761 	//FIXME-2 bo->depth=depth+1;
   762 	bo->setDefAttr (MovedBranch);
   763 	BranchItem *bi=(BranchItem*)treeItem;
   764 	if ( bi->isScrolled() ) bi->tmpUnscroll();
   765 	//setLastSelectedBranch (bo); //FIXME-3 needed?
   766 	//FIXME-2 qSort (branch.begin(),branch.end(), isAbove);
   767 	return bo;
   768 }
   769 
   770 void BranchObj::removeBranchHere(BranchObj* borem)	// FIXME-1 getNum no longer available
   771 {
   772 /*
   773 	// This removes the branch bo from list, but 
   774 	// inserts its children at the place of bo
   775 	BranchObj *bo;
   776 	bo=borem->getLastBranch();
   777 	int pos=borem->getNum();
   778 	while (bo)
   779 	{
   780 		bo->linkTo (this,pos+1);
   781 		bo=borem->getLastBranch();
   782 	}	
   783 	removeBranch (borem);
   784 	*/
   785 }
   786 
   787 void BranchObj::removeChildren()	// FIXME-3 not needed here
   788 {
   789 	clear();
   790 }
   791 
   792 void BranchObj::removeBranch(BranchObj* bo)	// FIXME-1 not needed here
   793 {
   794 /*
   795     // if bo is not in branch remove returns false, we
   796     // don't care...
   797 	
   798 	int i=branch.indexOf(bo);
   799     if (i>=0)
   800 	{
   801 		delete (bo);
   802 		branch.removeAt (i);
   803 	} else
   804 		qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
   805 	requestReposition();
   806 	*/
   807 }
   808 
   809 void BranchObj::removeBranchPtr(BranchObj* bo)	// FIXME-1 not needed here
   810 {
   811 /*
   812 	int i=branch.indexOf(bo);
   813 	
   814 	if (i>=0)
   815 		branch.removeAt (i);
   816 	else	
   817 		qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
   818 	requestReposition();
   819 */	
   820 }
   821 
   822 bool BranchObj::canMoveBranchUp() 
   823 {
   824 	/* FIXME-1 move to BranchItem
   825 	if (!parObj || depth==1) return false;
   826 	BranchObj* par=(BranchObj*)parObj;
   827 	if (this==par->getTreeItem()->getFirstBranch())
   828 		return false;
   829 	else
   830 		return true;
   831 		*/
   832 return false;
   833 }
   834 
   835 BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // FIXME-1
   836 {
   837 /*
   838 	savePosInAngle();
   839     int i=branch.indexOf(bo1);
   840     if (i>0) 
   841 	{	// -1 if bo1 not found 
   842 		treeItem->getBranchObjNum(i)->angle--;
   843 		treeItem->getBranchObjNum(i-1)->angle++;
   844 		qSort (branch.begin(),branch.end(), isAbove);
   845 		return treeItem->getBranchObjNum(i);
   846 	} else
   847 */	
   848 		return NULL;
   849 }
   850 
   851 bool BranchObj::canMoveBranchDown() 
   852 {
   853 	/* FIXME-1 move to BranchItem
   854 	if (!parObj|| depth==1) return false;
   855 	BranchObj* par=(BranchObj*)parObj;
   856 	if (this==par->getTreeItem()->getLastBranch())
   857 		return false;
   858 	else
   859 		return true;
   860 	*/
   861 return false;	
   862 }
   863 
   864 BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// FIXME-1
   865 {
   866 /*
   867 	savePosInAngle();
   868     int i=branch.indexOf(bo1);
   869 	int j;
   870 	if (i <treeItem->branchCount())
   871 	{
   872 		j = i+1;
   873 		treeItem->getBranchObjNum(i)->angle++;
   874 		treeItem->getBranchObjNum(j)->angle--;
   875 		qSort (branch.begin(),branch.end(), isAbove);
   876 		return treeItem->getBranchObjNum(i);
   877 	} else
   878 */	
   879 		return NULL;
   880 }
   881 
   882 void BranchObj::sortChildren() //FIXME-1  
   883 {
   884 /*
   885 	int childCount=branch.count(); 
   886 	int curChildIndex;
   887 	bool madeChanges=false;
   888 	do
   889 	{
   890 		madeChanges=false;
   891 		for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
   892 			BranchObj* curChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex);
   893 			BranchObj* prevChild=(BranchObj*)treeItem->getBranchObjNum(curChildIndex-1);
   894 			if(prevChild->heading->text().compare(curChild->heading->text())>0)
   895 			{
   896 				this->moveBranchUp(curChild);
   897 				madeChanges=true;
   898 			}
   899 		}
   900 	}while(madeChanges);
   901 */
   902 }
   903 
   904 
   905 BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
   906 {
   907 	// Find current parent and 
   908 	// remove pointer to myself there
   909 	if (!dst) return NULL;
   910 	BranchObj *par=(BranchObj*)parObj;
   911 	if (par)
   912 		par->removeBranchPtr (this);
   913 	else
   914 		return NULL;
   915 
   916 /* FIXME-1
   917 	// Create new pointer to myself at dst
   918 	if (pos<0||dst->getDepth()==0)
   919 	{	
   920 		// links myself as last branch at dst
   921 		dst->addBranchPtr (this);
   922 		updateLink();
   923 		return this;
   924 	} else
   925 	{
   926 		// inserts me at pos in parent of dst
   927 		if (par)
   928 		{
   929 			BranchObj *bo=dst->insertBranchPtr (this,pos);
   930 			bo->setDefAttr(MovedBranch);
   931 			updateLink();
   932 			return bo;
   933 
   934 		} else
   935 			return NULL;
   936 	}	
   937 */	
   938 }
   939 
   940 void BranchObj::alignRelativeTo (QPointF ref,bool alignSelf)
   941 {
   942 	qreal th = bboxTotal.height();	
   943 	int depth=treeItem->depth();
   944 // TODO testing
   945 /*
   946 
   947 	QString h=QString (depth,' ');
   948 	h+=treeItem->getHeading();
   949 	h+=QString (15,' ');
   950 	h.truncate (15);
   951 	QPointF pp; if (parObj) pp=parObj->getChildPos();
   952 	cout << "BO::alignRelTo ";
   953 	cout<<h.toStdString();
   954 	cout << "    d="<<depth<<
   955 //cout<<  "  ref="<<ref<<
   956       	"  bbox.tL="<<bboxTotal.topLeft()<<
   957 		"  absPos="<<absPos<<
   958 //		"  relPos="<<relPos<<
   959 //		"  parPos="<<pp<<
   960 		"  w="<<bbox.width()<<
   961 		"  h="<<bbox.height()<<
   962 //		"  orient="<<orientation<<
   963 //		"  alignSelf="<<alignSelf<<
   964 //		"  scrolled="<<((BranchItem*)treeItem)->isScrolled()<<
   965 //		"  pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
   966 //		"  hidden="<<hidden<<
   967 		"  th="<<th<<
   968 		endl;
   969 */
   970 
   971 	setOrientation();
   972 	//updateLink();
   973 
   974 	if (depth==1 && parObj)
   975 	{
   976 		// Position relatively, if needed
   977 		//if (useRelPos) move2RelPos (relPos.x(), relPos.y());
   978 
   979 		// Calc angle to mapCenter if I am a mainbranch
   980 		// needed for reordering the mainbranches clockwise 
   981 		// around mapcenter 
   982 		angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ), 
   983 								(int)(y() - parObj->getChildPos().y() ) ) );
   984 	}							
   985 	if (depth>1)
   986     {
   987 		// Align myself depending on orientation and parent, but
   988 		// only if I am not a mainbranch or mapcenter itself
   989 
   990 		if (anim.isAnimated())
   991 		{
   992 			move2RelPos(anim);
   993 		} else
   994 		{
   995 			LinkableMapObj::Orientation o;
   996 			o=parObj->getOrientation();
   997 			if (alignSelf)
   998 				switch (orientation) 
   999 				{
  1000 					case LinkableMapObj::LeftOfCenter:
  1001 						move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
  1002 						//move (ref.x() , ref.y() + (th-bbox.height())/2 );
  1003 					break;
  1004 					case LinkableMapObj::RightOfCenter:	
  1005 						move (ref.x() , ref.y() + (th-bbox.height())/2  );
  1006 					break;
  1007 					default:
  1008 						qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
  1009 					break;
  1010 			}
  1011 		}
  1012     }		
  1013 
  1014 	if ( ((BranchItem*)treeItem)->isScrolled() ) return;
  1015 
  1016     // Set reference point for alignment of children
  1017     QPointF ref2;
  1018     if (orientation==LinkableMapObj::LeftOfCenter)
  1019 		ref2.setX(bbox.topLeft().x() - linkwidth);
  1020     else	
  1021 		ref2.setX(bbox.topRight().x() + linkwidth);
  1022 
  1023 	if (depth==1)
  1024 		ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
  1025 	else	
  1026 		ref2.setY(ref.y() );	
  1027 
  1028     // Align the children depending on reference point 
  1029 	for (int i=0; i<treeItem->branchCount(); ++i)
  1030     {	
  1031 		if (!treeItem->getBranchNum(i)->isHidden())
  1032 		{
  1033 			treeItem->getBranchObjNum(i)->alignRelativeTo (ref2,true);
  1034 
  1035 			// append next branch below current one
  1036 			ref2.setY(ref2.y() + treeItem->getBranchObjNum(i)->getBBoxSizeWithChildren().height() );
  1037 		}
  1038     }
  1039 }
  1040 
  1041 
  1042 void BranchObj::reposition()
  1043 {	
  1044 /* TODO testing only
  1045 	if (!treeItem->getHeading().isEmpty())
  1046 		cout << "BO::reposition  "<<qPrintable(treeItem->getHeading())<<endl;
  1047 	else	
  1048 		cout << "BO::reposition  ???"<<endl;
  1049 //	cout << "  orient="<<orientation<<endl;
  1050 */		
  1051 
  1052 	if (treeItem->depth()==0)
  1053 	{
  1054 		// only calculate the sizes once. If the deepest LMO 
  1055 		// changes its height,
  1056 		// all upper LMOs have to change, too.
  1057 		calcBBoxSizeWithChildren();
  1058 		updateLink();	// This update is needed if the scene is resized 
  1059 						// due to excessive moving of a FIO
  1060 
  1061 	    alignRelativeTo ( QPointF (absPos.x(),
  1062 			absPos.y()-(bboxTotal.height()-bbox.height())/2) );
  1063 		//FIXME-2 qSort (branch.begin(),branch.end(), isAbove);
  1064 		positionBBox();	// Reposition bbox and contents
  1065 	} else
  1066 	{
  1067 		// This is only important for moving branches:
  1068 		// For editing a branch it isn't called...
  1069 	    alignRelativeTo ( QPointF (absPos.x(),
  1070 							absPos.y()-(bboxTotal.height()-bbox.height())/2) );
  1071 	}
  1072 }
  1073 
  1074 void BranchObj::unsetAllRepositionRequests()
  1075 {
  1076 	repositionRequest=false;
  1077 	for (int i=0; i<treeItem->branchCount(); ++i)
  1078 		treeItem->getBranchObjNum(i)->unsetAllRepositionRequests();
  1079 }
  1080 
  1081 
  1082 QPolygonF BranchObj::shape()
  1083 {
  1084 	QPolygonF p;
  1085 
  1086 	QRectF r=getTotalBBox();
  1087 	if (orientation==LinkableMapObj::LeftOfCenter)
  1088 		p   <<r.bottomLeft()
  1089 			<<r.topLeft()
  1090 			<<QPointF (bbox.topLeft().x(), r.topLeft().y() )
  1091 			<<bbox.topRight()
  1092 			<<bbox.bottomRight()
  1093 			<<QPointF (bbox.bottomLeft().x(), r.bottomLeft().y() ) ;
  1094 	else		
  1095 		p   <<r.bottomRight()
  1096 			<<r.topRight()
  1097 			<<QPointF (bbox.topRight().x(), r.topRight().y() )
  1098 			<<bbox.topLeft()
  1099 			<<bbox.bottomLeft()
  1100 			<<QPointF (bbox.bottomRight().x(), r.bottomRight().y() ) ;
  1101 	return p;
  1102 }
  1103 
  1104 QRectF BranchObj::getTotalBBox()
  1105 {
  1106 	QRectF r=bbox;
  1107 
  1108 	if ( ((BranchItem*)treeItem)->isScrolled() ) return r;
  1109 
  1110 	for (int i=0; i<treeItem->branchCount(); ++i)
  1111 		if (!treeItem->getBranchNum(i)->isHidden())
  1112 			r=addBBox(treeItem->getBranchObjNum(i)->getTotalBBox(),r);
  1113 
  1114 /* FIXME-3 lots of occurences of treeItem->getBranchObjNum(i) in branchobj.cpp
  1115             better check if they are not NULL and maybe simplify...
  1116 			(have been NULL at least in calcBBoxSizeWithChilds...)
  1117 */			
  1118 
  1119 /*
  1120 	FIXME-1 for (int i=0; i<floatimage.size(); ++i)
  1121 		if (!floatimage.at(i)->isHidden())
  1122 			r=addBBox(floatimage.at(i)->getTotalBBox(),r);
  1123 	*/	
  1124 	return r;
  1125 }
  1126 
  1127 QRectF BranchObj::getBBoxSizeWithChildren()
  1128 {
  1129 	return bboxTotal;
  1130 }
  1131 
  1132 void BranchObj::calcBBoxSizeWithChildren()
  1133 {	
  1134 	// This is initially called only from reposition and
  1135 	// and only for mapcenter. So it won't be
  1136 	// called more than once for a single user 
  1137 	// action
  1138 	
  1139 
  1140 	// Calculate size of LMO including all children (to align them later)
  1141 	bboxTotal.setX(bbox.x() );
  1142 	bboxTotal.setY(bbox.y() );
  1143 
  1144 	// if branch is scrolled, ignore children, but still consider floatimages
  1145 	BranchItem *bi=(BranchItem*)treeItem;
  1146 	if ( bi->isScrolled() ) 
  1147 	{
  1148 		bboxTotal.setWidth (bbox.width());
  1149 		bboxTotal.setHeight(bbox.height());
  1150 		return;
  1151 	}
  1152 	
  1153 	if (bi->isHidden())
  1154 	{
  1155 		bboxTotal.setWidth (0);
  1156 		bboxTotal.setHeight(0);
  1157 		if (parObj)
  1158 		{
  1159 			bboxTotal.setX (parObj->x());
  1160 			bboxTotal.setY (parObj->y());
  1161 		} else
  1162 		{
  1163 			bboxTotal.setX (bbox.x());
  1164 			bboxTotal.setY (bbox.y());
  1165 		}
  1166 		return;
  1167 	}
  1168 	
  1169 	QRectF r(0,0,0,0);
  1170 	QRectF br;
  1171 	// Now calculate recursivly
  1172 	// sum of heights 
  1173 	// maximum of widths 
  1174 	// minimum of y
  1175 	for (int i=0; i<treeItem->branchCount(); i++)
  1176 	{
  1177 		if (!bi->getBranchNum(i)->isHidden())
  1178 		{
  1179 			bi->getBranchObjNum(i)->calcBBoxSizeWithChildren();
  1180 			br=bi->getBranchObjNum(i)->getBBoxSizeWithChildren();
  1181 			r.setWidth( max (br.width(), r.width() ));
  1182 			r.setHeight(br.height() + r.height() );
  1183 			if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
  1184 		}
  1185 	}
  1186 	// Add myself and also
  1187 	// add width of link to sum if necessary
  1188 	if (bi->branchCount()<1)
  1189 		bboxTotal.setWidth (bbox.width() + r.width() );
  1190 	else	
  1191 		bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
  1192 	
  1193 	bboxTotal.setHeight(max (r.height(),  bbox.height()));
  1194 }
  1195 
  1196 /*
  1197 void BranchObj::select()	// FIXME-4 try to get rid of this in BO completely
  1198 {
  1199 	cout << "BO::select()\n";
  1200 	textEditor->setText(treeItem->getNoteObj().getNote() );
  1201 	QString fnh=treeItem->getNoteObj().getFilenameHint();
  1202 	if (fnh!="")
  1203 		textEditor->setFilenameHint(treeItem->getNoteObj().getFilenameHint() );
  1204 	else	
  1205 		textEditor->setFilenameHint(getHeading() );
  1206 	textEditor->setFontHint (treeItem->getNoteObj().getFontHint() );
  1207 	//isNoteInEditor=true;
  1208 
  1209 	// set selected and visible
  1210     LinkableMapObj::select();
  1211 
  1212     //if (po)	po->setLastSelectedBranch(this);  needed?
  1213 		
  1214 	// temporary unscroll, if we have scrolled parents somewhere
  1215 	if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
  1216 
  1217 	//moved to vymmodel or vymview...
  1218 	// Show URL and link in statusbar
  1219 	QString status;
  1220 	if (!url.isEmpty()) status+="URL: "+url+"  ";
  1221 	if (!vymLink.isEmpty()) status+="Link: "+vymLink;
  1222 	if (!status.isEmpty()) mainWindow->statusMessage (status);
  1223 
  1224 	// Update Toolbar
  1225 	updateFlagsToolbar();
  1226 
  1227 	// Update actions
  1228 	model->updateActions();
  1229 }
  1230 	*/
  1231 
  1232 /*
  1233 void BranchObj::unselect()	//FIXME-4 should not be needed
  1234 {
  1235 	cout << "BO::unselect()\n";
  1236 	LinkableMapObj::unselect();
  1237 	// Delete any messages like vymLink in StatusBar
  1238 	mainWindow->statusMessage ("");		//this causes segfault, when MainWindow is already gone in global destructor on quitting vym
  1239 
  1240 	// Save current note
  1241 	if (isNoteInEditor) getNoteFromTextEditor();
  1242 	isNoteInEditor=false;
  1243 
  1244 	// reset temporary unscroll, if we have scrolled parents somewhere
  1245 	if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
  1246 
  1247 	// Erase content of editor 
  1248 	textEditor->setInactive();
  1249 
  1250 	// unselect all buttons in toolbar
  1251 	standardFlagsDefault->updateToolbar();
  1252 }
  1253 */	
  1254 
  1255 QString BranchObj::getSelectString()
  1256 {
  1257 	return model->getSelectString (this);
  1258 }
  1259 
  1260 void BranchObj::setAnimation(const AnimPoint &ap)
  1261 {
  1262 	anim=ap;
  1263 }
  1264 
  1265 bool BranchObj::animate()
  1266 {
  1267 	anim.animate ();
  1268 	if ( anim.isAnimated() )
  1269 	{
  1270 		setRelPos (anim);
  1271 		return true;
  1272 	}
  1273 	parObj->reposition();	// we might have been relinked meanwhile
  1274 	return false;
  1275 }
  1276