From a7b692e8edf4b855d2096c9abd24179866bfb279 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 14 Sep 2016 19:05:40 +0300 Subject: [PATCH] PR #1954 improvements. Inverted the direction of move-by-wheel, so that scrolling down will move you forward through the photos or documents overview. Added an accumulation of the scroll amount so that you don't zoom or skip photos each time a (possibly very frequent) wheel event fires. --- Telegram/SourceFiles/mediaview.cpp | 31 ++++++++++++++++++------------ Telegram/SourceFiles/mediaview.h | 2 ++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Telegram/SourceFiles/mediaview.cpp b/Telegram/SourceFiles/mediaview.cpp index bf2b6a1f7..635c9166c 100644 --- a/Telegram/SourceFiles/mediaview.cpp +++ b/Telegram/SourceFiles/mediaview.cpp @@ -1890,20 +1890,27 @@ void MediaView::keyPressEvent(QKeyEvent *e) { } void MediaView::wheelEvent(QWheelEvent *e) { - if (e->delta() < 0) { - if (e->modifiers().testFlag(Qt::ControlModifier)) { - zoomOut(); - } else { - if (e->source() == Qt::MouseEventNotSynthesized) { - moveToNext(-1); + constexpr auto step = static_cast(QWheelEvent::DefaultDeltasPerStep); + + _verticalWheelDelta += e->angleDelta().y(); + while (qAbs(_verticalWheelDelta) >= step) { + if (_verticalWheelDelta < 0) { + _verticalWheelDelta += step; + if (e->modifiers().testFlag(Qt::ControlModifier)) { + zoomOut(); + } else { + if (e->source() == Qt::MouseEventNotSynthesized) { + moveToNext(1); + } } - } - } else { - if (e->modifiers().testFlag(Qt::ControlModifier)) { - zoomIn(); } else { - if (e->source() == Qt::MouseEventNotSynthesized) { - moveToNext(1); + _verticalWheelDelta -= step; + if (e->modifiers().testFlag(Qt::ControlModifier)) { + zoomIn(); + } else { + if (e->source() == Qt::MouseEventNotSynthesized) { + moveToNext(-1); + } } } } diff --git a/Telegram/SourceFiles/mediaview.h b/Telegram/SourceFiles/mediaview.h index 3f8756b39..ff1e85b6a 100644 --- a/Telegram/SourceFiles/mediaview.h +++ b/Telegram/SourceFiles/mediaview.h @@ -322,6 +322,8 @@ private: typedef QMap ShowingOpacities; ShowingOpacities _animOpacities; + int _verticalWheelDelta = 0; + void updateOverRect(OverState state); bool updateOverState(OverState newState); float64 overLevel(OverState control) const;