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