File: imageobj.cpp

package info (click to toggle)
vym 1.8.1-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,000 kB
  • ctags: 1,599
  • sloc: cpp: 14,723; sh: 373; xml: 277; perl: 89; makefile: 16
file content (100 lines) | stat: -rw-r--r-- 2,026 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "imageobj.h"

/////////////////////////////////////////////////////////////////
// ImageObj
/////////////////////////////////////////////////////////////////
ImageObj::ImageObj( QCanvas *canvas )
    : QCanvasRectangle( canvas )
{
//	cout << "Const ImageObj (canvas)\n";
    setZ(Z_ICON);	
	type=undef;
}

ImageObj::~ImageObj()
{
//   cout << "Destr ImageObj\n";
}

void ImageObj::copy(ImageObj* other)
{
	setSize (other->width(), other->height() );
	setVisibility (other->isVisible() );
	type=other->type;
//	if (type==qimage)
		image=other->image;
//	if (type==qpixmap)
		pixmap=other->pixmap;
}

void ImageObj::setVisibility (bool v)
{
	if (v)	
		show();
	else
		hide();
}

void ImageObj::save(const QString &fn, const char *format)
{
	switch (type)
	{
		case undef: qWarning("Warning: ImageObj::save() type=undef");break;
		case qimage: image.save (fn,format,-1);break;
		case qpixmap: pixmap.save (fn,format,-1);break;
	}
}

bool ImageObj::load (const QString &fn)
{
	if (!image.load( fn) )
		//cout << "Fatal Error in ImageObj::load ("<<fn<<")\n";
		return false;
    setSize( image.width(), image.height() );
	type=qimage;

#if !defined(Q_WS_QWS)
    pixmap.convertFromImage(image, OrderedAlphaDither);
#endif
	return true;
}

bool ImageObj::load (QPixmap pm)
{
#if !defined(Q_WS_QWS)
    //pixmap.convertFromImage(image, OrderedAlphaDither);
	type=qpixmap;
	pixmap=pm;
    setSize( pm.width(), pm.height() );
#else
	type=qimage;
	image=pm;
    setSize( image.width(), image.height() );
#endif
	return true;
}

void ImageObj::setImage(QImage img)
{
	type=qimage;
	image=img;
    pixmap.convertFromImage(image, OrderedAlphaDither);
}

QPixmap ImageObj::getPixmap()
{
	return pixmap;
}

void ImageObj::drawShape( QPainter &p )
{
// On Qt/Embedded, we can paint a QImage as fast as a QPixmap,
// but on other platforms, we need to use a QPixmap.
#if defined(Q_WS_QWS)
    p.drawImage( int(x()), int(y()), image, 0, 0, -1, -1, OrderedAlphaDither );
#else
    p.drawPixmap( int(x()), int(y()), pixmap );
#endif
}