2009-11-18 23:55:12 +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/QSizeF>
|
2010-08-06 04:01:40 +02:00
|
|
|
#include "backportglobal.h"
|
2009-11-18 23:55:12 +01:00
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(QSizeF*)
|
|
|
|
Q_DECLARE_METATYPE(QSizeF)
|
|
|
|
|
|
|
|
static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)
|
|
|
|
{
|
2009-11-27 03:43:45 +01:00
|
|
|
if (ctx->argumentCount() == 2) {
|
2009-11-18 23:55:12 +01:00
|
|
|
qreal width = ctx->argument(1).toNumber();
|
|
|
|
qreal height = ctx->argument(1).toNumber();
|
|
|
|
return qScriptValueFromValue(eng, QSizeF(width, height));
|
|
|
|
}
|
|
|
|
|
|
|
|
return qScriptValueFromValue(eng, QSizeF());
|
|
|
|
}
|
|
|
|
|
|
|
|
static QScriptValue width(QScriptContext *ctx, QScriptEngine *eng)
|
|
|
|
{
|
|
|
|
DECLARE_SELF(QSizeF, width);
|
2009-11-27 03:43:45 +01:00
|
|
|
if (ctx->argumentCount() > 0) {
|
|
|
|
qreal width = ctx->argument(0).toNumber();
|
|
|
|
self->setWidth(width);
|
|
|
|
}
|
|
|
|
|
2009-11-18 23:55:12 +01:00
|
|
|
return QScriptValue(eng, self->width());
|
|
|
|
}
|
|
|
|
|
|
|
|
static QScriptValue height(QScriptContext *ctx, QScriptEngine *eng)
|
|
|
|
{
|
|
|
|
DECLARE_SELF(QSizeF, height);
|
2009-11-27 03:43:45 +01:00
|
|
|
if (ctx->argumentCount() > 0) {
|
|
|
|
qreal height = ctx->argument(0).toNumber();
|
2011-01-21 14:29:29 +01:00
|
|
|
self->setHeight(height);
|
2009-11-27 03:43:45 +01:00
|
|
|
}
|
|
|
|
|
2009-11-18 23:55:12 +01:00
|
|
|
return QScriptValue(eng, self->height());
|
|
|
|
}
|
|
|
|
|
|
|
|
QScriptValue constructQSizeFClass(QScriptEngine *eng)
|
|
|
|
{
|
|
|
|
QScriptValue proto = qScriptValueFromValue(eng, QSizeF());
|
|
|
|
QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter;
|
|
|
|
QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter;
|
|
|
|
|
2009-11-27 03:43:45 +01:00
|
|
|
proto.setProperty("width", eng->newFunction(width), getter | setter);
|
|
|
|
proto.setProperty("height", eng->newFunction(height), getter | setter);
|
2009-11-18 23:55:12 +01:00
|
|
|
|
2009-11-27 03:43:45 +01:00
|
|
|
eng->setDefaultPrototype(qMetaTypeId<QSizeF>(), proto);
|
|
|
|
eng->setDefaultPrototype(qMetaTypeId<QSizeF*>(), proto);
|
2009-11-18 23:55:12 +01:00
|
|
|
return eng->newFunction(ctor, proto);
|
|
|
|
}
|
|
|
|
|