diff --git a/src/core/mainwindow.cpp b/src/core/mainwindow.cpp index 4c3e25dea..87a9e7fc9 100644 --- a/src/core/mainwindow.cpp +++ b/src/core/mainwindow.cpp @@ -1652,7 +1652,7 @@ void MainWindow::PlaylistDoubleClick(const QModelIndex &idx) { } void MainWindow::VolumeWheelEvent(const int delta) { - ui_->volume->setValue(ui_->volume->value() + delta / 30); + ui_->volume->HandleWheel(delta); } void MainWindow::ToggleShowHide() { diff --git a/src/widgets/volumeslider.cpp b/src/widgets/volumeslider.cpp index d1e464046..3d9775906 100644 --- a/src/widgets/volumeslider.cpp +++ b/src/widgets/volumeslider.cpp @@ -54,6 +54,7 @@ VolumeSlider::VolumeSlider(QWidget *parent, const uint max) : SliderSlider(Qt::Horizontal, parent, static_cast(max)), + wheel_accumulator_(0), anim_enter_(false), anim_count_(0), timer_anim_(new QTimer(this)), @@ -80,6 +81,23 @@ void VolumeSlider::SetEnabled(const bool enabled) { QSlider::setVisible(enabled); } +void VolumeSlider::HandleWheel(const int delta) { + + const int scroll_state = wheel_accumulator_ + delta; + const int steps = scroll_state / WHEEL_ROTATION_PER_STEP; + wheel_accumulator_ = scroll_state % WHEEL_ROTATION_PER_STEP; + + if (steps != 0) { + wheeling_ = true; + + QSlider::setValue(SliderSlider::value() + steps); + emit SliderReleased(value()); + + wheeling_ = false; + } + +} + void VolumeSlider::paintEvent(QPaintEvent*) { QPainter p(this); @@ -272,13 +290,5 @@ void VolumeSlider::mousePressEvent(QMouseEvent *e) { } void VolumeSlider::wheelEvent(QWheelEvent *e) { - - wheeling_ = true; - - const int step = e->angleDelta().y() / (e->angleDelta().x() == 0 ? 30 : -30); - QSlider::setValue(SliderSlider::value() + step); - emit SliderReleased(value()); - - wheeling_ = false; - + HandleWheel(e->angleDelta().y()); } diff --git a/src/widgets/volumeslider.h b/src/widgets/volumeslider.h index bb431e858..d61eb4756 100644 --- a/src/widgets/volumeslider.h +++ b/src/widgets/volumeslider.h @@ -48,6 +48,7 @@ class VolumeSlider : public SliderSlider { public: explicit VolumeSlider(QWidget *parent, uint max = 0); void SetEnabled(const bool enabled); + void HandleWheel(const int delta); protected: #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) @@ -70,6 +71,9 @@ class VolumeSlider : public SliderSlider { static const int ANIM_INTERVAL = 18; static const int ANIM_MAX = 18; + // Units are eighths of a degree + static const int WHEEL_ROTATION_PER_STEP = 30; + VolumeSlider(const VolumeSlider&); VolumeSlider &operator=(const VolumeSlider&); @@ -77,6 +81,8 @@ class VolumeSlider : public SliderSlider { QPixmap drawVolumePixmap() const; void drawVolumeSliderHandle(); + int wheel_accumulator_; + bool anim_enter_; int anim_count_; QTimer *timer_anim_;