From 7d3eac6e33085ffa66ff72294fc079ffd5f25b02 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 12 Jun 2017 15:16:19 +0200 Subject: Try to pick a useful size if we don't have an exact match. The smallest is not always the best. --- applications/kube/main.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/applications/kube/main.cpp b/applications/kube/main.cpp index 03a128c4..ad7bac88 100644 --- a/applications/kube/main.cpp +++ b/applications/kube/main.cpp @@ -27,8 +27,18 @@ public: } const auto icon = QIcon::fromTheme(id); auto expectedSize = requestedSize; - if (!icon.availableSizes().contains(requestedSize) && !icon.availableSizes().isEmpty()) { - expectedSize = icon.availableSizes().first(); + //Get the largest size that is still smaller or equal than requested + //Except if we only have larger sizes, then just pick the closest one + bool first = true; + for (const auto s : icon.availableSizes()) { + if (first && s.width() > requestedSize.width()) { + expectedSize = s; + break; + } + first = false; + if (s.width() <= requestedSize.width()) { + expectedSize = s; + } } const auto pixmap = icon.pixmap(expectedSize); if (size) { -- cgit v1.2.3