added smoothscrolling on new message
This commit is contained in:
@@ -40,6 +40,7 @@ public:
|
||||
BoolSetting hidePreferencesButton = {"/appearance/hidePreferencesButton", false};
|
||||
BoolSetting hideUserButton = {"/appearance/hideUserButton", false};
|
||||
BoolSetting enableSmoothScrolling = {"/appearance/smoothScrolling", true};
|
||||
BoolSetting enableSmoothScrollingNewMessages = {"/appearance/smoothScrolling", true};
|
||||
// BoolSetting useCustomWindowFrame = {"/appearance/useCustomWindowFrame", false};
|
||||
|
||||
/// Behaviour
|
||||
|
||||
@@ -72,8 +72,12 @@ ChannelView::ChannelView(BaseWidget *parent)
|
||||
this->layoutMessages(); //
|
||||
}));
|
||||
|
||||
connect(goToBottom, &RippleEffectLabel::clicked, this,
|
||||
[this] { QTimer::singleShot(180, [this] { this->scrollBar.scrollToBottom(); }); });
|
||||
connect(goToBottom, &RippleEffectLabel::clicked, this, [this] {
|
||||
QTimer::singleShot(180, [this] {
|
||||
this->scrollBar.scrollToBottom(singletons::SettingManager::getInstance()
|
||||
.enableSmoothScrollingNewMessages.getValue());
|
||||
});
|
||||
});
|
||||
|
||||
this->updateTimer.setInterval(1000 / 60);
|
||||
this->updateTimer.setSingleShot(true);
|
||||
@@ -186,13 +190,15 @@ void ChannelView::actuallyLayoutMessages()
|
||||
|
||||
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 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
|
||||
this->scrollBar.scrollToBottom();
|
||||
this->scrollBar.scrollToBottom(
|
||||
this->messageWasAdded &&
|
||||
singletons::SettingManager::getInstance().enableSmoothScrollingNewMessages.getValue());
|
||||
}
|
||||
|
||||
// MARK(timer);
|
||||
@@ -377,7 +383,8 @@ void ChannelView::setChannel(std::shared_ptr<Channel> newChannel)
|
||||
this->highlightedMessageReceived.invoke();
|
||||
}
|
||||
|
||||
layoutMessages();
|
||||
this->messageWasAdded = true;
|
||||
this->layoutMessages();
|
||||
});
|
||||
|
||||
this->messageAddedAtStartConnection =
|
||||
@@ -397,7 +404,8 @@ void ChannelView::setChannel(std::shared_ptr<Channel> newChannel)
|
||||
}
|
||||
}
|
||||
|
||||
layoutMessages();
|
||||
this->messageWasAdded = true;
|
||||
this->layoutMessages();
|
||||
});
|
||||
|
||||
// on message removed
|
||||
|
||||
@@ -71,6 +71,7 @@ private:
|
||||
|
||||
QTimer updateTimer;
|
||||
bool updateQueued = false;
|
||||
bool messageWasAdded = false;
|
||||
|
||||
void detachChannel();
|
||||
void actuallyLayoutMessages();
|
||||
|
||||
@@ -89,9 +89,9 @@ void ScrollBar::addHighlight(ScrollBarHighlight *highlight)
|
||||
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
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
|
||||
Q_PROPERTY(qreal desiredValue READ getDesiredValue WRITE setDesiredValue)
|
||||
|
||||
void scrollToBottom();
|
||||
void scrollToBottom(bool animate = false);
|
||||
|
||||
bool isAtBottom() const;
|
||||
|
||||
|
||||
@@ -280,6 +280,10 @@ QVBoxLayout *SettingsDialog::createAppearanceTab()
|
||||
createCheckbox("Enable smooth scrolling", settings.enableSmoothScrolling);
|
||||
form->addRow("Scrolling:", enableSmoothScrolling);
|
||||
|
||||
auto enableSmoothScrollingNewMessages = createCheckbox(
|
||||
"Enable smooth scrolling for new messages", settings.enableSmoothScrolling);
|
||||
form->addRow("", enableSmoothScrollingNewMessages);
|
||||
|
||||
group->setLayout(form);
|
||||
|
||||
layout->addWidget(group);
|
||||
|
||||
Reference in New Issue
Block a user