Commit 54cb3aa2 authored by Eike Ziller's avatar Eike Ziller

Mac/Retina: Fix target selector icon painting.

Task-number: QTCREATORBUG-10917
Change-Id: If151da45a83ce5b7ddf3166c16f8c63783f53f6a
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 40813174
......@@ -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);
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);
QPainter painter(&targetPixmap); // painter in user space
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);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment