ToolBox bindings for declarative containments

This adds the necessary bits, actions handling, showing / hiding of
toolbox and a hooks for config interface and add widgets.

The interesting bits:

Toolbox separate on the scene

For declarative containments, we add a declarativewidget on top of the
view which loads the "org.kde.toolbox" package. The toolbox can differ
per platform, layout of toolbox and containment can not "leak" into each
other.

ToolBox import

The most important and interesting bit is the list of actions the
ToolBox exposes, it's collected from corona, containment. The latter is
actually problematic, since we don't get access to the actions
internally provided by Containment
(ContainmentPrivate::addDefaultActions).
Containment::setToolBox(AbstractToolBox) being protected, we cannot
register our declarative ToolBoxProxy implementation to the containment,
so we have to wire up settings and addwidgets separately. Sorting of the
actions is "random", and expected to be done by the QML toolbox
implementation, based on objectName strings.

REVIEW:107232
This commit is contained in:
Sebastian Kügler 2012-11-07 17:21:26 +01:00
parent cdfd8688f4
commit d9612651cb
5 changed files with 50 additions and 3 deletions

View File

@ -12,6 +12,7 @@ set(simple_javascript_engine_SRCS
common/extension_io.cpp
common/guiscriptenv.cpp
common/javascriptaddonpackagestructure.cpp
declarative/toolboxproxy.cpp
declarative/appletcontainer.cpp
plasmoid/abstractjsappletscript.cpp
plasmoid/appletauthorization.cpp
@ -131,6 +132,7 @@ set(declarative_appletscript_SRCS
common/extension_io.cpp
common/javascriptaddonpackagestructure.cpp
common/declarativescriptenv.cpp
declarative/toolboxproxy.cpp
declarative/appletcontainer.cpp
declarative/declarativeitemcontainer.cpp
declarative/packageaccessmanager.cpp

View File

@ -20,7 +20,6 @@
*/
#include "appletinterface.h"
#include "../declarative/appletcontainer.h"
#include <QAction>
@ -596,7 +595,8 @@ void PopupAppletInterface::sourceAppletPopupEvent(bool show)
ContainmentInterface::ContainmentInterface(AbstractJsAppletScript *parent)
: APPLETSUPERCLASS(parent),
m_movableApplets(true)
m_movableApplets(true),
m_toolBox(0)
{
connect(containment(), SIGNAL(appletRemoved(Plasma::Applet *)), this, SLOT(appletRemovedForward(Plasma::Applet *)));
@ -613,7 +613,7 @@ ContainmentInterface::ContainmentInterface(AbstractJsAppletScript *parent)
}
qmlRegisterType<AppletContainer>("org.kde.plasma.containments", 0, 1, "AppletContainer");
qmlRegisterType<ToolBoxProxy>();
}
QScriptValue ContainmentInterface::applets()
@ -727,6 +727,15 @@ QString ContainmentInterface::activityId() const
return containment()->context()->currentActivityId();
}
ToolBoxProxy* ContainmentInterface::toolBox()
{
if (!m_toolBox) {
m_toolBox = new ToolBoxProxy(containment(), this);
//m_appletScriptEngine->setToolBox(m_toolBox); // setToolBox() is protected :/
}
return m_toolBox;
}
#ifndef USE_JS_SCRIPTENGINE
#include "appletinterface.moc"
#endif

View File

@ -35,6 +35,7 @@
#include <Plasma/ToolTipContent>
#include "abstractjsappletscript.h"
#include "../declarative/toolboxproxy.h"
class QAction;
class QmlAppletScript;
@ -417,6 +418,7 @@ class ContainmentInterface : public APPLETSUPERCLASS
Q_PROPERTY(bool movableApplets READ hasMovableApplets WRITE setMovableApplets)
Q_PROPERTY(QString activityName READ activityName NOTIFY activityNameChanged)
Q_PROPERTY(QString activityId READ activityId NOTIFY activityIdChanged)
Q_PROPERTY(ToolBoxProxy* toolBox READ toolBox CONSTANT)
Q_ENUMS(Type)
public:
@ -446,6 +448,8 @@ public:
QString activityName() const;
QString activityId() const;
ToolBoxProxy* toolBox();
Q_INVOKABLE QScriptValue screenGeometry(int id) const;
Q_INVOKABLE QScriptValue availableScreenRegion(int id) const;
@ -463,6 +467,7 @@ protected Q_SLOTS:
private:
bool m_movableApplets;
ToolBoxProxy* m_toolBox;
};
#endif

View File

@ -68,6 +68,8 @@ QScriptValue constructQPointClass(QScriptEngine *engine);
void registerSimpleAppletMetaTypes(QScriptEngine *engine);
DeclarativeAppletScript::DeclarativeAppletScript(QObject *parent, const QVariantList &args)
: AbstractJsAppletScript(parent, args),
m_declarativeWidget(0),
m_toolBoxWidget(0),
m_interface(0),
m_engine(0),
m_env(0),
@ -166,6 +168,34 @@ void DeclarativeAppletScript::qmlCreationFinished()
pa->setPopupIcon(a->icon());
}
}
Plasma::Containment *pc = qobject_cast<Plasma::Containment *>(a);
if (pc) {
Plasma::PackageStructure::Ptr structure = Plasma::PackageStructure::load("Plasma/Generic");
Plasma::Package pkg = Plasma::Package(QString(), "org.kde.toolbox", structure);
if (pkg.isValid()) {
const QString qmlPath = pkg.filePath("mainscript");
m_toolBoxWidget = new Plasma::DeclarativeWidget(pc);
m_toolBoxWidget->setInitializationDelayed(true);
m_toolBoxWidget->setQmlPath(qmlPath);
QGraphicsLinearLayout *toolBoxScreenLayout = new QGraphicsLinearLayout(m_declarativeWidget);
toolBoxScreenLayout->addItem(m_toolBoxWidget);
toolBoxScreenLayout->setContentsMargins(0, 0, 0, 0);
QScriptEngine *engine = m_toolBoxWidget->scriptEngine();
if (!engine) {
return;
}
QScriptValue global = engine->globalObject();
m_self = engine->newQObject(m_interface);
m_self.setScope(global);
global.setProperty("plasmoid", m_self);
} else {
kWarning() << "Could not load org.kde.toolbox package.";
}
}
}
void DeclarativeAppletScript::collectGarbage()

View File

@ -96,6 +96,7 @@ Q_SIGNALS:
private:
void callPlasmoidFunction(const QString &functionName, const QScriptValueList &args, ScriptEnv *env);
Plasma::DeclarativeWidget *m_declarativeWidget;
Plasma::DeclarativeWidget *m_toolBoxWidget;
AppletInterface *m_interface;
EngineAccess *m_engineAccess;
QScriptEngine *m_engine;