Make sure hicolor is searched before dash fallbacks
Search full icon name from hicolor before dash fallback Pick-to: 6.6 Fixes: QTBUG-121030 Change-Id: I3e3ee142c33466203639f32857fce3ea1946a9f7 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> (cherry picked from commit 0534a93ef04f38cf6dfc0d6c03827325d651a64c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
6affa9890d
commit
7b38b5e369
@ -441,7 +441,8 @@ QDebug operator<<(QDebug debug, const std::unique_ptr<QIconLoaderEngineEntry> &e
|
|||||||
|
|
||||||
QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName,
|
QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName,
|
||||||
const QString &iconName,
|
const QString &iconName,
|
||||||
QStringList &visited) const
|
QStringList &visited,
|
||||||
|
DashRule rule) const
|
||||||
{
|
{
|
||||||
qCDebug(lcIconLoader) << "Finding icon" << iconName << "in theme" << themeName
|
qCDebug(lcIconLoader) << "Finding icon" << iconName << "in theme" << themeName
|
||||||
<< "skipping" << visited;
|
<< "skipping" << visited;
|
||||||
@ -464,10 +465,10 @@ QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName,
|
|||||||
const QStringList contentDirs = theme.contentDirs();
|
const QStringList contentDirs = theme.contentDirs();
|
||||||
|
|
||||||
QStringView iconNameFallback(iconName);
|
QStringView iconNameFallback(iconName);
|
||||||
bool searchingGenericFallback = false;
|
bool searchingGenericFallback = m_iconName.length() > iconName.length();
|
||||||
|
|
||||||
// Iterate through all icon's fallbacks in current theme
|
// Iterate through all icon's fallbacks in current theme
|
||||||
while (info.entries.empty()) {
|
if (info.entries.empty()) {
|
||||||
const QString svgIconName = iconNameFallback + ".svg"_L1;
|
const QString svgIconName = iconNameFallback + ".svg"_L1;
|
||||||
const QString pngIconName = iconNameFallback + ".png"_L1;
|
const QString pngIconName = iconNameFallback + ".png"_L1;
|
||||||
|
|
||||||
@ -527,16 +528,7 @@ QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName,
|
|||||||
|
|
||||||
if (!info.entries.empty()) {
|
if (!info.entries.empty()) {
|
||||||
info.iconName = iconNameFallback.toString();
|
info.iconName = iconNameFallback.toString();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's possible - find next fallback for the icon
|
|
||||||
const int indexOfDash = iconNameFallback.lastIndexOf(u'-');
|
|
||||||
if (indexOfDash == -1)
|
|
||||||
break;
|
|
||||||
|
|
||||||
iconNameFallback.truncate(indexOfDash);
|
|
||||||
searchingGenericFallback = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.entries.empty()) {
|
if (info.entries.empty()) {
|
||||||
@ -551,13 +543,25 @@ QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName,
|
|||||||
const QString parentTheme = parents.at(i).trimmed();
|
const QString parentTheme = parents.at(i).trimmed();
|
||||||
|
|
||||||
if (!visited.contains(parentTheme)) // guard against recursion
|
if (!visited.contains(parentTheme)) // guard against recursion
|
||||||
info = findIconHelper(parentTheme, iconName, visited);
|
info = findIconHelper(parentTheme, iconName, visited, QIconLoader::NoFallBack);
|
||||||
|
|
||||||
if (!info.entries.empty()) // success
|
if (!info.entries.empty()) // success
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rule == QIconLoader::FallBack && info.entries.empty()) {
|
||||||
|
// If it's possible - find next fallback for the icon
|
||||||
|
const int indexOfDash = iconNameFallback.lastIndexOf(u'-');
|
||||||
|
if (indexOfDash != -1) {
|
||||||
|
qCDebug(lcIconLoader) << "Did not find matching icons in all themes;"
|
||||||
|
<< "trying dash fallback";
|
||||||
|
iconNameFallback.truncate(indexOfDash);
|
||||||
|
QStringList _visited;
|
||||||
|
info = findIconHelper(themeName, iconNameFallback.toString(), _visited, QIconLoader::FallBack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -605,13 +609,14 @@ QThemeIconInfo QIconLoader::loadIcon(const QString &name) const
|
|||||||
{
|
{
|
||||||
qCDebug(lcIconLoader) << "Loading icon" << name;
|
qCDebug(lcIconLoader) << "Loading icon" << name;
|
||||||
|
|
||||||
|
m_iconName = name;
|
||||||
QThemeIconInfo iconInfo;
|
QThemeIconInfo iconInfo;
|
||||||
QStringList visitedThemes;
|
QStringList visitedThemes;
|
||||||
if (!themeName().isEmpty())
|
if (!themeName().isEmpty())
|
||||||
iconInfo = findIconHelper(themeName(), name, visitedThemes);
|
iconInfo = findIconHelper(themeName(), name, visitedThemes, QIconLoader::FallBack);
|
||||||
|
|
||||||
if (iconInfo.entries.empty() && !fallbackThemeName().isEmpty())
|
if (iconInfo.entries.empty() && !fallbackThemeName().isEmpty())
|
||||||
iconInfo = findIconHelper(fallbackThemeName(), name, visitedThemes);
|
iconInfo = findIconHelper(fallbackThemeName(), name, visitedThemes, QIconLoader::FallBack);
|
||||||
|
|
||||||
if (iconInfo.entries.empty())
|
if (iconInfo.entries.empty())
|
||||||
iconInfo = lookupFallbackIcon(name);
|
iconInfo = lookupFallbackIcon(name);
|
||||||
|
@ -187,9 +187,11 @@ public:
|
|||||||
QIconEngine *iconEngine(const QString &iconName) const;
|
QIconEngine *iconEngine(const QString &iconName) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum DashRule { FallBack, NoFallBack };
|
||||||
QThemeIconInfo findIconHelper(const QString &themeName,
|
QThemeIconInfo findIconHelper(const QString &themeName,
|
||||||
const QString &iconName,
|
const QString &iconName,
|
||||||
QStringList &visited) const;
|
QStringList &visited,
|
||||||
|
DashRule rule) const;
|
||||||
QThemeIconInfo lookupFallbackIcon(const QString &iconName) const;
|
QThemeIconInfo lookupFallbackIcon(const QString &iconName) const;
|
||||||
|
|
||||||
uint m_themeKey;
|
uint m_themeKey;
|
||||||
@ -202,6 +204,7 @@ private:
|
|||||||
mutable QStringList m_iconDirs;
|
mutable QStringList m_iconDirs;
|
||||||
mutable QHash <QString, QIconTheme> themeList;
|
mutable QHash <QString, QIconTheme> themeList;
|
||||||
mutable QStringList m_fallbackDirs;
|
mutable QStringList m_fallbackDirs;
|
||||||
|
mutable QString m_iconName;
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user