File indexing completed on 2024-12-08 09:42:33

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 "brush.h"
0023 
0024 #include <QDebug>
0025 #include <QBrush>
0026 #include <QPixmap>
0027 #include <QColor>
0028 
0029 #include "pixmap.h"
0030 #include "color.h"
0031 #include "util.h"
0032 
0033 using namespace KJSEmbed;
0034 
0035 const KJS::ClassInfo BrushBinding::info = { "QBrush", &VariantBinding::info, nullptr, nullptr };
0036 BrushBinding::BrushBinding(KJS::ExecState *exec, const QBrush &value)
0037     : VariantBinding(exec, value)
0038 {
0039     StaticBinding::publish(exec, this, Brush::methods());
0040     StaticBinding::publish(exec, this, VariantFactory::methods());
0041 }
0042 
0043 namespace BrushNS
0044 {
0045 
0046 START_VARIANT_METHOD(callcolor, QBrush)
0047 QColor cppValue = value.color();
0048 result = KJSEmbed::createVariant(exec, "QColor", cppValue);
0049 END_VARIANT_METHOD
0050 
0051 START_VARIANT_METHOD(callgradient, QBrush)
0052 const QGradient *cppValue = value.gradient();
0053 result = KJSEmbed::createObject<QGradient>(exec, "QGradient", cppValue);
0054 END_VARIANT_METHOD
0055 
0056 START_VARIANT_METHOD(callisOpaque, QBrush)
0057 bool cppValue = value.isOpaque();
0058 result = KJS::jsBoolean(cppValue);
0059 END_VARIANT_METHOD
0060 
0061 START_VARIANT_METHOD(callsetColor, QBrush)
0062 QColor arg0 = KJSEmbed::extractVariant<QColor>(exec, args, 0);
0063 value.setColor(arg0);
0064 END_VARIANT_METHOD
0065 
0066 START_VARIANT_METHOD(callsetStyle, QBrush)
0067 Qt::BrushStyle arg0 = (Qt::BrushStyle)KJSEmbed::extractInt(exec, args, 0);
0068 value.setStyle(arg0);
0069 END_VARIANT_METHOD
0070 
0071 START_VARIANT_METHOD(callsetTexture, QBrush)
0072 QPixmap arg0 = KJSEmbed::extractVariant<QPixmap>(exec, args, 0);
0073 value.setTexture(arg0);
0074 END_VARIANT_METHOD
0075 
0076 START_VARIANT_METHOD(callstyle, QBrush)
0077 Qt::BrushStyle cppValue = value.style();
0078 result = KJS::jsNumber(cppValue);
0079 END_VARIANT_METHOD
0080 
0081 START_VARIANT_METHOD(calltexture, QBrush)
0082 QPixmap cppValue = value.texture();
0083 result = KJSEmbed::createVariant(exec, "QPixmap", cppValue);
0084 END_VARIANT_METHOD
0085 
0086 }
0087 
0088 START_METHOD_LUT(Brush)
0089 {"color", 0, KJS::DontDelete | KJS::ReadOnly, &BrushNS::callcolor},
0090 {"gradient", 0, KJS::DontDelete | KJS::ReadOnly, &BrushNS::callgradient},
0091 {"isOpaque", 0, KJS::DontDelete | KJS::ReadOnly, &BrushNS::callisOpaque},
0092 {"setColor", 1, KJS::DontDelete | KJS::ReadOnly, &BrushNS::callsetColor},
0093 {"setStyle", 1, KJS::DontDelete | KJS::ReadOnly, &BrushNS::callsetStyle},
0094 {"setTexture", 1, KJS::DontDelete | KJS::ReadOnly, &BrushNS::callsetTexture},
0095 {"style", 0, KJS::DontDelete | KJS::ReadOnly, &BrushNS::callstyle},
0096 {"texture", 0, KJS::DontDelete | KJS::ReadOnly, &BrushNS::calltexture}
0097 END_METHOD_LUT
0098 
0099 NO_ENUMS(Brush)
0100 NO_STATICS(Brush)
0101 
0102 START_CTOR(Brush, QBrush, 0)
0103 if (args.size() == 0)
0104 {
0105     return new KJSEmbed::BrushBinding(exec, QBrush());
0106 } else if (args.size() == 1)
0107 {
0108     KJS::JSValue *value0 = args[0];
0109     KJS::JSObject *obj0 = value0->toObject(exec);
0110     if (obj0) {
0111         if (obj0->inherits(&PixmapBinding::info)) {
0112             QPixmap arg0 = KJSEmbed::extractVariant<QPixmap>(exec, args, 0);
0113             return new KJSEmbed::BrushBinding(exec, QBrush(arg0));
0114         }
0115         if (obj0->inherits(&BrushBinding::info)) {
0116             QBrush arg0 = KJSEmbed::extractVariant<QBrush>(exec, args, 0);
0117             return new KJSEmbed::BrushBinding(exec, QBrush(arg0));
0118         }
0119 //             if(obj0->inherits(&GradientBinding::info))
0120 //             {
0121 //                 QGradient arg0 = KJSEmbed::extractVariant<QGradient>(exec, args, 0);
0122 //                 return new KJSEmbed::BrushBinding(exec, QBrush(arg0));
0123 //             }
0124     } else if (isBasic(value0)) {
0125         Qt::BrushStyle arg0 = (Qt::BrushStyle)KJSEmbed::extractInt(exec, args, 0);
0126         return new KJSEmbed::BrushBinding(exec, QBrush(arg0));
0127     }
0128 } else if (args.size() == 2)
0129 {
0130     KJS::JSValue *value0 = args[0];
0131     KJS::JSValue *value1 = args[1];
0132     KJS::JSObject *obj0 = value0->toObject(exec);
0133     KJS::JSObject *obj1 = value1->toObject(exec);
0134 
0135     if (obj0 && obj1 && obj0->inherits(&ColorBinding::info) && obj1->inherits(&PixmapBinding::info)) {
0136         QColor arg0 = KJSEmbed::extractVariant<QColor>(exec, args, 0);
0137         QPixmap arg1 = KJSEmbed::extractVariant<QPixmap>(exec, args, 1);
0138         return new KJSEmbed::BrushBinding(exec, QBrush(arg0, arg1));
0139     }
0140     if (obj1 && isBasic(value0) && obj1->inherits(&PixmapBinding::info)) {
0141         Qt::GlobalColor arg0 = (Qt::GlobalColor)KJSEmbed::extractInt(exec, args, 0);
0142         QPixmap arg1 = KJSEmbed::extractVariant<QPixmap>(exec, args, 1);
0143         return new KJSEmbed::BrushBinding(exec, QBrush(arg0, arg1));
0144     }
0145     if (obj0 && obj0->inherits(&ColorBinding::info) && isBasic(value1)) {
0146         QColor arg0 = KJSEmbed::extractVariant<QColor>(exec, args, 0);
0147         Qt::BrushStyle arg1 = (Qt::BrushStyle)KJSEmbed::extractInt(exec, args, 1);
0148         return new KJSEmbed::BrushBinding(exec, QBrush(arg0, arg1));
0149     }
0150     if (isBasic(value0) && isBasic(value1)) {
0151         Qt::GlobalColor arg0  = (Qt::GlobalColor)KJSEmbed::extractInt(exec, args, 0);
0152         Qt::BrushStyle arg1 = (Qt::BrushStyle)KJSEmbed::extractInt(exec, args, 1);
0153         return new KJSEmbed::BrushBinding(exec, QBrush(arg0, arg1));
0154     }
0155 }
0156 return new KJSEmbed::BrushBinding(exec, QBrush());
0157 
0158 END_CTOR