From 13b0e00b2736bb5d4ecb2e69c95f68e9b7fd894e Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Sun, 12 Mar 2023 20:56:14 +0100 Subject: [PATCH] Add variable support to SliderSpinbox --- src/utils/slider-spinbox.cpp | 37 +++++++++++++++++++++++++++--------- src/utils/slider-spinbox.hpp | 11 ++++++++--- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/utils/slider-spinbox.cpp b/src/utils/slider-spinbox.cpp index 7c379c56..7e1e666b 100644 --- a/src/utils/slider-spinbox.cpp +++ b/src/utils/slider-spinbox.cpp @@ -4,7 +4,7 @@ SliderSpinBox::SliderSpinBox(double min, double max, const QString &label, const QString &description, QWidget *parent) : QWidget(parent), - _spinBox(new QDoubleSpinBox()), + _spinBox(new VariableDoubleSpinBox()), _slider(new QSlider()) { _slider->setOrientation(Qt::Horizontal); @@ -15,8 +15,12 @@ SliderSpinBox::SliderSpinBox(double min, double max, const QString &label, connect(_slider, SIGNAL(valueChanged(int)), this, SLOT(SliderValueChanged(int))); - connect(_spinBox, SIGNAL(valueChanged(double)), this, - SLOT(SpinBoxValueChanged(double))); + QWidget::connect( + _spinBox, + SIGNAL(NumberVariableChanged(const NumberVariable &)), + this, + SLOT(SpinBoxValueChanged(const NumberVariable &))); + QVBoxLayout *mainLayout = new QVBoxLayout(); QHBoxLayout *sliderLayout = new QHBoxLayout(); if (!label.isEmpty()) { @@ -33,22 +37,37 @@ SliderSpinBox::SliderSpinBox(double min, double max, const QString &label, } void SliderSpinBox::SetDoubleValue(double value) +{ + NumberVariable temp = value; + SetDoubleValue(temp); +} + +void SliderSpinBox::SetDoubleValue(const NumberVariable &value) { const QSignalBlocker b1(_slider); const QSignalBlocker b2(_spinBox); _slider->setValue(value * _scale); - _spinBox->setValue(value); + _spinBox->SetValue(value); + SetVisibility(value); } -void SliderSpinBox::SpinBoxValueChanged(double value) +void SliderSpinBox::SpinBoxValueChanged(const NumberVariable &value) { - int sliderPos = value * _scale; - _slider->setValue(sliderPos); + if (value.IsFixedType()) { + int sliderPos = value * _scale; + _slider->setValue(sliderPos); + } + SetVisibility(value); emit DoubleValueChanged(value); } void SliderSpinBox::SliderValueChanged(int value) { - double doubleValue = value / _scale; - _spinBox->setValue(doubleValue); + NumberVariable doubleValue = value / _scale; + _spinBox->SetValue(doubleValue); +} + +void SliderSpinBox::SetVisibility(const NumberVariable &value) +{ + _slider->setVisible(value.IsFixedType()); } diff --git a/src/utils/slider-spinbox.hpp b/src/utils/slider-spinbox.hpp index 4d319624..1adc3a2d 100644 --- a/src/utils/slider-spinbox.hpp +++ b/src/utils/slider-spinbox.hpp @@ -1,4 +1,6 @@ #pragma once +#include "variable-spinbox.hpp" + #include #include #include @@ -12,14 +14,17 @@ public: const QString &label = "threshold", const QString &description = "", QWidget *parent = 0); void SetDoubleValue(double); + void SetDoubleValue(const NumberVariable &); public slots: void SliderValueChanged(int value); - void SpinBoxValueChanged(double value); + void SpinBoxValueChanged(const NumberVariable &value); signals: - void DoubleValueChanged(double value); + void DoubleValueChanged(const NumberVariable &value); private: - QDoubleSpinBox *_spinBox; + void SetVisibility(const NumberVariable &); + + VariableDoubleSpinBox *_spinBox; QSlider *_slider; double _scale = 100.0; };