File indexing completed on 2024-11-10 09:42:21

0001 /* This file is part of the KDE libraries
0002     Copyright (C) 2005, 2006 Ian Reinhart Geiser <geiseri@kde.org>
0003     Copyright (C) 2005, 2006 Matt Broadstone <mbroadst@gmail.com>
0004     Copyright (C) 2005, 2006 Richard J. Moore <rich@kde.org>
0005     Copyright (C) 2005, 2006 Erik L. Bunce <kde@bunce.us>
0006 
0007     This library is free software; you can redistribute it and/or
0008     modify it under the terms of the GNU Library General Public
0009     License as published by the Free Software Foundation; either
0010     version 2 of the License, or (at your option) any later version.
0011 
0012     This library is distributed in the hope that it will be useful,
0013     but WITHOUT ANY WARRANTY; without even the implied warranty of
0014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015     Library General Public License for more details.
0016 
0017     You should have received a copy of the GNU Library General Public License
0018     along with this library; see the file COPYING.LIB.  If not, write to
0019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020     Boston, MA 02110-1301, USA.
0021 */
0022 #include "rect.h"
0023 
0024 #include <QDebug>
0025 #include <QRect>
0026 #include <QPoint>
0027 #include <QSize>
0028 
0029 using namespace KJSEmbed;
0030 
0031 RectBinding::RectBinding(KJS::ExecState *exec, const QRect &value)
0032     : VariantBinding(exec, value)
0033 {
0034     StaticBinding::publish(exec, this, Rect::methods());
0035     StaticBinding::publish(exec, this, VariantFactory::methods());
0036 }
0037 
0038 namespace RectNS
0039 {
0040 
0041 START_VARIANT_METHOD(calladjust, QRect)
0042 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0043 int arg1 = KJSEmbed::extractInt(exec, args, 1);
0044 int arg2 = KJSEmbed::extractInt(exec, args, 2);
0045 int arg3 = KJSEmbed::extractInt(exec, args, 3);
0046 value.adjust(arg0, arg1, arg2, arg3);
0047 END_VARIANT_METHOD
0048 
0049 START_VARIANT_METHOD(calladjusted, QRect)
0050 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0051 int arg1 = KJSEmbed::extractInt(exec, args, 1);
0052 int arg2 = KJSEmbed::extractInt(exec, args, 2);
0053 int arg3 = KJSEmbed::extractInt(exec, args, 3);
0054 QRect cppValue = value.adjusted(arg0, arg1, arg2, arg3);
0055 result = KJSEmbed::createVariant(exec, "QRect", cppValue);
0056 END_VARIANT_METHOD
0057 
0058 START_VARIANT_METHOD(callbottom, QRect)
0059 int cppValue = value.bottom();
0060 result = KJS::jsNumber(cppValue);
0061 END_VARIANT_METHOD
0062 
0063 START_VARIANT_METHOD(callbottomLeft, QRect)
0064 QPoint cppValue = value.bottomLeft();
0065 result = KJSEmbed::createVariant(exec, "QPoint", cppValue);
0066 END_VARIANT_METHOD
0067 
0068 START_VARIANT_METHOD(callbottomRight, QRect)
0069 QPoint cppValue = value.bottomRight();
0070 result = KJSEmbed::createVariant(exec, "QPoint", cppValue);
0071 END_VARIANT_METHOD
0072 
0073 START_VARIANT_METHOD(callcenter, QRect)
0074 QPoint cppValue = value.center();
0075 result = KJSEmbed::createVariant(exec, "QPoint", cppValue);
0076 END_VARIANT_METHOD
0077 
0078 START_VARIANT_METHOD(callcontains, QRect)
0079 // 1
0080 if (args.size() == 2 /* &&  !KJSEmbed::extractVariant<QPoint>(exec,args, 0).isNull() */)
0081 {
0082     QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
0083     bool arg1 = KJSEmbed::extractBool(exec, args, 1);
0084     bool cppValue = value.contains(arg0, arg1);
0085     result = KJS::jsBoolean(cppValue);
0086 }
0087 //2
0088 else if (args.size() == 3)
0089 {
0090     int arg0 = KJSEmbed::extractInt(exec, args, 0);
0091     int arg1 = KJSEmbed::extractInt(exec, args, 1);
0092     bool arg2 = KJSEmbed::extractBool(exec, args, 2);
0093     bool cppValue = value.contains(arg0, arg1, arg2);
0094     result = KJS::jsBoolean(cppValue);
0095 }
0096 // 3
0097 else
0098 {
0099     int arg0 = KJSEmbed::extractInt(exec, args, 0);
0100     int arg1 = KJSEmbed::extractInt(exec, args, 1);
0101     bool cppValue = value.contains(arg0, arg1);
0102     result = KJS::jsBoolean(cppValue);
0103 }
0104 END_VARIANT_METHOD
0105 
0106 START_VARIANT_METHOD(callheight, QRect)
0107 int cppValue = value.height();
0108 result = KJS::jsNumber(cppValue);
0109 END_VARIANT_METHOD
0110 
0111 START_VARIANT_METHOD(callintersect, QRect)
0112 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec, args, 0);
0113 QRect cppValue = value.intersected(arg0);
0114 result = KJSEmbed::createVariant(exec, "QRect", cppValue);
0115 END_VARIANT_METHOD
0116 
0117 START_VARIANT_METHOD(callintersects, QRect)
0118 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec, args, 0);
0119 bool cppValue = value.intersects(arg0);
0120 result = KJS::jsBoolean(cppValue);
0121 END_VARIANT_METHOD
0122 
0123 START_VARIANT_METHOD(callisEmpty, QRect)
0124 bool cppValue = value.isEmpty();
0125 result = KJS::jsBoolean(cppValue);
0126 END_VARIANT_METHOD
0127 
0128 START_VARIANT_METHOD(callisNull, QRect)
0129 bool cppValue = value.isNull();
0130 result = KJS::jsBoolean(cppValue);
0131 END_VARIANT_METHOD
0132 
0133 START_VARIANT_METHOD(callisValid, QRect)
0134 bool cppValue = value.isValid();
0135 result = KJS::jsBoolean(cppValue);
0136 END_VARIANT_METHOD
0137 
0138 START_VARIANT_METHOD(callleft, QRect)
0139 int cppValue = value.left();
0140 result = KJS::jsNumber(cppValue);
0141 END_VARIANT_METHOD
0142 
0143 START_VARIANT_METHOD(callmoveBottom, QRect)
0144 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0145 value.moveBottom(arg0);
0146 END_VARIANT_METHOD
0147 
0148 START_VARIANT_METHOD(callmoveBottomLeft, QRect)
0149 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
0150 value.moveBottomLeft(arg0);
0151 END_VARIANT_METHOD
0152 
0153 START_VARIANT_METHOD(callmoveBottomRight, QRect)
0154 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
0155 value.moveBottomRight(arg0);
0156 END_VARIANT_METHOD
0157 
0158 START_VARIANT_METHOD(callmoveCenter, QRect)
0159 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
0160 value.moveCenter(arg0);
0161 END_VARIANT_METHOD
0162 
0163 START_VARIANT_METHOD(callmoveLeft, QRect)
0164 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0165 value.moveLeft(arg0);
0166 END_VARIANT_METHOD
0167 
0168 START_VARIANT_METHOD(callmoveRight, QRect)
0169 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0170 value.moveRight(arg0);
0171 END_VARIANT_METHOD
0172 
0173 START_VARIANT_METHOD(callmoveTo, QRect)
0174 if (args.size() == 1)
0175 {
0176     QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
0177     value.moveTo(arg0);
0178 } else
0179 {
0180     int arg0 = KJSEmbed::extractInt(exec, args, 0);
0181     int arg1 = KJSEmbed::extractInt(exec, args, 1);
0182     value.moveTo(arg0, arg1);
0183 }
0184 END_VARIANT_METHOD
0185 
0186 START_VARIANT_METHOD(callmoveTop, QRect)
0187 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0188 value.moveTop(arg0);
0189 END_VARIANT_METHOD
0190 
0191 START_VARIANT_METHOD(callmoveTopLeft, QRect)
0192 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
0193 value.moveTopLeft(arg0);
0194 END_VARIANT_METHOD
0195 
0196 START_VARIANT_METHOD(callmoveTopRight, QRect)
0197 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
0198 value.moveTopRight(arg0);
0199 END_VARIANT_METHOD
0200 
0201 START_VARIANT_METHOD(callnormalized, QRect)
0202 QRect cppValue = value.normalized();
0203 result = KJSEmbed::createVariant(exec, "QRect", cppValue);
0204 END_VARIANT_METHOD
0205 
0206 START_VARIANT_METHOD(callright, QRect)
0207 int cppValue = value.right();
0208 result = KJS::jsNumber(cppValue);
0209 END_VARIANT_METHOD
0210 
0211 START_VARIANT_METHOD(callsetBottom, QRect)
0212 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0213 value.setBottom(arg0);
0214 END_VARIANT_METHOD
0215 
0216 START_VARIANT_METHOD(callsetBottomLeft, QRect)
0217 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
0218 value.setBottomLeft(arg0);
0219 END_VARIANT_METHOD
0220 
0221 START_VARIANT_METHOD(callsetBottomRight, QRect)
0222 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
0223 value.setBottomRight(arg0);
0224 END_VARIANT_METHOD
0225 
0226 START_VARIANT_METHOD(callsetCoords, QRect)
0227 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0228 int arg1 = KJSEmbed::extractInt(exec, args, 1);
0229 int arg2 = KJSEmbed::extractInt(exec, args, 2);
0230 int arg3 = KJSEmbed::extractInt(exec, args, 3);
0231 value.setCoords(arg0, arg1, arg2, arg3);
0232 END_VARIANT_METHOD
0233 
0234 START_VARIANT_METHOD(callsetHeight, QRect)
0235 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0236 value.setHeight(arg0);
0237 END_VARIANT_METHOD
0238 
0239 START_VARIANT_METHOD(callsetLeft, QRect)
0240 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0241 value.setLeft(arg0);
0242 END_VARIANT_METHOD
0243 
0244 START_VARIANT_METHOD(callsetRect, QRect)
0245 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0246 int arg1 = KJSEmbed::extractInt(exec, args, 1);
0247 int arg2 = KJSEmbed::extractInt(exec, args, 2);
0248 int arg3 = KJSEmbed::extractInt(exec, args, 3);
0249 value.setRect(arg0, arg1, arg2, arg3);
0250 END_VARIANT_METHOD
0251 
0252 START_VARIANT_METHOD(callsetRight, QRect)
0253 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0254 value.setRight(arg0);
0255 END_VARIANT_METHOD
0256 
0257 START_VARIANT_METHOD(callsetSize, QRect)
0258 QSize arg0 = KJSEmbed::extractVariant<QSize>(exec, args, 0);
0259 value.setSize(arg0);
0260 END_VARIANT_METHOD
0261 
0262 START_VARIANT_METHOD(callsetTop, QRect)
0263 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0264 value.setTop(arg0);
0265 END_VARIANT_METHOD
0266 
0267 START_VARIANT_METHOD(callsetTopLeft, QRect)
0268 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
0269 value.setTopLeft(arg0);
0270 END_VARIANT_METHOD
0271 
0272 START_VARIANT_METHOD(callsetTopRight, QRect)
0273 QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
0274 value.setTopRight(arg0);
0275 END_VARIANT_METHOD
0276 
0277 START_VARIANT_METHOD(callsetWidth, QRect)
0278 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0279 value.setWidth(arg0);
0280 END_VARIANT_METHOD
0281 
0282 START_VARIANT_METHOD(callsetX, QRect)
0283 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0284 value.setX(arg0);
0285 END_VARIANT_METHOD
0286 
0287 START_VARIANT_METHOD(callsetY, QRect)
0288 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0289 value.setY(arg0);
0290 END_VARIANT_METHOD
0291 
0292 START_VARIANT_METHOD(callsize, QRect)
0293 QSize cppValue = value.size();
0294 result = KJSEmbed::createVariant(exec, "QSize", cppValue);
0295 END_VARIANT_METHOD
0296 
0297 START_VARIANT_METHOD(calltop, QRect)
0298 int cppValue = value.top();
0299 result = KJS::jsNumber(cppValue);
0300 END_VARIANT_METHOD
0301 
0302 START_VARIANT_METHOD(calltopLeft, QRect)
0303 QPoint cppValue = value.topLeft();
0304 result = KJSEmbed::createVariant(exec, "QPoint", cppValue);
0305 END_VARIANT_METHOD
0306 
0307 START_VARIANT_METHOD(calltopRight, QRect)
0308 QPoint cppValue = value.topRight();
0309 result = KJSEmbed::createVariant(exec, "QPoint", cppValue);
0310 END_VARIANT_METHOD
0311 
0312 START_VARIANT_METHOD(calltranslate, QRect)
0313 if (args.size() == 1)
0314 {
0315     QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
0316     value.translate(arg0);
0317 } else
0318 {
0319     int arg0 = KJSEmbed::extractInt(exec, args, 0);
0320     int arg1 = KJSEmbed::extractInt(exec, args, 1);
0321     value.translate(arg0, arg1);
0322 }
0323 END_VARIANT_METHOD
0324 
0325 START_VARIANT_METHOD(calltranslated, QRect)
0326 if (args.size() == 1)
0327 {
0328     QPoint arg0 = KJSEmbed::extractVariant<QPoint>(exec, args, 0);
0329     QRect cppValue = value.translated(arg0);
0330     result = KJSEmbed::createVariant(exec, "QRect", cppValue);
0331 } else
0332 {
0333     int arg0 = KJSEmbed::extractInt(exec, args, 0);
0334     int arg1 = KJSEmbed::extractInt(exec, args, 1);
0335     QRect cppValue = value.translated(arg0, arg1);
0336     result = KJSEmbed::createVariant(exec, "QRect", cppValue);
0337 }
0338 END_VARIANT_METHOD
0339 
0340 START_VARIANT_METHOD(callunite, QRect)
0341 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec, args, 0);
0342 QRect cppValue = value.united(arg0);
0343 result = KJSEmbed::createVariant(exec, "QRect", cppValue);
0344 END_VARIANT_METHOD
0345 
0346 START_VARIANT_METHOD(callwidth, QRect)
0347 int cppValue = value.width();
0348 result = KJS::jsNumber(cppValue);
0349 END_VARIANT_METHOD
0350 
0351 START_VARIANT_METHOD(callx, QRect)
0352 int cppValue = value.x();
0353 result = KJS::jsNumber(cppValue);
0354 END_VARIANT_METHOD
0355 
0356 START_VARIANT_METHOD(cally, QRect)
0357 int cppValue = value.y();
0358 result = KJS::jsNumber(cppValue);
0359 END_VARIANT_METHOD
0360 }
0361 
0362 START_METHOD_LUT(Rect)
0363 {"adjust", 3, KJS::DontDelete | KJS::ReadOnly, &RectNS::calladjust},
0364 {"adjusted", 3, KJS::DontDelete | KJS::ReadOnly, &RectNS::calladjusted},
0365 {"bottom", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callbottom},
0366 {"bottomLeft", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callbottomLeft},
0367 {"bottomRight", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callbottomRight},
0368 {"center", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callcenter},
0369 {"contains", 2, KJS::DontDelete | KJS::ReadOnly, &RectNS::callcontains},
0370 {"height", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callheight},
0371 {"intersect", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callintersect},
0372 {"intersects", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callintersects},
0373 {"isEmpty", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callisEmpty},
0374 {"isNull", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callisNull},
0375 {"isValid", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callisValid},
0376 {"left", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callleft},
0377 {"moveBottom", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callmoveBottom},
0378 {"moveBottomLeft", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callmoveBottomLeft},
0379 {"moveBottomRight", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callmoveBottomRight},
0380 {"moveCenter", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callmoveCenter},
0381 {"moveLeft", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callmoveLeft},
0382 {"moveRight", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callmoveRight},
0383 {"moveTo", 1, KJS::DontDelete | KJS::ReadOnly, &RectNS::callmoveTo},
0384 {"moveTop", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callmoveTop},
0385 {"moveTopLeft", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callmoveTopLeft},
0386 {"moveTopRight", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callmoveTopRight},
0387 {"normalized", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callnormalized},
0388 {"right", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callright},
0389 {"setBottom", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callsetBottom},
0390 {"setBottomLeft", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callsetBottomLeft},
0391 {"setBottomRight", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callsetBottomRight},
0392 {"setCoords", 3, KJS::DontDelete | KJS::ReadOnly, &RectNS::callsetCoords},
0393 {"setHeight", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callsetHeight},
0394 {"setLeft", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callsetLeft},
0395 {"setRect", 3, KJS::DontDelete | KJS::ReadOnly, &RectNS::callsetRect},
0396 {"setRight", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callsetRight},
0397 {"setSize", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callsetSize},
0398 {"setTop", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callsetTop},
0399 {"setTopLeft", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callsetTopLeft},
0400 {"setTopRight", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callsetTopRight},
0401 {"setWidth", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callsetWidth},
0402 {"setX", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callsetX},
0403 {"setY", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callsetY},
0404 {"size", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callsize},
0405 {"top", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::calltop},
0406 {"topLeft", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::calltopLeft},
0407 {"topRight", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::calltopRight},
0408 {"translate", 1, KJS::DontDelete | KJS::ReadOnly, &RectNS::calltranslate},
0409 {"translated", 1, KJS::DontDelete | KJS::ReadOnly, &RectNS::calltranslated},
0410 {"unite", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callunite},
0411 {"width", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callwidth},
0412 {"x", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::callx},
0413 {"y", 0, KJS::DontDelete | KJS::ReadOnly, &RectNS::cally}
0414 END_METHOD_LUT
0415 
0416 NO_ENUMS(Rect)
0417 NO_STATICS(Rect)
0418 
0419 START_CTOR(Rect, QRect, 0)
0420 if (args.size() == 2)
0421 {
0422     /*
0423                     return KJSEmbed::RectBinding( exec,
0424                             QRect( KJSEmbed::extractQString(exec,args,0 ) ) );
0425     */
0426 } else if (args.size() == 4)
0427 {
0428     return new KJSEmbed::RectBinding(exec,
0429                                      QRect(KJSEmbed::extractInt(exec, args, 0),
0430                                            KJSEmbed::extractInt(exec, args, 1),
0431                                            KJSEmbed::extractInt(exec, args, 2),
0432                                            KJSEmbed::extractInt(exec, args, 3)
0433                                           ));
0434 }
0435 
0436 return new KJSEmbed::RectBinding(exec, QRect());
0437 END_CTOR
0438