@@ -42,6 +42,8 @@ SpectrogramPlot::SpectrogramPlot(std::shared_ptr<SampleSource<std::complex<float
4242 sampleRate = 0 ;
4343 frequencyScaleEnabled = false ;
4444 sigmfAnnotationsEnabled = true ;
45+ timePointerEnabled = false ;
46+ frequencyPointerEnabled = false ;
4547
4648 for (int i = 0 ; i < 256 ; i++) {
4749 float p = (float )i / 256 ;
@@ -72,6 +74,54 @@ void SpectrogramPlot::paintFront(QPainter &painter, QRect &rect, range_t<size_t>
7274
7375 if (sigmfAnnotationsEnabled)
7476 paintAnnotations (painter, rect, sampleRange);
77+
78+ if (timePointerEnabled || frequencyPointerEnabled)
79+ paintTimeFrequencyPointers (painter, rect, sampleRange);
80+ }
81+
82+ void SpectrogramPlot::paintTimeFrequencyPointers (QPainter &painter, QRect &rect, range_t <size_t > sampleRange)
83+ {
84+ if (sampleRate == 0 ) {
85+ return ;
86+ }
87+
88+ if (sampleRate / 2 > UINT64_MAX) {
89+ return ;
90+ }
91+
92+ int plotHeight = rect.height ();
93+ if (inputSource->realSignal ())
94+ plotHeight *= 2 ;
95+
96+ double bwPerPixel = (double )sampleRate / plotHeight;
97+
98+ painter.save ();
99+
100+ QPen pen (Qt::white, 1 , Qt::SolidLine);
101+ painter.setPen (pen);
102+ QFontMetrics fm (painter.font ());
103+
104+
105+ char buf[128 ];
106+ if (frequencyPointerEnabled) {
107+ int freqHz = ((plotHeight / 2 ) - mouseY) * bwPerPixel;
108+ snprintf (buf, sizeof (buf), " Frequency: %d Hz" , freqHz);
109+
110+ painter.drawLine (0 , mouseY, mouseX, mouseY);
111+ painter.drawText (mouseX + 15 , mouseY, buf);
112+ }
113+ if (timePointerEnabled) {
114+ float timeStart = sampleRange.minimum / sampleRate;
115+ float timeEnd = sampleRange.maximum / sampleRate;
116+ float secondsPerPixel = (timeEnd - timeStart) / rect.width ();
117+ float timeAtPointer = timeStart + mouseX * secondsPerPixel;
118+ snprintf (buf, sizeof (buf), " Time: %.6f s" , timeAtPointer);
119+
120+ painter.drawText (mouseX + 15 , mouseY + fm.height (), buf);
121+ painter.drawLine (mouseX, 0 , mouseX, mouseY);
122+ }
123+
124+ painter.restore ();
75125}
76126
77127void SpectrogramPlot::paintFrequencyScale (QPainter &painter, QRect &rect)
@@ -356,6 +406,11 @@ bool SpectrogramPlot::mouseEvent(QEvent::Type type, QMouseEvent *event)
356406 if (tunerEnabled ())
357407 return tuner.mouseEvent (type, event);
358408
409+ if (timePointerEnabled || frequencyPointerEnabled) {
410+ mouseX = event->x ();
411+ mouseY = event->y ();
412+ }
413+
359414 return false ;
360415}
361416
@@ -448,6 +503,11 @@ void SpectrogramPlot::tunerMoved()
448503 emit repaint ();
449504}
450505
506+ void SpectrogramPlot::enableTimeFrequencyPointers (bool timePointer, bool frequencyPointer) {
507+ timePointerEnabled = timePointer;
508+ frequencyPointerEnabled = frequencyPointer;
509+ }
510+
451511uint qHash (const TileCacheKey &key, uint seed)
452512{
453513 return key.fftSize ^ key.zoomLevel ^ key.sample ^ seed;
0 commit comments