aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/objects/KvsObject_pixmap.cpp
blob: 65f091c50e318225c38c2421f403259998ffa526 (about) (plain) (blame)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
//=============================================================================
//
//   File : KvsObject_pixmap.cpp
//   Creation date : Fri Mar 18 14:30:48 CEST 2005
//   by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor)
//
//   This file is part of the KVIrc irc client distribution
//   Copyright (C) 2005-2008 Alessandro Carbone (elfonol at gmail dot com)
//
//   This program is FREE software. You can redistribute it and/or
//   modify it under the terms of the GNU General Public License
//   as published by the Free Software Foundation; either version 2
//   of the License, or (at your opinion) any later version.
//
//   This program is distributed in the HOPE that it will be USEFUL,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//   See the GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program. If not, write to the Free Software Foundation,
//   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//=============================================================================

#include "KvsObject_pixmap.h"
#include "KvsObject_widget.h"

#include "KvsObject_memoryBuffer.h"
#include "KviAnimatedPixmap.h"

#include "kvi_debug.h"
#include "KviLocale.h"

#include <QFile>

/*
	@doc: pixmap
	@keyterms:
	    pixmap object class
	@title:
		pixmap class
	@type:
		class
	@short:
		This class provide a pixmap.
	@inherits:
		[class]object[/class]
		[class]widget[/class]
	@description:
		The pixmap class is an off-screen, pixel-based paint device.
	@functions:
		!fn: $fill(<colorname, rgb or hsv array value or [<red>,<green>,<blue>][<hue>,<saturation>,<value>],[opacity],[system color:RGB or HSV])
		Fills the pixmap with color and opacity.[br]
		!fn: $resize(<width:integer>,<height:integer>)
		Resizes the pixmap to w width and h height. Set wh or hg to 0, to have a null pixmap.
			!fn: $scale(<width:integer>,<height:integer>,[<aspect_ratio:string>])
			Scales the pixmap or the animation by sx horizontally and sy vertically.
		Aspect_ratio values:
		- IgnoreAspectRatio:the pixmap is scaled ignoring his aspect ratio.
		- KeepAspectRatio: pixmap is scaled to a rectangle as large as possible inside size, preserving the aspect ratio.
		- KeepAspectRatioByExpanding, the pixmap is scaled to a rectangle as small as possible outside size, preserving the aspect ratio.
			Default value is KeepAspectRatio.
			!fn: $load(<file_name:string>)
			Load a pixmap from the file <file_name>.
			!fn: $save(<file_name:string>)
			Save the pixmap or the current animation frame to the file <file_name>.
			!fn: $loadAnimation(<file_name:string>)
			Load an animation from the file <file_name> and start it.
			!fn: $startAnimation()
			Start the animation.
			!fn: $stopAnimation()
			Stop the animation.
		!fn: <integer> $height()
			Return the height of the pixmap or of the animation.
		!fn: <integer> $width()
			Return the width of the pixmap or of the animation.
			!fn: $frameChangedEvent()
			This event is triggered by KVIrc when the current animation frame changes.
		@signals:
			!sg: $frameChanged()
			This signal is emitted by the default implementation of [classfnc]$frameChangedEvent[/classfnc]().[br]

*/


KVSO_BEGIN_REGISTERCLASS(KvsObject_pixmap,"pixmap","object")

	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,fill)
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,resize)
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,scale)
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,load)
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,loadAnimation)
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,save)
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,startAnimation)
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,stopAnimation)
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,loadFromMemoryBuffer)
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,height)
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,width)
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,rotate)
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,mirrored)
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,setPixel)
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,pixel)
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,grabWidget)
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,frameChangedEvent)


KVSO_END_REGISTERCLASS(KvsObject_pixmap)


KVSO_BEGIN_CONSTRUCTOR(KvsObject_pixmap,KviKvsObject)
	m_pAnimatedPixmap = 0;
	m_currentType = Image;
	m_pPixmap = 0;
	m_pImage = 0;
KVSO_END_CONSTRUCTOR(KvsObject_pixmap)


KVSO_BEGIN_DESTRUCTOR(KvsObject_pixmap)
	emit aboutToDie();
	if (m_pPixmap)
		delete m_pPixmap;
	if (m_pAnimatedPixmap)
		delete m_pAnimatedPixmap;
	if (m_pImage)
		delete m_pImage;
