From 70700ee4dccd123397b86f7b23658f4c55c1ef45 Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 28 Oct 2015 09:27:51 +0100 Subject: [PATCH] Channel Analyzer: display trace max and average power. Interim state #2 --- include/gui/glscope.h | 7 ++++++- sdrbase/gui/glscope.cpp | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/include/gui/glscope.h b/include/gui/glscope.h index 61b5f8448..8c34fbe1f 100644 --- a/include/gui/glscope.h +++ b/include/gui/glscope.h @@ -29,6 +29,7 @@ class DSPEngine; class ScopeVis; +class QPainter; class SDRANGEL_API GLScope: public QGLWidget { Q_OBJECT @@ -124,18 +125,22 @@ private: QRectF m_glLeft2ScaleRect; QRectF m_glBot1ScaleRect; QRectF m_glBot2ScaleRect; + QRectF m_glPowerOverlay1; QPixmap m_left1ScalePixmap; QPixmap m_left2ScalePixmap; QPixmap m_bot1ScalePixmap; QPixmap m_bot2ScalePixmap; + QPixmap m_powerOverlayPixmap1; bool m_left1ScaleTextureAllocated; bool m_left2ScaleTextureAllocated; bool m_bot1ScaleTextureAllocated; bool m_bot2ScaleTextureAllocated; + bool m_powerOverlayTextureAllocated1; GLuint m_left1ScaleTexture; GLuint m_left2ScaleTexture; GLuint m_bot1ScaleTexture; GLuint m_bot2ScaleTexture; + GLuint m_powerOverlayTexture1; ScaleEngine m_x1Scale; ScaleEngine m_x2Scale; ScaleEngine m_y1Scale; @@ -149,7 +154,7 @@ private: void handleMode(); void applyConfig(); - void drawPowerOverlay(); + void drawPowerOverlay(QPainter *painter); protected slots: void tick(); diff --git a/sdrbase/gui/glscope.cpp b/sdrbase/gui/glscope.cpp index 8440240cc..e40cd1c27 100644 --- a/sdrbase/gui/glscope.cpp +++ b/sdrbase/gui/glscope.cpp @@ -422,7 +422,9 @@ void GLScope::paintGL() { if (m_nbPow > 0) { - qDebug("%.1f %.1f", 10.0f * log10f(m_maxPow), 10.0f * log10f(m_sumPow / m_nbPow)); + QPainter painter(this); + drawPowerOverlay(&painter); + painter.end(); } } @@ -805,9 +807,21 @@ void GLScope::handleMode() } } -void GLScope::drawPowerOverlay() +void GLScope::drawPowerOverlay(QPainter *painter) { + //qDebug("%.1f %.1f", 10.0f * log10f(m_maxPow), 10.0f * log10f(m_sumPow / m_nbPow)); + double maxPow = 10.0f * log10f(m_maxPow); + double avgPow = 10.0f * log10f(m_sumPow / m_nbPow); + double peakToAvgPow = maxPow - avgPow; + QString text("test"); + + QFontMetrics metrics = QFontMetrics(font()); + QRect rect = metrics.boundingRect(0, 0, width(), int(height()*0.125), Qt::AlignLeft | Qt::TextWordWrap, text); + painter->setRenderHint(QPainter::TextAntialiasing); + painter->fillRect(QRect(0, 0, width(), rect.height()), QColor(0, 0, 0, 127)); + painter->setPen(Qt::white); + painter->drawText(0, 0, rect.width(), rect.height(), Qt::AlignLeft | Qt::TextWordWrap, text); } void GLScope::applyConfig() @@ -816,11 +830,14 @@ void GLScope::applyConfig() QFontMetrics fm(font()); int M = fm.width("-"); + int H = fm.height(); int topMargin = 5; int botMargin = 20; int leftMargin = 35; int rightMargin = 5; + int powerOverlayWidth = 20*M; + int powerOverlayHeight = 2*H; float pow_floor = -100.0 + m_ofs * 100.0; float pow_range = 100.0 / m_amp; @@ -905,6 +922,12 @@ void GLScope::applyConfig() (float) scopeWidth / (float) width(), (float) (botMargin - 1) / (float) height() ); + m_glPowerOverlay1 = QRectF( + (float) leftMargin / (float) width(), + (float) topMargin / (float) height(), + (float) powerOverlayWidth / (float) width(), + (float) powerOverlayHeight / (float) height() + ); { // Y1 scale m_y1Scale.setSize(scopeHeight); @@ -1090,6 +1113,12 @@ void GLScope::applyConfig() (float) scopeWidth / (float) width(), (float) (botMargin - 1) / (float) height() ); + m_glPowerOverlay1 = QRectF( + (float) leftMargin / (float) width(), + (float) topMargin / (float) height(), + (float) powerOverlayWidth / (float) width(), + (float) powerOverlayHeight / (float) height() + ); { // Y1 scale m_y1Scale.setSize(scopeHeight);