diff options
-rw-r--r-- | src/gui/widgets/tabs/chat/chattab.cpp | 19 | ||||
-rw-r--r-- | src/gui/widgets/tabs/chat/chattab.h | 5 |
2 files changed, 20 insertions, 4 deletions
diff --git a/src/gui/widgets/tabs/chat/chattab.cpp b/src/gui/widgets/tabs/chat/chattab.cpp index ec9042694..f411249fe 100644 --- a/src/gui/widgets/tabs/chat/chattab.cpp +++ b/src/gui/widgets/tabs/chat/chattab.cpp @@ -290,8 +290,7 @@ void ChatTab::chatLog(std::string line, mScrollArea->getVerticalMaxScroll()) { addRow(line); - mScrollArea->setVerticalScrollAmount( - mScrollArea->getVerticalMaxScroll()); + scrollToBottom(); } else { @@ -428,6 +427,12 @@ void ChatTab::scroll(const int amount) mTextOutput->showPart(scr); } +void ChatTab::scrollToBottom() +{ + mScrollArea->setVerticalScrollAmount( + mScrollArea->getVerticalMaxScroll()); +} + void ChatTab::clearText() { mTextOutput->clearRows(); @@ -514,6 +519,9 @@ void ChatTab::loadFromLogFile(const std::string &name) { if (chatLogger != nullptr) { + bool doScroll = mScrollArea->getVerticalScrollAmount() >= + mScrollArea->getVerticalMaxScroll(); + std::list<std::string> list; chatLogger->loadLast(name, list, 5); std::list<std::string>::const_iterator i = list.begin(); @@ -523,6 +531,10 @@ void ChatTab::loadFromLogFile(const std::string &name) addRow(line); ++i; } + + if (doScroll) + scrollToBottom(); + mScrollArea->logic(); } } @@ -532,8 +544,7 @@ void ChatTab::addNewRow(std::string &line) mScrollArea->getVerticalMaxScroll()) { addRow(line); - mScrollArea->setVerticalScrollAmount( - mScrollArea->getVerticalMaxScroll()); + scrollToBottom(); } else { diff --git a/src/gui/widgets/tabs/chat/chattab.h b/src/gui/widgets/tabs/chat/chattab.h index 7a3774fc2..adb14861d 100644 --- a/src/gui/widgets/tabs/chat/chattab.h +++ b/src/gui/widgets/tabs/chat/chattab.h @@ -114,6 +114,11 @@ class ChatTab notfinal : public Tab void scroll(const int amount); /** + * Scrolls the chat window to the bottom + */ + void scrollToBottom(); + + /** * Clears the text from the tab */ void clearText(); |