branchobj.cpp
changeset 408 c2a05fa925a1
parent 406 1c8ff1928b97
child 411 910ba9fab728
     1.1 --- a/branchobj.cpp	Thu Nov 23 16:18:26 2006 +0000
     1.2 +++ b/branchobj.cpp	Fri Dec 08 20:18:56 2006 +0000
     1.3 @@ -37,25 +37,25 @@
     1.4      depth=-1;
     1.5  }
     1.6  
     1.7 -BranchObj::BranchObj (Q3Canvas* c):OrnamentedObj (c)
     1.8 +BranchObj::BranchObj (QGraphicsScene* s):OrnamentedObj (s)
     1.9  {
    1.10 -//    cout << "Const BranchObj (c)  called from MapCenterObj (c)\n";
    1.11 +//    cout << "Const BranchObj (s)  called from MapCenterObj (s)\n";
    1.12  	parObj=NULL;
    1.13 -    canvas=c;
    1.14 +    scene=s;
    1.15  }
    1.16  
    1.17 -BranchObj::BranchObj (Q3Canvas* c, LinkableMapObj* p):OrnamentedObj (c)
    1.18 +BranchObj::BranchObj (QGraphicsScene* s, LinkableMapObj* p):OrnamentedObj (s)
    1.19  {
    1.20 -//    cout << "Const BranchObj (c,p)\n";
    1.21 -    canvas=c;
    1.22 +//    cout << "Const BranchObj (s,p)\n";
    1.23 +    scene=s;
    1.24      setParObj (p);	
    1.25      depth=p->getDepth()+1;
    1.26  	if (depth==1)
    1.27  		// Calc angle to mapCenter if I am a mainbranch
    1.28  		// needed for reordering the mainbranches clockwise 
    1.29  		// around mapcenter 
    1.30 -		angle=getAngle (QPoint ((int)(x() - parObj->getChildPos().x() ), 
    1.31 -								(int)(y() - parObj->getChildPos().y() ) ) );
    1.32 +		angle=getAngle (QPointF (x() - parObj->getChildPos().x() , 
    1.33 +								(y() - parObj->getChildPos().y() ) ) );
    1.34      init();
    1.35  }
    1.36  
    1.37 @@ -93,7 +93,7 @@
    1.38  		absPos+=parObj->getChildPos();
    1.39  	}
    1.40  
    1.41 -    lastSelectedBranch=-1;
    1.42 +    lastSelectedBranch=0;
    1.43  
    1.44      setChildObj(this);
    1.45  
    1.46 @@ -171,7 +171,7 @@
    1.47  	return xlink.count();
    1.48  }
    1.49  
    1.50 -void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPoint m, int off)
    1.51 +void BranchObj::setParObjTmp(LinkableMapObj* lmo, QPointF m, int off)
    1.52  {
    1.53  	// Temporary link to lmo
    1.54  	// m is position of mouse pointer 
    1.55 @@ -202,17 +202,17 @@
    1.56  	if (depth==1)
    1.57  	{	// new parent is the mapcenter itself
    1.58  
    1.59 -		QPoint p= normalise ( QPoint (m.x() - o->getChildPos().x(),
    1.60 +		QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(),
    1.61  									  m.y() - o->getChildPos().y() ));
    1.62  		if (p.x()<0) p.setX( p.x()-bbox.width() );
    1.63  		move2RelPos (p);
    1.64  	} else
    1.65  	{	
    1.66 -		int y;
    1.67 +		qreal y;
    1.68  		if (off==0)
    1.69  		{
    1.70  			// new parent is just a branch, link to it
    1.71 -			QRect t=o->getBBoxSizeWithChilds();
    1.72 +			QRectF t=o->getBBoxSizeWithChilds();
    1.73  			if (o->getLastBranch())
    1.74  				y=t.y() + t.height() ;
    1.75  			else
    1.76 @@ -547,7 +547,7 @@
    1.77      positionBBox();
    1.78  }
    1.79  
    1.80 -void BranchObj::move (QPoint p)
    1.81 +void BranchObj::move (QPointF p)
    1.82  {
    1.83  	move (p.x(), p.y());
    1.84  }
    1.85 @@ -560,7 +560,7 @@
    1.86      positionBBox();
    1.87  }
    1.88  	
    1.89 -void BranchObj::moveBy (QPoint p)
    1.90 +void BranchObj::moveBy (QPointF p)
    1.91  {
    1.92  	moveBy (p.x(), p.y());
    1.93  }
    1.94 @@ -568,13 +568,13 @@
    1.95  
    1.96  void BranchObj::positionBBox()
    1.97  {
    1.98 -	QPoint ap=getAbsPos();
    1.99 +	QPointF ap=getAbsPos();
   1.100  	bbox.moveTopLeft (ap);
   1.101  	positionContents();
   1.102  	setSelBox();
   1.103  
   1.104  	// set the frame
   1.105 -	frame->setRect(QRect(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
   1.106 +	frame->setRect(QRectF(bbox.x(),bbox.y(),bbox.width(),bbox.height() ) );
   1.107  
   1.108  	// Update links to other branches
   1.109  	for (int i=0; i<xlink.size(); ++i)
   1.110 @@ -583,17 +583,17 @@
   1.111  
   1.112  void BranchObj::calcBBoxSize()
   1.113  {
   1.114 -    QSize heading_r=heading->getSize();
   1.115 -    int heading_w=(int) heading_r.width() ;
   1.116 -    int heading_h=(int) heading_r.height() ;
   1.117 -    QSize sysflags_r=systemFlags->getSize();
   1.118 -	int sysflags_h=sysflags_r.height();
   1.119 -	int sysflags_w=sysflags_r.width();
   1.120 -    QSize stanflags_r=standardFlags->getSize();
   1.121 -	int stanflags_h=stanflags_r.height();
   1.122 -	int stanflags_w=stanflags_r.width();
   1.123 -    int w;
   1.124 -    int h;
   1.125 +    QSizeF heading_r=heading->getSize();
   1.126 +    qreal heading_w=(qreal) heading_r.width() ;
   1.127 +    qreal heading_h=(qreal) heading_r.height() ;
   1.128 +    QSizeF sysflags_r=systemFlags->getSize();
   1.129 +	qreal sysflags_h=sysflags_r.height();
   1.130 +	qreal sysflags_w=sysflags_r.width();
   1.131 +    QSizeF stanflags_r=standardFlags->getSize();
   1.132 +	qreal stanflags_h=stanflags_r.height();
   1.133 +	qreal stanflags_w=stanflags_r.width();
   1.134 +    qreal w;
   1.135 +    qreal h;
   1.136  
   1.137  	// set width to sum of all widths
   1.138  	w=heading_w + sysflags_w + stanflags_w;
   1.139 @@ -602,13 +602,13 @@
   1.140  	h=max (h,heading_h);
   1.141  
   1.142  	// Save the dimension of flags and heading
   1.143 -	ornamentsBBox.setSize ( QSize(w,h));
   1.144 +	ornamentsBBox.setSize ( QSizeF(w,h));
   1.145  
   1.146  	// clickBox includes Flags and Heading
   1.147      clickBox.setSize (ornamentsBBox.size() );
   1.148  
   1.149  	// Floatimages 
   1.150 -	QPoint rp;
   1.151 +	QPointF rp;
   1.152  
   1.153  	topPad=botPad=leftPad=rightPad=0;
   1.154  	if (includeImagesVer || includeImagesHor)
   1.155 @@ -652,7 +652,7 @@
   1.156      h+=frame->getBorder();
   1.157  	
   1.158  	// Finally set size
   1.159 -    bbox.setSize (QSize (w,h));
   1.160 +    bbox.setSize (QSizeF (w,h));
   1.161  }
   1.162  
   1.163  void BranchObj::setDockPos()
   1.164 @@ -660,16 +660,16 @@
   1.165  	// Sets childpos and parpos depending on orientation
   1.166  	if (getOrientation()==OrientLeftOfCenter )
   1.167      {
   1.168 -		childPos=QPoint (ornamentsBBox.bottomLeft().x(), ornamentsBBox.bottomLeft().y() );
   1.169 -		parPos=QPoint (ornamentsBBox.bottomRight().x(),ornamentsBBox.bottomRight().y() );
   1.170 +		childPos=QPointF (ornamentsBBox.bottomLeft().x(), ornamentsBBox.bottomLeft().y() );
   1.171 +		parPos=QPointF (ornamentsBBox.bottomRight().x(),ornamentsBBox.bottomRight().y() );
   1.172      } else
   1.173      {
   1.174 -		childPos=QPoint (ornamentsBBox.bottomRight().x(), ornamentsBBox.bottomRight().y() );
   1.175 -		parPos=QPoint (ornamentsBBox.bottomLeft().x(),ornamentsBBox.bottomLeft().y() );
   1.176 +		childPos=QPointF (ornamentsBBox.bottomRight().x(), ornamentsBBox.bottomRight().y() );
   1.177 +		parPos=QPointF (ornamentsBBox.bottomLeft().x(),ornamentsBBox.bottomLeft().y() );
   1.178      }
   1.179  }
   1.180  
   1.181 -LinkableMapObj* BranchObj::findMapObj(QPoint p, LinkableMapObj* excludeLMO)
   1.182 +LinkableMapObj* BranchObj::findMapObj(QPointF p, LinkableMapObj* excludeLMO)
   1.183  {
   1.184  	// Search branches
   1.185      LinkableMapObj *lmo;
   1.186 @@ -735,7 +735,7 @@
   1.187  		return false;
   1.188  }
   1.189  
   1.190 -QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPoint& offset)
   1.191 +QString BranchObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPointF& offset)
   1.192  {
   1.193  	if (hidden) return "";
   1.194  
   1.195 @@ -757,10 +757,10 @@
   1.196  	if (!((BranchObj*)(parObj))->isScrolled() )
   1.197  	{
   1.198  		areaAttr=
   1.199 -			attribut("x1",QString().setNum(absPos.x()-offset.x(),10)) +
   1.200 -			attribut("y1",QString().setNum(absPos.y()-offset.y(),10)) +
   1.201 -			attribut("x2",QString().setNum(absPos.x()+width()-offset.x(),10)) +
   1.202 -			attribut("y2",QString().setNum(absPos.y()+height()-offset.y(),10));
   1.203 +			attribut("x1",QString().setNum(absPos.x()-offset.x())) +
   1.204 +			attribut("y1",QString().setNum(absPos.y()-offset.y())) +
   1.205 +			attribut("x2",QString().setNum(absPos.x()+width()-offset.x())) +
   1.206 +			attribut("y2",QString().setNum(absPos.y()+height()-offset.y()));
   1.207  
   1.208  	} else
   1.209  		areaAttr="";
   1.210 @@ -913,7 +913,7 @@
   1.211  
   1.212  FloatImageObj* BranchObj::addFloatImage ()
   1.213  {
   1.214 -	FloatImageObj *newfi=new FloatImageObj (canvas,this);
   1.215 +	FloatImageObj *newfi=new FloatImageObj (scene,this);
   1.216  	floatimage.append (newfi);
   1.217  	if (hasScrolledParent(this) )
   1.218  		newfi->setVisibility (false);
   1.219 @@ -929,7 +929,7 @@
   1.220  
   1.221  FloatImageObj* BranchObj::addFloatImage (FloatImageObj *fio)
   1.222  {
   1.223 -	FloatImageObj *newfi=new FloatImageObj (canvas,this);
   1.224 +	FloatImageObj *newfi=new FloatImageObj (scene,this);
   1.225  	floatimage.append (newfi);
   1.226  	newfi->copy (fio);
   1.227  	if (hasScrolledParent(this) )
   1.228 @@ -1000,7 +1000,7 @@
   1.229  
   1.230  BranchObj* BranchObj::addBranch()
   1.231  {
   1.232 -    BranchObj* newbo=new BranchObj(canvas,this);
   1.233 +    BranchObj* newbo=new BranchObj(scene,this);
   1.234      branch.append (newbo);
   1.235      newbo->setParObj(this);
   1.236  	newbo->setDefAttr(NewBranch);
   1.237 @@ -1016,7 +1016,7 @@
   1.238  
   1.239  BranchObj* BranchObj::addBranch(BranchObj* bo)
   1.240  {
   1.241 -    BranchObj* newbo=new BranchObj(canvas,this);
   1.242 +    BranchObj* newbo=new BranchObj(scene,this);
   1.243      branch.append (newbo);
   1.244      newbo->copy(bo);
   1.245      newbo->setParObj(this);
   1.246 @@ -1129,22 +1129,25 @@
   1.247  
   1.248  BranchObj* BranchObj::getLastSelectedBranch ()
   1.249  {
   1.250 -    if (lastSelectedBranch>=0) 
   1.251 -	{
   1.252 -		BranchObj* bo=branch.at(lastSelectedBranch);
   1.253 -		if (bo) return bo;
   1.254 -    }	
   1.255 -    return branch.first();
   1.256 +    if (lastSelectedBranch>=0 && branch.size()>0) 
   1.257 +		return branch.at(lastSelectedBranch);
   1.258 +    return NULL;
   1.259  }
   1.260  
   1.261  BranchObj* BranchObj::getFirstBranch ()
   1.262  {
   1.263 -    return branch.first();
   1.264 +	if (branch.size()>0)
   1.265 +		return branch.first();
   1.266 +	else
   1.267 +		return NULL;
   1.268  }
   1.269  
   1.270  BranchObj* BranchObj::getLastBranch ()
   1.271  {
   1.272 -    return branch.last();
   1.273 +	if (branch.size()>0)
   1.274 +		return branch.last();
   1.275 +	else
   1.276 +		return NULL;
   1.277  }
   1.278  
   1.279  BranchObj* BranchObj::getBranchNum (int i)
   1.280 @@ -1238,9 +1241,9 @@
   1.281  	}	
   1.282  }
   1.283  
   1.284 -void BranchObj::alignRelativeTo (QPoint ref)
   1.285 +void BranchObj::alignRelativeTo (QPointF ref)
   1.286  {
   1.287 -	int th = bboxTotal.height();	
   1.288 +	qreal th = bboxTotal.height();	
   1.289  // TODO testing
   1.290  /*
   1.291  	cout << "BO::alignRelTo "<<getHeading().ascii()<<endl;
   1.292 @@ -1269,7 +1272,7 @@
   1.293  			// Calc angle to mapCenter if I am a mainbranch
   1.294  			// needed for reordering the mainbranches clockwise 
   1.295  			// around mapcenter 
   1.296 -			angle=getAngle (QPoint ((int)(x() - parObj->getChildPos().x() ), 
   1.297 +			angle=getAngle (QPointF ((int)(x() - parObj->getChildPos().x() ), 
   1.298  									(int)(y() - parObj->getChildPos().y() ) ) );
   1.299  		}							
   1.300  	} 
   1.301 @@ -1296,7 +1299,7 @@
   1.302  	if (scrolled) return;
   1.303  
   1.304      // Set reference point for alignment of childs
   1.305 -    QPoint ref2;
   1.306 +    QPointF ref2;
   1.307      if (orientation==OrientLeftOfCenter)
   1.308  		ref2.setX(bbox.topLeft().x() - linkwidth);
   1.309      else	
   1.310 @@ -1336,11 +1339,11 @@
   1.311  		// changes its height,
   1.312  		// all upper LMOs have to change, too.
   1.313  		calcBBoxSizeWithChilds();
   1.314 -		updateLink();	// This update is needed if the canvas is resized 
   1.315 +		updateLink();	// This update is needed if the scene is resized 
   1.316  						// due to excessive moving of a FIO
   1.317  						// FIXME really needed? reposition is also called from updateLink...
   1.318  
   1.319 -	    alignRelativeTo ( QPoint (absPos.x(),
   1.320 +	    alignRelativeTo ( QPointF (absPos.x(),
   1.321  			absPos.y()-(bboxTotal.height()-bbox.height())/2) );
   1.322  		//FIXME branch.sort();	
   1.323  		positionBBox();	// Reposition bbox and contents
   1.324 @@ -1348,7 +1351,7 @@
   1.325  	{
   1.326  		// This is only important for moving branches:
   1.327  		// For editing a branch it isn't called...
   1.328 -	    alignRelativeTo ( QPoint (absPos.x(),
   1.329 +	    alignRelativeTo ( QPointF (absPos.x(),
   1.330  							absPos.y()-(bboxTotal.height()-bbox.height())/2) );
   1.331  	}
   1.332  }
   1.333 @@ -1361,9 +1364,9 @@
   1.334  }
   1.335  
   1.336  
   1.337 -QRect BranchObj::getTotalBBox()
   1.338 +QRectF BranchObj::getTotalBBox()
   1.339  {
   1.340 -	QRect r=bbox;
   1.341 +	QRectF r=bbox;
   1.342  
   1.343  	if (scrolled) return r;
   1.344  
   1.345 @@ -1378,7 +1381,7 @@
   1.346  	return r;
   1.347  }
   1.348  
   1.349 -QRect BranchObj::getBBoxSizeWithChilds()
   1.350 +QRectF BranchObj::getBBoxSizeWithChilds()
   1.351  {
   1.352  	return bboxTotal;
   1.353  }
   1.354 @@ -1419,8 +1422,8 @@
   1.355  		return;
   1.356  	}
   1.357  	
   1.358 -	QRect r(0,0,0,0);
   1.359 -	QRect br;
   1.360 +	QRectF r(0,0,0,0);
   1.361 +	QRectF br;
   1.362  	// Now calculate recursivly
   1.363  	// sum of heights 
   1.364  	// maximum of widths