3232#include < QRadioButton>
3333#include < QScrollBar>
3434#include < QSpinBox>
35+ #include < QToolTip>
3536#include < QVBoxLayout>
3637#include " plots.h"
3738
@@ -50,6 +51,7 @@ PlotView::PlotView(InputSource *input) : cursors(this), viewRange({0, 0})
5051 enableScales (true );
5152
5253 enableAnnotations (true );
54+ enableAnnotationCommentsTooltips (true );
5355
5456 addPlot (spectrogramPlot);
5557
@@ -62,6 +64,39 @@ void PlotView::addPlot(Plot *plot)
6264 connect (plot, &Plot::repaint, this , &PlotView::repaint);
6365}
6466
67+ void PlotView::mouseMoveEvent (QMouseEvent *event)
68+ {
69+ updateAnnotationTooltip (event);
70+ QGraphicsView::mouseMoveEvent (event);
71+ }
72+
73+ void PlotView::mouseReleaseEvent (QMouseEvent *event)
74+ {
75+ // This is used to show the tooltip again on drag release if the mouse is
76+ // hovering over an annotation.
77+ updateAnnotationTooltip (event);
78+ QGraphicsView::mouseReleaseEvent (event);
79+ }
80+
81+ void PlotView::updateAnnotationTooltip (QMouseEvent *event)
82+ {
83+ // If there are any mouse buttons pressed, we assume
84+ // that the plot is being dragged and hide the tooltip.
85+ bool isDrag = event->buttons () != Qt::NoButton;
86+ if (!annotationCommentsEnabled
87+ || !spectrogramPlot->isAnnotationsEnabled ()
88+ || isDrag) {
89+ QToolTip::hideText ();
90+ } else {
91+ QString* comment = spectrogramPlot->mouseAnnotationComment (event);
92+ if (comment != nullptr ) {
93+ QToolTip::showText (event->globalPos (), *comment);
94+ } else {
95+ QToolTip::hideText ();
96+ }
97+ }
98+ }
99+
65100void PlotView::contextMenuEvent (QContextMenuEvent * event)
66101{
67102 QMenu menu;
@@ -612,6 +647,13 @@ void PlotView::enableAnnotations(bool enabled)
612647 viewport ()->update ();
613648}
614649
650+ void PlotView::enableAnnotationCommentsTooltips (bool enabled)
651+ {
652+ annotationCommentsEnabled = enabled;
653+
654+ viewport ()->update ();
655+ }
656+
615657int PlotView::sampleToColumn (size_t sample)
616658{
617659 return sample / samplesPerColumn ();
0 commit comments