mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
added fix for scrollbar smooth scrolling jumping on new messages
This commit is contained in:
parent
625e33d654
commit
a399af9c66
|
@ -36,6 +36,7 @@ public:
|
||||||
BoolSetting hideTabX = {"/appearance/hideTabX", false};
|
BoolSetting hideTabX = {"/appearance/hideTabX", false};
|
||||||
BoolSetting hidePreferencesButton = {"/appearance/hidePreferencesButton", false};
|
BoolSetting hidePreferencesButton = {"/appearance/hidePreferencesButton", false};
|
||||||
BoolSetting hideUserButton = {"/appearance/hideUserButton", false};
|
BoolSetting hideUserButton = {"/appearance/hideUserButton", false};
|
||||||
|
BoolSetting enableSmoothScrolling = {"/appearance/smoothScrolling", true};
|
||||||
// BoolSetting useCustomWindowFrame = {"/appearance/useCustomWindowFrame", false};
|
// BoolSetting useCustomWindowFrame = {"/appearance/useCustomWindowFrame", false};
|
||||||
|
|
||||||
/// Behaviour
|
/// Behaviour
|
||||||
|
|
|
@ -15,6 +15,7 @@ ScrollBar::ScrollBar(ChannelView *parent)
|
||||||
: BaseWidget(parent)
|
: BaseWidget(parent)
|
||||||
, _currentValueAnimation(this, "_currentValue")
|
, _currentValueAnimation(this, "_currentValue")
|
||||||
, _highlights(nullptr)
|
, _highlights(nullptr)
|
||||||
|
, smoothScrollingSetting(SettingsManager::getInstance().enableSmoothScrolling)
|
||||||
{
|
{
|
||||||
resize(16, 100);
|
resize(16, 100);
|
||||||
_currentValueAnimation.setDuration(250);
|
_currentValueAnimation.setDuration(250);
|
||||||
|
@ -115,12 +116,13 @@ void ScrollBar::setSmallChange(qreal value)
|
||||||
|
|
||||||
void ScrollBar::setDesiredValue(qreal value, bool animated)
|
void ScrollBar::setDesiredValue(qreal value, bool animated)
|
||||||
{
|
{
|
||||||
|
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 != value) {
|
||||||
if (animated) {
|
if (animated) {
|
||||||
_currentValueAnimation.stop();
|
_currentValueAnimation.stop();
|
||||||
_currentValueAnimation.setStartValue(_currentValue);
|
_currentValueAnimation.setStartValue(_currentValue + this->_smoothScrollingOffset);
|
||||||
|
|
||||||
_currentValueAnimation.setEndValue(value);
|
_currentValueAnimation.setEndValue(value);
|
||||||
_currentValueAnimation.start();
|
_currentValueAnimation.start();
|
||||||
|
@ -133,6 +135,7 @@ void ScrollBar::setDesiredValue(qreal value, bool animated)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->_smoothScrollingOffset = 0;
|
||||||
_desiredValue = value;
|
_desiredValue = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,6 +169,15 @@ qreal ScrollBar::getCurrentValue() const
|
||||||
return _currentValue;
|
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()
|
boost::signals2::signal<void()> &ScrollBar::getCurrentValueChanged()
|
||||||
{
|
{
|
||||||
return _currentValueChanged;
|
return _currentValueChanged;
|
||||||
|
@ -173,7 +185,8 @@ boost::signals2::signal<void()> &ScrollBar::getCurrentValueChanged()
|
||||||
|
|
||||||
void ScrollBar::setCurrentValue(qreal value)
|
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) {
|
if (_currentValue != value) {
|
||||||
_currentValue = value;
|
_currentValue = value;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <boost/signals2.hpp>
|
#include <boost/signals2.hpp>
|
||||||
|
#include <settingsmanager.hpp>
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
|
@ -44,6 +45,8 @@ public:
|
||||||
qreal getSmallChange() const;
|
qreal getSmallChange() const;
|
||||||
qreal getDesiredValue() const;
|
qreal getDesiredValue() const;
|
||||||
qreal getCurrentValue() const;
|
qreal getCurrentValue() const;
|
||||||
|
// offset the desired value without breaking smooth scolling
|
||||||
|
void offset(qreal value);
|
||||||
boost::signals2::signal<void()> &getCurrentValueChanged();
|
boost::signals2::signal<void()> &getCurrentValueChanged();
|
||||||
void setCurrentValue(qreal value);
|
void setCurrentValue(qreal value);
|
||||||
|
|
||||||
|
@ -79,9 +82,12 @@ private:
|
||||||
qreal _smallChange = 5;
|
qreal _smallChange = 5;
|
||||||
qreal _desiredValue = 0;
|
qreal _desiredValue = 0;
|
||||||
qreal _currentValue = 0;
|
qreal _currentValue = 0;
|
||||||
|
qreal _smoothScrollingOffset = 0;
|
||||||
|
|
||||||
boost::signals2::signal<void()> _currentValueChanged;
|
boost::signals2::signal<void()> _currentValueChanged;
|
||||||
|
|
||||||
|
pajlada::Settings::Setting<bool> &smoothScrollingSetting;
|
||||||
|
|
||||||
void updateScroll();
|
void updateScroll();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue