From 1774f6c9bdcddf9219afacd478a9ed8bc1856e96 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 23 Apr 2014 15:37:28 -0700 Subject: [PATCH 1/2] Add threshold to auto scroll --- interface/src/ui/ChatWindow.cpp | 10 +++++----- interface/src/ui/ChatWindow.h | 8 +++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/interface/src/ui/ChatWindow.cpp b/interface/src/ui/ChatWindow.cpp index d967e2305d..e0802c6bc5 100644 --- a/interface/src/ui/ChatWindow.cpp +++ b/interface/src/ui/ChatWindow.cpp @@ -171,7 +171,7 @@ void ChatWindow::addTimeStamp() { timeLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); timeLabel->setAlignment(Qt::AlignLeft); - bool atBottom = isAtBottom(); + bool atBottom = isNearBottom(); ui->messagesVBoxLayout->addWidget(timeLabel); ui->messagesVBoxLayout->parentWidget()->updateGeometry(); @@ -288,7 +288,7 @@ void ChatWindow::messageReceived(const QXmppMessage& message) { messageText = messageText.replace(regexHifiLinks, "\\1"); messageArea->setHtml(userLabel + messageText); - bool atBottom = isAtBottom(); + bool atBottom = isNearBottom(); ui->messagesVBoxLayout->addWidget(messageArea); ui->messagesVBoxLayout->parentWidget()->updateGeometry(); @@ -308,13 +308,13 @@ void ChatWindow::messageReceived(const QXmppMessage& message) { #endif -bool ChatWindow::isAtBottom() { +bool ChatWindow::isNearBottom() { 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. void ChatWindow::scrollToBottom() { QScrollBar* verticalScrollBar = ui->messagesScrollArea->verticalScrollBar(); - verticalScrollBar->setSliderPosition(verticalScrollBar->maximum()); + verticalScrollBar->setValue(verticalScrollBar->maximum()); } diff --git a/interface/src/ui/ChatWindow.h b/interface/src/ui/ChatWindow.h index 399c9e917c..104fbe1746 100644 --- a/interface/src/ui/ChatWindow.h +++ b/interface/src/ui/ChatWindow.h @@ -27,6 +27,12 @@ #endif namespace Ui { + + +// Maximum amount the chat can be scrolled up in order to auto scroll. +const int AUTO_SCROLL_THRESHOLD = 20; + + class ChatWindow; } @@ -49,7 +55,7 @@ private: #endif void startTimerForTimeStamps(); void addTimeStamp(); - bool isAtBottom(); + bool isNearBottom(); void scrollToBottom(); Ui::ChatWindow* ui; From 0cba95e7ad1f8550eec37743af415ba2b03f80a7 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 23 Apr 2014 15:37:49 -0700 Subject: [PATCH 2/2] Reorder property initialization in FramelessDialog --- interface/src/ui/FramelessDialog.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/ui/FramelessDialog.cpp b/interface/src/ui/FramelessDialog.cpp index 816c45b38a..4919e99db6 100644 --- a/interface/src/ui/FramelessDialog.cpp +++ b/interface/src/ui/FramelessDialog.cpp @@ -16,10 +16,10 @@ const int RESIZE_HANDLE_WIDTH = 7; FramelessDialog::FramelessDialog(QWidget *parent, Qt::WindowFlags flags, Position position) : QDialog(parent, flags | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint), - _position(position), - _selfHidden(false), _isResizing(false), - _resizeInitialWidth(0) { + _resizeInitialWidth(0), + _selfHidden(false), + _position(position) { setAttribute(Qt::WA_DeleteOnClose);