From 092bf9d3e64e5cbd4321c42b5466d423ca9b4baa Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Tue, 5 Jan 2010 23:48:56 +0000 Subject: [PATCH] count/itemAt; plugs some holes that made layouts rather unuseful (though getting reports about these things is nice: people are actually using them! wow! :) svn path=/trunk/KDE/kdebase/runtime/; revision=1070549 --- .../simplebindings/linearlayout.cpp | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/scriptengines/javascript/simplebindings/linearlayout.cpp b/scriptengines/javascript/simplebindings/linearlayout.cpp index 21edfb875..f5c57f2bc 100644 --- a/scriptengines/javascript/simplebindings/linearlayout.cpp +++ b/scriptengines/javascript/simplebindings/linearlayout.cpp @@ -39,7 +39,6 @@ DECLARE_VOID_NUMBER_METHOD(QGraphicsLinearLayout, addStretch) DECLARE_VOID_NUMBER_NUMBER_METHOD(QGraphicsLinearLayout, insertStretch) DECLARE_VOID_NUMBER_NUMBER_METHOD(QGraphicsLinearLayout, setItemSpacing) DECLARE_VOID_QUAD_NUMBER_METHOD(QGraphicsLinearLayout, setContentsMargins) -DECLARE_NUMBER_GET_SET_METHODS(QGraphicsLinearLayout, spacing, setSpacing) ///////////////////////////////////////////////////////////// @@ -79,12 +78,11 @@ static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) } BEGIN_DECLARE_METHOD(QGraphicsLinearLayout, orientation) { - return QScriptValue(eng, static_cast(self->orientation())); -} END_DECLARE_METHOD + if (ctx->argumentCount() > 0) { + self->setOrientation(static_cast(ctx->argument(0).toInt32())); + } -BEGIN_DECLARE_METHOD(QGraphicsLinearLayout, setOrientation) { - self->setOrientation(static_cast(ctx->argument(0).toInt32())); - return eng->undefinedValue(); + return QScriptValue(eng, static_cast(self->orientation())); } END_DECLARE_METHOD BEGIN_DECLARE_METHOD(QGraphicsLinearLayout, setAlignment) { @@ -146,14 +144,29 @@ BEGIN_DECLARE_METHOD(QGraphicsItem, toString) { return QScriptValue(eng, "QGraphicsLinearLayout"); } END_DECLARE_METHOD -///////////////////////////////////////////////////////////// +BEGIN_DECLARE_METHOD(QGraphicsLinearLayout, count) { + return QScriptValue(eng, self->count()); +} END_DECLARE_METHOD -class PrototypeLinearLayout : public QGraphicsLinearLayout -{ -public: - PrototypeLinearLayout() - { } -}; +BEGIN_DECLARE_METHOD(QGraphicsLinearLayout, itemAt) { + if (ctx->argumentCount() < 1) { + return eng->undefinedValue(); + } + + int index = ctx->argument(0).toInt32(); + return qScriptValueFromValue(eng, self->itemAt(index)); +} END_DECLARE_METHOD + +BEGIN_DECLARE_METHOD(QGraphicsLinearLayout, spacing) { + if (ctx->argumentCount() > 0) { + int pixels = ctx->argument(0).toInt32(); + self->setSpacing(pixels); + } + + return QScriptValue(eng, self->spacing()); +} END_DECLARE_METHOD + +///////////////////////////////////////////////////////////// QScriptValue constructLinearLayoutClass(QScriptEngine *eng) { @@ -161,10 +174,10 @@ QScriptValue constructLinearLayoutClass(QScriptEngine *eng) QScriptValue proto = QScript::wrapPointer(eng, new QGraphicsLinearLayout(), QScript::UserOwnership); const QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter; const QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter; - proto.setProperty("spacing", eng->newFunction(spacing), getter); - proto.setProperty("spacing", eng->newFunction(setSpacing), setter); - proto.setProperty("orientation", eng->newFunction(orientation), getter); - proto.setProperty("orientation", eng->newFunction(setOrientation), setter); + proto.setProperty("count", eng->newFunction(count), getter); + proto.setProperty("spacing", eng->newFunction(spacing), getter | setter); + proto.setProperty("orientation", eng->newFunction(orientation), getter | setter); + ADD_METHOD(proto, itemAt); ADD_METHOD(proto, removeAt); ADD_METHOD(proto, addStretch); ADD_METHOD(proto, setStretchFactor);