Enter fader value when space key pressed

Let the users enter the fader value via dialog when the space key is
pressed.

Extract the dialog logic into the new method `adjustByDialog` and call
it from `MixerView::keyPressEvent`.

Make `Fader::mouseDoubleClickEvent` delegate to `adjustByDialog` and
also fix the behavior by accepting the event.
This commit is contained in:
Michael Gregorius
2025-01-12 14:18:20 +01:00
parent 4a720cb3e5
commit d451531b34
3 changed files with 50 additions and 31 deletions

View File

@@ -102,6 +102,8 @@ public:
void adjust(const Qt::KeyboardModifiers & modifiers, AdjustmentDirection direction);
void adjustByDecibelDelta(float value);
void adjustByDialog();
void setDisplayConversion(bool b)
{
m_conversionFactor = b ? 100.0 : 1.0;

View File

@@ -537,6 +537,16 @@ void MixerView::keyPressEvent(QKeyEvent * e)
case Qt::Key_F2:
renameChannel(m_currentMixerChannel->channelIndex());
break;
case Qt::Key_Space:
{
auto* mixerChannel = currentMixerChannel();
if (mixerChannel)
{
mixerChannel->fader()->adjustByDialog();
}
}
break;
}
}

View File

@@ -119,6 +119,42 @@ void Fader::adjustByDecibelDelta(float value)
s_textFloat->setVisibilityTimeOut(1000);
}
void Fader::adjustByDialog()
{
bool ok;
if (modelIsLinear())
{
auto minDB = m_faderMinDb;
auto maxDB = ampToDbfs(model()->maxValue());
const auto currentValue = model()->value() <= 0. ? m_faderMinDb : ampToDbfs(model()->value());
float enteredValue = QInputDialog::getDouble(this, tr("Set value"),
tr("Please enter a new value between %1 and %2:").arg(minDB).arg(maxDB),
currentValue, minDB, maxDB, model()->getDigitCount(), &ok);
if (ok)
{
model()->setValue(dbfsToAmp(enteredValue));
}
return;
}
else
{
// The model already is in dB
auto minv = model()->minValue() * m_conversionFactor;
auto maxv = model()->maxValue() * m_conversionFactor;
float enteredValue = QInputDialog::getDouble(this, tr("Set value"),
tr("Please enter a new value between %1 and %2:").arg(minv).arg(maxv),
model()->getRoundedValue() * m_conversionFactor, minv, maxv, model()->getDigitCount(), &ok);
if (ok)
{
model()->setValue(enteredValue / m_conversionFactor);
}
}
}
void Fader::contextMenuEvent(QContextMenuEvent* ev)
{
CaptionMenu contextMenu(windowTitle());
@@ -198,38 +234,9 @@ void Fader::mousePressEvent(QMouseEvent* mouseEvent)
void Fader::mouseDoubleClickEvent(QMouseEvent* mouseEvent)
{
bool ok;
adjustByDialog();
if (modelIsLinear())
{
auto minDB = m_faderMinDb;
auto maxDB = ampToDbfs(model()->maxValue());
const auto currentValue = model()->value() <= 0. ? m_faderMinDb : ampToDbfs(model()->value());
float enteredValue = QInputDialog::getDouble(this, tr("Set value"),
tr("Please enter a new value between %1 and %2:").arg(minDB).arg(maxDB),
currentValue, minDB, maxDB, model()->getDigitCount(), &ok);
if (ok)
{
model()->setValue(dbfsToAmp(enteredValue));
}
return;
}
else
{
// The model already is in dB
auto minv = model()->minValue() * m_conversionFactor;
auto maxv = model()->maxValue() * m_conversionFactor;
float enteredValue = QInputDialog::getDouble(this, tr("Set value"),
tr("Please enter a new value between %1 and %2:").arg(minv).arg(maxv),
model()->getRoundedValue() * m_conversionFactor, minv, maxv, model()->getDigitCount(), &ok);
if (ok)
{
model()->setValue(enteredValue / m_conversionFactor);
}
}
mouseEvent->accept();
}