Mac/Retina: Fix target selector icon painting.

Task-number: QTCREATORBUG-10917
Change-Id: If151da45a83ce5b7ddf3166c16f8c63783f53f6a
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Eike Ziller
2013-11-27 16:53:25 +01:00
parent 4081317470
commit 54cb3aa251

View File

@@ -59,21 +59,42 @@
#include <QAction>
#include <QItemDelegate>
#if QT_VERSION >= 0x050100
#include <QGuiApplication>
#endif
static QIcon createCenteredIcon(const QIcon &icon, const QIcon &overlay)
{
QPixmap targetPixmap;
targetPixmap = QPixmap(Core::Constants::TARGET_ICON_SIZE, Core::Constants::TARGET_ICON_SIZE);
qreal appDevicePixelRatio = 1.0;
#if QT_VERSION >= 0x050100
appDevicePixelRatio = qApp->devicePixelRatio();
#endif
int deviceSpaceIconSize = Core::Constants::TARGET_ICON_SIZE * appDevicePixelRatio;
targetPixmap = QPixmap(deviceSpaceIconSize, deviceSpaceIconSize);
#if QT_VERSION >= 0x050100
targetPixmap.setDevicePixelRatio(appDevicePixelRatio);
#endif
targetPixmap.fill(Qt::transparent);
QPainter painter(&targetPixmap);
QPainter painter(&targetPixmap); // painter in user space
QPixmap pixmap = icon.pixmap(Core::Constants::TARGET_ICON_SIZE);
painter.drawPixmap((Core::Constants::TARGET_ICON_SIZE - pixmap.width())/2,
(Core::Constants::TARGET_ICON_SIZE - pixmap.height())/2, pixmap);
QPixmap pixmap = icon.pixmap(Core::Constants::TARGET_ICON_SIZE); // already takes app devicePixelRatio into account
qreal pixmapDevicePixelRatio = 1.0;
#if QT_VERSION >= 0x050100
pixmapDevicePixelRatio = pixmap.devicePixelRatio();
#endif
painter.drawPixmap((Core::Constants::TARGET_ICON_SIZE - pixmap.width() / pixmapDevicePixelRatio) / 2,
(Core::Constants::TARGET_ICON_SIZE - pixmap.height() / pixmapDevicePixelRatio) / 2, pixmap);
if (!overlay.isNull()) {
pixmap = overlay.pixmap(Core::Constants::TARGET_ICON_SIZE);
painter.drawPixmap((Core::Constants::TARGET_ICON_SIZE - pixmap.width())/2,
(Core::Constants::TARGET_ICON_SIZE - pixmap.height())/2, pixmap);
pixmap = overlay.pixmap(Core::Constants::TARGET_ICON_SIZE); // already takes app devicePixelRatio into account
pixmapDevicePixelRatio = 1.0;
#if QT_VERSION >= 0x050100
pixmapDevicePixelRatio = pixmap.devicePixelRatio();
#endif
painter.drawPixmap((Core::Constants::TARGET_ICON_SIZE - pixmap.width() / pixmapDevicePixelRatio) / 2,
(Core::Constants::TARGET_ICON_SIZE - pixmap.height() / pixmapDevicePixelRatio) / 2, pixmap);
}
return QIcon(targetPixmap);
}