fix: always rotate according to current viewport state
This commit is contained in:
		@ -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);
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user