From 99945e5a99201ff25bbd1d9bb9a9eadbf6780438 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Wed, 24 Mar 2010 23:56:07 +0000 Subject: [PATCH] QSizePolicy, need to make size policy setting possible svn path=/trunk/KDE/kdebase/runtime/; revision=1107165 --- scriptengines/javascript/CMakeLists.txt | 1 + .../javascript/simplebindings/sizepolicy.cpp | 102 ++++++++++++++++++ .../javascript/simplejavascriptapplet.cpp | 2 + 3 files changed, 105 insertions(+) create mode 100644 scriptengines/javascript/simplebindings/sizepolicy.cpp diff --git a/scriptengines/javascript/CMakeLists.txt b/scriptengines/javascript/CMakeLists.txt index 54682f926..ddb8c786a 100644 --- a/scriptengines/javascript/CMakeLists.txt +++ b/scriptengines/javascript/CMakeLists.txt @@ -26,6 +26,7 @@ set(simple_javascript_engine_SRCS simplebindings/rect.cpp simplebindings/qscriptbookkeeping.cpp simplebindings/size.cpp + simplebindings/sizepolicy.cpp simplebindings/timer.cpp simplebindings/uiloader.cpp simplebindings/url.cpp diff --git a/scriptengines/javascript/simplebindings/sizepolicy.cpp b/scriptengines/javascript/simplebindings/sizepolicy.cpp new file mode 100644 index 000000000..ed6f46ecd --- /dev/null +++ b/scriptengines/javascript/simplebindings/sizepolicy.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2010 Aaron J. Seigo + * + * 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 +#include +#include +#include +#include "../backportglobal.h" + +Q_DECLARE_METATYPE(QSizePolicy*) + +static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) +{ + QSizePolicy::Policy h(QSizePolicy::Fixed); + QSizePolicy::Policy v(QSizePolicy::Fixed); + if (ctx->argumentCount() > 1) { + h = static_cast(ctx->argument(0).toInt32()); + v = static_cast(ctx->argument(1).toInt32()); + } + + QScriptValue value = qScriptValueFromValue(eng, QSizePolicy(h, v)); + return value; +} + +static QScriptValue horizontalPolicy(QScriptContext *ctx, QScriptEngine *eng) +{ + DECLARE_SELF(QSizePolicy, horizontalPolicy); + + if (ctx->argumentCount() > 0) { + QScriptValue arg = ctx->argument(0); + self->setHorizontalPolicy(static_cast(arg.toInt32())); + } + + return QScriptValue(eng, self->horizontalPolicy()); +} + +static QScriptValue verticalPolicy(QScriptContext *ctx, QScriptEngine *eng) +{ + DECLARE_SELF(QSizePolicy, vertialPolicy); + + if (ctx->argumentCount() > 0) { + QScriptValue arg = ctx->argument(0); + self->setVerticalPolicy(static_cast(arg.toInt32())); + } + + return QScriptValue(eng, self->verticalPolicy()); +} + +static QScriptValue horizontalStretch(QScriptContext *ctx, QScriptEngine *eng) +{ + DECLARE_SELF(QSizePolicy, horizontalStretch); + + if (ctx->argumentCount() > 0) { + QScriptValue arg = ctx->argument(0); + self->setHorizontalStretch(arg.toInt32()); + } + + return QScriptValue(eng, self->horizontalStretch()); +} + +static QScriptValue verticalStretch(QScriptContext *ctx, QScriptEngine *eng) +{ + DECLARE_SELF(QSizePolicy, verticalStretch); + + if (ctx->argumentCount() > 0) { + QScriptValue arg = ctx->argument(0); + self->setVerticalStretch(arg.toInt32()); + } + + return QScriptValue(eng, self->verticalStretch()); +} + +QScriptValue constructQSizePolicyClass(QScriptEngine *eng) +{ + QScriptValue proto = qScriptValueFromValue(eng, QSizePolicy()); + QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter; + QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter; + proto.setProperty("horizontalPolicy", eng->newFunction(horizontalPolicy), getter | setter); + proto.setProperty("verticalPolicy", eng->newFunction(verticalPolicy), getter | setter); + proto.setProperty("horizontalStretch", eng->newFunction(horizontalStretch), getter | setter); + proto.setProperty("verticalStretch", eng->newFunction(verticalStretch), getter | setter); + + eng->setDefaultPrototype(qMetaTypeId(), proto); + eng->setDefaultPrototype(qMetaTypeId(), proto); + + return eng->newFunction(ctor, proto); +} diff --git a/scriptengines/javascript/simplejavascriptapplet.cpp b/scriptengines/javascript/simplejavascriptapplet.cpp index 5cf5d36b6..5ef380fb1 100644 --- a/scriptengines/javascript/simplejavascriptapplet.cpp +++ b/scriptengines/javascript/simplejavascriptapplet.cpp @@ -81,6 +81,7 @@ QScriptValue constructQPixmapClass(QScriptEngine *engine); QScriptValue constructQPointClass(QScriptEngine *engine); QScriptValue constructQRectFClass(QScriptEngine *engine); QScriptValue constructQSizeFClass(QScriptEngine *engine); +QScriptValue constructQSizePolicyClass(QScriptEngine *engine); QScriptValue constructTimerClass(QScriptEngine *engine); void registerSimpleAppletMetaTypes(QScriptEngine *engine); @@ -355,6 +356,7 @@ void SimpleJavaScriptApplet::setupObjects() global.setProperty("QPen", constructPenClass(m_engine)); global.setProperty("QPixmap", constructQPixmapClass(m_engine)); global.setProperty("QSizeF", constructQSizeFClass(m_engine)); + global.setProperty("QSizePolicy", constructQSizePolicyClass(m_engine)); global.setProperty("QPoint", constructQPointClass(m_engine)); global.setProperty("LinearLayout", constructLinearLayoutClass(m_engine)); global.setProperty("GridLayout", constructGridLayoutClass(m_engine));