2015-03-17 18:33:21 -07:00
|
|
|
#include "double-slider.hpp"
|
|
|
|
|
2015-06-30 23:05:45 -07:00
|
|
|
#include <cmath>
|
|
|
|
|
2015-03-17 18:33:21 -07:00
|
|
|
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)
|
|
|
|
{
|
2015-06-30 23:05:45 -07:00
|
|
|
emit doubleValChanged((minVal/minStep + val) * minStep);
|
2015-03-17 18:33:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void DoubleSlider::setDoubleVal(double val)
|
|
|
|
{
|
2015-06-30 23:05:45 -07:00
|
|
|
setValue(lround((val - minVal) / minStep));
|
2015-03-17 18:33:21 -07:00
|
|
|
}
|