imageobj.cpp
author insilmaril
Fri Jun 16 08:27:10 2006 +0000 (2006-06-16)
changeset 350 13b9befc665e
parent 0 7a96bd401351
child 366 e95081c21da2
permissions -rw-r--r--
1.8.0
     1 #include "imageobj.h"
     2 
     3 /////////////////////////////////////////////////////////////////
     4 // ImageObj
     5 /////////////////////////////////////////////////////////////////
     6 ImageObj::ImageObj( QCanvas *canvas )
     7     : QCanvasRectangle( canvas )
     8 {
     9 //	cout << "Const ImageObj (canvas)\n";
    10     setZ(Z_ICON);	
    11 	type=undef;
    12 }
    13 
    14 ImageObj::~ImageObj()
    15 {
    16 //   cout << "Destr ImageObj\n";
    17 }
    18 
    19 void ImageObj::copy(ImageObj* other)
    20 {
    21 	setSize (other->width(), other->height() );
    22 	setVisibility (other->isVisible() );
    23 	type=other->type;
    24 //	if (type==qimage)
    25 		image=other->image;
    26 //	if (type==qpixmap)
    27 		pixmap=other->pixmap;
    28 }
    29 
    30 void ImageObj::setVisibility (bool v)
    31 {
    32 	if (v)	
    33 		show();
    34 	else
    35 		hide();
    36 }
    37 
    38 void ImageObj::save(const QString &fn, const char *format)
    39 {
    40 	switch (type)
    41 	{
    42 		case undef: qWarning("Warning: ImageObj::save() type=undef");break;
    43 		case qimage: image.save (fn,format,-1);break;
    44 		case qpixmap: pixmap.save (fn,format,-1);break;
    45 	}
    46 }
    47 
    48 bool ImageObj::load (const QString &fn)
    49 {
    50 	if (!image.load( fn) )
    51 		//cout << "Fatal Error in ImageObj::load ("<<fn<<")\n";
    52 		return false;
    53     setSize( image.width(), image.height() );
    54 	type=qimage;
    55 
    56 #if !defined(Q_WS_QWS)
    57     pixmap.convertFromImage(image, OrderedAlphaDither);
    58 #endif
    59 	return true;
    60 }
    61 
    62 bool ImageObj::load (QPixmap pm)
    63 {
    64 #if !defined(Q_WS_QWS)
    65     //pixmap.convertFromImage(image, OrderedAlphaDither);
    66 	type=qpixmap;
    67 	pixmap=pm;
    68     setSize( pm.width(), pm.height() );
    69 #else
    70 	type=qimage;
    71 	image=pm;
    72     setSize( image.width(), image.height() );
    73 #endif
    74 	return true;
    75 }
    76 
    77 void ImageObj::setImage(QImage img)
    78 {
    79 	type=qimage;
    80 	image=img;
    81     pixmap.convertFromImage(image, OrderedAlphaDither);
    82 }
    83 
    84 QPixmap ImageObj::getPixmap()
    85 {
    86 	return pixmap;
    87 }
    88 
    89 void ImageObj::drawShape( QPainter &p )
    90 {
    91 // On Qt/Embedded, we can paint a QImage as fast as a QPixmap,
    92 // but on other platforms, we need to use a QPixmap.
    93 #if defined(Q_WS_QWS)
    94     p.drawImage( int(x()), int(y()), image, 0, 0, -1, -1, OrderedAlphaDither );
    95 #else
    96     p.drawPixmap( int(x()), int(y()), pixmap );
    97 #endif
    98 }
    99 
   100