minor tweaks, fix typo, add new bug
This commit is contained in:
		| @ -46,7 +46,9 @@ BottomButtonGroup::BottomButtonGroup(QWidget *parent) | |||||||
|     addButton(newBtn("view-background-checkerboard", [this]() { |     addButton(newBtn("view-background-checkerboard", [this]() { | ||||||
|         emit toggleCheckerboardBtnClicked(); |         emit toggleCheckerboardBtnClicked(); | ||||||
|     })); |     })); | ||||||
|     addButton(newBtn("object-rorate-right", [](){qDebug()<< "TODO: object-rorate-right";})); |     addButton(newBtn("object-rotate-right", [this]() { | ||||||
|  |         emit rotateRightBtnClicked(); | ||||||
|  |     })); | ||||||
| } | } | ||||||
|  |  | ||||||
| void BottomButtonGroup::addButton(QAbstractButton *button) | void BottomButtonGroup::addButton(QAbstractButton *button) | ||||||
|  | |||||||
| @ -17,6 +17,7 @@ signals: | |||||||
|     void zoomInBtnClicked(); |     void zoomInBtnClicked(); | ||||||
|     void zoomOutBtnClicked(); |     void zoomOutBtnClicked(); | ||||||
|     void toggleCheckerboardBtnClicked(); |     void toggleCheckerboardBtnClicked(); | ||||||
|  |     void rotateRightBtnClicked(); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| #endif // BOTTOMBUTTONGROUP_H | #endif // BOTTOMBUTTONGROUP_H | ||||||
|  | |||||||
| @ -84,6 +84,14 @@ void GraphicsView::setScene(GraphicsScene *scene) | |||||||
|     return QGraphicsView::setScene(scene); |     return QGraphicsView::setScene(scene); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | void GraphicsView::checkAndDoFitInView() | ||||||
|  | { | ||||||
|  |     if (!isThingSmallerThanWindowWith(transform())) { | ||||||
|  |         m_enableFitInView = true; | ||||||
|  |         fitInView(sceneRect(), Qt::KeepAspectRatio); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| void GraphicsView::toggleCheckerboard() | void GraphicsView::toggleCheckerboard() | ||||||
| { | { | ||||||
|     setCheckerboardEnabled(!m_checkerboardEnabled); |     setCheckerboardEnabled(!m_checkerboardEnabled); | ||||||
| @ -189,14 +197,14 @@ void GraphicsView::dropEvent(QDropEvent *event) | |||||||
| } | } | ||||||
|  |  | ||||||
| bool GraphicsView::isThingSmallerThanWindowWith(const QTransform &transform) const | bool GraphicsView::isThingSmallerThanWindowWith(const QTransform &transform) const | ||||||
| { | {qDebug() << sceneRect(); | ||||||
|     return rect().size().expandedTo(transform.mapRect(sceneRect()).size().toSize()) |     return rect().size().expandedTo(transform.mapRect(sceneRect()).size().toSize()) | ||||||
|             == rect().size(); |             == rect().size(); | ||||||
| } | } | ||||||
|  |  | ||||||
| bool GraphicsView::shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) const | bool GraphicsView::shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) const | ||||||
| { | { | ||||||
|     if (isThingSmallerThanWindowWith(transform())) { |     if (event->buttons() == Qt::NoButton) { | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @ -205,15 +213,11 @@ bool GraphicsView::shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) con | |||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return false; |     if (isThingSmallerThanWindowWith(transform())) { | ||||||
| } |         return true; | ||||||
|  |  | ||||||
| void GraphicsView::checkAndDoFitInView() |  | ||||||
| { |  | ||||||
|     if (!isThingSmallerThanWindowWith(transform())) { |  | ||||||
|         m_enableFitInView = true; |  | ||||||
|         fitInView(sceneRect(), Qt::KeepAspectRatio); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     return false; | ||||||
| } | } | ||||||
|  |  | ||||||
| void GraphicsView::setCheckerboardEnabled(bool enabled) | void GraphicsView::setCheckerboardEnabled(bool enabled) | ||||||
| @ -222,9 +226,9 @@ void GraphicsView::setCheckerboardEnabled(bool enabled) | |||||||
|     if (m_checkerboardEnabled) { |     if (m_checkerboardEnabled) { | ||||||
|         // Prepare background check-board pattern |         // Prepare background check-board pattern | ||||||
|         QPixmap tilePixmap(0x20, 0x20); |         QPixmap tilePixmap(0x20, 0x20); | ||||||
|         tilePixmap.fill(QColor(30, 30, 30, 100)); |         tilePixmap.fill(QColor(35, 35, 35, 110)); | ||||||
|         QPainter tilePainter(&tilePixmap); |         QPainter tilePainter(&tilePixmap); | ||||||
|         QColor color(40, 40, 40, 100); |         QColor color(40, 40, 40, 110); | ||||||
|         tilePainter.fillRect(0, 0, 0x10, 0x10, color); |         tilePainter.fillRect(0, 0, 0x10, 0x10, color); | ||||||
|         tilePainter.fillRect(0x10, 0x10, 0x10, 0x10, color); |         tilePainter.fillRect(0x10, 0x10, 0x10, 0x10, color); | ||||||
|         tilePainter.end(); |         tilePainter.end(); | ||||||
|  | |||||||
| @ -20,6 +20,8 @@ public: | |||||||
|     GraphicsScene * scene() const; |     GraphicsScene * scene() const; | ||||||
|     void setScene(GraphicsScene *scene); |     void setScene(GraphicsScene *scene); | ||||||
|  |  | ||||||
|  |     void checkAndDoFitInView(); | ||||||
|  |  | ||||||
| public slots: | public slots: | ||||||
|     void toggleCheckerboard(); |     void toggleCheckerboard(); | ||||||
|  |  | ||||||
| @ -36,7 +38,6 @@ private: | |||||||
|  |  | ||||||
|     bool isThingSmallerThanWindowWith(const QTransform &transform) const; |     bool isThingSmallerThanWindowWith(const QTransform &transform) const; | ||||||
|     bool shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) const; |     bool shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) const; | ||||||
|     void checkAndDoFitInView(); |  | ||||||
|     void setCheckerboardEnabled(bool enabled); |     void setCheckerboardEnabled(bool enabled); | ||||||
|  |  | ||||||
|     bool m_enableFitInView = false; |     bool m_enableFitInView = false; | ||||||
|  | |||||||
| Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB | 
| @ -59,13 +59,18 @@ MainWindow::MainWindow(QWidget *parent) : | |||||||
|     m_bottomButtonGroup = new BottomButtonGroup(this); |     m_bottomButtonGroup = new BottomButtonGroup(this); | ||||||
|  |  | ||||||
|     connect(m_bottomButtonGroup, &BottomButtonGroup::resetToOriginalBtnClicked, |     connect(m_bottomButtonGroup, &BottomButtonGroup::resetToOriginalBtnClicked, | ||||||
|             this, [ = ](){ m_graphicsView->setTransform(QTransform()); }); |             this, [ = ](){ m_graphicsView->resetTransform(); }); | ||||||
|     connect(m_bottomButtonGroup, &BottomButtonGroup::zoomInBtnClicked, |     connect(m_bottomButtonGroup, &BottomButtonGroup::zoomInBtnClicked, | ||||||
|             this, [ = ](){ m_graphicsView->scale(1.25, 1.25); }); |             this, [ = ](){ m_graphicsView->scale(1.25, 1.25); }); | ||||||
|     connect(m_bottomButtonGroup, &BottomButtonGroup::zoomOutBtnClicked, |     connect(m_bottomButtonGroup, &BottomButtonGroup::zoomOutBtnClicked, | ||||||
|             this, [ = ](){ m_graphicsView->scale(0.75, 0.75); }); |             this, [ = ](){ m_graphicsView->scale(0.75, 0.75); }); | ||||||
|     connect(m_bottomButtonGroup, &BottomButtonGroup::toggleCheckerboardBtnClicked, |     connect(m_bottomButtonGroup, &BottomButtonGroup::toggleCheckerboardBtnClicked, | ||||||
|             this, [ = ](){ m_graphicsView->toggleCheckerboard(); }); |             this, [ = ](){ m_graphicsView->toggleCheckerboard(); }); | ||||||
|  |     connect(m_bottomButtonGroup, &BottomButtonGroup::rotateRightBtnClicked, | ||||||
|  |             this, [ = ](){ | ||||||
|  |         m_graphicsView->rotate(90); | ||||||
|  |         m_graphicsView->checkAndDoFitInView(); | ||||||
|  |     }); | ||||||
|  |  | ||||||
|     centerWindow(); |     centerWindow(); | ||||||
| } | } | ||||||
| @ -114,7 +119,8 @@ void MainWindow::mousePressEvent(QMouseEvent *event) | |||||||
|     if (event->buttons() & Qt::LeftButton) { |     if (event->buttons() & Qt::LeftButton) { | ||||||
|         m_clickedOnWindow = true; |         m_clickedOnWindow = true; | ||||||
|         m_oldMousePos = event->pos(); |         m_oldMousePos = event->pos(); | ||||||
|         qDebug() << m_oldMousePos; |         qDebug() << m_oldMousePos << m_graphicsView->transform().m11() | ||||||
|  |                  << m_graphicsView->transform().m22() << m_graphicsView->matrix().m11(); | ||||||
|         event->accept(); |         event->accept(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | |||||||
| @ -4,7 +4,7 @@ | |||||||
|         <file>icons/zoom-out.svg</file> |         <file>icons/zoom-out.svg</file> | ||||||
|         <file>icons/view-fullscreen.svg</file> |         <file>icons/view-fullscreen.svg</file> | ||||||
|         <file>icons/zoom-original.svg</file> |         <file>icons/zoom-original.svg</file> | ||||||
|         <file>icons/object-rorate-right.svg</file> |         <file>icons/object-rotate-right.svg</file> | ||||||
|         <file>icons/view-background-checkerboard.svg</file> |         <file>icons/view-background-checkerboard.svg</file> | ||||||
|         <file>icons/app-icon.svg</file> |         <file>icons/app-icon.svg</file> | ||||||
|     </qresource> |     </qresource> | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user