declare the default constructors and width/height as getters/setters

svn path=/trunk/KDE/kdebase/runtime/; revision=1054895
This commit is contained in:
Aaron J. Seigo 2009-11-27 02:43:45 +00:00
parent b0287c853b
commit 23cba1143e

View File

@ -27,8 +27,7 @@ Q_DECLARE_METATYPE(QSizeF)
static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)
{
if (ctx->argumentCount() == 2)
{
if (ctx->argumentCount() == 2) {
qreal width = ctx->argument(1).toNumber();
qreal height = ctx->argument(1).toNumber();
return qScriptValueFromValue(eng, QSizeF(width, height));
@ -40,12 +39,22 @@ static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)
static QScriptValue width(QScriptContext *ctx, QScriptEngine *eng)
{
DECLARE_SELF(QSizeF, width);
if (ctx->argumentCount() > 0) {
qreal width = ctx->argument(0).toNumber();
self->setWidth(width);
}
return QScriptValue(eng, self->width());
}
static QScriptValue height(QScriptContext *ctx, QScriptEngine *eng)
{
DECLARE_SELF(QSizeF, height);
if (ctx->argumentCount() > 0) {
qreal height = ctx->argument(0).toNumber();
self->setWidth(height);
}
return QScriptValue(eng, self->height());
}
@ -55,9 +64,11 @@ QScriptValue constructQSizeFClass(QScriptEngine *eng)
QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter;
QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter;
proto.setProperty("width", eng->newFunction(width));
proto.setProperty("height", eng->newFunction(height));
proto.setProperty("width", eng->newFunction(width), getter | setter);
proto.setProperty("height", eng->newFunction(height), getter | setter);
eng->setDefaultPrototype(qMetaTypeId<QSizeF>(), proto);
eng->setDefaultPrototype(qMetaTypeId<QSizeF*>(), proto);
return eng->newFunction(ctor, proto);
}