00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "qpainter_binding.h"
00023 #include "object_binding.h"
00024 #include "static_binding.h"
00025 #include "kjseglobal.h"
00026
00027 #include <kjs/object.h>
00028 #include <QtCore/QDebug>
00029
00030 #include <QtGui/QWidget>
00031 #include <QtGui/QPainter>
00032 #include <QtGui/QImage>
00033 #include <QtGui/QPixmap>
00034 #include <QtGui/QPen>
00035 #include <QtGui/QBrush>
00036 #include <QtCore/QLine>
00037 #include <QtGui/QPolygon>
00038 #include <QtCore/QPoint>
00039
00040 #include <QtGui/QFrame>
00041
00042 using namespace KJSEmbed;
00043
00044 QPaintDevice *extractPaintDevice( KJS::ExecState *exec, KJS::JSValue *arg)
00045 {
00046 QPaintDevice *device = 0;
00047
00048 ObjectBinding *imp = extractBindingImp<ObjectBinding>(exec,arg);
00049 if( imp )
00050 {
00051 #ifdef __GNUC__
00052 #warning There be dragons here...
00053 #endif
00054
00060 QObject *qobject = imp->object<QObject>();
00061 if( qobject )
00062 device = qobject_cast<QWidget*>(qobject);
00063 else
00064 device = imp->object<QPaintDevice>();
00065
00066 if( device )
00067 qDebug("Height = %d Width = %d", device->height(), device->width() );
00068 }
00069 else
00070 {
00071 VariantBinding *valueImp = extractBindingImp<VariantBinding>(exec,arg);
00072 if( valueImp && (valueImp->variant().type() == QVariant::Pixmap ||
00073 valueImp->variant().type() == QVariant::Image ))
00074 {
00075 device = static_cast<QPaintDevice*>( valueImp->pointer() );
00076 }
00077 }
00078 return device;
00079 }
00080
00081 START_OBJECT_METHOD( callPainterBegin, QPainter )
00082 result = KJS::jsBoolean(false);
00083 QPaintDevice *device = extractPaintDevice(exec, args[0]);
00084 if( device )
00085 {
00086 result = KJS::jsBoolean(object->begin(device));
00087 } else {
00088 result = KJS::jsBoolean(false);
00089 }
00090 END_OBJECT_METHOD
00091
00092 START_OBJECT_METHOD( callPainterEnd, QPainter )
00093 result = KJS::jsBoolean(object->end());
00094 END_OBJECT_METHOD
00095
00096 START_OBJECT_METHOD( callbackground, QPainter )
00097 QBrush cppValue = object->background();
00098 result = KJSEmbed::createVariant(exec, "QBrush", cppValue );
00099 END_OBJECT_METHOD
00100
00101 START_OBJECT_METHOD( callbackgroundMode, QPainter )
00102 Qt::BGMode cppValue = object->backgroundMode();
00103 result = KJS::jsNumber(cppValue);
00104 END_OBJECT_METHOD
00105
00106 START_OBJECT_METHOD( callboundingRect, QPainter )
00107 if( args.size() == 3 )
00108 {
00109 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec,args, 0);
00110 int arg1 = KJSEmbed::extractInt(exec, args, 1);
00111 QString arg2 = KJSEmbed::extractQString(exec, args, 2);
00112 QRect cppValue = object->boundingRect(arg0, arg1, arg2);
00113 result = KJSEmbed::createVariant(exec, "QRect", cppValue );
00114 }
00115 else if( args.size() == 6)
00116 {
00117 int arg0 = KJSEmbed::extractInt(exec, args, 0);
00118 int arg1 = KJSEmbed::extractInt(exec, args, 1);
00119 int arg2 = KJSEmbed::extractInt(exec, args, 2);
00120 int arg3 = KJSEmbed::extractInt(exec, args, 3);
00121 int arg4 = KJSEmbed::extractInt(exec, args, 4);
00122 QString arg5 = KJSEmbed::extractQString(exec, args, 5);
00123 QRect cppValue = object->boundingRect(arg0, arg1, arg2, arg3, arg4, arg5);
00124 result = KJSEmbed::createVariant(exec, "QRect", cppValue );
00125 }
00126 END_OBJECT_METHOD
00127
00128 START_OBJECT_METHOD( callbrush, QPainter )
00129 QBrush cppValue = object->brush();
00130 result = KJSEmbed::createVariant(exec, "QBrush", cppValue );
00131 END_OBJECT_METHOD
00132
00133 START_OBJECT_METHOD( callbrushOrigin, QPainter )
00134 QPoint cppValue = object->brushOrigin();
00135 result = KJSEmbed::createVariant(exec, "QPoint", cppValue );
00136 END_OBJECT_METHOD
00137
00138 START_OBJECT_METHOD( calldrawArc, QPainter )
00139 if( args.size() == 3 )
00140 {
00141 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec,args, 0);
00142 int arg1 = KJSEmbed::extractInt(exec, args, 1);
00143 int arg2 = KJSEmbed::extractInt(exec, args, 2);
00144 object->drawArc(arg0, arg1, arg2);
00145 }
00146 else if( args.size() == 6 )
00147 {
00148 int arg0 = KJSEmbed::extractInt(exec, args, 0);
00149 int arg1 = KJSEmbed::extractInt(exec, args, 1);
00150 int arg2 = KJSEmbed::extractInt(exec, args, 2);
00151 int arg3 = KJSEmbed::extractInt(exec, args, 3);
00152 int arg4 = KJSEmbed::extractInt(exec, args, 4);
00153 int arg5 = KJSEmbed::extractInt(exec, args, 5);
00154 object->drawArc(arg0, arg1, arg2, arg3, arg4, arg5);
00155 }
00156 END_OBJECT_METHOD
00157
00158 START_OBJECT_METHOD( calldrawChord, QPainter )
00159 if( args.size() == 3 )
00160 {
00161 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec,args, 0);
00162 int arg1 = KJSEmbed::extractInt(exec, args, 1);
00163 int arg2 = KJSEmbed::extractInt(exec, args, 2);
00164 object->drawChord(arg0, arg1, arg2);
00165 }
00166 else if ( args.size() == 6 )
00167 {
00168 int arg0 = KJSEmbed::extractInt(exec, args, 0);
00169 int arg1 = KJSEmbed::extractInt(exec, args, 1);
00170 int arg2 = KJSEmbed::extractInt(exec, args, 2);
00171 int arg3 = KJSEmbed::extractInt(exec, args, 3);
00172 int arg4 = KJSEmbed::extractInt(exec, args, 4);
00173 int arg5 = KJSEmbed::extractInt(exec, args, 5);
00174 object->drawChord(arg0, arg1, arg2, arg3, arg4, arg5);
00175 }
00176 END_OBJECT_METHOD
00177
00178 START_OBJECT_METHOD( calldrawConvexPolygon, QPainter )
00179 QPolygon arg0 = KJSEmbed::extractVariant<QPolygon>(exec,args, 0);
00180 object->drawConvexPolygon(arg0);
00181 END_OBJECT_METHOD
00182
00183 START_OBJECT_METHOD( calldrawEllipse, QPainter )
00184 if ( args.size() == 4 )
00185 {
00186 int arg0 = KJSEmbed::extractInt(exec, args, 0);
00187 int arg1 = KJSEmbed::extractInt(exec, args, 1);
00188 int arg2 = KJSEmbed::extractInt(exec, args, 2);
00189 int arg3 = KJSEmbed::extractInt(exec, args, 3);
00190 object->drawEllipse(arg0, arg1, arg2, arg3);
00191 }
00192 else if ( args.size() == 1 )
00193 {
00194 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec,args, 0);
00195 object->drawEllipse(arg0);
00196 }
00197 END_OBJECT_METHOD
00198
00199 START_OBJECT_METHOD( calldrawImage, QPainter )
00200 if ( args.size() == 2 )
00201 {
00202 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec,args, 0);
00203 QImage arg1 = KJSEmbed::extractVariant<QImage>(exec,args, 1);
00204 object->drawImage(arg0, arg1);
00205 }
00206 else if ( args.size() == 4 )
00207 {
00208 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec,args, 0);
00209 QImage arg1 = KJSEmbed::extractVariant<QImage>(exec,args, 1);
00210 QRect arg2 = KJSEmbed::extractVariant<QRect>(exec,args, 2);
00211 Qt::ImageConversionFlags arg3 = (Qt::ImageConversionFlags)KJSEmbed::extractInt(exec, args, 3);
00212 object->drawImage(arg0, arg1, arg2, arg3);
00213 }
00214 else if ( args.size() == 8 )
00215 {
00216 int arg0 = KJSEmbed::extractInt(exec, args, 0);
00217 int arg1 = KJSEmbed::extractInt(exec, args, 1);
00218 QImage arg2 = KJSEmbed::extractVariant<QImage>(exec,args, 2);
00219 int arg3 = KJSEmbed::extractInt(exec, args, 3);
00220 int arg4 = KJSEmbed::extractInt(exec, args, 4);
00221 int arg5 = KJSEmbed::extractInt(exec, args, 5);
00222 int arg6 = KJSEmbed::extractInt(exec, args, 6);
00223 Qt::ImageConversionFlags arg7 = (Qt::ImageConversionFlags)KJSEmbed::extractInt(exec, args, 7);
00224 object->drawImage(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
00225 }
00226 END_OBJECT_METHOD
00227
00228 START_OBJECT_METHOD( calldrawLine, QPainter )
00229 if( args.size() == 1 )
00230 {
00231 QLine arg0 = KJSEmbed::extractVariant<QLine>(exec,args, 0);
00232 object->drawLine(arg0);
00233 }
00234 else if ( args.size() == 2 )
00235 {
00236 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec,args, 0);
00237 QPoint arg1 = KJSEmbed::extractVariant<QPoint>(exec,args, 1);
00238 object->drawLine(arg0, arg1);
00239 }
00240 else if ( args.size() == 4 )
00241 {
00242 int arg0 = KJSEmbed::extractInt(exec, args, 0);
00243 int arg1 = KJSEmbed::extractInt(exec, args, 1);
00244 int arg2 = KJSEmbed::extractInt(exec, args, 2);
00245 int arg3 = KJSEmbed::extractInt(exec, args, 3);
00246 object->drawLine(arg0, arg1, arg2, arg3);
00247 }
00248 END_OBJECT_METHOD
00249
00250 START_OBJECT_METHOD( calldrawPie, QPainter )
00251 if( args.size() == 3 )
00252 {
00253 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec,args, 0);
00254 int arg1 = KJSEmbed::extractInt(exec, args, 1);
00255 int arg2 = KJSEmbed::extractInt(exec, args, 2);
00256 object->drawPie(arg0, arg1, arg2);
00257 }
00258 else if (args.size() == 6 )
00259 {
00260 int arg0 = KJSEmbed::extractInt(exec, args, 0);
00261 int arg1 = KJSEmbed::extractInt(exec, args, 1);
00262 int arg2 = KJSEmbed::extractInt(exec, args, 2);
00263 int arg3 = KJSEmbed::extractInt(exec, args, 3);
00264 int arg4 = KJSEmbed::extractInt(exec, args, 4);
00265 int arg5 = KJSEmbed::extractInt(exec, args, 5);
00266 object->drawPie(arg0, arg1, arg2, arg3, arg4, arg5);
00267 }
00268 END_OBJECT_METHOD
00269
00270 START_OBJECT_METHOD( calldrawPixmap, QPainter )
00271 if ( args.size() == 2)
00272 {
00273 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec,args, 0);
00274 QPixmap arg1 = KJSEmbed::extractVariant<QPixmap>(exec,args, 1);
00275 object->drawPixmap(arg0, arg1);
00276 }
00277 else if ( args.size() == 3 )
00278 {
00279 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec,args, 0);
00280 QPixmap arg1 = KJSEmbed::extractVariant<QPixmap>(exec,args, 1);
00281 QRect arg2 = KJSEmbed::extractVariant<QRect>(exec,args, 2);
00282 object->drawPixmap(arg0, arg1, arg2);
00283 }
00284 END_OBJECT_METHOD
00285
00286 START_OBJECT_METHOD( calldrawPoint, QPainter )
00287 if( args.size() == 1 )
00288 {
00289 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec,args, 0);
00290 object->drawPoint(arg0);
00291 }
00292 else if (args.size() == 2 )
00293 {
00294 int arg0 = KJSEmbed::extractInt(exec, args, 0);
00295 int arg1 = KJSEmbed::extractInt(exec, args, 1);
00296 object->drawPoint(arg0, arg1);
00297 }
00298 END_OBJECT_METHOD
00299
00300 START_OBJECT_METHOD( calldrawPoints, QPainter )
00301 QPolygon arg0 = KJSEmbed::extractVariant<QPolygon>(exec,args, 0);
00302 object->drawPoints(arg0);
00303 END_OBJECT_METHOD
00304
00305 START_OBJECT_METHOD( calldrawPolygon, QPainter )
00306 QPolygon arg0 = KJSEmbed::extractVariant<QPolygon>(exec,args, 0);
00307 Qt::FillRule arg1 = (Qt::FillRule)KJSEmbed::extractInt(exec, args, 1, Qt::OddEvenFill );
00308 object->drawPolygon(arg0, arg1);
00309 END_OBJECT_METHOD
00310
00311 START_OBJECT_METHOD( calldrawPolyline, QPainter )
00312 QPolygon arg0 = KJSEmbed::extractVariant<QPolygon>(exec,args, 0);
00313 object->drawPolyline(arg0);
00314 END_OBJECT_METHOD
00315
00316 START_OBJECT_METHOD( calldrawRect, QPainter )
00317 if (args.size() == 1 )
00318 {
00319 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec,args, 0);
00320 object->drawRect(arg0);
00321 }
00322 else if ( args.size() == 4 )
00323 {
00324 int arg0 = KJSEmbed::extractInt(exec, args, 0);
00325 int arg1 = KJSEmbed::extractInt(exec, args, 1);
00326 int arg2 = KJSEmbed::extractInt(exec, args, 2);
00327 int arg3 = KJSEmbed::extractInt(exec, args, 3);
00328 object->drawRect(arg0, arg1, arg2, arg3);
00329 }
00330 END_OBJECT_METHOD
00331
00332 START_OBJECT_METHOD( calldrawRoundRect, QPainter )
00333 if ( args.size() == 2 )
00334 {
00335 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec,args, 0);
00336 int arg1 = KJSEmbed::extractInt(exec, args, 1);
00337 int arg2 = KJSEmbed::extractInt(exec, args, 2);
00338 object->drawRoundRect(arg0, arg1, arg2);
00339 }
00340 else if ( args.size() == 6 )
00341 {
00342 int arg0 = KJSEmbed::extractInt(exec, args, 0);
00343 int arg1 = KJSEmbed::extractInt(exec, args, 1);
00344 int arg2 = KJSEmbed::extractInt(exec, args, 2);
00345 int arg3 = KJSEmbed::extractInt(exec, args, 3);
00346 int arg4 = KJSEmbed::extractInt(exec, args, 4);
00347 int arg5 = KJSEmbed::extractInt(exec, args, 5);
00348 object->drawRoundRect(arg0, arg1, arg2, arg3, arg4, arg5);
00349 }
00350 END_OBJECT_METHOD
00351
00352 START_OBJECT_METHOD( calldrawText, QPainter )
00353 if( args.size() == 2 )
00354 {
00355 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec,args, 0);
00356 QString arg1 = KJSEmbed::extractQString(exec, args, 1);
00357 object->drawText(arg0, arg1);
00358 }
00359 else if ( args.size() == 3 )
00360 {
00361 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec,args, 0);
00362 int arg1 = KJSEmbed::extractInt(exec, args, 1);
00363 QString arg2 = KJSEmbed::extractQString(exec, args, 2);
00364 QRect* arg3 = 0;
00365 object->drawText(arg0, arg1, arg2, arg3);
00366 }
00367 else if ( args.size () == 6 )
00368 {
00369 int arg0 = KJSEmbed::extractInt(exec, args, 0);
00370 int arg1 = KJSEmbed::extractInt(exec, args, 1);
00371 int arg2 = KJSEmbed::extractInt(exec, args, 2);
00372 int arg3 = KJSEmbed::extractInt(exec, args, 3);
00373 int arg4 = KJSEmbed::extractInt(exec, args, 4);
00374 QString arg5 = KJSEmbed::extractQString(exec, args, 5);
00375 QRect* arg6 = 0;
00376 object->drawText(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
00377 }
00378 END_OBJECT_METHOD
00379
00380 START_OBJECT_METHOD( calltranslate, QPainter )
00381 if( args.size() == 2 )
00382 {
00383 int arg0 = KJSEmbed::extractInt(exec, args, 0);
00384 int arg1 = KJSEmbed::extractInt(exec, args, 1);
00385 object->translate(arg0,arg1);
00386 }
00387 else if( args.size() == 1 )
00388 {
00389 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec,args, 0);
00390 object->translate(arg0);
00391 }
00392 END_OBJECT_METHOD
00393
00394 START_OBJECT_METHOD( calldrawTiledPixmap, QPainter)
00395 if( args.size() == 3 )
00396 {
00397 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec,args, 0);
00398 QPixmap arg1 = KJSEmbed::extractVariant<QPixmap>(exec,args, 1);
00399 QPoint arg2 = KJSEmbed::extractVariant<QPoint>(exec,args, 2);
00400 object->drawTiledPixmap(arg0,arg1,arg2);
00401 }
00402 else if( args.size() == 7)
00403 {
00404 int arg0 = KJSEmbed::extractInt(exec, args, 0);
00405 int arg1 = KJSEmbed::extractInt(exec, args, 1);
00406 int arg2 = KJSEmbed::extractInt(exec, args, 2);
00407 int arg3 = KJSEmbed::extractInt(exec, args, 3);
00408 QPixmap arg4 = KJSEmbed::extractVariant<QPixmap>(exec,args, 4);
00409 int arg5 = KJSEmbed::extractInt(exec, args, 5);
00410 int arg6 = KJSEmbed::extractInt(exec, args, 6);
00411 object->drawTiledPixmap(arg0,arg1,arg2,arg3,arg4,arg5,arg6);
00412 }
00413 END_OBJECT_METHOD
00414
00415 START_OBJECT_METHOD( calleraseRect, QPainter)
00416 if( args.size() == 4)
00417 {
00418 int arg0 = KJSEmbed::extractInt(exec, args, 0);
00419 int arg1 = KJSEmbed::extractInt(exec, args, 1);
00420 int arg2 = KJSEmbed::extractInt(exec, args, 2);
00421 int arg3 = KJSEmbed::extractInt(exec, args, 3);
00422 object->eraseRect(arg0,arg1,arg2,arg3);
00423 }
00424 else if (args.size() == 1 )
00425 {
00426 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec,args, 0);
00427 object->eraseRect(arg0);
00428 }
00429 END_OBJECT_METHOD
00430
00431 START_METHOD_LUT( Painter )
00432 {"begin", 1, KJS::DontDelete|KJS::ReadOnly, &callPainterBegin },
00433 {"end", 0, KJS::DontDelete|KJS::ReadOnly, &callPainterEnd },
00434 {"background", 0, KJS::DontDelete|KJS::ReadOnly, &callbackground},
00435 {"backgroundMode", 0, KJS::DontDelete|KJS::ReadOnly, &callbackgroundMode},
00436 {"boundingRect", 6, KJS::DontDelete|KJS::ReadOnly, &callboundingRect},
00437 {"brush", 0, KJS::DontDelete|KJS::ReadOnly, &callbrush},
00438 {"brushOrigin", 0, KJS::DontDelete|KJS::ReadOnly, &callbrushOrigin},
00439 {"drawArc", 6, KJS::DontDelete|KJS::ReadOnly, &calldrawArc},
00440 {"drawChord", 6, KJS::DontDelete|KJS::ReadOnly, &calldrawChord},
00441 {"drawConvexPolygon", 1, KJS::DontDelete|KJS::ReadOnly, &calldrawConvexPolygon},
00442 {"drawEllipse", 3, KJS::DontDelete|KJS::ReadOnly, &calldrawEllipse},
00443 {"drawImage", 7, KJS::DontDelete|KJS::ReadOnly, &calldrawImage},
00444 {"drawLine", 3, KJS::DontDelete|KJS::ReadOnly, &calldrawLine},
00445
00446
00447
00448 {"drawPie", 6, KJS::DontDelete|KJS::ReadOnly, &calldrawPie},
00449 {"drawPixmap", 8, KJS::DontDelete|KJS::ReadOnly, &calldrawPixmap},
00450 {"drawPoint", 2, KJS::DontDelete|KJS::ReadOnly, &calldrawPoint},
00451 {"drawPoints", 1, KJS::DontDelete|KJS::ReadOnly, &calldrawPoints},
00452 {"drawPolygon", 2, KJS::DontDelete|KJS::ReadOnly, &calldrawPolygon},
00453 {"drawPolyline", 1, KJS::DontDelete|KJS::ReadOnly, &calldrawPolyline},
00454 {"drawRect", 4, KJS::DontDelete|KJS::ReadOnly, &calldrawRect},
00455
00456 {"drawRoundRect", 5, KJS::DontDelete|KJS::ReadOnly, &calldrawRoundRect},
00457 {"drawText", 7, KJS::DontDelete|KJS::ReadOnly, &calldrawText},
00458 {"drawTiledPixmap", 3, KJS::DontDelete|KJS::ReadOnly, &calldrawTiledPixmap},
00459 {"eraseRect", 1, KJS::DontDelete|KJS::ReadOnly, &calleraseRect},
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485 {"translate", 1, KJS::DontDelete|KJS::ReadOnly, &calltranslate}
00486 END_METHOD_LUT
00487
00488 NO_ENUMS( Painter )
00489 NO_STATICS( Painter )
00490
00491 START_CTOR( Painter, QPainter, 0 )
00492 KJS::JSObject *object;
00493
00494 if( args.size() == 1 )
00495 {
00496 QPaintDevice *device = extractPaintDevice(exec, args[0]);
00497 if ( device )
00498 {
00499 object = new KJSEmbed::ObjectBinding(exec, "Painter", new QPainter(device) );
00500 }
00501 else
00502 {
00503 KJS::throwError( exec, KJS::EvalError, QString("Cannot paint to object %1").arg(toQString(args[0]->toString(exec))));
00504 return 0L;
00505 }
00506 }
00507 else
00508 {
00509 object = new KJSEmbed::ObjectBinding(exec, "Painter", new QPainter() );
00510 }
00511
00512 StaticBinding::publish( exec, object, ObjectFactory::methods() );
00513 StaticBinding::publish( exec, object, Painter::methods() );
00514 return object;
00515 END_CTOR
00516
00517