Changeset 264


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

gui: QPixmap: Don't scale small pixmaps to fit the system icon size when creating icons (e.g. 16x16 -> 20x20) but instead center them in a system sized rectangle to avoid ugly distortions happening when scaling such small images.

File:
1 edited

Legend:

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

    r262 r264  
    4747#include "qicon.h"
    4848#include "qbitmap.h"
     49#include "qpainter.h"
    4950
    5051#include "qt_os2.h"
     
    230231        return NULLHANDLE;
    231232
     233    // get the system icon size
    232234    int w = WinQuerySysValue(HWND_DESKTOP, isPointer ? SV_CXPOINTER : SV_CXICON);
    233235    int h = WinQuerySysValue(HWND_DESKTOP, isPointer ? SV_CYPOINTER : SV_CYICON);
     236    int w2 = w / 2;
     237    int h2 = h / 2;
     238
     239    // obtain the closest (but never larger) icon sizes we have
    234240    QSize size = icon.actualSize(QSize(w, h));
    235     QSize sizeMini = icon.actualSize(QSize(w / 2, h / 2));
     241    QSize sizeMini = icon.actualSize(QSize(w2, h2));
    236242
    237243    QPixmap pm = icon.pixmap(size);
     
    239245    if (pm.isNull() && pmMini.isNull())
    240246        return NULLHANDLE;
     247
     248    // if we got smaller pixmaps then center them inside the system sized rect
     249    // instead of letting WinCreatePointerIndirect() scale them (this covers a
     250    // usual case when we got 32 and 16 px pixmaps on a 120 DPI system where the
     251    // icon size is 40 and 20 px respectively): scaling such small images looks
     252    // really ugly.
     253    if (!pm.isNull() && (pm.width() < w || pm.height() < h)) {
     254        Q_ASSERT(pm.width() <= w && pm.height() <= h);
     255        QPixmap pmNew(w, h);
     256        pmNew.fill(Qt::transparent);
     257        QPainter painter(&pmNew);
     258        painter.drawPixmap((w - pm.width()) / 2, (h - pm.height()) / 2, pm);
     259        pm = pmNew;
     260    }
     261    if (!pmMini.isNull() && (pmMini.width() < w2 || pmMini.height() < h2)) {
     262        Q_ASSERT(pmMini.width() <= w2 && pmMini.height() <= h2);
     263        QPixmap pmNew(w2, h2);
     264        pmNew.fill(Qt::transparent);
     265        QPainter painter(&pmNew);
     266        painter.drawPixmap((w2 - pmMini.width()) / 2, (h2 - pmMini.height()) / 2, pmMini);
     267        pmMini = pmNew;
     268    }
    241269
    242270    if (pm.isNull()) {
Note: See TracChangeset for help on using the changeset viewer.