@@ -72,6 +72,54 @@ void SpectrogramPlot::paintFront(QPainter &painter, QRect &rect, range_t<size_t>
7272
7373 if (sigmfAnnotationsEnabled)
7474 paintAnnotations (painter, rect, sampleRange);
75+
76+ if (timePointerEnabled || frequencyPointerEnabled)
77+ paintTimeFrequencyPointers (painter, rect, sampleRange);
78+ }
79+
80+ void SpectrogramPlot::paintTimeFrequencyPointers (QPainter &painter, QRect &rect, range_t <size_t > sampleRange)
81+ {
82+ if (sampleRate == 0 ) {
83+ return ;
84+ }
85+
86+ if (sampleRate / 2 > UINT64_MAX) {
87+ return ;
88+ }
89+
90+ int plotHeight = rect.height ();
91+ if (inputSource->realSignal ())
92+ plotHeight *= 2 ;
93+
94+ double bwPerPixel = (double )sampleRate / plotHeight;
95+
96+ painter.save ();
97+
98+ QPen pen (Qt::white, 1 , Qt::SolidLine);
99+ painter.setPen (pen);
100+ QFontMetrics fm (painter.font ());
101+
102+
103+ char buf[128 ];
104+ if (frequencyPointerEnabled) {
105+ int freqHz = ((plotHeight / 2 ) - mouseY) * bwPerPixel;
106+ snprintf (buf, sizeof (buf), " Frequency: %d Hz" , freqHz);
107+
108+ painter.drawLine (0 , mouseY, mouseX, mouseY);
109+ painter.drawText (mouseX + 15 , mouseY, buf);
110+ }
111+ if (timePointerEnabled) {
112+ float timeStart = sampleRange.minimum / sampleRate;
113+ float timeEnd = sampleRange.maximum / sampleRate;
114+ float secondsPerPixel = (timeEnd - timeStart) / rect.width ();
115+ float timeAtPointer = timeStart + mouseX * secondsPerPixel;
116+ snprintf (buf, sizeof (buf), " Time: %.6f s" , timeAtPointer);
117+
118+ painter.drawText (mouseX + 15 , mouseY + fm.height (), buf);
119+ painter.drawLine (mouseX, 0 , mouseX, mouseY);
120+ }
121+
122+ painter.restore ();
75123}
76124
77125void SpectrogramPlot::paintFrequencyScale (QPainter &painter, QRect &rect)
@@ -356,6 +404,11 @@ bool SpectrogramPlot::mouseEvent(QEvent::Type type, QMouseEvent *event)
356404 if (tunerEnabled ())
357405 return tuner.mouseEvent (type, event);
358406
407+ if (timePointerEnabled || frequencyPointerEnabled) {
408+ mouseX = event->x ();
409+ mouseY = event->y ();
410+ }
411+
359412 return false ;
360413}
361414
@@ -448,6 +501,11 @@ void SpectrogramPlot::tunerMoved()
448501 emit repaint ();
449502}
450503
504+ void SpectrogramPlot::enableTimeFrequencyPointers (bool timePointer, bool frequencyPointer) {
505+ timePointerEnabled = timePointer;
506+ frequencyPointerEnabled = frequencyPointer;
507+ }
508+
451509uint qHash (const TileCacheKey &key, uint seed)
452510{
453511 return key.fftSize ^ key.zoomLevel ^ key.sample ^ seed;
0 commit comments