~ubuntu-branches/ubuntu/trusty/kvirc/trusty-proposed

« back to all changes in this revision

Viewing changes to src/modules/objects/KvsObject_pixmap.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=============================================================================
 
2
//
 
3
//   File : KvsObject_pixmap.cpp
 
4
//   Creation date : Fri Mar 18 14:30:48 CEST 2005
 
5
//   by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor)
 
6
//
 
7
//   This file is part of the KVIrc irc client distribution
 
8
//   Copyright (C) 2005-2008 Alessandro Carbone (elfonol at gmail dot com)
 
9
//
 
10
//   This program is FREE software. You can redistribute it and/or
 
11
//   modify it under the terms of the GNU General Public License
 
12
//   as published by the Free Software Foundation; either version 2
 
13
//   of the License, or (at your opinion) any later version.
 
14
//
 
15
//   This program is distributed in the HOPE that it will be USEFUL,
 
16
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
18
//   See the GNU General Public License for more details.
 
19
//
 
20
//   You should have received a copy of the GNU General Public License
 
21
//   along with this program. If not, write to the Free Software Foundation,
 
22
//   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
23
//
 
24
//=============================================================================
 
25
 
 
26
#include "KvsObject_pixmap.h"
 
27
#include "KvsObject_widget.h"
 
28
 
 
29
#include "KvsObject_memoryBuffer.h"
 
30
#include "KviAnimatedPixmap.h"
 
31
 
 
32
#include "kvi_debug.h"
 
33
#include "KviLocale.h"
 
34
 
 
35
#include <QFile>
 
36
 
 
37
/*
 
38
        @doc:   pixmap
 
39
        @keyterms:
 
40
            pixmap object class
 
41
        @title:
 
42
                pixmap class
 
43
        @type:
 
44
                class
 
45
        @short:
 
46
                This class provide a pixmap.
 
47
        @inherits:
 
48
                [class]object[/class]
 
49
                [class]widget[/class]
 
50
        @description:
 
51
                The pixmap class is an off-screen, pixel-based paint device.
 
52
        @functions:
 
53
                !fn: $fill(<widget:object>,<x_offset:integer>,<y:offset>)
 
54
                Fills the pixmap with the widget's background color or pixmap.[br]
 
55
                Note that x_offset, y_offest are offsets in the widget.
 
56
                !fn: $resize(<width:integer>,<height:integer>)
 
57
                Resizes the pixmap to w width and h height. Set wh or hg to 0, to have a null pixmap.
 
58
                        !fn: $scale(<width:integer>,<height:integer>,[<aspect_ratio:string>])
 
59
                        Scales the pixmap or the animation by sx horizontally and sy vertically.
 
60
                Aspect_ratio values:
 
61
                - IgnoreAspectRatio:the pixmap is scaled ignoring his aspect ratio.
 
62
                - KeepAspectRatio: pixmap is scaled to a rectangle as large as possible inside size, preserving the aspect ratio.
 
63
                - KeepAspectRatioByExpanding, the pixmap is scaled to a rectangle as small as possible outside size, preserving the aspect ratio.
 
64
                        Default value is KeepAspectRatio.
 
65
                        !fn: $load(<file_name:string>)
 
66
                        Load a pixmap from the file <file_name>.
 
67
                        !fn: $save(<file_name:string>)
 
68
                        Save the pixmap or the current animation frame to the file <file_name>.
 
69
                        !fn: $loadAnimation(<file_name:string>)
 
70
                        Load an animation from the file <file_name> and start it.
 
71
                        !fn: $startAnimation()
 
72
                        Start the animation.
 
73
                        !fn: $stopAnimation()
 
74
                        Stop the animation.
 
75
                !fn: <integer> $height()
 
76
                        Return the height of the pixmap or of the animation.
 
77
                !fn: <integer> $width()
 
78
                        Return the width of the pixmap or of the animation.
 
79
                        !fn: $frameChangedEvent()
 
80
                        This event is triggered by KVIrc when the current animation frame changes.
 
81
              @signals:
 
82
                        !sg: $frameChanged()
 
83
                        This signal is emitted by the default implementation of [classfnc]$frameChangedEvent[/classfnc]().[br]
 
84
 
 
85
*/
 
86
 
 
87
 
 
88
KVSO_BEGIN_REGISTERCLASS(KvsObject_pixmap,"pixmap","object")
 
89
 
 
90
        KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,fill)
 
91
        KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,resize)
 
92
        KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,scale)
 
93
        KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,load)
 
94
        KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,loadAnimation)
 
95
        KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,save)
 
96
        KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,startAnimation)
 
97
        KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,stopAnimation)
 
