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