From fdb0b62deedcfd53d0113dfb4dfe79eb2f82e203 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 4 Aug 2019 18:44:06 +0300 Subject: [PATCH] Fixed switching tabs using trackpad scroll. --- src/widgets/helper/NotebookTab.cpp | 21 ++++++++++++++++++--- src/widgets/helper/NotebookTab.hpp | 1 + 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index 77d2f9e4e..96eb61948 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -559,13 +559,28 @@ void NotebookTab::mouseMoveEvent(QMouseEvent *event) void NotebookTab::wheelEvent(QWheelEvent *event) { - if (event->delta() > 0) + const auto defaultMouseDelta = 120; + const auto delta = event->delta(); + const auto selectTab = [this](int delta) { + delta > 0 + ? this->notebook_->selectPreviousTab() + : this->notebook_->selectNextTab(); + }; + // 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) { - this->notebook_->selectPreviousTab(); + this->mouseWheelDelta_ += delta; + if (std::abs(this->mouseWheelDelta_) >= defaultMouseDelta) + { + selectTab(this->mouseWheelDelta_); + this->mouseWheelDelta_ = 0; + } } else { - this->notebook_->selectNextTab(); + selectTab(delta); } } diff --git a/src/widgets/helper/NotebookTab.hpp b/src/widgets/helper/NotebookTab.hpp index d0dab2b9f..70d251d2e 100644 --- a/src/widgets/helper/NotebookTab.hpp +++ b/src/widgets/helper/NotebookTab.hpp @@ -90,6 +90,7 @@ private: bool mouseOverX_{}; bool mouseDownX_{}; bool isInLastRow_{}; + int mouseWheelDelta_ = 0; HighlightState highlightState_ = HighlightState::None; bool highlightEnabled_ = true;