diff options
Diffstat (limited to 'src/gui/image')
-rw-r--r-- | src/gui/image/qicon.cpp | 4 | ||||
-rw-r--r-- | src/gui/image/qiconloader.cpp | 32 | ||||
-rw-r--r-- | src/gui/image/qiconloader_p.h | 2 |
3 files changed, 28 insertions, 10 deletions
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index bf6eb8d..fad51f4 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -982,7 +982,9 @@ QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback) icon = *cachedIcon; } - if (icon.availableSizes().isEmpty()) + // Note the qapp check is to allow lazy loading of static icons + // Supporting fallbacks will not work for this case. + if (qApp && icon.availableSizes().isEmpty()) return fallback; return icon; diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp index b35e80a..72ec2e8 100644 --- a/src/gui/image/qiconloader.cpp +++ b/src/gui/image/qiconloader.cpp @@ -85,19 +85,30 @@ static QString fallbackTheme() } QIconLoader::QIconLoader() : - m_themeKey(1), m_supportsSvg(false) + m_themeKey(1), m_supportsSvg(false), m_initialized(false) { - m_systemTheme = qt_guiPlatformPlugin()->systemIconThemeName(); - if (m_systemTheme.isEmpty()) - m_systemTheme = fallbackTheme(); +} + +// We lazily initialize the loader to make static icons +// work. Though we do not officially support this. +void QIconLoader::ensureInitialized() +{ + if (!m_initialized) { + m_initialized = true; + + Q_ASSERT(qApp); + m_systemTheme = qt_guiPlatformPlugin()->systemIconThemeName(); + if (m_systemTheme.isEmpty()) + m_systemTheme = fallbackTheme(); #ifndef QT_NO_LIBRARY - QFactoryLoader iconFactoryLoader(QIconEngineFactoryInterfaceV2_iid, - QLatin1String("/iconengines"), - Qt::CaseInsensitive); - if (iconFactoryLoader.keys().contains(QLatin1String("svg"))) - m_supportsSvg = true; + QFactoryLoader iconFactoryLoader(QIconEngineFactoryInterfaceV2_iid, + QLatin1String("/iconengines"), + Qt::CaseInsensitive); + if (iconFactoryLoader.keys().contains(QLatin1String("svg"))) + m_supportsSvg = true; #endif //QT_NO_LIBRARY + } } QIconLoader *QIconLoader::instance() @@ -339,6 +350,9 @@ bool QIconLoaderEngine::hasIcon() const // Lazily load the icon void QIconLoaderEngine::ensureLoaded() { + + iconLoaderInstance()->ensureInitialized(); + if (!(iconLoaderInstance()->themeKey() == m_key)) { while (!m_entries.isEmpty()) diff --git a/src/gui/image/qiconloader_p.h b/src/gui/image/qiconloader_p.h index 19f2dda..a6b5f5b 100644 --- a/src/gui/image/qiconloader_p.h +++ b/src/gui/image/qiconloader_p.h @@ -169,6 +169,7 @@ public: static QIconLoader *instance(); void updateSystemTheme(); void invalidateKey() { m_themeKey++; } + void ensureInitialized(); private: QThemeIconEntries findIconHelper(const QString &themeName, @@ -176,6 +177,7 @@ private: QStringList &visited) const; uint m_themeKey; bool m_supportsSvg; + bool m_initialized; mutable QString m_userTheme; mutable QString m_systemTheme; |