double-slider.cpp 656 B

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