From dc6496d944025c6749961e7759d69a27207e380d Mon Sep 17 00:00:00 2001 From: Cameron Porter Date: Thu, 25 Jul 2024 21:18:12 -0500 Subject: [PATCH 1/6] Handle panning touch gestures. --- src/widgets/helper/ChannelView.cpp | 43 ++++++++++++++++++++++++++++++ src/widgets/helper/ChannelView.hpp | 5 ++++ 2 files changed, 48 insertions(+) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 7430614a947..c1d6acdcc84 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -369,6 +370,8 @@ ChannelView::ChannelView(InternalCtor /*tag*/, QWidget *parent, Split *split, this->scrollUpdateRequested(); }); + this->grabGesture(Qt::PanGesture); + // TODO: Figure out if we need this, and if so, why // StrongFocus means we can focus this event through clicking it // and tabbing to it from another widget. I don't currently know @@ -1786,8 +1789,48 @@ void ChannelView::leaveEvent(QEvent * /*event*/) this->unpause(PauseReason::Mouse); } +bool ChannelView::event(QEvent *event) +{ + if (event->type() == QEvent::Gesture) + { + return gestureEvent(dynamic_cast(event)); + } + + return BaseWidget::event(event); +} + +bool ChannelView::gestureEvent(const QGestureEvent *event) +{ + if (QGesture *pan = event->gesture(Qt::PanGesture)) + { + auto const *gesture = dynamic_cast(pan); + + switch (gesture->state()) + { + case Qt::GestureStarted: + case Qt::GestureUpdated: + this->isPanning_ = true; + this->clearSelection(); + break; + default: + this->isPanning_ = false; + break; + } + + this->scrollBar_->offset(-gesture->delta().y() * 0.5); + } + + return false; +} + void ChannelView::mouseMoveEvent(QMouseEvent *event) { + if (this->isPanning_) + { + // Don't do any text selection, hovering, etc while panning + return; + } + /// Pause on hover if (float pauseTime = getSettings()->pauseOnHoverDuration; pauseTime > 0.001F) diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index e6cb7597ee8..d46eb93566a 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -10,6 +10,7 @@ #include "widgets/TooltipWidget.hpp" #include +#include #include #include #include @@ -216,6 +217,9 @@ class ChannelView final : public BaseWidget #endif void leaveEvent(QEvent * /*event*/) override; + bool event(QEvent* event) override; + bool gestureEvent(const QGestureEvent* event); + void mouseMoveEvent(QMouseEvent *event) override; void mousePressEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; @@ -374,6 +378,7 @@ class ChannelView final : public BaseWidget QTimer clickTimer_; bool isScrolling_ = false; + bool isPanning_ = false; QPointF lastMiddlePressPosition_; QPointF currentMousePosition_; QTimer scrollTimer_; From 9da4ba7e36049482c9e85e14ab68ac4e15aaeeca Mon Sep 17 00:00:00 2001 From: Cameron Porter Date: Sat, 27 Jul 2024 14:03:22 -0500 Subject: [PATCH 2/6] Separate gesture states better, format --- src/widgets/helper/ChannelView.cpp | 66 +++++++++++++++++++----------- src/widgets/helper/ChannelView.hpp | 4 +- 2 files changed, 43 insertions(+), 27 deletions(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index c1d6acdcc84..149417b1f76 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1791,36 +1791,52 @@ void ChannelView::leaveEvent(QEvent * /*event*/) bool ChannelView::event(QEvent *event) { - if (event->type() == QEvent::Gesture) - { - return gestureEvent(dynamic_cast(event)); - } + if (event->type() == QEvent::Gesture) + { + if (const auto *gestureEvent = dynamic_cast(event)) + { + return this->gestureEvent(gestureEvent); + } + } - return BaseWidget::event(event); + return BaseWidget::event(event); } bool ChannelView::gestureEvent(const QGestureEvent *event) { - if (QGesture *pan = event->gesture(Qt::PanGesture)) - { - auto const *gesture = dynamic_cast(pan); - - switch (gesture->state()) - { - case Qt::GestureStarted: - case Qt::GestureUpdated: - this->isPanning_ = true; - this->clearSelection(); - break; - default: - this->isPanning_ = false; - break; - } - - this->scrollBar_->offset(-gesture->delta().y() * 0.5); - } - - return false; + if (QGesture *pan = event->gesture(Qt::PanGesture)) + { + if (const auto *gesture = dynamic_cast(pan)) + { + switch (gesture->state()) + { + case Qt::GestureStarted: + this->isPanning_ = true; + // Remove any selections and hide tooltip while panning + this->clearSelection(); + this->tooltipWidget_->hide(); + if (this->isScrolling_) + { + this->disableScrolling(); + } + break; + case Qt::GestureUpdated: + if (this->scrollBar_->isVisible()) + { + this->scrollBar_->offset(-gesture->delta().y() * 0.1); + } + break; + case Qt::GestureFinished: + case Qt::GestureCanceled: + default: + this->clearSelection(); + this->isPanning_ = false; + break; + } + } + } + + return false; } void ChannelView::mouseMoveEvent(QMouseEvent *event) diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index d46eb93566a..a670d6e3074 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -217,8 +217,8 @@ class ChannelView final : public BaseWidget #endif void leaveEvent(QEvent * /*event*/) override; - bool event(QEvent* event) override; - bool gestureEvent(const QGestureEvent* event); + bool event(QEvent *event) override; + bool gestureEvent(const QGestureEvent *event); void mouseMoveEvent(QMouseEvent *event) override; void mousePressEvent(QMouseEvent *event) override; From bdfc19371fd57389c07964478bab5fed3f19e5e0 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 28 Jul 2024 11:22:11 +0200 Subject: [PATCH 3/6] minor reformatting --- src/widgets/helper/ChannelView.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 149417b1f76..a79dbfbb054 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1799,7 +1799,7 @@ bool ChannelView::event(QEvent *event) } } - return BaseWidget::event(event); + return BaseWidget::event(event); } bool ChannelView::gestureEvent(const QGestureEvent *event) @@ -1810,7 +1810,7 @@ bool ChannelView::gestureEvent(const QGestureEvent *event) { switch (gesture->state()) { - case Qt::GestureStarted: + case Qt::GestureStarted: { this->isPanning_ = true; // Remove any selections and hide tooltip while panning this->clearSelection(); @@ -1819,18 +1819,23 @@ bool ChannelView::gestureEvent(const QGestureEvent *event) { this->disableScrolling(); } + } break; - case Qt::GestureUpdated: + + case Qt::GestureUpdated: { if (this->scrollBar_->isVisible()) { this->scrollBar_->offset(-gesture->delta().y() * 0.1); } + } break; + case Qt::GestureFinished: case Qt::GestureCanceled: - default: + default: { this->clearSelection(); this->isPanning_ = false; + } break; } } From cf19eda36beaf76c8ef9d9aea3e26f0b431ad216 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 28 Jul 2024 11:22:18 +0200 Subject: [PATCH 4/6] return true when gesture event is handled by us --- src/widgets/helper/ChannelView.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index a79dbfbb054..a6179c74c0d 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1819,6 +1819,8 @@ bool ChannelView::gestureEvent(const QGestureEvent *event) { this->disableScrolling(); } + + return true; } break; @@ -1827,6 +1829,8 @@ bool ChannelView::gestureEvent(const QGestureEvent *event) { this->scrollBar_->offset(-gesture->delta().y() * 0.1); } + + return true; } break; @@ -1835,6 +1839,8 @@ bool ChannelView::gestureEvent(const QGestureEvent *event) default: { this->clearSelection(); this->isPanning_ = false; + + return true; } break; } From 68405cf4501b33a66eb3cc03d208a995a79afe71 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 28 Jul 2024 11:23:47 +0200 Subject: [PATCH 5/6] make single return --- src/widgets/helper/ChannelView.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index a6179c74c0d..be91e2342df 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1819,8 +1819,6 @@ bool ChannelView::gestureEvent(const QGestureEvent *event) { this->disableScrolling(); } - - return true; } break; @@ -1829,8 +1827,6 @@ bool ChannelView::gestureEvent(const QGestureEvent *event) { this->scrollBar_->offset(-gesture->delta().y() * 0.1); } - - return true; } break; @@ -1839,11 +1835,11 @@ bool ChannelView::gestureEvent(const QGestureEvent *event) default: { this->clearSelection(); this->isPanning_ = false; - - return true; } break; } + + return true; } } From 939010dc003972ae3ad814c3d70d6088e31eb943 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 28 Jul 2024 11:25:17 +0200 Subject: [PATCH 6/6] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 714681d098f..deec23cb2f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ - Minor: Support more Firefox variants for incognito link opening. (#5503) - Minor: Replying to a message will now display the message being replied to. (#4350, #5519) - Minor: Links can now have prefixes and suffixes such as parentheses. (#5486, #5515) +- Minor: Added support for scrolling in splits with touchscreen panning gestures. (#5524) - Bugfix: Fixed tab move animation occasionally failing to start after closing a tab. (#5426) - Bugfix: If a network request errors with 200 OK, Qt's error code is now reported instead of the HTTP status. (#5378) - Bugfix: Fixed restricted users usernames not being clickable. (#5405)