1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/imageobj.cpp Mon Aug 04 06:52:15 2008 +0000
1.3 @@ -0,0 +1,100 @@
1.4 +#include "imageobj.h"
1.5 +
1.6 +/////////////////////////////////////////////////////////////////
1.7 +// ImageObj
1.8 +/////////////////////////////////////////////////////////////////
1.9 +ImageObj::ImageObj( QCanvas *canvas )
1.10 + : QCanvasRectangle( canvas )
1.11 +{
1.12 +// cout << "Const ImageObj (canvas)\n";
1.13 + setZ(Z_ICON);
1.14 + type=undef;
1.15 +}
1.16 +
1.17 +ImageObj::~ImageObj()
1.18 +{
1.19 +// cout << "Destr ImageObj\n";
1.20 +}
1.21 +
1.22 +void ImageObj::copy(ImageObj* other)
1.23 +{
1.24 + setSize (other->width(), other->height() );
1.25 + setVisibility (other->isVisible() );
1.26 + type=other->type;
1.27 +// if (type==qimage)
1.28 + image=other->image;
1.29 +// if (type==qpixmap)
1.30 + pixmap=other->pixmap;
1.31 +}
1.32 +
1.33 +void ImageObj::setVisibility (bool v)
1.34 +{
1.35 + if (v)
1.36 + show();
1.37 + else
1.38 + hide();
1.39 +}
1.40 +
1.41 +void ImageObj::save(const QString &fn, const char *format)
1.42 +{
1.43 + switch (type)
1.44 + {
1.45 + case undef: qWarning("undef");break;
1.46 + case qimage: image.save (fn,format,-1);break;
1.47 + case qpixmap: pixmap.save (fn,format,-1);break;
1.48 + }
1.49 +}
1.50 +
1.51 +bool ImageObj::load (const QString &fn)
1.52 +{
1.53 + if (!image.load( fn) )
1.54 + //cout << "Fatal Error in ImageObj::load ("<<fn<<")\n";
1.55 + return false;
1.56 + setSize( image.width(), image.height() );
1.57 + type=qimage;
1.58 +
1.59 +#if !defined(Q_WS_QWS)
1.60 + pixmap.convertFromImage(image, OrderedAlphaDither);
1.61 +#endif
1.62 + return true;
1.63 +}
1.64 +
1.65 +bool ImageObj::load (QPixmap pm)
1.66 +{
1.67 +#if !defined(Q_WS_QWS)
1.68 + //pixmap.convertFromImage(image, OrderedAlphaDither);
1.69 + type=qpixmap;
1.70 + pixmap=pm;
1.71 + setSize( pm.width(), pm.height() );
1.72 +#else
1.73 + type=qimage;
1.74 + image=pm;
1.75 + setSize( image.width(), image.height() );
1.76 +#endif
1.77 + return true;
1.78 +}
1.79 +
1.80 +void ImageObj::setImage(QImage img)
1.81 +{
1.82 + type=qimage;
1.83 + image=img;
1.84 + pixmap.convertFromImage(image, OrderedAlphaDither);
1.85 +}
1.86 +
1.87 +QPixmap ImageObj::getPixmap()
1.88 +{
1.89 + return pixmap;
1.90 +}
1.91 +
1.92 +void ImageObj::drawShape( QPainter &p )
1.93 +{
1.94 +// On Qt/Embedded, we can paint a QImage as fast as a QPixmap,
1.95 +// but on other platforms, we need to use a QPixmap.
1.96 +#if defined(Q_WS_QWS)
1.97 + p.drawImage( int(x()), int(y()), image, 0, 0, -1, -1, OrderedAlphaDither );
1.98 +#else
1.99 + p.drawPixmap( int(x()), int(y()), pixmap );
1.100 +#endif
1.101 +}
1.102 +
1.103 +