File indexing completed on 2024-10-13 12:16:31

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 "point.h"
0023 
0024 #include <QDebug>
0025 #include <QPoint>
0026 
0027 using namespace KJSEmbed;
0028 
0029 const KJS::ClassInfo PointBinding::info = { "QPoint", &VariantBinding::info, nullptr, nullptr };
0030 PointBinding::PointBinding(KJS::ExecState *exec, const QPoint &value)
0031     : VariantBinding(exec, value)
0032 {
0033     StaticBinding::publish(exec, this, Point::methods());
0034     StaticBinding::publish(exec, this, VariantFactory::methods());
0035 }
0036 
0037 namespace PointNS
0038 {
0039 
0040 START_VARIANT_METHOD(callisNull, QPoint)
0041 bool cppValue = value.isNull();
0042 result = KJS::jsBoolean(cppValue);
0043 END_VARIANT_METHOD
0044 
0045 START_VARIANT_METHOD(callmanhattanLength, QPoint)
0046 int cppValue = value.manhattanLength();
0047 result = KJS::jsNumber(cppValue);
0048 END_VARIANT_METHOD
0049 
0050 START_VARIANT_METHOD(callrx, QPoint)
0051 int cppValue = value.rx();
0052 result = KJS::jsNumber(cppValue);
0053 END_VARIANT_METHOD
0054 
0055 START_VARIANT_METHOD(callry, QPoint)
0056 int cppValue = value.ry();
0057 result = KJS::jsNumber(cppValue);
0058 END_VARIANT_METHOD
0059 
0060 START_VARIANT_METHOD(callsetX, QPoint)
0061 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0062 value.setX(arg0);
0063 END_VARIANT_METHOD
0064 
0065 START_VARIANT_METHOD(callsetY, QPoint)
0066 int arg0 = KJSEmbed::extractInt(exec, args, 0);
0067 value.setY(arg0);
0068 END_VARIANT_METHOD
0069 
0070 START_VARIANT_METHOD(callx, QPoint)
0071 int cppValue = value.x();
0072 result = KJS::jsNumber(cppValue);
0073 END_VARIANT_METHOD
0074 
0075 START_VARIANT_METHOD(cally, QPoint)
0076 int cppValue = value.y();
0077 result = KJS::jsNumber(cppValue);
0078 END_VARIANT_METHOD
0079 
0080 }
0081 
0082 START_METHOD_LUT(Point)
0083 {"isNull", 0, KJS::DontDelete | KJS::ReadOnly, &PointNS::callisNull},
0084 {"manhattanLength", 0, KJS::DontDelete | KJS::ReadOnly, &PointNS::callmanhattanLength},
0085 {"rx", 0, KJS::DontDelete | KJS::ReadOnly, &PointNS::callrx},
0086 {"ry", 0, KJS::DontDelete | KJS::ReadOnly, &PointNS::callry},
0087 {"setX", 0, KJS::DontDelete | KJS::ReadOnly, &PointNS::callsetX},
0088 {"setY", 0, KJS::DontDelete | KJS::ReadOnly, &PointNS::callsetY},
0089 {"x", 0, KJS::DontDelete | KJS::ReadOnly, &PointNS::callx},
0090 {"y", 0, KJS::DontDelete | KJS::ReadOnly, &PointNS::cally}
0091 END_METHOD_LUT
0092 
0093 NO_ENUMS(Point)
0094 NO_STATICS(Point)
0095 
0096 START_CTOR(Point, QPoint, 0)
0097 if (args.size() == 2)
0098 {
0099     return new KJSEmbed::PointBinding(exec,
0100                                       QPoint(KJSEmbed::extractInt(exec, args, 0),
0101                                               KJSEmbed::extractInt(exec, args, 1)
0102                                             ));
0103 }
0104 
0105 return new KJSEmbed::PointBinding(exec, QPoint());
0106 END_CTOR
0107