summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUwe Klotz <uklotz@mixxx.org>2020-12-05 13:45:11 +0100
committerUwe Klotz <uklotz@mixxx.org>2020-12-05 13:45:11 +0100
commitbf343d2677f19d1886682c4bd15e26f70884ce27 (patch)
treedf252407d939038800bde40f9e2da7e0da67d16f /src
parentb5e172912d87e3dd5f09c4794fbacaa38e4d5884 (diff)
parentac8f705385d61c996a32c185ef5892742e6501e4 (diff)
Merge branch '2.2' of git@github.com:mixxxdj/mixxx.git into 2.3
# Conflicts: # src/widget/wnumberrate.cpp
Diffstat (limited to 'src')
-rw-r--r--src/widget/wnumberrate.cpp27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/widget/wnumberrate.cpp b/src/widget/wnumberrate.cpp
index 048e840c91..04ce8c18bd 100644
--- a/src/widget/wnumberrate.cpp
+++ b/src/widget/wnumberrate.cpp
@@ -16,6 +16,20 @@
#include "control/controlproxy.h"
#include "util/math.h"
+namespace {
+
+inline QChar sign(double number) {
+ if (number > 0) {
+ return '+';
+ }
+ if (number < 0) {
+ return '-';
+ }
+ return ' ';
+}
+
+} // namespace
+
WNumberRate::WNumberRate(const QString& group, QWidget* parent)
: WNumber(parent) {
m_pRateRatio = new ControlProxy(group, "rate_ratio", this, ControlFlag::NoAssertIfMissing);
@@ -30,13 +44,8 @@ void WNumberRate::setup(const QDomNode& node, const SkinContext& context) {
}
void WNumberRate::setValue(double dValue) {
- double vsign = dValue - 1;
-
- char sign = '+';
- if (vsign < -0.00000001) {
- sign = '-';
- }
-
- setText(QString(m_skinText).append(sign)
- .append("%1").arg(fabs(vsign) * 100.0, 0, 'f', m_iNoDigits));
+ const double digitFactor = pow(10, m_iNoDigits);
+ // Calculate percentage rounded to the number of digits specified by iNoDigits
+ const double percentage = round((dValue - 1) * 100.0 * digitFactor) / digitFactor;
+ setText(m_skinText + sign(percentage) + QString::number(fabs(percentage), 'f', m_iNoDigits));
}