a simple binding for scripted containments
This commit is contained in:
parent
145bcf4045
commit
ea0b394a55
@ -32,6 +32,7 @@ public:
|
|||||||
AbstractJsAppletScript(QObject *parent, const QVariantList &args = QVariantList());
|
AbstractJsAppletScript(QObject *parent, const QVariantList &args = QVariantList());
|
||||||
~AbstractJsAppletScript();
|
~AbstractJsAppletScript();
|
||||||
|
|
||||||
|
virtual QScriptEngine *engine() const = 0;
|
||||||
virtual bool include(const QString &path) = 0;
|
virtual bool include(const QString &path) = 0;
|
||||||
virtual QString filePath(const QString &type, const QString &file) const = 0;
|
virtual QString filePath(const QString &type, const QString &file) const = 0;
|
||||||
virtual QScriptValue variantToScriptValue(QVariant var) = 0;
|
virtual QScriptValue variantToScriptValue(QVariant var) = 0;
|
||||||
|
@ -375,7 +375,7 @@ void AppletInterface::gc()
|
|||||||
|
|
||||||
|
|
||||||
PopupAppletInterface::PopupAppletInterface(AbstractJsAppletScript *parent)
|
PopupAppletInterface::PopupAppletInterface(AbstractJsAppletScript *parent)
|
||||||
: POPUPAPPLETSUPERCLASS(parent)
|
: APPLETSUPERCLASS(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,6 +429,35 @@ QGraphicsWidget *PopupAppletInterface::popupWidget()
|
|||||||
return popupApplet()->graphicsWidget();
|
return popupApplet()->graphicsWidget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ContainmentInterface::ContainmentInterface(AbstractJsAppletScript *parent)
|
||||||
|
: APPLETSUPERCLASS(parent)
|
||||||
|
{
|
||||||
|
connect(containment(), SIGNAL(appletRemoved(Plasma::Applet *)), this, SLOT(appletRemovedForward(Plasma::Applet *)));
|
||||||
|
|
||||||
|
connect(containment(), SIGNAL(appletAdded(Plasma::Applet *, const QPointF &)), this, SLOT(appletAddedForward(Plasma::Applet *, const QPointF &)));
|
||||||
|
}
|
||||||
|
|
||||||
|
QScriptValue ContainmentInterface::applets()
|
||||||
|
{
|
||||||
|
QScriptValue list = m_appletScriptEngine->engine()->newArray(containment()->applets().size());
|
||||||
|
int i = 0;
|
||||||
|
foreach (Plasma::Applet *applet, containment()->applets()) {
|
||||||
|
list.setProperty(i, m_appletScriptEngine->engine()->newQObject(applet));
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContainmentInterface::appletAddedForward(Plasma::Applet *applet, const QPointF &pos)
|
||||||
|
{
|
||||||
|
emit appletAdded(applet, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ContainmentInterface::appletRemovedForward(Plasma::Applet *applet)
|
||||||
|
{
|
||||||
|
emit appletRemoved(applet);
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef USE_JS_SCRIPTENGINE
|
#ifndef USE_JS_SCRIPTENGINE
|
||||||
#include "appletinterface.moc"
|
#include "appletinterface.moc"
|
||||||
#endif
|
#endif
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include <QScriptValue>
|
#include <QScriptValue>
|
||||||
|
|
||||||
#include <Plasma/Applet>
|
#include <Plasma/Applet>
|
||||||
|
#include <Plasma/Containment>
|
||||||
#include <Plasma/PopupApplet>
|
#include <Plasma/PopupApplet>
|
||||||
#include <Plasma/DataEngine>
|
#include <Plasma/DataEngine>
|
||||||
#include <Plasma/Theme>
|
#include <Plasma/Theme>
|
||||||
@ -319,11 +320,11 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#ifdef USE_JS_SCRIPTENGINE
|
#ifdef USE_JS_SCRIPTENGINE
|
||||||
#define POPUPAPPLETSUPERCLASS JsAppletInterface
|
#define APPLETSUPERCLASS JsAppletInterface
|
||||||
#else
|
#else
|
||||||
#define POPUPAPPLETSUPERCLASS AppletInterface
|
#define APPLETSUPERCLASS AppletInterface
|
||||||
#endif
|
#endif
|
||||||
class PopupAppletInterface : public POPUPAPPLETSUPERCLASS
|
class PopupAppletInterface : public APPLETSUPERCLASS
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QIcon popupIcon READ popupIcon WRITE setPopupIcon)
|
Q_PROPERTY(QIcon popupIcon READ popupIcon WRITE setPopupIcon)
|
||||||
@ -351,4 +352,26 @@ public Q_SLOTS:
|
|||||||
void showPopup();
|
void showPopup();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class ContainmentInterface : public APPLETSUPERCLASS
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QScriptValue applets READ applets)
|
||||||
|
|
||||||
|
public:
|
||||||
|
ContainmentInterface(AbstractJsAppletScript *parent);
|
||||||
|
|
||||||
|
inline Plasma::Containment *containment() const { return static_cast<Plasma::Containment *>(m_appletScriptEngine->applet()); }
|
||||||
|
|
||||||
|
QScriptValue applets() ;
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void appletAdded(QGraphicsWidget *applet, const QPointF &pos);
|
||||||
|
void appletRemoved(QGraphicsWidget *applet);
|
||||||
|
|
||||||
|
protected Q_SLOTS:
|
||||||
|
void appletAddedForward(Plasma::Applet *applet, const QPointF &pos);
|
||||||
|
void appletRemovedForward(Plasma::Applet *applet);
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -102,6 +102,7 @@ bool DeclarativeAppletScript::init()
|
|||||||
|
|
||||||
Plasma::Applet *a = applet();
|
Plasma::Applet *a = applet();
|
||||||
Plasma::PopupApplet *pa = qobject_cast<Plasma::PopupApplet *>(a);
|
Plasma::PopupApplet *pa = qobject_cast<Plasma::PopupApplet *>(a);
|
||||||
|
Plasma::Containment *cont = qobject_cast<Plasma::Containment *>(a);
|
||||||
|
|
||||||
if (pa) {
|
if (pa) {
|
||||||
pa->setPopupIcon(a->icon());
|
pa->setPopupIcon(a->icon());
|
||||||
@ -112,7 +113,15 @@ bool DeclarativeAppletScript::init()
|
|||||||
lay->addItem(m_declarativeWidget);
|
lay->addItem(m_declarativeWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_interface = pa ? new PopupAppletInterface(this) : new AppletInterface(this);
|
m_interface = 0;
|
||||||
|
if (pa) {
|
||||||
|
m_interface = new PopupAppletInterface(this);
|
||||||
|
} else if (cont) {
|
||||||
|
m_interface = new ContainmentInterface(this);
|
||||||
|
//fail? so it's a normal Applet
|
||||||
|
} else {
|
||||||
|
m_interface = new AppletInterface(this);
|
||||||
|
}
|
||||||
|
|
||||||
m_engineAccess = new EngineAccess(this);
|
m_engineAccess = new EngineAccess(this);
|
||||||
m_declarativeWidget->engine()->rootContext()->setContextProperty("__engineAccess", m_engineAccess);
|
m_declarativeWidget->engine()->rootContext()->setContextProperty("__engineAccess", m_engineAccess);
|
||||||
@ -443,6 +452,11 @@ QScriptValue DeclarativeAppletScript::loadService(QScriptContext *context, QScri
|
|||||||
return engine->newQObject(service, QScriptEngine::AutoOwnership);
|
return engine->newQObject(service, QScriptEngine::AutoOwnership);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QScriptEngine *DeclarativeAppletScript::engine() const
|
||||||
|
{
|
||||||
|
return m_engine;
|
||||||
|
}
|
||||||
|
|
||||||
void DeclarativeAppletScript::setEngine(QScriptValue &val)
|
void DeclarativeAppletScript::setEngine(QScriptValue &val)
|
||||||
{
|
{
|
||||||
if (val.engine() == m_engine) {
|
if (val.engine() == m_engine) {
|
||||||
|
@ -59,6 +59,8 @@ public:
|
|||||||
|
|
||||||
ScriptEnv *scriptEnv();
|
ScriptEnv *scriptEnv();
|
||||||
|
|
||||||
|
QScriptEngine *engine() const;
|
||||||
|
|
||||||
QScriptValue variantToScriptValue(QVariant var);
|
QScriptValue variantToScriptValue(QVariant var);
|
||||||
|
|
||||||
static QScriptValue loadui(QScriptContext *context, QScriptEngine *engine);
|
static QScriptValue loadui(QScriptContext *context, QScriptEngine *engine);
|
||||||
|
@ -808,6 +808,11 @@ void SimpleJavaScriptApplet::installWidgets(QScriptEngine *engine)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QScriptEngine *SimpleJavaScriptApplet::engine() const
|
||||||
|
{
|
||||||
|
return m_engine;
|
||||||
|
}
|
||||||
|
|
||||||
QGraphicsWidget *SimpleJavaScriptApplet::extractParent(QScriptContext *context, QScriptEngine *engine,
|
QGraphicsWidget *SimpleJavaScriptApplet::extractParent(QScriptContext *context, QScriptEngine *engine,
|
||||||
int argIndex, bool *parentedToApplet)
|
int argIndex, bool *parentedToApplet)
|
||||||
{
|
{
|
||||||
|
@ -58,6 +58,8 @@ public:
|
|||||||
|
|
||||||
bool eventFilter(QObject *watched, QEvent *event);
|
bool eventFilter(QObject *watched, QEvent *event);
|
||||||
|
|
||||||
|
QScriptEngine *engine() const;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_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