Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / plasma / scriptengines / qscript / qtgui / point.cpp
blob821085f9636cb4d319e8ef8bfd4a204f7551c28d
1 /*
2 * Copyright 2007 Richard J. Moore <rich@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU Library General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include <QtScript/QScriptValue>
20 #include <QtScript/QScriptEngine>
21 #include <QtScript/QScriptContext>
22 #include <QtCore/QPoint>
23 #include "../backportglobal.h"
25 Q_DECLARE_METATYPE(QPoint*)
26 Q_DECLARE_METATYPE(QPoint)
28 static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)
30 if (ctx->argumentCount() == 2)
32 int x = ctx->argument(0).toInt32();
33 int y = ctx->argument(1).toInt32();
34 return qScriptValueFromValue(eng, QPoint(x, y));
37 return qScriptValueFromValue(eng, QPoint());
40 static QScriptValue isNull(QScriptContext *ctx, QScriptEngine *eng)
42 DECLARE_SELF(QPoint, isNull);
43 return QScriptValue(eng, self->isNull());
46 static QScriptValue manhattanLength(QScriptContext *ctx, QScriptEngine *eng)
48 DECLARE_SELF(QPoint, manhattanLength);
49 return QScriptValue(eng, self->manhattanLength());
52 static QScriptValue x(QScriptContext *ctx, QScriptEngine *eng)
54 DECLARE_SELF(QPoint, x);
55 return QScriptValue(eng, self->x());
58 static QScriptValue y(QScriptContext *ctx, QScriptEngine *eng)
60 DECLARE_SELF(QPoint, y);
61 return QScriptValue(eng, self->y());
64 static QScriptValue setX(QScriptContext *ctx, QScriptEngine *)
66 DECLARE_SELF(QPoint, setX);
67 int x = ctx->argument(0).toInt32();
68 self->setX(x);
69 return QScriptValue();
72 static QScriptValue setY(QScriptContext *ctx, QScriptEngine *)
74 DECLARE_SELF(QPoint, setY);
75 int y = ctx->argument(0).toInt32();
76 self->setY(y);
77 return QScriptValue();
80 QScriptValue constructQPointClass(QScriptEngine *eng)
82 QScriptValue proto = qScriptValueFromValue(eng, QPoint());
83 QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter;
84 QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter;
86 proto.setProperty("isNull", eng->newFunction(isNull));
87 proto.setProperty("manhattanLength", eng->newFunction(manhattanLength));
88 proto.setProperty("x", eng->newFunction(x));
89 proto.setProperty("y", eng->newFunction(y));
90 proto.setProperty("setX", eng->newFunction(setX));
91 proto.setProperty("setY", eng->newFunction(setY));
93 eng->setDefaultPrototype(qMetaTypeId<QPoint>(), proto);
94 eng->setDefaultPrototype(qMetaTypeId<QPoint*>(), proto);
96 return eng->newFunction(ctor, proto);