diff options
author | Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com> | 2015-03-13 12:51:09 +0100 |
---|---|---|
committer | Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com> | 2015-03-14 00:50:43 +0000 |
commit | 35819dc7641067540cafc448632af5603dd887aa (patch) | |
tree | be6edc37bd0d0d64365c18aab12e829c27a7a225 /src/widgets | |
parent | d09f81864e989b739d504e97bfc6b4a367bdfb22 (diff) |
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 <shawn.rutledge@digia.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/itemviews/qfileiconprovider.cpp | 24 |
1 files changed, 19 insertions, 5 deletions
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<QSize> &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: |