mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
added smoothscrolling on new message
This commit is contained in:
parent
e58c5ec11b
commit
1606ea648b
6 changed files with 27 additions and 13 deletions
src
|
@ -40,6 +40,7 @@ public:
|
||||||
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 enableSmoothScrolling = {"/appearance/smoothScrolling", true};
|
||||||
|
BoolSetting enableSmoothScrollingNewMessages = {"/appearance/smoothScrolling", true};
|
||||||
// BoolSetting useCustomWindowFrame = {"/appearance/useCustomWindowFrame", false};
|
// BoolSetting useCustomWindowFrame = {"/appearance/useCustomWindowFrame", false};
|
||||||
|
|
||||||
/// Behaviour
|
/// Behaviour
|
||||||
|
|
|
@ -72,8 +72,12 @@ ChannelView::ChannelView(BaseWidget *parent)
|
||||||
this->layoutMessages(); //
|
this->layoutMessages(); //
|
||||||
}));
|
}));
|
||||||
|
|
||||||
connect(goToBottom, &RippleEffectLabel::clicked, this,
|
connect(goToBottom, &RippleEffectLabel::clicked, this, [this] {
|
||||||
[this] { QTimer::singleShot(180, [this] { this->scrollBar.scrollToBottom(); }); });
|
QTimer::singleShot(180, [this] {
|
||||||
|
this->scrollBar.scrollToBottom(singletons::SettingManager::getInstance()
|
||||||
|
.enableSmoothScrollingNewMessages.getValue());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
this->updateTimer.setInterval(1000 / 60);
|
this->updateTimer.setInterval(1000 / 60);
|
||||||
this->updateTimer.setSingleShot(true);
|
this->updateTimer.setSingleShot(true);
|
||||||
|
@ -186,13 +190,15 @@ void ChannelView::actuallyLayoutMessages()
|
||||||
|
|
||||||
this->scrollBar.setMaximum(messagesSnapshot.getLength());
|
this->scrollBar.setMaximum(messagesSnapshot.getLength());
|
||||||
|
|
||||||
|
// If we were showing the latest messages and the scrollbar now wants to be rendered, scroll
|
||||||
|
// to bottom
|
||||||
|
// TODO: Do we want to check if the user is currently moving the scrollbar?
|
||||||
|
// Perhaps also if the user scrolled with the scrollwheel in this ChatWidget in the last 0.2
|
||||||
|
// seconds or something
|
||||||
if (this->enableScrollingToBottom && this->showingLatestMessages && showScrollbar) {
|
if (this->enableScrollingToBottom && this->showingLatestMessages && showScrollbar) {
|
||||||
// If we were showing the latest messages and the scrollbar now wants to be rendered, scroll
|
this->scrollBar.scrollToBottom(
|
||||||
// to bottom
|
this->messageWasAdded &&
|
||||||
// TODO: Do we want to check if the user is currently moving the scrollbar?
|
singletons::SettingManager::getInstance().enableSmoothScrollingNewMessages.getValue());
|
||||||
// Perhaps also if the user scrolled with the scrollwheel in this ChatWidget in the last 0.2
|
|
||||||
// seconds or something
|
|
||||||
this->scrollBar.scrollToBottom();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK(timer);
|
// MARK(timer);
|
||||||
|
@ -377,7 +383,8 @@ void ChannelView::setChannel(std::shared_ptr<Channel> newChannel)
|
||||||
this->highlightedMessageReceived.invoke();
|
this->highlightedMessageReceived.invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
layoutMessages();
|
this->messageWasAdded = true;
|
||||||
|
this->layoutMessages();
|
||||||
});
|
});
|
||||||
|
|
||||||
this->messageAddedAtStartConnection =
|
this->messageAddedAtStartConnection =
|
||||||
|
@ -397,7 +404,8 @@ void ChannelView::setChannel(std::shared_ptr<Channel> newChannel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
layoutMessages();
|
this->messageWasAdded = true;
|
||||||
|
this->layoutMessages();
|
||||||
});
|
});
|
||||||
|
|
||||||
// on message removed
|
// on message removed
|
||||||
|
|
|
@ -71,6 +71,7 @@ private:
|
||||||
|
|
||||||
QTimer updateTimer;
|
QTimer updateTimer;
|
||||||
bool updateQueued = false;
|
bool updateQueued = false;
|
||||||
|
bool messageWasAdded = false;
|
||||||
|
|
||||||
void detachChannel();
|
void detachChannel();
|
||||||
void actuallyLayoutMessages();
|
void actuallyLayoutMessages();
|
||||||
|
|
|
@ -89,9 +89,9 @@ void ScrollBar::addHighlight(ScrollBarHighlight *highlight)
|
||||||
this->mutex.unlock();
|
this->mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollBar::scrollToBottom()
|
void ScrollBar::scrollToBottom(bool animate)
|
||||||
{
|
{
|
||||||
this->setDesiredValue(this->maximum - this->getLargeChange());
|
this->setDesiredValue(this->maximum - this->getLargeChange(), animate);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScrollBar::isAtBottom() const
|
bool ScrollBar::isAtBottom() const
|
||||||
|
|
|
@ -28,7 +28,7 @@ public:
|
||||||
|
|
||||||
Q_PROPERTY(qreal desiredValue READ getDesiredValue WRITE setDesiredValue)
|
Q_PROPERTY(qreal desiredValue READ getDesiredValue WRITE setDesiredValue)
|
||||||
|
|
||||||
void scrollToBottom();
|
void scrollToBottom(bool animate = false);
|
||||||
|
|
||||||
bool isAtBottom() const;
|
bool isAtBottom() const;
|
||||||
|
|
||||||
|
|
|
@ -280,6 +280,10 @@ QVBoxLayout *SettingsDialog::createAppearanceTab()
|
||||||
createCheckbox("Enable smooth scrolling", settings.enableSmoothScrolling);
|
createCheckbox("Enable smooth scrolling", settings.enableSmoothScrolling);
|
||||||
form->addRow("Scrolling:", enableSmoothScrolling);
|
form->addRow("Scrolling:", enableSmoothScrolling);
|
||||||
|
|
||||||
|
auto enableSmoothScrollingNewMessages = createCheckbox(
|
||||||
|
"Enable smooth scrolling for new messages", settings.enableSmoothScrolling);
|
||||||
|
form->addRow("", enableSmoothScrollingNewMessages);
|
||||||
|
|
||||||
group->setLayout(form);
|
group->setLayout(form);
|
||||||
|
|
||||||
layout->addWidget(group);
|
layout->addWidget(group);
|
||||||
|
|
Loading…
Reference in a new issue