Skip to content

Commit

Permalink
GraphViewer: added "Show mouse cursor position (m)" context menu option.
Browse files Browse the repository at this point in the history
  • Loading branch information
matlabbe committed Feb 27, 2024
1 parent 752ca76 commit fccf33d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions guilib/include/rtabmap/gui/GraphViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public Q_SLOTS:

protected:
virtual void wheelEvent ( QWheelEvent * event );
virtual void mouseMoveEvent(QMouseEvent * event);
virtual void contextMenuEvent(QContextMenuEvent * event);

private:
Expand Down Expand Up @@ -228,6 +229,7 @@ public Q_SLOTS:
float _loopClosureOutlierThr;
float _maxLinkLength;
bool _orientationENU;
bool _mouseTracking;
ViewPlane _viewPlane;
bool _ensureFrameVisible;
};
Expand Down
28 changes: 28 additions & 0 deletions guilib/src/GraphViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endif
#include <QInputDialog>
#include <QMessageBox>
#include <QToolTip>

#include <QtCore/QDir>
#include <QtCore/QDateTime>
Expand Down Expand Up @@ -316,6 +317,7 @@ GraphViewer::GraphViewer(QWidget * parent) :
_loopClosureOutlierThr(0),
_maxLinkLength(0.02f),
_orientationENU(false),
_mouseTracking(false),
_viewPlane(XY),
_ensureFrameVisible(true)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1878,6 +1898,7 @@ void GraphViewer::contextMenuEvent(QContextMenuEvent * event)
QAction * aShowHideGPSGraph;
QAction * aShowHideOdomCacheOverlay;
QAction * aOrientationENU;
QAction * aMouseTracking;
QAction * aViewPlaneXY;
QAction * aViewPlaneXZ;
QAction * aViewPlaneYZ;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit fccf33d

Please sign in to comment.