diff --git a/graphicsview.cpp b/graphicsview.cpp index 6314cc1..28f23b1 100644 --- a/graphicsview.cpp +++ b/graphicsview.cpp @@ -103,7 +103,6 @@ qreal GraphicsView::scaleFactor() const void GraphicsView::resetTransform() { - m_scaleFactor = 1; m_rotateAngle = 0; QGraphicsView::resetTransform(); } @@ -111,15 +110,13 @@ void GraphicsView::resetTransform() void GraphicsView::zoomView(qreal scaleFactor) { m_enableFitInView = false; - m_scaleFactor *= scaleFactor; - reapplyViewTransform(); + scale(scaleFactor, scaleFactor); emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), m_rotateAngle); } void GraphicsView::resetScale() { - m_scaleFactor = 1; - reapplyViewTransform(); + resetWithScaleAndRotate(1, m_rotateAngle); emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), m_rotateAngle); } @@ -127,13 +124,12 @@ void GraphicsView::rotateView(qreal rotateAngel) { m_rotateAngle += rotateAngel; m_rotateAngle = static_cast(m_rotateAngle) % 360; - reapplyViewTransform(); + resetWithScaleAndRotate(1, m_rotateAngle); } void GraphicsView::fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode) { QGraphicsView::fitInView(rect, aspectRadioMode); - m_scaleFactor = scaleFactor(); } void GraphicsView::checkAndDoFitInView() @@ -291,9 +287,9 @@ void GraphicsView::setCheckerboardEnabled(bool enabled) } } -void GraphicsView::reapplyViewTransform() +void GraphicsView::resetWithScaleAndRotate(qreal scaleFactor, qreal rotateAngle) { QGraphicsView::resetTransform(); - scale(m_scaleFactor, m_scaleFactor); - rotate(m_rotateAngle); + scale(scaleFactor, scaleFactor); + rotate(rotateAngle); } diff --git a/graphicsview.h b/graphicsview.h index f216752..6f5cc7f 100644 --- a/graphicsview.h +++ b/graphicsview.h @@ -53,11 +53,10 @@ private: bool shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) const; void setCheckerboardEnabled(bool enabled); - void reapplyViewTransform(); + void resetWithScaleAndRotate(qreal scaleFactor, qreal rotateAngle); bool m_enableFitInView = false; bool m_checkerboardEnabled = false; - qreal m_scaleFactor = 1; qreal m_rotateAngle = 0; };