mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 09:48:44 +02:00
Add threshold to auto scroll
This commit is contained in:
parent
d56a4e169e
commit
1774f6c9bd
2 changed files with 12 additions and 6 deletions
|
@ -171,7 +171,7 @@ void ChatWindow::addTimeStamp() {
|
||||||
timeLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
timeLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||||
timeLabel->setAlignment(Qt::AlignLeft);
|
timeLabel->setAlignment(Qt::AlignLeft);
|
||||||
|
|
||||||
bool atBottom = isAtBottom();
|
bool atBottom = isNearBottom();
|
||||||
|
|
||||||
ui->messagesVBoxLayout->addWidget(timeLabel);
|
ui->messagesVBoxLayout->addWidget(timeLabel);
|
||||||
ui->messagesVBoxLayout->parentWidget()->updateGeometry();
|
ui->messagesVBoxLayout->parentWidget()->updateGeometry();
|
||||||
|
@ -288,7 +288,7 @@ void ChatWindow::messageReceived(const QXmppMessage& message) {
|
||||||
messageText = messageText.replace(regexHifiLinks, "<a href=\"hifi://\\1\">\\1</a>");
|
messageText = messageText.replace(regexHifiLinks, "<a href=\"hifi://\\1\">\\1</a>");
|
||||||
messageArea->setHtml(userLabel + messageText);
|
messageArea->setHtml(userLabel + messageText);
|
||||||
|
|
||||||
bool atBottom = isAtBottom();
|
bool atBottom = isNearBottom();
|
||||||
|
|
||||||
ui->messagesVBoxLayout->addWidget(messageArea);
|
ui->messagesVBoxLayout->addWidget(messageArea);
|
||||||
ui->messagesVBoxLayout->parentWidget()->updateGeometry();
|
ui->messagesVBoxLayout->parentWidget()->updateGeometry();
|
||||||
|
@ -308,13 +308,13 @@ void ChatWindow::messageReceived(const QXmppMessage& message) {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool ChatWindow::isAtBottom() {
|
bool ChatWindow::isNearBottom() {
|
||||||
QScrollBar* verticalScrollBar = ui->messagesScrollArea->verticalScrollBar();
|
QScrollBar* verticalScrollBar = ui->messagesScrollArea->verticalScrollBar();
|
||||||
return verticalScrollBar->sliderPosition() == verticalScrollBar->maximum();
|
return verticalScrollBar->value() >= verticalScrollBar->maximum() - Ui::AUTO_SCROLL_THRESHOLD;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scroll chat message area to bottom.
|
// Scroll chat message area to bottom.
|
||||||
void ChatWindow::scrollToBottom() {
|
void ChatWindow::scrollToBottom() {
|
||||||
QScrollBar* verticalScrollBar = ui->messagesScrollArea->verticalScrollBar();
|
QScrollBar* verticalScrollBar = ui->messagesScrollArea->verticalScrollBar();
|
||||||
verticalScrollBar->setSliderPosition(verticalScrollBar->maximum());
|
verticalScrollBar->setValue(verticalScrollBar->maximum());
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,12 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
||||||
|
|
||||||
|
// Maximum amount the chat can be scrolled up in order to auto scroll.
|
||||||
|
const int AUTO_SCROLL_THRESHOLD = 20;
|
||||||
|
|
||||||
|
|
||||||
class ChatWindow;
|
class ChatWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +55,7 @@ private:
|
||||||
#endif
|
#endif
|
||||||
void startTimerForTimeStamps();
|
void startTimerForTimeStamps();
|
||||||
void addTimeStamp();
|
void addTimeStamp();
|
||||||
bool isAtBottom();
|
bool isNearBottom();
|
||||||
void scrollToBottom();
|
void scrollToBottom();
|
||||||
|
|
||||||
Ui::ChatWindow* ui;
|
Ui::ChatWindow* ui;
|
||||||
|
|
Loading…
Reference in a new issue