Ignore:
Timestamp:
Oct 28, 2009, 8:20:57 PM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

gui: QIcon: Be in line with the documentation and prefer the largest pixmap among smaller ones (instead of the smallest among larger) when searching for the best match for the given icon size in the pixmap icon engine [vendor bug].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gui/image/qicon.cpp

    r2 r261  
    188188
    189189// returns the smallest of the two that is still larger than or equal to size.
    190 static QPixmapIconEngineEntry *bestSizeMatch( const QSize &size, QPixmapIconEngineEntry *pa, QPixmapIconEngineEntry *pb)
     190
     191// According to the QIcon documentation, actualSize() and pixmap() may return
     192// icons that are smaller than the requested size but never larger. If we only
     193// have a larger icon, the engine will smooth scale it to the requested size.
     194// Given that, we should prefer the largerst pixmap that is smaller or equal to
     195// the requested size (i.e. the most close one from the group of smaller
     196// pixmaps), and if there are no such pixmaps, we return the smallest one
     197// from the larger group. This function just does that.
     198static QPixmapIconEngineEntry *bestSizeMatch(const QSize &size, QPixmapIconEngineEntry *pa, QPixmapIconEngineEntry *pb)
    191199{
    192200    int s = area(size);
     
    201209    }
    202210    int b = area(pb->size);
    203     int res = a;
    204     if (qMin(a,b) >= s)
     211
     212    // prefer the largest among smaller
     213    int res = qMax(a,b);
     214    if (res > s) {
     215        // fallback to the smallest among larger
    205216        res = qMin(a,b);
    206     else
    207         res = qMax(a,b);
     217   
     218
    208219    if (res == a)
    209220        return pa;
     
    347358        return actualSize;
    348359
    349     if (!actualSize.isNull() && (actualSize.width() > size.width() || actualSize.height() > size.height()))
     360    if ())
    350361        actualSize.scale(size, Qt::KeepAspectRatio);
    351362    return actualSize;
Note: See TracChangeset for help on using the changeset viewer.