KVSO_END_CONSTRUCTOR(KvsObject_pixmap)


KVSO_CLASS_FUNCTION(pixmap,fill)
{
	kvs_int_t iCol1,iCol2,iCol3,iOpacity;
	QString szColorMode,szColor;
	KviKvsVariant *var1,*var2,*var3;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("Color_1_Or_Colorname",KVS_PT_VARIANT,0,var1)
		KVSO_PARAMETER("Color_2",KVS_PT_VARIANT,KVS_PF_OPTIONAL,var2)
		KVSO_PARAMETER("Colo3_3",KVS_PT_VARIANT,KVS_PF_OPTIONAL,var3)
		KVSO_PARAMETER("color_mode",KVS_PT_STRING,KVS_PF_OPTIONAL,szColorMode)
		KVSO_PARAMETER("opacity",KVS_PT_INT,KVS_PF_OPTIONAL,iOpacity)
	KVSO_PARAMETERS_END(c)

	QColor col;
	if (!var1->asInteger(iCol1))
	{
		var1->asString(szColor);
		if (c->paramCount()<2) 
			iOpacity=255;
		else {
			if (!var2->asInteger(iOpacity))
			{
				c->warning(__tr2qs_ctx("The opacity parameter didn't evaluate to integer","objects"));
				return true;
			}
		}
		col.setNamedColor(szColor);
		col.setAlpha(iOpacity);
	} else {
		if(c->paramCount()<3)
		{
			c->error(__tr2qs_ctx("Color name or triplette rgb/hsv value required","objects"));
			return true;
		}
		if (!var2->asInteger(iCol2)||!var3->asInteger(iCol3))
		{
			c->error(__tr2qs_ctx("One of the triplette parameters didn't evaluate to an integer","objects"));\
			return true;
		}
		if (c->paramCount()<5)
			iOpacity=255;

		if(KviQString::equalCI(szColorMode, "HSV"))
			col.setHsv(iCol1,iCol2,iCol3,iOpacity);
		else
			col.setRgb(iCol1,iCol2,iCol3,iOpacity);
	}
	if(m_currentType==Image)
	{
		if(m_pImage)
		{
			if(!m_pPixmap)
				m_pPixmap = new QPixmap();
			*m_pPixmap = QPixmap::fromImage(*m_pImage);
			delete m_pImage;
			m_pImage = 0;
		} else {
			m_pPixmap = 0;
		}
	} else if(m_currentType==AnimatedPixmap) {
	      delete m_pAnimatedPixmap;
	      m_pAnimatedPixmap=0;
	}
	m_currentType = Pixmap;
	if(!m_pPixmap)
		m_pPixmap=new QPixmap();
	m_pPixmap->fill(col);
	return true;
}

KVSO_CLASS_FUNCTION(pixmap,resize)
{
	kvs_int_t iWidth,iHeight;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("width",KVS_PT_INTEGER,0,iWidth)
		KVSO_PARAMETER("height",KVS_PT_INTEGER,0,iHeight)
	KVSO_PARAMETERS_END(c)

	if(m_currentType==Image)
	{
		if(m_pImage)
		{
			delete m_pImage;
			m_pImage = 0;
		}
	}
	else if(m_currentType==AnimatedPixmap) {
		if(m_pAnimatedPixmap)
		{
			delete m_pAnimatedPixmap;
			m_pAnimatedPixmap=0;
		}
	} else if(m_pPixmap) {
		delete m_pPixmap;
	}
	m_currentType = Image;
	m_pImage=new QImage(iWidth,iHeight,QImage::Format_ARGB32_Premultiplied);
	m_pImage->fill(Qt::transparent);
	return true;
}

