add more spacing
[personal-kdebase.git] / workspace / plasma / scriptengines / javascript / qtgui / painter.cpp
blob533628c7bb86efe53e3323c4f905281c7150f6e1
1 /*
2 * Copyright 2007 Richard J. Moore <rich@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU Library General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include <QtScript/QScriptValue>
20 #include <QtScript/QScriptEngine>
21 #include <QtScript/QScriptContext>
23 #include <QtGui/QPainter>
24 #include <QtGui/QPicture>
25 #include <QtGui/QPolygonF>
26 #include <QtGui/QWidget>
28 #include <QtCore/qdebug.h>
30 #include "../backportglobal.h"
32 Q_DECLARE_METATYPE(QPolygonF)
33 Q_DECLARE_METATYPE(QPainterPath)
34 Q_DECLARE_METATYPE(QPainterPath*)
35 Q_DECLARE_METATYPE(QPicture)
36 Q_DECLARE_METATYPE(QVector<QRectF>)
37 Q_DECLARE_METATYPE(QPaintDevice*)
38 Q_DECLARE_METATYPE(QPaintEngine*)
40 DECLARE_POINTER_METATYPE(QPainter)
42 static QScriptValue newPainter(QScriptEngine *eng, QPainter *p)
44 return QScript::wrapPointer(eng, p);
47 /////////////////////////////////////////////////////////////
49 static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)
51 if (ctx->argumentCount() > 0) {
52 QPaintDevice *device = qscriptvalue_cast<QPaintDevice*>(ctx->argument(0));
53 return newPainter(eng, new QPainter(device));
54 } else {
55 return newPainter(eng, new QPainter());
59 /////////////////////////////////////////////////////////////
61 static QScriptValue background(QScriptContext *ctx, QScriptEngine *eng)
63 DECLARE_SELF(QPainter, background);
64 return qScriptValueFromValue(eng, self->background());
67 /////////////////////////////////////////////////////////////
69 static QScriptValue backgroundMode(QScriptContext *ctx, QScriptEngine *eng)
71 DECLARE_SELF(QPainter, backgroundMode);
72 return QScriptValue(eng, static_cast<int>(self->backgroundMode()));
75 /////////////////////////////////////////////////////////////
77 static QScriptValue begin(QScriptContext *ctx, QScriptEngine *eng)
79 DECLARE_SELF(QPainter, begin);
80 QWidget *device = qscriptvalue_cast<QWidget*>(ctx->argument(0));
81 if (!device) {
82 return ctx->throwError(QScriptContext::TypeError,
83 "QPainter.prototype.begin: argument is not a QWidget");
85 return QScriptValue(eng, self->begin(device));
88 /////////////////////////////////////////////////////////////
90 static QScriptValue boundingRect(QScriptContext *ctx, QScriptEngine *eng)
92 DECLARE_SELF(QPainter, boundingRect);
93 QRect result;
94 if (ctx->argumentCount() == 3) {
95 result = self->boundingRect(qscriptvalue_cast<QRect>(ctx->argument(0)),
96 ctx->argument(1).toInt32(),
97 ctx->argument(2).toString());
98 } else if (ctx->argumentCount() == 6) {
99 result = self->boundingRect(ctx->argument(0).toInt32(),
100 ctx->argument(1).toInt32(),
101 ctx->argument(2).toInt32(),
102 ctx->argument(3).toInt32(),
103 ctx->argument(4).toInt32(),
104 ctx->argument(5).toString());
106 return qScriptValueFromValue(eng, result);
109 /////////////////////////////////////////////////////////////
111 static QScriptValue brush(QScriptContext *ctx, QScriptEngine *eng)
113 DECLARE_SELF(QPainter, brush);
114 return qScriptValueFromValue(eng, self->brush());
117 /////////////////////////////////////////////////////////////
119 static QScriptValue brushOrigin(QScriptContext *ctx, QScriptEngine *eng)
121 DECLARE_SELF(QPainter, brushOrigin);
122 return qScriptValueFromValue(eng, self->brushOrigin());
125 /////////////////////////////////////////////////////////////
127 static QScriptValue clipPath(QScriptContext *ctx, QScriptEngine *eng)
129 DECLARE_SELF(QPainter, clipPath);
130 return qScriptValueFromValue(eng, self->clipPath());
133 /////////////////////////////////////////////////////////////
135 static QScriptValue clipRegion(QScriptContext *ctx, QScriptEngine *eng)
137 DECLARE_SELF(QPainter, clipRegion);
138 return qScriptValueFromValue(eng, self->clipRegion());
141 /////////////////////////////////////////////////////////////
143 static QScriptValue combinedMatrix(QScriptContext *ctx, QScriptEngine *eng)
145 DECLARE_SELF(QPainter, combinedMatrix);
146 return qScriptValueFromValue(eng, self->combinedMatrix());
149 /////////////////////////////////////////////////////////////
151 static QScriptValue combinedTransform(QScriptContext *ctx, QScriptEngine *eng)
153 DECLARE_SELF(QPainter, combinedTransform);
154 return qScriptValueFromValue(eng, self->combinedTransform());
157 /////////////////////////////////////////////////////////////
159 static QScriptValue compositionMode(QScriptContext *ctx, QScriptEngine *eng)
161 DECLARE_SELF(QPainter, compositionMode);
162 return QScriptValue(eng, static_cast<int>(self->compositionMode()));
165 /////////////////////////////////////////////////////////////
167 static QScriptValue device(QScriptContext *ctx, QScriptEngine *eng)
169 DECLARE_SELF(QPainter, device);
170 return qScriptValueFromValue(eng, self->device());
173 /////////////////////////////////////////////////////////////
175 static QScriptValue deviceMatrix(QScriptContext *ctx, QScriptEngine *eng)
177 DECLARE_SELF(QPainter, deviceMatrix);
178 return qScriptValueFromValue(eng, self->deviceMatrix());
181 /////////////////////////////////////////////////////////////
183 static QScriptValue deviceTransform(QScriptContext *ctx, QScriptEngine *eng)
185 DECLARE_SELF(QPainter, deviceTransform);
186 return qScriptValueFromValue(eng, self->deviceTransform());
189 /////////////////////////////////////////////////////////////
191 static QScriptValue drawArc(QScriptContext *ctx, QScriptEngine *eng)
193 DECLARE_SELF(QPainter, drawArc);
194 if (ctx->argumentCount() == 6) {
195 // drawArc(x, y, height, width, startAngle, spanAngle)
196 self->drawArc(ctx->argument(0).toInt32(),
197 ctx->argument(1).toInt32(),
198 ctx->argument(2).toInt32(),
199 ctx->argument(3).toInt32(),
200 ctx->argument(4).toInt32(),
201 ctx->argument(5).toInt32());
202 } else if (ctx->argumentCount() == 3) {
203 // drawArc(rectangle, startAngle, spanAngle)
204 self->drawArc(qscriptvalue_cast<QRectF>(ctx->argument(0)),
205 ctx->argument(1).toInt32(),
206 ctx->argument(2).toInt32());
208 return eng->undefinedValue();
211 /////////////////////////////////////////////////////////////
213 static QScriptValue drawChord(QScriptContext *ctx, QScriptEngine *eng)
215 DECLARE_SELF(QPainter, drawChord);
216 if (ctx->argumentCount() == 6) {
217 // x, y, height, width, startAngle, spanAngle
218 self->drawChord(ctx->argument(0).toInt32(),
219 ctx->argument(1).toInt32(),
220 ctx->argument(2).toInt32(),
221 ctx->argument(3).toInt32(),
222 ctx->argument(4).toInt32(),
223 ctx->argument(5).toInt32());
224 } else if (ctx->argumentCount() == 3) {
225 // rectangle, startAngle, spanAngle
226 self->drawChord(qscriptvalue_cast<QRectF>(ctx->argument(0)),
227 ctx->argument(1).toInt32(),
228 ctx->argument(2).toInt32());
230 return eng->undefinedValue();
233 /////////////////////////////////////////////////////////////
235 static QScriptValue drawConvexPolygon(QScriptContext *ctx, QScriptEngine *eng)
237 DECLARE_SELF(QPainter, drawConvexPolygon);
238 self->drawConvexPolygon(qscriptvalue_cast<QPolygonF>(ctx->argument(0)));
239 return eng->undefinedValue();
242 /////////////////////////////////////////////////////////////
244 static QScriptValue drawEllipse(QScriptContext *ctx, QScriptEngine *eng)
246 DECLARE_SELF(QPainter, drawEllipse);
247 if (ctx->argumentCount() == 4) {
248 // drawEllipse(x, y, width, height)
249 self->drawEllipse(ctx->argument(0).toInt32(),
250 ctx->argument(1).toInt32(),
251 ctx->argument(2).toInt32(),
252 ctx->argument(3).toInt32());
253 } else if (ctx->argumentCount() == 1) {
254 // drawEllipse(rect)
255 self->drawEllipse(qscriptvalue_cast<QRectF>(ctx->argument(0)));
257 return eng->undefinedValue();
260 /////////////////////////////////////////////////////////////
262 static QScriptValue drawImage(QScriptContext *ctx, QScriptEngine *eng)
264 DECLARE_SELF(QPainter, drawImage);
265 if (ctx->argumentCount() == 2) {
266 // target, image
267 QScriptValue arg0 = ctx->argument(0);
268 QImage image = qscriptvalue_cast<QImage>(ctx->argument(1));
269 if (arg0.property("width").isValid()) {
270 self->drawImage(qscriptvalue_cast<QRectF>(arg0), image);
271 } else {
272 self->drawImage(qscriptvalue_cast<QPointF>(arg0), image);
274 } else if (ctx->argumentCount() == 3) {
275 // x, y, image
276 self->drawImage(ctx->argument(0).toInt32(),
277 ctx->argument(1).toInt32(),
278 qscriptvalue_cast<QImage>(ctx->argument(2)));
279 } else if (ctx->argumentCount() == 5) {
280 // x, y, width, height, image
281 self->drawImage(QRect(ctx->argument(0).toInt32(),
282 ctx->argument(1).toInt32(),
283 ctx->argument(2).toInt32(),
284 ctx->argument(3).toInt32()),
285 qscriptvalue_cast<QImage>(ctx->argument(4)));
287 return eng->undefinedValue();
290 /////////////////////////////////////////////////////////////
292 static QScriptValue drawLine(QScriptContext *ctx, QScriptEngine *eng)
294 DECLARE_SELF(QPainter, drawLine);
295 if (ctx->argumentCount() == 4) {
296 // x1, y1, x2, y2
297 self->drawLine(ctx->argument(0).toInt32(),
298 ctx->argument(1).toInt32(),
299 ctx->argument(2).toInt32(),
300 ctx->argument(3).toInt32());
301 } else if (ctx->argumentCount() == 2) {
302 // p1, p2
303 self->drawLine(qscriptvalue_cast<QPointF>(ctx->argument(0)),
304 qscriptvalue_cast<QPointF>(ctx->argument(1)));
305 } else if (ctx->argumentCount() == 1) {
306 // line
307 self->drawLine(qscriptvalue_cast<QLineF>(ctx->argument(0)));
309 return eng->undefinedValue();
312 /////////////////////////////////////////////////////////////
314 static QScriptValue drawLines(QScriptContext *ctx, QScriptEngine *eng)
316 DECLARE_SELF(QPainter, drawLines);
317 return ctx->throwError("QPainter.prototype.drawLines is not implemented");
318 // self->drawLines(qscriptvalue_cast<QVector<QLineF> >(ctx->argument(0)));
319 return eng->undefinedValue();
322 /////////////////////////////////////////////////////////////
324 static QScriptValue drawPath(QScriptContext *ctx, QScriptEngine *eng)
326 DECLARE_SELF(QPainter, drawPath);
327 self->drawPath(qscriptvalue_cast<QPainterPath>(ctx->argument(0)));
328 return eng->undefinedValue();
331 /////////////////////////////////////////////////////////////
333 static QScriptValue drawPicture(QScriptContext *ctx, QScriptEngine *eng)
335 DECLARE_SELF(QPainter, drawPicture);
336 if (ctx->argumentCount() == 2) {
337 self->drawPicture(qscriptvalue_cast<QPointF>(ctx->argument(0)),
338 qscriptvalue_cast<QPicture>(ctx->argument(1)));
339 } else if (ctx->argumentCount() == 3) {
340 self->drawPicture(ctx->argument(0).toInt32(),
341 ctx->argument(1).toInt32(),
342 qscriptvalue_cast<QPicture>(ctx->argument(2)));
344 return eng->undefinedValue();
347 /////////////////////////////////////////////////////////////
349 static QScriptValue drawPie(QScriptContext *ctx, QScriptEngine *eng)
351 DECLARE_SELF(QPainter, drawPie);
352 if (ctx->argumentCount() == 6) {
353 // x, y, height, width, startAngle, spanAngle
354 self->drawPie(ctx->argument(0).toInt32(),
355 ctx->argument(1).toInt32(),
356 ctx->argument(2).toInt32(),
357 ctx->argument(3).toInt32(),
358 ctx->argument(4).toInt32(),
359 ctx->argument(5).toInt32());
360 } else if (ctx->argumentCount() == 3) {
361 // rectangle, startAngle, spanAngle
362 self->drawPie(qscriptvalue_cast<QRectF>(ctx->argument(0)),
363 ctx->argument(1).toInt32(),
364 ctx->argument(2).toInt32());
366 return eng->undefinedValue();
369 /////////////////////////////////////////////////////////////
371 static QScriptValue drawPixmap(QScriptContext *ctx, QScriptEngine *eng)
373 DECLARE_SELF(QPainter, drawPixmap);
374 if (ctx->argumentCount() == 2) {
375 // target, pixmap
376 QScriptValue arg0 = ctx->argument(0);
377 QPixmap pixmap = qscriptvalue_cast<QPixmap>(ctx->argument(1));
378 if (arg0.property("width").isValid()) {
379 self->drawPixmap(qscriptvalue_cast<QRectF>(arg0), pixmap,
380 QRectF(0, 0, pixmap.width(), pixmap.height()));
381 } else {
382 self->drawPixmap(qscriptvalue_cast<QPointF>(arg0), pixmap);
384 } else if (ctx->argumentCount() == 3) {
385 // x, y, pixmap
386 self->drawPixmap(ctx->argument(0).toInt32(),
387 ctx->argument(1).toInt32(),
388 qscriptvalue_cast<QPixmap>(ctx->argument(2)));
389 } else if (ctx->argumentCount() == 5) {
390 // x, y, width, height, pixmap
391 self->drawPixmap(ctx->argument(0).toInt32(),
392 ctx->argument(1).toInt32(),
393 ctx->argument(2).toInt32(),
394 ctx->argument(3).toInt32(),
395 qscriptvalue_cast<QPixmap>(ctx->argument(4)));
397 return eng->undefinedValue();
400 /////////////////////////////////////////////////////////////
402 static QScriptValue drawPoint(QScriptContext *ctx, QScriptEngine *eng)
404 DECLARE_SELF(QPainter, drawPoint);
405 if (ctx->argumentCount() == 2) {
406 // drawPoint(x, y)
407 self->drawPoint(ctx->argument(0).toInt32(),
408 ctx->argument(1).toInt32());
409 } else if (ctx->argumentCount() == 1) {
410 // drawPoint(point)
411 self->drawPoint(qscriptvalue_cast<QPointF>(ctx->argument(0)));
413 return eng->undefinedValue();
416 /////////////////////////////////////////////////////////////
418 static QScriptValue drawPoints(QScriptContext *ctx, QScriptEngine *eng)
420 DECLARE_SELF(QPainter, drawPoints);
421 self->drawPoints(qscriptvalue_cast<QPolygonF>(ctx->argument(0)));
422 return eng->undefinedValue();
425 /////////////////////////////////////////////////////////////
427 static QScriptValue drawPolygon(QScriptContext *ctx, QScriptEngine *eng)
429 DECLARE_SELF(QPainter, drawPolygon);
430 // ### fillRule (2nd argument)
431 self->drawPolygon(qscriptvalue_cast<QPolygonF>(ctx->argument(0)));
432 return eng->undefinedValue();
435 /////////////////////////////////////////////////////////////
437 static QScriptValue drawPolyline(QScriptContext *ctx, QScriptEngine *eng)
439 DECLARE_SELF(QPainter, drawPolyline);
440 self->drawPolyline(qscriptvalue_cast<QPolygonF>(ctx->argument(0)));
441 return eng->undefinedValue();
444 /////////////////////////////////////////////////////////////
446 static QScriptValue drawRect(QScriptContext *ctx, QScriptEngine *eng)
448 DECLARE_SELF(QPainter, drawRect);
449 if (ctx->argumentCount() == 4) {
450 // x, y, width, height
451 self->drawRect(ctx->argument(0).toInt32(),
452 ctx->argument(1).toInt32(),
453 ctx->argument(2).toInt32(),
454 ctx->argument(3).toInt32());
455 } else if (ctx->argumentCount() == 1) {
456 // rect
457 self->drawRect(qscriptvalue_cast<QRectF>(ctx->argument(0)));
459 return eng->undefinedValue();
462 /////////////////////////////////////////////////////////////
464 static QScriptValue drawRects(QScriptContext *ctx, QScriptEngine *eng)
466 DECLARE_SELF(QPainter, drawRects);
467 self->drawRects(qscriptvalue_cast<QVector<QRectF> >(ctx->argument(0)));
468 return eng->undefinedValue();
471 /////////////////////////////////////////////////////////////
473 static QScriptValue drawRoundRect(QScriptContext *ctx, QScriptEngine *eng)
475 DECLARE_SELF(QPainter, drawRoundRect);
476 // ### xRnd, yRnd
477 if (ctx->argumentCount() >= 4) {
478 self->drawRoundRect(ctx->argument(0).toInt32(),
479 ctx->argument(1).toInt32(),
480 ctx->argument(2).toInt32(),
481 ctx->argument(3).toInt32());
482 } else {
483 self->drawRoundRect(qscriptvalue_cast<QRectF>(ctx->argument(0)));
485 return eng->undefinedValue();
488 /////////////////////////////////////////////////////////////
490 static QScriptValue drawText(QScriptContext *ctx, QScriptEngine *eng)
492 DECLARE_SELF(QPainter, drawText);
493 if (ctx->argumentCount() == 3) {
494 // x, y, text
495 self->drawText(ctx->argument(0).toInt32(),
496 ctx->argument(1).toInt32(),
497 ctx->argument(2).toString());
498 } else if (ctx->argumentCount() == 2) {
499 QScriptValue arg0 = ctx->argument(0);
500 if (arg0.property("width").isValid()) {
501 self->drawText(qscriptvalue_cast<QRectF>(arg0),
502 ctx->argument(1).toString());
503 } else {
504 self->drawText(qscriptvalue_cast<QPointF>(arg0),
505 ctx->argument(1).toString());
508 return eng->undefinedValue();
511 /////////////////////////////////////////////////////////////
513 static QScriptValue drawTiledPixmap(QScriptContext *ctx, QScriptEngine *eng)
515 DECLARE_SELF(QPainter, drawTiledPixmap);
516 if (ctx->argumentCount() >= 5) {
517 // x, y, width, height, pixmap, sx, sy
518 self->drawTiledPixmap(ctx->argument(0).toInt32(),
519 ctx->argument(1).toInt32(),
520 ctx->argument(2).toInt32(),
521 ctx->argument(3).toInt32(),
522 qscriptvalue_cast<QPixmap>(ctx->argument(4)),
523 ctx->argument(5).toInt32(),
524 ctx->argument(6).toInt32());
525 } else {
526 // rect, pixmap, position
527 self->drawTiledPixmap(qscriptvalue_cast<QRectF>(ctx->argument(0)),
528 qscriptvalue_cast<QPixmap>(ctx->argument(1)),
529 qscriptvalue_cast<QPointF>(ctx->argument(2)));
531 return eng->undefinedValue();
534 /////////////////////////////////////////////////////////////
536 static QScriptValue end(QScriptContext *ctx, QScriptEngine *eng)
538 DECLARE_SELF(QPainter, end);
539 return QScriptValue(eng, self->end());
542 /////////////////////////////////////////////////////////////
544 static QScriptValue eraseRect(QScriptContext *ctx, QScriptEngine *eng)
546 DECLARE_SELF(QPainter, eraseRect);
547 if (ctx->argumentCount() == 4) {
548 // x, y, width, height
549 self->eraseRect(ctx->argument(0).toInt32(),
550 ctx->argument(1).toInt32(),
551 ctx->argument(2).toInt32(),
552 ctx->argument(3).toInt32());
553 } else if (ctx->argumentCount() == 1) {
554 // rect
555 self->eraseRect(qscriptvalue_cast<QRectF>(ctx->argument(0)));
557 return eng->undefinedValue();
560 /////////////////////////////////////////////////////////////
562 static QScriptValue fillPath(QScriptContext *ctx, QScriptEngine *eng)
564 DECLARE_SELF(QPainter, fillPath);
565 QPainterPath *path = qscriptvalue_cast<QPainterPath*>(ctx->argument(0));
566 if (!path) {
567 return ctx->throwError(QScriptContext::TypeError,
568 "QPainter.prototype.fillPath: argument is not a PainterPath");
570 self->fillPath(*path, qscriptvalue_cast<QBrush>(ctx->argument(1)));
571 return eng->undefinedValue();
574 /////////////////////////////////////////////////////////////
576 static QScriptValue fillRect(QScriptContext *ctx, QScriptEngine *eng)
578 DECLARE_SELF(QPainter, fillRect);
579 if (ctx->argumentCount() == 5) {
580 // x, y, width, height, brush
581 self->fillRect(ctx->argument(0).toInt32(),
582 ctx->argument(1).toInt32(),
583 ctx->argument(2).toInt32(),
584 ctx->argument(3).toInt32(),
585 qscriptvalue_cast<QBrush>(ctx->argument(4)));
586 } else if (ctx->argumentCount() == 2) {
587 // rect, brush
588 self->fillRect(qscriptvalue_cast<QRectF>(ctx->argument(0)),
589 qscriptvalue_cast<QBrush>(ctx->argument(1)));
591 return eng->undefinedValue();
594 /////////////////////////////////////////////////////////////
596 static QScriptValue font(QScriptContext *ctx, QScriptEngine *eng)
598 DECLARE_SELF(QPainter, font);
599 return qScriptValueFromValue(eng, self->font());
602 /////////////////////////////////////////////////////////////
604 static QScriptValue fontInfo(QScriptContext *ctx, QScriptEngine *)
606 DECLARE_SELF(QPainter, fontInfo);
607 return ctx->throwError("QPainter.prototype.fontInfo is not implemented");
610 /////////////////////////////////////////////////////////////
612 static QScriptValue fontMetrics(QScriptContext *ctx, QScriptEngine *)
614 DECLARE_SELF(QPainter, fontMetrics);
615 return ctx->throwError("QPainter.prototype.fontMetrics is not implemented");
618 /////////////////////////////////////////////////////////////
620 static QScriptValue hasClipping(QScriptContext *ctx, QScriptEngine *eng)
622 DECLARE_SELF(QPainter, hasClipping);
623 return QScriptValue(eng, self->hasClipping());
626 /////////////////////////////////////////////////////////////
628 static QScriptValue initFrom(QScriptContext *ctx, QScriptEngine *eng)
630 DECLARE_SELF(QPainter, initFrom);
631 QWidget *widget = qscriptvalue_cast<QWidget*>(ctx->argument(0));
632 if (!widget) {
633 return ctx->throwError(QScriptContext::TypeError,
634 "QPainter.prototype.initFrom: argument is not a Widget");
636 self->initFrom(widget);
637 return eng->undefinedValue();
640 /////////////////////////////////////////////////////////////
642 static QScriptValue isActive(QScriptContext *ctx, QScriptEngine *eng)
644 DECLARE_SELF(QPainter, isActive);
645 return QScriptValue(eng, self->isActive());
648 /////////////////////////////////////////////////////////////
650 static QScriptValue layoutDirection(QScriptContext *ctx, QScriptEngine *eng)
652 DECLARE_SELF(QPainter, layoutDirection);
653 return QScriptValue(eng, static_cast<int>(self->layoutDirection()));
656 /////////////////////////////////////////////////////////////
658 static QScriptValue opacity(QScriptContext *ctx, QScriptEngine *eng)
660 DECLARE_SELF(QPainter, opacity);
661 return QScriptValue(eng, self->opacity());
664 /////////////////////////////////////////////////////////////
666 static QScriptValue paintEngine(QScriptContext *ctx, QScriptEngine *eng)
668 DECLARE_SELF(QPainter, paintEngine);
669 return qScriptValueFromValue(eng, self->paintEngine());
672 /////////////////////////////////////////////////////////////
674 static QScriptValue pen(QScriptContext *ctx, QScriptEngine *eng)
676 DECLARE_SELF(QPainter, pen);
677 return qScriptValueFromValue(eng, self->pen());
680 /////////////////////////////////////////////////////////////
682 static QScriptValue renderHints(QScriptContext *ctx, QScriptEngine *eng)
684 DECLARE_SELF(QPainter, renderHints);
685 return QScriptValue(eng, static_cast<int>(self->renderHints()));
688 /////////////////////////////////////////////////////////////
690 static QScriptValue resetMatrix(QScriptContext *ctx, QScriptEngine *eng)
692 DECLARE_SELF(QPainter, resetMatrix);
693 self->resetMatrix();
694 return eng->undefinedValue();
697 /////////////////////////////////////////////////////////////
699 static QScriptValue resetTransform(QScriptContext *ctx, QScriptEngine *eng)
701 DECLARE_SELF(QPainter, resetTransform);
702 self->resetTransform();
703 return eng->undefinedValue();
706 /////////////////////////////////////////////////////////////
708 static QScriptValue restore(QScriptContext *ctx, QScriptEngine *eng)
710 DECLARE_SELF(QPainter, restore);
711 self->restore();
712 return eng->undefinedValue();
715 /////////////////////////////////////////////////////////////
717 static QScriptValue rotate(QScriptContext *ctx, QScriptEngine *eng)
719 DECLARE_SELF(QPainter, rotate);
720 self->rotate(ctx->argument(0).toNumber());
721 return eng->undefinedValue();
724 /////////////////////////////////////////////////////////////
726 static QScriptValue save(QScriptContext *ctx, QScriptEngine *eng)
728 DECLARE_SELF(QPainter, save);
729 self->save();
730 return eng->undefinedValue();
733 /////////////////////////////////////////////////////////////
735 static QScriptValue scale(QScriptContext *ctx, QScriptEngine *eng)
737 DECLARE_SELF(QPainter, scale);
738 self->scale(ctx->argument(0).toNumber(),
739 ctx->argument(1).toNumber());
740 return eng->undefinedValue();
743 /////////////////////////////////////////////////////////////
745 static QScriptValue setBackground(QScriptContext *ctx, QScriptEngine *eng)
747 DECLARE_SELF(QPainter, setBackground);
748 self->setBackground(qscriptvalue_cast<QBrush>(ctx->argument(0)));
749 return eng->undefinedValue();
752 /////////////////////////////////////////////////////////////
754 static QScriptValue setBackgroundMode(QScriptContext *ctx, QScriptEngine *eng)
756 DECLARE_SELF(QPainter, setBackgroundMode);
757 self->setBackgroundMode(static_cast<Qt::BGMode>(ctx->argument(0).toInt32()));
758 return eng->undefinedValue();
761 /////////////////////////////////////////////////////////////
763 static QScriptValue setBrush(QScriptContext *ctx, QScriptEngine *eng)
765 DECLARE_SELF(QPainter, setBrush);
766 self->setBrush(qscriptvalue_cast<QBrush>(ctx->argument(0)));
767 return eng->undefinedValue();
770 /////////////////////////////////////////////////////////////
772 static QScriptValue setBrushOrigin(QScriptContext *ctx, QScriptEngine *eng)
774 DECLARE_SELF(QPainter, setBrushOrigin);
775 self->setBrushOrigin(qscriptvalue_cast<QPointF>(ctx->argument(0)));
776 return eng->undefinedValue();
779 /////////////////////////////////////////////////////////////
781 static QScriptValue setClipPath(QScriptContext *ctx, QScriptEngine *eng)
783 DECLARE_SELF(QPainter, setClipPath);
784 // ### ClipOperation
785 self->setClipPath(qscriptvalue_cast<QPainterPath>(ctx->argument(0)));
786 return eng->undefinedValue();
789 /////////////////////////////////////////////////////////////
791 static QScriptValue setClipRect(QScriptContext *ctx, QScriptEngine *eng)
793 DECLARE_SELF(QPainter, setClipRect);
794 // ### ClipOperation
795 if (ctx->argumentCount() >= 4) {
796 // x, y, width, height [, operation]
797 self->setClipRect(ctx->argument(0).toInt32(),
798 ctx->argument(1).toInt32(),
799 ctx->argument(2).toInt32(),
800 ctx->argument(3).toInt32());
801 } else if (ctx->argumentCount() >= 1) {
802 // rect [, operation]
803 self->setClipRect(qscriptvalue_cast<QRectF>(ctx->argument(0)));
805 return eng->undefinedValue();
808 /////////////////////////////////////////////////////////////
810 static QScriptValue setClipRegion(QScriptContext *ctx, QScriptEngine *eng)
812 DECLARE_SELF(QPainter, setClipRegion);
813 // ### ClipOperation
814 self->setClipRegion(qscriptvalue_cast<QRegion>(ctx->argument(0)));
815 return eng->undefinedValue();
818 /////////////////////////////////////////////////////////////
820 static QScriptValue setClipping(QScriptContext *ctx, QScriptEngine *eng)
822 DECLARE_SELF(QPainter, setClipping);
823 self->setClipping(ctx->argument(0).toBoolean());
824 return eng->undefinedValue();
827 /////////////////////////////////////////////////////////////
829 static QScriptValue setCompositionMode(QScriptContext *ctx, QScriptEngine *eng)
831 DECLARE_SELF(QPainter, setCompositionMode);
832 self->setCompositionMode(static_cast<QPainter::CompositionMode>(ctx->argument(0).toInt32()));
833 return eng->undefinedValue();
836 /////////////////////////////////////////////////////////////
838 static QScriptValue setFont(QScriptContext *ctx, QScriptEngine *eng)
840 DECLARE_SELF(QPainter, setFont);
841 self->setFont(qscriptvalue_cast<QFont>(ctx->argument(0)));
842 return eng->undefinedValue();
845 /////////////////////////////////////////////////////////////
847 static QScriptValue setLayoutDirection(QScriptContext *ctx, QScriptEngine *eng)
849 DECLARE_SELF(QPainter, setLayoutDirection);
850 self->setLayoutDirection(static_cast<Qt::LayoutDirection>(ctx->argument(0).toInt32()));
851 return eng->undefinedValue();
854 /////////////////////////////////////////////////////////////
856 static QScriptValue setOpacity(QScriptContext *ctx, QScriptEngine *eng)
858 DECLARE_SELF(QPainter, setOpacity);
859 self->setOpacity(ctx->argument(0).toNumber());
860 return eng->undefinedValue();
863 /////////////////////////////////////////////////////////////
865 static QScriptValue setPen(QScriptContext *ctx, QScriptEngine *eng)
867 DECLARE_SELF(QPainter, setPen);
868 self->setPen(qscriptvalue_cast<QPen>(ctx->argument(0)));
869 return eng->undefinedValue();
872 /////////////////////////////////////////////////////////////
874 static QScriptValue setRenderHint(QScriptContext *ctx, QScriptEngine *eng)
876 DECLARE_SELF(QPainter, setRenderHint);
877 self->setRenderHint(static_cast<QPainter::RenderHint>(ctx->argument(0).toInt32()),
878 ctx->argument(1).toBoolean());
879 return eng->undefinedValue();
882 /////////////////////////////////////////////////////////////
884 static QScriptValue setRenderHints(QScriptContext *ctx, QScriptEngine *eng)
886 DECLARE_SELF(QPainter, setRenderHints);
887 self->setRenderHints(static_cast<QPainter::RenderHints>(ctx->argument(0).toInt32()),
888 ctx->argument(1).toBoolean());
889 return eng->undefinedValue();
892 /////////////////////////////////////////////////////////////
894 static QScriptValue setTransform(QScriptContext *ctx, QScriptEngine *eng)
896 DECLARE_SELF(QPainter, setTransform);
897 self->setTransform(qscriptvalue_cast<QTransform>(ctx->argument(0)));
898 return eng->undefinedValue();
901 /////////////////////////////////////////////////////////////
903 static QScriptValue setViewTransformEnabled(QScriptContext *ctx, QScriptEngine *eng)
905 DECLARE_SELF(QPainter, setViewTransformEnabled);
906 self->setViewTransformEnabled(ctx->argument(0).toBoolean());
907 return eng->undefinedValue();
910 /////////////////////////////////////////////////////////////
912 static QScriptValue setViewport(QScriptContext *ctx, QScriptEngine *eng)
914 DECLARE_SELF(QPainter, setViewport);
915 if (ctx->argumentCount() == 4) {
916 // x, y, width, height
917 self->setViewport(ctx->argument(0).toInt32(),
918 ctx->argument(1).toInt32(),
919 ctx->argument(2).toInt32(),
920 ctx->argument(3).toInt32());
921 } else if (ctx->argumentCount() == 1) {
922 // rect
923 self->setViewport(qscriptvalue_cast<QRect>(ctx->argument(0)));
925 return eng->undefinedValue();
928 /////////////////////////////////////////////////////////////
930 static QScriptValue setWindow(QScriptContext *ctx, QScriptEngine *eng)
932 DECLARE_SELF(QPainter, setWindow);
933 if (ctx->argumentCount() == 4) {
934 // x, y, width, height
935 self->setWindow(ctx->argument(0).toInt32(),
936 ctx->argument(1).toInt32(),
937 ctx->argument(2).toInt32(),
938 ctx->argument(3).toInt32());
939 } else if (ctx->argumentCount() == 1) {
940 // rect
941 self->setWindow(qscriptvalue_cast<QRect>(ctx->argument(0)));
943 return eng->undefinedValue();
946 /////////////////////////////////////////////////////////////
948 static QScriptValue setWorldMatrix(QScriptContext *ctx, QScriptEngine *eng)
950 DECLARE_SELF(QPainter, setWorldMatrix);
951 self->setWorldMatrix(qscriptvalue_cast<QMatrix>(ctx->argument(0)),
952 ctx->argument(1).toBoolean());
953 return eng->undefinedValue();
956 /////////////////////////////////////////////////////////////
958 static QScriptValue setWorldMatrixEnabled(QScriptContext *ctx, QScriptEngine *eng)
960 DECLARE_SELF(QPainter, setWorldMatrixEnabled);
961 self->setWorldMatrixEnabled(ctx->argument(0).toBoolean());
962 return eng->undefinedValue();
965 /////////////////////////////////////////////////////////////
967 static QScriptValue setWorldTransform(QScriptContext *ctx, QScriptEngine *eng)
969 DECLARE_SELF(QPainter, setWorldTransform);
970 self->setWorldTransform(qscriptvalue_cast<QTransform>(ctx->argument(0)),
971 ctx->argument(1).toBoolean());
972 return eng->undefinedValue();
975 /////////////////////////////////////////////////////////////
977 static QScriptValue shear(QScriptContext *ctx, QScriptEngine *eng)
979 DECLARE_SELF(QPainter, shear);
980 self->shear(ctx->argument(0).toNumber(),
981 ctx->argument(1).toNumber());
982 return eng->undefinedValue();
985 /////////////////////////////////////////////////////////////
987 static QScriptValue strokePath(QScriptContext *ctx, QScriptEngine *eng)
989 DECLARE_SELF(QPainter, strokePath);
990 QPainterPath *path = qscriptvalue_cast<QPainterPath*>(ctx->argument(0));
991 if (!path) {
992 return ctx->throwError(QScriptContext::TypeError,
993 "QPainter.prototype.strokePath: argument is not a PainterPath");
995 self->strokePath(*path, qscriptvalue_cast<QPen>(ctx->argument(1)));
996 return eng->undefinedValue();
999 /////////////////////////////////////////////////////////////
1001 static QScriptValue testRenderHint(QScriptContext *ctx, QScriptEngine *eng)
1003 DECLARE_SELF(QPainter, testRenderHint);
1004 return QScriptValue(eng, self->testRenderHint(static_cast<QPainter::RenderHint>(ctx->argument(0).toInt32())));
1007 /////////////////////////////////////////////////////////////
1009 static QScriptValue transform(QScriptContext *ctx, QScriptEngine *eng)
1011 DECLARE_SELF(QPainter, transform);
1012 return qScriptValueFromValue(eng, self->transform());
1015 /////////////////////////////////////////////////////////////
1017 static QScriptValue translate(QScriptContext *ctx, QScriptEngine *eng)
1019 DECLARE_SELF(QPainter, translate);
1020 if (ctx->argumentCount() == 2) {
1021 // dx, dy
1022 self->translate(ctx->argument(0).toNumber(),
1023 ctx->argument(1).toNumber());
1024 } else if (ctx->argumentCount() == 1) {
1025 // offset
1026 self->translate(qscriptvalue_cast<QPointF>(ctx->argument(0)));
1028 return eng->undefinedValue();
1031 /////////////////////////////////////////////////////////////
1033 static QScriptValue viewTransformEnabled(QScriptContext *ctx, QScriptEngine *eng)
1035 DECLARE_SELF(QPainter, viewTransformEnabled);
1036 return QScriptValue(eng, self->viewTransformEnabled());
1039 /////////////////////////////////////////////////////////////
1041 static QScriptValue viewport(QScriptContext *ctx, QScriptEngine *eng)
1043 DECLARE_SELF(QPainter, viewport);
1044 return qScriptValueFromValue(eng, self->viewport());
1047 /////////////////////////////////////////////////////////////
1049 static QScriptValue window(QScriptContext *ctx, QScriptEngine *eng)
1051 DECLARE_SELF(QPainter, window);
1052 return qScriptValueFromValue(eng, self->window());
1055 /////////////////////////////////////////////////////////////
1057 static QScriptValue worldMatrix(QScriptContext *ctx, QScriptEngine *eng)
1059 DECLARE_SELF(QPainter, worldMatrix);
1060 return qScriptValueFromValue(eng, self->worldMatrix());
1063 /////////////////////////////////////////////////////////////
1065 static QScriptValue worldMatrixEnabled(QScriptContext *ctx, QScriptEngine *eng)
1067 DECLARE_SELF(QPainter, worldMatrixEnabled);
1068 return QScriptValue(eng, self->worldMatrixEnabled());
1071 /////////////////////////////////////////////////////////////
1073 static QScriptValue worldTransform(QScriptContext *ctx, QScriptEngine *eng)
1075 DECLARE_SELF(QPainter, worldTransform);
1076 return qScriptValueFromValue(eng, self->worldTransform());
1079 /////////////////////////////////////////////////////////////
1081 static QScriptValue toString(QScriptContext *ctx, QScriptEngine *eng)
1083 DECLARE_SELF(QPainter, toString);
1084 return QScriptValue(eng, "QPainter");
1087 /////////////////////////////////////////////////////////////
1089 QScriptValue constructPainterClass(QScriptEngine *eng)
1091 QScriptValue proto = newPainter(eng, new QPainter());
1092 ADD_METHOD(proto, background);
1093 ADD_METHOD(proto, backgroundMode);
1094 ADD_METHOD(proto, begin);
1095 ADD_METHOD(proto, boundingRect);
1096 ADD_METHOD(proto, brush);
1097 ADD_METHOD(proto, brushOrigin);
1098 ADD_METHOD(proto, clipPath);
1099 ADD_METHOD(proto, clipRegion);
1100 ADD_METHOD(proto, combinedMatrix);
1101 ADD_METHOD(proto, combinedTransform);
1102 ADD_METHOD(proto, compositionMode);
1103 ADD_METHOD(proto, device);
1104 ADD_METHOD(proto, deviceMatrix);
1105 ADD_METHOD(proto, deviceTransform);
1106 ADD_METHOD(proto, drawChord);
1107 ADD_METHOD(proto, drawConvexPolygon);
1108 ADD_METHOD(proto, drawArc);
1109 ADD_METHOD(proto, drawEllipse);
1110 ADD_METHOD(proto, drawImage);
1111 ADD_METHOD(proto, drawLine);
1112 ADD_METHOD(proto, drawLines);
1113 ADD_METHOD(proto, drawPath);
1114 ADD_METHOD(proto, drawPicture);
1115 ADD_METHOD(proto, drawPie);
1116 ADD_METHOD(proto, drawPixmap);
1117 ADD_METHOD(proto, drawPoint);
1118 ADD_METHOD(proto, drawPoints);
1119 ADD_METHOD(proto, drawPolygon);
1120 ADD_METHOD(proto, drawPolyline);
1121 ADD_METHOD(proto, drawRect);
1122 ADD_METHOD(proto, drawRects);
1123 ADD_METHOD(proto, drawRoundRect);
1124 ADD_METHOD(proto, drawText);
1125 ADD_METHOD(proto, drawTiledPixmap);
1126 ADD_METHOD(proto, end);
1127 ADD_METHOD(proto, eraseRect);
1128 ADD_METHOD(proto, fillPath);
1129 ADD_METHOD(proto, fillRect);
1130 ADD_METHOD(proto, font);
1131 ADD_METHOD(proto, fontInfo);
1132 ADD_METHOD(proto, fontMetrics);
1133 ADD_METHOD(proto, hasClipping);
1134 ADD_METHOD(proto, initFrom);
1135 ADD_METHOD(proto, isActive);
1136 ADD_METHOD(proto, layoutDirection);
1137 ADD_METHOD(proto, opacity);
1138 ADD_METHOD(proto, paintEngine);
1139 ADD_METHOD(proto, pen);
1140 ADD_METHOD(proto, renderHints);
1141 ADD_METHOD(proto, resetMatrix);
1142 ADD_METHOD(proto, resetTransform);
1143 ADD_METHOD(proto, restore);
1144 ADD_METHOD(proto, rotate);
1145 ADD_METHOD(proto, save);
1146 ADD_METHOD(proto, scale);
1147 ADD_METHOD(proto, setBackground);
1148 ADD_METHOD(proto, setBackgroundMode);
1149 ADD_METHOD(proto, setBrush);
1150 ADD_METHOD(proto, setBrushOrigin);
1151 ADD_METHOD(proto, setClipPath);
1152 ADD_METHOD(proto, setClipRect);
1153 ADD_METHOD(proto, setClipRegion);
1154 ADD_METHOD(proto, setClipping);
1155 ADD_METHOD(proto, setCompositionMode);
1156 ADD_METHOD(proto, setFont);
1157 ADD_METHOD(proto, setLayoutDirection);
1158 ADD_METHOD(proto, setOpacity);
1159 ADD_METHOD(proto, setPen);
1160 ADD_METHOD(proto, setRenderHint);
1161 ADD_METHOD(proto, setRenderHints);
1162 ADD_METHOD(proto, setTransform);
1163 ADD_METHOD(proto, setViewTransformEnabled);
1164 ADD_METHOD(proto, setViewport);
1165 ADD_METHOD(proto, setWindow);
1166 ADD_METHOD(proto, setWorldMatrix);
1167 ADD_METHOD(proto, setWorldMatrixEnabled);
1168 ADD_METHOD(proto, setWorldTransform);
1169 ADD_METHOD(proto, shear);
1170 ADD_METHOD(proto, strokePath);
1171 ADD_METHOD(proto, testRenderHint);
1172 ADD_METHOD(proto, toString);
1173 ADD_METHOD(proto, transform);
1174 ADD_METHOD(proto, translate);
1175 ADD_METHOD(proto, viewTransformEnabled);
1176 ADD_METHOD(proto, viewport);
1177 ADD_METHOD(proto, window);
1178 ADD_METHOD(proto, worldMatrix);
1179 ADD_METHOD(proto, worldMatrixEnabled);
1180 ADD_METHOD(proto, worldTransform);
1182 QScript::registerPointerMetaType<QPainter>(eng, proto);
1184 qScriptRegisterSequenceMetaType<QVector<QRectF> >(eng);
1186 QScriptValue ctorFun = eng->newFunction(ctor, proto);
1187 ADD_ENUM_VALUE(ctorFun, QPainter, Antialiasing);
1188 ADD_ENUM_VALUE(ctorFun, QPainter, TextAntialiasing);
1189 ADD_ENUM_VALUE(ctorFun, QPainter, SmoothPixmapTransform);
1190 ADD_ENUM_VALUE(ctorFun, QPainter, HighQualityAntialiasing);
1192 eng->setDefaultPrototype(qMetaTypeId<QPainter*>(), proto);
1194 return ctorFun;