7#include "styleselector.h"
12#include <kirigamiplatform_logging.h>
19QString StyleSelector::style()
21 if (qEnvironmentVariableIntValue(
"KIRIGAMI_FORCE_STYLE") == 1) {
24 return styleChain().first();
28QStringList StyleSelector::styleChain()
30 if (qEnvironmentVariableIntValue(
"KIRIGAMI_FORCE_STYLE") == 1) {
34 if (!s_styleChain.isEmpty()) {
40#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
42 if (style.isEmpty() || style == QStringLiteral(
"org.kde.desktop.plasma")) {
43 auto path = resolveFilePath(QStringLiteral(
"/styles/org.kde.desktop"));
45 s_styleChain.prepend(QStringLiteral(
"org.kde.desktop"));
48#elif defined(Q_OS_ANDROID)
49 s_styleChain.prepend(QStringLiteral(
"Material"));
51 s_styleChain.prepend(QStringLiteral(
"Material"));
54 auto stylePath = resolveFilePath(QStringLiteral(
"/styles/") + style);
55 if (!style.isEmpty() &&
QFile::exists(stylePath) && !s_styleChain.contains(style)) {
56 s_styleChain.prepend(style);
58 auto plasmaPath = resolveFilePath(QStringLiteral(
"/styles/org.kde.desktop.plasma"));
59 if (style == QStringLiteral(
"org.kde.desktop") &&
QFile::exists(plasmaPath)) {
60 s_styleChain.prepend(QStringLiteral(
"org.kde.desktop.plasma"));
63#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
64 s_styleChain.prepend(QStringLiteral(
"org.kde.desktop"));
71QUrl StyleSelector::componentUrl(
const QString &fileName)
73 const auto chain = styleChain();
74 for (
const QString &style : chain) {
75 const QString candidate = QStringLiteral(
"styles/") + style + QLatin1Char(
'/') + fileName;
77 return QUrl(resolveFileUrl(candidate));
82 qCWarning(KirigamiPlatform) <<
"Requested an unexisting component" << fileName;
84 return QUrl(resolveFileUrl(fileName));
87void StyleSelector::setBaseUrl(
const QUrl &baseUrl)
92QString StyleSelector::resolveFilePath(
const QString &path)
94#if defined(KIRIGAMI_BUILD_TYPE_STATIC) || defined(Q_OS_ANDROID)
95 return QStringLiteral(
":/qt/qml/org/kde/kirigami/") +
path;
97 if (s_baseUrl.isValid()) {
98 return s_baseUrl.toLocalFile() + QLatin1Char(
'/') +
path;
105QString StyleSelector::resolveFileUrl(
const QString &path)
107#if defined(KIRIGAMI_BUILD_TYPE_STATIC) || defined(Q_OS_ANDROID)
108 return QStringLiteral(
"qrc:/qt/qml/org/kde/kirigami/") +
path;
110 return s_baseUrl.toString() + QLatin1Char(
'/') +
path;
QString path(const QString &relativePath)
bool exists() const const