Use accumulator for seeking via scrolling
This results in much smoother experience on my touchpad. The value of 120 was chosen as the most common for mice, according to Qt 6 documentation.
This commit is contained in:
parent
3ecf224d91
commit
3bd0331aa3
|
@ -42,7 +42,8 @@ TrackSliderSlider::TrackSliderSlider(QWidget *parent)
|
|||
#ifndef Q_OS_MACOS
|
||||
popup_(new TrackSliderPopup(window())),
|
||||
#endif
|
||||
mouse_hover_seconds_(0) {
|
||||
mouse_hover_seconds_(0),
|
||||
wheel_accumulator_(0) {
|
||||
|
||||
setMouseTracking(true);
|
||||
#ifndef Q_OS_MACOS
|
||||
|
@ -122,10 +123,14 @@ void TrackSliderSlider::mouseMoveEvent(QMouseEvent *e) {
|
|||
|
||||
void TrackSliderSlider::wheelEvent(QWheelEvent *e) {
|
||||
|
||||
if (e->angleDelta().y() < 0) {
|
||||
const int scroll_state = wheel_accumulator_ + e->angleDelta().y();
|
||||
const int steps = scroll_state / WHEEL_ROTATION_TO_SEEK;
|
||||
wheel_accumulator_ = scroll_state % WHEEL_ROTATION_TO_SEEK;
|
||||
|
||||
if (steps < 0) {
|
||||
emit SeekBackward();
|
||||
}
|
||||
else {
|
||||
else if (steps > 0) {
|
||||
emit SeekForward();
|
||||
}
|
||||
e->accept();
|
||||
|
|
|
@ -66,11 +66,16 @@ class TrackSliderSlider : public QSlider {
|
|||
void UpdateDeltaTime();
|
||||
|
||||
private:
|
||||
// Units are eighths of a degree
|
||||
static const int WHEEL_ROTATION_TO_SEEK = 120;
|
||||
|
||||
#ifndef Q_OS_MACOS
|
||||
TrackSliderPopup *popup_;
|
||||
#endif
|
||||
|
||||
int mouse_hover_seconds_;
|
||||
|
||||
int wheel_accumulator_;
|
||||
};
|
||||
|
||||
#endif // TRACKSLIDERSLIDER_H
|
||||
|
|
Loading…
Reference in New Issue