From 0ab7db4524e65c771ecf720d37d831a5b4a9d2eb Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Fri, 27 Nov 2009 20:29:14 +0000 Subject: [PATCH] pen, without which painter is a lot less useful svn path=/trunk/KDE/kdebase/runtime/; revision=1055311 --- scriptengines/javascript/CMakeLists.txt | 1 + .../javascript/simplebindings/pen.cpp | 170 ++++++++++++++++++ .../javascript/simplejavascriptapplet.cpp | 2 + 3 files changed, 173 insertions(+) create mode 100644 scriptengines/javascript/simplebindings/pen.cpp diff --git a/scriptengines/javascript/CMakeLists.txt b/scriptengines/javascript/CMakeLists.txt index 62f6aed7e..270565d74 100644 --- a/scriptengines/javascript/CMakeLists.txt +++ b/scriptengines/javascript/CMakeLists.txt @@ -10,6 +10,7 @@ set(simple_javascript_engine_SRCS simplebindings/graphicsitem.cpp simplebindings/linearlayout.cpp simplebindings/painter.cpp + simplebindings/pen.cpp simplebindings/pixmap.cpp simplebindings/point.cpp simplebindings/rect.cpp diff --git a/scriptengines/javascript/simplebindings/pen.cpp b/scriptengines/javascript/simplebindings/pen.cpp new file mode 100644 index 000000000..6b4692bbf --- /dev/null +++ b/scriptengines/javascript/simplebindings/pen.cpp @@ -0,0 +1,170 @@ +/* + * Copyright 2009 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(QPen*) + +static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) +{ + Q_UNUSED(ctx) + return qScriptValueFromValue(eng, QPen()); +} + +static QScriptValue brush(QScriptContext *ctx, QScriptEngine *eng) +{ + DECLARE_SELF(QPen, brush); + + if (ctx->argumentCount() > 0) { + QScriptValue arg = ctx->argument(0); + self->setBrush(qscriptvalue_cast(arg)); + } + + return qScriptValueFromValue(eng, self->brush()); +} + +static QScriptValue color(QScriptContext *ctx, QScriptEngine *eng) +{ + DECLARE_SELF(QPen, color); + + if (ctx->argumentCount() > 0) { + QScriptValue arg = ctx->argument(0); + self->setColor(qscriptvalue_cast(arg)); + } + + return qScriptValueFromValue(eng, self->color()); +} + +static QScriptValue style(QScriptContext *ctx, QScriptEngine *eng) +{ + DECLARE_SELF(QPen, style); + + if (ctx->argumentCount() > 0) { + QScriptValue arg = ctx->argument(0); + self->setStyle(Qt::PenStyle(arg.toInt32())); + } + + return QScriptValue(eng, self->style()); +} + +static QScriptValue capStyle(QScriptContext *ctx, QScriptEngine *eng) +{ + DECLARE_SELF(QPen, capStyle); + + if (ctx->argumentCount() > 0) { + QScriptValue arg = ctx->argument(0); + self->setCapStyle(Qt::PenCapStyle(arg.toInt32())); + } + + return QScriptValue(eng, self->capStyle()); +} + +static QScriptValue joinStyle(QScriptContext *ctx, QScriptEngine *eng) +{ + DECLARE_SELF(QPen, joinStyle); + + if (ctx->argumentCount() > 0) { + QScriptValue arg = ctx->argument(0); + self->setJoinStyle(Qt::PenJoinStyle(arg.toInt32())); + } + + return QScriptValue(eng, self->joinStyle()); +} + +static QScriptValue dashOffset(QScriptContext *ctx, QScriptEngine *eng) +{ + DECLARE_SELF(QPen, dashOffset); + + if (ctx->argumentCount() > 0) { + QScriptValue arg = ctx->argument(0); + self->setDashOffset(arg.toInt32()); + } + + return QScriptValue(eng, self->dashOffset()); +} + +static QScriptValue miterLimit(QScriptContext *ctx, QScriptEngine *eng) +{ + DECLARE_SELF(QPen, miterLimit); + + if (ctx->argumentCount() > 0) { + QScriptValue arg = ctx->argument(0); + self->setMiterLimit(arg.toInt32()); + } + + return QScriptValue(eng, self->miterLimit()); +} + +static QScriptValue width(QScriptContext *ctx, QScriptEngine *eng) +{ + DECLARE_SELF(QPen, width); + + if (ctx->argumentCount() > 0) { + QScriptValue arg = ctx->argument(0); + self->setWidth(arg.toInt32()); + } + + return QScriptValue(eng, self->width()); +} + +static QScriptValue isSolid(QScriptContext *ctx, QScriptEngine *eng) +{ + DECLARE_SELF(QPen, isSolid); + return QScriptValue(eng, self->isSolid()); +} + +QScriptValue constructPenClass(QScriptEngine *eng) +{ + QScriptValue proto = qScriptValueFromValue(eng, QColor()); + QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter; + QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter; + proto.setProperty("brush", eng->newFunction(brush), getter | setter); + proto.setProperty("color", eng->newFunction(color), getter | setter); + proto.setProperty("capStyle", eng->newFunction(capStyle), getter | setter); + proto.setProperty("joinStyle", eng->newFunction(joinStyle), getter | setter); + proto.setProperty("style", eng->newFunction(style), getter | setter); + proto.setProperty("dashOffset", eng->newFunction(dashOffset), getter | setter); + proto.setProperty("miterLimit", eng->newFunction(miterLimit), getter | setter); + proto.setProperty("width", eng->newFunction(width), getter | setter); + proto.setProperty("isSolid", eng->newFunction(isSolid), getter); + + QScriptValue ctorFun = eng->newFunction(ctor, proto); + ADD_ENUM_VALUE(ctorFun, Qt, FlatCap); + ADD_ENUM_VALUE(ctorFun, Qt, SquareCap); + ADD_ENUM_VALUE(ctorFun, Qt, RoundCap); + ADD_ENUM_VALUE(ctorFun, Qt, RoundCap); + ADD_ENUM_VALUE(ctorFun, Qt, BevelJoin); + ADD_ENUM_VALUE(ctorFun, Qt, MiterJoin); + ADD_ENUM_VALUE(ctorFun, Qt, RoundJoin); + ADD_ENUM_VALUE(ctorFun, Qt, SolidLine); + ADD_ENUM_VALUE(ctorFun, Qt, DashLine); + ADD_ENUM_VALUE(ctorFun, Qt, DotLine); + ADD_ENUM_VALUE(ctorFun, Qt, DashDotLine); + ADD_ENUM_VALUE(ctorFun, Qt, DashDotDotLine); + ADD_ENUM_VALUE(ctorFun, Qt, CustomDashLine); + + eng->setDefaultPrototype(qMetaTypeId(), proto); + eng->setDefaultPrototype(qMetaTypeId(), proto); + + return ctorFun; +} + diff --git a/scriptengines/javascript/simplejavascriptapplet.cpp b/scriptengines/javascript/simplejavascriptapplet.cpp index 4280c182a..fddafe543 100644 --- a/scriptengines/javascript/simplejavascriptapplet.cpp +++ b/scriptengines/javascript/simplejavascriptapplet.cpp @@ -69,6 +69,7 @@ QScriptValue constructKUrlClass(QScriptEngine *engine); QScriptValue constructLinearLayoutClass(QScriptEngine *engine); QScriptValue constructAnchorLayoutClass(QScriptEngine *engine); QScriptValue constructPainterClass(QScriptEngine *engine); +QScriptValue constructPenClass(QScriptEngine *engine); QScriptValue constructQPixmapClass(QScriptEngine *engine); QScriptValue constructQPointClass(QScriptEngine *engine); QScriptValue constructQRectFClass(QScriptEngine *engine); @@ -554,6 +555,7 @@ void SimpleJavaScriptApplet::setupObjects() global.setProperty("QFont", constructFontClass(m_engine)); global.setProperty("QColor", constructColorClass(m_engine)); global.setProperty("QRectF", constructQRectFClass(m_engine)); + global.setProperty("QPen", constructPenClass(m_engine)); global.setProperty("QPixmap", constructQPixmapClass(m_engine)); global.setProperty("QSizeF", constructQSizeFClass(m_engine)); global.setProperty("QPoint", constructQPointClass(m_engine));