diff --git a/app/graphicsview.cpp b/app/graphicsview.cpp index 7be7572..e74126f 100644 --- a/app/graphicsview.cpp +++ b/app/graphicsview.cpp @@ -133,6 +133,19 @@ void GraphicsView::zoomView(qreal scaleFactor) emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform()); } +// This is always according to user's view. +// the direction of the rotation will NOT be clockwise because the y-axis points downwards. +void GraphicsView::rotateView(bool clockwise) +{ + resetScale(); + + QTransform tf(0, clockwise ? 1 : -1, 0, + clockwise ? -1 : 1, 0, 0, + 0, 0, 1); + tf = transform() * tf; + setTransform(tf); +} + void GraphicsView::flipView(bool horizontal) { QTransform tf(horizontal ? -1 : 1, 0, 0, @@ -151,12 +164,6 @@ void GraphicsView::resetScale() emit navigatorViewRequired(!isThingSmallerThanWindowWith(transform()), transform()); } -void GraphicsView::rotateView(qreal rotateAngel) -{ - resetScale(); - rotate(rotateAngel); -} - void GraphicsView::fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode) { QGraphicsView::fitInView(rect, aspectRadioMode); diff --git a/app/graphicsview.h b/app/graphicsview.h index eb20a03..02cd6c6 100644 --- a/app/graphicsview.h +++ b/app/graphicsview.h @@ -26,9 +26,9 @@ public: void resetTransform(); void zoomView(qreal scaleFactor); + void rotateView(bool clockwise = true); void flipView(bool horizontal = true); void resetScale(); - void rotateView(qreal rotateAngel); void fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio); void checkAndDoFitInView(bool markItOnAnyway = true); diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index 3220d3a..bac7f8b 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -119,7 +119,7 @@ MainWindow::MainWindow(QWidget *parent) this, &MainWindow::toggleCheckerboard); connect(m_bottomButtonGroup, &BottomButtonGroup::rotateRightBtnClicked, this, [ = ](){ - m_graphicsView->rotateView(90); + m_graphicsView->rotateView(); m_graphicsView->checkAndDoFitInView(); m_gv->setVisible(false); });