File indexing completed on 2024-04-28 15:28:45

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 "pen.h"
0023 
0024 #include <QDebug>
0025 #include <QPen>
0026 #include <QBrush>
0027 #include <QColor>
0028 
0029 using namespace KJSEmbed;
0030 
0031 const KJS::ClassInfo PenBinding::info = { "QPen", &VariantBinding::info, nullptr, nullptr };
0032 PenBinding::PenBinding(KJS::ExecState *exec, const QPen &value)
0033     : VariantBinding(exec, value)
0034 {
0035     StaticBinding::publish(exec, this, Pen::methods());
0036     StaticBinding::publish(exec, this, VariantFactory::methods());
0037 }
0038 
0039 namespace PenNS
0040 {
0041 
0042 START_VARIANT_METHOD(callbrush, QPen)
0043 QBrush cppValue = value.brush();
0044 result = KJSEmbed::createVariant(exec, "QBrush", cppValue);
0045 END_VARIANT_METHOD
0046 
0047 START_VARIANT_METHOD(callcapStyle, QPen)
0048 Qt::PenCapStyle cppValue = value.capStyle();
0049 result = KJS::jsNumber(cppValue);
0050 END_VARIANT_METHOD
0051 
0052 START_VARIANT_METHOD(callcolor, QPen)
0053 QColor cppValue = value.color();
0054 result = KJSEmbed::createVariant(exec, "QColor", cppValue);
0055 END_VARIANT_METHOD
0056 
0057 START_VARIANT_METHOD(callisSolid, QPen)
0058 bool cppValue = value.isSolid();
0059 result = KJS::jsBoolean(cppValue);
0060 END_VARIANT_METHOD
0061 
0062 START_VARIANT_METHOD(calljoinStyle, QPen)
0063 Qt::PenJoinStyle cppValue = value.joinStyle();
0064 result = KJS::jsNumber(cppValue);
0065 END_VARIANT_METHOD
0066 
0067 START_VARIANT_METHOD(callsetBrush, QPen)
0068 QBrush arg0 = KJSEmbed::extractVariant<QBrush>(exec, args, 0);
0069 value.setBrush(arg0);
0070 END_VARIANT_METHOD
0071 
0072 START_VARIANT_METHOD(callsetCapStyle, QPen)
0073 Qt::PenCapStyle arg0 = (Qt::PenCapStyle)KJSEmbed::extractInt(exec, args, 0);
0074 value.setCapStyle(arg0);
0075 END_VARIANT_METHOD
0076 
0077 START_VARIANT_METHOD(callsetColor, QPen)
0078 QColor arg0 = KJSEmbed::extractVariant<QColor>(exec, args, 0);
0079 value.setColor(arg0);
0080 END_VARIANT_METHOD
0081 
0082 START_VARIANT_METHOD(callsetJoinStyle, QPen)
0083 Qt::PenJoinStyle arg0  = (Qt::PenJoinStyle)KJSEmbed::extractInt(exec, args, 0);
0084 value.setJoinStyle(arg0);
0085 END_VARIANT_METHOD
0086 
0087 START_VARIANT_METHOD(callsetStyle, QPen)
0088 Qt::PenStyle arg0  = (Qt::PenStyle)KJSEmbed::extractInt(exec, args, 0);
0089 value.setStyle(arg0);
0090 END_VARIANT_METHOD
0091 
0092 START_VARIANT_METHOD(callsetWidth, QPen)
0093 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0094 value.setWidth(arg0);
0095 END_VARIANT_METHOD
0096 
0097 START_VARIANT_METHOD(callstyle, QPen)
0098 Qt::PenStyle cppValue = value.style();
0099 result = KJS::jsNumber(cppValue);
0100 END_VARIANT_METHOD
0101 
0102 START_VARIANT_METHOD(callwidth, QPen)
0103 int cppValue = value.width();
0104 result = KJS::jsNumber(cppValue);
0105 END_VARIANT_METHOD
0106 
0107 }
0108 
0109 START_METHOD_LUT(Pen)
0110 {"brush", 0, KJS::DontDelete | KJS::ReadOnly, &PenNS::callbrush},
0111 {"capStyle", 0, KJS::DontDelete | KJS::ReadOnly, &PenNS::callcapStyle},
0112 {"color", 0, KJS::DontDelete | KJS::ReadOnly, &PenNS::callcolor},
0113 {"isSolid", 0, KJS::DontDelete | KJS::ReadOnly, &PenNS::callisSolid},
0114 {"joinStyle", 0, KJS::DontDelete | KJS::ReadOnly, &PenNS::calljoinStyle},
0115 {"setBrush", 1, KJS::DontDelete | KJS::ReadOnly, &PenNS::callsetBrush},
0116 {"setCapStyle", 1, KJS::DontDelete | KJS::ReadOnly, &PenNS::callsetCapStyle},
0117 {"setColor", 1, KJS::DontDelete | KJS::ReadOnly, &PenNS::callsetColor},
0118 {"setJoinStyle", 1, KJS::DontDelete | KJS::ReadOnly, &PenNS::callsetJoinStyle},
0119 {"setStyle", 1, KJS::DontDelete | KJS::ReadOnly, &PenNS::callsetStyle},
0120 {"setWidth", 1, KJS::DontDelete | KJS::ReadOnly, &PenNS::callsetWidth},
0121 {"style", 0, KJS::DontDelete | KJS::ReadOnly, &PenNS::callstyle},
0122 {"width", 0, KJS::DontDelete | KJS::ReadOnly, &PenNS::callwidth}
0123 END_METHOD_LUT
0124 
0125 NO_ENUMS(Pen)
0126 NO_STATICS(Pen)
0127 
0128 START_CTOR(Pen, QPen, 0)
0129 if (args.size() == 1)
0130 {
0131     return new KJSEmbed::PenBinding(exec,
0132                                     QPen(KJSEmbed::extractVariant<QColor>(exec, args, 0)
0133                                         ));
0134 } else if (args.size() >= 2)
0135 {
0136     return new KJSEmbed::PenBinding(exec,
0137                                     QPen(KJSEmbed::extractVariant<QBrush>(exec, args, 0),
0138                                          KJSEmbed::extractInt(exec, args, 1),
0139                                          (Qt::PenStyle)KJSEmbed::extractInt(exec, args, 2, Qt::SolidLine),
0140                                          (Qt::PenCapStyle)KJSEmbed::extractInt(exec, args, 3, Qt::SquareCap),
0141                                          (Qt::PenJoinStyle)KJSEmbed::extractInt(exec, args, 4, Qt::BevelJoin)
0142                                         ));
0143 
0144 }
0145 
0146 return new KJSEmbed::PenBinding(exec, QPen());
0147 END_CTOR
0148