From 7c20e4773d3aefc8505b86846f5f7d28eb4150a0 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 17 Dec 2014 20:55:32 +0300 Subject: [PATCH] added photo switch by scroll gestures for os x in mediaview --- Telegram/SourceFiles/mediaview.cpp | 17 +++++++++++++++++ Telegram/SourceFiles/mediaview.h | 1 + .../src/plugins/platforms/cocoa/qnsview.mm | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/mediaview.cpp b/Telegram/SourceFiles/mediaview.cpp index c8e19a2a1..2b679a3d5 100644 --- a/Telegram/SourceFiles/mediaview.cpp +++ b/Telegram/SourceFiles/mediaview.cpp @@ -1194,6 +1194,23 @@ bool MediaView::event(QEvent *e) { return true; } } + } else if (e->type() == QEvent::Wheel) { + QWheelEvent *ev = static_cast(e); + if (ev->phase() == Qt::ScrollBegin) { + _accumScroll = ev->angleDelta(); + LOG(("Scrolling begin: %1 sum %2").arg(ev->angleDelta().x()).arg(_accumScroll.x())); + } else { + _accumScroll += ev->angleDelta(); + if (ev->phase() == Qt::ScrollEnd) { + LOG(("Scrolling end: %1 sum %2").arg(ev->angleDelta().x()).arg(_accumScroll.x())); + if (ev->orientation() == Qt::Horizontal) { + if (_accumScroll.x() * _accumScroll.x() > _accumScroll.y() * _accumScroll.y() && _accumScroll.x() != 0) { + moveToPhoto(_accumScroll.x() > 0 ? -1 : 1); + } + _accumScroll = QPoint(); + } + } + } } return QWidget::event(e); } diff --git a/Telegram/SourceFiles/mediaview.h b/Telegram/SourceFiles/mediaview.h index 33d90fba6..41ac66f48 100644 --- a/Telegram/SourceFiles/mediaview.h +++ b/Telegram/SourceFiles/mediaview.h @@ -135,6 +135,7 @@ private: bool _touchPress, _touchMove, _touchRightButton; QTimer _touchTimer; QPoint _touchStart; + QPoint _accumScroll; QString _saveMsgFilename; uint64 _saveMsgStarted; diff --git a/Telegram/_qt_5_3_1_patch/qtbase/src/plugins/platforms/cocoa/qnsview.mm b/Telegram/_qt_5_3_1_patch/qtbase/src/plugins/platforms/cocoa/qnsview.mm index 1d8787ce6..1ca8105a3 100644 --- a/Telegram/_qt_5_3_1_patch/qtbase/src/plugins/platforms/cocoa/qnsview.mm +++ b/Telegram/_qt_5_3_1_patch/qtbase/src/plugins/platforms/cocoa/qnsview.mm @@ -1248,7 +1248,7 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent) #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8 if (QSysInfo::QSysInfo::MacintoshVersion >= QSysInfo::MV_10_8) { // On 10.8 and above, MayBegin is likely to happen. We treat it the same as an actual begin. - if (phase == NSEventPhaseMayBegin) + if (phase == NSEventPhaseMayBegin || phase == NSEventPhaseBegan) ph = Qt::ScrollBegin; } else #endif