branchobj.cpp
branchrelease-1-12-maintained
changeset 40 394b2f297e1d
parent 0 7a96bd401351
child 41 6f28020b33d1
     1.1 --- a/branchobj.cpp	Thu Jul 17 09:27:20 2008 +0000
     1.2 +++ b/branchobj.cpp	Thu Jul 17 11:11:55 2008 +0000
     1.3 @@ -1,12 +1,16 @@
     1.4  #include "branchobj.h"
     1.5 -#include "texteditor.h"
     1.6 +
     1.7 +// #include "texteditor.h"
     1.8 +#include "geometry.h"
     1.9  #include "mapeditor.h"
    1.10  #include "mainwindow.h"
    1.11 +#include "misc.h"
    1.12 +
    1.13 +class TextEditor;
    1.14  
    1.15  extern TextEditor *textEditor;
    1.16  extern Main *mainWindow;
    1.17  extern FlagRowObj *standardFlagsDefault;
    1.18 -extern QAction *actionEditOpenURL;
    1.19  
    1.20  
    1.21  /////////////////////////////////////////////////////////////////
    1.22 @@ -14,6 +18,7 @@
    1.23  /////////////////////////////////////////////////////////////////
    1.24  
    1.25  BranchObj* BranchObj::itLast=NULL;
    1.26 +BranchObj* BranchObj::itFirst=NULL;
    1.27  
    1.28  
    1.29  BranchObj::BranchObj () :OrnamentedObj()
    1.30 @@ -24,39 +29,50 @@
    1.31      depth=-1;
    1.32  }
    1.33  
    1.34 -BranchObj::BranchObj (QCanvas* c):OrnamentedObj (c)
    1.35 +BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s)
    1.36  {
    1.37 -//    cout << "Const BranchObj (c)  called from MapCenterObj (c)\n";
    1.38 -    canvas=c;
    1.39 +//    cout << "Const BranchObj (s)  called from MapCenterObj (s)\n";
    1.40 +	parObj=NULL;
    1.41 +    scene=s;
    1.42  }
    1.43  
    1.44 -BranchObj::BranchObj (QCanvas* c, LinkableMapObj* p):OrnamentedObj (c)
    1.45 +BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)
    1.46  {
    1.47 -//    cout << "Const BranchObj (c,p)\n";
    1.48 -    canvas=c;
    1.49 +//    cout << "Const BranchObj (s,p)\n";
    1.50 +    scene=s;
    1.51      setParObj (p);	
    1.52      depth=p->getDepth()+1;
    1.53  	if (depth==1)
    1.54  		// Calc angle to mapCenter if I am a mainbranch
    1.55  		// needed for reordering the mainbranches clockwise 
    1.56  		// around mapcenter 
    1.57 -		angle=getAngle (QPoint ((int)(x() - parObj->getChildPos().x() ), 
    1.58 -								(int)(y() - parObj->getChildPos().y() ) ) );
    1.59 +		angle=getAngle (QPointF (x() - parObj->getChildPos().x() , 
    1.60 +								(y() - parObj->getChildPos().y() ) ) );
    1.61      init();
    1.62  }
    1.63  
    1.64  BranchObj::~BranchObj ()
    1.65  {
    1.66 -    //cout << "Destr BranchObj\n";
    1.67 +	// If I'm animated, I need to un-animate myself first
    1.68 +	if (anim.isAnimated() )
    1.69 +	{
    1.70 +		anim.setAnimated (false);
    1.71 +		mapEditor->getModel()->stopAnimation (this);
    1.72 +	}
    1.73 +
    1.74 +
    1.75 +	//cout << "Destr BranchObj of "<<this<<endl;
    1.76  	// Check, if this branch was the last child to be deleted
    1.77  	// If so, unset the scrolled flags
    1.78  
    1.79 -	BranchObj *po=(BranchObj*)(parObj);
    1.80 +	BranchObj *po=(BranchObj*)parObj;
    1.81 +	BranchObj *bo;
    1.82  	if (po)
    1.83  	{
    1.84 -		BranchObj *bo=((BranchObj*)(parObj))->getLastBranch();
    1.85 -		if (!bo) po->unScroll();
    1.86 +		bo=((BranchObj*)parObj)->getLastBranch();
    1.87 +		if (bo) po->unScroll();
    1.88  	}
    1.89 +	clear();
    1.90  }
    1.91  
    1.92  bool BranchObj::operator< ( const BranchObj & other )
    1.93 @@ -69,40 +85,23 @@
    1.94      return angle == other.angle;
    1.95  }
    1.96  
    1.97 -int BranchObjPtrList::compareItems ( QPtrCollection::Item i, QPtrCollection::Item j)
    1.98 -{
    1.99 -	// Make sure PtrList::find works
   1.100 -	if (i==j) return 0;
   1.101 -
   1.102 -	if ( ((BranchObj*)(i))->angle > ((BranchObj*)(j))->angle )
   1.103 -		return 1;
   1.104 -	else
   1.105 -		return -1;
   1.106 -}
   1.107 -
   1.108  void BranchObj::init () 
   1.109  {
   1.110 -    branch.setAutoDelete (true);
   1.111 -    floatimage.setAutoDelete (true);
   1.112 +	if (parObj)
   1.113 +	{
   1.114 +		absPos=getRandPos();
   1.115 +		absPos+=parObj->getChildPos();
   1.116 +	}
   1.117  
   1.118 -	absPos=getRandPos();
   1.119 -	absPos+=parObj->getChildPos();
   1.120 -
   1.121 -    // TODO This should be done in TextObj later
   1.122 -    QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
   1.123 -//    font.setPointSize(12);
   1.124 -   heading->setFont(font );
   1.125 -//    heading->setText(QObject::tr("new branch"));
   1.126 -
   1.127 -    lastSelectedBranch=-1;
   1.128 +    lastSelectedBranch=0;
   1.129  
   1.130      setChildObj(this);
   1.131  
   1.132  	scrolled=false;
   1.133  	tmpUnscrolled=false;
   1.134  
   1.135 -	url="";
   1.136 -	vymLink="";
   1.137 +	includeImagesVer=false;
   1.138 +	includeImagesHor=false;
   1.139  }
   1.140  
   1.141  void BranchObj::copy (BranchObj* other)
   1.142 @@ -110,24 +109,18 @@
   1.143      OrnamentedObj::copy(other);
   1.144  
   1.145  	branch.clear();
   1.146 -    BranchObj* b;
   1.147 -    for (b=other->branch.first(); b;b=other->branch.next() ) 
   1.148 +	for (int i=0; i<other->branch.size(); ++i)
   1.149  		// Make deep copy of b
   1.150  		// Because addBranch again calls copy for the childs,
   1.151  		// Those will get a deep copy, too
   1.152 -		addBranch(b);	
   1.153 +		addBranch(other->branch.at(i) );	
   1.154  
   1.155 -	FloatImageObj *fi;
   1.156 -	for (fi=other->floatimage.first(); fi;fi=other->floatimage.next() )
   1.157 -		addFloatImage (fi);
   1.158 -
   1.159 +	for (int i=0; i<other->floatimage.size(); ++i)
   1.160 +		addFloatImage  (other->floatimage.at(i));
   1.161  	scrolled=other->scrolled;
   1.162  	tmpUnscrolled=other->tmpUnscrolled;
   1.163  	setVisibility (other->visible);
   1.164  
   1.165 -	url=other->url;
   1.166 -	vymLink=other->vymLink;
   1.167 -
   1.168  	angle=other->angle;
   1.169  
   1.170      positionBBox();
   1.171 @@ -135,26 +128,42 @@
   1.172  
   1.173  void BranchObj::clear() 
   1.174  {
   1.175 -	branch.clear();
   1.176 -	floatimage.clear();
   1.177 +	setVisibility (true);
   1.178 +
   1.179 +	while (!floatimage.isEmpty())
   1.180 +		delete floatimage.takeFirst();
   1.181 +
   1.182 +	while (!xlink.isEmpty())
   1.183 +		delete xlink.takeFirst();
   1.184 +
   1.185 +	while (!branch.isEmpty())
   1.186 +		delete branch.takeFirst();
   1.187 +}
   1.188 +
   1.189 +bool isAbove (BranchObj* a, BranchObj *b)
   1.190 +{
   1.191 +	if (a->angle < b->angle)
   1.192 +		return true;
   1.193 +	else	
   1.194 +		return false;
   1.195  }
   1.196  
   1.197  int BranchObj::getNum()
   1.198  {
   1.199  	if (parObj)
   1.200 -		return ((BranchObj*)(parObj))->getNum ((BranchObj*)(this));
   1.201 +		return ((BranchObj*)parObj)->getNum (this);
   1.202  	else
   1.203  		return 0;
   1.204  }
   1.205  
   1.206  int BranchObj::getNum(BranchObj *bo)
   1.207  {
   1.208 -	return branch.findRef (bo);
   1.209 +	return branch.indexOf (bo);
   1.210  }
   1.211  
   1.212  int BranchObj::getFloatImageNum(FloatImageObj *fio)
   1.213  {
   1.214 -	return floatimage.findRef (fio);
   1.215 +	return floatimage.indexOf(fio);
   1.216  }
   1.217  
   1.218  int BranchObj::countBranches()
   1.219 @@ -167,7 +176,12 @@
   1.220  	return floatimage.count();
   1.221  }
   1.222  
   1.223 -void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPoint m, int off)
   1.224 +int BranchObj::countXLinks()
   1.225 +{
   1.226 +	return xlink.count();
   1.227 +}
   1.228 +
   1.229 +void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
   1.230  {
   1.231  	// Temporary link to lmo
   1.232  	// m is position of mouse pointer 
   1.233 @@ -181,19 +195,10 @@
   1.234  	// ignore mapcenter and mainbranch
   1.235  	if (lmo->getDepth()<2) off=0;
   1.236  	if (off==0)
   1.237 -	{
   1.238  		link2ParPos=false;
   1.239 -		parObj=o;
   1.240 -	}	
   1.241  	else
   1.242 -	{	
   1.243  		link2ParPos=true;
   1.244 -		if (off>0)
   1.245 -			parObj=o->getParObj();
   1.246 -		else	
   1.247 -			parObj=o->getParObj();
   1.248 -		parObj=o;
   1.249 -	}		
   1.250 +	parObj=o;
   1.251  
   1.252  	depth=parObj->getDepth()+1;
   1.253  
   1.254 @@ -207,17 +212,17 @@
   1.255  	if (depth==1)
   1.256  	{	// new parent is the mapcenter itself
   1.257  
   1.258 -		QPoint p= normalise ( QPoint (m.x() - o->getChildPos().x(),
   1.259 +		QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
   1.260  									  m.y() - o->getChildPos().y() ));
   1.261  		if (p.x()<0) p.setX( p.x()-bbox.width() );
   1.262  		move2RelPos (p);
   1.263  	} else
   1.264  	{	
   1.265 -		int y;
   1.266 +		qreal y;
   1.267  		if (off==0)
   1.268  		{
   1.269  			// new parent is just a branch, link to it
   1.270 -			QRect t=o->getBBoxSizeWithChilds();
   1.271 +			QRectF t=o->getBBoxSizeWithChilds();
   1.272  			if (o->getLastBranch())
   1.273  				y=t.y() + t.height() ;
   1.274  			else
   1.275 @@ -235,14 +240,14 @@
   1.276  				// Don't try to find that branch, guess 12 pixels
   1.277  				y=o->getChildPos().y()  -height() + 12; 
   1.278  		}	
   1.279 -		if (o->getOrientation()==OrientLeftOfCenter)
   1.280 +		if (o->getOrientation()==LinkableMapObj::LeftOfCenter)
   1.281  			move ( o->getChildPos().x() - linkwidth, y );
   1.282  		else	
   1.283  			move (o->getChildPos().x() + linkwidth, y );
   1.284  	}	
   1.285  
   1.286  	// updateLink is called implicitly in move
   1.287 -	reposition();	// FIXME shouldn't be this a request?
   1.288 +	requestReposition();	
   1.289  }
   1.290  
   1.291  void BranchObj::unsetParObjTmp()
   1.292 @@ -254,6 +259,7 @@
   1.293  		parObjTmpBuf=NULL;
   1.294  		depth=parObj->getDepth()+1;
   1.295  		setLinkStyle (getDefLinkStyle() );
   1.296 +		updateLink();
   1.297  	}		
   1.298  }
   1.299  
   1.300 @@ -265,23 +271,18 @@
   1.301  
   1.302  void BranchObj::toggleScroll()
   1.303  {
   1.304 -	BranchObj *bo;
   1.305  	if (scrolled)
   1.306  	{
   1.307  		scrolled=false;
   1.308  		systemFlags->deactivate("scrolledright");
   1.309 -		for (bo=branch.first(); bo; bo=branch.next() )
   1.310 -		{
   1.311 -			bo->setVisibility(true);
   1.312 -		}
   1.313 +		for (int i=0; i<branch.size(); ++i)
   1.314 +			branch.at(i)->setVisibility(true);
   1.315  	} else
   1.316  	{
   1.317  		scrolled=true;
   1.318  		systemFlags->activate("scrolledright");
   1.319 -		for (bo=branch.first(); bo; bo=branch.next() )
   1.320 -		{
   1.321 -			bo->setVisibility(false);
   1.322 -		}
   1.323 +		for (int i=0; i<branch.size(); ++i)
   1.324 +			branch.at(i)->setVisibility(false);
   1.325  	}
   1.326  	calcBBoxSize();
   1.327  	positionBBox();	
   1.328 @@ -350,18 +351,19 @@
   1.329  		standardFlags->setVisibility(v);
   1.330  		LinkableMapObj::setVisibility (v);
   1.331  		
   1.332 +		// Only change childs, if I am not scrolled
   1.333  		if (!scrolled && (depth < toDepth))
   1.334  		{
   1.335  			// Now go recursivly through all childs
   1.336 -			BranchObj* b;
   1.337 -			for (b=branch.first(); b;b=branch.next() ) 
   1.338 -				b->setVisibility (v,toDepth);	
   1.339 -			FloatImageObj *fio;
   1.340 -			for (fio=floatimage.first(); fio; fio=floatimage.next())
   1.341 -				fio->setVisibility (v);
   1.342 +			int i;
   1.343 +			for (i=0; i<branch.size(); ++i)
   1.344 +				branch.at(i)->setVisibility (v,toDepth);	
   1.345 +			for (i=0; i<floatimage.size(); ++i)
   1.346 +				floatimage.at(i)->setVisibility (v);
   1.347 +			for (i=0; i<xlink.size(); ++i)	
   1.348 +				xlink.at(i)->setVisibility ();	
   1.349  		}
   1.350      } // depth <= toDepth	
   1.351 -	move (absPos.x(), absPos.y() );
   1.352  	requestReposition();
   1.353  }	
   1.354  
   1.355 @@ -376,53 +378,60 @@
   1.356  	// Overloaded from LinkableMapObj
   1.357  	// BranchObj can use color of heading
   1.358  
   1.359 -	if (mapEditor->getLinkColorHint()==HeadingColor)
   1.360 -		LinkableMapObj::setLinkColor (heading->getColor() );
   1.361 -	else	
   1.362 -		LinkableMapObj::setLinkColor ();
   1.363 +	if (mapEditor)
   1.364 +	{
   1.365 +		if (mapEditor->getMapLinkColorHint()==HeadingColor)
   1.366 +			LinkableMapObj::setLinkColor (heading->getColor() );
   1.367 +		else	
   1.368 +			LinkableMapObj::setLinkColor ();
   1.369 +	}		
   1.370  }
   1.371  
   1.372 -void BranchObj::setColor (QColor col, bool colorChilds)
   1.373 +void BranchObj::setColorSubtree(QColor col)
   1.374  {
   1.375 -    heading->setColor(col);
   1.376 -	setLinkColor();
   1.377 -    if (colorChilds) 
   1.378 -    {
   1.379 -		BranchObj *bo;
   1.380 -		for (bo=branch.first(); bo; bo=branch.next() )
   1.381 -			bo->setColor(col,colorChilds);
   1.382 -    }	
   1.383 +	setColor (col);
   1.384 +	for (int i=0; i<branch.size(); ++i)
   1.385 +		branch.at(i)->setColorSubtree(col);
   1.386  }
   1.387  
   1.388 -
   1.389  BranchObj* BranchObj::first()
   1.390  {
   1.391  	itLast=NULL;	
   1.392 +	itFirst=this;
   1.393  	return this; 
   1.394  }
   1.395  	
   1.396  BranchObj* BranchObj::next()
   1.397  {
   1.398 +	BranchObj *bo;
   1.399  	BranchObj *lmo;
   1.400 -	BranchObj *bo=branch.first();
   1.401 -	BranchObj *po=(BranchObj*)(parObj);
   1.402 +	BranchObj *po=(BranchObj*)parObj;
   1.403 +
   1.404 +	if (branch.isEmpty())
   1.405 +		bo=NULL;
   1.406 +	else
   1.407 +		bo=branch.first();
   1.408  
   1.409  	if (!itLast)
   1.410 -	{	// We are just beginning at the mapCenter
   1.411 +	{
   1.412 +		// no itLast, we are just beginning
   1.413  		if (bo) 
   1.414  		{
   1.415 +			// we have childs, return first one
   1.416  			itLast=this;
   1.417  			return bo;
   1.418  		}	
   1.419  		else
   1.420  		{
   1.421 -			itLast=NULL;
   1.422 +			// No childs, so there is no next
   1.423 +			itLast=this;
   1.424  			return NULL;
   1.425  		}	
   1.426  	}
   1.427  
   1.428 -	if (itLast==parObj)
   1.429 -	{	// We come from above
   1.430 +	// We have an itLast
   1.431 +	if (itLast==po)
   1.432 +	{	// We come from parent
   1.433  		if (bo)
   1.434  		{
   1.435  			// there are childs, go there
   1.436 @@ -433,7 +442,7 @@
   1.437  		{	// no childs, try to go up again
   1.438  			if (po)
   1.439  			{
   1.440 -				// go up
   1.441 +				// go back to parent and try to find next there
   1.442  				itLast=this;
   1.443  				lmo=po->next();
   1.444  				itLast=this;
   1.445 @@ -442,22 +451,35 @@
   1.446  			}	
   1.447  			else
   1.448  			{
   1.449 -				// can't go up, I am mapCenter
   1.450 +				// can't go up, I am mapCenter, no next
   1.451  				itLast=NULL;
   1.452  				return NULL;
   1.453  			}	
   1.454  		}
   1.455  	}
   1.456  
   1.457 -	// Try to find last child, we came from, in my own childs
   1.458 +	// We don't come from parent, but from brother or childs
   1.459 +
   1.460 +	// Try to find last child, where we came from, in my own childs
   1.461  	bool searching=true;
   1.462 -	while (bo && searching)
   1.463 +	int i=0;
   1.464 +	while (i<branch.size())
   1.465  	{
   1.466 -		if (itLast==bo) searching=false;
   1.467 -		bo=branch.next();
   1.468 +		// Try to find itLast in my own childs
   1.469 +		if (itLast==branch.at(i))
   1.470 +		{
   1.471 +			// ok, we come from my own childs
   1.472 +			if (i<branch.size()-1)
   1.473 +				bo=branch.at(i+1);
   1.474 +			 else
   1.475 +				bo=NULL;
   1.476 +			searching=false;
   1.477 +			i=branch.size();
   1.478 +		} 	
   1.479 +		++i;	
   1.480  	}
   1.481  	if (!searching)
   1.482 -	{	// found lastLMO in my childs
   1.483 +	{	// found itLast in my childs
   1.484  		if (bo)
   1.485  		{
   1.486  			// found a brother of lastLMO 
   1.487 @@ -468,6 +490,7 @@
   1.488  		{
   1.489  			if (po)
   1.490  			{
   1.491 +				if (this==itFirst) return NULL;	// Stop at starting point
   1.492  				// go up
   1.493  				itLast=this;
   1.494  				lmo=po->next();
   1.495 @@ -484,12 +507,11 @@
   1.496  	}
   1.497  
   1.498  	// couldn't find last child, it must be a nephew of mine
   1.499 -	bo=branch.first();
   1.500 -	if (bo)
   1.501 +	if (branch.size()>0)
   1.502  	{
   1.503  		// proceed with my first child
   1.504  		itLast=this;	
   1.505 -		return bo;
   1.506 +		return branch.first();
   1.507  	}	
   1.508  	else
   1.509  	{
   1.510 @@ -521,14 +543,22 @@
   1.511  	itLast=it;
   1.512  }
   1.513  
   1.514 +void BranchObj::positionContents()
   1.515 +{
   1.516 +    for (int i=0; i<floatimage.size(); ++i )
   1.517 +		floatimage.at(i)->reposition();
   1.518 +	OrnamentedObj::positionContents();
   1.519 +}
   1.520  
   1.521  void BranchObj::move (double x, double y)
   1.522  {
   1.523  	OrnamentedObj::move (x,y);
   1.524 +    for (int i=0; i<floatimage.size(); ++i )
   1.525 +		floatimage.at(i)->reposition();
   1.526      positionBBox();
   1.527  }
   1.528  
   1.529 -void BranchObj::move (QPoint p)
   1.530 +void BranchObj::move (QPointF p)
   1.531  {
   1.532  	move (p.x(), p.y());
   1.533  }
   1.534 @@ -536,13 +566,12 @@
   1.535  void BranchObj::moveBy (double x, double y)
   1.536  {
   1.537  	OrnamentedObj::moveBy (x,y);
   1.538 +	for (int i=0; i<branch.size(); ++i)
   1.539 +		branch.at(i)->moveBy (x,y);
   1.540      positionBBox();
   1.541 -    BranchObj* b;
   1.542 -    for (b=branch.first(); b;b=branch.next() ) 
   1.543 -		b->moveBy (x,y);
   1.544  }
   1.545 -
   1.546 -void BranchObj::moveBy (QPoint p)
   1.547 +	
   1.548 +void BranchObj::moveBy (QPointF p)
   1.549  {
   1.550  	moveBy (p.x(), p.y());
   1.551  }
   1.552 @@ -550,38 +579,31 @@
   1.553  
   1.554  void BranchObj::positionBBox()
   1.555  {
   1.556 -
   1.557 -    heading->positionBBox();
   1.558 -	systemFlags->positionBBox();
   1.559 -	standardFlags->positionBBox();
   1.560 -	// It seems that setting x,y also affects width,height
   1.561 -	int w_old=bbox.width();
   1.562 -	int h_old=bbox.height();
   1.563 -    bbox.setX (absPos.x() );
   1.564 -	bbox.setY (absPos.y() );
   1.565 -	bbox.setWidth(w_old);
   1.566 -	bbox.setHeight(h_old);
   1.567 -
   1.568 -
   1.569 -	setSelBox();
   1.570 +	QPointF ap=getAbsPos();
   1.571 +	bbox.moveTopLeft (ap);
   1.572 +	positionContents();
   1.573  
   1.574  	// set the frame
   1.575 -	frame->setRect(QRect(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
   1.576 +	frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
   1.577 +
   1.578 +	// Update links to other branches
   1.579 +	for (int i=0; i<xlink.size(); ++i)
   1.580 +		xlink.at(i)->updateXLink();
   1.581  }
   1.582  
   1.583  void BranchObj::calcBBoxSize()
   1.584  {
   1.585 -    QSize heading_r=heading->getSize();
   1.586 -    int heading_w=static_cast <int> (heading_r.width() );
   1.587 -    int heading_h=static_cast <int> (heading_r.height() );
   1.588 -    QSize sysflags_r=systemFlags->getSize();
   1.589 -	int sysflags_h=sysflags_r.height();
   1.590 -	int sysflags_w=sysflags_r.width();
   1.591 -    QSize stanflags_r=standardFlags->getSize();
   1.592 -	int stanflags_h=stanflags_r.height();
   1.593 -	int stanflags_w=stanflags_r.width();
   1.594 -    int w;
   1.595 -    int h;
   1.596 +    QSizeF heading_r=heading->getSize();
   1.597 +    qreal heading_w=(qreal) heading_r.width() ;
   1.598 +    qreal heading_h=(qreal) heading_r.height() ;
   1.599 +    QSizeF sysflags_r=systemFlags->getSize();
   1.600 +	qreal sysflags_h=sysflags_r.height();
   1.601 +	qreal sysflags_w=sysflags_r.width();
   1.602 +    QSizeF stanflags_r=standardFlags->getSize();
   1.603 +	qreal stanflags_h=stanflags_r.height();
   1.604 +	qreal stanflags_w=stanflags_r.width();
   1.605 +    qreal w;
   1.606 +    qreal h;
   1.607  
   1.608  	// set width to sum of all widths
   1.609  	w=heading_w + sysflags_w + stanflags_w;
   1.610 @@ -589,106 +611,186 @@
   1.611  	h=max (sysflags_h,stanflags_h);
   1.612  	h=max (h,heading_h);
   1.613  
   1.614 -    w+=frame->getBorder();
   1.615 -    h+=frame->getBorder();
   1.616 -    bbox.setSize (QSize (w,h));
   1.617 +	// Save the dimension of flags and heading
   1.618 +	ornamentsBBox.setSize ( QSizeF(w,h));
   1.619 +
   1.620 +	// clickBox includes Flags and Heading
   1.621 +    clickBox.setSize (ornamentsBBox.size() );
   1.622 +
   1.623 +	// Floatimages 
   1.624 +	QPointF rp;
   1.625 +
   1.626 +	topPad=botPad=leftPad=rightPad=0;
   1.627 +	if (includeImagesVer || includeImagesHor)
   1.628 +	{
   1.629 +		if (countFloatImages()>0)
   1.630 +		{
   1.631 +			for (int i=0; i<floatimage.size(); ++i )
   1.632 +			{
   1.633 +				rp=floatimage.at(i)->getRelPos();
   1.634 +				if (includeImagesVer)
   1.635 +				{
   1.636 +					if (rp.y() < 0) 
   1.637 +						topPad=max (topPad,-rp.y()-h);
   1.638 +					if (rp.y()+floatimage.at(i)->height() > 0)
   1.639 +						botPad=max (botPad,rp.y()+floatimage.at(i)->height());
   1.640 +				}		
   1.641 +				if (includeImagesHor)
   1.642 +				{
   1.643 +					if (orientation==LinkableMapObj::RightOfCenter)
   1.644 +					{
   1.645 +						if (-rp.x()-w > 0) 
   1.646 +							leftPad=max (leftPad,-rp.x()-w);
   1.647 +						if (rp.x()+floatimage.at(i)->width() > 0)
   1.648 +							rightPad=max (rightPad,rp.x()+floatimage.at(i)->width());
   1.649 +					} else
   1.650 +					{
   1.651 +						if (rp.x()< 0) 
   1.652 +							leftPad=max (leftPad,-rp.x());
   1.653 +						if (rp.x()+floatimage.at(i)->width() > w)
   1.654 +							rightPad=max (rightPad,rp.x()+floatimage.at(i)->width()-w);
   1.655 +					}
   1.656 +				}		
   1.657 +			}	
   1.658 +		}	
   1.659 +		h+=topPad+botPad;
   1.660 +		w+=leftPad+rightPad;
   1.661 +	}
   1.662 +
   1.663 +	// Frame thickness
   1.664 +    w+=frame->getPadding();
   1.665 +    h+=frame->getPadding();
   1.666 +	
   1.667 +	// Finally set size
   1.668 +    bbox.setSize (QSizeF (w,h));
   1.669  }
   1.670  
   1.671 -LinkableMapObj* BranchObj::findMapObj(QPoint p, LinkableMapObj* excludeLMO)
   1.672 +void BranchObj::setDockPos()
   1.673 +{
   1.674 +	// Sets childpos and parpos depending on orientation
   1.675 +	if (getOrientation()==LinkableMapObj::LeftOfCenter )
   1.676 +    {
   1.677 +		childPos=QPointF (
   1.678 +			ornamentsBBox.bottomLeft().x(), 
   1.679 +			bottomlineY);
   1.680 +		parPos=QPointF (
   1.681 +			ornamentsBBox.bottomRight().x(),
   1.682 +			bottomlineY);
   1.683 +    } else
   1.684 +    {
   1.685 +		childPos=QPointF (
   1.686 +			ornamentsBBox.bottomRight().x(), 
   1.687 +			bottomlineY);
   1.688 +		parPos=QPointF (
   1.689 +			ornamentsBBox.bottomLeft().x(),
   1.690 +			bottomlineY);
   1.691 +    }
   1.692 +}
   1.693 +
   1.694 +LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
   1.695  {
   1.696  	// Search branches
   1.697 -    BranchObj *b;
   1.698      LinkableMapObj *lmo;
   1.699 -    for (b=branch.first(); b; b=branch.next() )
   1.700 +	for (int i=0; i<branch.size(); ++i)
   1.701      {	
   1.702 -		lmo=b->findMapObj(p, excludeLMO);
   1.703 +		lmo=branch.at(i)->findMapObj(p, excludeLMO);
   1.704 +		if (lmo != NULL) return lmo;
   1.705 +    }
   1.706 +	
   1.707 +
   1.708 +	// Search myself
   1.709 +    if (inBox (p,clickBox) && (this != excludeLMO) && isVisibleObj() ) 
   1.710 +		return this;
   1.711 +
   1.712 +	// Search float images
   1.713 +    for (int i=0; i<floatimage.size(); ++i )
   1.714 +		if (inBox(p,floatimage.at(i)->getClickBox()) && 
   1.715 +			(floatimage.at(i) != excludeLMO) && 
   1.716 +			floatimage.at(i)->getParObj()!= excludeLMO &&
   1.717 +			floatimage.at(i)->isVisibleObj() 
   1.718 +		) return floatimage.at(i);
   1.719 +
   1.720 +    return NULL;
   1.721 +}
   1.722 +
   1.723 +LinkableMapObj* BranchObj::findID (QString sid)
   1.724 +{
   1.725 +	// Search branches
   1.726 +    LinkableMapObj *lmo;
   1.727 +	for (int i=0; i<branch.size(); ++i)
   1.728 +    {	
   1.729 +		lmo=branch.at(i)->findID (sid);
   1.730  		if (lmo != NULL) return lmo;
   1.731      }
   1.732  	
   1.733  	// Search myself
   1.734 -    if (inBBox (p) && (this != excludeLMO) && isVisibleObj() ) 
   1.735 -		return this;
   1.736 +	if (sid==objID) return this;
   1.737  
   1.738 +
   1.739 +/*
   1.740  	// Search float images
   1.741 -	FloatImageObj *foi;
   1.742 -    for (foi=floatimage.first(); foi; foi=floatimage.next() )
   1.743 -		if (foi->inBBox(p) && (foi != excludeLMO) && foi->getParObj()!= excludeLMO) return foi;
   1.744 -
   1.745 +    for (int i=0; i<floatimage.size(); ++i )
   1.746 +		if (floatimage.at(i)->inBox(p) && 
   1.747 +			(floatimage.at(i) != excludeLMO) && 
   1.748 +			floatimage.at(i)->getParObj()!= excludeLMO &&
   1.749 +			floatimage.at(i)->isVisibleObj() 
   1.750 +		) return floatimage.at(i);
   1.751 +*/
   1.752      return NULL;
   1.753  }
   1.754  
   1.755  void BranchObj::setHeading(QString s)
   1.756  {
   1.757 -    // Adjusting font size
   1.758 -    QFont font=heading->getFont();
   1.759 -	if (depth==0)
   1.760 -		font.setPointSize(16);
   1.761 -	else	
   1.762 -		if (depth>1) 
   1.763 -			font.setPointSize(10);
   1.764 -		else
   1.765 -			font.setPointSize(12);
   1.766 -    heading->setFont(font);
   1.767      heading->setText(s);	// set new heading
   1.768  	calcBBoxSize();			// recalculate bbox
   1.769      positionBBox();			// rearrange contents
   1.770  	requestReposition();
   1.771  }
   1.772  
   1.773 -void BranchObj::setURL(QString s)
   1.774 +void BranchObj::setHideTmp (HideTmpMode mode)
   1.775  {
   1.776 -	url=s;
   1.777 -	if (!url.isEmpty())
   1.778 -		systemFlags->activate("url");
   1.779 -	else	
   1.780 -		systemFlags->deactivate("url");
   1.781 -	calcBBoxSize();			// recalculate bbox
   1.782 -    positionBBox();			// rearrange contents
   1.783 -	forceReposition();
   1.784 +	if (mode==HideExport && (hideExport|| hasHiddenExportParent() ) )
   1.785 +	{
   1.786 +		// Hide stuff according to hideExport flag and parents
   1.787 +		setVisibility (false);
   1.788 +		hidden=true;
   1.789 +	}else
   1.790 +	{
   1.791 +		// Do not hide, but still take care of scrolled status
   1.792 +		if (hasScrolledParent(this))
   1.793 +			setVisibility (false);
   1.794 +		else
   1.795 +			setVisibility (true);
   1.796 +		hidden=false;
   1.797 +	}	
   1.798 +
   1.799 +	// And take care of my childs
   1.800 +	for (int i=0; i<branch.size(); ++i)
   1.801 +		branch.at(i)->setHideTmp (mode);
   1.802  }
   1.803  
   1.804 -QString BranchObj::getURL()
   1.805 +bool BranchObj::hasHiddenExportParent()
   1.806  {
   1.807 -	return url;
   1.808 +	// Calls parents recursivly to
   1.809 +	// find out, if we or parents are temp. hidden
   1.810 +
   1.811 +	if (hidden || hideExport) return true;
   1.812 +
   1.813 +	BranchObj* bo=(BranchObj*)parObj;
   1.814 +	if (bo) 
   1.815 +		return bo->hasHiddenExportParent();
   1.816 +	else
   1.817 +		return false;
   1.818  }
   1.819  
   1.820 -void BranchObj::setVymLink(QString s)
   1.821 +QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
   1.822  {
   1.823 -	if (!s.isEmpty())
   1.824 -	{
   1.825 -		// We need the relative (from loading) 
   1.826 -		// or absolute path (from User event)
   1.827 -		// and build the absolute path.
   1.828 -		// Note: If we have relative, use path of
   1.829 -		// current map to build absolute path
   1.830 -		QDir d(s);
   1.831 -		if (!d.path().startsWith ("/"))
   1.832 -		{
   1.833 -			QString p=mapEditor->getDestPath();
   1.834 -			int i=p.findRev("/",-1);
   1.835 -			d.setPath(p.left(i)+"/"+s);
   1.836 -			d.convertToAbs();
   1.837 -		}
   1.838 -		vymLink=d.path();
   1.839 -		systemFlags->activate("vymLink");
   1.840 -	}	
   1.841 -	else	
   1.842 -	{
   1.843 -		systemFlags->deactivate("vymLink");
   1.844 -		vymLink="";
   1.845 -	}	
   1.846 -	calcBBoxSize();			// recalculate bbox
   1.847 -    positionBBox();			// rearrange contents
   1.848 -	forceReposition();
   1.849 -}
   1.850 +	// Cloudy stuff can be hidden during exports
   1.851 +	if (hidden) return "";
   1.852  
   1.853 -QString BranchObj::getVymLink()
   1.854 -{
   1.855 -	return vymLink;
   1.856 -}
   1.857 -
   1.858 -QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPoint& offset)
   1.859 -{
   1.860 +	// Update of note is usually done while unselecting a branch
   1.861 +	if (isNoteInEditor) getNoteFromTextEditor();
   1.862 +	
   1.863      QString s,a;
   1.864  	QString scrolledAttr;
   1.865  	if (scrolled) 
   1.866 @@ -696,90 +798,192 @@
   1.867  	else
   1.868  		scrolledAttr="";
   1.869  
   1.870 -	QString posAttr;
   1.871 -	if (depth<2) posAttr=
   1.872 -		attribut("absPosX",QString().setNum(absPos.x(),10)) +
   1.873 -		attribut("absPosY",QString().setNum(absPos.y(),10)); 
   1.874 -	else
   1.875 -		posAttr="";
   1.876 -
   1.877 -	QString urlAttr;
   1.878 -	if (!url.isEmpty())
   1.879 -		urlAttr=attribut ("url",url);
   1.880 -
   1.881 -	QString vymLinkAttr;
   1.882 -	if (!vymLink.isEmpty())
   1.883 -		vymLinkAttr=attribut ("vymLink",convertToRel(mapEditor->getDestPath(),vymLink) );
   1.884 -
   1.885 -	QString frameAttr;
   1.886 -	if (frame->getFrameType()!=NoFrame)
   1.887 -		frameAttr=attribut ("frameType",frame->getFrameTypeName());
   1.888 -	else
   1.889 -		frameAttr="";
   1.890 -
   1.891  	// save area, if not scrolled
   1.892  	QString areaAttr;
   1.893  	if (!((BranchObj*)(parObj))->isScrolled() )
   1.894  	{
   1.895  		areaAttr=
   1.896 -			attribut("x1",QString().setNum(absPos.x()-offset.x(),10)) +
   1.897 -			attribut("y1",QString().setNum(absPos.y()-offset.y(),10)) +
   1.898 -			attribut("x2",QString().setNum(absPos.x()+width()-offset.x(),10)) +
   1.899 -			attribut("y2",QString().setNum(absPos.y()+height()-offset.y(),10));
   1.900 +			attribut("x1",QString().setNum(absPos.x()-offset.x())) +
   1.901 +			attribut("y1",QString().setNum(absPos.y()-offset.y())) +
   1.902 +			attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
   1.903 +			attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
   1.904  
   1.905  	} else
   1.906  		areaAttr="";
   1.907  	
   1.908 -    s=beginElement ("branch" +scrolledAttr +posAttr +urlAttr +vymLinkAttr +frameAttr +areaAttr);
   1.909 +	// Providing an ID for a branch makes export to XHTML easier
   1.910 +	QString idAttr;
   1.911 +	if (countXLinks()>0)
   1.912 +		idAttr=attribut ("id",mapEditor->getModel()->getSelectString(this)); //TODO directly access model
   1.913 +	else
   1.914 +		idAttr="";
   1.915 +
   1.916 +    s=beginElement ("branch" 
   1.917 +		+getOrnXMLAttr() 
   1.918 +		+scrolledAttr 
   1.919 +		+areaAttr 
   1.920 +		+idAttr 
   1.921 +		+getIncludeImageAttr() );
   1.922      incIndent();
   1.923  
   1.924  	// save heading
   1.925 -    s=s+valueElement("heading", getHeading(),
   1.926 +    s+=valueElement("heading", getHeading(),
   1.927  		attribut ("textColor",QColor(heading->getColor()).name()));
   1.928  
   1.929 +	// Save frame
   1.930 +	if (frame->getFrameType()!=FrameObj::NoFrame) 
   1.931 +		s+=frame->saveToDir ();
   1.932 +
   1.933  	// save names of flags set
   1.934  	s+=standardFlags->saveToDir(tmpdir,prefix,0);
   1.935  	
   1.936 +	// Save FloatImages
   1.937 +	for (int i=0; i<floatimage.size(); ++i)
   1.938 +		s+=floatimage.at(i)->saveToDir (tmpdir,prefix);
   1.939 +
   1.940  	// save note
   1.941  	if (!note.isEmpty() )
   1.942  		s+=note.saveToDir();
   1.943  	
   1.944  	// Save branches
   1.945 -    BranchObj *bo;
   1.946 -    for (bo=branch.first(); bo; bo=branch.next() )
   1.947 -		s+=bo->saveToDir(tmpdir,prefix,offset);
   1.948 +	for (int i=0; i<branch.size(); ++i)
   1.949 +		s+=branch.at(i)->saveToDir(tmpdir,prefix,offset);
   1.950 +
   1.951 +	// Save XLinks
   1.952 +	QString ol;	// old link
   1.953 +	QString cl;	// current link
   1.954 +	for (int i=0; i<xlink.size(); ++i)
   1.955 +	{
   1.956 +		cl=xlink.at(i)->saveToDir();
   1.957 +		if (cl!=ol)
   1.958 +		{
   1.959 +			s+=cl;
   1.960 +			ol=cl;
   1.961 +		} else
   1.962 +		{
   1.963 +			qWarning (QString("Ignoring of duplicate xLink in %1").arg(getHeading()));
   1.964 +		}
   1.965 +	}	
   1.966 +
   1.967      decIndent();
   1.968 -
   1.969 -	// Save FloatImages
   1.970 -	FloatImageObj *fio;
   1.971 -	for (fio=floatimage.first(); fio; fio=floatimage.next() )
   1.972 -		s+=fio->saveToDir (tmpdir,prefix);
   1.973 -
   1.974      s+=endElement   ("branch");
   1.975      return s;
   1.976  }
   1.977  
   1.978 -LinkableMapObj* BranchObj::addFloatImage ()
   1.979 +void BranchObj::addXLink (XLinkObj *xlo)
   1.980  {
   1.981 -	FloatImageObj *newfi=new FloatImageObj (canvas,this);
   1.982 +	xlink.append (xlo);
   1.983 +	
   1.984 +}
   1.985 +
   1.986 +void BranchObj::removeXLinkRef (XLinkObj *xlo)
   1.987 +{
   1.988 +	xlink.removeAt (xlink.indexOf(xlo));
   1.989 +}
   1.990 +
   1.991 +void BranchObj::deleteXLink(XLinkObj *xlo)
   1.992 +{
   1.993 +	xlo->deactivate();
   1.994 +	if (!xlo->isUsed()) delete (xlo);
   1.995 +}
   1.996 +
   1.997 +void BranchObj::deleteXLinkAt (int i)
   1.998 +{
   1.999 +	XLinkObj *xlo=xlink.at(i);
  1.1000 +	xlo->deactivate();
  1.1001 +	if (!xlo->isUsed()) delete(xlo);
  1.1002 +}
  1.1003 +
  1.1004 +XLinkObj* BranchObj::XLinkAt (int i)
  1.1005 +{
  1.1006 +	return xlink.at(i);
  1.1007 +}
  1.1008 +
  1.1009 +int BranchObj::countXLink()
  1.1010 +{
  1.1011 +	return xlink.count();
  1.1012 +}
  1.1013 +
  1.1014 +
  1.1015 +BranchObj* BranchObj::XLinkTargetAt (int i)
  1.1016 +{
  1.1017 +	if (i>=0 && i<xlink.size())
  1.1018 +	{
  1.1019 +		if (xlink.at(i))
  1.1020 +			return xlink.at(i)->otherBranch (this);
  1.1021 +	}
  1.1022 +	return NULL;
  1.1023 +}
  1.1024 +
  1.1025 +void BranchObj::setIncludeImagesVer(bool b)
  1.1026 +{
  1.1027 +	includeImagesVer=b;
  1.1028 +	calcBBoxSize();
  1.1029 +	positionBBox();
  1.1030 +	requestReposition();
  1.1031 +}
  1.1032 +
  1.1033 +bool BranchObj::getIncludeImagesVer()
  1.1034 +{
  1.1035 +	return includeImagesVer;
  1.1036 +}
  1.1037 +
  1.1038 +void BranchObj::setIncludeImagesHor(bool b)
  1.1039 +{
  1.1040 +	includeImagesHor=b;
  1.1041 +	calcBBoxSize();
  1.1042 +	positionBBox();
  1.1043 +	requestReposition();
  1.1044 +}
  1.1045 +
  1.1046 +bool BranchObj::getIncludeImagesHor()
  1.1047 +{
  1.1048 +	return includeImagesHor;
  1.1049 +}
  1.1050 +
  1.1051 +QString BranchObj::getIncludeImageAttr()
  1.1052 +{
  1.1053 +	QString a;
  1.1054 +	if (includeImagesVer)
  1.1055 +		a=attribut ("incImgV","true");
  1.1056 +	else
  1.1057 +		a=attribut ("incImgV","false");
  1.1058 +	if (includeImagesHor)
  1.1059 +		a+=attribut ("incImgH","true");
  1.1060 +	else
  1.1061 +		a+=attribut ("incImgH","false");
  1.1062 +	return a;	
  1.1063 +}
  1.1064 +
  1.1065 +FloatImageObj* BranchObj::addFloatImage ()
  1.1066 +{
  1.1067 +	FloatImageObj *newfi=new FloatImageObj (scene,this);
  1.1068  	floatimage.append (newfi);
  1.1069  	if (hasScrolledParent(this) )
  1.1070  		newfi->setVisibility (false);
  1.1071  	else	
  1.1072  		newfi->setVisibility(visible);
  1.1073 +		/*
  1.1074 +	calcBBoxSize();
  1.1075 +	positionBBox();
  1.1076 +	*/
  1.1077  	requestReposition();
  1.1078  	return newfi;
  1.1079  }
  1.1080  
  1.1081 -LinkableMapObj* BranchObj::addFloatImage (FloatImageObj *fio)
  1.1082 +FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
  1.1083  {
  1.1084 -	FloatImageObj *newfi=new FloatImageObj (canvas,this);
  1.1085 +	FloatImageObj *newfi=new FloatImageObj (scene,this);
  1.1086  	floatimage.append (newfi);
  1.1087  	newfi->copy (fio);
  1.1088  	if (hasScrolledParent(this) )
  1.1089  		newfi->setVisibility (false);
  1.1090  	else	
  1.1091  		newfi->setVisibility(visible);
  1.1092 +		/*
  1.1093 +	calcBBoxSize();
  1.1094 +	positionBBox();
  1.1095 +	*/
  1.1096  	requestReposition();
  1.1097  	return newfi;
  1.1098  }
  1.1099 @@ -801,62 +1005,92 @@
  1.1100  
  1.1101  void BranchObj::removeFloatImage (FloatImageObj *fio)
  1.1102  {
  1.1103 -	floatimage.remove (fio);
  1.1104 +	int i=floatimage.indexOf (fio);
  1.1105 +	if (i>-1) delete (floatimage.takeAt (i));
  1.1106 +	calcBBoxSize();
  1.1107 +	positionBBox();
  1.1108  	requestReposition();
  1.1109  }
  1.1110  
  1.1111  void BranchObj::savePosInAngle ()
  1.1112  {
  1.1113  	// Save position in angle
  1.1114 -    BranchObj *b;
  1.1115 -	int i=0;
  1.1116 -    for (b=branch.first(); b; b=branch.next() )
  1.1117 +	for (int i=0; i<branch.size(); ++i)
  1.1118 +		branch.at(i)->angle=i;
  1.1119 +}
  1.1120 +
  1.1121 +void BranchObj::setDefAttr (BranchModification mod)
  1.1122 +{
  1.1123 +	int fontsize;
  1.1124 +	switch (depth)
  1.1125  	{
  1.1126 -		b->angle=i;
  1.1127 -		i++;
  1.1128 -	}
  1.1129 +		case 0: fontsize=16; break;
  1.1130 +		case 1: fontsize=12; break;
  1.1131 +		default: fontsize=10; break;
  1.1132 +	}	
  1.1133 +
  1.1134 +	setLinkColor ();
  1.1135 +	setLinkStyle(getDefLinkStyle());
  1.1136 +	QFont font("Sans Serif,8,-1,5,50,0,0,0,0,0");
  1.1137 +	font.setPointSize(fontsize);
  1.1138 +	heading->setFont(font );
  1.1139 +
  1.1140 +	if (mod==NewBranch)
  1.1141 +		setColor (((BranchObj*)(parObj))->getColor());
  1.1142 +	
  1.1143 +	calcBBoxSize();
  1.1144  }
  1.1145  
  1.1146  BranchObj* BranchObj::addBranch()
  1.1147  {
  1.1148 -    BranchObj* newbo=new BranchObj(canvas,this);
  1.1149 +    BranchObj* newbo=new BranchObj(scene,this);
  1.1150      branch.append (newbo);
  1.1151      newbo->setParObj(this);
  1.1152 -    newbo->setColor(getColor(),false);	
  1.1153 -    newbo->setLinkColor();	
  1.1154 +	newbo->setDefAttr(NewBranch);
  1.1155      newbo->setHeading ("new");
  1.1156 -	newbo->setLinkStyle (newbo->getDefLinkStyle());
  1.1157  	if (scrolled)
  1.1158  		newbo->setVisibility (false);
  1.1159  	else	
  1.1160  		newbo->setVisibility(visible);
  1.1161 +	newbo->updateLink();	
  1.1162  	requestReposition();
  1.1163  	return newbo;
  1.1164  }
  1.1165  
  1.1166  BranchObj* BranchObj::addBranch(BranchObj* bo)
  1.1167  {
  1.1168 -    BranchObj* newbo=new BranchObj(canvas,this);
  1.1169 +    BranchObj* newbo=new BranchObj(scene,this);
  1.1170      branch.append (newbo);
  1.1171      newbo->copy(bo);
  1.1172      newbo->setParObj(this);
  1.1173 -	newbo->setHeading (newbo->getHeading());	// adjust fontsize to depth
  1.1174 -	newbo->setLinkStyle (newbo->getDefLinkStyle());
  1.1175 +	newbo->setDefAttr(MovedBranch);
  1.1176  	if (scrolled)
  1.1177  		newbo->setVisibility (false);
  1.1178  	else	
  1.1179  		newbo->setVisibility(bo->visible);
  1.1180 +	newbo->updateLink();	
  1.1181  	requestReposition();
  1.1182  	return newbo;
  1.1183  }
  1.1184  
  1.1185 +BranchObj* BranchObj::addBranchPtr(BranchObj* bo)
  1.1186 +{
  1.1187 +	branch.append (bo);
  1.1188 +	bo->setParObj (this);
  1.1189 +	bo->depth=depth+1;
  1.1190 +	bo->setDefAttr(MovedBranch);
  1.1191 +	if (scrolled) tmpUnscroll();
  1.1192 +	setLastSelectedBranch (bo);
  1.1193 +	return bo;
  1.1194 +}
  1.1195 +
  1.1196  BranchObj* BranchObj::insertBranch(int pos)
  1.1197  {
  1.1198  	savePosInAngle();
  1.1199  	// Add new bo and resort branches
  1.1200  	BranchObj *newbo=addBranch ();
  1.1201  	newbo->angle=pos-0.5;
  1.1202 -	branch.sort();
  1.1203 +	qSort (branch.begin(),branch.end(), isAbove);
  1.1204  	return newbo;
  1.1205  }
  1.1206  
  1.1207 @@ -866,133 +1100,288 @@
  1.1208  	// Add new bo and resort branches
  1.1209  	bo->angle=pos-0.5;
  1.1210  	BranchObj *newbo=addBranch (bo);
  1.1211 -	branch.sort();
  1.1212 +	qSort (branch.begin(),branch.end(), isAbove);
  1.1213  	return newbo;
  1.1214  }
  1.1215  
  1.1216 +BranchObj* BranchObj::insertBranchPtr (BranchObj* bo, int pos)
  1.1217 +{
  1.1218 +	savePosInAngle();
  1.1219 +	// Add new bo and resort branches
  1.1220 +	bo->angle=pos-0.5;
  1.1221 +	branch.append (bo);
  1.1222 +	bo->setParObj (this);
  1.1223 +	bo->depth=depth+1;
  1.1224 +	bo->setDefAttr (MovedBranch);
  1.1225 +	if (scrolled) tmpUnscroll();
  1.1226 +	setLastSelectedBranch (bo);
  1.1227 +	qSort (branch.begin(),branch.end(), isAbove);
  1.1228 +	return bo;
  1.1229 +}
  1.1230 +
  1.1231 +void BranchObj::removeBranchHere(BranchObj* borem)
  1.1232 +{
  1.1233 +	// This removes the branch bo from list, but 
  1.1234 +	// inserts its childs at the place of bo
  1.1235 +	BranchObj *bo;
  1.1236 +	bo=borem->getLastBranch();
  1.1237 +	int pos=borem->getNum();
  1.1238 +	while (bo)
  1.1239 +	{
  1.1240 +		bo->linkTo (this,pos+1);
  1.1241 +		bo=borem->getLastBranch();
  1.1242 +	}	
  1.1243 +	removeBranch (borem);
  1.1244 +}
  1.1245 +
  1.1246 +void BranchObj::removeChilds()
  1.1247 +{
  1.1248 +	clear();
  1.1249 +}
  1.1250 +
  1.1251  void BranchObj::removeBranch(BranchObj* bo)
  1.1252  {
  1.1253      // if bo is not in branch remove returns false, we
  1.1254      // don't care...
  1.1255 -    branch.remove (bo);
  1.1256 +	
  1.1257 +	int i=branch.indexOf(bo);
  1.1258 +    if (i>=0)
  1.1259 +	{
  1.1260 +		delete (bo);
  1.1261 +		branch.removeAt (i);
  1.1262 +	} else
  1.1263 +		qWarning ("BranchObj::removeBranch tried to remove non existing branch?!\n");
  1.1264 +	requestReposition();
  1.1265 +}
  1.1266 +
  1.1267 +void BranchObj::removeBranchPtr(BranchObj* bo)
  1.1268 +{
  1.1269 +	int i=branch.indexOf(bo);
  1.1270 +	
  1.1271 +	if (i>=0)
  1.1272 +		branch.removeAt (i);
  1.1273 +	else	
  1.1274 +		qWarning ("BranchObj::removeBranchPtr tried to remove non existing branch?!\n");
  1.1275  	requestReposition();
  1.1276  }
  1.1277  
  1.1278  void BranchObj::setLastSelectedBranch (BranchObj* bo)
  1.1279  {
  1.1280 -    lastSelectedBranch=branch.find(bo);
  1.1281 +    lastSelectedBranch=branch.indexOf(bo);
  1.1282  }
  1.1283  
  1.1284  BranchObj* BranchObj::getLastSelectedBranch ()
  1.1285  {
  1.1286 -    if (lastSelectedBranch>=0) 
  1.1287 +    if (lastSelectedBranch>=0)
  1.1288  	{
  1.1289 -		BranchObj* bo=branch.at(lastSelectedBranch);
  1.1290 -		if (bo) return bo;
  1.1291 -    }	
  1.1292 -    return branch.first();
  1.1293 +		if ( branch.size()>lastSelectedBranch) 
  1.1294 +			return branch.at(lastSelectedBranch);
  1.1295 +		if (branch.size()>0)
  1.1296 +			return branch.last();
  1.1297 +	}	
  1.1298 +    return NULL;
  1.1299  }
  1.1300  
  1.1301  BranchObj* BranchObj::getFirstBranch ()
  1.1302  {
  1.1303 -    return branch.first();
  1.1304 +	if (branch.size()>0)
  1.1305 +		return branch.first();
  1.1306 +	else
  1.1307 +		return NULL;
  1.1308  }
  1.1309  
  1.1310  BranchObj* BranchObj::getLastBranch ()
  1.1311  {
  1.1312 -    return branch.last();
  1.1313 +	if (branch.size()>0)
  1.1314 +		return branch.last();
  1.1315 +	else
  1.1316 +		return NULL;
  1.1317  }
  1.1318  
  1.1319 -BranchObj* BranchObj::getBranchNum (const uint &i)
  1.1320 +BranchObj* BranchObj::getBranchNum (int i)
  1.1321  {
  1.1322 -    return branch.at(i);
  1.1323 +	if (i>=0 && i<branch.size())
  1.1324 +		return branch.at(i);
  1.1325 +	else	
  1.1326 +		return	NULL;
  1.1327  }
  1.1328  
  1.1329 +bool BranchObj::canMoveBranchUp() 
  1.1330 +{
  1.1331 +	if (!parObj || depth==1) return false;
  1.1332 +	BranchObj* par=(BranchObj*)parObj;
  1.1333 +	if (this==par->getFirstBranch())
  1.1334 +		return false;
  1.1335 +	else
  1.1336 +		return true;
  1.1337 +}
  1.1338  
  1.1339 -BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // move a branch up (modify myself)
  1.1340 +BranchObj* BranchObj::moveBranchUp(BranchObj* bo1) // modify my childlist
  1.1341  {
  1.1342  	savePosInAngle();
  1.1343 -    int i=branch.find(bo1);
  1.1344 +    int i=branch.indexOf(bo1);
  1.1345      if (i>0) 
  1.1346  	{	// -1 if bo1 not found 
  1.1347  		branch.at(i)->angle--;
  1.1348  		branch.at(i-1)->angle++;
  1.1349 -		branch.sort();
  1.1350 -		return branch.at(i-1);
  1.1351 +		qSort (branch.begin(),branch.end(), isAbove);
  1.1352 +		return branch.at(i);
  1.1353  	} else
  1.1354 -		return branch.at(i);
  1.1355 +		return NULL;
  1.1356  }
  1.1357  
  1.1358 -BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)
  1.1359 +bool BranchObj::canMoveBranchDown() 
  1.1360 +{
  1.1361 +	if (!parObj|| depth==1) return false;
  1.1362 +	BranchObj* par=(BranchObj*)parObj;
  1.1363 +	if (this==par->getLastBranch())
  1.1364 +		return false;
  1.1365 +	else
  1.1366 +		return true;
  1.1367 +}
  1.1368 +
  1.1369 +BranchObj* BranchObj::moveBranchDown(BranchObj* bo1)// modify my childlist
  1.1370  {
  1.1371  	savePosInAngle();
  1.1372 -    int i=branch.find(bo1);
  1.1373 +    int i=branch.indexOf(bo1);
  1.1374  	int j;
  1.1375 -	if (branch.next())
  1.1376 +	if (i <branch.size())
  1.1377  	{
  1.1378 -		j = branch.at();
  1.1379 +		j = i+1;
  1.1380  		branch.at(i)->angle++;
  1.1381  		branch.at(j)->angle--;
  1.1382 -		branch.sort();
  1.1383 -		return branch.at(j);
  1.1384 +		qSort (branch.begin(),branch.end(), isAbove);
  1.1385 +		return branch.at(i);
  1.1386  	} else
  1.1387 -		return branch.at(i);
  1.1388 +		return NULL;
  1.1389  }
  1.1390  
  1.1391 -void BranchObj::alignRelativeTo (QPoint ref)
  1.1392 +void BranchObj::sortChildren()
  1.1393  {
  1.1394 -/* FIXME testing
  1.1395 -	if (!getHeading().isEmpty())
  1.1396 -		cout << "BO::alignRelTo "<<getHeading()<<endl;
  1.1397 -	else	
  1.1398 -		cout << "BO::alignRelTo  ???"<<endl;
  1.1399 -	cout << "  d="<<depth<<endl;
  1.1400 -*/	
  1.1401 -	int th = bboxTotal.height();	
  1.1402 +	int childCount=branch.count();
  1.1403 +	int curChildIndex;
  1.1404 +	bool madeChanges=false;
  1.1405 +	do
  1.1406 +	{
  1.1407 +		madeChanges=false;
  1.1408 +		for(curChildIndex=1;curChildIndex<childCount;curChildIndex++){
  1.1409 +			BranchObj* curChild=(BranchObj*)branch.at(curChildIndex);
  1.1410 +			BranchObj* prevChild=(BranchObj*)branch.at(curChildIndex-1);
  1.1411 +			if(prevChild->heading->text().compare(curChild->heading->text())>0)
  1.1412 +			{
  1.1413 +				this->moveBranchUp(curChild);
  1.1414 +				madeChanges=true;
  1.1415 +			}
  1.1416 +		}
  1.1417 +	}while(madeChanges);
  1.1418 +}
  1.1419  
  1.1420 -	// If I am the mapcenter or a mainbranch, reposition heading
  1.1421 +
  1.1422 +BranchObj* BranchObj::linkTo (BranchObj* dst, int pos)
  1.1423 +{
  1.1424 +	// Find current parent and 
  1.1425 +	// remove pointer to myself there
  1.1426 +	if (!dst) return NULL;
  1.1427 +	BranchObj *par=(BranchObj*)parObj;
  1.1428 +	if (par)
  1.1429 +		par->removeBranchPtr (this);
  1.1430 +	else
  1.1431 +		return NULL;
  1.1432 +
  1.1433 +	// Create new pointer to myself at dst
  1.1434 +	if (pos<0||dst->getDepth()==0)
  1.1435 +	{	
  1.1436 +		// links myself as last branch at dst
  1.1437 +		dst->addBranchPtr (this);
  1.1438 +		updateLink();
  1.1439 +		return this;
  1.1440 +	} else
  1.1441 +	{
  1.1442 +		// inserts me at pos in parent of dst
  1.1443 +		if (par)
  1.1444 +		{
  1.1445 +			BranchObj *bo=dst->insertBranchPtr (this,pos);
  1.1446 +			bo->setDefAttr(MovedBranch);
  1.1447 +			updateLink();
  1.1448 +			return bo;
  1.1449 +
  1.1450 +		} else
  1.1451 +			return NULL;
  1.1452 +	}	
  1.1453 +}
  1.1454 +
  1.1455 +void BranchObj::alignRelativeTo (QPointF ref)
  1.1456 +{
  1.1457 +	qreal th = bboxTotal.height();	
  1.1458 +// TODO testing
  1.1459 +/*
  1.1460 +	QPointF pp; if (parObj) pp=parObj->getChildPos();
  1.1461 +	cout << "BO::alignRelTo "<<qPrintable (getHeading());
  1.1462 +	cout << "    d="<<depth<<
  1.1463 +		"  ref="<<ref<<
  1.1464 +//		"  bbox.topLeft="<<bboxTotal.topLeft()<<
  1.1465 +		"  absPos="<<absPos<<
  1.1466 +		"  relPos="<<relPos<<
  1.1467 +		"  parPos="<<pp<<
  1.1468 +		"  orient="<<orientation<<
  1.1469 +//		"  pad="<<topPad<<","<<botPad<<","<<leftPad<<","<<rightPad<<
  1.1470 +//		"  hidden="<<hidden<<
  1.1471 +//		"  th="<<th<<
  1.1472 +		endl;
  1.1473 +*/
  1.1474 +
  1.1475 +	setOrientation();
  1.1476 +	//updateLink();
  1.1477 +
  1.1478  	if (depth<2)
  1.1479  	{
  1.1480 -		move (absPos.x(),absPos.y());
  1.1481  		if (depth==1)
  1.1482  		{
  1.1483 +			// Position relatively, if needed
  1.1484 +			//if (useRelPos) move2RelPos (relPos.x(), relPos.y());
  1.1485 +
  1.1486  			// Calc angle to mapCenter if I am a mainbranch
  1.1487  			// needed for reordering the mainbranches clockwise 
  1.1488  			// around mapcenter 
  1.1489 -			angle=getAngle (QPoint ((int)(x() - parObj->getChildPos().x() ), 
  1.1490 +			angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ), 
  1.1491  									(int)(y() - parObj->getChildPos().y() ) ) );
  1.1492 -		}	
  1.1493 +		}							
  1.1494  	} 
  1.1495  	else
  1.1496      {
  1.1497  		// Align myself depending on orientation and parent, but
  1.1498 -		// only if I am not the mainbranch or mapcenter itself
  1.1499 -		switch (orientation) 
  1.1500 +		// only if I am not a mainbranch or mapcenter itself
  1.1501 +
  1.1502 +		if (anim.isAnimated())
  1.1503  		{
  1.1504 -			case OrientLeftOfCenter:
  1.1505 -				move (ref.x()-bbox.width(), ref.y() + (th-bbox.height())/2 );
  1.1506 -			break;
  1.1507 -			case OrientRightOfCenter:	
  1.1508 -				move (ref.x(), ref.y() + (th-bbox.height())/2 );
  1.1509 -			break;
  1.1510 -			default:
  1.1511 -				cout <<"LMO::alignRelativeTo: oops, no orientation given...\n";
  1.1512 -			break;
  1.1513 -		}		
  1.1514 +			move2RelPos(anim);
  1.1515 +		} else
  1.1516 +		{
  1.1517 +			LinkableMapObj::Orientation o;
  1.1518 +			o=parObj->getOrientation();
  1.1519 +			switch (orientation) 
  1.1520 +			{
  1.1521 +				case LinkableMapObj::LeftOfCenter:
  1.1522 +					move (ref.x() - bbox.width(), ref.y() + (th-bbox.height())/2 );
  1.1523 +				break;
  1.1524 +				case LinkableMapObj::RightOfCenter:	
  1.1525 +					move (ref.x() , ref.y() + (th-bbox.height())/2  );
  1.1526 +				break;
  1.1527 +				default:
  1.1528 +					qWarning ("LMO::alignRelativeTo: oops, no orientation given...");
  1.1529 +				break;
  1.1530 +			}	
  1.1531 +		}
  1.1532      }		
  1.1533  
  1.1534 -	FloatImageObj *fio;
  1.1535 -    for (fio=floatimage.first(); fio; fio=floatimage.next() )
  1.1536 -		fio->reposition();
  1.1537 -
  1.1538  	if (scrolled) return;
  1.1539  
  1.1540      // Set reference point for alignment of childs
  1.1541 -    QPoint ref2;
  1.1542 -    if (orientation==OrientLeftOfCenter)
  1.1543 -		ref2.setX(childPos.x() - linkwidth);
  1.1544 +    QPointF ref2;
  1.1545 +    if (orientation==LinkableMapObj::LeftOfCenter)
  1.1546 +		ref2.setX(bbox.topLeft().x() - linkwidth);
  1.1547      else	
  1.1548 -		ref2.setX(childPos.x() + linkwidth);
  1.1549 +		ref2.setX(bbox.topRight().x() + linkwidth);
  1.1550  
  1.1551  	if (depth==1)
  1.1552  		ref2.setY(absPos.y()-(bboxTotal.height()-bbox.height())/2);
  1.1553 @@ -1000,73 +1389,111 @@
  1.1554  		ref2.setY(ref.y() );	
  1.1555  
  1.1556      // Align the childs depending on reference point 
  1.1557 -    BranchObj *b;
  1.1558 -    for (b=branch.first(); b; b=branch.next() )
  1.1559 +	for (int i=0; i<branch.size(); ++i)
  1.1560      {	
  1.1561 -		b->alignRelativeTo (ref2);
  1.1562 -		ref2.setY(ref2.y() + b->getBBoxSizeWithChilds().height() );
  1.1563 +		if (!branch.at(i)->isHidden())
  1.1564 +		{
  1.1565 +			branch.at(i)->alignRelativeTo (ref2);
  1.1566 +			ref2.setY(ref2.y() + branch.at(i)->getBBoxSizeWithChilds().height() );
  1.1567 +		}
  1.1568      }
  1.1569  }
  1.1570  
  1.1571  
  1.1572  void BranchObj::reposition()
  1.1573  {	
  1.1574 -/* FIXME testing
  1.1575 +/* TODO testing only
  1.1576  	if (!getHeading().isEmpty())
  1.1577 -		cout << "BO::reposition  "<<getHeading()<<endl;
  1.1578 +		cout << "BO::reposition  "<<qPrintable(getHeading())<<endl;
  1.1579  	else	
  1.1580  		cout << "BO::reposition  ???"<<endl;
  1.1581 +
  1.1582 +	cout << "  orient="<<orientation<<endl;
  1.1583  */		
  1.1584 +
  1.1585  	if (depth==0)
  1.1586  	{
  1.1587  		// only calculate the sizes once. If the deepest LMO 
  1.1588  		// changes its height,
  1.1589  		// all upper LMOs have to change, too.
  1.1590  		calcBBoxSizeWithChilds();
  1.1591 -	    alignRelativeTo ( QPoint (absPos.x(),
  1.1592 +		updateLink();	// This update is needed if the scene is resized 
  1.1593 +						// due to excessive moving of a FIO
  1.1594 +
  1.1595 +	    alignRelativeTo ( QPointF (absPos.x(),
  1.1596  			absPos.y()-(bboxTotal.height()-bbox.height())/2) );
  1.1597 -		branch.sort();	
  1.1598 +		qSort (branch.begin(),branch.end(), isAbove);
  1.1599 +		positionBBox();	// Reposition bbox and contents
  1.1600  	} else
  1.1601  	{
  1.1602  		// This is only important for moving branches:
  1.1603  		// For editing a branch it isn't called...
  1.1604 -	    alignRelativeTo ( QPoint (absPos.x(),
  1.1605 +	    alignRelativeTo ( QPointF (absPos.x(),
  1.1606  							absPos.y()-(bboxTotal.height()-bbox.height())/2) );
  1.1607  	}
  1.1608  }
  1.1609  
  1.1610 +void BranchObj::unsetAllRepositionRequests()
  1.1611 +{
  1.1612 +	repositionRequest=false;
  1.1613 +	for (int i=0; i<branch.size(); ++i)
  1.1614 +		branch.at(i)->unsetAllRepositionRequests();
  1.1615 +}
  1.1616  
  1.1617 -QRect BranchObj::getTotalBBox()
  1.1618 +
  1.1619 +QPolygonF BranchObj::shape()
  1.1620  {
  1.1621 -	QRect r=bbox;
  1.1622 +	QPolygonF p;
  1.1623 +
  1.1624 +	QRectF r=getTotalBBox();
  1.1625 +	if (orientation==LinkableMapObj::LeftOfCenter)
  1.1626 +		p   <<r.bottomLeft()
  1.1627 +			<<r.topLeft()
  1.1628 +			<<QPointF (bbox.topLeft().x(), r.topLeft().y() )
  1.1629 +			<<bbox.topRight()
  1.1630 +			<<bbox.bottomRight()
  1.1631 +			<<QPointF (bbox.bottomLeft().x(), r.bottomLeft().y() ) ;
  1.1632 +	else		
  1.1633 +		p   <<r.bottomRight()
  1.1634 +			<<r.topRight()
  1.1635 +			<<QPointF (bbox.topRight().x(), r.topRight().y() )
  1.1636 +			<<bbox.topLeft()
  1.1637 +			<<bbox.bottomLeft()
  1.1638 +			<<QPointF (bbox.bottomRight().x(), r.bottomRight().y() ) ;
  1.1639 +	return p;
  1.1640 +}
  1.1641 +
  1.1642 +QRectF BranchObj::getTotalBBox()
  1.1643 +{
  1.1644 +	QRectF r=bbox;
  1.1645  
  1.1646  	if (scrolled) return r;
  1.1647  
  1.1648 -	BranchObj* b;
  1.1649 -	for (b=branch.first();b ;b=branch.next() )
  1.1650 -		r=addBBox(b->getTotalBBox(),r);
  1.1651 +	for (int i=0; i<branch.size(); ++i)
  1.1652 +		if (!branch.at(i)->isHidden())
  1.1653 +			r=addBBox(branch.at(i)->getTotalBBox(),r);
  1.1654  
  1.1655 -	FloatImageObj* fio;
  1.1656 -	for (fio=floatimage.first();fio ;fio=floatimage.next() )
  1.1657 -		r=addBBox(fio->getTotalBBox(),r);
  1.1658 +	for (int i=0; i<floatimage.size(); ++i)
  1.1659 +		if (!floatimage.at(i)->isHidden())
  1.1660 +			r=addBBox(floatimage.at(i)->getTotalBBox(),r);
  1.1661  		
  1.1662  	return r;
  1.1663  }
  1.1664  
  1.1665 -QRect BranchObj::getBBoxSizeWithChilds()
  1.1666 +QRectF BranchObj::getBBoxSizeWithChilds()
  1.1667  {
  1.1668  	return bboxTotal;
  1.1669  }
  1.1670  
  1.1671  void BranchObj::calcBBoxSizeWithChilds()
  1.1672 -{
  1.1673 -	// This is called only from reposition and
  1.1674 +{	
  1.1675 +	// This is initially called only from reposition and
  1.1676  	// and only for mapcenter. So it won't be
  1.1677  	// called more than once for a single user 
  1.1678  	// action
  1.1679  	
  1.1680 +
  1.1681  	// Calculate size of LMO including all childs (to align them later)
  1.1682 -
  1.1683  	bboxTotal.setX(bbox.x() );
  1.1684  	bboxTotal.setY(bbox.y() );
  1.1685  
  1.1686 @@ -1078,20 +1505,38 @@
  1.1687  		return;
  1.1688  	}
  1.1689  	
  1.1690 -	QRect r(0,0,0,0);
  1.1691 -	QRect br;
  1.1692 +	if (hidden)
  1.1693 +	{
  1.1694 +		bboxTotal.setWidth (0);
  1.1695 +		bboxTotal.setHeight(0);
  1.1696 +		if (parObj)
  1.1697 +		{
  1.1698 +			bboxTotal.setX (parObj->x());
  1.1699 +			bboxTotal.setY (parObj->y());
  1.1700 +		} else
  1.1701 +		{
  1.1702 +			bboxTotal.setX (bbox.x());
  1.1703 +			bboxTotal.setY (bbox.y());
  1.1704 +		}
  1.1705 +		return;
  1.1706 +	}
  1.1707 +	
  1.1708 +	QRectF r(0,0,0,0);
  1.1709 +	QRectF br;
  1.1710  	// Now calculate recursivly
  1.1711  	// sum of heights 
  1.1712  	// maximum of widths 
  1.1713  	// minimum of y
  1.1714 -	BranchObj* b;
  1.1715 -	for (b=branch.first();b ;b=branch.next() )
  1.1716 +	for (int i=0; i<branch.size(); ++i)
  1.1717  	{
  1.1718 -		b->calcBBoxSizeWithChilds();
  1.1719 -		br=b->getBBoxSizeWithChilds();
  1.1720 -		r.setWidth( max (br.width(), r.width() ));
  1.1721 -		r.setHeight(br.height() + r.height() );
  1.1722 -		if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
  1.1723 +		if (!branch.at(i)->isHidden())
  1.1724 +		{
  1.1725 +			branch.at(i)->calcBBoxSizeWithChilds();
  1.1726 +			br=branch.at(i)->getBBoxSizeWithChilds();
  1.1727 +			r.setWidth( max (br.width(), r.width() ));
  1.1728 +			r.setHeight(br.height() + r.height() );
  1.1729 +			if (br.y()<bboxTotal.y()) bboxTotal.setY(br.y());
  1.1730 +		}
  1.1731  	}
  1.1732  	// Add myself and also
  1.1733  	// add width of link to sum if necessary
  1.1734 @@ -1099,13 +1544,25 @@
  1.1735  		bboxTotal.setWidth (bbox.width() + r.width() );
  1.1736  	else	
  1.1737  		bboxTotal.setWidth (bbox.width() + r.width() + linkwidth);
  1.1738 -	bboxTotal.setHeight(max (r.height(),  bbox.height() ) );
  1.1739 -//	frame->setRect(QRect(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
  1.1740 +	
  1.1741 +	bboxTotal.setHeight(max (r.height(),  bbox.height()));
  1.1742  }
  1.1743  
  1.1744  void BranchObj::select()
  1.1745  {
  1.1746 +	// update NoteEditor
  1.1747 +	textEditor->setText(note.getNote() );
  1.1748 +	QString fnh=note.getFilenameHint();
  1.1749 +	if (fnh!="")
  1.1750 +		textEditor->setFilenameHint(note.getFilenameHint() );
  1.1751 +	else	
  1.1752 +		textEditor->setFilenameHint(getHeading() );
  1.1753 +	textEditor->setFontHint (note.getFontHint() );
  1.1754 +	isNoteInEditor=true;
  1.1755 +
  1.1756 +	// set selected and visible
  1.1757      LinkableMapObj::select();
  1.1758 +
  1.1759  	// Tell parent that I am selected now:
  1.1760  	BranchObj* po=(BranchObj*)(parObj);
  1.1761      if (po)	// TODO	    Try to get rid of this cast...
  1.1762 @@ -1114,13 +1571,6 @@
  1.1763  	// temporary unscroll, if we have scrolled parents somewhere
  1.1764  	if (parObj) ((BranchObj*)(parObj))->tmpUnscroll();
  1.1765  
  1.1766 -	// set Text in Editor	
  1.1767 -	textEditor->setText(note.getNote() );
  1.1768 -	textEditor->setFilename(note.getFilenameHint() );
  1.1769 -	textEditor->setFontHint (note.getFontHint() );
  1.1770 -	connect (textEditor, SIGNAL (textHasChanged() ), this, SLOT (updateNoteFlag() ) ); 
  1.1771 -	connect (textEditor, SIGNAL (fontSizeHasChanged() ), this, SLOT (updateNoteFlag() ) ); 
  1.1772 -
  1.1773  	// Show URL and link in statusbar
  1.1774  	QString status;
  1.1775  	if (!url.isEmpty()) status+="URL: "+url+"  ";
  1.1776 @@ -1128,15 +1578,9 @@
  1.1777  	if (!status.isEmpty()) mainWindow->statusMessage (status);
  1.1778  
  1.1779  	// Update Toolbar
  1.1780 -	standardFlags->updateToolBar();
  1.1781 +	updateFlagsToolbar();
  1.1782  
  1.1783 -	// Update Browserbutton
  1.1784 -	if (!url.isEmpty())
  1.1785 -		actionEditOpenURL->setEnabled (true);
  1.1786 -	else	
  1.1787 -		actionEditOpenURL->setEnabled (false);
  1.1788 -
  1.1789 -	// Update actions in mapeditor
  1.1790 +	// Update actions
  1.1791  	mapEditor->updateActions();
  1.1792  }
  1.1793  
  1.1794 @@ -1146,39 +1590,38 @@
  1.1795  	// Delete any messages like vymLink in StatusBar
  1.1796  	mainWindow->statusMessage ("");
  1.1797  
  1.1798 -	// save note from editor and set flag
  1.1799 -	// text is done by updateNoteFlag(), just save
  1.1800 -	// filename here
  1.1801 -	note.setFilenameHint (textEditor->getFilename());
  1.1802 +	// Save current note
  1.1803 +	if (isNoteInEditor) getNoteFromTextEditor();
  1.1804 +	isNoteInEditor=false;
  1.1805  
  1.1806  	// reset temporary unscroll, if we have scrolled parents somewhere
  1.1807  	if (parObj) ((BranchObj*)(parObj))->resetTmpUnscroll();
  1.1808  
  1.1809 -	// Disconnect textEditor from this LMO
  1.1810 -	disconnect( textEditor, SIGNAL(textHasChanged()), 0, 0 );
  1.1811 -	disconnect( textEditor, SIGNAL (fontSizeHasChanged()),0,0 ); 
  1.1812 -
  1.1813  	// Erase content of editor 
  1.1814  	textEditor->setInactive();
  1.1815  
  1.1816  	// unselect all buttons in toolbar
  1.1817 -	standardFlagsDefault->updateToolBar();
  1.1818 +	standardFlagsDefault->updateToolbar();
  1.1819  }
  1.1820  
  1.1821  QString BranchObj::getSelectString()
  1.1822  {
  1.1823 -	QString s;
  1.1824 -	if (parObj)
  1.1825 -	{
  1.1826 -		if (parObj->getDepth()==0)
  1.1827 -			s= "bo:" + QString("%1").arg(getNum());
  1.1828 -		else	
  1.1829 -			s= ((BranchObj*)(parObj))->getSelectString() + ",bo:" + QString("%1").arg(getNum());
  1.1830 -	} else
  1.1831 -	{
  1.1832 -		s="mc:";
  1.1833 -	}
  1.1834 -	
  1.1835 -	return s;
  1.1836 +	return mapEditor->getModel()->getSelectString (this);
  1.1837  }
  1.1838  
  1.1839 +void BranchObj::setAnimation(const AnimPoint &ap)
  1.1840 +{
  1.1841 +	anim=ap;
  1.1842 +}
  1.1843 +
  1.1844 +bool BranchObj::animate()
  1.1845 +{
  1.1846 +	anim.animate ();
  1.1847 +	if ( anim.isAnimated() )
  1.1848 +	{
  1.1849 +		setRelPos (anim);
  1.1850 +		return true;
  1.1851 +	}
  1.1852 +	return false;
  1.1853 +}
  1.1854 +