diff --git a/guilib/include/rtabmap/gui/GraphViewer.h b/guilib/include/rtabmap/gui/GraphViewer.h index fac00a0908..d42f19ede1 100644 --- a/guilib/include/rtabmap/gui/GraphViewer.h +++ b/guilib/include/rtabmap/gui/GraphViewer.h @@ -172,6 +172,7 @@ public Q_SLOTS: protected: virtual void wheelEvent ( QWheelEvent * event ); + virtual void mouseMoveEvent(QMouseEvent * event); virtual void contextMenuEvent(QContextMenuEvent * event); private: @@ -228,6 +229,7 @@ public Q_SLOTS: float _loopClosureOutlierThr; float _maxLinkLength; bool _orientationENU; + bool _mouseTracking; ViewPlane _viewPlane; bool _ensureFrameVisible; }; diff --git a/guilib/src/GraphViewer.cpp b/guilib/src/GraphViewer.cpp index c9b1110f16..9a807c6d33 100644 --- a/guilib/src/GraphViewer.cpp +++ b/guilib/src/GraphViewer.cpp @@ -45,6 +45,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endif #include #include +#include #include #include @@ -316,6 +317,7 @@ GraphViewer::GraphViewer(QWidget * parent) : _loopClosureOutlierThr(0), _maxLinkLength(0.02f), _orientationENU(false), + _mouseTracking(false), _viewPlane(XY), _ensureFrameVisible(true) { @@ -1789,6 +1791,24 @@ void GraphViewer::wheelEvent ( QWheelEvent * event ) } } +void GraphViewer::mouseMoveEvent(QMouseEvent * event) +{ + QPointF scenePoint = mapToScene(event->pos()); + if(_mouseTracking && this->sceneRect().contains(scenePoint)) + { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QToolTip::showText(event->globalPosition().toPoint(), QString("%1,%2").arg(scenePoint.x()/100.0).arg(scenePoint.y()/100.0)); +#else + QToolTip::showText(event->globalPos(), QString("%1m %2m").arg(scenePoint.x()/100.0).arg(scenePoint.y()/100.0)); +#endif + } + else + { + QToolTip::hideText(); + } + QGraphicsView::mouseMoveEvent(event); +} + QIcon createIcon(const QColor & color) { QPixmap pixmap(50, 50); @@ -1878,6 +1898,7 @@ void GraphViewer::contextMenuEvent(QContextMenuEvent * event) QAction * aShowHideGPSGraph; QAction * aShowHideOdomCacheOverlay; QAction * aOrientationENU; + QAction * aMouseTracking; QAction * aViewPlaneXY; QAction * aViewPlaneXZ; QAction * aViewPlaneYZ; @@ -1976,6 +1997,9 @@ void GraphViewer::contextMenuEvent(QContextMenuEvent * event) aOrientationENU = menu.addAction(tr("ENU Orientation")); aOrientationENU->setCheckable(true); aOrientationENU->setChecked(_orientationENU); + aMouseTracking = menu.addAction(tr("Show mouse cursor position (m)")); + aMouseTracking->setCheckable(true); + aMouseTracking->setChecked(_mouseTracking); aShowHideGraph->setEnabled(_nodeItems.size() && _viewPlane == XY); aShowHideGraphNodes->setEnabled(_nodeItems.size() && _graphRoot->isVisible()); aShowHideGlobalPath->setEnabled(_globalPathLinkItems.size()); @@ -2405,6 +2429,10 @@ void GraphViewer::contextMenuEvent(QContextMenuEvent * event) { this->setOrientationENU(!this->isOrientationENU()); } + else if(r == aMouseTracking) + { + _mouseTracking = aMouseTracking->isChecked(); + } else if(r == aViewPlaneXY) { this->setViewPlane(XY);