diff options
-rw-r--r-- | src/gui/image/qicon.cpp | 33 | ||||
-rw-r--r-- | src/gui/image/qicon.h | 3 | ||||
-rw-r--r-- | src/gui/image/qiconloader.cpp | 20 | ||||
-rw-r--r-- | src/gui/image/qiconloader_p.h | 3 |
4 files changed, 53 insertions, 6 deletions
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 32fa9e75ac..14a0248600 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -1194,7 +1194,7 @@ void QIcon::setFallbackSearchPaths(const QStringList &paths) The \a name should correspond to a directory name in the themeSearchPath() containing an index.theme - file describing it's contents. + file describing its contents. \sa themeSearchPaths(), themeName() */ @@ -1220,6 +1220,37 @@ QString QIcon::themeName() } /*! + \since 5.12 + + Returns the name of the fallback icon theme. + + On X11, if not set, the fallback icon theme depends on your desktop + settings. On other platforms it is not set by default. + + \sa setFallbackThemeName(), themeName() +*/ +QString QIcon::fallbackThemeName() +{ + return QIconLoader::instance()->fallbackThemeName(); +} + +/*! + \since 5.12 + + Sets the fallback icon theme to \a name. + + The \a name should correspond to a directory name in the + themeSearchPath() containing an index.theme + file describing its contents. + + \sa fallbackThemeName(), themeSearchPaths(), themeName() +*/ +void QIcon::setFallbackThemeName(const QString &name) +{ + QIconLoader::instance()->setFallbackThemeName(name); +} + +/*! \since 4.6 Returns the QIcon corresponding to \a name in the current diff --git a/src/gui/image/qicon.h b/src/gui/image/qicon.h index 653ba6fda4..6a4fc8927a 100644 --- a/src/gui/image/qicon.h +++ b/src/gui/image/qicon.h @@ -124,6 +124,9 @@ public: static QString themeName(); static void setThemeName(const QString &path); + static QString fallbackThemeName(); + static void setFallbackThemeName(const QString &name); + Q_DUMMY_COMPARISON_OPERATOR(QIcon) private: 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(); diff --git a/src/gui/image/qiconloader_p.h b/src/gui/image/qiconloader_p.h index 746e871fb1..fac18b5d79 100644 --- a/src/gui/image/qiconloader_p.h +++ b/src/gui/image/qiconloader_p.h @@ -177,6 +177,8 @@ public: QString themeName() const { return m_userTheme.isEmpty() ? m_systemTheme : m_userTheme; } void setThemeName(const QString &themeName); + QString fallbackThemeName() const; + void setFallbackThemeName(const QString &themeName); QIconTheme theme() { return themeList.value(themeName()); } void setThemeSearchPath(const QStringList &searchPaths); QStringList themeSearchPaths() const; @@ -200,6 +202,7 @@ private: bool m_initialized; mutable QString m_userTheme; + mutable QString m_userFallbackTheme; mutable QString m_systemTheme; mutable QStringList m_iconDirs; mutable QHash <QString, QIconTheme> themeList; |