From fd8ddcff55e03fa28639911a83ef2b4e33bc4675 Mon Sep 17 00:00:00 2001 From: fourtf Date: Fri, 5 Jan 2018 02:55:24 +0100 Subject: [PATCH] fixes #113 --- src/widgets/helper/channelview.cpp | 55 ++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/src/widgets/helper/channelview.cpp b/src/widgets/helper/channelview.cpp index ae6fa3a10..e23712e65 100644 --- a/src/widgets/helper/channelview.cpp +++ b/src/widgets/helper/channelview.cpp @@ -815,8 +815,59 @@ void ChannelView::wheelEvent(QWheelEvent *event) if (this->scrollBar.isVisible()) { float mouseMultiplier = singletons::SettingManager::getInstance().mouseScrollMultiplier; - this->scrollBar.setDesiredValue( - this->scrollBar.getDesiredValue() - event->delta() / 10.0 * mouseMultiplier, true); + float desired = this->scrollBar.getDesiredValue(); + float delta = event->delta() * 1.5 * mouseMultiplier; + + auto snapshot = this->getMessagesSnapshot(); + int i = std::min((int)desired, (int)snapshot.getLength()); + + if (delta > 0) { + float scrollFactor = fmod(desired, 1); + float currentScrollLeft = (int)(scrollFactor * snapshot[i]->getHeight()); + + for (; i >= 0; i--) { + if (delta < currentScrollLeft) { + desired -= scrollFactor * (delta / currentScrollLeft); + break; + } else { + delta -= currentScrollLeft; + desired -= scrollFactor; + } + + if (i == 0) { + desired = 0; + } else { + snapshot[i - 1]->layout(this->width(), this->getDpiMultiplier()); + scrollFactor = 1; + currentScrollLeft = snapshot[i - 1]->getHeight(); + } + } + } else { + delta = -delta; + float scrollFactor = 1 - fmod(desired, 1); + float currentScrollLeft = (int)(scrollFactor * snapshot[i]->getHeight()); + + for (; i < snapshot.getLength(); i++) { + if (delta < currentScrollLeft) { + desired += scrollFactor * ((double)delta / currentScrollLeft); + break; + } else { + delta -= currentScrollLeft; + desired += scrollFactor; + } + + if (i == snapshot.getLength() - 1) { + desired = snapshot.getLength(); + } else { + snapshot[i + 1]->layout(this->width(), this->getDpiMultiplier()); + + scrollFactor = 1; + currentScrollLeft = snapshot[i + 1]->getHeight(); + } + } + } + + this->scrollBar.setDesiredValue(desired, true); } }