File: double-slider.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 (63 lines) | stat: -rw-r--r-- 1,250 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
#include "double-slider.hpp"
#include <QWheelEvent>

#include <cmath>

namespace advss {

SliderIgnoreScroll::SliderIgnoreScroll(QWidget *parent) : QSlider(parent)
{
	setFocusPolicy(Qt::StrongFocus);
}

SliderIgnoreScroll::SliderIgnoreScroll(Qt::Orientation orientation,
				       QWidget *parent)
	: QSlider(parent)
{
	setFocusPolicy(Qt::StrongFocus);
	setOrientation(orientation);
}

void SliderIgnoreScroll::wheelEvent(QWheelEvent *event)
{
	if (!hasFocus()) {
		event->ignore();
	} else {
		QSlider::wheelEvent(event);
	}
}

DoubleSlider::DoubleSlider(QWidget *parent) : SliderIgnoreScroll(parent)
{
	connect(this, &DoubleSlider::valueChanged, [this](int val) {
		emit DoubleValChanged((minVal / minStep + val) * minStep);
	});
}

void DoubleSlider::SetDoubleConstraints(double newMin, double newMax,
					double newStep, double val)
{
	minVal = newMin;
	maxVal = newMax;
	minStep = newStep;

	double total = maxVal - minVal;
	int intMax = int(total / minStep);

	setMinimum(0);
	setMaximum(intMax);
	setSingleStep(1);
	SetDoubleVal(val);
}

double DoubleSlider::DoubleValue()
{
	return (minVal / minStep + value()) * minStep;
}

void DoubleSlider::SetDoubleVal(double val)
{
	setValue(lround((val - minVal) / minStep));
}

} // namespace advss