KVSO_CLASS_FUNCTION(pixmap,setPixel)
{
	kvs_int_t iCol1,iCol2,iCol3,iOpacity,iX,iY;
	QString szColorMode,szColor;
	KviKvsVariant *var1,*var2,*var3;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("x",KVS_PT_INTEGER,0,iX)
		KVSO_PARAMETER("y",KVS_PT_INTEGER,0,iY)
		KVSO_PARAMETER("Color_1_Or_Colorname",KVS_PT_VARIANT,0,var1)
		KVSO_PARAMETER("Color_2",KVS_PT_VARIANT,KVS_PF_OPTIONAL,var2)
		KVSO_PARAMETER("Colo3_3",KVS_PT_VARIANT,KVS_PF_OPTIONAL,var3)
		KVSO_PARAMETER("color_mode",KVS_PT_STRING,KVS_PF_OPTIONAL,szColorMode)
		KVSO_PARAMETER("opacity",KVS_PT_INT,KVS_PF_OPTIONAL,iOpacity)
	KVSO_PARAMETERS_END(c)

	QColor col;
	if (!var1->asInteger(iCol1))
	{
		var1->asString(szColor);
		if (c->paramCount()<4)
		{
			iOpacity=255;
		} else {
			if (!var2->asInteger(iOpacity))
			{
				c->warning(__tr2qs_ctx("The opacity parameter didn't evaluate to integer","objects"));
				return true;
			}
		}
		col.setNamedColor(szColor);
		col.setAlpha(iOpacity);
	} else {
		if(c->paramCount()<5)
		{
			c->error(__tr2qs_ctx("Color name or triplette rgb/hsv value required","objects"));
			return true;
		}
		if (!var2->asInteger(iCol2)||!var3->asInteger(iCol3))
		{
			c->error(__tr2qs_ctx("One of the triplette parameters didn't evaluate to an integer","objects"));\
			return true;
		}
		if (c->paramCount()<7)
			iOpacity=255;

		if(KviQString::equalCI(szColorMode, "HSV"))
			col.setHsv(iCol1,iCol2,iCol3,iOpacity);
		else
			col.setRgb(iCol1,iCol2,iCol3,iOpacity);
	}

	if(m_currentType==AnimatedPixmap)
	{
		c->warning(__tr2qs_ctx("AnimatedPixmap not supported","objects"));
		return true;
	} else if((m_currentType==Image && !m_pImage) || (m_currentType==Pixmap && !m_pPixmap)) {
		c->error(__tr2qs_ctx("The pixmap is null","objects"));
		return false;
	} else if(m_currentType==Pixmap) {
		if(m_pImage)
			delete m_pImage;
		*m_pImage = m_pPixmap->toImage();
		delete m_pPixmap;
	}
	m_currentType = Image;
	m_pImage->setPixel(iX,iY,col.rgba());
	return true;
}

KVSO_CLASS_FUNCTION(pixmap,pixel)
{
	kvs_int_t iX,iY;
	QString szFlags;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("x",KVS_PT_INTEGER,0,iX)
		KVSO_PARAMETER("y",KVS_PT_INTEGER,0,iY)
		KVSO_PARAMETER("b",KVS_PT_STRING,KVS_PF_OPTIONAL,szFlags)
	KVSO_PARAMETERS_END(c)

	if(m_currentType==AnimatedPixmap)
	{
		c->warning(__tr2qs_ctx("AnimatedPixmap not supported","objects"));
		return true;
	} else if((m_currentType==Image && !m_pImage) || (m_currentType==Pixmap && !m_pPixmap)) {
		c->error(__tr2qs_ctx("The pixmap is null","objects"));
		return false;
	} else if(m_currentType==Pixmap) {
		qDebug("mpimage %i",m_pImage);
		qDebug("pixmap %i %i",m_pPixmap->width(),m_pPixmap->height());
		if(m_pImage)
			delete m_pImage;
		else m_pImage = new QImage();
		*m_pImage = m_pPixmap->toImage();
		delete m_pPixmap;
		m_pPixmap = 0;
	}
	m_currentType = Image;
	QRgb rgb= m_pImage->pixel(iX,iY);
	QColor col(rgb);
	if(szFlags.isEmpty()){
		c->returnValue()->setString(col.name());
		return true;
	}
	KviKvsVariant *pRed = new KviKvsVariant((kvs_int_t)col.red());
	KviKvsVariant *pGreen = new KviKvsVariant((kvs_int_t)col.green());
	KviKvsVariant *pBlue = new KviKvsVariant((kvs_int_t)col.blue());
	if (szFlags.indexOf('a',0,Qt::CaseInsensitive) != -1){
		KviKvsArray *pArray = new KviKvsArray();
		pArray->set(0,pRed);
		pArray->set(1,pGreen);
		pArray->set(2,pBlue);
		c->returnValue()->setArray(pArray);
	} else if (szFlags.indexOf('h',0,Qt::CaseInsensitive) != -1){
		KviKvsHash *pHash = new KviKvsHash();
		pHash->set("red",pRed);
		pHash->set("green",pGreen);
		pHash->set("blue",pBlue);
	}
	return true;
}
KVSO_CLASS_FUNCTION(pixmap,rotate)
{
	kvs_real_t dAngle;
	QString szAxis;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("angle",KVS_PT_DOUBLE,0,dAngle)
		KVSO_PARAMETER("axis",KVS_PT_STRING,KVS_PF_OPTIONAL,szAxis)
	KVSO_PARAMETERS_END(c)

	Qt::Axis axis = Qt::ZAxis;
	if(!szAxis.isEmpty())
	{
		if (KviQString::equalCI(szAxis,"XAxis"))
			axis=Qt::XAxis;
		else if (KviQString::equalCI(szAxis,"YAxis")) 
			axis=Qt::YAxis;
		else if (KviQString::equalCI(szAxis,"ZAxis")) 
			axis=Qt::ZAxis;
		else 
			c->warning(__tr2qs_ctx("Unknown axis '%Q' switching to default ZAxis","objects"),&szAxis);
	}

	if(m_currentType==Pixmap)
	{
		if(m_pPixmap)
		{
			if(!m_pImage)
				m_pImage = new QImage();
			*m_pImage = m_pPixmap->toImage();
		} else {
			c->error(__tr2qs_ctx("The pixmap is null","objects"));
			return false;
		}
	} else if(m_currentType==AnimatedPixmap) {
		c->warning(__tr2qs_ctx("AnimatedPixmap not supported","objects"));
		return true;
	}

	if(!m_pImage)
	{
		c->error(__tr2qs_ctx("The pixmap is null","objects"));
		return false;
	}
	m_currentType = Image;
	QTransform transform;
	transform.rotate(dAngle,axis);
	*m_pImage=m_pImage->transformed(transform);
	return true;
}


