Commit 79033399 authored by Marco Martin's avatar Marco Martin
Browse files

support accessing applet geometry

the geometry property remained broken for all plasma5 lifetime.
reading it makes sense, writing it not so much (ad it depends ffrom
containment to containment)
reading works, writing stays noop (for max compatibility)
parent 9c64b36a
......@@ -18,6 +18,7 @@
*/
#include "applet.h"
#include "scriptengine.h"
#include <QAction>
......@@ -41,6 +42,7 @@ public:
{
}
QPointer<ScriptEngine> engine = nullptr;
KConfigGroup configGroup;
QStringList configGroupPath;
KConfigGroup globalConfigGroup;
......@@ -49,10 +51,11 @@ public:
bool inWallpaperConfig : 1;
};
Applet::Applet(QObject *parent)
Applet::Applet(ScriptEngine *parent)
: QObject(parent),
d(new Applet::Private)
{
d->engine = parent;
}
Applet::~Applet()
......@@ -268,6 +271,11 @@ Plasma::Applet *Applet::applet() const
return nullptr;
}
ScriptEngine *Applet::engine() const
{
return d->engine;
}
}
......
......@@ -35,13 +35,15 @@ namespace Plasma
namespace WorkspaceScripting
{
class ScriptEngine;
class Applet : public QObject
{
Q_OBJECT
Q_PROPERTY(QStringList currentConfigGroup WRITE setCurrentConfigGroup READ currentConfigGroup)
public:
explicit Applet(QObject *parent = nullptr);
explicit Applet(ScriptEngine *parent);
~Applet() override;
QStringList configKeys() const;
......@@ -63,6 +65,8 @@ public:
virtual Plasma::Applet *applet() const;
ScriptEngine *engine() const;
protected:
void reloadConfigIfNeeded();
......
......@@ -40,7 +40,6 @@ namespace WorkspaceScripting
class Containment::Private
{
public:
QPointer<ScriptEngine> engine;
QPointer<Plasma::Containment> containment;
ShellCorona *corona;
QString oldWallpaperPlugin;
......@@ -56,7 +55,6 @@ Containment::Containment(Plasma::Containment *containment, ScriptEngine *engine)
: Applet(engine),
d(new Containment::Private)
{
d->engine = engine;
d->containment = containment;
d->corona = qobject_cast<ShellCorona *>(containment->corona());
......@@ -157,7 +155,7 @@ QList<int> Containment::widgetIds() const
QJSValue Containment::widgetById(const QJSValue &paramId) const
{
if (!paramId.isNumber()) {
return d->engine->newError(i18n("widgetById requires an id"));
return engine()->newError(i18n("widgetById requires an id"));
}
const uint id = paramId.toInt();
......@@ -165,7 +163,7 @@ QJSValue Containment::widgetById(const QJSValue &paramId) const
if (d->containment) {
foreach (Plasma::Applet *w, d->containment.data()->applets()) {
if (w->id() == id) {
return d->engine->wrap(w);
return engine()->wrap(w);
}
}
}
......@@ -176,7 +174,7 @@ QJSValue Containment::widgetById(const QJSValue &paramId) const
QJSValue Containment::addWidget(const QJSValue &v, qreal x, qreal y, qreal w, qreal h, const QVariantList &args)
{
if (!v.isString() && !v.isQObject()) {
return d->engine->newError(i18n("addWidget requires a name of a widget or a widget object"));
return engine()->newError(i18n("addWidget requires a name of a widget or a widget object"));
}
if (!d->containment) {
......@@ -197,9 +195,9 @@ QJSValue Containment::addWidget(const QJSValue &v, qreal x, qreal y, qreal w, qr
QMetaObject::invokeMethod(containmentItem , "createApplet", Qt::DirectConnection, Q_RETURN_ARG(Plasma::Applet *, applet), Q_ARG(QString, v.toString()), Q_ARG(QVariantList, args), Q_ARG(QRectF, geometry));
}
if (applet) {
return d->engine->wrap(applet);
return engine()->wrap(applet);
}
return d->engine->newError(i18n("Could not create the %1 widget!", v.toString()));
return engine()->newError(i18n("Could not create the %1 widget!", v.toString()));
}
//Case in which either:
......@@ -208,10 +206,10 @@ QJSValue Containment::addWidget(const QJSValue &v, qreal x, qreal y, qreal w, qr
applet = d->containment.data()->createApplet(v.toString(), args);
if (applet) {
return d->engine->wrap(applet);
return engine()->wrap(applet);
}
return d->engine->newError(i18n("Could not create the %1 widget!", v.toString()));
return engine()->newError(i18n("Could not create the %1 widget!", v.toString()));
} else if (Widget *widget = qobject_cast<Widget*>(v.toQObject())) {
applet = widget->applet();
d->containment.data()->addApplet(applet);
......@@ -227,12 +225,12 @@ QJSValue Containment::widgets(const QString &widgetType) const
return QJSValue();
}
QJSValue widgets = d->engine->newArray();
QJSValue widgets = engine()->newArray();
int count = 0;
foreach (Plasma::Applet *widget, d->containment.data()->applets()) {
if (widgetType.isEmpty() || widget->pluginMetaData().pluginId() == widgetType) {
widgets.setProperty(count, d->engine->wrap(widget));
widgets.setProperty(count, engine()->wrap(widget));
++count;
}
}
......
......@@ -81,7 +81,7 @@ QString ScriptEngine::errorString() const
QJSValue ScriptEngine::wrap(Plasma::Applet *w)
{
Widget *wrapper = new Widget(w);
Widget *wrapper = new Widget(w, this);
return newQObject(wrapper);
}
......
......@@ -18,9 +18,11 @@
*/
#include "widget.h"
#include "scriptengine.h"
#include <QAction>
#include <QMetaEnum>
#include <QQuickItem>
#include <Plasma/Applet>
#include <Plasma/Containment>
......@@ -39,7 +41,7 @@ public:
QPointer<Plasma::Applet> applet;
};
Widget::Widget(Plasma::Applet *applet, QObject *parent)
Widget::Widget(Plasma::Applet *applet, ScriptEngine *parent)
: Applet(parent),
d(new Widget::Private)
{
......@@ -151,10 +153,18 @@ void Widget::setIndex(int index)
QJSValue Widget::geometry() const
{
/*if (d->applet) {
return d->applet.data()->geometry();
QQuickItem *appletItem = d->applet.data()->property("_plasma_graphicObject").value<QQuickItem *>();
if (appletItem) {
QJSValue rect = engine()->newObject();
const QPointF pos = appletItem->mapToScene(QPointF(0,0));
rect.setProperty(QStringLiteral("x"), pos.x());
rect.setProperty(QStringLiteral("y"), pos.y());
rect.setProperty(QStringLiteral("width"), appletItem->width());
rect.setProperty(QStringLiteral("height"), appletItem->height());
return rect;
}
*/
return QJSValue();
}
......
......@@ -52,7 +52,7 @@ class Widget : public Applet
Q_PROPERTY(QString userBackgroundHints WRITE setUserBackgroundHints READ userBackgroundHints)
public:
explicit Widget(Plasma::Applet *applet, QObject *parent = nullptr);
explicit Widget(Plasma::Applet *applet, ScriptEngine *parent = nullptr);
~Widget() override;
uint id() const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment