Support high-dpi pixmaps.

When Qt::AA_UseHighDPIImages is set images and pixmaps
may be of the high-dpi type.

Account for this when calculating layout sizes by
dividing by devicePixelRatio() to go from device pixels
to device-independent pixels.

Change-Id: I977a86789f9097ebc3c3704ae76e9706f2cb79d8
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
This commit is contained in:
Morten Johan Sørvig 2013-03-01 12:29:35 +01:00 committed by The Qt Project
parent 4ecd6bc560
commit ebde672032

View File

@ -3336,9 +3336,9 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
QPixmap pixmap = header->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize), mode);
QRect pixr = header->rect;
pixr.setY(header->rect.center().y() - (pixmap.height() - 1) / 2);
pixr.setY(header->rect.center().y() - (pixmap.height() / pixmap.devicePixelRatio() - 1) / 2);
proxy()->drawItemPixmap(p, pixr, Qt::AlignVCenter, pixmap);
textr.translate(pixmap.width() + 2, 0);
textr.translate(pixmap.width() / pixmap.devicePixelRatio() + 2, 0);
}
p->setFont(qt_app_fonts_hash()->value("QSmallFont", QFont()));
@ -3392,15 +3392,15 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
if (tb->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
QMainWindow *mw = qobject_cast<QMainWindow *>(w->window());
if (mw && mw->unifiedTitleAndToolBarOnMac()) {
pr.setHeight(pixmap.size().height());
pr.setHeight(pixmap.size().height() / pixmap.devicePixelRatio());
cr.adjust(0, pr.bottom() + 1, 0, 1);
} else {
pr.setHeight(pixmap.size().height() + 6);
pr.setHeight(pixmap.size().height() / pixmap.devicePixelRatio() + 6);
cr.adjust(0, pr.bottom(), 0, -3);
}
alignment |= Qt::AlignCenter;
} else {
pr.setWidth(pixmap.width() + 8);
pr.setWidth(pixmap.width() / pixmap.devicePixelRatio() + 8);
cr.adjust(pr.right(), 0, 0, 0);
alignment |= Qt::AlignLeft | Qt::AlignVCenter;
}
@ -3638,10 +3638,12 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
if (btn->state & State_On)
state = QIcon::On;
QPixmap pixmap = btn->icon.pixmap(btn->iconSize, mode, state);
contentW += pixmap.width() + QMacStylePrivate::PushButtonContentPadding;
int pixmapWidth = pixmap.width() / pixmap.devicePixelRatio();
int pixmapHeight = pixmap.height() / pixmap.devicePixelRatio();
contentW += pixmapWidth + QMacStylePrivate::PushButtonContentPadding;
int iconLeftOffset = freeContentRect.x() + (freeContentRect.width() - contentW) / 2;
int iconTopOffset = freeContentRect.y() + (freeContentRect.height() - pixmap.height()) / 2;
QRect iconDestRect(iconLeftOffset, iconTopOffset, pixmap.width(), pixmap.height());
int iconTopOffset = freeContentRect.y() + (freeContentRect.height() - pixmapHeight) / 2;
QRect iconDestRect(iconLeftOffset, iconTopOffset, pixmapWidth, pixmapHeight);
QRect visualIconDestRect = visualRect(btn->direction, freeContentRect, iconDestRect);
proxy()->drawItemPixmap(p, visualIconDestRect, Qt::AlignLeft | Qt::AlignVCenter, pixmap);
int newOffset = iconDestRect.x() + iconDestRect.width()
@ -4070,8 +4072,8 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
iconSize = comboBox->iconSize();
}
QPixmap pixmap = mi->icon.pixmap(iconSize, mode);
int pixw = pixmap.width();
int pixh = pixmap.height();
int pixw = pixmap.width() / pixmap.devicePixelRatio();
int pixh = pixmap.height() / pixmap.devicePixelRatio();
QRect cr(xpos, contentRect.y(), checkcol, contentRect.height());
QRect pmr(0, 0, pixw, pixh);
pmr.moveCenter(cr.center());
@ -6353,6 +6355,7 @@ QIcon QMacStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption *o
QPixmap pixmap(QLatin1String(":/qt-project.org/styles/macstyle/images/toolbar-ext.png"));
if (standardIcon == SP_ToolBarVerticalExtensionButton) {
QPixmap pix2(pixmap.height(), pixmap.width());
pix2.setDevicePixelRatio(pixmap.devicePixelRatio());
pix2.fill(Qt::transparent);
QPainter p(&pix2);
p.translate(pix2.width(), 0);