22 #include "qpainter_binding.h"
23 #include "object_binding.h"
24 #include "static_binding.h"
25 #include "kjseglobal.h"
27 #include <kjs/object.h>
42 using namespace KJSEmbed;
48 ObjectBinding *imp = extractBindingImp<ObjectBinding>(exec, arg);
51 #warning There be dragons here...
61 device = qobject_cast<QWidget *>(qobject);
67 qDebug(
"Height = %d Width = %d", device->
height(), device->
width());
70 VariantBinding *valueImp = extractBindingImp<VariantBinding>(exec, arg);
73 device =
static_cast<QPaintDevice *
>(valueImp->pointer());
79 START_OBJECT_METHOD(callPainterBegin,
QPainter)
80 result = KJS::jsBoolean(
false);
81 QPaintDevice *device = extractPaintDevice(exec, args[0]);
84 result = KJS::jsBoolean(object->begin(device));
87 result = KJS::jsBoolean(
false);
91 START_OBJECT_METHOD(callPainterEnd,
QPainter)
92 result = KJS::jsBoolean(object->end());
95 START_OBJECT_METHOD(callbackground,
QPainter)
96 QBrush cppValue =
object->background();
97 result = KJSEmbed::createVariant(exec,
"QBrush", cppValue);
100 START_OBJECT_METHOD(callbackgroundMode,
QPainter)
101 Qt::BGMode cppValue =
object->backgroundMode();
102 result = KJS::jsNumber(cppValue);
105 START_OBJECT_METHOD(callboundingRect,
QPainter)
106 if (args.size() == 3)
108 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec, args, 0);
109 int arg1 = KJSEmbed::extractInt(exec, args, 1);
110 QString arg2 = KJSEmbed::extractQString(exec, args, 2);
111 QRect cppValue =
object->boundingRect(arg0, arg1, arg2);
112 result = KJSEmbed::createVariant(exec,
"QRect", cppValue);
113 }
else if (args.size() == 6)
115 int arg0 = KJSEmbed::extractInt(exec, args, 0);
116 int arg1 = KJSEmbed::extractInt(exec, args, 1);
117 int arg2 = KJSEmbed::extractInt(exec, args, 2);
118 int arg3 = KJSEmbed::extractInt(exec, args, 3);
119 int arg4 = KJSEmbed::extractInt(exec, args, 4);
120 QString arg5 = KJSEmbed::extractQString(exec, args, 5);
121 QRect cppValue =
object->boundingRect(arg0, arg1, arg2, arg3, arg4, arg5);
122 result = KJSEmbed::createVariant(exec,
"QRect", cppValue);
126 START_OBJECT_METHOD(callbrush,
QPainter)
127 QBrush cppValue =
object->brush();
128 result = KJSEmbed::createVariant(exec,
"QBrush", cppValue);
131 START_OBJECT_METHOD(callbrushOrigin,
QPainter)
132 QPoint cppValue =
object->brushOrigin();
133 result = KJSEmbed::createVariant(exec,
"QPoint", cppValue);
136 START_OBJECT_METHOD(calldrawArc,
QPainter)
137 if (args.size() == 3)
139 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec, args, 0);
140 int arg1 = KJSEmbed::extractInt(exec, args, 1);
141 int arg2 = KJSEmbed::extractInt(exec, args, 2);
142 object->drawArc(arg0, arg1, arg2);
143 }
else if (args.size() == 6)
145 int arg0 = KJSEmbed::extractInt(exec, args, 0);
146 int arg1 = KJSEmbed::extractInt(exec, args, 1);
147 int arg2 = KJSEmbed::extractInt(exec, args, 2);
148 int arg3 = KJSEmbed::extractInt(exec, args, 3);
149 int arg4 = KJSEmbed::extractInt(exec, args, 4);
150 int arg5 = KJSEmbed::extractInt(exec, args, 5);
151 object->drawArc(arg0, arg1, arg2, arg3, arg4, arg5);
155 START_OBJECT_METHOD(calldrawChord,
QPainter)
156 if (args.size() == 3)
158 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec, args, 0);
159 int arg1 = KJSEmbed::extractInt(exec, args, 1);
160 int arg2 = KJSEmbed::extractInt(exec, args, 2);
161 object->drawChord(arg0, arg1, arg2);
162 }
else if (args.size() == 6)
164 int arg0 = KJSEmbed::extractInt(exec, args, 0);
165 int arg1 = KJSEmbed::extractInt(exec, args, 1);
166 int arg2 = KJSEmbed::extractInt(exec, args, 2);
167 int arg3 = KJSEmbed::extractInt(exec, args, 3);
168 int arg4 = KJSEmbed::extractInt(exec, args, 4);
169 int arg5 = KJSEmbed::extractInt(exec, args, 5);
170 object->drawChord(arg0, arg1, arg2, arg3, arg4, arg5);
174 START_OBJECT_METHOD(calldrawConvexPolygon,
QPainter)
175 QPolygon arg0 = KJSEmbed::extractVariant<QPolygon>(exec, args, 0);
176 object->drawConvexPolygon(arg0);
179 START_OBJECT_METHOD(calldrawEllipse,
QPainter)
180 if (args.size() == 4)
182 int arg0 = KJSEmbed::extractInt(exec, args, 0);
183 int arg1 = KJSEmbed::extractInt(exec, args, 1);
184 int arg2 = KJSEmbed::extractInt(exec, args, 2);
185 int arg3 = KJSEmbed::extractInt(exec, args, 3);
186 object->drawEllipse(arg0, arg1, arg2, arg3);
187 }
else if (args.size() == 1)
189 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec, args, 0);
190 object->drawEllipse(arg0);
194 START_OBJECT_METHOD(calldrawImage,
QPainter)
195 if (args.size() == 2)
197 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
198 QImage arg1 = KJSEmbed::extractVariant<QImage>(exec, args, 1);
199 object->drawImage(arg0, arg1);
200 }
else if (args.size() == 4)
202 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
203 QImage arg1 = KJSEmbed::extractVariant<QImage>(exec, args, 1);
204 QRect arg2 = KJSEmbed::extractVariant<QRect>(exec, args, 2);
206 object->drawImage(arg0, arg1, arg2, arg3);
207 }
else if (args.size() == 8)
209 int arg0 = KJSEmbed::extractInt(exec, args, 0);
210 int arg1 = KJSEmbed::extractInt(exec, args, 1);
211 QImage arg2 = KJSEmbed::extractVariant<QImage>(exec, args, 2);
212 int arg3 = KJSEmbed::extractInt(exec, args, 3);
213 int arg4 = KJSEmbed::extractInt(exec, args, 4);
214 int arg5 = KJSEmbed::extractInt(exec, args, 5);
215 int arg6 = KJSEmbed::extractInt(exec, args, 6);
217 object->drawImage(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
221 START_OBJECT_METHOD(calldrawLine,
QPainter)
222 if (args.size() == 1)
224 QLine arg0 = KJSEmbed::extractVariant<QLine>(exec, args, 0);
225 object->drawLine(arg0);
226 }
else if (args.size() == 2)
228 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
229 QPoint arg1 = KJSEmbed::extractVariant<QPoint>(exec, args, 1);
230 object->drawLine(arg0, arg1);
231 }
else if (args.size() == 4)
233 int arg0 = KJSEmbed::extractInt(exec, args, 0);
234 int arg1 = KJSEmbed::extractInt(exec, args, 1);
235 int arg2 = KJSEmbed::extractInt(exec, args, 2);
236 int arg3 = KJSEmbed::extractInt(exec, args, 3);
237 object->drawLine(arg0, arg1, arg2, arg3);
241 START_OBJECT_METHOD(calldrawPie,
QPainter)
242 if (args.size() == 3)
244 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec, args, 0);
245 int arg1 = KJSEmbed::extractInt(exec, args, 1);
246 int arg2 = KJSEmbed::extractInt(exec, args, 2);
247 object->drawPie(arg0, arg1, arg2);
248 }
else if (args.size() == 6)
250 int arg0 = KJSEmbed::extractInt(exec, args, 0);
251 int arg1 = KJSEmbed::extractInt(exec, args, 1);
252 int arg2 = KJSEmbed::extractInt(exec, args, 2);
253 int arg3 = KJSEmbed::extractInt(exec, args, 3);
254 int arg4 = KJSEmbed::extractInt(exec, args, 4);
255 int arg5 = KJSEmbed::extractInt(exec, args, 5);
256 object->drawPie(arg0, arg1, arg2, arg3, arg4, arg5);
260 START_OBJECT_METHOD(calldrawPixmap,
QPainter)
261 if (args.size() == 2)
263 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
264 QPixmap arg1 = KJSEmbed::extractVariant<QPixmap>(exec, args, 1);
265 object->drawPixmap(arg0, arg1);
266 }
else if (args.size() == 3)
268 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
269 QPixmap arg1 = KJSEmbed::extractVariant<QPixmap>(exec, args, 1);
270 QRect arg2 = KJSEmbed::extractVariant<QRect>(exec, args, 2);
271 object->drawPixmap(arg0, arg1, arg2);
275 START_OBJECT_METHOD(calldrawPoint,
QPainter)
276 if (args.size() == 1)
278 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
279 object->drawPoint(arg0);
280 }
else if (args.size() == 2)
282 int arg0 = KJSEmbed::extractInt(exec, args, 0);
283 int arg1 = KJSEmbed::extractInt(exec, args, 1);
284 object->drawPoint(arg0, arg1);
288 START_OBJECT_METHOD(calldrawPoints,
QPainter)
289 QPolygon arg0 = KJSEmbed::extractVariant<QPolygon>(exec, args, 0);
290 object->drawPoints(arg0);
293 START_OBJECT_METHOD(calldrawPolygon,
QPainter)
294 QPolygon arg0 = KJSEmbed::extractVariant<QPolygon>(exec, args, 0);
296 object->drawPolygon(arg0, arg1);
299 START_OBJECT_METHOD(calldrawPolyline,
QPainter)
300 QPolygon arg0 = KJSEmbed::extractVariant<QPolygon>(exec, args, 0);
301 object->drawPolyline(arg0);
304 START_OBJECT_METHOD(calldrawRect,
QPainter)
305 if (args.size() == 1)
307 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec, args, 0);
308 object->drawRect(arg0);
309 }
else if (args.size() == 4)
311 int arg0 = KJSEmbed::extractInt(exec, args, 0);
312 int arg1 = KJSEmbed::extractInt(exec, args, 1);
313 int arg2 = KJSEmbed::extractInt(exec, args, 2);
314 int arg3 = KJSEmbed::extractInt(exec, args, 3);
315 object->drawRect(arg0, arg1, arg2, arg3);
319 START_OBJECT_METHOD(calldrawRoundRect,
QPainter)
320 if (args.size() == 2)
322 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec, args, 0);
323 int arg1 = KJSEmbed::extractInt(exec, args, 1);
324 int arg2 = KJSEmbed::extractInt(exec, args, 2);
325 object->drawRoundRect(arg0, arg1, arg2);
326 }
else if (args.size() == 6)
328 int arg0 = KJSEmbed::extractInt(exec, args, 0);
329 int arg1 = KJSEmbed::extractInt(exec, args, 1);
330 int arg2 = KJSEmbed::extractInt(exec, args, 2);
331 int arg3 = KJSEmbed::extractInt(exec, args, 3);
332 int arg4 = KJSEmbed::extractInt(exec, args, 4);
333 int arg5 = KJSEmbed::extractInt(exec, args, 5);
334 object->drawRoundRect(arg0, arg1, arg2, arg3, arg4, arg5);
338 START_OBJECT_METHOD(calldrawText,
QPainter)
339 if (args.size() == 2)
341 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
342 QString arg1 = KJSEmbed::extractQString(exec, args, 1);
343 object->drawText(arg0, arg1);
344 }
else if (args.size() == 3)
346 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec, args, 0);
347 int arg1 = KJSEmbed::extractInt(exec, args, 1);
348 QString arg2 = KJSEmbed::extractQString(exec, args, 2);
349 QRect *arg3 =
nullptr;
350 object->drawText(arg0, arg1, arg2, arg3);
351 }
else if (args.size() == 6)
353 int arg0 = KJSEmbed::extractInt(exec, args, 0);
354 int arg1 = KJSEmbed::extractInt(exec, args, 1);
355 int arg2 = KJSEmbed::extractInt(exec, args, 2);
356 int arg3 = KJSEmbed::extractInt(exec, args, 3);
357 int arg4 = KJSEmbed::extractInt(exec, args, 4);
358 QString arg5 = KJSEmbed::extractQString(exec, args, 5);
359 QRect *arg6 =
nullptr;
360 object->drawText(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
364 START_OBJECT_METHOD(calltranslate,
QPainter)
365 if (args.size() == 2)
367 int arg0 = KJSEmbed::extractInt(exec, args, 0);
368 int arg1 = KJSEmbed::extractInt(exec, args, 1);
369 object->translate(arg0, arg1);
370 }
else if (args.size() == 1)
372 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
373 object->translate(arg0);
377 START_OBJECT_METHOD(calldrawTiledPixmap,
QPainter)
378 if (args.size() == 3)
380 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec, args, 0);
381 QPixmap arg1 = KJSEmbed::extractVariant<QPixmap>(exec, args, 1);
382 QPoint arg2 = KJSEmbed::extractVariant<QPoint>(exec, args, 2);
383 object->drawTiledPixmap(arg0, arg1, arg2);
384 }
else if (args.size() == 7)
386 int arg0 = KJSEmbed::extractInt(exec, args, 0);
387 int arg1 = KJSEmbed::extractInt(exec, args, 1);
388 int arg2 = KJSEmbed::extractInt(exec, args, 2);
389 int arg3 = KJSEmbed::extractInt(exec, args, 3);
390 QPixmap arg4 = KJSEmbed::extractVariant<QPixmap>(exec, args, 4);
391 int arg5 = KJSEmbed::extractInt(exec, args, 5);
392 int arg6 = KJSEmbed::extractInt(exec, args, 6);
393 object->drawTiledPixmap(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
397 START_OBJECT_METHOD(calleraseRect,
QPainter)
398 if (args.size() == 4)
400 int arg0 = KJSEmbed::extractInt(exec, args, 0);
401 int arg1 = KJSEmbed::extractInt(exec, args, 1);
402 int arg2 = KJSEmbed::extractInt(exec, args, 2);
403 int arg3 = KJSEmbed::extractInt(exec, args, 3);
404 object->eraseRect(arg0, arg1, arg2, arg3);
405 }
else if (args.size() == 1)
407 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec, args, 0);
408 object->eraseRect(arg0);
412 START_METHOD_LUT(Painter)
413 {
"begin", 1, KJS::DontDelete | KJS::ReadOnly, &callPainterBegin },
414 {
"end", 0, KJS::DontDelete | KJS::ReadOnly, &callPainterEnd },
415 {
"background", 0, KJS::DontDelete | KJS::ReadOnly, &callbackground},
416 {
"backgroundMode", 0, KJS::DontDelete | KJS::ReadOnly, &callbackgroundMode},
417 {
"boundingRect", 6, KJS::DontDelete | KJS::ReadOnly, &callboundingRect},
418 {
"brush", 0, KJS::DontDelete | KJS::ReadOnly, &callbrush},
419 {
"brushOrigin", 0, KJS::DontDelete | KJS::ReadOnly, &callbrushOrigin},
420 {
"drawArc", 6, KJS::DontDelete | KJS::ReadOnly, &calldrawArc},
421 {
"drawChord", 6, KJS::DontDelete | KJS::ReadOnly, &calldrawChord},
422 {
"drawConvexPolygon", 1, KJS::DontDelete | KJS::ReadOnly, &calldrawConvexPolygon},
423 {
"drawEllipse", 3, KJS::DontDelete | KJS::ReadOnly, &calldrawEllipse},
424 {
"drawImage", 7, KJS::DontDelete | KJS::ReadOnly, &calldrawImage},
425 {
"drawLine", 3, KJS::DontDelete | KJS::ReadOnly, &calldrawLine},
429 {
"drawPie", 6, KJS::DontDelete | KJS::ReadOnly, &calldrawPie},
430 {
"drawPixmap", 8, KJS::DontDelete | KJS::ReadOnly, &calldrawPixmap},
431 {
"drawPoint", 2, KJS::DontDelete | KJS::ReadOnly, &calldrawPoint},
432 {
"drawPoints", 1, KJS::DontDelete | KJS::ReadOnly, &calldrawPoints},
433 {
"drawPolygon", 2, KJS::DontDelete | KJS::ReadOnly, &calldrawPolygon},
434 {
"drawPolyline", 1, KJS::DontDelete | KJS::ReadOnly, &calldrawPolyline},
435 {
"drawRect", 4, KJS::DontDelete | KJS::ReadOnly, &calldrawRect},
437 {
"drawRoundRect", 5, KJS::DontDelete | KJS::ReadOnly, &calldrawRoundRect},
438 {
"drawText", 7, KJS::DontDelete | KJS::ReadOnly, &calldrawText},
439 {
"drawTiledPixmap", 3, KJS::DontDelete | KJS::ReadOnly, &calldrawTiledPixmap},
440 {
"eraseRect", 1, KJS::DontDelete | KJS::ReadOnly, &calleraseRect},
466 {
"translate", 1, KJS::DontDelete | KJS::ReadOnly, &calltranslate}
473 KJS::JSObject *
object;
475 if (args.size() == 1)
477 QPaintDevice *device = extractPaintDevice(exec, args[0]);
479 object =
new KJSEmbed::ObjectBinding(exec,
"Painter",
new QPainter(device));
481 KJS::throwError(exec, KJS::EvalError,
QString(
"Cannot paint to object %1").arg(toQString(args[0]->
toString(exec))));
486 object =
new KJSEmbed::ObjectBinding(exec,
"Painter",
new QPainter());