From 869c087e213cbf33c1a51f2d70b08f338a48aa0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 3 Mar 2014 13:42:13 +0100 Subject: [PATCH] [kwin] Use QQmlEngine from Scripting in TabBox Instead of having it's own QQmlEngine TabBox just uses the newly exposed engine from Scripting and creates a new context for it's own usage. REVIEW: 116565 --- scripting/scripting.cpp | 1 + tabbox/tabboxhandler.cpp | 16 +++++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/scripting/scripting.cpp b/scripting/scripting.cpp index 76150980fe..f6af34754d 100644 --- a/scripting/scripting.cpp +++ b/scripting/scripting.cpp @@ -620,6 +620,7 @@ void KWin::Scripting::init() qmlRegisterType("org.kde.kwin", 2, 0, "ClientFilterModel"); qmlRegisterType(); qmlRegisterType(); + qmlRegisterType(); m_qmlEngine->rootContext()->setContextProperty(QStringLiteral("workspace"), m_workspaceWrapper); m_qmlEngine->rootContext()->setContextProperty(QStringLiteral("options"), options); diff --git a/tabbox/tabboxhandler.cpp b/tabbox/tabboxhandler.cpp index 6542374893..c712a6b369 100644 --- a/tabbox/tabboxhandler.cpp +++ b/tabbox/tabboxhandler.cpp @@ -27,6 +27,7 @@ along with this program. If not, see . #include "desktopmodel.h" #include "tabboxconfig.h" #include "thumbnailitem.h" +#include "scripting/scripting.h" #include "switcheritem.h" // Qt #include @@ -79,7 +80,7 @@ public: TabBoxHandler *q; // public pointer // members TabBoxConfig config; - QScopedPointer m_qmlEngine; + QScopedPointer m_qmlContext; QScopedPointer m_qmlComponent; QObject *m_mainItem; QMap m_clientTabBoxes; @@ -103,7 +104,7 @@ private: }; TabBoxHandlerPrivate::TabBoxHandlerPrivate(TabBoxHandler *q) - : m_qmlEngine() + : m_qmlContext() , m_qmlComponent() , m_mainItem(nullptr) , m_embedded(0) @@ -275,7 +276,7 @@ QObject *TabBoxHandlerPrivate::createSwitcherItem(bool desktopMode) "Contact your distribution about this.") << QStringLiteral("20"); KProcess::startDetached(QStringLiteral("kdialog"), args); } else { - QObject *object = m_qmlComponent->create(); + QObject *object = m_qmlComponent->create(m_qmlContext.data()); if (desktopMode) { m_desktopTabBoxes.insert(config.layoutName(), object); } else { @@ -288,15 +289,12 @@ QObject *TabBoxHandlerPrivate::createSwitcherItem(bool desktopMode) void TabBoxHandlerPrivate::show() { - if (m_qmlEngine.isNull()) { - m_qmlEngine.reset(new QQmlEngine); + if (m_qmlContext.isNull()) { qmlRegisterType("org.kde.kwin", 2, 0, "Switcher"); - qmlRegisterType("org.kde.kwin", 2, 0, "DesktopThumbnailItem"); - qmlRegisterType("org.kde.kwin", 2, 0, "ThumbnailItem"); - qmlRegisterType(); + m_qmlContext.reset(new QQmlContext(Scripting::self()->qmlEngine())); } if (m_qmlComponent.isNull()) { - m_qmlComponent.reset(new QQmlComponent(m_qmlEngine.data())); + m_qmlComponent.reset(new QQmlComponent(Scripting::self()->qmlEngine())); } const bool desktopMode = (config.tabBoxMode() == TabBoxConfig::DesktopTabBox); auto findMainItem = [this](const QMap &tabBoxes) -> QObject* {