imageobj.cpp
changeset 408 c2a05fa925a1
parent 366 e95081c21da2
child 421 5522d1da7e37
     1.1 --- a/imageobj.cpp	Thu Nov 23 16:18:26 2006 +0000
     1.2 +++ b/imageobj.cpp	Fri Dec 08 20:18:56 2006 +0000
     1.3 @@ -1,16 +1,17 @@
     1.4  #include "imageobj.h"
     1.5 -//Added by qt3to4:
     1.6 -#include <QPixmap>
     1.7 +#include "mapobj.h"
     1.8  
     1.9  /////////////////////////////////////////////////////////////////
    1.10  // ImageObj
    1.11  /////////////////////////////////////////////////////////////////
    1.12 -ImageObj::ImageObj( Q3Canvas *canvas )
    1.13 -    : Q3CanvasRectangle( canvas )
    1.14 +ImageObj::ImageObj( QGraphicsScene *scene) : QGraphicsPixmapItem (NULL,scene )
    1.15  {
    1.16 -//	cout << "Const ImageObj (canvas)\n";
    1.17 -    setZ(Z_ICON);	
    1.18 -	type=undef;
    1.19 +//	cout << "Const ImageObj (scene)\n";
    1.20 +
    1.21 +	setShapeMode (QGraphicsPixmapItem::BoundingRectShape);
    1.22 +    setZValue(Z_ICON);	
    1.23 +	mapScene=scene;
    1.24 +	hide();
    1.25  }
    1.26  
    1.27  ImageObj::~ImageObj()
    1.28 @@ -20,13 +21,9 @@
    1.29  
    1.30  void ImageObj::copy(ImageObj* other)
    1.31  {
    1.32 -	setSize (other->width(), other->height() );
    1.33  	setVisibility (other->isVisible() );
    1.34 -	type=other->type;
    1.35 -//	if (type==qimage)
    1.36 -		image=other->image;
    1.37 -//	if (type==qpixmap)
    1.38 -		pixmap=other->pixmap;
    1.39 +	setPixmap (other->QGraphicsPixmapItem::pixmap());	
    1.40 +	setPos (other->pos());
    1.41  }
    1.42  
    1.43  void ImageObj::setVisibility (bool v)
    1.44 @@ -39,64 +36,24 @@
    1.45  
    1.46  void ImageObj::save(const QString &fn, const char *format)
    1.47  {
    1.48 -	switch (type)
    1.49 -	{
    1.50 -		case undef: qWarning("Warning: ImageObj::save() type=undef");break;
    1.51 -		case qimage: image.save (fn,format,-1);break;
    1.52 -		case qpixmap: pixmap.save (fn,format,-1);break;
    1.53 -	}
    1.54 +	pixmap().save (fn,format,-1);
    1.55  }
    1.56  
    1.57  bool ImageObj::load (const QString &fn)
    1.58  {
    1.59 -	if (!image.load( fn) )
    1.60 -		//cout << "Fatal Error in ImageObj::load ("<<fn<<")\n";
    1.61 -		return false;
    1.62 -    setSize( image.width(), image.height() );
    1.63 -	type=qimage;
    1.64 +	QPixmap pixmap;
    1.65 +    if (pixmap.load (fn)) 
    1.66 +	{
    1.67 +		setPixmap (pixmap);
    1.68 +		return true;
    1.69 +	}	
    1.70 +	return false;
    1.71 +}
    1.72  
    1.73 -#if !defined(Q_WS_QWS)
    1.74 -    pixmap.convertFromImage(image, Qt::OrderedAlphaDither);
    1.75 -#endif
    1.76 +bool ImageObj::load (const QPixmap &pm)
    1.77 +{
    1.78 +	setPixmap (pm);
    1.79  	return true;
    1.80  }
    1.81  
    1.82 -bool ImageObj::load (QPixmap pm)
    1.83 -{
    1.84 -#if !defined(Q_WS_QWS)
    1.85 -    //pixmap.convertFromImage(image, OrderedAlphaDither);
    1.86 -	type=qpixmap;
    1.87 -	pixmap=pm;
    1.88 -    setSize( pm.width(), pm.height() );
    1.89 -#else
    1.90 -	type=qimage;
    1.91 -	image=pm;
    1.92 -    setSize( image.width(), image.height() );
    1.93 -#endif
    1.94 -	return true;
    1.95 -}
    1.96  
    1.97 -void ImageObj::setImage(QImage img)
    1.98 -{
    1.99 -	type=qimage;
   1.100 -	image=img;
   1.101 -    pixmap.convertFromImage(image, Qt::OrderedAlphaDither);
   1.102 -}
   1.103 -
   1.104 -QPixmap ImageObj::getPixmap()
   1.105 -{
   1.106 -	return pixmap;
   1.107 -}
   1.108 -
   1.109 -void ImageObj::drawShape( QPainter &p )
   1.110 -{
   1.111 -// On Qt/Embedded, we can paint a QImage as fast as a QPixmap,
   1.112 -// but on other platforms, we need to use a QPixmap.
   1.113 -#if defined(Q_WS_QWS)
   1.114 -    p.drawImage( int(x()), int(y()), image, 0, 0, -1, -1, Qt::OrderedAlphaDither );
   1.115 -#else
   1.116 -    p.drawPixmap( int(x()), int(y()), pixmap );
   1.117 -#endif
   1.118 -}
   1.119 -
   1.120 -