diff --git a/src/settingsmanager.hpp b/src/settingsmanager.hpp index 8c21323cb..7cdf144d0 100644 --- a/src/settingsmanager.hpp +++ b/src/settingsmanager.hpp @@ -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 diff --git a/src/widgets/scrollbar.cpp b/src/widgets/scrollbar.cpp index 3dedf6f35..66a2ae21b 100644 --- a/src/widgets/scrollbar.cpp +++ b/src/widgets/scrollbar.cpp @@ -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 &ScrollBar::getCurrentValueChanged() { return _currentValueChanged; @@ -173,7 +185,8 @@ boost::signals2::signal &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; diff --git a/src/widgets/scrollbar.hpp b/src/widgets/scrollbar.hpp index 6c70a23e5..90b8cbf1d 100644 --- a/src/widgets/scrollbar.hpp +++ b/src/widgets/scrollbar.hpp @@ -7,6 +7,7 @@ #include #include #include +#include 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 &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 _currentValueChanged; + pajlada::Settings::Setting &smoothScrollingSetting; + void updateScroll(); };