Add mouse position functionality

This commit is contained in:
Ronan Le Tiec 2020-11-14 10:55:57 +01:00
parent d55dbbb61e
commit 491d5848b4
4 changed files with 52 additions and 3 deletions

View File

@ -74,6 +74,12 @@ void VPMainGraphicsView::RefreshLayout()
m_scene->update();
}
//---------------------------------------------------------------------------------------------------------------------
VMainGraphicsScene* VPMainGraphicsView::GetScene()
{
return m_scene;
}
//---------------------------------------------------------------------------------------------------------------------
void VPMainGraphicsView::dragEnterEvent(QDragEnterEvent *event)
{

View File

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

View File

@ -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 <QLoggingCategory>
@ -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<QKeySequence> 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<qint32>(FromPixel(scenePos.x(), m_layout->GetUnit())))
.arg(static_cast<qint32>(FromPixel(scenePos.y(), m_layout->GetUnit())))
.arg(UnitsToStr(m_layout->GetUnit(), true)));
}
}

View File

@ -31,6 +31,7 @@
#include <QMainWindow>
#include <QMessageBox>
#include <QDoubleSpinBox>
#include <QPointer>
#include "../vmisc/def.h"
#include "vpcarrousel.h"
@ -103,9 +104,16 @@ private:
VPLayout *m_layout{nullptr};
QList<VPPiece *>m_selectedPieces{QList<VPPiece *>()};
QLabel* m_mouseCoordinate{nullptr};
/**
* @brief spin box with the scale factor of the graphic view
*/
QPointer<QDoubleSpinBox> 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