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