floatimageobj.cpp
changeset 409 81ffad43d53f
parent 395 7ced3733ba60
child 411 910ba9fab728
     1.1 --- a/floatimageobj.cpp	Mon Oct 30 12:39:37 2006 +0000
     1.2 +++ b/floatimageobj.cpp	Fri Dec 08 20:18:58 2006 +0000
     1.3 @@ -1,8 +1,8 @@
     1.4 +#include <QImageReader>
     1.5 +#include <QPixmap>
     1.6 +
     1.7  #include "floatimageobj.h"
     1.8  #include "branchobj.h"
     1.9 -//Added by qt3to4:
    1.10 -#include <QPixmap>
    1.11 -
    1.12  
    1.13  /////////////////////////////////////////////////////////////////
    1.14  // FloatImageObj
    1.15 @@ -19,15 +19,15 @@
    1.16      depth=-1;
    1.17  }
    1.18  
    1.19 -FloatImageObj::FloatImageObj (Q3Canvas* c):FloatObj(c)
    1.20 +FloatImageObj::FloatImageObj (QGraphicsScene* s):FloatObj(s)
    1.21  {
    1.22 - //   cout << "Const FloatImageObj (c)  called from MapCenterObj (c)\n";
    1.23 + //   cout << "Const FloatImageObj (s)  called from MapCenterObj (s)\n";
    1.24      setParObj (this);	
    1.25      init();
    1.26      depth=-1;
    1.27  }
    1.28  
    1.29 -FloatImageObj::FloatImageObj (Q3Canvas* c, OrnamentedObj* p):FloatObj(c,p)
    1.30 +FloatImageObj::FloatImageObj (QGraphicsScene *s, OrnamentedObj* p):FloatObj(s,p)
    1.31  {
    1.32   //   cout << "Const FloatImageObj (c,p)\n";
    1.33      init();
    1.34 @@ -41,13 +41,12 @@
    1.35  
    1.36  void FloatImageObj::init () 
    1.37  {
    1.38 -	icon=new ImageObj (canvas);
    1.39 -	icon->move (absPos.x(), absPos.y() );
    1.40 +	icon=new ImageObj (scene);
    1.41 +	icon->setPos (absPos.x(), absPos.y() );
    1.42  	icon->setVisibility (true);
    1.43 -	setZ (Z_FLOATIMG);
    1.44 -	bbox.setSize (QSize(icon->size().width(), icon->size().height()));
    1.45 -	clickBox.setSize (QSize(icon->size().width(), icon->size().height()));
    1.46 -	filename="";
    1.47 +	setZValue (Z_FLOATIMG);
    1.48 +	bbox.setSize (QSizeF(icon->boundingRect().width(), icon->boundingRect().height()));
    1.49 +	clickBox.setSize (QSizeF(icon->boundingRect().width(), icon->boundingRect().height()));filename="";
    1.50  	originalFilename="no original name available";
    1.51  	filetype="";
    1.52  	saveInMap=true;
    1.53 @@ -68,35 +67,41 @@
    1.54      positionBBox();
    1.55  }
    1.56  
    1.57 -void FloatImageObj::setZ (const int &i)
    1.58 +void FloatImageObj::setZValue (const int &i)
    1.59  {
    1.60 -	icon->setZ (i);
    1.61 +	icon->setZValue (i);
    1.62  	zPlane=i;
    1.63  }
    1.64  
    1.65  int FloatImageObj::z ()
    1.66  {
    1.67 -	return qRound (icon->z());
    1.68 +	return qRound (icon->zValue());
    1.69  }
    1.70  
    1.71  void FloatImageObj::load (const QPixmap &pixmap)
    1.72  {
    1.73 -  icon->load(pixmap);
    1.74 -  bbox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
    1.75 -  clickBox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
    1.76 -  positionBBox();
    1.77 -  filetype="PNG";
    1.78 -  filename="No filename given";
    1.79 +	icon->load(pixmap);
    1.80 +	bbox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
    1.81 +	clickBox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
    1.82 +	selbox->setRect(0,0,clickBox.width(),clickBox.height());
    1.83 +	positionBBox();
    1.84 +	filetype="PNG";
    1.85 +	filename="No filename given";
    1.86  }
    1.87  
    1.88  bool FloatImageObj::load (const QString &fn)
    1.89  {	
    1.90 -	if( icon->load (fn))
    1.91 +	QImageReader reader (fn);
    1.92 +	QImage img;
    1.93 +
    1.94 +	if( reader.read (&img))
    1.95  	{
    1.96 -		bbox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
    1.97 +		icon->setPixmap(QPixmap::fromImage(img));
    1.98 +		bbox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
    1.99 +		selbox->setRect(0,0,clickBox.width(),clickBox.height());
   1.100  		positionBBox();
   1.101  		filename=fn;
   1.102 -//FIXME QT3 was		filetype=QPixmap::imageFormat (fn);
   1.103 +		filetype=reader.format();
   1.104  		setOriginalFilename (fn);
   1.105  		return true;
   1.106  	} else
   1.107 @@ -135,18 +140,19 @@
   1.108  void FloatImageObj::move (double x, double y)
   1.109  {
   1.110  	FloatObj::move(x,y);
   1.111 -	icon->move (x+4,y+4);
   1.112 +	icon->setPos (x+4,y+4);
   1.113      positionBBox();
   1.114  }
   1.115  
   1.116 -void FloatImageObj::move (QPoint p)
   1.117 +void FloatImageObj::move (QPointF p)
   1.118  {
   1.119 -	move (p.x(), p.y());
   1.120 +	OrnamentedObj::move (p.x(),p.y());
   1.121  }
   1.122  
   1.123  void FloatImageObj::positionBBox()
   1.124  {
   1.125  	clickBox=bbox;
   1.126 +	setSelBox();
   1.127  }
   1.128  
   1.129  void FloatImageObj::calcBBoxSize()
   1.130 @@ -206,12 +212,12 @@
   1.131  }
   1.132  
   1.133  
   1.134 -QRect FloatImageObj::getTotalBBox()
   1.135 +QRectF FloatImageObj::getTotalBBox()
   1.136  {
   1.137  	return bbox;
   1.138  }
   1.139  
   1.140 -QRect FloatImageObj::getBBoxSizeWithChilds()
   1.141 +QRectF FloatImageObj::getBBoxSizeWithChilds()
   1.142  {
   1.143  	//FIXME  abstract in linkablemapobj.h, not calculated
   1.144  	return bboxTotal;