summaryrefslogtreecommitdiffstats
path: root/src/widget/wraterange.cpp
diff options
context:
space:
mode:
authorKatsarov <me@katsarov.info>2020-07-14 22:01:47 +0200
committerJan Holthuis <jan.holthuis@ruhr-uni-bochum.de>2021-03-11 22:42:18 +0100
commit274fcc8137455de703bd88918629623192e38b15 (patch)
tree1407ebd8c3ec2f9018d2439aab796d6f88bc839f /src/widget/wraterange.cpp
parent28f0c8448af6faa806720c829d1826941732fa30 (diff)
widget: Add WRateRange widget for displaying the current rate slider range
Diffstat (limited to 'src/widget/wraterange.cpp')
-rw-r--r--src/widget/wraterange.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/widget/wraterange.cpp b/src/widget/wraterange.cpp
new file mode 100644
index 0000000000..42c5f7d678
--- /dev/null
+++ b/src/widget/wraterange.cpp
@@ -0,0 +1,67 @@
+#include "widget/wraterange.h"
+
+#include "control/controlobject.h"
+#include "control/controlproxy.h"
+#include "moc_wraterange.cpp"
+#include "util/math.h"
+
+WRateRange::WRateRange(const QString& group, QWidget* parent)
+ : WNumber(parent) {
+ m_pRateRangeControl = new ControlProxy(
+ group, "rateRange", this, ControlFlag::NoAssertIfMissing);
+ m_pRateRangeControl->connectValueChanged(this, &WRateRange::setValue);
+ m_pRateDirControl = new ControlProxy(
+ group, "rate_dir", this, ControlFlag::NoAssertIfMissing);
+ m_pRateDirControl->connectValueChanged(this, &WRateRange::slotRateDirChanged);
+}
+
+void WRateRange::setup(const QDomNode& node, const SkinContext& context) {
+ WNumber::setup(node, context);
+
+ QDomElement RateRangePosition = context.selectElement(node, "Position");
+ QDomElement RateRangeType = context.selectElement(node, "Display");
+ m_nodePosition = RateRangePosition.text() == "Top"
+ ? VerticalPosition::Top
+ : VerticalPosition::Bottom;
+ if (RateRangeType.text() == "prefix") {
+ m_nodeDisplay = DisplayType::Prefix;
+ } else if (RateRangeType.text() == "range") {
+ m_nodeDisplay = DisplayType::Range;
+ } else {
+ m_nodeDisplay = DisplayType::Default;
+ }
+
+ // Initialize the widget (overrides the base class initial value).
+ const double range = m_pRateRangeControl->get();
+ setValue(range);
+}
+
+void WRateRange::slotRateDirChanged(double dir) {
+ Q_UNUSED(dir);
+
+ const double range = m_pRateRangeControl->get();
+ setValue(range);
+}
+
+void WRateRange::setValue(double range) {
+ const double direction = m_pRateDirControl->get();
+
+ QString prefix('-');
+ if (m_nodePosition == VerticalPosition::Top && direction > 0) {
+ prefix = '+';
+ }
+
+ if (m_nodePosition == VerticalPosition::Bottom && direction < 0) {
+ prefix = '+';
+ }
+
+ if (m_nodeDisplay == DisplayType::Prefix) {
+ m_nodeText = prefix;
+ } else if (m_nodeDisplay == DisplayType::Range) {
+ m_nodeText = QString::number(range * 100).append("\%");
+ } else {
+ m_nodeText = prefix.append(QString::number(range * 100)).append("\%");
+ }
+
+ setText(m_nodeText);
+}