fix: always rotate according to current viewport state

This commit is contained in:
Gary Wang 2021-03-29 22:43:37 +08:00
parent e1324d901c
commit 622938ac23
3 changed files with 15 additions and 8 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);
});