2009-11-18 23:54:17 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Aaron J. Seigo <aseigo@kde.org>
|
|
|
|
*
|
|
|
|
* 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 <QtScript/QScriptValue>
|
|
|
|
#include <QtScript/QScriptEngine>
|
|
|
|
#include <QtScript/QScriptContext>
|
2012-04-10 00:22:13 +02:00
|
|
|
#include <QPixmap>
|
2010-08-06 04:01:40 +02:00
|
|
|
#include "backportglobal.h"
|
|
|
|
#include "plasmoid/appletinterface.h"
|
2009-11-18 23:54:17 +01:00
|
|
|
|
|
|
|
static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)
|
|
|
|
{
|
|
|
|
if (ctx->argumentCount() == 1 && ctx->argument(0).isString()) {
|
|
|
|
// a path on disk in the package
|
2010-08-06 04:01:40 +02:00
|
|
|
AppletInterface *interface = AppletInterface::extract(eng);
|
|
|
|
const QString path = interface ? interface->file("images", ctx->argument(0).toString()) : QString();
|
|
|
|
return qScriptValueFromValue(eng, QPixmap(path));
|
2009-11-18 23:54:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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()));
|
|
|
|
}
|
|
|
|
|
2010-01-27 22:06:03 +01:00
|
|
|
static QScriptValue null(QScriptContext *ctx, QScriptEngine *eng)
|
2009-11-18 23:54:17 +01:00
|
|
|
{
|
2010-01-27 22:06:03 +01:00
|
|
|
DECLARE_SELF(QPixmap, null);
|
2009-11-18 23:54:17 +01:00
|
|
|
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());
|
2009-11-27 03:20:33 +01:00
|
|
|
QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter;
|
2010-01-27 22:06:03 +01:00
|
|
|
proto.setProperty("null", eng->newFunction(null), getter);
|
2009-11-27 03:20:33 +01:00
|
|
|
proto.setProperty("rect", eng->newFunction(rect), getter);
|
2010-02-16 22:18:40 +01:00
|
|
|
proto.setProperty("scaled", eng->newFunction(scaled));
|
2009-11-18 23:54:17 +01:00
|
|
|
|
|
|
|
eng->setDefaultPrototype(qMetaTypeId<QPixmap>(), proto);
|
|
|
|
eng->setDefaultPrototype(qMetaTypeId<QPixmap*>(), proto);
|
|
|
|
|
|
|
|
return eng->newFunction(ctor, proto);
|
|
|
|
}
|