2009-12-16 23:05:46 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2007-2008 Richard J. Moore <rich@kde.org>
|
|
|
|
* 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 <QGraphicsWidget>
|
|
|
|
#include <QScriptEngine>
|
|
|
|
|
|
|
|
#include <Plasma/Applet>
|
|
|
|
#include <Plasma/Animation>
|
2010-01-20 22:40:55 +01:00
|
|
|
#include <Plasma/Extender>
|
2009-12-16 23:05:46 +01:00
|
|
|
#include <Plasma/VideoWidget>
|
|
|
|
|
|
|
|
//Q_DECLARE_METATYPE(SimpleJavaScriptApplet*)
|
|
|
|
Q_DECLARE_METATYPE(QGraphicsWidget*)
|
|
|
|
Q_DECLARE_METATYPE(QGraphicsLayout*)
|
2010-01-20 22:40:55 +01:00
|
|
|
|
2009-12-16 23:05:46 +01:00
|
|
|
Q_DECLARE_METATYPE(Plasma::Animation*)
|
2010-01-20 22:40:55 +01:00
|
|
|
Q_DECLARE_METATYPE(Plasma::Applet*)
|
|
|
|
Q_DECLARE_METATYPE(Plasma::Extender*)
|
2009-12-16 23:05:46 +01:00
|
|
|
Q_DECLARE_METATYPE(Plasma::VideoWidget::Controls)
|
2010-03-09 21:01:51 +01:00
|
|
|
Q_DECLARE_METATYPE(Plasma::Svg*)
|
2010-05-21 20:48:09 +02:00
|
|
|
Q_DECLARE_METATYPE(Qt::MouseButton)
|
2010-10-04 19:23:21 +02:00
|
|
|
Q_DECLARE_METATYPE(QList<double>)
|
2009-12-16 23:05:46 +01:00
|
|
|
|
|
|
|
QScriptValue qScriptValueFromControls(QScriptEngine *engine, const Plasma::VideoWidget::Controls &controls)
|
|
|
|
{
|
|
|
|
return QScriptValue(engine, controls);
|
|
|
|
}
|
|
|
|
|
|
|
|
void controlsFromScriptValue(const QScriptValue& obj, Plasma::VideoWidget::Controls &controls)
|
|
|
|
{
|
|
|
|
int flagValue = obj.toInteger();
|
|
|
|
//FIXME: it has to be a less ugly way to do that :)
|
|
|
|
if (flagValue & Plasma::VideoWidget::Play) {
|
|
|
|
controls |= Plasma::VideoWidget::Play;
|
|
|
|
}
|
|
|
|
if (flagValue & Plasma::VideoWidget::Pause) {
|
|
|
|
controls |= Plasma::VideoWidget::Pause;
|
|
|
|
}
|
|
|
|
if (flagValue & Plasma::VideoWidget::Stop) {
|
|
|
|
controls |= Plasma::VideoWidget::Stop;
|
|
|
|
}
|
|
|
|
if (flagValue & Plasma::VideoWidget::PlayPause) {
|
|
|
|
controls |= Plasma::VideoWidget::PlayPause;
|
|
|
|
}
|
|
|
|
if (flagValue & Plasma::VideoWidget::Progress) {
|
|
|
|
controls |= Plasma::VideoWidget::Progress;
|
|
|
|
}
|
|
|
|
if (flagValue & Plasma::VideoWidget::Volume) {
|
|
|
|
controls |= Plasma::VideoWidget::Volume;
|
|
|
|
}
|
|
|
|
if (flagValue & Plasma::VideoWidget::OpenFile) {
|
|
|
|
controls |= Plasma::VideoWidget::OpenFile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef Plasma::Animation* AnimationPtr;
|
|
|
|
QScriptValue qScriptValueFromAnimation(QScriptEngine *engine, const AnimationPtr &anim)
|
|
|
|
{
|
2010-09-16 03:13:34 +02:00
|
|
|
return engine->newQObject(const_cast<Plasma::Animation *>(anim), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
|
2009-12-16 23:05:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void abstractAnimationFromQScriptValue(const QScriptValue &scriptValue, AnimationPtr &anim)
|
|
|
|
{
|
|
|
|
QObject *obj = scriptValue.toQObject();
|
2010-09-16 03:13:34 +02:00
|
|
|
anim = static_cast<Plasma::Animation *>(obj);
|
2009-12-16 23:05:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef QGraphicsWidget * QGraphicsWidgetPtr;
|
|
|
|
QScriptValue qScriptValueFromQGraphicsWidget(QScriptEngine *engine, const QGraphicsWidgetPtr &anim)
|
|
|
|
{
|
|
|
|
return engine->newQObject(const_cast<QGraphicsWidget *>(anim), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
|
|
|
|
}
|
|
|
|
|
2010-03-09 21:01:51 +01:00
|
|
|
void graphicsWidgetFromQScriptValue(const QScriptValue &scriptValue, QGraphicsWidgetPtr &anim)
|
2009-12-16 23:05:46 +01:00
|
|
|
{
|
|
|
|
QObject *obj = scriptValue.toQObject();
|
|
|
|
anim = static_cast<QGraphicsWidget *>(obj);
|
|
|
|
}
|
|
|
|
|
2010-03-09 21:01:51 +01:00
|
|
|
typedef Plasma::Svg * SvgPtr;
|
|
|
|
QScriptValue qScriptValueFromSvg(QScriptEngine *engine, const SvgPtr &anim)
|
|
|
|
{
|
|
|
|
return engine->newQObject(const_cast<Plasma::Svg *>(anim), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
void svgFromQScriptValue(const QScriptValue &scriptValue, SvgPtr &anim)
|
|
|
|
{
|
|
|
|
QObject *obj = scriptValue.toQObject();
|
|
|
|
anim = static_cast<Plasma::Svg *>(obj);
|
|
|
|
}
|
|
|
|
|
2010-01-20 22:40:55 +01:00
|
|
|
typedef Plasma::Extender *ExtenderPtr;
|
|
|
|
QScriptValue qScriptValueFromExtender(QScriptEngine *engine, const ExtenderPtr &extender)
|
|
|
|
{
|
|
|
|
return engine->newQObject(const_cast<Plasma::Extender *>(extender), QScriptEngine::AutoOwnership, QScriptEngine::PreferExistingWrapperObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
void extenderFromQScriptValue(const QScriptValue &scriptValue, ExtenderPtr &extender)
|
|
|
|
{
|
|
|
|
QObject *obj = scriptValue.toQObject();
|
|
|
|
extender = static_cast<Plasma::Extender *>(obj);
|
|
|
|
}
|
2010-02-13 01:32:26 +01:00
|
|
|
|
2010-05-21 20:49:40 +02:00
|
|
|
QScriptValue qScriptValueFromMouseButton(QScriptEngine *, const Qt::MouseButton &button)
|
2010-05-21 20:48:09 +02:00
|
|
|
{
|
|
|
|
return int(button);
|
|
|
|
}
|
|
|
|
|
|
|
|
void mouseButtonFromScriptValue(const QScriptValue &scriptValue, Qt::MouseButton &button)
|
|
|
|
{
|
|
|
|
button = static_cast<Qt::MouseButton>(scriptValue.toInt32());
|
|
|
|
}
|
|
|
|
|
2010-01-21 00:13:40 +01:00
|
|
|
using namespace Plasma;
|
2010-01-20 22:40:55 +01:00
|
|
|
|
2010-02-13 01:53:46 +01:00
|
|
|
void registerSimpleAppletMetaTypes(QScriptEngine *engine)
|
2009-12-16 23:05:46 +01:00
|
|
|
{
|
2010-03-09 21:01:51 +01:00
|
|
|
qScriptRegisterMetaType<QGraphicsWidget*>(engine, qScriptValueFromQGraphicsWidget, graphicsWidgetFromQScriptValue);
|
|
|
|
qScriptRegisterMetaType<Plasma::Svg*>(engine, qScriptValueFromSvg, svgFromQScriptValue);
|
2010-01-20 22:40:55 +01:00
|
|
|
|
2010-10-04 19:23:21 +02:00
|
|
|
qScriptRegisterSequenceMetaType<QList<double> >(engine);
|
2010-01-20 22:40:55 +01:00
|
|
|
qScriptRegisterMetaType<Plasma::Animation *>(engine, qScriptValueFromAnimation, abstractAnimationFromQScriptValue);
|
2010-01-21 00:13:40 +01:00
|
|
|
qScriptRegisterMetaType<Plasma::Extender *>(engine, qScriptValueFromExtender, extenderFromQScriptValue);
|
2010-01-20 22:40:55 +01:00
|
|
|
qScriptRegisterMetaType<Plasma::VideoWidget::Controls>(engine, qScriptValueFromControls, controlsFromScriptValue, QScriptValue());
|
2010-05-21 20:48:09 +02:00
|
|
|
qScriptRegisterMetaType<Qt::MouseButton>(engine, qScriptValueFromMouseButton, mouseButtonFromScriptValue);
|
2009-12-16 23:05:46 +01:00
|
|
|
}
|
2010-02-13 01:53:46 +01:00
|
|
|
|
2010-09-16 03:13:34 +02:00
|
|
|
#include "simplebindings/qscriptnonguibookkeeping.cpp"
|
|
|
|
|