Force Plasma style for QQC2 in applets
Summary: using the qml url interceptor, rewrite imports in order to load always the plasma styled qqc2 controls in plasmoids and plasma views. As is per-engine, is possible to load controls with qstyle theme in configuration dialogs and plasma style in plasmoids. Note: this replaces just the style org.kde.desktop to Plasma and not every style (so with Material set as QT_QUICK_CONTROLS_STYLE environment variable plasma would load controls with material style) because we can control both org.kde.desktop and Plasma styles: they must have the same subdirectories as unlike files, their existence is checked before the rewrite (in our case, "private"), so in order to work they must exist in both styles Test Plan: a qqc2 button in a plasmoid has the plasma style, in a config dialog has the qwidget style. rewrite works only from org.kde.desktop to Plasma and not from other styles, due to the existence of the "private" subdirectory Reviewers: #plasma, davidedmundson Reviewed By: #plasma, davidedmundson Subscribers: davidedmundson, plasma-devel, #frameworks Tags: #plasma, #frameworks Differential Revision: https://phabricator.kde.org/D6964
This commit is contained in:
parent
a25b628e25
commit
ac24340877
@ -65,6 +65,7 @@ void AppletQuickItemPrivate::init()
|
||||
qmlObject = new KDeclarative::QmlObjectSharedEngine(q);
|
||||
if (!qmlObject->engine()->urlInterceptor()) {
|
||||
PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(qmlObject->engine(), KPackage::Package());
|
||||
interceptor->setForcePlasmaStyle(true);
|
||||
qmlObject->engine()->setUrlInterceptor(interceptor);
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
KPackage::Package package;
|
||||
QStringList allowedPaths;
|
||||
QQmlEngine *engine;
|
||||
bool forcePlasmaStyle = false;
|
||||
|
||||
//FIXME: those are going to be stuffed here and stay..
|
||||
// they should probably be removed when the last applet of that type is removed
|
||||
@ -81,9 +82,23 @@ QStringList PackageUrlInterceptor::allowedPaths() const
|
||||
return d->allowedPaths;
|
||||
}
|
||||
|
||||
bool PackageUrlInterceptor::forcePlasmaStyle() const
|
||||
{
|
||||
return d->forcePlasmaStyle;
|
||||
}
|
||||
|
||||
void PackageUrlInterceptor::setForcePlasmaStyle(bool force)
|
||||
{
|
||||
d->forcePlasmaStyle = force;
|
||||
}
|
||||
|
||||
QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlInterceptor::DataType type)
|
||||
{
|
||||
//qDebug() << "Intercepted URL:" << path << type;
|
||||
|
||||
if (d->forcePlasmaStyle && path.path().contains("Controls.2/org.kde.desktop/")) {
|
||||
return QUrl::fromLocalFile(path.path().replace(QLatin1String("Controls.2/org.kde.desktop/"), QLatin1String("Controls.2/Plasma/")));
|
||||
}
|
||||
QString pkgRoot;
|
||||
KPackage::Package package;
|
||||
if (d->package.isValid()) {
|
||||
|
@ -55,6 +55,9 @@ public:
|
||||
void removeAllowedPath(const QString &path);
|
||||
QStringList allowedPaths() const;
|
||||
|
||||
bool forcePlasmaStyle() const;
|
||||
void setForcePlasmaStyle(bool force);
|
||||
|
||||
QUrl intercept(const QUrl &path, QQmlAbstractUrlInterceptor::DataType type) Q_DECL_OVERRIDE;
|
||||
|
||||
static inline QByteArray prefixForType(QQmlAbstractUrlInterceptor::DataType type, const QString &fileName)
|
||||
|
@ -191,6 +191,7 @@ View::View(Plasma::Corona *corona, QWindow *parent)
|
||||
const auto pkg = corona->kPackage();
|
||||
if (pkg.isValid()) {
|
||||
PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(engine(), pkg);
|
||||
interceptor->setForcePlasmaStyle(true);
|
||||
engine()->setUrlInterceptor(interceptor);
|
||||
|
||||
KDeclarative::KDeclarative kdeclarative;
|
||||
|
Loading…
Reference in New Issue
Block a user