Skip to content

Commit

Permalink
Merge pull request #11032 from ronso0/effect-parameter-change-label
Browse files Browse the repository at this point in the history
Effect parameter: briefly show value in parameter name widget
  • Loading branch information
daschuer authored Nov 2, 2022
2 parents db33730 + d360922 commit febc702
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/effects/effectparameterslotbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ void EffectParameterSlotBase::onEffectMetaParameterChanged(double parameter, boo
void EffectParameterSlotBase::slotValueChanged(double v) {
if (m_pEffectParameter) {
m_pEffectParameter->setValue(v);
emit valueChanged(v);
}
}
1 change: 1 addition & 0 deletions src/effects/effectparameterslotbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class EffectParameterSlotBase : public QObject {
signals:
// Signal that indicates that the EffectParameterSlotBase has been updated.
void updated();
void valueChanged(double v);

public slots:
// Solely for handling control changes
Expand Down
33 changes: 29 additions & 4 deletions src/widget/weffectparameternamebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@

namespace {
const QString kMimeTextDelimiter = QStringLiteral("\n");
// for rounding the value display to 2 decimals
constexpr int kValDecimals = 100;
} // anonymous namespace

WEffectParameterNameBase::WEffectParameterNameBase(
QWidget* pParent, EffectsManager* pEffectsManager)
: WLabel(pParent), m_pEffectsManager(pEffectsManager) {
: WLabel(pParent),
m_pEffectsManager(pEffectsManager),
m_text("") {
setAcceptDrops(true);
parameterUpdated();
// When the parameter value changed it is display briefly.
// Set up the timer that restores the parameter name.
m_displayNameResetTimer.setSingleShot(true);
m_displayNameResetTimer.setInterval(800);
m_displayNameResetTimer.callOnTimeout(this, [this]() { setText(m_text); });
}

void WEffectParameterNameBase::setEffectParameterSlot(
Expand All @@ -33,17 +42,33 @@ void WEffectParameterNameBase::setEffectParameterSlot(
void WEffectParameterNameBase::parameterUpdated() {
if (m_pParameterSlot) {
if (!m_pParameterSlot->shortName().isEmpty()) {
setText(m_pParameterSlot->shortName());
m_text = m_pParameterSlot->shortName();
} else {
setText(m_pParameterSlot->name());
m_text = m_pParameterSlot->name();
}
setBaseTooltip(QString("%1\n%2").arg(
m_pParameterSlot->name(),
m_pParameterSlot->description()));
// Make connection to show parameter value instead of name briefly
// after value has changed.
if (m_pParameterSlot->parameterType() == EffectParameterType::Knob) {
connect(m_pParameterSlot.data(),
&EffectParameterSlotBase::valueChanged,
this,
&WEffectParameterNameBase::showNewValue);
}
} else {
setText(kNoEffectString);
m_text = kNoEffectString;
setBaseTooltip(tr("No effect loaded."));
}
setText(m_text);
}

void WEffectParameterNameBase::showNewValue(double newValue) {
double newValRounded =
std::ceil(newValue * kValDecimals) / kValDecimals;
setText(QString::number(newValRounded));
m_displayNameResetTimer.start();
}

void WEffectParameterNameBase::mousePressEvent(QMouseEvent* event) {
Expand Down
4 changes: 4 additions & 0 deletions src/widget/weffectparameternamebase.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <QDomNode>
#include <QTimer>

#include "effects/effectparameterslotbase.h"
#include "skin/legacy/skincontext.h"
Expand All @@ -21,6 +22,7 @@ class WEffectParameterNameBase : public WLabel {

protected slots:
void parameterUpdated();
void showNewValue(double v);

protected:
void setEffectParameterSlot(EffectParameterSlotBasePointer pEffectKnobParameterSlot);
Expand All @@ -31,4 +33,6 @@ class WEffectParameterNameBase : public WLabel {

private:
const QString mimeTextIdentifier() const;
QString m_text;
QTimer m_displayNameResetTimer;
};

0 comments on commit febc702

Please sign in to comment.