summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@digia.com>2015-04-14 20:01:15 +0200
committerMorten Johan Sørvig <morten.sorvig@digia.com>2015-04-15 12:54:15 +0200
commit7ec765b1d10d26de2e13cb22364e45427b654d86 (patch)
treeb41a1ead7cd4bee427fd3b4f4b3a5e4a9ea47e99 /src/gui
parent56b72d7809a6016149668b7df0dfd35022ff01c6 (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')
-rw-r--r--src/gui/image/qpicture.cpp3
-rw-r--r--src/gui/kernel/qopenglwindow.cpp5
-rw-r--r--src/gui/kernel/qpaintdevicewindow.cpp6
-rw-r--r--src/gui/kernel/qrasterwindow.cpp2
-rw-r--r--src/gui/kernel/qwindow.cpp14
-rw-r--r--src/gui/painting/qbackingstore.cpp2
-rw-r--r--src/gui/painting/qpaintdevice.h4
-rw-r--r--src/gui/painting/qpainter.cpp8
-rw-r--r--src/gui/painting/qpdf.cpp3
-rw-r--r--src/gui/text/qstatictext.cpp3
-rw-r--r--src/gui/text/qtextimagehandler.cpp4
11 files changed, 31 insertions, 23 deletions
diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp
index b63be19153..02a510ce29 100644
--- a/src/gui/image/qpicture.cpp
+++ b/src/gui/image/qpicture.cpp
@@ -961,6 +961,9 @@ int QPicture::metric(PaintDeviceMetric m) const
case PdmDevicePixelRatio:
val = 1;
break;
+ case PdmDevicePixelRatioScaled:
+ val = 1 * QPaintDevice::devicePixelRatioFScale;
+ break;
default:
val = 0;
qWarning("QPicture::metric: Invalid metric command");
diff --git a/src/gui/kernel/qopenglwindow.cpp b/src/gui/kernel/qopenglwindow.cpp
index a7ba57e85e..2853f05ef3 100644
--- a/src/gui/kernel/qopenglwindow.cpp
+++ b/src/gui/kernel/qopenglwindow.cpp
@@ -646,15 +646,10 @@ int QOpenGLWindow::metric(PaintDeviceMetric metric) const
if (d->paintDevice)
return d->paintDevice->depth();
break;
- case PdmDevicePixelRatio:
- if (d->paintDevice)
- return devicePixelRatio();
- break;
default:
break;
}
return QPaintDeviceWindow::metric(metric);
-
}
/*!
diff --git a/src/gui/kernel/qpaintdevicewindow.cpp b/src/gui/kernel/qpaintdevicewindow.cpp
index b32ab3b34d..32f0aeb6d5 100644
--- a/src/gui/kernel/qpaintdevicewindow.cpp
+++ b/src/gui/kernel/qpaintdevicewindow.cpp
@@ -144,8 +144,10 @@ int QPaintDeviceWindow::metric(PaintDeviceMetric metric) const
return qRound(screen->physicalDotsPerInchY());
break;
case PdmDevicePixelRatio:
- if (screen)
- return screen->devicePixelRatio();
+ return int(QWindow::devicePixelRatio());
+ break;
+ case PdmDevicePixelRatioScaled:
+ return int(QWindow::devicePixelRatio() * devicePixelRatioFScale);
break;
default:
break;
diff --git a/src/gui/kernel/qrasterwindow.cpp b/src/gui/kernel/qrasterwindow.cpp
index c04eb71420..fc1739ca0e 100644
--- a/src/gui/kernel/qrasterwindow.cpp
+++ b/src/gui/kernel/qrasterwindow.cpp
@@ -108,8 +108,6 @@ int QRasterWindow::metric(PaintDeviceMetric metric) const
switch (metric) {
case PdmDepth:
return d->backingstore->paintDevice()->depth();
- case PdmDevicePixelRatio:
- return d->backingstore->paintDevice()->devicePixelRatio();
default:
break;
}
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index 6b74bd66ed..e376df24cb 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -1082,13 +1082,17 @@ qreal QWindow::devicePixelRatio() const
{
Q_D(const QWindow);
- // If there is no platform window, do the second best thing and
- // return the app global devicePixelRatio. This is the highest
+ // Get the platform scale factor. If there is no platform window
+ // use the app global devicePixelRatio, which is the the highest
// devicePixelRatio found on the system screens, and will be
// correct for single-display systems (a very common case).
- if (!d->platformWindow)
- return qApp->devicePixelRatio();
- return d->platformWindow->devicePixelRatio() * QHighDpiScaling::factor(this);
+ qreal ratio = d->platformWindow ? d->platformWindow->devicePixelRatio()
+ : qApp->devicePixelRatio();
+
+ //
+ ratio *= QHighDpiScaling::factor(this);
+
+ return ratio;
}
/*!
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;
diff --git a/src/gui/text/qstatictext.cpp b/src/gui/text/qstatictext.cpp
index fc95a859e7..38d83c485c 100644
--- a/src/gui/text/qstatictext.cpp
+++ b/src/gui/text/qstatictext.cpp
@@ -555,6 +555,9 @@ namespace {
case PdmDevicePixelRatio:
val = 1;
break;
+ case PdmDevicePixelRatioScaled:
+ val = devicePixelRatioFScale;
+ break;
default:
val = 0;
qWarning("DrawTextItemDevice::metric: Invalid metric command");
diff --git a/src/gui/text/qtextimagehandler.cpp b/src/gui/text/qtextimagehandler.cpp
index e85890baf2..1ba2cb31ca 100644
--- a/src/gui/text/qtextimagehandler.cpp
+++ b/src/gui/text/qtextimagehandler.cpp
@@ -256,10 +256,10 @@ void QTextImageHandler::drawObject(QPainter *p, const QRectF &rect, QTextDocumen
const QTextImageFormat imageFormat = format.toImageFormat();
if (QCoreApplication::instance()->thread() != QThread::currentThread()) {
- const QImage image = getImage(doc, imageFormat, p->device()->devicePixelRatio());
+ const QImage image = getImage(doc, imageFormat, p->device()->devicePixelRatioF());
p->drawImage(rect, image, image.rect());
} else {
- const QPixmap pixmap = getPixmap(doc, imageFormat, p->device()->devicePixelRatio());
+ const QPixmap pixmap = getPixmap(doc, imageFormat, p->device()->devicePixelRatioF());
p->drawPixmap(rect, pixmap, pixmap.rect());
}
}