KVSO_CLASS_FUNCTION(pixmap,mirrored)
{
        bool bHorizontal,bVertical;

	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("bHorizontal",KVS_PT_BOOLEAN,0,bHorizontal)
	        KVSO_PARAMETER("bvertical",KVS_PT_BOOLEAN,0,bVertical)
	KVSO_PARAMETERS_END(c)
	if(m_currentType==Pixmap)
	{
		if(m_pPixmap)
		{
			if(!m_pImage) m_pImage = new QImage();
			*m_pImage = m_pPixmap->toImage();
		} else {
			c->error(__tr2qs_ctx("The pixmap is null","objects"));
			return false;
		}
	} else if(m_currentType==AnimatedPixmap) {
		c->warning(__tr2qs_ctx("AnimatedPixmap not supported","objects"));
		return true;
	}

	if(!m_pImage)
	{
		c->error(__tr2qs_ctx("The pixmap is null","objects"));
		return false;
	}
	m_currentType = Image;
	*m_pImage=m_pImage->mirrored(bHorizontal,bVertical);
	return true;
}



KVSO_CLASS_FUNCTION(pixmap,scale)
{
        kvs_int_t iWidth,iHeight;
        QString szAspectRatio;
        KVSO_PARAMETERS_BEGIN(c)
            KVSO_PARAMETER("width",KVS_PT_INTEGER,0,iWidth)
            KVSO_PARAMETER("height",KVS_PT_INTEGER,0,iHeight)
            KVSO_PARAMETER("aspect_ratio",KVS_PT_STRING,KVS_PF_OPTIONAL,szAspectRatio)
        KVSO_PARAMETERS_END(c)
        Qt::AspectRatioMode ratio=Qt::KeepAspectRatio;
        if(!szAspectRatio.isEmpty())
        {
            if(KviQString::equalCI(szAspectRatio,"IgnoreAspectRatio")) ratio=Qt::IgnoreAspectRatio;
            else if (KviQString::equalCI(szAspectRatio,"KeepAspectRatio")) ratio=Qt::KeepAspectRatio;
            else if (KviQString::equalCI(szAspectRatio,"KeepAspectRatioByExpanding")) ratio=Qt::KeepAspectRatioByExpanding;
            else  c->warning(__tr2qs_ctx("Unknown aspect ratio %Q - Switching to KeepAspectRatio ratio","objects"),&szAspectRatio);
        }
        if(m_currentType==Pixmap)
        {
	        if(m_pPixmap)
		*m_pPixmap=m_pPixmap->scaled(iWidth,iHeight,ratio,Qt::SmoothTransformation);
	        else{
		    c->error(__tr2qs_ctx("The pixmap is null","objects"));
		    return false;
	        }
        }
        else if (m_currentType==AnimatedPixmap)
	        m_pAnimatedPixmap->resize(QSize(iWidth,iHeight),ratio);
        else if(m_currentType==Image)
        {
		if(!m_pImage)
		{
			c->error(__tr2qs_ctx("The pixmap is null","objects"));
			return false;
		}
		*m_pImage=m_pImage->scaled(iWidth,iHeight,ratio,Qt::SmoothTransformation);
        }
        return true;
}

KVSO_CLASS_FUNCTION(pixmap,loadAnimation)
{
	QString szFile;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("file",KVS_PT_STRING,0,szFile)
	KVSO_PARAMETERS_END(c)

	if(!QFile::exists(szFile))
	{
		c->warning(__tr2qs_ctx("I can't find the specified file '%Q'.","objects"),&szFile);
		return true;
	}
	if (m_pAnimatedPixmap) {
		delete m_pAnimatedPixmap;
		m_pAnimatedPixmap = 0;
	}
	if (m_pPixmap)
	{
		delete m_pPixmap;
		m_pPixmap=0;
	}
	m_pAnimatedPixmap= new KviAnimatedPixmap(szFile);
	connect(m_pAnimatedPixmap,SIGNAL(frameChanged()),this,SLOT(frameChanged()));
	return true;
}

KVSO_CLASS_FUNCTION(pixmap,startAnimation)
{
	Q_UNUSED(c);
	if (m_pAnimatedPixmap)
		m_pAnimatedPixmap->start();
	return true;
}

KVSO_CLASS_FUNCTION(pixmap,stopAnimation)
{
	Q_UNUSED(c);
	if (m_pAnimatedPixmap)
		m_pAnimatedPixmap->stop();
	return true;
}

KVSO_CLASS_FUNCTION(pixmap,load)
{
	QString szFile;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("file",KVS_PT_STRING,0,szFile)
	KVSO_PARAMETERS_END(c)

	if(!QFile::exists(szFile))
	{
		c->warning(__tr2qs_ctx("I can't find the specified file '%Q'.","objects"),&szFile);
		return true;
	}
	if(!m_pImage)
		m_pImage=new QImage();
	m_currentType = Image;
	m_pImage->load(szFile);
	return true;
/*
 *	FIXME UNUSED CODE
	if (m_currentType==Image && m_pImage)
		delete m_pImage;
	else if (m_currentType==AnimatedPixmap && m_pAnimatedPixmap)
		delete m_pAnimatedPixmap;
	if(!m_pPixmap) m_pPixmap=new QPixmap();
	m_currentType=Pixmap;
	m_pPixmap->load(szFile);
	qDebug("alpha %i",m_pPixmap->hasAlpha());
	return true;
*/
}

KVSO_CLASS_FUNCTION(pixmap,save)
{
	QString szFile;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("file",KVS_PT_STRING,0,szFile)
	KVSO_PARAMETERS_END(c)

	if(m_currentType==Pixmap)
	{
		if(m_pPixmap)
		{
			m_pPixmap->save(szFile);
		} else {
			c->error(__tr2qs_ctx("The pixmap is null","objects"));
			return false;
		}
	} else if(m_currentType==Image) {
		if(m_pImage)
		{
			m_pImage->save(szFile);
		} else {
			c->error(__tr2qs_ctx("The pixmap is null","objects"));
			return false;
		}
	} else {
		m_pAnimatedPixmap->pixmap()->save(szFile);
	}
	return true;
}