98
        KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,loadFromMemoryBuffer)
 
99
        KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,height)
 
100
        KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,width)
 
101
        KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,grabWidget)
 
102
        KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_pixmap,frameChangedEvent)
 
103
 
 
104
KVSO_END_REGISTERCLASS(KvsObject_pixmap)
 
105
 
 
106
 
 
107
KVSO_BEGIN_CONSTRUCTOR(KvsObject_pixmap,KviKvsObject)
 
108
        m_pAnimatedPixmap = 0;
 
109
        m_pPixmap = 0;
 
110
KVSO_END_CONSTRUCTOR(KvsObject_pixmap)
 
111
 
 
112
 
 
113
KVSO_BEGIN_DESTRUCTOR(KvsObject_pixmap)
 
114
        emit aboutToDie();
 
115
        if (m_pPixmap)delete m_pPixmap;
 
116
        if (m_pAnimatedPixmap) delete m_pAnimatedPixmap;
 
117
KVSO_END_CONSTRUCTOR(KvsObject_pixmap)
 
118
 
 
119
 
 
120
KVSO_CLASS_FUNCTION(pixmap,fill)
 
121
{
 
122
        KviKvsObject *pObject;
 
123
        kvs_int_t iXoffset,iYoffset;
 
124
        kvs_hobject_t hObject;
 
125
        KVSO_PARAMETERS_BEGIN(c)
 
126
            KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject)
 
127
            KVSO_PARAMETER("x_offset",KVS_PT_INT,0,iXoffset)
 
128
            KVSO_PARAMETER("y_offset",KVS_PT_INT,0,iYoffset)
 
129
        KVSO_PARAMETERS_END(c)
 
130
 
 
131
        pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject);
 
132
        CHECK_HOBJECT_IS_WIDGET(pObject)
 
133
        if (m_pAnimatedPixmap)
 
134
        {
 
135
              delete m_pAnimatedPixmap;
 
136
              m_pAnimatedPixmap=0;
 
137
        }
 
138
        if(!m_pPixmap) m_pPixmap=new QPixmap();
 
139
        m_pPixmap->fill(((QWidget *)(pObject->object())),iXoffset,iYoffset);
 
140
        return true;
 
141
}
 
142
KVSO_CLASS_FUNCTION(pixmap,resize)
 
143
{
 
144
        kvs_int_t iWidth,iHeight;
 
145
        KVSO_PARAMETERS_BEGIN(c)
 
146
            KVSO_PARAMETER("width",KVS_PT_INTEGER,0,iWidth)
 
147
            KVSO_PARAMETER("height",KVS_PT_INTEGER,0,iHeight)
 
148
        KVSO_PARAMETERS_END(c)
 
149
        if(m_pPixmap) delete m_pPixmap;
 
150
        if (m_pAnimatedPixmap){
 
151
           delete m_pAnimatedPixmap;
 
152
           m_pAnimatedPixmap=0;
 
153
        }
 
154
        m_pPixmap=new QPixmap(iWidth,iHeight);
 
155
        return true;
 
156
}
 
157
KVSO_CLASS_FUNCTION(pixmap,scale)
 
158
{
 
159
        kvs_int_t iWidth,iHeight;
 
160
        QString szAspectRatio;
 
161
        KVSO_PARAMETERS_BEGIN(c)
 
162
            KVSO_PARAMETER("width",KVS_PT_INTEGER,0,iWidth)
 
163
            KVSO_PARAMETER("height",KVS_PT_INTEGER,0,iHeight)
 
164
            KVSO_PARAMETER("aspect_ratio",KVS_PT_STRING,KVS_PF_OPTIONAL,szAspectRatio)
 
165
        KVSO_PARAMETERS_END(c)
 
166
        Qt::AspectRatioMode ratio=Qt::KeepAspectRatio;
 
167
        if(!m_pPixmap || m_pAnimatedPixmap) return true;
 
168
        if(!szAspectRatio.isEmpty())
 
169
        {
 
170
            if(KviQString::equalCI(szAspectRatio,"IgnoreAspectRatio")) ratio=Qt::IgnoreAspectRatio;
 
171
            else if (KviQString::equalCI(szAspectRatio,"KeepAspectRatio")) ratio=Qt::KeepAspectRatio;
 
172
            else if (KviQString::equalCI(szAspectRatio,"KeepAspectRatioByExpanding")) ratio=Qt::KeepAspectRatioByExpanding;
 
173
            else  c->warning(__tr2qs_ctx("Unknown aspect ratio %Q - Switching to KeepAspectRatio ratio","objects"),&szAspectRatio);
 
174
        }
 
175
        if (m_pAnimatedPixmap) m_pAnimatedPixmap->resize(QSize(iWidth,iHeight),ratio);
 
176
        else *m_pPixmap=m_pPixmap->scaled(iWidth,iHeight,ratio,Qt::SmoothTransformation);
 
177
        return true;
 
178
}
 
