File: slider-spinbox.cpp

package info (click to toggle)
obs-advanced-scene-switcher 1.32.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 43,492 kB
  • sloc: xml: 297,593; cpp: 147,875; python: 387; sh: 280; ansic: 170; makefile: 33
file content (82 lines) | stat: -rw-r--r-- 2,111 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "slider-spinbox.hpp"
#include <QHBoxLayout>

namespace advss {

SliderSpinBox::SliderSpinBox(double min, double max, const QString &label,
			     const QString &description,
			     bool descriptionAsTooltip, QWidget *parent)
	: QWidget(parent),
	  _spinBox(new VariableDoubleSpinBox()),
	  _slider(new QSlider())
{
	_slider->setOrientation(Qt::Horizontal);
	_slider->setRange(min * _scale, max * _scale);
	_spinBox->setMinimum(min);
	_spinBox->setMaximum(max);
	_spinBox->setDecimals(5);

	connect(_slider, SIGNAL(valueChanged(int)), this,
		SLOT(SliderValueChanged(int)));
	QWidget::connect(
		_spinBox,
		SIGNAL(NumberVariableChanged(const NumberVariable<double> &)),
		this,
		SLOT(SpinBoxValueChanged(const NumberVariable<double> &)));

	auto mainLayout = new QVBoxLayout();
	auto sliderLayout = new QHBoxLayout();
	if (!label.isEmpty()) {
		sliderLayout->addWidget(new QLabel(label));
	}
	sliderLayout->addWidget(_spinBox);
	sliderLayout->addWidget(_slider);
	mainLayout->addLayout(sliderLayout);
	if (!description.isEmpty()) {
		if (descriptionAsTooltip) {
			setToolTip(description);
		} else {
			mainLayout->addWidget(new QLabel(description));
		}
	}
	mainLayout->setContentsMargins(0, 0, 0, 0);
	setLayout(mainLayout);
}

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);
	SetVisibility(value);
}

void SliderSpinBox::SpinBoxValueChanged(const NumberVariable<double> &value)
{
	if (value.IsFixedType()) {
		int sliderPos = value * _scale;
		_slider->setValue(sliderPos);
	}
	SetVisibility(value);
	emit DoubleValueChanged(value);
}

void SliderSpinBox::SliderValueChanged(int value)
{
	NumberVariable<double> doubleValue = value / _scale;
	_spinBox->SetValue(doubleValue);
}

void SliderSpinBox::SetVisibility(const NumberVariable<double> &value)
{
	_slider->setVisible(value.IsFixedType());
}

} // namespace advss