summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@digia.com>2013-03-01 12:28:51 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-28 14:42:15 +0100
commit4ecd6bc56072000f8eb51c39a4721408f6007aec (patch)
treed6f37086b6e6d1ca549f4a55fc4530b6a2480bf1 /src/widgets
parent8aed635640d0c6a41185a89551e5a4bd3c7e3b41 (diff)
Support high-dpi pixmaps and images.
When Qt::AA_UseHighDPIImages is set images and pixmaps may be of the high-dpi type. Account for this when calculating layout sizes dividing by devicePixelRatio() to go from device pixels to device-independent pixels. Change-Id: I8aa3d2ee947635ce2a49fff9e0029c9f55ae6c09 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/styles/qcommonstyle.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp
index 1af909a3cb..f7ae667a82 100644
--- a/src/widgets/styles/qcommonstyle.cpp
+++ b/src/widgets/styles/qcommonstyle.cpp
@@ -1115,6 +1115,8 @@ void QCommonStylePrivate::tabLayout(const QStyleOptionTabV3 *opt, const QWidget
QSize tabIconSize = opt->icon.actualSize(iconSize,
(opt->state & QStyle::State_Enabled) ? QIcon::Normal : QIcon::Disabled,
(opt->state & QStyle::State_Selected) ? QIcon::On : QIcon::Off );
+ // High-dpi icons do not need adjustmet; make sure tabIconSize is not larger than iconSize
+ tabIconSize = QSize(qMin(tabIconSize.width(), iconSize.width()), qMin(tabIconSize.height(), iconSize.width()));
*iconRect = QRect(tr.left(), tr.center().y() - tabIconSize.height() / 2,
tabIconSize.width(), tabIconSize .height());
@@ -1236,8 +1238,11 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
state = QIcon::On;
QPixmap pixmap = button->icon.pixmap(button->iconSize, mode, state);
- int labelWidth = pixmap.width();
- int labelHeight = pixmap.height();
+
+ int pixmapWidth = pixmap.width() / pixmap.devicePixelRatio();
+ int pixmapHeight = pixmap.height() / pixmap.devicePixelRatio();
+ int labelWidth = pixmapWidth;
+ int labelHeight = pixmapHeight;
int iconSpacing = 4;//### 4 is currently hardcoded in QPushButton::sizeHint()
int textWidth = button->fontMetrics.boundingRect(opt->rect, tf, button->text).width();
if (!button->text.isEmpty())
@@ -1245,7 +1250,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
iconRect = QRect(textRect.x() + (textRect.width() - labelWidth) / 2,
textRect.y() + (textRect.height() - labelHeight) / 2,
- pixmap.width(), pixmap.height());
+ pixmapWidth, pixmapHeight);
iconRect = visualRect(button->direction, textRect, iconRect);
@@ -1517,9 +1522,9 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
if (!header->icon.isNull()) {
QPixmap pixmap
= header->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize), (header->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled);
- int pixw = pixmap.width();
+ int pixw = pixmap.width() / pixmap.devicePixelRatio();
- QRect aligned = alignedRect(header->direction, QFlag(header->iconAlignment), pixmap.size(), rect);
+ QRect aligned = alignedRect(header->direction, QFlag(header->iconAlignment), pixmap.size() / pixmap.devicePixelRatio(), rect);
QRect inter = aligned.intersected(rect);
p->drawPixmap(inter.x(), inter.y(), pixmap, inter.x() - aligned.x(), inter.y() - aligned.y(), inter.width(), inter.height());
@@ -1574,7 +1579,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
mode = QIcon::Normal;
pm = toolbutton->icon.pixmap(toolbutton->rect.size().boundedTo(toolbutton->iconSize),
mode, state);
- pmSize = pm.size();
+ pmSize = pm.size() / pm.devicePixelRatio();
}
if (toolbutton->toolButtonStyle != Qt::ToolButtonIconOnly) {
@@ -1800,8 +1805,8 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
tr = cr;
tr.adjust(4, 0, -8, 0);
} else {
- int iw = pm.width() + 4;
- ih = pm.height();
+ int iw = pm.width() / pm.devicePixelRatio() + 4;
+ ih = pm.height()/ pm.devicePixelRatio();
ir = QRect(cr.left() + 4, cr.top(), iw + 2, ih);
tr = QRect(ir.right(), cr.top(), cr.width() - ir.right() - 4, cr.height());
}