From 9c41adca2efcdd633998ddc5b06db90fb2bbff15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82?= Date: Mon, 26 Apr 2021 21:38:16 +0200 Subject: [PATCH] Fixed deprecated method QWheelEvent::delta (#2647) Reference: https://doc.qt.io/qt-5/qwheelevent-obsolete.html#delta and https://doc.qt.io/qt-5/qwheelevent-obsolete.html#orientation Changes in behavior introduced in this commit Change from `event->delta()` to `event->angleDelta().y()` makes it, so you can no longer scroll horizontally (with trackpad / touchpad) to select next/previous tab (until now, you were able to do it, but I believe this is wrong anyways). Co-authored-by: pajlada --- src/widgets/helper/ChannelView.cpp | 6 ++++-- src/widgets/helper/NotebookTab.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index e68d7b8e..a1d69a5f 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1110,8 +1110,10 @@ void ChannelView::drawMessages(QPainter &painter) void ChannelView::wheelEvent(QWheelEvent *event) { - if (event->orientation() != Qt::Vertical) + if (!event->angleDelta().y()) + { return; + } if (event->modifiers() & Qt::ControlModifier) { @@ -1124,7 +1126,7 @@ void ChannelView::wheelEvent(QWheelEvent *event) float mouseMultiplier = getSettings()->mouseScrollMultiplier; qreal desired = this->scrollBar_->getDesiredValue(); - qreal delta = event->delta() * qreal(1.5) * mouseMultiplier; + qreal delta = event->angleDelta().y() * qreal(1.5) * mouseMultiplier; auto snapshot = this->getMessagesSnapshot(); int snapshotLength = int(snapshot.size()); diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index 56cba673..66bd9ef4 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -600,7 +600,7 @@ void NotebookTab::mouseMoveEvent(QMouseEvent *event) void NotebookTab::wheelEvent(QWheelEvent *event) { const auto defaultMouseDelta = 120; - const auto delta = event->delta(); + const auto verticalDelta = event->angleDelta().y(); const auto selectTab = [this](int delta) { delta > 0 ? this->notebook_->selectPreviousTab() : this->notebook_->selectNextTab(); @@ -608,9 +608,9 @@ void NotebookTab::wheelEvent(QWheelEvent *event) // If it's true // Then the user uses the trackpad or perhaps the most accurate mouse // Which has small delta. - if (std::abs(delta) < defaultMouseDelta) + if (std::abs(verticalDelta) < defaultMouseDelta) { - this->mouseWheelDelta_ += delta; + this->mouseWheelDelta_ += verticalDelta; if (std::abs(this->mouseWheelDelta_) >= defaultMouseDelta) { selectTab(this->mouseWheelDelta_); @@ -619,7 +619,7 @@ void NotebookTab::wheelEvent(QWheelEvent *event) } else { - selectTab(delta); + selectTab(verticalDelta); } }