small fixes for the scrollbar

This commit is contained in:
fourtf 2017-12-18 22:13:46 +01:00
parent f8cf983b7c
commit e46357ad9b
3 changed files with 22 additions and 13 deletions

View file

@ -341,11 +341,11 @@ void ChannelView::setChannel(std::shared_ptr<Channel> channel)
auto messageRef = new MessageRef(message); auto messageRef = new MessageRef(message);
if (this->messages.appendItem(SharedMessageRef(messageRef), deleted)) { if (this->messages.appendItem(SharedMessageRef(messageRef), deleted)) {
// qreal value = std::max(0.0, this->getScrollBar().getDesiredValue() if (this->scrollBar.isAtBottom()) {
// - 1); this->scrollBar.scrollToBottom();
} else {
// this->getScrollBar().setDesiredValue(value, false); this->scrollBar.offset(-1);
this->getScrollBar().offset(-1); }
} }
layoutMessages(); layoutMessages();
@ -417,7 +417,7 @@ void ChannelView::paintEvent(QPaintEvent * /*event*/)
// BENCH(timer); // BENCH(timer);
QPainter painter(this); QPainter painter(this);
// painter.setRenderHint(QPainter::SmoothPixmapTransform); painter.setRenderHint(QPainter::SmoothPixmapTransform);
// only update gif emotes // only update gif emotes
#ifndef Q_OS_MAC #ifndef Q_OS_MAC

View file

@ -83,7 +83,7 @@ void ScrollBar::scrollToBottom()
bool ScrollBar::isAtBottom() const bool ScrollBar::isAtBottom() const
{ {
return ((this->getMaximum() - this->getLargeChange()) - this->getCurrentValue()) <= 1; return this->atBottom;
} }
void ScrollBar::setMaximum(qreal value) void ScrollBar::setMaximum(qreal value)
@ -119,23 +119,30 @@ void ScrollBar::setDesiredValue(qreal value, bool animated)
animated &= this->smoothScrollingSetting.getValue(); animated &= this->smoothScrollingSetting.getValue();
value = std::max(_minimum, std::min(_maximum - _largeChange, value)); value = std::max(_minimum, std::min(_maximum - _largeChange, value));
if (_desiredValue != value) { if (_desiredValue + _smoothScrollingOffset != value) {
if (animated) { if (animated) {
_currentValueAnimation.stop(); _currentValueAnimation.stop();
_currentValueAnimation.setStartValue(_currentValue + this->_smoothScrollingOffset); _currentValueAnimation.setStartValue(_currentValue + _smoothScrollingOffset);
// if (((this->getMaximum() - this->getLargeChange()) - value) <= 0.01) {
// value += 1;
// }
_currentValueAnimation.setEndValue(value); _currentValueAnimation.setEndValue(value);
_smoothScrollingOffset = 0;
_currentValueAnimation.start(); _currentValueAnimation.start();
} else { } else {
if (_currentValueAnimation.state() != QPropertyAnimation::Running) { if (_currentValueAnimation.state() != QPropertyAnimation::Running) {
// currentValueAnimation.stop(); _smoothScrollingOffset = 0;
_desiredValue = value;
_currentValueAnimation.stop();
setCurrentValue(value); setCurrentValue(value);
} }
} }
} }
this->_smoothScrollingOffset = 0; this->atBottom = ((this->getMaximum() - this->getLargeChange()) - value) <= 0.01;
_smoothScrollingOffset = 0;
_desiredValue = value; _desiredValue = value;
} }
@ -161,7 +168,7 @@ qreal ScrollBar::getSmallChange() const
qreal ScrollBar::getDesiredValue() const qreal ScrollBar::getDesiredValue() const
{ {
return _desiredValue; return _desiredValue + _smoothScrollingOffset;
} }
qreal ScrollBar::getCurrentValue() const qreal ScrollBar::getCurrentValue() const

View file

@ -67,6 +67,8 @@ private:
void mouseReleaseEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event);
void leaveEvent(QEvent *); void leaveEvent(QEvent *);
bool atBottom = false;
int _mouseOverIndex = -1; int _mouseOverIndex = -1;
int _mouseDownIndex = -1; int _mouseDownIndex = -1;
QPoint _lastMousePosition; QPoint _lastMousePosition;