Show current dB value of fader in tool tip
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.
This commit is contained in:
@@ -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; }
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user