void KvsObject_pixmap::setInternalPixmap(QPixmap *pPixmap)
{
	if(m_currentType==Image && m_pImage)
		delete m_pImage;
	else if(m_currentType==Pixmap && m_pPixmap)
		delete m_pPixmap;
	m_currentType=Pixmap;
	m_pPixmap=pPixmap;
}
void KvsObject_pixmap::setInternalImage(QImage *pImage)
{
	if(m_currentType==Image && m_pImage)
		delete m_pImage;
	else if(m_currentType==Pixmap && m_pPixmap)
		delete m_pPixmap;
	m_currentType=Image;
	m_pImage=pImage;
}
KVSO_CLASS_FUNCTION(pixmap,loadFromMemoryBuffer)
{
	KviKvsObject * pObject;
	kvs_hobject_t hObject;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("hobject",KVS_PT_HOBJECT,0,hObject)
	KVSO_PARAMETERS_END(c)

	pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject);
	if (!pObject)
	{
		c->warning(__tr2qs_ctx("Buffer parameter is not an object","objects"));
		return true;
	}
	if (!pObject->inheritsClass("memorybuffer"))
	{
		c->warning(__tr2qs_ctx("Buffer parameter is not a memorybuffer object","objects"));
		return true;
	}
	if (m_pAnimatedPixmap)
	{
		delete m_pAnimatedPixmap;
		m_pAnimatedPixmap=0;
	}
	if (!m_pPixmap)
		m_pPixmap=new QPixmap();
	m_pPixmap->loadFromData(((KvsObject_memoryBuffer *)pObject)->dataBuffer());
	return true;
}

KVSO_CLASS_FUNCTION(pixmap,grabWidget)
{
	CHECK_INTERNAL_POINTER(m_pPixmap)
	KviKvsObject * pObject;
	kvs_hobject_t hObject;
	KVSO_PARAMETERS_BEGIN(c)
	       KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject)
	KVSO_PARAMETERS_END(c)

	pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject);
	CHECK_HOBJECT_IS_WIDGET(pObject)
	if (m_pAnimatedPixmap)
	{
		delete m_pAnimatedPixmap;
		m_pAnimatedPixmap=0;
	}
	if (!m_pPixmap)
		m_pPixmap=new QPixmap();
	*m_pPixmap=QPixmap::grabWidget(((KvsObject_widget *)pObject)->widget());
	return true;

/*	FIXME UNUSED CODE
	QString szFileName;
	KVSO_PARAMETERS_BEGIN(c)
			KVSO_PARAMETER("file_name",KVS_PT_STRING,0,szFileName)
	KVSO_PARAMETERS_END(c)
	QPrinter printer;//(QPrinter::HighResolution);
	printer.setOutputFormat(QPrinter::PdfFormat);
	printer.setPaperSize(QPrinter::A4);
	printer.setOutputFileName(szFileName);

	QPixmap pixmap=QPixmap::grabWidget(((QTableWidget *)widget()));
	QPainter painter(&printer);
	painter.drawPixmap(QPoint(0,0), pixmap, pixmap.rect());
*/
}

KVSO_CLASS_FUNCTION(pixmap,height)
{
	if (m_currentType==Image && m_pImage)
		 c->returnValue()->setInteger(m_pImage->height());
	else if(m_currentType==Pixmap && m_pPixmap)
		c->returnValue()->setInteger(m_pPixmap->height());
	else
		c->returnValue()->setInteger(0);
	//else if(m_pAnimatedPixmap) c->returnValue()->setInteger(m_pAnimatedPixmap->size().height());
	//else c->returnValue()->setInteger(m_pPixmap->height());
	return true;
}

KVSO_CLASS_FUNCTION(pixmap,width)
{
	if (m_currentType==Image && m_pImage)
		c->returnValue()->setInteger(m_pImage->width());
	else if(m_currentType==Pixmap && m_pPixmap)
		c->returnValue()->setInteger(m_pPixmap->width());
	else
		c->returnValue()->setInteger(0);
	//else if(m_pAnimatedPixmap) c->returnValue()->setInteger(m_pAnimatedPixmap->size().height());
	//else c->returnValue()->setInteger(m_pPixmap->height());
	 return true;
}

/*QPixmap * KvsObject_pixmap::getPixmap()
{
	if (!m_pAnimatedPixmap && !m_pPixmap) return new QPixmap();
	else if(m_pAnimatedPixmap) return m_pAnimatedPixmap->pixmap();
	else return m_pPixmap;
}*/
KVSO_CLASS_FUNCTION(pixmap,frameChangedEvent)
{
	emitSignal("frameChanged",c);
	return true;
}

// slots
void KvsObject_pixmap::frameChanged()
{
	KviKvsVariantList *params=0;
	callFunction(this,"frameChangedEvent",params);
}

#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
#include "m_KvsObject_pixmap.moc"
#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES