From d7bd1a7a86f3ebf359b2506fb2b7f01b9243455c Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Wed, 18 Nov 2009 22:54:17 +0000 Subject: [PATCH] Restore files svn path=/trunk/KDE/kdebase/runtime/; revision=1051155 --- .../javascript/simplebindings/pixmap.cpp | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 scriptengines/javascript/simplebindings/pixmap.cpp diff --git a/scriptengines/javascript/simplebindings/pixmap.cpp b/scriptengines/javascript/simplebindings/pixmap.cpp new file mode 100644 index 000000000..e9bafdb4e --- /dev/null +++ b/scriptengines/javascript/simplebindings/pixmap.cpp @@ -0,0 +1,76 @@ +/* + * 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" +#include "../simplejavascriptapplet.h" + +Q_DECLARE_METATYPE(QPixmap*) +Q_DECLARE_METATYPE(QPixmap) + +static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) +{ + if (ctx->argumentCount() == 1 && ctx->argument(0).isString()) { + // a path on disk in the package + return qScriptValueFromValue(eng, QPixmap(SimpleJavaScriptApplet::findImageFile(eng, ctx->argument(0).toString()))); + } + + if (ctx->argumentCount() == 2) { + qreal x = ctx->argument(0).toNumber(); + qreal y = ctx->argument(1).toNumber(); + return qScriptValueFromValue(eng, QPixmap(x, y)); + } + + return qScriptValueFromValue(eng, QPixmap()); +} + +static QScriptValue rect(QScriptContext *ctx, QScriptEngine *eng) +{ + DECLARE_SELF(QPixmap, rect) + return qScriptValueFromValue(eng, QRectF(self->rect())); +} + +static QScriptValue isNull(QScriptContext *ctx, QScriptEngine *eng) +{ + DECLARE_SELF(QPixmap, isNull); + return QScriptValue(eng, self->isNull()); +} + +static QScriptValue scaled(QScriptContext *ctx, QScriptEngine *eng) +{ + DECLARE_SELF(QPixmap, scaled); + qreal x = ctx->argument(0).toNumber(); + qreal y = ctx->argument(1).toNumber(); + return qScriptValueFromValue(eng, self->scaled(x, y)); +} + +QScriptValue constructQPixmapClass(QScriptEngine *eng) +{ + QScriptValue proto = qScriptValueFromValue(eng, QPixmap()); + proto.setProperty("isNull", eng->newFunction(isNull)); + proto.setProperty("rect", eng->newFunction(rect)); + proto.setProperty("scaled", eng->newFunction(scaled)); + + eng->setDefaultPrototype(qMetaTypeId(), proto); + eng->setDefaultPrototype(qMetaTypeId(), proto); + + return eng->newFunction(ctor, proto); +}