[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
This commit is contained in:
Martin Gräßlin 2014-03-03 13:42:13 +01:00
parent adf485c261
commit 869c087e21
2 changed files with 8 additions and 9 deletions

View file

@ -620,6 +620,7 @@ void KWin::Scripting::init()
qmlRegisterType<KWin::ScriptingClientModel::ClientFilterModel>("org.kde.kwin", 2, 0, "ClientFilterModel"); qmlRegisterType<KWin::ScriptingClientModel::ClientFilterModel>("org.kde.kwin", 2, 0, "ClientFilterModel");
qmlRegisterType<KWin::Client>(); qmlRegisterType<KWin::Client>();
qmlRegisterType<QQuickWindow>(); qmlRegisterType<QQuickWindow>();
qmlRegisterType<QAbstractItemModel>();
m_qmlEngine->rootContext()->setContextProperty(QStringLiteral("workspace"), m_workspaceWrapper); m_qmlEngine->rootContext()->setContextProperty(QStringLiteral("workspace"), m_workspaceWrapper);
m_qmlEngine->rootContext()->setContextProperty(QStringLiteral("options"), options); m_qmlEngine->rootContext()->setContextProperty(QStringLiteral("options"), options);

View file

@ -27,6 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "desktopmodel.h" #include "desktopmodel.h"
#include "tabboxconfig.h" #include "tabboxconfig.h"
#include "thumbnailitem.h" #include "thumbnailitem.h"
#include "scripting/scripting.h"
#include "switcheritem.h" #include "switcheritem.h"
// Qt // Qt
#include <QApplication> #include <QApplication>
@ -79,7 +80,7 @@ public:
TabBoxHandler *q; // public pointer TabBoxHandler *q; // public pointer
// members // members
TabBoxConfig config; TabBoxConfig config;
QScopedPointer<QQmlEngine> m_qmlEngine; QScopedPointer<QQmlContext> m_qmlContext;
QScopedPointer<QQmlComponent> m_qmlComponent; QScopedPointer<QQmlComponent> m_qmlComponent;
QObject *m_mainItem; QObject *m_mainItem;
QMap<QString, QObject*> m_clientTabBoxes; QMap<QString, QObject*> m_clientTabBoxes;
@ -103,7 +104,7 @@ private:
}; };
TabBoxHandlerPrivate::TabBoxHandlerPrivate(TabBoxHandler *q) TabBoxHandlerPrivate::TabBoxHandlerPrivate(TabBoxHandler *q)
: m_qmlEngine() : m_qmlContext()
, m_qmlComponent() , m_qmlComponent()
, m_mainItem(nullptr) , m_mainItem(nullptr)
, m_embedded(0) , m_embedded(0)
@ -275,7 +276,7 @@ QObject *TabBoxHandlerPrivate::createSwitcherItem(bool desktopMode)
"Contact your distribution about this.") << QStringLiteral("20"); "Contact your distribution about this.") << QStringLiteral("20");
KProcess::startDetached(QStringLiteral("kdialog"), args); KProcess::startDetached(QStringLiteral("kdialog"), args);
} else { } else {
QObject *object = m_qmlComponent->create(); QObject *object = m_qmlComponent->create(m_qmlContext.data());
if (desktopMode) { if (desktopMode) {
m_desktopTabBoxes.insert(config.layoutName(), object); m_desktopTabBoxes.insert(config.layoutName(), object);
} else { } else {
@ -288,15 +289,12 @@ QObject *TabBoxHandlerPrivate::createSwitcherItem(bool desktopMode)
void TabBoxHandlerPrivate::show() void TabBoxHandlerPrivate::show()
{ {
if (m_qmlEngine.isNull()) { if (m_qmlContext.isNull()) {
m_qmlEngine.reset(new QQmlEngine);
qmlRegisterType<SwitcherItem>("org.kde.kwin", 2, 0, "Switcher"); qmlRegisterType<SwitcherItem>("org.kde.kwin", 2, 0, "Switcher");
qmlRegisterType<DesktopThumbnailItem>("org.kde.kwin", 2, 0, "DesktopThumbnailItem"); m_qmlContext.reset(new QQmlContext(Scripting::self()->qmlEngine()));
qmlRegisterType<WindowThumbnailItem>("org.kde.kwin", 2, 0, "ThumbnailItem");
qmlRegisterType<QAbstractItemModel>();
} }
if (m_qmlComponent.isNull()) { 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); const bool desktopMode = (config.tabBoxMode() == TabBoxConfig::DesktopTabBox);
auto findMainItem = [this](const QMap<QString, QObject *> &tabBoxes) -> QObject* { auto findMainItem = [this](const QMap<QString, QObject *> &tabBoxes) -> QObject* {