179
KVSO_CLASS_FUNCTION(pixmap,loadAnimation)
 
180
 
 
181
{
 
182
        QString szFile;
 
183
        KVSO_PARAMETERS_BEGIN(c)
 
184
            KVSO_PARAMETER("file",KVS_PT_STRING,0,szFile)
 
185
        KVSO_PARAMETERS_END(c)
 
186
        if(!QFile::exists(szFile))
 
187
        {
 
188
            c->warning(__tr2qs_ctx("I can't find the specified file '%Q'.","objects"),&szFile);
 
189
            return true;
 
190
        }
 
191
        if (m_pAnimatedPixmap) delete m_pAnimatedPixmap;
 
192
        if (m_pPixmap)
 
193
        {
 
194
            delete m_pPixmap;
 
195
            m_pPixmap=0;
 
196
        }
 
197
        m_pAnimatedPixmap= new KviAnimatedPixmap(szFile);
 
198
        connect(m_pAnimatedPixmap,SIGNAL(frameChanged()),this,SLOT(frameChanged()));
 
199
        return true;
 
200
}
 
201
 
 
202
KVSO_CLASS_FUNCTION(pixmap,startAnimation)
 
203
{
 
204
        Q_UNUSED(c);
 
205
        if (m_pAnimatedPixmap)    m_pAnimatedPixmap->start();
 
206
        return true;
 
207
}
 
208
 
 
209
KVSO_CLASS_FUNCTION(pixmap,stopAnimation)
 
210
{
 
211
        Q_UNUSED(c);
 
212
        if (m_pAnimatedPixmap)    m_pAnimatedPixmap->stop();
 
213
        return true;
 
214
}
 
215
 
 
216
KVSO_CLASS_FUNCTION(pixmap,load)
 
217
{
 
218
        QString szFile;
 
219
        KVSO_PARAMETERS_BEGIN(c)
 
220
            KVSO_PARAMETER("file",KVS_PT_STRING,0,szFile)
 
221
        KVSO_PARAMETERS_END(c)
 
222
        if(!QFile::exists(szFile))
 
223
        {
 
224
            c->warning(__tr2qs_ctx("I can't find the specified file '%Q'.","objects"),&szFile);
 
225
            return true;
 
226
        }
 
227
        if (m_pAnimatedPixmap) delete m_pAnimatedPixmap;
 
228
        if(!m_pPixmap) m_pPixmap=new QPixmap();
 
229
        m_pPixmap->load(szFile);
 
230
        return true;
 
231
}
 
232
KVSO_CLASS_FUNCTION(pixmap,save)
 
233
{
 
234
        QString szFile;
 
235
        KVSO_PARAMETERS_BEGIN(c)
 
236
            KVSO_PARAMETER("file",KVS_PT_STRING,0,szFile)
 
237
        KVSO_PARAMETERS_END(c)
 
238
        if (m_pAnimatedPixmap) m_pAnimatedPixmap->pixmap()->save(szFile);
 
239
        else if(m_pPixmap) m_pPixmap->save(szFile);
 
240
        return true;
 
241
}
 
242
/*
 
243
KVSO_CLASS_FUNCTION(pixmap,save)
 
244
{
 
245
        //CHECK_INTERNAL_POINTER(m_pPixmap)
 
246
        QString szFile;
 
247
        KVSO_PARAMETERS_BEGIN(c)
 
248
            KVSO_PARAMETER("file",KVS_PT_STRING,0,szFile)
 
249
        KVSO_PARAMETERS_END(c)
 
250
        if(!QFile::exists(szFile))
 
251
        {
 
252
            c->warning(__tr2qs_ctx("I can't find the specified file '%Q'.","objects"),&szFile);
 
253
            return true;
 
254
        }
 
255
        if (m_pAnimatedPixmap) delete m_pAnimatedPixmap;
 
256
        m_pAnimatedPixmap= new KviAnimatedPixmap(szFile);
 
257
        connect(m_pAnimatedPixmap,SIGNAL(frameChanged()),this,SLOT(frameChanged()));
 
258
        //bPixmapModified=true;
 
259
 
 
260
            return true;
 
261
}
 
262
*/
 
263
KVSO_CLASS_FUNCTION(pixmap,loadFromMemoryBuffer)
 
