summaryrefslogtreecommitdiffstats
path: root/src/gui/image/qiconloader.cpp
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2018-08-16 15:42:41 +0200
committerAlbert Astals Cid <aacid@kde.org>2018-08-20 21:42:58 +0000
commit0e7724079f1eae283714ae12769d1372b8f85659 (patch)
treec07ae322b1b0012795be07c7ce485e63fc273ab0 /src/gui/image/qiconloader.cpp
parent67cc8fea106c35c7ca75bf476667d07b3bbf3257 (diff)
Allow setting the QIcon fallback theme
This allows apps that know their icons are in a given icon theme to set that theme as fallback, so in case the user theme does not include them, the icons can still be found. This solves the problem of missing icons that often happens when running KDE applications on a GNOME desktop. Change-Id: I4e5543d598012352a29ff79dab0357506d986b6d Reviewed-by: Dominik Haumann <dhaumann@kde.org> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/gui/image/qiconloader.cpp')
-rw-r--r--src/gui/image/qiconloader.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp
index 1ea4f1340b..228de3adc3 100644
--- a/src/gui/image/qiconloader.cpp
+++ b/src/gui/image/qiconloader.cpp
@@ -60,7 +60,7 @@ QT_BEGIN_NAMESPACE
Q_GLOBAL_STATIC(QIconLoader, iconLoaderInstance)
/* Theme to use in last resort, if the theme does not have the icon, neither the parents */
-static QString fallbackTheme()
+static QString systemFallbackThemeName()
{
if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
const QVariant themeHint = theme->themeHint(QPlatformTheme::SystemIconFallbackThemeName);
@@ -117,7 +117,7 @@ void QIconLoader::ensureInitialized()
m_systemTheme = systemThemeName();
if (m_systemTheme.isEmpty())
- m_systemTheme = fallbackTheme();
+ m_systemTheme = systemFallbackThemeName();
if (qt_iconEngineFactoryLoader()->keyMap().key(QLatin1String("svg"), -1) != -1)
m_supportsSvg = true;
}
@@ -137,7 +137,7 @@ void QIconLoader::updateSystemTheme()
if (m_userTheme.isEmpty()) {
QString theme = systemThemeName();
if (theme.isEmpty())
- theme = fallbackTheme();
+ theme = fallbackThemeName();
if (theme != m_systemTheme) {
m_systemTheme = theme;
invalidateKey();
@@ -151,6 +151,16 @@ void QIconLoader::setThemeName(const QString &themeName)
invalidateKey();
}
+QString QIconLoader::fallbackThemeName() const
+{
+ return m_userFallbackTheme.isEmpty() ? systemFallbackThemeName() : m_userFallbackTheme;
+}
+
+void QIconLoader::setFallbackThemeName(const QString &themeName)
+{
+ m_userFallbackTheme = themeName;
+}
+
void QIconLoader::setThemeSearchPath(const QStringList &searchPaths)
{
m_iconDirs = searchPaths;
@@ -388,7 +398,7 @@ QIconTheme::QIconTheme(const QString &themeName)
// Ensure a default platform fallback for all themes
if (m_parents.isEmpty()) {
- const QString fallback = fallbackTheme();
+ const QString fallback = QIconLoader::instance()->fallbackThemeName();
if (!fallback.isEmpty())
m_parents.append(fallback);
}
@@ -414,7 +424,7 @@ QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName,
if (!theme.isValid()) {
theme = QIconTheme(themeName);
if (!theme.isValid())
- theme = QIconTheme(fallbackTheme());
+ theme = QIconTheme(fallbackThemeName());
}
const QStringList contentDirs = theme.contentDirs();