added fix for scrollbar smooth scrolling jumping on new messages

This commit is contained in:
fourtf 2017-12-18 18:55:09 +01:00
parent 625e33d654
commit a399af9c66
3 changed files with 22 additions and 2 deletions

View file

@ -36,6 +36,7 @@ public:
BoolSetting hideTabX = {"/appearance/hideTabX", false};
BoolSetting hidePreferencesButton = {"/appearance/hidePreferencesButton", false};
BoolSetting hideUserButton = {"/appearance/hideUserButton", false};
BoolSetting enableSmoothScrolling = {"/appearance/smoothScrolling", true};
// BoolSetting useCustomWindowFrame = {"/appearance/useCustomWindowFrame", false};
/// Behaviour

View file

@ -15,6 +15,7 @@ ScrollBar::ScrollBar(ChannelView *parent)
: BaseWidget(parent)
, _currentValueAnimation(this, "_currentValue")
, _highlights(nullptr)
, smoothScrollingSetting(SettingsManager::getInstance().enableSmoothScrolling)
{
resize(16, 100);
_currentValueAnimation.setDuration(250);
@ -115,12 +116,13 @@ void ScrollBar::setSmallChange(qreal value)
void ScrollBar::setDesiredValue(qreal value, bool animated)
{
animated &= this->smoothScrollingSetting.getValue();
value = std::max(_minimum, std::min(_maximum - _largeChange, value));
if (_desiredValue != value) {
if (animated) {
_currentValueAnimation.stop();
_currentValueAnimation.setStartValue(_currentValue);
_currentValueAnimation.setStartValue(_currentValue + this->_smoothScrollingOffset);
_currentValueAnimation.setEndValue(value);
_currentValueAnimation.start();
@ -133,6 +135,7 @@ void ScrollBar::setDesiredValue(qreal value, bool animated)
}
}
this->_smoothScrollingOffset = 0;
_desiredValue = value;
}
@ -166,6 +169,15 @@ qreal ScrollBar::getCurrentValue() const
return _currentValue;
}
void ScrollBar::offset(qreal value)
{
if (_currentValueAnimation.state() == QPropertyAnimation::Running) {
this->_smoothScrollingOffset += value;
} else {
this->setDesiredValue(this->getDesiredValue() + value);
}
}
boost::signals2::signal<void()> &ScrollBar::getCurrentValueChanged()
{
return _currentValueChanged;
@ -173,7 +185,8 @@ boost::signals2::signal<void()> &ScrollBar::getCurrentValueChanged()
void ScrollBar::setCurrentValue(qreal value)
{
value = std::max(_minimum, std::min(_maximum - _largeChange, value));
value =
std::max(_minimum, std::min(_maximum - _largeChange, value + this->_smoothScrollingOffset));
if (_currentValue != value) {
_currentValue = value;

View file

@ -7,6 +7,7 @@
#include <QPropertyAnimation>
#include <QWidget>
#include <boost/signals2.hpp>
#include <settingsmanager.hpp>
namespace chatterino {
@ -44,6 +45,8 @@ public:
qreal getSmallChange() const;
qreal getDesiredValue() const;
qreal getCurrentValue() const;
// offset the desired value without breaking smooth scolling
void offset(qreal value);
boost::signals2::signal<void()> &getCurrentValueChanged();
void setCurrentValue(qreal value);
@ -79,9 +82,12 @@ private:
qreal _smallChange = 5;
qreal _desiredValue = 0;
qreal _currentValue = 0;
qreal _smoothScrollingOffset = 0;
boost::signals2::signal<void()> _currentValueChanged;
pajlada::Settings::Setting<bool> &smoothScrollingSetting;
void updateScroll();
};