diff options
author | Morten Johan Sørvig <morten.sorvig@digia.com> | 2015-04-14 20:01:15 +0200 |
---|---|---|
committer | Morten Johan Sørvig <morten.sorvig@digia.com> | 2015-04-15 12:54:15 +0200 |
commit | 7ec765b1d10d26de2e13cb22364e45427b654d86 (patch) | |
tree | b41a1ead7cd4bee427fd3b4f4b3a5e4a9ea47e99 /src/gui/painting | |
parent | 56b72d7809a6016149668b7df0dfd35022ff01c6 (diff) |
Use qreal for devicePixelRatio everywhere
QPaintDevice::devicePixelRatio() -> devicePixelRatioF()
Implement PdmDevicePixelRatioScaled for QPaintDevice subclasses.
Remove instances of casting to int.
Change-Id: I6e769d21e889bf8f88aedc1c49b53fef20a6709c
Diffstat (limited to 'src/gui/painting')
-rw-r--r-- | src/gui/painting/qbackingstore.cpp | 2 | ||||
-rw-r--r-- | src/gui/painting/qpaintdevice.h | 4 | ||||
-rw-r--r-- | src/gui/painting/qpainter.cpp | 8 | ||||
-rw-r--r-- | src/gui/painting/qpdf.cpp | 3 |
4 files changed, 10 insertions, 7 deletions
diff --git a/src/gui/painting/qbackingstore.cpp b/src/gui/painting/qbackingstore.cpp index f81dcd3cd8..d35814df0a 100644 --- a/src/gui/painting/qbackingstore.cpp +++ b/src/gui/painting/qbackingstore.cpp @@ -131,7 +131,7 @@ QPaintDevice *QBackingStore::paintDevice() || source->size() != d_ptr->highDpiBackingstore->size() || source->devicePixelRatio() != d_ptr->highDpiBackingstore->devicePixelRatio(); if (needsNewImage) { - qCDebug(lcScaling) << "QBackingStore::paintDevice new backingstore:"; + qCDebug(lcScaling) << "QBackingStore::paintDevice new backingstore for" << d_ptr->window; qCDebug(lcScaling) << " source size" << source->size() << "dpr" << source->devicePixelRatio(); d_ptr->highDpiBackingstore.reset( new QImage(source->bits(), source->width(), source->height(), source->format())); diff --git a/src/gui/painting/qpaintdevice.h b/src/gui/painting/qpaintdevice.h index 819116c585..c4ef9db766 100644 --- a/src/gui/painting/qpaintdevice.h +++ b/src/gui/painting/qpaintdevice.h @@ -81,8 +81,8 @@ public: int colorCount() const { return metric(PdmNumColors); } int depth() const { return metric(PdmDepth); } - // ### Classes that are not QPaintDevice subclasses are implementing metric() - // ### There needs to be some kind of (semi)-public API. + // ### Classes that are not QPaintDevice subclasses are implementing metric(), + // ### and need to access this constant. Add it here as a static constant for now static qreal devicePixelRatioFScale; protected: QPaintDevice(); diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 70862ea583..d3e8b542f0 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -223,14 +223,14 @@ qreal QPainterPrivate::effectiveDevicePixelRatio() const { // Special cases for devices that does not support PdmDevicePixelRatio go here: if (device->devType() == QInternal::Printer) - return 1; + return qreal(1); - return qMax(1, device->metric(QPaintDevice::PdmDevicePixelRatio)); + return qMax(qreal(1), device->devicePixelRatioF()); } QTransform QPainterPrivate::hidpiScaleTransform() const { - int devicePixelRatio = effectiveDevicePixelRatio(); + const qreal devicePixelRatio = effectiveDevicePixelRatio(); return QTransform::fromScale(devicePixelRatio, devicePixelRatio); } @@ -5110,7 +5110,7 @@ void QPainter::drawPixmap(const QPointF &p, const QPixmap &pm) x += d->state->matrix.dx(); y += d->state->matrix.dy(); } - int scale = pm.devicePixelRatio(); + qreal scale = pm.devicePixelRatio(); d->engine->drawPixmap(QRectF(x, y, w / scale, h / scale), pm, QRectF(0, 0, w, h)); } } diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index cc1ad02eee..ebb0e5f142 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -1502,6 +1502,9 @@ int QPdfEngine::metric(QPaintDevice::PaintDeviceMetric metricType) const case QPaintDevice::PdmDevicePixelRatio: val = 1; break; + case QPaintDevice::PdmDevicePixelRatioScaled: + val = 1 * QPaintDevice::devicePixelRatioFScale; + break; default: qWarning("QPdfWriter::metric: Invalid metric command"); return 0; |