GraphViewer: added "Show mouse cursor position (m)" context menu option.

This commit is contained in:
matlabbe
2024-02-26 17:13:50 -08:00
parent 752ca76cf5
commit fccf33dd96
2 changed files with 30 additions and 0 deletions

View File

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