fix: zoom jump due to stupid bug

This commit is contained in:
Gary Wang 2019-11-02 13:32:13 +08:00
parent f2d83e3f85
commit fb9207cb71
2 changed files with 7 additions and 12 deletions

View File

@ -103,7 +103,6 @@ qreal GraphicsView::scaleFactor() const
void GraphicsView::resetTransform() void GraphicsView::resetTransform()
{ {
m_scaleFactor = 1;
m_rotateAngle = 0; m_rotateAngle = 0;
QGraphicsView::resetTransform(); QGraphicsView::resetTransform();
} }
@ -111,15 +110,13 @@ void GraphicsView::resetTransform()
void GraphicsView::zoomView(qreal scaleFactor) void GraphicsView::zoomView(qreal scaleFactor)
{ {
m_enableFitInView = false; m_enableFitInView = false;
m_scaleFactor *= scaleFactor; scale(scaleFactor, scaleFactor);
reapplyViewTransform();
emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), m_rotateAngle); emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), m_rotateAngle);
} }
void GraphicsView::resetScale() void GraphicsView::resetScale()
{ {
m_scaleFactor = 1; resetWithScaleAndRotate(1, m_rotateAngle);
reapplyViewTransform();
emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), m_rotateAngle); emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), m_rotateAngle);
} }
@ -127,13 +124,12 @@ void GraphicsView::rotateView(qreal rotateAngel)
{ {
m_rotateAngle += rotateAngel; m_rotateAngle += rotateAngel;
m_rotateAngle = static_cast<int>(m_rotateAngle) % 360; m_rotateAngle = static_cast<int>(m_rotateAngle) % 360;
reapplyViewTransform(); resetWithScaleAndRotate(1, m_rotateAngle);
} }
void GraphicsView::fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode) void GraphicsView::fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode)
{ {
QGraphicsView::fitInView(rect, aspectRadioMode); QGraphicsView::fitInView(rect, aspectRadioMode);
m_scaleFactor = scaleFactor();
} }
void GraphicsView::checkAndDoFitInView() void GraphicsView::checkAndDoFitInView()
@ -291,9 +287,9 @@ void GraphicsView::setCheckerboardEnabled(bool enabled)
} }
} }
void GraphicsView::reapplyViewTransform() void GraphicsView::resetWithScaleAndRotate(qreal scaleFactor, qreal rotateAngle)
{ {
QGraphicsView::resetTransform(); QGraphicsView::resetTransform();
scale(m_scaleFactor, m_scaleFactor); scale(scaleFactor, scaleFactor);
rotate(m_rotateAngle); rotate(rotateAngle);
} }

View File

@ -53,11 +53,10 @@ private:
bool shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) const; bool shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) const;
void setCheckerboardEnabled(bool enabled); void setCheckerboardEnabled(bool enabled);
void reapplyViewTransform(); void resetWithScaleAndRotate(qreal scaleFactor, qreal rotateAngle);
bool m_enableFitInView = false; bool m_enableFitInView = false;
bool m_checkerboardEnabled = false; bool m_checkerboardEnabled = false;
qreal m_scaleFactor = 1;
qreal m_rotateAngle = 0; qreal m_rotateAngle = 0;
}; };