Commit 7ffd08aa authored by Oliver Sander's avatar Oliver Sander
Browse files

Use device pixel ratio for the correct screen

The method qApp->devicePixelRatio() should only be used under
special circumstances.  The documentation of QGuiApplication says:

  "Returns the highest screen device pixel ratio found on the system.
   [...] Use this function only when you don't know which window
   you are targeting. If you do know the target window,
   use QWindow::devicePixelRatio() instead."

The Okular code used qApp->devicePixelRatio() a few times without
reason.  Few people noticed this, because apparently only Windows
and Wayland can set per-screen dprs.  This patch replaces those
calls with the correct QWindow call.
parent c07944e6
Pipeline #54875 passed with stage
in 10 minutes and 30 seconds
......@@ -106,7 +106,7 @@ void PagePainter::paintCroppedPageOnPainter(QPainter *destPainter,
if (p != nullptr) {
pixmap = *p;
pixmap.setDevicePixelRatio(qApp->devicePixelRatio());
pixmap.setDevicePixelRatio(dpr);
}
/** 1B - IF NO PIXMAP, DRAW EMPTY PAGE **/
......@@ -250,7 +250,7 @@ void PagePainter::paintCroppedPageOnPainter(QPainter *destPainter,
if (!limitsInTile.isEmpty()) {
QPixmap *tilePixmap = tile.pixmap();
tilePixmap->setDevicePixelRatio(qApp->devicePixelRatio());
tilePixmap->setDevicePixelRatio(dpr);
if (tilePixmap->width() == dTileRect.width() && tilePixmap->height() == dTileRect.height()) {
destPainter->drawPixmap(limitsInTile.topLeft(), *tilePixmap, dLimitsInTile.translated(-dTileRect.topLeft()));
......@@ -290,7 +290,7 @@ void PagePainter::paintCroppedPageOnPainter(QPainter *destPainter,
if (!limitsInTile.isEmpty()) {
QPixmap *tilePixmap = tile.pixmap();
tilePixmap->setDevicePixelRatio(qApp->devicePixelRatio());
tilePixmap->setDevicePixelRatio(dpr);
if (tilePixmap->width() == dTileRect.width() && tilePixmap->height() == dTileRect.height()) {
p.drawPixmap(limitsInTile.translated(-limits.topLeft()).topLeft(), *tilePixmap, dLimitsInTile.translated(-dTileRect.topLeft()));
......
......@@ -439,7 +439,7 @@ void PresentationWidget::notifyCurrentPageChanged(int previousPage, int currentP
// if pixmap not inside the Okular::Page we request it and wait for
// notifyPixmapChanged call or else we can proceed to pixmap generation
if (!frame->page->hasPixmap(this, ceil(pixW * qApp->devicePixelRatio()), ceil(pixH * qApp->devicePixelRatio()))) {
if (!frame->page->hasPixmap(this, ceil(pixW * devicePixelRatioF()), ceil(pixH * devicePixelRatioF()))) {
requestPixmaps();
} else {
// make the background pixmap
......@@ -1019,7 +1019,7 @@ void PresentationWidget::changePage(int newPage)
void PresentationWidget::generatePage(bool disableTransition)
{
if (m_lastRenderedPixmap.isNull()) {
qreal dpr = qApp->devicePixelRatio();
qreal dpr = devicePixelRatioF();
m_lastRenderedPixmap = QPixmap(m_width * dpr, m_height * dpr);
m_lastRenderedPixmap.setDevicePixelRatio(dpr);
......@@ -1069,7 +1069,7 @@ void PresentationWidget::generatePage(bool disableTransition)
void PresentationWidget::generateIntroPage(QPainter &p)
{
qreal dpr = qApp->devicePixelRatio();
qreal dpr = devicePixelRatioF();
// use a vertical gray gradient background
int blend1 = m_height / 10, blend2 = 9 * m_height / 10;
......@@ -1148,7 +1148,7 @@ inline int qt_div255(int x)
void PresentationWidget::generateOverlay()
{
#ifdef ENABLE_PROGRESS_OVERLAY
qreal dpr = qApp->devicePixelRatio();
qreal dpr = devicePixelRatioF();
// calculate overlay geometry and resize pixmap if needed
double side = m_width / 16.0;
......@@ -1483,7 +1483,7 @@ void PresentationWidget::slotTransitionStep()
QPainter pixmapPainter;
m_currentPixmapOpacity += 1.0 / m_transitionSteps;
m_lastRenderedPixmap = QPixmap(m_lastRenderedPixmap.size());
m_lastRenderedPixmap.setDevicePixelRatio(qApp->devicePixelRatio());
m_lastRenderedPixmap.setDevicePixelRatio(devicePixelRatioF());
m_lastRenderedPixmap.fill(Qt::transparent);
pixmapPainter.begin(&m_lastRenderedPixmap);
pixmapPainter.setCompositionMode(QPainter::CompositionMode_Source);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment