Display annotation comments as tooltips

When the mouse is moved over a SigMF annotation rectangle on the
waterfall, a tooltip showing the annotation comment is displayed
(if the annotation has a comment field).

This feature can be enabled/disabled with a checkbox, in the same
way as annotations. If annotations are disabled, the annotation comments
checkbox is grayed out and the tooltips are not shown.

Signed-off-by: Daniel Estévez <daniel@destevez.net>
This commit is contained in:
Daniel Estévez
2022-10-25 22:32:26 +02:00
parent 6b8a4408db
commit 11171c8e62
9 changed files with 115 additions and 3 deletions

View File

@@ -32,6 +32,7 @@
#include <QRadioButton>
#include <QScrollBar>
#include <QSpinBox>
#include <QToolTip>
#include <QVBoxLayout>
#include "plots.h"
@@ -50,6 +51,7 @@ PlotView::PlotView(InputSource *input) : cursors(this), viewRange({0, 0})
enableScales(true);
enableAnnotations(true);
enableAnnotationCommentsTooltips(true);
addPlot(spectrogramPlot);
@@ -62,6 +64,39 @@ void PlotView::addPlot(Plot *plot)
connect(plot, &Plot::repaint, this, &PlotView::repaint);
}
void PlotView::mouseMoveEvent(QMouseEvent *event)
{
updateAnnotationTooltip(event);
QGraphicsView::mouseMoveEvent(event);
}
void PlotView::mouseReleaseEvent(QMouseEvent *event)
{
// This is used to show the tooltip again on drag release if the mouse is
// hovering over an annotation.
updateAnnotationTooltip(event);
QGraphicsView::mouseReleaseEvent(event);
}
void PlotView::updateAnnotationTooltip(QMouseEvent *event)
{
// If there are any mouse buttons pressed, we assume
// that the plot is being dragged and hide the tooltip.
bool isDrag = event->buttons() != Qt::NoButton;
if (!annotationCommentsEnabled
|| !spectrogramPlot->isAnnotationsEnabled()
|| isDrag) {
QToolTip::hideText();
} else {
QString* comment = spectrogramPlot->mouseAnnotationComment(event);
if (comment != nullptr) {
QToolTip::showText(event->globalPos(), *comment);
} else {
QToolTip::hideText();
}
}
}
void PlotView::contextMenuEvent(QContextMenuEvent * event)
{
QMenu menu;
@@ -612,6 +647,13 @@ void PlotView::enableAnnotations(bool enabled)
viewport()->update();
}
void PlotView::enableAnnotationCommentsTooltips(bool enabled)
{
annotationCommentsEnabled = enabled;
viewport()->update();
}
int PlotView::sampleToColumn(size_t sample)
{
return sample / samplesPerColumn();