yolobs-studio/UI/double-slider.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
714 B
C++
Raw Normal View History

2016-02-23 23:16:51 +00:00
#include "double-slider.hpp"
#include <cmath>
2019-07-27 12:47:10 +00:00
DoubleSlider::DoubleSlider(QWidget *parent) : SliderIgnoreScroll(parent)
2016-02-23 23:16:51 +00:00
{
2019-09-22 21:19:10 +00:00
connect(this, SIGNAL(valueChanged(int)), this,
SLOT(intValChanged(int)));
2016-02-23 23:16:51 +00:00
}
void DoubleSlider::setDoubleConstraints(double newMin, double newMax,
2019-09-22 21:19:10 +00:00
double newStep, double val)
2016-02-23 23:16:51 +00:00
{
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)
{
2019-09-22 21:19:10 +00:00
emit doubleValChanged((minVal / minStep + val) * minStep);
2016-02-23 23:16:51 +00:00
}
void DoubleSlider::setDoubleVal(double val)
{
setValue(lround((val - minVal) / minStep));
}