# HG changeset patch # User unc0rr # Date 1359308785 -14400 # Node ID 8c7da08df048b5b7657618f1db75fc384d1ef60a # Parent 2816230a107ecd61d7b20d3539f530ab200f6e1b Allow navigating backwards chat widget log while new lines are being added diff -r 2816230a107e -r 8c7da08df048 QTfrontend/hwform.cpp --- a/QTfrontend/hwform.cpp Sun Jan 27 02:09:02 2013 +0100 +++ b/QTfrontend/hwform.cpp Sun Jan 27 21:46:25 2013 +0400 @@ -1278,7 +1278,7 @@ connect(hwnet, SIGNAL(chatStringLobby(const QString&)), ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); connect(hwnet, SIGNAL(chatStringLobby(const QString&, const QString&)), - ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&, const QString&))); + ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&, const QString&)), Qt::QueuedConnection); connect(hwnet, SIGNAL(chatStringFromMeLobby(const QString&)), ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); diff -r 2816230a107e -r 8c7da08df048 QTfrontend/ui/widget/chatwidget.cpp --- a/QTfrontend/ui/widget/chatwidget.cpp Sun Jan 27 02:09:02 2013 +0100 +++ b/QTfrontend/ui/widget/chatwidget.cpp Sun Jan 27 21:46:25 2013 +0400 @@ -31,6 +31,7 @@ #include #include #include +#include #include "DataManager.h" #include "hwconsts.h" @@ -156,24 +157,18 @@ void HWChatWidget::displayError(const QString & message) { addLine("msg_Error", " !!! " + message); - // scroll to the end - chatText->moveCursor(QTextCursor::End); } void HWChatWidget::displayNotice(const QString & message) { addLine("msg_Notice", " *** " + message); - // scroll to the end - chatText->moveCursor(QTextCursor::End); } void HWChatWidget::displayWarning(const QString & message) { addLine("msg_Warning", " *!* " + message); - // scroll to the end - chatText->moveCursor(QTextCursor::End); } @@ -451,6 +446,8 @@ if (s_displayNone->contains(cssClass)) return; // the css forbids us to display this line + beforeContentAdd(); + if (chatStrings.size() > 250) chatStrings.removeFirst(); @@ -473,11 +470,13 @@ chatText->setHtml(""+chatStrings.join("
")+""); - chatText->moveCursor(QTextCursor::End); + afterContentAdd(); } void HWChatWidget::onServerMessage(const QString& str) { + beforeContentAdd(); + if (chatStrings.size() > 250) chatStrings.removeFirst(); @@ -485,7 +484,7 @@ chatText->setHtml(""+chatStrings.join("
")+""); - chatText->moveCursor(QTextCursor::End); + afterContentAdd(); } @@ -901,3 +900,21 @@ m_nicksMenu->popup(chatNicks->mapToGlobal(pos)); } + +void HWChatWidget::beforeContentAdd() +{ + m_scrollBarPos = chatText->verticalScrollBar()->value(); + m_scrollToBottom = m_scrollBarPos == chatText->verticalScrollBar()->maximum(); +} + +void HWChatWidget::afterContentAdd() +{ + if(m_scrollToBottom) + { + chatText->verticalScrollBar()->setValue(chatText->verticalScrollBar()->maximum()); + chatText->moveCursor(QTextCursor::End); + } else + { + chatText->verticalScrollBar()->setValue(m_scrollBarPos); + } +} diff -r 2816230a107e -r 8c7da08df048 QTfrontend/ui/widget/chatwidget.h --- a/QTfrontend/ui/widget/chatwidget.h Sun Jan 27 02:09:02 2013 +0100 +++ b/QTfrontend/ui/widget/chatwidget.h Sun Jan 27 21:46:25 2013 +0400 @@ -83,6 +83,8 @@ void discardStyleSheet(); void saveStyleSheet(); QString linkedNick(const QString & nickname); + void beforeContentAdd(); + void afterContentAdd(); public slots: void onChatString(const QString& str); @@ -124,6 +126,8 @@ QList m_highlights; ///< regular expressions used for highlighting bool notify; bool m_autoKickEnabled; + bool m_scrollToBottom; + int m_scrollBarPos; private slots: void returnPressed();