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:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user