summaryrefslogtreecommitdiff
path: root/src/widgets/kernel/qwidget.cpp
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@digia.com>2012-11-20 11:34:52 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-12-01 08:33:20 +0100
commit5e61bbe586519c3d9bc636153d32e810da4e59a3 (patch)
tree67d67ef644be72ee5b3d685c9a22538d7ec1e01d /src/widgets/kernel/qwidget.cpp
parentc8dc41bacdc30026cb79d0d6c72255312084bfe3 (diff)
downloadqtbase-5e61bbe586519c3d9bc636153d32e810da4e59a3.tar.gz
Basic high-dpi "retina" support for Qt 5.
Bring Qt 5 on par with Qt 4, prepare for more comprehensive support later on. Introduce device independent pixels (dips), device pixels, and devicePixelRatio. Add high-dpi support to QPainter, QGLWidget, the cocoa platform plugin, mac and fusion styles. Dips are similar to CSS pixels, Apple points and Android density-independent pixels. Device pixels are pixels in the backing store/physical pixels on screen. devicePixelRatio is the ratio between them, which is 1.0 on standard displays and 2.0 on "retina" displays. New API: QImage::devicePixelRatio() and setDevicePixelRatio() QPixmap::devicePixelRatio() and setDevicePixelRatio() QWindow::devicePixelRatio() QScreen::devicePixelRatio() QGuiApplicaiton::devicePixelRatio() Change-Id: If98c3ca9bfdf0e1bdbcf7574cd5b912c9ff63856 Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com> Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Diffstat (limited to 'src/widgets/kernel/qwidget.cpp')
-rw-r--r--src/widgets/kernel/qwidget.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index e167e646c0..ace25fa78b 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -1794,6 +1794,23 @@ QRegion QWidgetPrivate::clipRegion() const
return r;
}
+void QWidgetPrivate::setSystemClip(QPaintDevice *paintDevice, const QRegion &region)
+{
+// Transform the system clip region from device-independent pixels to device pixels
+// Qt 5.0.0: This is a Mac-only code path for now, can be made cross-platform once
+// it has been tested.
+ QPaintEngine *paintEngine = paintDevice->paintEngine();
+#ifdef Q_OS_MAC
+ const qreal devicePixelRatio = (paintDevice->physicalDpiX() == 0 || paintDevice->logicalDpiX() == 0) ?
+ 1.0 : (paintDevice->physicalDpiX() / paintDevice->logicalDpiX());
+ QTransform scaleTransform;
+ scaleTransform.scale(devicePixelRatio, devicePixelRatio);
+ paintEngine->d_func()->systemClip = scaleTransform.map(region);
+#else
+ paintEngine->d_func()->systemClip = region;
+#endif
+}
+
#ifndef QT_NO_GRAPHICSEFFECT
void QWidgetPrivate::invalidateGraphicsEffectsRecursively()
{
@@ -4998,13 +5015,12 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP
QWidgetPaintContext context(pdev, rgn, offset, flags, sharedPainter, backingStore);
sourced->context = &context;
if (!sharedPainter) {
- QPaintEngine *paintEngine = pdev->paintEngine();
- paintEngine->d_func()->systemClip = rgn.translated(offset);
+ setSystemClip(pdev, rgn.translated(offset));
QPainter p(pdev);
p.translate(offset);
context.painter = &p;
graphicsEffect->draw(&p);
- paintEngine->d_func()->systemClip = QRegion();
+ setSystemClip(pdev, QRegion());
} else {
context.painter = sharedPainter;
if (sharedPainter->worldTransform() != sourced->lastEffectTransform) {
@@ -5061,7 +5077,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP
#endif
if (sharedPainter)
- paintEngine->d_func()->systemClip = toBePainted;
+ setSystemClip(pdev, toBePainted);
else
paintEngine->d_func()->systemRect = q->data->crect;
@@ -5073,7 +5089,7 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP
}
if (!sharedPainter)
- paintEngine->d_func()->systemClip = toBePainted.translated(offset);
+ setSystemClip(pdev, toBePainted.translated(offset));
if (!onScreen && !asRoot && !isOpaque && q->testAttribute(Qt::WA_TintedBackground)) {
QPainter p(q);
@@ -5108,7 +5124,8 @@ void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QP
paintEngine->d_func()->systemRect = QRect();
else
paintEngine->d_func()->currentClipDevice = 0;
- paintEngine->d_func()->systemClip = QRegion();
+
+ setSystemClip(pdev, QRegion());
}
q->setAttribute(Qt::WA_WState_InPaintEvent, false);
if (q->paintingActive())