mirror of
https://github.com/miek/inspectrum.git
synced 2026-03-05 16:04:20 +01:00
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user