double-slider.cpp 662 B

12345678910111213141516171819202122232425262728293031
  1. #include "moc_double-slider.cpp"
  2. #include <cmath>
  3. DoubleSlider::DoubleSlider(QWidget *parent) : SliderIgnoreScroll(parent)
  4. {
  5. connect(this, &DoubleSlider::valueChanged, [this](int val) {
  6. emit doubleValChanged((minVal / minStep + val) * minStep);
  7. });
  8. }
  9. void DoubleSlider::setDoubleConstraints(double newMin, double newMax,
  10. double newStep, double val)
  11. {
  12. minVal = newMin;
  13. maxVal = newMax;
  14. minStep = newStep;
  15. double total = maxVal - minVal;
  16. int intMax = int(total / minStep);
  17. setMinimum(0);
  18. setMaximum(intMax);
  19. setSingleStep(1);
  20. setDoubleVal(val);
  21. }
  22. void DoubleSlider::setDoubleVal(double val)
  23. {
  24. setValue(lround((val - minVal) / minStep));
  25. }