0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 21:13:04 +02:00
obs-studio/obs/double-slider.cpp
Palana 8293103106 UI: Fix DoubleSlider behavior for OBS_NUMBER_SLIDER properties
When using e.g. a color correction filter on any source and changing
any value (with slider enabled, e.g. contrast) to -0.10 the value would
get cycle between -0.07/-0.08 at some point when using the up arrow; it
would also get stuck on -0.69.

For the other direction, when starting from e.g. -0.02 the value would
jump from 0.05 to -0.08 when pressing the down arrow.

Problem was reported at https://obsproject.com/forum/threads/32450
2015-07-01 08:22:04 +02:00

36 lines
699 B
C++

#include "double-slider.hpp"
#include <cmath>
DoubleSlider::DoubleSlider(QWidget *parent) : QSlider(parent)
{
connect(this, SIGNAL(valueChanged(int)),
this, SLOT(intValChanged(int)));
}
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);
}
void DoubleSlider::intValChanged(int val)
{
emit doubleValChanged((minVal/minStep + val) * minStep);
}
void DoubleSlider::setDoubleVal(double val)
{
setValue(lround((val - minVal) / minStep));
}