Skip to content

Commit 3c68fb9

Browse files
committed
Re-invert DPI adjustment
1 parent 898af0f commit 3c68fb9

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/qvgraphicsview.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ void QVGraphicsView::zoomAbsolute(const qreal absoluteLevel, const QPoint &pos)
305305
}
306306
else
307307
{
308-
setTransformScale(absoluteLevel / appliedDpiAdjustment);
308+
setTransformScale(absoluteLevel * appliedDpiAdjustment);
309309
}
310310
zoomLevel = absoluteLevel;
311311

@@ -349,7 +349,7 @@ void QVGraphicsView::applyExpensiveScaling()
349349

350350
// Calculate scaled resolution
351351
const qreal dpiAdjustment = getDpiAdjustment();
352-
const QSizeF mappedSize = QSizeF(getCurrentFileDetails().loadedPixmapSize) * zoomLevel * (devicePixelRatioF() / dpiAdjustment);
352+
const QSizeF mappedSize = QSizeF(getCurrentFileDetails().loadedPixmapSize) * zoomLevel * dpiAdjustment * devicePixelRatioF();
353353

354354
// Set image to scaled version
355355
loadedPixmapItem->setPixmap(imageCore.scaleExpensively(mappedSize));
@@ -371,7 +371,7 @@ void QVGraphicsView::removeExpensiveScaling()
371371

372372
// Set appropriate scale factor
373373
const qreal dpiAdjustment = getDpiAdjustment();
374-
const qreal newTransformScale = zoomLevel / dpiAdjustment;
374+
const qreal newTransformScale = zoomLevel * dpiAdjustment;
375375
setTransformScale(newTransformScale);
376376
appliedDpiAdjustment = dpiAdjustment;
377377
appliedExpensiveScaleZoomLevel = 0.0;
@@ -580,7 +580,7 @@ void QVGraphicsView::goToFile(const GoToFileMode &mode, int index)
580580

581581
QSizeF QVGraphicsView::getEffectiveOriginalSize() const
582582
{
583-
return getTransformWithNoScaling().mapRect(QRectF(QPoint(), getCurrentFileDetails().loadedPixmapSize)).size() / getDpiAdjustment();
583+
return getTransformWithNoScaling().mapRect(QRectF(QPoint(), getCurrentFileDetails().loadedPixmapSize)).size() * getDpiAdjustment();
584584
}
585585

586586
LogicalPixelFitter QVGraphicsView::getPixelFitter() const
@@ -596,7 +596,7 @@ QRect QVGraphicsView::getContentRect() const
596596
// the process of zooming in and haven't re-applied the expensive scaling yet. If that's the case, callers need
597597
// to know what the content rect will be once the dust settles rather than what's being temporarily displayed.
598598
const QRectF loadedPixmapBoundingRect = QRectF(QPoint(), getCurrentFileDetails().loadedPixmapSize);
599-
const qreal effectiveTransformScale = zoomLevel / appliedDpiAdjustment;
599+
const qreal effectiveTransformScale = zoomLevel * appliedDpiAdjustment;
600600
const QTransform effectiveTransform = getTransformWithNoScaling().scale(effectiveTransformScale, effectiveTransformScale);
601601
const QRectF contentRect = effectiveTransform.mapRect(loadedPixmapBoundingRect);
602602
const QSize snappedSize = getPixelFitter().snapSize(contentRect.size());
@@ -636,7 +636,11 @@ QTransform QVGraphicsView::getTransformWithNoScaling() const
636636

637637
qreal QVGraphicsView::getDpiAdjustment() const
638638
{
639-
return isOneToOnePixelSizingEnabled ? devicePixelRatioF() : 1.0;
639+
// Although inverting this potentially introduces a rounding error, it is inevitable. For
640+
// example with 1:1 pixel sizing @ 100% zoom, the transform's scale must be set to the
641+
// inverted value. Pre-inverting it here helps keep things consistent, e.g. so that the
642+
// content rect calculation has the same error that will happen during painting.
643+
return isOneToOnePixelSizingEnabled ? 1.0 / devicePixelRatioF() : 1.0;
640644
}
641645

642646
void QVGraphicsView::handleDpiAdjustmentChange()

0 commit comments

Comments
 (0)