make the plasmoid object accessible

This commit is contained in:
Marco Martin 2013-02-04 20:28:41 +01:00
parent feec1a5b40
commit b4669ab783
6 changed files with 28 additions and 8 deletions

View File

@ -24,6 +24,8 @@
#include <QAction> #include <QAction>
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QQmlEngine>
#include <QQmlComponent>
#include <QScriptEngine> #include <QScriptEngine>
#include <QSignalMapper> #include <QSignalMapper>
#include <QTimer> #include <QTimer>
@ -46,6 +48,7 @@ AppletInterface::AppletInterface(AbstractJsAppletScript *parent)
m_appletScriptEngine(parent), m_appletScriptEngine(parent),
m_actionSignals(0) m_actionSignals(0)
{ {
qmlRegisterType<AppletInterface>();
connect(this, SIGNAL(releaseVisualFocus()), applet(), SIGNAL(releaseVisualFocus())); connect(this, SIGNAL(releaseVisualFocus()), applet(), SIGNAL(releaseVisualFocus()));
connect(this, SIGNAL(configNeedsSaving()), applet(), SIGNAL(configNeedsSaving())); connect(this, SIGNAL(configNeedsSaving()), applet(), SIGNAL(configNeedsSaving()));
connect(applet(), SIGNAL(immutabilityChanged(Plasma::ImmutabilityType)), this, SIGNAL(immutableChanged())); connect(applet(), SIGNAL(immutabilityChanged(Plasma::ImmutabilityType)), this, SIGNAL(immutableChanged()));
@ -388,6 +391,7 @@ ContainmentInterface::ContainmentInterface(AbstractJsAppletScript *parent)
: APPLETSUPERCLASS(parent), : APPLETSUPERCLASS(parent),
m_movableApplets(true) m_movableApplets(true)
{ {
qmlRegisterType<ContainmentInterface>();
connect(containment(), SIGNAL(appletRemoved(Plasma::Applet *)), this, SLOT(appletRemovedForward(Plasma::Applet *))); 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 &))); connect(containment(), SIGNAL(appletAdded(Plasma::Applet *, const QPointF &)), this, SLOT(appletAddedForward(Plasma::Applet *, const QPointF &)));

View File

@ -278,6 +278,8 @@ ScriptEnv *DeclarativeAppletScript::scriptEnv()
void DeclarativeAppletScript::setupObjects() void DeclarativeAppletScript::setupObjects()
{ {
m_qmlObject->engine()->rootContext()->setContextProperty("plasmoid", m_interface);
#if 0 #if 0
TODO: make this work with QQmlEngine TODO: make this work with QQmlEngine
m_engine = m_qmlObject->scriptEngine(); m_engine = m_qmlObject->scriptEngine();

View File

@ -53,9 +53,9 @@ void DesktopCorona::loadDefaultLayout()
Plasma::Containment *cont = addContainment("org.kde.testcontainment"); Plasma::Containment *cont = addContainment("org.kde.testcontainment");
cont->setScreen(0); cont->setScreen(0);
qDebug() << containmentForScreen(0); qDebug() << containmentForScreen(0);
//Plasma::Applet *appl = cont->addApplet("foo"); Plasma::Applet *appl = cont->addApplet("foo");
qDebug() << "Containment:" << cont << cont->name(); qDebug() << "Containment:" << cont << cont->name();
//qDebug() << "Applet:" << appl->name() << appl; qDebug() << "Applet:" << appl->name() << appl;
} }
void DesktopCorona::checkScreens(bool signalWhenExists) void DesktopCorona::checkScreens(bool signalWhenExists)

View File

@ -36,5 +36,7 @@ Rectangle {
containment.anchors.fill = root containment.anchors.fill = root
} }
Component.onCompleted: print("View QML loaded") Component.onCompleted: {
print("View QML loaded")
}
} }

View File

@ -55,10 +55,15 @@ Rectangle {
//Behavior on y { PropertyAnimation { easing.type: Easing.OutElastic; duration: 800 } } //Behavior on y { PropertyAnimation { easing.type: Easing.OutElastic; duration: 800 } }
Behavior on height { PropertyAnimation { easing.type: Easing.InOutDouble; duration: 300 } } Behavior on height { PropertyAnimation { easing.type: Easing.InOutDouble; duration: 300 } }
Text { Column {
id: txt
text: "Click or Drag";
anchors.centerIn: parent anchors.centerIn: parent
Text {
id: txt
text: "Click or Drag";
}
Text {
text: plasmoid
}
} }
PlasmaCore.SvgItem { PlasmaCore.SvgItem {
svg: actionssvg svg: actionssvg
@ -88,5 +93,11 @@ Rectangle {
Rectangle { color: "white"; opacity: 0.2; anchors.fill: parent; } Rectangle { color: "white"; opacity: 0.2; anchors.fill: parent; }
} }
Component.onCompleted: print("Test Containment loaded") Component.onCompleted: {
print("Test Containment loaded")
print(plasmoid)
for (var i in plasmoid) {
print(i+" "+plasmoid[i])
}
}
} }

View File

@ -20,6 +20,7 @@
#include <QDebug> #include <QDebug>
#include <QQuickItem> #include <QQuickItem>
#include <QQmlContext>
#include <QTimer> #include <QTimer>
#include "plasma/pluginloader.h" #include "plasma/pluginloader.h"
@ -35,7 +36,7 @@ View::View(QWindow *parent)
setResizeMode(View::SizeRootObjectToView); setResizeMode(View::SizeRootObjectToView);
setSource(QUrl::fromLocalFile(m_package.filePath("mainscript"))); setSource(QUrl::fromLocalFile(m_package.filePath("mainscript")));
show(); show();rootContext()->setContextProperty("plasmoid", this);
} }
View::~View() View::~View()