From 20da400b2122f299f4aba47a81a2115b2c56b4aa Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 16 Feb 2021 07:25:22 +0100 Subject: [PATCH] Spectrum: added top info line with zooming info --- sdrgui/gui/glspectrum.cpp | 65 +++++++++++++++++++++++++++++++++++++-- sdrgui/gui/glspectrum.h | 6 ++++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/sdrgui/gui/glspectrum.cpp b/sdrgui/gui/glspectrum.cpp index f77db9c0e..8ec12a552 100644 --- a/sdrgui/gui/glspectrum.cpp +++ b/sdrgui/gui/glspectrum.cpp @@ -613,6 +613,7 @@ void GLSpectrum::initializeGL() m_glShaderWaterfall.initializeGL(); m_glShaderHistogram.initializeGL(); m_glShaderTextOverlay.initializeGL(); + m_glShaderInfo.initializeGL(); } void GLSpectrum::resizeGL(int width, int height) @@ -1114,6 +1115,24 @@ void GLSpectrum::paintGL() } } + // Paint info line + { + GLfloat vtx1[] = { + 0, 1, + 1, 1, + 1, 0, + 0, 0 + }; + GLfloat tex1[] = { + 0, 1, + 1, 1, + 1, 0, + 0, 0 + }; + + m_glShaderInfo.drawSurface(m_glInfoBoxMatrix, tex1, vtx1, 4); + } + m_mutex.unlock(); } @@ -1275,8 +1294,9 @@ void GLSpectrum::applyChanges() QFontMetrics fm(font()); int M = fm.horizontalAdvance("-"); - m_topMargin = fm.ascent() * 1.5; - m_bottomMargin = fm.ascent() * 1.5; + m_topMargin = fm.ascent() * 2.0; + m_bottomMargin = fm.ascent() * 1.0; + m_infoHeight = fm.height() * 3; int waterfallTop = 0; m_frequencyScaleHeight = fm.height() * 3; // +1 line for marker frequency scale @@ -1844,6 +1864,39 @@ void GLSpectrum::applyChanges() m_glShaderFrequencyScale.initTexture(m_frequencyPixmap.toImage()); } + // Top info line + m_glInfoBoxMatrix.setToIdentity(); + m_glInfoBoxMatrix.translate ( + -1.0f, + 1.0f + ); + m_glInfoBoxMatrix.scale ( + 2.0f, + (float) -2*m_infoHeight / (float) height() + ); + m_infoRect = QRect( + 0, + 0, + width(), + m_infoHeight + ); + QString infoText; + formatTextInfo(infoText); + m_infoPixmap = QPixmap(width(), m_infoHeight); + m_infoPixmap.fill(Qt::transparent); + { + QPainter painter(&m_infoPixmap); + painter.setPen(Qt::NoPen); + painter.setBrush(Qt::black); + painter.setBrush(Qt::transparent); + painter.drawRect(m_leftMargin, 0, width() - m_leftMargin, m_infoHeight); + painter.setPen(QColor(0xf0, 0xf0, 0xff)); + painter.setFont(font()); + painter.drawText(QPointF(m_leftMargin, fm.height() + fm.ascent() / 2 - 1), infoText); + } + + m_glShaderInfo.initTexture(m_infoPixmap.toImage()); + bool fftSizeChanged = true; if (m_waterfallBuffer) { @@ -2413,6 +2466,7 @@ void GLSpectrum::cleanup() m_glShaderLeftScale.cleanup(); m_glShaderWaterfall.cleanup(); m_glShaderTextOverlay.cleanup(); + m_glShaderInfo.cleanup(); //doneCurrent(); } @@ -2543,3 +2597,10 @@ void GLSpectrum::drawTextOverlay( m_glShaderTextOverlay.drawSurface(mat, tex1, vtx1, 4); } } + +void GLSpectrum::formatTextInfo(QString& info) +{ + if (m_frequencyZoomFactor != 1.0f) { + info.append(tr("%1x ").arg(QString::number(m_frequencyZoomFactor, 'f', 1))); + } +} diff --git a/sdrgui/gui/glspectrum.h b/sdrgui/gui/glspectrum.h index 78aaee359..cf73ca682 100644 --- a/sdrgui/gui/glspectrum.h +++ b/sdrgui/gui/glspectrum.h @@ -272,20 +272,24 @@ private: int m_rightMargin; int m_topMargin; int m_frequencyScaleHeight; + int m_infoHeight; int m_histogramHeight; int m_waterfallHeight; int m_bottomMargin; QFont m_textOverlayFont; QPixmap m_leftMarginPixmap; QPixmap m_frequencyPixmap; + QPixmap m_infoPixmap; ScaleEngine m_timeScale; ScaleEngine m_powerScale; ScaleEngine m_frequencyScale; QRectF m_histogramRect; QRect m_frequencyScaleRect; QRectF m_waterfallRect; + QRect m_infoRect; QMatrix4x4 m_glFrequencyScaleBoxMatrix; QMatrix4x4 m_glLeftScaleBoxMatrix; + QMatrix4x4 m_glInfoBoxMatrix; QRgb m_waterfallPalette[240]; QImage* m_waterfallBuffer; @@ -319,6 +323,7 @@ private: GLShaderTextured m_glShaderWaterfall; GLShaderTextured m_glShaderHistogram; GLShaderTextured m_glShaderTextOverlay; + GLShaderTextured m_glShaderInfo; int m_matrixLoc; int m_colorLoc; IncrementalArray m_q3TickTime; @@ -365,6 +370,7 @@ private: bool leftHalf, bool topHalf, const QRectF& glRect); + void formatTextInfo(QString& info); private slots: void cleanup();