2009-11-18 23:54:36 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2007 Richard J. Moore <rich@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QtScript/QScriptValue>
|
|
|
|
#include <QtScript/QScriptEngine>
|
|
|
|
#include <QtScript/QScriptContext>
|
|
|
|
#include <QtCore/QPoint>
|
2010-08-06 04:01:40 +02:00
|
|
|
#include "backportglobal.h"
|
2009-11-18 23:54:36 +01:00
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(QPoint*)
|
|
|
|
Q_DECLARE_METATYPE(QPoint)
|
|
|
|
|
|
|
|
static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)
|
|
|
|
{
|
|
|
|
if (ctx->argumentCount() == 2)
|
|
|
|
{
|
|
|
|
int x = ctx->argument(0).toInt32();
|
|
|
|
int y = ctx->argument(1).toInt32();
|
|
|
|
return qScriptValueFromValue(eng, QPoint(x, y));
|
|
|
|
}
|
|
|
|
|
|
|
|
return qScriptValueFromValue(eng, QPoint());
|
|
|
|
}
|
|
|
|
|
2010-01-27 22:06:03 +01:00
|
|
|
static QScriptValue null(QScriptContext *ctx, QScriptEngine *eng)
|
2009-11-18 23:54:36 +01:00
|
|
|
{
|
2010-01-27 22:06:03 +01:00
|
|
|
DECLARE_SELF(QPoint, null);
|
2009-11-18 23:54:36 +01:00
|
|
|
return QScriptValue(eng, self->isNull());
|
|
|
|
}
|
|
|
|
|
|
|
|
static QScriptValue manhattanLength(QScriptContext *ctx, QScriptEngine *eng)
|
|
|
|
{
|
|
|
|
DECLARE_SELF(QPoint, manhattanLength);
|
|
|
|
return QScriptValue(eng, self->manhattanLength());
|
|
|
|
}
|
|
|
|
|
|
|
|
static QScriptValue x(QScriptContext *ctx, QScriptEngine *eng)
|
|
|
|
{
|
|
|
|
DECLARE_SELF(QPoint, x);
|
2009-11-27 03:49:38 +01:00
|
|
|
|
|
|
|
if (ctx->argumentCount() > 0) {
|
|
|
|
int x = ctx->argument(0).toInt32();
|
|
|
|
self->setX(x);
|
|
|
|
}
|
|
|
|
|
2009-11-18 23:54:36 +01:00
|
|
|
return QScriptValue(eng, self->x());
|
|
|
|
}
|
|
|
|
|
|
|
|
static QScriptValue y(QScriptContext *ctx, QScriptEngine *eng)
|
|
|
|
{
|
|
|
|
DECLARE_SELF(QPoint, y);
|
|
|
|
|
2009-11-27 03:49:38 +01:00
|
|
|
if (ctx->argumentCount() > 0) {
|
|
|
|
int y = ctx->argument(0).toInt32();
|
|
|
|
self->setY(y);
|
|
|
|
}
|
2009-11-18 23:54:36 +01:00
|
|
|
|
2009-11-27 03:49:38 +01:00
|
|
|
return QScriptValue(eng, self->y());
|
2009-11-18 23:54:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QScriptValue constructQPointClass(QScriptEngine *eng)
|
|
|
|
{
|
|
|
|
QScriptValue proto = qScriptValueFromValue(eng, QPoint());
|
|
|
|
QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter;
|
|
|
|
QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter;
|
|
|
|
|
2010-01-27 22:06:03 +01:00
|
|
|
proto.setProperty("null", eng->newFunction(null), getter);
|
2009-11-27 03:49:38 +01:00
|
|
|
proto.setProperty("manhattanLength", eng->newFunction(manhattanLength), getter);
|
|
|
|
proto.setProperty("x", eng->newFunction(x), getter | setter);
|
|
|
|
proto.setProperty("y", eng->newFunction(y), getter | setter);
|
2009-11-18 23:54:36 +01:00
|
|
|
|
|
|
|
eng->setDefaultPrototype(qMetaTypeId<QPoint>(), proto);
|
|
|
|
eng->setDefaultPrototype(qMetaTypeId<QPoint*>(), proto);
|
|
|
|
|
|
|
|
return eng->newFunction(ctor, proto);
|
|
|
|
}
|