qpixmap
svn path=/trunk/KDE/kdebase/runtime/; revision=1038273
This commit is contained in:
parent
bd32426522
commit
07f1255677
@ -8,6 +8,7 @@ set(simple_javascript_engine_SRCS
|
|||||||
qtgui/graphicsitem.cpp
|
qtgui/graphicsitem.cpp
|
||||||
qtgui/linearlayout.cpp
|
qtgui/linearlayout.cpp
|
||||||
qtgui/painter.cpp
|
qtgui/painter.cpp
|
||||||
|
qtgui/pixmap.cpp
|
||||||
qtgui/point.cpp
|
qtgui/point.cpp
|
||||||
qtgui/rect.cpp
|
qtgui/rect.cpp
|
||||||
qtgui/size.cpp
|
qtgui/size.cpp
|
||||||
@ -18,8 +19,7 @@ set(simple_javascript_engine_SRCS
|
|||||||
include_directories(${PHONON_INCLUDES})
|
include_directories(${PHONON_INCLUDES})
|
||||||
|
|
||||||
|
|
||||||
kde4_add_plugin(plasma_appletscript_simple_javascript
|
kde4_add_plugin(plasma_appletscript_simple_javascript ${simple_javascript_engine_SRCS})
|
||||||
${simple_javascript_engine_SRCS})
|
|
||||||
|
|
||||||
target_link_libraries(plasma_appletscript_simple_javascript
|
target_link_libraries(plasma_appletscript_simple_javascript
|
||||||
${KDE4_KDECORE_LIBS}
|
${KDE4_KDECORE_LIBS}
|
||||||
|
76
scriptengines/javascript/qtgui/pixmap.cpp
Normal file
76
scriptengines/javascript/qtgui/pixmap.cpp
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* 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>
|
||||||
|
#include <QtGui/QPixmap>
|
||||||
|
#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, 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<QPixmap>(), proto);
|
||||||
|
eng->setDefaultPrototype(qMetaTypeId<QPixmap*>(), proto);
|
||||||
|
|
||||||
|
return eng->newFunction(ctor, proto);
|
||||||
|
}
|
@ -53,15 +53,16 @@ Q_DECLARE_METATYPE(KConfigGroup)
|
|||||||
|
|
||||||
Q_SCRIPT_DECLARE_QMETAOBJECT(AppletInterface, SimpleJavaScriptApplet*)
|
Q_SCRIPT_DECLARE_QMETAOBJECT(AppletInterface, SimpleJavaScriptApplet*)
|
||||||
|
|
||||||
QScriptValue constructPainterClass(QScriptEngine *engine);
|
|
||||||
QScriptValue constructGraphicsItemClass(QScriptEngine *engine);
|
|
||||||
QScriptValue constructLinearLayoutClass(QScriptEngine *engine);
|
|
||||||
QScriptValue constructKUrlClass(QScriptEngine *engine);
|
|
||||||
QScriptValue constructTimerClass(QScriptEngine *engine);
|
|
||||||
QScriptValue constructFontClass(QScriptEngine *engine);
|
QScriptValue constructFontClass(QScriptEngine *engine);
|
||||||
QScriptValue constructQRectFClass(QScriptEngine *engine);
|
QScriptValue constructGraphicsItemClass(QScriptEngine *engine);
|
||||||
|
QScriptValue constructKUrlClass(QScriptEngine *engine);
|
||||||
|
QScriptValue constructLinearLayoutClass(QScriptEngine *engine);
|
||||||
|
QScriptValue constructPainterClass(QScriptEngine *engine);
|
||||||
|
QScriptValue constructQPixmapClass(QScriptEngine *engine);
|
||||||
QScriptValue constructQPointClass(QScriptEngine *engine);
|
QScriptValue constructQPointClass(QScriptEngine *engine);
|
||||||
|
QScriptValue constructQRectFClass(QScriptEngine *engine);
|
||||||
QScriptValue constructQSizeFClass(QScriptEngine *engine);
|
QScriptValue constructQSizeFClass(QScriptEngine *engine);
|
||||||
|
QScriptValue constructTimerClass(QScriptEngine *engine);
|
||||||
|
|
||||||
|
|
||||||
//typedef VideoWidget::Control Control;
|
//typedef VideoWidget::Control Control;
|
||||||
@ -412,6 +413,7 @@ void SimpleJavaScriptApplet::setupObjects()
|
|||||||
global.setProperty("QTimer", constructTimerClass(m_engine));
|
global.setProperty("QTimer", constructTimerClass(m_engine));
|
||||||
global.setProperty("QFont", constructFontClass(m_engine));
|
global.setProperty("QFont", constructFontClass(m_engine));
|
||||||
global.setProperty("QRectF", constructQRectFClass(m_engine));
|
global.setProperty("QRectF", constructQRectFClass(m_engine));
|
||||||
|
global.setProperty("QPixap", constructQPixmapClass(m_engine));
|
||||||
global.setProperty("QSizeF", constructQSizeFClass(m_engine));
|
global.setProperty("QSizeF", constructQSizeFClass(m_engine));
|
||||||
global.setProperty("QPoint", constructQPointClass(m_engine));
|
global.setProperty("QPoint", constructQPointClass(m_engine));
|
||||||
global.setProperty("LinearLayout", constructLinearLayoutClass(m_engine));
|
global.setProperty("LinearLayout", constructLinearLayoutClass(m_engine));
|
||||||
@ -503,6 +505,24 @@ QScriptValue SimpleJavaScriptApplet::loadui(QScriptContext *context, QScriptEngi
|
|||||||
return engine->newQObject(w);
|
return engine->newQObject(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString SimpleJavaScriptApplet::findImageFile(QScriptEngine *engine, const QString &file)
|
||||||
|
{
|
||||||
|
QScriptValue appletValue = engine->globalObject().property("plasmoid");
|
||||||
|
//kDebug() << "appletValue is " << appletValue.toString();
|
||||||
|
|
||||||
|
QObject *appletObject = appletValue.toQObject();
|
||||||
|
if (!appletObject) {
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
AppletInterface *interface = qobject_cast<AppletInterface*>(appletObject);
|
||||||
|
if (!interface) {
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return interface->package()->filePath("images", file);
|
||||||
|
}
|
||||||
|
|
||||||
QString SimpleJavaScriptApplet::findSvg(QScriptEngine *engine, const QString &file)
|
QString SimpleJavaScriptApplet::findSvg(QScriptEngine *engine, const QString &file)
|
||||||
{
|
{
|
||||||
QScriptValue appletValue = engine->globalObject().property("plasmoid");
|
QScriptValue appletValue = engine->globalObject().property("plasmoid");
|
||||||
|
@ -51,6 +51,8 @@ public:
|
|||||||
|
|
||||||
QScriptValue variantToScriptValue(QVariant var);
|
QScriptValue variantToScriptValue(QVariant var);
|
||||||
|
|
||||||
|
static QString findImageFile(QScriptEngine *engine, const QString &file);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void dataUpdated( const QString &name, const Plasma::DataEngine::Data &data );
|
void dataUpdated( const QString &name, const Plasma::DataEngine::Data &data );
|
||||||
void configChanged();
|
void configChanged();
|
||||||
|
Loading…
Reference in New Issue
Block a user