Skip to content

Commit

Permalink
WEffectParameterNameBase: adjust value decimals per range
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Nov 5, 2022
1 parent e34ed56 commit 1d806e8
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/widget/weffectparameternamebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
namespace {
const QString kMimeTextDelimiter = QStringLiteral("\n");
// for rounding the value display to 2 decimals
constexpr int kValDecimals = 100;
constexpr int kVal2Decimals = 100;
constexpr int kVal1Decimals = 10;
} // anonymous namespace

WEffectParameterNameBase::WEffectParameterNameBase(
Expand Down Expand Up @@ -75,14 +76,20 @@ void WEffectParameterNameBase::parameterUpdated() {
}

void WEffectParameterNameBase::showNewValue(double newValue) {
// TODO(ronso0) Trim decimals if value string is longer than X digits to
// prevent labels to expand.
double newValRounded =
std::ceil(newValue * kValDecimals) / kValDecimals;
int absVal = abs(static_cast<int>(round(newValue)));
double dispVal;
if (absVal < 100) { // Round to 2 decimals
dispVal = std::ceil(newValue * kVal2Decimals) / kVal2Decimals;
} else if (absVal < 1000) { // Round to 2 decimals
dispVal = std::ceil(newValue * kVal1Decimals) / kVal1Decimals;
} else if (absVal >= 1000) { // Show only integer part
dispVal = round(newValue);
}

if (m_unitString.isEmpty()) {
setText(QString::number(newValRounded));
setText(QString::number(dispVal));
} else {
setText(QString::number(newValRounded) + QChar(' ') + m_unitString);
setText(QString::number(dispVal) + QChar(' ') + m_unitString);
}
m_displayNameResetTimer.start();
}
Expand Down

0 comments on commit 1d806e8

Please sign in to comment.