264
{
 
265
        KviKvsObject * pObject;
 
266
        kvs_hobject_t hObject;
 
267
        KVSO_PARAMETERS_BEGIN(c)
 
268
            KVSO_PARAMETER("hobject",KVS_PT_HOBJECT,0,hObject)
 
269
        KVSO_PARAMETERS_END(c)
 
270
 
 
271
        pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject);
 
272
        if (!pObject)
 
273
        {
 
274
            c->warning(__tr2qs_ctx("Buffer parameter is not an object","objects"));
 
275
            return true;
 
276
        }
 
277
        if (!pObject->inheritsClass("memorybuffer"))
 
278
        {
 
279
            c->warning(__tr2qs_ctx("Buffer parameter is not a memorybuffer object","objects"));
 
280
            return true;
 
281
        }
 
282
        if (m_pAnimatedPixmap){
 
283
            delete m_pAnimatedPixmap;
 
284
            m_pAnimatedPixmap=0;
 
285
        }
 
286
        if (!m_pPixmap) m_pPixmap=new QPixmap();
 
287
        m_pPixmap->loadFromData(((KvsObject_memoryBuffer *)pObject)->dataBuffer());
 
288
        return true;
 
289
}
 
290
 
 
291
KVSO_CLASS_FUNCTION(pixmap,grabWidget)
 
292
{
 
293
        CHECK_INTERNAL_POINTER(m_pPixmap)
 
294
        KviKvsObject * pObject;
 
295
        kvs_hobject_t hObject;
 
296
        KVSO_PARAMETERS_BEGIN(c)
 
297
               KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject)
 
298
        KVSO_PARAMETERS_END(c)
 
299
        pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject);
 
300
        CHECK_HOBJECT_IS_WIDGET(pObject)
 
301
        if (m_pAnimatedPixmap){
 
302
            delete m_pAnimatedPixmap;
 
303
            m_pAnimatedPixmap=0;
 
304
        }
 
305
        if (!m_pPixmap) m_pPixmap=new QPixmap();
 
306
        *m_pPixmap=QPixmap::grabWidget(((KvsObject_widget *)pObject)->widget());
 
307
  /*          QString szFileName;
 
308
            KVSO_PARAMETERS_BEGIN(c)
 
309
                        KVSO_PARAMETER("file_name",KVS_PT_STRING,0,szFileName)
 
310
            KVSO_PARAMETERS_END(c)
 
311
            QPrinter printer;//(QPrinter::HighResolution);
 
312
            printer.setOutputFormat(QPrinter::PdfFormat);
 
313
            printer.setPaperSize(QPrinter::A4);
 
314
            printer.setOutputFileName(szFileName);
 
315
 
 
316
            QPixmap pixmap=QPixmap::grabWidget(((QTableWidget *)widget()));
 
317
            QPainter painter(&printer);
 
318
            painter.drawPixmap(QPoint(0,0), pixmap, pixmap.rect());
 
319
             */
 
320
 
 
321
        return true;
 
322
}
 
323
KVSO_CLASS_FUNCTION(pixmap,height)
 
324
{
 
325
        if(!m_pAnimatedPixmap && !m_pPixmap) c->returnValue()->setInteger(0);
 
326
        else if(m_pAnimatedPixmap) c->returnValue()->setInteger(m_pAnimatedPixmap->size().height());
 
327
        else c->returnValue()->setInteger(m_pPixmap->height());
 
328
        return true;
 
329
}
 
330
KVSO_CLASS_FUNCTION(pixmap,width)
 
331
{
 
332
        if(!m_pAnimatedPixmap && !m_pPixmap) c->returnValue()->setInteger(0);
 
333
        else if(m_pAnimatedPixmap) c->returnValue()->setInteger(m_pAnimatedPixmap->size().width());
 
334
        else c->returnValue()->setInteger(m_pPixmap->width());
 
335
        return true;
 
336
}
 
337
 
 
338
QPixmap * KvsObject_pixmap::getPixmap()
 
339
{
 
340
        if (!m_pAnimatedPixmap && !m_pPixmap) return new QPixmap();
 
341
        else if(m_pAnimatedPixmap) return m_pAnimatedPixmap->pixmap();
 
342
        else return m_pPixmap;
 
343
}
 
344
KVSO_CLASS_FUNCTION(pixmap,frameChangedEvent)
 
345
{
 
346
        emitSignal("frameChanged",c);
 
347
        return true;
 
348
}
 
349
 
 
350
// slots
 
351
void KvsObject_pixmap::frameChanged()
 
352
{
 
353
        KviKvsVariantList *params=0;
 
354
        callFunction(this,"frameChangedEvent",params);
 
355
}
 
356
 
 
357
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
 
358
#include "m_KvsObject_pixmap.moc"
 
359
#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES
 
360