From cf4b2b61847beb43a55b3da242d07632b785e73e Mon Sep 17 00:00:00 2001 From: "J.D. Purcell" Date: Wed, 1 Jan 2025 01:31:35 -0500 Subject: [PATCH] WIP --- src/qvgraphicsview.cpp | 44 ++++++++++++++++++++---------------------- src/qvgraphicsview.h | 10 ++++++---- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/qvgraphicsview.cpp b/src/qvgraphicsview.cpp index 08a7f9aa..44c9ea27 100644 --- a/src/qvgraphicsview.cpp +++ b/src/qvgraphicsview.cpp @@ -337,7 +337,7 @@ void QVGraphicsView::keyPressEvent(QKeyEvent *event) if (scrollXSmallSteps != 0 || scrollYSmallSteps != 0 || scrollYLargeSteps != 0) { const QPoint delta { - (horizontalScrollBar()->singleStep() * scrollXSmallSteps) * (isRightToLeft() ? -1 : 1), + (horizontalScrollBar()->singleStep() * scrollXSmallSteps) * getRtlFlip(), (verticalScrollBar()->singleStep() * scrollYSmallSteps) + (verticalScrollBar()->pageStep() * scrollYLargeSteps) }; scrollHelper->move(delta); @@ -384,7 +384,7 @@ void QVGraphicsView::executeDragAction(const Qv::ViewportDragAction action, cons { if (action == Qv::ViewportDragAction::Pan) { - scrollHelper->move(QPointF(-delta.x() * (isRightToLeft() ? -1 : 1), -delta.y())); + scrollHelper->move(QPointF(-delta.x() * getRtlFlip(), -delta.y())); } else if (action == Qv::ViewportDragAction::MoveWindow) { @@ -403,7 +403,7 @@ void QVGraphicsView::executeDragAction(const Qv::ViewportDragAction action, cons void QVGraphicsView::executeScrollAction(const Qv::ViewportScrollAction action, const QPoint delta, const QPoint mousePos, const bool hasShiftModifier) { const int deltaPerWheelStep = 120; - const int rtlFlip = isRightToLeft() ? -1 : 1; + const int rtlFlip = getRtlFlip(); const auto getUniAxisDelta = [delta, rtlFlip]() { return @@ -612,7 +612,7 @@ void QVGraphicsView::zoomAbsolute(const qreal absoluteLevel, const std::optional if (pos.has_value()) { const QPointF move = mapFromScene(scenePos) - pos.value(); - horizontalScrollBar()->setValue(horizontalScrollBar()->value() + (move.x() * (isRightToLeft() ? -1 : 1))); + horizontalScrollBar()->setValue(horizontalScrollBar()->value() + (move.x() * getRtlFlip())); verticalScrollBar()->setValue(verticalScrollBar()->value() + move.y()); lastZoomRoundingError = mapToScene(pos.value()) - scenePos; constrainBoundsTimer->start(); @@ -936,7 +936,7 @@ LogicalPixelFitter QVGraphicsView::getPixelFitter() const void QVGraphicsView::matchContentCenter(const QRect target) { const QPointF delta = QRectF(getContentRect()).center() - QRectF(target).center(); - scrollHelper->move(QPointF(delta.x() * (isRightToLeft() ? -1 : 1), delta.y())); + scrollHelper->move(QPointF(delta.x() * getRtlFlip(), delta.y())); } QRect QVGraphicsView::getContentRect() const @@ -965,19 +965,14 @@ QRect QVGraphicsView::getUsableViewportRect(const bool addOverscan) const return rect; } -void QVGraphicsView::setTransformScale(qreal value) +void QVGraphicsView::setTransformScale(const qreal value) { setTransformWithNormalization(getUnspecializedTransform().scale(value, value)); } -void QVGraphicsView::setTransformWithNormalization(QTransform matrix) +void QVGraphicsView::setTransformWithNormalization(const QTransform &matrix) { - if (!loadedPixmapItem->pixmap().isNull()) - { - matrix = normalizeTransformOrigin(matrix, loadedPixmapItem->boundingRect().size()); - } - setTransform(matrix); - qDebug() << getContentRect(); + setTransform(normalizeTransformOrigin(matrix, loadedPixmapItem->boundingRect().size())); } QTransform QVGraphicsView::getUnspecializedTransform() const @@ -993,6 +988,14 @@ QTransform QVGraphicsView::getUnspecializedTransform() const return { t.m11() < 0 ? -1.0 : 1.0, 0, 0, t.m22() < 0 ? -1.0 : 1.0, 0, 0 }; } +QTransform QVGraphicsView::normalizeTransformOrigin(const QTransform &matrix, const QSizeF &pixmapSize) const +{ + const int horizontalFactor = matrix.m11() < 0 ? -1 * getRtlFlip() : matrix.m12() < 0 ? -1 : 0; + const int verticalFactor = matrix.m22() < 0 ? -1 : matrix.m21() < 0 ? -1 * getRtlFlip() : 0; + QTransform t { matrix.m11(), matrix.m12(), matrix.m21(), matrix.m22(), 0, 0 }; + return t.translate(pixmapSize.width() * horizontalFactor, pixmapSize.height() * verticalFactor); +} + qreal QVGraphicsView::getDpiAdjustment() const { // Although inverting this potentially introduces a rounding error, it is inevitable. For @@ -1024,6 +1027,11 @@ void QVGraphicsView::handleSmoothScalingChange() removeExpensiveScaling(); } +int QVGraphicsView::getRtlFlip() const +{ + return isRightToLeft() ? -1 : 1; +} + void QVGraphicsView::cancelTurboNav() { if (!turboNavMode.has_value()) @@ -1042,16 +1050,6 @@ MainWindow* QVGraphicsView::getMainWindow() const return qobject_cast(window()); } -QTransform QVGraphicsView::normalizeTransformOrigin(QTransform matrix, const QSizeF pixmapSize) -{ - const bool isXNegative = matrix.m11() < 0 || matrix.m12() < 0; - const bool isYNegative = matrix.m22() < 0 || matrix.m21() < 0; - return matrix.translate( - isXNegative ? -pixmapSize.width() : 0, - isYNegative ? -pixmapSize.height() : 0 - ); -} - void QVGraphicsView::settingsUpdated() { auto &settingsManager = qvApp->getSettingsManager(); diff --git a/src/qvgraphicsview.h b/src/qvgraphicsview.h index a03f80d1..c94f6b5f 100644 --- a/src/qvgraphicsview.h +++ b/src/qvgraphicsview.h @@ -144,24 +144,26 @@ class QVGraphicsView : public QGraphicsView QRect getUsableViewportRect(const bool addOverscan = false) const; - void setTransformScale(qreal absoluteScale); + void setTransformScale(const qreal absoluteScale); - void setTransformWithNormalization(QTransform matrix); + void setTransformWithNormalization(const QTransform &matrix); QTransform getUnspecializedTransform() const; + QTransform normalizeTransformOrigin(const QTransform &matrix, const QSizeF &pixmapSize) const; + qreal getDpiAdjustment() const; void handleDpiAdjustmentChange(); void handleSmoothScalingChange(); + int getRtlFlip() const; + void cancelTurboNav(); MainWindow* getMainWindow() const; - static QTransform normalizeTransformOrigin(QTransform matrix, const QSizeF pixmapSize); - private slots: void animatedFrameChanged(QRect rect);