From e46357ad9b947923585092040b9101c85d95995b Mon Sep 17 00:00:00 2001 From: fourtf Date: Mon, 18 Dec 2017 22:13:46 +0100 Subject: [PATCH] small fixes for the scrollbar --- src/widgets/helper/channelview.cpp | 12 ++++++------ src/widgets/scrollbar.cpp | 21 ++++++++++++++------- src/widgets/scrollbar.hpp | 2 ++ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/widgets/helper/channelview.cpp b/src/widgets/helper/channelview.cpp index 634ddfd59..89c13909c 100644 --- a/src/widgets/helper/channelview.cpp +++ b/src/widgets/helper/channelview.cpp @@ -341,11 +341,11 @@ void ChannelView::setChannel(std::shared_ptr channel) auto messageRef = new MessageRef(message); if (this->messages.appendItem(SharedMessageRef(messageRef), deleted)) { - // qreal value = std::max(0.0, this->getScrollBar().getDesiredValue() - // - 1); - - // this->getScrollBar().setDesiredValue(value, false); - this->getScrollBar().offset(-1); + if (this->scrollBar.isAtBottom()) { + this->scrollBar.scrollToBottom(); + } else { + this->scrollBar.offset(-1); + } } layoutMessages(); @@ -417,7 +417,7 @@ void ChannelView::paintEvent(QPaintEvent * /*event*/) // BENCH(timer); QPainter painter(this); -// painter.setRenderHint(QPainter::SmoothPixmapTransform); + painter.setRenderHint(QPainter::SmoothPixmapTransform); // only update gif emotes #ifndef Q_OS_MAC diff --git a/src/widgets/scrollbar.cpp b/src/widgets/scrollbar.cpp index 66a2ae21b..7ecd0d6f1 100644 --- a/src/widgets/scrollbar.cpp +++ b/src/widgets/scrollbar.cpp @@ -83,7 +83,7 @@ void ScrollBar::scrollToBottom() bool ScrollBar::isAtBottom() const { - return ((this->getMaximum() - this->getLargeChange()) - this->getCurrentValue()) <= 1; + return this->atBottom; } void ScrollBar::setMaximum(qreal value) @@ -119,23 +119,30 @@ void ScrollBar::setDesiredValue(qreal value, bool animated) animated &= this->smoothScrollingSetting.getValue(); value = std::max(_minimum, std::min(_maximum - _largeChange, value)); - if (_desiredValue != value) { + if (_desiredValue + _smoothScrollingOffset != value) { if (animated) { _currentValueAnimation.stop(); - _currentValueAnimation.setStartValue(_currentValue + this->_smoothScrollingOffset); + _currentValueAnimation.setStartValue(_currentValue + _smoothScrollingOffset); + // if (((this->getMaximum() - this->getLargeChange()) - value) <= 0.01) { + // value += 1; + // } _currentValueAnimation.setEndValue(value); + _smoothScrollingOffset = 0; _currentValueAnimation.start(); } else { if (_currentValueAnimation.state() != QPropertyAnimation::Running) { - // currentValueAnimation.stop(); - + _smoothScrollingOffset = 0; + _desiredValue = value; + _currentValueAnimation.stop(); setCurrentValue(value); } } } - this->_smoothScrollingOffset = 0; + this->atBottom = ((this->getMaximum() - this->getLargeChange()) - value) <= 0.01; + + _smoothScrollingOffset = 0; _desiredValue = value; } @@ -161,7 +168,7 @@ qreal ScrollBar::getSmallChange() const qreal ScrollBar::getDesiredValue() const { - return _desiredValue; + return _desiredValue + _smoothScrollingOffset; } qreal ScrollBar::getCurrentValue() const diff --git a/src/widgets/scrollbar.hpp b/src/widgets/scrollbar.hpp index 90b8cbf1d..3e9f67b68 100644 --- a/src/widgets/scrollbar.hpp +++ b/src/widgets/scrollbar.hpp @@ -67,6 +67,8 @@ private: void mouseReleaseEvent(QMouseEvent *event); void leaveEvent(QEvent *); + bool atBottom = false; + int _mouseOverIndex = -1; int _mouseDownIndex = -1; QPoint _lastMousePosition;