diff --git a/src/app/puzzle/vpmaingraphicsview.cpp b/src/app/puzzle/vpmaingraphicsview.cpp index a114a8ff0..1db306030 100644 --- a/src/app/puzzle/vpmaingraphicsview.cpp +++ b/src/app/puzzle/vpmaingraphicsview.cpp @@ -74,6 +74,12 @@ void VPMainGraphicsView::RefreshLayout() m_scene->update(); } +//--------------------------------------------------------------------------------------------------------------------- +VMainGraphicsScene* VPMainGraphicsView::GetScene() +{ + return m_scene; +} + //--------------------------------------------------------------------------------------------------------------------- void VPMainGraphicsView::dragEnterEvent(QDragEnterEvent *event) { diff --git a/src/app/puzzle/vpmaingraphicsview.h b/src/app/puzzle/vpmaingraphicsview.h index 15709c520..fdea4efb6 100644 --- a/src/app/puzzle/vpmaingraphicsview.h +++ b/src/app/puzzle/vpmaingraphicsview.h @@ -48,6 +48,14 @@ public: */ void RefreshLayout(); + + /** + * @brief GetScene Returns the scene of the view + * @return + */ + VMainGraphicsScene* GetScene(); + + protected: void dragEnterEvent(QDragEnterEvent *event) override; void dragMoveEvent(QDragMoveEvent *event) override; diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 97740e8de..5633b3602 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -41,6 +41,7 @@ #include "../vmisc/projectversion.h" #include "../ifc/xml/vlayoutconverter.h" #include "../ifc/exception/vexception.h" +#include "../vwidgets/vmaingraphicsscene.h" #include "vpsheet.h" #include @@ -480,11 +481,21 @@ void VPMainWindow::InitMainGraphics() m_graphicsView->RefreshLayout(); connect(m_graphicsView, &VPMainGraphicsView::ScaleChanged, this, &VPMainWindow::on_ScaleChanged); + connect(m_graphicsView->GetScene(), &VMainGraphicsScene::mouseMove, this, &VPMainWindow::on_MouseMoved); } //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::InitZoomToolBar() { + if (not m_doubleSpinBoxScale.isNull()) + { + delete m_doubleSpinBoxScale; + } + + if (m_mouseCoordinate != nullptr) + { + delete m_mouseCoordinate; + } // connect the zoom buttons and shortcuts to the slots QList zoomInShortcuts; @@ -530,7 +541,6 @@ void VPMainWindow::InitZoomToolBar() m_mouseCoordinate = new QLabel(QString("0, 0 (%1)").arg(UnitsToStr(m_layout->GetUnit(), true))); ui->toolBarZoom->addWidget(m_mouseCoordinate); ui->toolBarZoom->addSeparator(); - } //--------------------------------------------------------------------------------------------------------------------- @@ -1099,3 +1109,15 @@ void VPMainWindow::on_ScaleChanged(qreal scale) m_doubleSpinBoxScale->blockSignals(false); } } + +//--------------------------------------------------------------------------------------------------------------------- +void VPMainWindow::on_MouseMoved(const QPointF &scenePos) +{ + if (m_mouseCoordinate != nullptr) + { + m_mouseCoordinate->setText(QStringLiteral("%1, %2 (%3)") + .arg(static_cast(FromPixel(scenePos.x(), m_layout->GetUnit()))) + .arg(static_cast(FromPixel(scenePos.y(), m_layout->GetUnit()))) + .arg(UnitsToStr(m_layout->GetUnit(), true))); + } +} diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index 5e74f3f1d..ce6d166bb 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -31,6 +31,7 @@ #include #include #include +#include #include "../vmisc/def.h" #include "vpcarrousel.h" @@ -103,9 +104,16 @@ private: VPLayout *m_layout{nullptr}; QListm_selectedPieces{QList()}; - QLabel* m_mouseCoordinate{nullptr}; + /** + * @brief spin box with the scale factor of the graphic view + */ QPointer m_doubleSpinBoxScale{nullptr}; + /** + * @brief mouseCoordinate pointer to label who show mouse coordinate. + */ + QLabel* m_mouseCoordinate{nullptr}; + /** * @brief CreatePiece creates a piece from the given VLayoutPiece data * @param rawPiece the raw piece data @@ -399,10 +407,15 @@ private slots: void on_PieceRotationChanged(); /** - * @brief on_ScaleChanged + * @brief on_ScaleChanged When the scale of the graphic view is changed */ void on_ScaleChanged(qreal scale); + /** + * @brief mouseMove save mouse position and show user. + * @param scenePos position mouse. + */ + void on_MouseMoved(const QPointF &scenePos); }; #endif // VPMAINWINDOW_H