File indexing completed on 2024-12-01 12:37:38
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 "pixmap.h" 0023 0024 #include <QDebug> 0025 #include <QPixmap> 0026 #include <QBitmap> 0027 #include <QWidget> 0028 0029 #include <variant_binding.h> 0030 #include <object_binding.h> 0031 0032 using namespace KJSEmbed; 0033 0034 const KJS::ClassInfo PixmapBinding::info = { "QPixmap", &VariantBinding::info, nullptr, nullptr }; 0035 PixmapBinding::PixmapBinding(KJS::ExecState *exec, const QPixmap &value) 0036 : VariantBinding(exec, value) 0037 { 0038 StaticBinding::publish(exec, this, Pixmap::methods()); 0039 StaticBinding::publish(exec, this, VariantFactory::methods()); 0040 } 0041 0042 namespace PixmapNS 0043 { 0044 START_VARIANT_METHOD(callalphaChannel, QPixmap) 0045 QPixmap cppValue = value.alphaChannel(); 0046 result = KJSEmbed::createVariant(exec, "QPixmap", cppValue); 0047 END_VARIANT_METHOD 0048 0049 START_VARIANT_METHOD(callcopy, QPixmap) 0050 if (args.size() == 1) 0051 { 0052 QRect arg0 = KJSEmbed::extractVariant<QRect>(exec, args, 0); 0053 QPixmap cppValue = value.copy(arg0); 0054 result = KJSEmbed::createVariant(exec, "QPixmap", cppValue); 0055 } else if (args.size() == 4) 0056 { 0057 int arg0 = KJSEmbed::extractInt(exec, args, 0); 0058 int arg1 = KJSEmbed::extractInt(exec, args, 1); 0059 int arg2 = KJSEmbed::extractInt(exec, args, 2); 0060 int arg3 = KJSEmbed::extractInt(exec, args, 3); 0061 QPixmap cppValue = value.copy(arg0, arg1, arg2, arg3); 0062 result = KJSEmbed::createVariant(exec, "QPixmap", cppValue); 0063 } 0064 END_VARIANT_METHOD 0065 0066 START_VARIANT_METHOD(callcreateHeuristicMask, QPixmap) 0067 bool arg0 = KJSEmbed::extractBool(exec, args, 0); 0068 QBitmap cppValue = value.createHeuristicMask(arg0); 0069 result = KJSEmbed::createVariant(exec, "QBitmap", cppValue); 0070 END_VARIANT_METHOD 0071 0072 START_VARIANT_METHOD(callcreateMaskFromColor, QPixmap) 0073 QColor arg0 = KJSEmbed::extractVariant<QColor>(exec, args, 0); 0074 QBitmap cppValue = value.createMaskFromColor(arg0); 0075 result = KJSEmbed::createVariant(exec, "QBitmap", cppValue); 0076 END_VARIANT_METHOD 0077 0078 START_VARIANT_METHOD(calldefaultDepth, QPixmap) 0079 int cppValue = value.defaultDepth(); 0080 result = KJS::jsNumber(cppValue); 0081 END_VARIANT_METHOD 0082 0083 START_VARIANT_METHOD(calldepth, QPixmap) 0084 int cppValue = value.depth(); 0085 result = KJS::jsNumber(cppValue); 0086 END_VARIANT_METHOD 0087 0088 START_VARIANT_METHOD(callfill, QPixmap) 0089 if (args.size() == 3) 0090 { 0091 QWidget *arg0 = KJSEmbed::extractObject<QWidget>(exec, args, 0); 0092 int arg1 = KJSEmbed::extractInt(exec, args, 1); 0093 int arg2 = KJSEmbed::extractInt(exec, args, 2); 0094 value.fill(arg0, arg1, arg2); 0095 } else if (args.size() == 1) 0096 { 0097 QColor arg0 = KJSEmbed::extractVariant<QColor>(exec, args, 0); 0098 value.fill(arg0); 0099 } else if (args.size() == 2) 0100 { 0101 QWidget *arg0 = KJSEmbed::extractObject<QWidget>(exec, args, 0); 0102 QPoint arg1 = KJSEmbed::extractVariant<QPoint>(exec, args, 1); 0103 value.fill(arg0, arg1); 0104 } 0105 END_VARIANT_METHOD 0106 0107 START_VARIANT_METHOD(callfromImage, QPixmap) 0108 QImage arg0 = KJSEmbed::extractVariant<QImage>(exec, args, 0); 0109 Qt::ImageConversionFlags arg1 = (Qt::ImageConversionFlags)KJSEmbed::extractInt(exec, args, 1); 0110 QPixmap cppValue = QPixmap::fromImage(arg0, arg1); 0111 result = KJSEmbed::createVariant(exec, "QPixmap", cppValue); 0112 END_VARIANT_METHOD 0113 0114 START_VARIANT_METHOD(callgrabWidget, QPixmap) 0115 if (args.size() == 2) 0116 { 0117 QWidget *arg0 = KJSEmbed::extractObject<QWidget>(exec, args, 0); 0118 QRect arg1 = KJSEmbed::extractVariant<QRect>(exec, args, 1); 0119 QPixmap cppValue = value.grabWidget(arg0, arg1); 0120 result = KJSEmbed::createVariant(exec, "QPixmap", cppValue); 0121 } else if (args.size() == 5) 0122 { 0123 QWidget *arg0 = KJSEmbed::extractObject<QWidget>(exec, args, 0); 0124 int arg1 = KJSEmbed::extractInt(exec, args, 1); 0125 int arg2 = KJSEmbed::extractInt(exec, args, 2); 0126 int arg3 = KJSEmbed::extractInt(exec, args, 3); 0127 int arg4 = KJSEmbed::extractInt(exec, args, 4); 0128 QPixmap cppValue = value.grabWidget(arg0, arg1, arg2, arg3, arg4); 0129 result = KJSEmbed::createVariant(exec, "QPixmap", cppValue); 0130 } 0131 END_VARIANT_METHOD 0132 0133 START_VARIANT_METHOD(callhasAlpha, QPixmap) 0134 bool cppValue = value.hasAlpha(); 0135 result = KJS::jsBoolean(cppValue); 0136 END_VARIANT_METHOD 0137 0138 START_VARIANT_METHOD(callhasAlphaChannel, QPixmap) 0139 bool cppValue = value.hasAlphaChannel(); 0140 result = KJS::jsBoolean(cppValue); 0141 END_VARIANT_METHOD 0142 0143 START_VARIANT_METHOD(callheight, QPixmap) 0144 int cppValue = value.height(); 0145 result = KJS::jsNumber(cppValue); 0146 END_VARIANT_METHOD 0147 0148 START_VARIANT_METHOD(callisNull, QPixmap) 0149 bool cppValue = value.isNull(); 0150 result = KJS::jsBoolean(cppValue); 0151 END_VARIANT_METHOD 0152 0153 START_VARIANT_METHOD(callisQBitmap, QPixmap) 0154 bool cppValue = value.isQBitmap(); 0155 result = KJS::jsBoolean(cppValue); 0156 END_VARIANT_METHOD 0157 0158 START_VARIANT_METHOD(callload, QPixmap) 0159 QString arg0 = KJSEmbed::extractQString(exec, args, 0); 0160 QByteArray arg1 = KJSEmbed::extractQString(exec, args, 1).toLatin1(); 0161 Qt::ImageConversionFlags arg2 = (Qt::ImageConversionFlags) KJSEmbed::extractInt(exec, args, 2); 0162 bool cppValue = value.load(arg0, arg1, arg2); 0163 result = KJS::jsBoolean(cppValue); 0164 END_VARIANT_METHOD 0165 0166 START_VARIANT_METHOD(callmask, QPixmap) 0167 QBitmap cppValue = value.mask(); 0168 result = KJSEmbed::createVariant(exec, "QBitmap", cppValue); 0169 END_VARIANT_METHOD 0170 0171 START_VARIANT_METHOD(callrect, QPixmap) 0172 QRect cppValue = value.rect(); 0173 result = KJSEmbed::createVariant(exec, "QRect", cppValue); 0174 END_VARIANT_METHOD 0175 0176 START_VARIANT_METHOD(callsave, QPixmap) 0177 QString arg0 = KJSEmbed::extractQString(exec, args, 0); 0178 QByteArray arg1 = KJSEmbed::extractQString(exec, args, 1).toLatin1(); 0179 int arg2 = KJSEmbed::extractInt(exec, args, 2, -1); 0180 bool cppValue = value.save(arg0, arg1, arg2); 0181 result = KJS::jsBoolean(cppValue); 0182 END_VARIANT_METHOD 0183 0184 START_VARIANT_METHOD(callscaled, QPixmap) 0185 if (args.size() == 3) 0186 { 0187 QSize arg0 = KJSEmbed::extractVariant<QSize>(exec, args, 0); 0188 Qt::AspectRatioMode arg1 = (Qt::AspectRatioMode) KJSEmbed::extractInt(exec, args, 1); 0189 Qt::TransformationMode arg2 = (Qt::TransformationMode) KJSEmbed::extractInt(exec, args, 3); 0190 QPixmap cppValue = value.scaled(arg0, arg1, arg2); 0191 result = KJSEmbed::createVariant(exec, "QPixmap", cppValue); 0192 } else if (args.size() == 4) 0193 { 0194 int arg0 = KJSEmbed::extractInt(exec, args, 0); 0195 int arg1 = KJSEmbed::extractInt(exec, args, 1); 0196 Qt::AspectRatioMode arg2 = (Qt::AspectRatioMode) KJSEmbed::extractInt(exec, args, 2); 0197 Qt::TransformationMode arg3 = (Qt::TransformationMode) KJSEmbed::extractInt(exec, args, 3); 0198 QPixmap cppValue = value.scaled(arg0, arg1, arg2, arg3); 0199 result = KJSEmbed::createVariant(exec, "QPixmap", cppValue); 0200 } 0201 END_VARIANT_METHOD 0202 0203 START_VARIANT_METHOD(callscaledToHeight, QPixmap) 0204 int arg0 = KJSEmbed::extractInt(exec, args, 0); 0205 Qt::TransformationMode arg1 = (Qt::TransformationMode) KJSEmbed::extractInt(exec, args, 1); 0206 QPixmap cppValue = value.scaledToHeight(arg0, arg1); 0207 result = KJSEmbed::createVariant(exec, "QPixmap", cppValue); 0208 END_VARIANT_METHOD 0209 0210 START_VARIANT_METHOD(callscaledToWidth, QPixmap) 0211 int arg0 = KJSEmbed::extractInt(exec, args, 0); 0212 Qt::TransformationMode arg1 = (Qt::TransformationMode) KJSEmbed::extractInt(exec, args, 1); 0213 QPixmap cppValue = value.scaledToWidth(arg0, arg1); 0214 result = KJSEmbed::createVariant(exec, "QPixmap", cppValue); 0215 END_VARIANT_METHOD 0216 0217 START_VARIANT_METHOD(callserialNumber, QPixmap) 0218 int cppValue = value.serialNumber(); 0219 result = KJS::jsNumber(cppValue); 0220 END_VARIANT_METHOD 0221 0222 START_VARIANT_METHOD(callsetAlphaChannel, QPixmap) 0223 QPixmap arg0 = KJSEmbed::extractVariant<QPixmap>(exec, args, 0); 0224 value.setAlphaChannel(arg0); 0225 END_VARIANT_METHOD 0226 0227 START_VARIANT_METHOD(callsetMask, QPixmap) 0228 QBitmap arg0 = KJSEmbed::extractVariant<QBitmap>(exec, args, 0); 0229 value.setMask(arg0); 0230 END_VARIANT_METHOD 0231 0232 START_VARIANT_METHOD(callsize, QPixmap) 0233 QSize cppValue = value.size(); 0234 result = KJSEmbed::createVariant(exec, "QSize", cppValue); 0235 END_VARIANT_METHOD 0236 0237 START_VARIANT_METHOD(calltoImage, QPixmap) 0238 QImage cppValue = value.toImage(); 0239 result = KJSEmbed::createVariant(exec, "QImage", cppValue); 0240 END_VARIANT_METHOD 0241 0242 START_VARIANT_METHOD(callwidth, QPixmap) 0243 int cppValue = value.width(); 0244 result = KJS::jsNumber(cppValue); 0245 END_VARIANT_METHOD 0246 0247 } 0248 0249 START_METHOD_LUT(Pixmap) 0250 {"alphaChannel", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callalphaChannel}, 0251 {"copy", 3, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callcopy}, 0252 {"createHeuristicMask", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callcreateHeuristicMask}, 0253 {"createMaskFromColor", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callcreateMaskFromColor}, 0254 {"defaultDepth", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::calldefaultDepth}, 0255 {"depth", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::calldepth}, 0256 {"fill", 2, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callfill}, 0257 {"fromImage", 1, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callfromImage}, 0258 {"grabWidget", 4, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callgrabWidget}, 0259 {"hasAlpha", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callhasAlpha}, 0260 {"hasAlphaChannel", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callhasAlphaChannel}, 0261 {"height", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callheight}, 0262 {"isNull", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callisNull}, 0263 {"isQBitmap", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callisQBitmap}, 0264 {"load", 2, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callload}, 0265 {"mask", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callmask}, 0266 {"rect", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callrect}, 0267 {"save", 2, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callsave}, 0268 {"scaled", 3, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callscaled}, 0269 {"scaledToHeight", 1, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callscaledToHeight}, 0270 {"scaledToWidth", 1, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callscaledToWidth}, 0271 {"serialNumber", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callserialNumber}, 0272 {"setAlphaChannel", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callsetAlphaChannel}, 0273 {"setMask", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callsetMask}, 0274 {"size", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callsize}, 0275 {"toImage", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::calltoImage}, 0276 {"width", 0, KJS::DontDelete | KJS::ReadOnly, &PixmapNS::callwidth} 0277 END_METHOD_LUT 0278 0279 NO_STATICS(Pixmap) 0280 NO_ENUMS(Pixmap) 0281 START_CTOR(Pixmap, QPixmap, 0) 0282 if (args.size() == 0) 0283 { 0284 return new KJSEmbed::PixmapBinding(exec, QPixmap()); 0285 } else if (args.size() == 1) 0286 { 0287 return new KJSEmbed::PixmapBinding(exec, 0288 QPixmap(KJSEmbed::extractQString(exec, args, 0))); 0289 } else if (args.size() == 2) 0290 { 0291 return new KJSEmbed::PixmapBinding(exec, 0292 QPixmap(KJSEmbed::extractInt(exec, args, 0), 0293 KJSEmbed::extractInt(exec, args, 1) 0294 )); 0295 } else if (args.size() == 3) 0296 { 0297 QString tmp = toQString(args[2]->toObject(exec)->className()); 0298 qDebug() << tmp; 0299 0300 return new KJSEmbed::PixmapBinding(exec, 0301 QPixmap(KJSEmbed::extractQString(exec, args, 0), 0302 KJSEmbed::extractVariant<QByteArray>(exec, args, 1).constData(), 0303 (Qt::ImageConversionFlags)KJSEmbed::extractInt(exec, args, 2) 0304 )); 0305 } 0306 return new KJSEmbed::PixmapBinding(exec, QPixmap()); 0307 END_CTOR 0308