diff options
author | Morten Johan Sørvig <morten.sorvig@digia.com> | 2012-11-20 11:34:52 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-12-01 08:33:20 +0100 |
commit | 5e61bbe586519c3d9bc636153d32e810da4e59a3 (patch) | |
tree | 67d67ef644be72ee5b3d685c9a22538d7ec1e01d /src/widgets/styles/qmacstyle_mac.mm | |
parent | c8dc41bacdc30026cb79d0d6c72255312084bfe3 (diff) |
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/styles/qmacstyle_mac.mm')
-rw-r--r-- | src/widgets/styles/qmacstyle_mac.mm | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index 759b3678d7..89ea4d553a 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -462,7 +462,7 @@ class QMacCGContext { CGContextRef context; public: - QMacCGContext(QPainter *p); //qpaintengine_mac.cpp + QMacCGContext(QPainter *p); inline QMacCGContext() { context = 0; } inline QMacCGContext(const QPaintDevice *pdev) { extern CGContextRef qt_mac_cg_context(const QPaintDevice *); @@ -6476,6 +6476,18 @@ void qt_mac_clip_cg(CGContextRef hd, const QRegion &rgn, CGAffineTransform *orig } } +// move to QRegion? +void qt_mac_scale_region(QRegion *region, qreal scaleFactor) +{ + QVector<QRect> scaledRects; + scaledRects.reserve(region->rects().count()); + + foreach (const QRect &rect, region->rects()) { + scaledRects.append(QRect(rect.topLeft(), rect.size() * scaleFactor)); + } + region->setRects(&scaledRects[0], scaledRects.count()); +} + QMacCGContext::QMacCGContext(QPainter *p) { QPaintEngine *pe = p->paintEngine(); @@ -6502,20 +6514,28 @@ QMacCGContext::QMacCGContext(QPainter *p) CGContextScaleCTM(context, 1, -1); if (devType == QInternal::Widget) { - QRegion clip = p->paintEngine()->systemClip(); - QTransform native = p->deviceTransform(); + // Set the clip rect which is an intersection of the system clip + // and the painter clip. To make matters more interesting these + // are in device pixels and device-independent pixels, respectively. + const qreal devicePixelRatio = image->devicePixelRatio(); + + QRegion clip = p->paintEngine()->systemClip(); // get system clip in device pixels + QTransform native = p->deviceTransform(); // get device transform. dx/dy is in device pixels if (p->hasClipping()) { - QRegion r = p->clipRegion(); + QRegion r = p->clipRegion(); // get painter clip, which is in device-independent pixels + qt_mac_scale_region(&r, devicePixelRatio); // scale painter clip to device pixels r.translate(native.dx(), native.dy()); if (clip.isEmpty()) clip = r; else clip &= r; } - qt_mac_clip_cg(context, clip, 0); + qt_mac_clip_cg(context, clip, 0); // clip in device pixels - CGContextTranslateCTM(context, native.dx(), native.dy()); + // Scale the context so that painting happens in device-independet pixels. + CGContextScaleCTM(context, devicePixelRatio, devicePixelRatio); + CGContextTranslateCTM(context, native.dx() / devicePixelRatio, native.dy() / devicePixelRatio); } } else { qDebug() << "QMacCGContext:: Unsupported painter devtype type" << devType; |