From be0084b76a40d0f1c5fefcdc0d41f6432d471216 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Tue, 24 Dec 2024 14:47:49 +0100 Subject: [PATCH] Show current dB value of fader in tool tip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Show the current value of the fader in its tool tip. Please note that this value is always shown in dB because the goal should be to get rid of the linear values for the faders. Some of the code is extracted into the new method `Fader::getModelValueAsDbString` which is shared by `Fader::modelValueChanged` (also new) and `Fader::updateTextFloat`. Please note that `getModelValueAsDbString` will use "dB" instead of "dBFS" as the unit and that it will format "-inf dB" instead of "-∞ dB". These changes will also be visible in the text float that is used to show the new values as the fader is being dragged. --- include/Fader.h | 2 ++ src/gui/widgets/Fader.cpp | 50 ++++++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/include/Fader.h b/include/Fader.h index 1fa8f4882..becdfeeb2 100644 --- a/include/Fader.h +++ b/include/Fader.h @@ -125,6 +125,8 @@ private: void setPeak(float fPeak, float& targetPeak, float& persistentPeak, QElapsedTimer& lastPeakTimer); void updateTextFloat(); + void modelValueChanged(); + QString getModelValueAsDbString() const; bool modelIsLinear() const { return m_modelIsLinear; } diff --git a/src/gui/widgets/Fader.cpp b/src/gui/widgets/Fader.cpp index 398b4a31b..602fc79e1 100644 --- a/src/gui/widgets/Fader.cpp +++ b/src/gui/widgets/Fader.cpp @@ -83,6 +83,17 @@ Fader::Fader(FloatModel* model, const QString& name, QWidget* parent, bool model setHintText("Volume:", "%"); m_conversionFactor = 100.0; + + if (model) + { + // We currently assume that the model is not changed later on and only connect here once + + // This is for example used to update the tool tip which shows the current value of the fader + connect(model, &FloatModel::dataChanged, this, &Fader::modelValueChanged); + + // Trigger manually so that the tool tip is initialized correctly + modelValueChanged(); + } } @@ -346,17 +357,7 @@ void Fader::updateTextFloat() { if (ConfigManager::inst()->value("app", "displaydbfs").toInt() && m_conversionFactor == 100.0) { - QString label(tr("Volume: %1 dBFS")); - - auto const modelValue = model()->value(); - if (modelValue <= 0.) - { - s_textFloat->setText(label.arg("-∞")); - } - else - { - s_textFloat->setText(label.arg(ampToDbfs(modelValue), 3, 'f', 2)); - } + s_textFloat->setText(getModelValueAsDbString()); } else { @@ -366,6 +367,33 @@ void Fader::updateTextFloat() s_textFloat->moveGlobal(this, QPoint(width() + 2, calculateKnobPosYFromModel() - s_textFloat->height() / 2)); } +void Fader::modelValueChanged() +{ + setToolTip(getModelValueAsDbString()); +} + +QString Fader::getModelValueAsDbString() const +{ + const auto value = model()->value(); + + QString label(tr("Volume: %1 dB")); + + if (modelIsLinear()) + { + if (value <= 0.) + { + return label.arg(tr("-inf")); + } + else + { + return label.arg(ampToDbfs(value), 3, 'f', 2); + } + } + else + { + return label.arg(value, 3, 'f', 2); + } +} void Fader::paintEvent(QPaintEvent* ev) {