Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Effect parameter: briefly show value in parameter name widget #11032

Merged
merged 1 commit into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
ronso0 marked this conversation as resolved.
Show resolved Hide resolved
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;
};