From e1324d901c35dd38f280b90e7637140cced39bb1 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Sat, 27 Mar 2021 22:22:04 +0800 Subject: [PATCH] fix: always flip according to current viewport state --- app/graphicsview.cpp | 20 ++++++++------------ app/graphicsview.h | 2 -- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/app/graphicsview.cpp b/app/graphicsview.cpp index a2012b9..7be7572 100644 --- a/app/graphicsview.cpp +++ b/app/graphicsview.cpp @@ -135,11 +135,12 @@ void GraphicsView::zoomView(qreal scaleFactor) void GraphicsView::flipView(bool horizontal) { - if (horizontal) { - scale(-1, 1); - } else { - scale(1, -1); - } + QTransform tf(horizontal ? -1 : 1, 0, 0, + 0, horizontal ? 1 : -1, 0, + 0, 0, 1); + tf = transform() * tf; + setTransform(tf); + // Ensure the navigation view is also flipped. emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform()); } @@ -179,6 +180,8 @@ inline double zeroOrOne(double number) return qFuzzyIsNull(number) ? 0 : (number > 0 ? 1 : -1); } +// Note: this only works if we only have 90 degree based rotation +// and no shear/translate. QTransform GraphicsView::resetScale(const QTransform & orig) { return QTransform(zeroOrOne(orig.m11()), zeroOrOne(orig.m12()), @@ -349,10 +352,3 @@ void GraphicsView::applyTransformationModeByScaleFactor() scene()->trySetTransformationMode(Qt::FastTransformation); } } - -void GraphicsView::resetWithScaleAndRotate(qreal scaleFactor, qreal rotateAngle) -{ - QGraphicsView::resetTransform(); - scale(scaleFactor, scaleFactor); - rotate(rotateAngle); -} diff --git a/app/graphicsview.h b/app/graphicsview.h index bdeeb4a..eb20a03 100644 --- a/app/graphicsview.h +++ b/app/graphicsview.h @@ -59,8 +59,6 @@ private: void setCheckerboardEnabled(bool enabled, bool invertColor = false); void applyTransformationModeByScaleFactor(); - void resetWithScaleAndRotate(qreal scaleFactor, qreal rotateAngle); - bool m_enableFitInView = false; bool m_checkerboardEnabled = false; bool m_isLastCheckerboardColorInverted = false;