Support high-dpi images.

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

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

Change-Id: I7b7f4c36ebd83d72ecdf6fbe0ae20e20ed6540bb
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
This commit is contained in:
Morten Johan Sørvig 2013-03-01 12:28:03 +01:00 committed by The Qt Project
parent 491dcbfac8
commit d616915b0a

View File

@ -355,7 +355,10 @@ void QStyledItemDelegate::initStyleOption(QStyleOptionViewItem *option,
else
mode = QIcon::Normal;
QIcon::State state = option->state & QStyle::State_Open ? QIcon::On : QIcon::Off;
option->decorationSize = option->icon.actualSize(option->decorationSize, mode, state);
QSize actualSize = option->icon.actualSize(option->decorationSize, mode, state);
// For highdpi icons actualSize might be larger than decorationSize, which we don't want. Clamp it to decorationSize.
option->decorationSize = QSize(qMin(option->decorationSize.width(), actualSize.width()),
qMin(option->decorationSize.height(), actualSize.height()));
break;
}
case QVariant::Color: {
@ -367,13 +370,13 @@ void QStyledItemDelegate::initStyleOption(QStyleOptionViewItem *option,
case QVariant::Image: {
QImage image = qvariant_cast<QImage>(value);
option->icon = QIcon(QPixmap::fromImage(image));
option->decorationSize = image.size();
option->decorationSize = image.size() / image.devicePixelRatio();
break;
}
case QVariant::Pixmap: {
QPixmap pixmap = qvariant_cast<QPixmap>(value);
option->icon = QIcon(pixmap);
option->decorationSize = pixmap.size();
option->decorationSize = pixmap.size() / pixmap.devicePixelRatio();
break;
}
default: