[AppletQuickItem] Only set QtQuick Controls 1 style once per engine

The style is global per engine, there's no need to set it for every applet created
as the engines are shared.
Since this entire thing is just a hack, just setting a dynamic property to identify
that we've set a style is valid imho.
Also turn it into a plain QtObject since we don't need a fully-fledged Item.

Differential Revision: https://phabricator.kde.org/D4362
This commit is contained in:
Kai Uwe Broulik 2017-12-05 23:35:07 +01:00
parent 78f83f5c77
commit 3ad4798ca6

View File

@ -504,17 +504,20 @@ void AppletQuickItem::init()
//Force QtQuickControls to use the "Plasma" style for this engine.
//this way is possible to mix QtQuickControls and plasma components in applets
//while still having the desktop style in configuration dialogs
QQmlComponent c(engine);
c.setData(QByteArrayLiteral("import QtQuick 2.1\n\
import QtQuick.Controls 1.0\n\
import QtQuick.Controls.Private 1.0\n \
Item {\
Component.onCompleted: {\
Settings.styleName = \"Plasma\";\
}\
}"), QUrl());
QObject *o = c.create();
o->deleteLater();
if (!engine->property("_plasma_qqc_style_set").toBool()) {
QQmlComponent c(engine);
c.setData(QByteArrayLiteral("import QtQuick 2.1\n\
import QtQuick.Controls 1.0\n\
import QtQuick.Controls.Private 1.0\n \
QtObject {\
Component.onCompleted: {\
Settings.styleName = \"Plasma\";\
}\
}"), QUrl());
QObject *o = c.create();
o->deleteLater();
engine->setProperty(("_plasma_qqc_style_set"), true);
}
d->qmlObject->setSource(QUrl::fromLocalFile(d->applet->kPackage().filePath("mainscript")));