Add variable support to SliderSpinbox

This commit is contained in:
WarmUpTill 2023-03-12 20:56:14 +01:00 committed by WarmUpTill
parent bf5d8ca19e
commit 13b0e00b27
2 changed files with 36 additions and 12 deletions

View File

@ -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<double> &)),
this,
SLOT(SpinBoxValueChanged(const NumberVariable<double> &)));
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<double> temp = value;
SetDoubleValue(temp);
}
void SliderSpinBox::SetDoubleValue(const NumberVariable<double> &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<double> &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<double> doubleValue = value / _scale;
_spinBox->SetValue(doubleValue);
}
void SliderSpinBox::SetVisibility(const NumberVariable<double> &value)
{
_slider->setVisible(value.IsFixedType());
}

View File

@ -1,4 +1,6 @@
#pragma once
#include "variable-spinbox.hpp"
#include <QWidget>
#include <QSlider>
#include <QLabel>
@ -12,14 +14,17 @@ public:
const QString &label = "threshold",
const QString &description = "", QWidget *parent = 0);
void SetDoubleValue(double);
void SetDoubleValue(const NumberVariable<double> &);
public slots:
void SliderValueChanged(int value);
void SpinBoxValueChanged(double value);
void SpinBoxValueChanged(const NumberVariable<double> &value);
signals:
void DoubleValueChanged(double value);
void DoubleValueChanged(const NumberVariable<double> &value);
private:
QDoubleSpinBox *_spinBox;
void SetVisibility(const NumberVariable<double> &);
VariableDoubleSpinBox *_spinBox;
QSlider *_slider;
double _scale = 100.0;
};