From fe53a53dc4e5ae16b9b69730e3a4de11642ccf3d Mon Sep 17 00:00:00 2001 From: Martin Piatka Date: Mon, 22 Feb 2021 13:41:19 +0100 Subject: [PATCH] GUI: vuMeter: Indicate if not connected to control socket --- gui/QT/widget/vuMeterWidget.cpp | 31 +++++++++++++++++++++++++------ gui/QT/widget/vuMeterWidget.hpp | 2 ++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/gui/QT/widget/vuMeterWidget.cpp b/gui/QT/widget/vuMeterWidget.cpp index ce324c7ec..a51352217 100644 --- a/gui/QT/widget/vuMeterWidget.cpp +++ b/gui/QT/widget/vuMeterWidget.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "vuMeterWidget.hpp" constexpr double VuMeterWidget::zeroLevel; @@ -43,6 +44,9 @@ void VuMeterWidget::updateVolumes(){ int count; bool ret = ug_control_get_volumes(ug_c, peak, rms, &count); + connected = ret; + setToolTip(connected ? "" : "Unable to read volume info from UG"); + if(!ret){ last_connect = std::chrono::system_clock::now(); connect_ug(); @@ -70,11 +74,13 @@ void VuMeterWidget::paintMeter(QPainter& painter, gradient.setColorAt(1, Qt::green); QBrush brush(gradient); - painter.fillRect(x, y, width, height, Qt::black); - painter.fillRect(x + meterBarPad, - y + meterBarPad + (in_full_height - barHeight), - in_width, barHeight, - brush); + painter.fillRect(x, y, width, height, connected ? Qt::black : Qt::gray); + if(connected){ + painter.fillRect(x + meterBarPad, + y + meterBarPad + (in_full_height - barHeight), + in_width, barHeight, + brush); + } int pos = y + meterBarPad + (in_full_height - rmsHeight); @@ -92,7 +98,7 @@ void VuMeterWidget::paintScale(QPainter& painter, const int barStart = y + meterVerticalPad + meterBarPad; const float stepPx = (float) barHeight / std::fabs(zeroLevel); - painter.setPen(Qt::black); + painter.setPen(connected ? Qt::black : Qt::gray); int i = 0; for(float y = barStart; y <= barStart + barHeight + 0.1; y += stepPx){ static const int lineLenghtSmall = 2; @@ -113,6 +119,19 @@ void VuMeterWidget::paintScale(QPainter& painter, i++; } + + if(!connected){ + int iconDim = 32; + QIcon icon = style()->standardIcon(QStyle::SP_MessageBoxWarning); + QPixmap pixmap = icon.pixmap(iconDim,iconDim); + painter.eraseRect(x+width/2 - (iconDim+4)/2, y + height / 2 - (iconDim+4)/2, + iconDim+4, iconDim+4); + painter.drawPixmap(x+width/2 - iconDim/2, y + height / 2 - iconDim/2, + iconDim, iconDim, + pixmap, + 0, 0, + iconDim, iconDim); + } } void VuMeterWidget::paintEvent(QPaintEvent * /*paintEvent*/){ diff --git a/gui/QT/widget/vuMeterWidget.hpp b/gui/QT/widget/vuMeterWidget.hpp index 9a6e1eac1..6db1f35a4 100644 --- a/gui/QT/widget/vuMeterWidget.hpp +++ b/gui/QT/widget/vuMeterWidget.hpp @@ -55,6 +55,8 @@ private: double rmsLevel[num_channels]; int updatesPerSecond; + bool connected = false; + void updateVolumes(); void connect_ug(); void disconnect_ug();