1 /* This file is part of the KDE libraries
2     Copyright (C) 2005, 2006 Ian Reinhart Geiser <geiseri@kde.org>
3     Copyright (C) 2005, 2006 Matt Broadstone <mbroadst@gmail.com>
4     Copyright (C) 2005, 2006 Richard J. Moore <rich@kde.org>
5     Copyright (C) 2005, 2006 Erik L. Bunce <kde@bunce.us>
6 
7     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Library General Public
9     License as published by the Free Software Foundation; either
10     version 2 of the License, or (at your option) any later version.
11 
12     This library is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15     Library General Public License for more details.
16 
17     You should have received a copy of the GNU Library General Public License
18     along with this library; see the file COPYING.LIB.  If not, write to
19     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20     Boston, MA 02110-1301, USA.
21 */
22 #include "pixmap.h"
23 
24 #include <QDebug>
25 #include <QPixmap>
26 #include <QBitmap>
27 #include <QWidget>
28 
29 #include <variant_binding.h>
30 #include <object_binding.h>
31 
32 using namespace KJSEmbed;
33 
34 const KJS::ClassInfo PixmapBinding::info = { "QPixmap", &VariantBinding::info, nullptr, nullptr };
PixmapBinding(KJS::ExecState * exec,const QPixmap & value)35 PixmapBinding::PixmapBinding(KJS::ExecState *exec, const QPixmap &value)
36     : VariantBinding(exec, value)
37 {
38     StaticBinding::publish(exec, this, Pixmap::methods());
39     StaticBinding::publish(exec, this, VariantFactory::methods());
40 }
41 
42 namespace PixmapNS
43 {
44 START_VARIANT_METHOD(callalphaChannel, QPixmap)
45 QPixmap cppValue = value.alphaChannel();
46 result = KJSEmbed::createVariant(exec, "QPixmap", cppValue);
47 END_VARIANT_METHOD
48 
49 START_VARIANT_METHOD(callcopy, QPixmap)
50 if (args.size() == 1)
51 {
52     QRect arg0 = KJSEmbed::extractVariant<QRect>(exec, args, 0);
53     QPixmap cppValue = value.copy(arg0);
54     result = KJSEmbed::createVariant(exec, "QPixmap", cppValue);
55 } else if (args.size() == 4)
56 {
57     int arg0 = KJSEmbed::extractInt(exec, args, 0);
58     int arg1 = KJSEmbed::extractInt(exec, args, 1);
59     int arg2 = KJSEmbed::extractInt(exec, args, 2);
60     int arg3 = KJSEmbed::extractInt(exec, args, 3);
61     QPixmap cppValue = value.copy(arg0, arg1, arg2, arg3);
62     result = KJSEmbed::createVariant(exec, "QPixmap", cppValue);
63 }
64 END_VARIANT_METHOD
65 
66 START_VARIANT_METHOD(callcreateHeuristicMask, QPixmap)
67 bool arg0 = KJSEmbed::extractBool(exec, args, 0);
68 QBitmap cppValue = value.createHeuristicMask(arg0);
69 result = KJSEmbed::createVariant(exec, "QBitmap", cppValue);
70 END_VARIANT_METHOD
71 
72 START_VARIANT_METHOD(callcreateMaskFromColor, QPixmap)
73 QColor arg0 = KJSEmbed::extractVariant<QColor>(exec, args, 0);
74 QBitmap cppValue = value.createMaskFromColor(arg0);
75 result = KJSEmbed::createVariant(exec, "QBitmap", cppValue);
76 END_VARIANT_METHOD
77 
78 START_VARIANT_METHOD(calldefaultDepth, QPixmap)
79 int cppValue = value.defaultDepth();
80 result = KJS::jsNumber(cppValue);
81 END_VARIANT_METHOD
82 
83 START_VARIANT_METHOD(calldepth, QPixmap)
84 int cppValue = value.depth();
85 result = KJS::jsNumber(cppValue);
86 END_VARIANT_METHOD
87 
88 START_VARIANT_METHOD(callfill, QPixmap)
89 if (args.size() == 3)
90 {
91     QWidget *arg0 = KJSEmbed::extractObject<QWidget>(exec, args, 0);
92     int arg1 = KJSEmbed::extractInt(exec, args, 1);
93     int arg2 = KJSEmbed::extractInt(exec, args, 2);
94     value.fill(arg0, arg1, arg2);
95 } else if (args.size() == 1)
96 {
97     QColor arg0 = KJSEmbed::extractVariant<QColor>(exec, args, 0);
98     value.fill(arg0);
99 } else if (args.size() == 2)
100 {
101     QWidget *arg0 = KJSEmbed::extractObject<QWidget>(exec, args, 0);
102     QPoint arg1 = KJSEmbed::extractVariant<QPoint>(exec, args, 1);
103     value.fill(arg0, arg1);
104 }
105 END_VARIANT_METHOD
106 
107 START_VARIANT_METHOD(callfromImage, QPixmap)
108 QImage arg0 = KJSEmbed::extractVariant<QImage>(exec, args, 0);
109 Qt::ImageConversionFlags arg1 = (Qt::ImageConversionFlags)KJSEmbed::extractInt(exec, args, 1);
110 QPixmap cppValue = QPixmap::fromImage(arg0, arg1);
111 result = KJSEmbed::createVariant(exec, "QPixmap", cppValue);
112 END_VARIANT_METHOD
113 
114 START_VARIANT_METHOD(callgrabWidget, QPixmap)
115 if (args.size() == 2)
116 {
117     QWidget *arg0 = KJSEmbed::extractObject<QWidget>(exec, args, 0);
118     QRect arg1 = KJSEmbed::extractVariant<QRect>(exec, args, 1);
119     QPixmap cppValue = value.grabWidget(arg0, arg1);
120     result = KJSEmbed::createVariant(exec, "QPixmap", cppValue);
121 } else if (args.size() == 5)
122 {
123     QWidget *arg0 = KJSEmbed::extractObject<QWidget>(exec, args, 0);
124     int arg1 = KJSEmbed::extractInt(exec, args, 1);
125     int arg2 = KJSEmbed::extractInt(exec, args, 2);
126     int arg3 = KJSEmbed::extractInt(exec, args, 3);
127     int arg4 = KJSEmbed::extractInt(exec, args, 4);
128     QPixmap cppValue = value.grabWidget(arg0, arg1, arg2, arg3, arg4);
129     result = KJSEmbed::createVariant(exec, "QPixmap", cppValue);
130 }
131 END_VARIANT_METHOD
132 
133 START_VARIANT_METHOD(callhasAlpha, QPixmap)
134 bool cppValue = value.hasAlpha();
135 result = KJS::jsBoolean(cppValue);
136 END_VARIANT_METHOD
137 
138 START_VARIANT_METHOD(callhasAlphaChannel, QPixmap)
139 bool cppValue = value.hasAlphaChannel();
140 result = KJS::jsBoolean(cppValue);
141 END_VARIANT_METHOD
142 
143 START_VARIANT_METHOD(callheight, QPixmap)
144 int cppValue = value.height();
145 result = KJS::jsNumber(cppValue);
146 END_VARIANT_METHOD
147 
148 START_VARIANT_METHOD(callisNull, QPixmap)
149 bool cppValue = value.isNull();
150 result = KJS::jsBoolean(cppValue);
151 END_VARIANT_METHOD
152 
153 START_VARIANT_METHOD(callisQBitmap, QPixmap)
154 bool cppValue = value.isQBitmap();
155 result = KJS::jsBoolean(cppValue);
156 END_VARIANT_METHOD
157 
158 START_VARIANT_METHOD(callload, QPixmap)
159 QString arg0 = KJSEmbed::extractQString(exec, args, 0);
160 QByteArray arg1 = KJSEmbed::extractQString(exec, args, 1).toLatin1();
161 Qt::ImageConversionFlags arg2 = (Qt::ImageConversionFlags) KJSEmbed::extractInt(exec, args, 2);
162 bool cppValue = value.load(arg0, arg1, arg2);
163 result = KJS::jsBoolean(cppValue);
164 END_VARIANT_METHOD
165 
166 START_VARIANT_METHOD(callmask, QPixmap)
167 QBitmap cppValue = value.mask();
168 result = KJSEmbed::createVariant(exec, "QBitmap", cppValue);
169 END_VARIANT_METHOD
170 
171 START_VARIANT_METHOD(callrect, QPixmap)
172 QRect cppValue = value.rect();
173 result = KJSEmbed::createVariant(exec, "QRect", cppValue);
174 END_VARIANT_METHOD
175 
176 START_VARIANT_METHOD(callsave, QPixmap)
177 QString arg0 = KJSEmbed::extractQString(exec, args, 0);
178 QByteArray arg1 = KJSEmbed::extractQString(exec, args, 1).toLatin1();
179 int arg2 = KJSEmbed::extractInt(exec, args, 2, -1);
180 bool cppValue = value.save(arg0, arg1, arg2);
181 result = KJS::jsBoolean(cppValue);
182 END_VARIANT_METHOD
183 
184 START_VARIANT_METHOD(callscaled, QPixmap)
185 if (args.size() == 3)
186 {
187     QSize arg0 = KJSEmbed::extractVariant<QSize>(exec, args, 0);
188     Qt::AspectRatioMode arg1 = (Qt::AspectRatioMode) KJSEmbed::extractInt(exec, args, 1);
189     Qt::TransformationMode arg2 = (Qt::TransformationMode) KJSEmbed::extractInt(exec, args, 3);
190     QPixmap cppValue = value.scaled(arg0, arg1, arg2);
191     result = KJSEmbed::createVariant(exec, "QPixmap", cppValue);
192 } else if (args.size() == 4)
193 {
194     int arg0 = KJSEmbed::extractInt(exec, args, 0);
195     int arg1 = KJSEmbed::extractInt(exec, args, 1);
196     Qt::AspectRatioMode arg2 = (Qt::AspectRatioMode) KJSEmbed::extractInt(exec, args, 2);
197     Qt::TransformationMode arg3 = (Qt::TransformationMode) KJSEmbed::extractInt(exec, args, 3);
198     QPixmap cppValue = value.scaled(arg0, arg1, arg2, arg3);
199     result = KJSEmbed::createVariant(exec, "QPixmap", cppValue);
200 }
201 END_VARIANT_METHOD
202 
203 START_VARIANT_METHOD(callscaledToHeight, QPixmap)
204 int arg0 = KJSEmbed::extractInt(exec, args, 0);
205 Qt::TransformationMode arg1  = (Qt::TransformationMode) KJSEmbed::extractInt(exec, args, 1);
206 QPixmap cppValue = value.scaledToHeight(arg0, arg1);
207 result = KJSEmbed::createVariant(exec, "QPixmap", cppValue);
208 END_VARIANT_METHOD
209 
210 START_VARIANT_METHOD(callscaledToWidth, QPixmap)
211 int arg0 = KJSEmbed::extractInt(exec, args, 0);
212 Qt::TransformationMode arg1  = (Qt::TransformationMode) KJSEmbed::extractInt(exec, args, 1);
213 QPixmap cppValue = value.scaledToWidth(arg0, arg1);
214 result = KJSEmbed::createVariant(exec, "QPixmap", cppValue);
215 END_VARIANT_METHOD
216 
217 START_VARIANT_METHOD(callserialNumber, QPixmap)
218 int cppValue = value.serialNumber();
219 result = KJS::jsNumber(cppValue);
220 END_VARIANT_METHOD
221 
222 START_VARIANT_METHOD(callsetAlphaChannel, QPixmap)
223 QPixmap arg0 = KJSEmbed::extractVariant<QPixmap>(exec, args, 0);
224 value.setAlphaChannel(arg0);
225 END_VARIANT_METHOD
226 
227 START_VARIANT_METHOD(callsetMask, QPixmap)
228 QBitmap arg0 = KJSEmbed::extractVariant<QBitmap>(exec, args, 0);
229 value.setMask(arg0);
230 END_VARIANT_METHOD
231 
232 START_VARIANT_METHOD(callsize, QPixmap)
233 QSize cppValue = value.size();
234 result = KJSEmbed::createVariant(exec, "QSize", cppValue);
235 END_VARIANT_METHOD
236 
237 START_VARIANT_METHOD(calltoImage, QPixmap)
238 QImage cppValue = value.toImage();
239 result = KJSEmbed::createVariant(exec, "QImage", cppValue);
240 END_VARIANT_METHOD
241 
242 START_VARIANT_METHOD(callwidth, QPixmap)
243 int cppValue = value.width();
244 result = KJS::jsNumber(cppValue);
245 END_VARIANT_METHOD
246 
247 }
248 
START_METHOD_LUT(Pixmap)249 START_METHOD_LUT(Pixmap)
250 {"alphaChannel", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callalphaChannel},
251 {"copy", 3, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callcopy},
252 {"createHeuristicMask", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callcreateHeuristicMask},
253 {"createMaskFromColor", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callcreateMaskFromColor},
254 {"defaultDepth", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::calldefaultDepth},
255 {"depth", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::calldepth},
256 {"fill", 2, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callfill},
257 {"fromImage", 1, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callfromImage},
258 {"grabWidget", 4, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callgrabWidget},
259 {"hasAlpha", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callhasAlpha},
260 {"hasAlphaChannel", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callhasAlphaChannel},
261 {"height", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callheight},
262 {"isNull", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callisNull},
263 {"isQBitmap", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callisQBitmap},
264 {"load", 2, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callload},
265 {"mask", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callmask},
266 {"rect", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callrect},
267 {"save", 2, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callsave},
268 {"scaled", 3, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callscaled},
269 {"scaledToHeight", 1, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callscaledToHeight},
270 {"scaledToWidth", 1, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callscaledToWidth},
271 {"serialNumber", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callserialNumber},
272 {"setAlphaChannel", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callsetAlphaChannel},
273 {"setMask", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callsetMask},
274 {"size", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callsize},
275 {"toImage", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::calltoImage},
276 {"width", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callwidth}
277 END_METHOD_LUT
278 
279 NO_STATICS(Pixmap)
280 NO_ENUMS(Pixmap)
281 START_CTOR(Pixmap, QPixmap, 0)
282 if (args.size() == 0)
283 {
284     return new KJSEmbed::PixmapBinding(exec, QPixmap());
285 } else if (args.size() == 1)
286 {
287     return new KJSEmbed::PixmapBinding(exec,
288                                        QPixmap(KJSEmbed::extractQString(exec, args, 0)));
289 } else if (args.size() == 2)
290 {
291     return new KJSEmbed::PixmapBinding(exec,
292                                        QPixmap(KJSEmbed::extractInt(exec, args, 0),
293                                                KJSEmbed::extractInt(exec, args, 1)
294                                               ));
295 } else if (args.size() == 3)
296 {
297     QString tmp = toQString(args[2]->toObject(exec)->className());
298     qDebug() << tmp;
299 
300     return new KJSEmbed::PixmapBinding(exec,
301                                        QPixmap(KJSEmbed::extractQString(exec, args, 0),
302                                                KJSEmbed::extractVariant<QByteArray>(exec, args, 1).constData(),
303                                                (Qt::ImageConversionFlags)KJSEmbed::extractInt(exec, args, 2)
304                                               ));
305 }
306 return new KJSEmbed::PixmapBinding(exec, QPixmap());
307 END_CTOR
308 
309