From 35819dc7641067540cafc448632af5603dd887aa Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Fri, 13 Mar 2015 12:51:09 +0100 Subject: QFileIconEngine: Use closest area when resolving the actual size This is similar to what QPixmapIconEngine does. Change-Id: I00b9e4083fa03fa0602b8e363055a612791bd149 Task-number: QTBUG-44981 Reviewed-by: Shawn Rutledge Reviewed-by: Friedemann Kleint --- src/widgets/itemviews/qfileiconprovider.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/itemviews/qfileiconprovider.cpp b/src/widgets/itemviews/qfileiconprovider.cpp index 50ca733991..1cc3a2a905 100644 --- a/src/widgets/itemviews/qfileiconprovider.cpp +++ b/src/widgets/itemviews/qfileiconprovider.cpp @@ -126,15 +126,29 @@ public: QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state) Q_DECL_OVERRIDE { const QList &sizes = availableSizes(mode, state); - if (sizes.isEmpty()) + const int numberSizes = sizes.length(); + if (numberSizes == 0) return QSize(); - foreach (const QSize &availableSize, sizes) { - if (availableSize.width() >= size.width()) - return availableSize; + // Find the smallest available size whose area is still larger than the input + // size. Otherwise, use the largest area available size. (We don't assume the + // platform theme sizes are sorted, hence the extra logic.) + const int sizeArea = size.width() * size.height(); + QSize actualSize = sizes.first(); + int actualArea = actualSize.width() * actualSize.height(); + for (int i = 1; i < numberSizes; ++i) { + const QSize &s = sizes.at(i); + const int a = s.width() * s.height(); + if ((sizeArea <= a && a < actualArea) || (actualArea < sizeArea && actualArea < a)) { + actualSize = s; + actualArea = a; + } } - return sizes.last(); + if (!actualSize.isNull() && (actualSize.width() > size.width() || actualSize.height() > size.height())) + actualSize.scale(size, Qt::KeepAspectRatio); + + return actualSize; } private: -- cgit v1.2.3