Fixed switching tabs using trackpad scroll.

This commit is contained in:
23rd 2019-08-04 18:44:06 +03:00 committed by pajlada
parent 0c245fbc4e
commit fdb0b62dee
2 changed files with 19 additions and 3 deletions

View file

@ -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);
}
}

View file

@ -90,6 +90,7 @@ private:
bool mouseOverX_{};
bool mouseDownX_{};
bool isInLastRow_{};
int mouseWheelDelta_ = 0;
HighlightState highlightState_ = HighlightState::None;
bool highlightEnabled_ = true;