summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Ehrlicher <[email protected]>2025-06-13 22:18:42 +0200
committerQt Cherry-pick Bot <[email protected]>2025-06-20 21:45:13 +0000
commit0cff18f1a3c5523a7f04a75713237796056b88e1 (patch)
treeb5aeb9d856fb068cd8688001fe766a4d32b472f8
parentd82a017a3e1b1399ebbaa15da55535bd698fbbea (diff)
QIconLoader: return an exact match for svg icon theme entry6.10
Fix an regression which was introduced with the fix for QTBUG-90634 - when a scalable svg entry or a threshold entry was found then return an exact match instead no match. This amends 7746c3ce6904d188046644ab7fafc64a8e4395d8 Task-number: QTBUG-90634 Fixes: QTBUG-137700 Pick-to: 6.9 Change-Id: I211b4a082ea8f9ec91157b02845fe272308f6a4f Reviewed-by: Volker Hilsheimer <[email protected]> (cherry picked from commit 46e7060ee8506c69d4e4f065f3b371bd89a24280) Reviewed-by: Qt Cherry-pick Bot <[email protected]>
-rw-r--r--src/gui/image/qiconloader.cpp37
1 files changed, 17 insertions, 20 deletions
diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp
index 7c5fbdc2d96..8e21c92f9b3 100644
--- a/src/gui/image/qiconloader.cpp
+++ b/src/gui/image/qiconloader.cpp
@@ -830,7 +830,7 @@ static bool directoryMatchesSizeAndScale(const QIconDirInfo &dir, int iconsize,
* This algorithm is a modification of the algorithm defined by the freedesktop spec:
* http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
*/
-static std::optional<int> directorySizeDelta(const QIconDirInfo &dir, int iconsize, int iconscale)
+static int directorySizeDelta(const QIconDirInfo &dir, int iconsize, int iconscale)
{
const auto scaledIconSize = iconsize * iconscale;
@@ -844,16 +844,16 @@ static std::optional<int> directorySizeDelta(const QIconDirInfo &dir, int iconsi
const auto maxScaled = dir.maxSize * dir.scale;
if (scaledIconSize > maxScaled)
return scaledIconSize - maxScaled;
- return {};
+ return 0;
}
case QIconDirInfo::Threshold:
if (scaledIconSize < (dir.size - dir.threshold) * dir.scale)
return dir.minSize * dir.scale - scaledIconSize;
if (scaledIconSize > (dir.size + dir.threshold) * dir.scale)
return scaledIconSize - dir.maxSize * dir.scale;
- return {};
+ return 0;
case QIconDirInfo::Fallback:
- return {};
+ return INT_MAX;
}
Q_ASSERT(1); // Not a valid value
@@ -880,22 +880,19 @@ QIconLoaderEngineEntry *QIconLoaderEngine::entryForSize(const QThemeIconInfo &in
return entry.get();
// Find the minimum distance icon
- const auto delta = directorySizeDelta(entry->dir, iconsize, scale);
- if (delta.has_value()) {
- const auto deltaValue = delta.value();
- // always prefer downscaled icons over upscaled icons
- if (deltaValue > minimalDelta && minimalDelta <= 0) {
- minimalDelta = deltaValue;
- closestMatch = entry.get();
- } else if (deltaValue > 0 && deltaValue < qAbs(minimalDelta)) {
- minimalDelta = deltaValue;
- closestMatch = entry.get();
- } else if (deltaValue == 0) {
- // exact match but different dpr:
- // --> size * scale == entry.size * entry.scale
- minimalDelta = deltaValue;
- closestMatch = entry.get();
- }
+ const auto deltaValue = directorySizeDelta(entry->dir, iconsize, scale);
+ // always prefer downscaled icons over upscaled icons
+ if (deltaValue > minimalDelta && minimalDelta <= 0) {
+ minimalDelta = deltaValue;
+ closestMatch = entry.get();
+ } else if (deltaValue > 0 && deltaValue < qAbs(minimalDelta)) {
+ minimalDelta = deltaValue;
+ closestMatch = entry.get();
+ } else if (deltaValue == 0) {
+ // exact match but different dpr:
+ // --> size * scale == entry.size * entry.scale
+ minimalDelta = deltaValue;
+ closestMatch = entry.get();
}
}
return closestMatch ? closestMatch : info.entries.at(0).get();