double-slider.cpp 710 B

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