summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorewewukek <ewewukek@gmail.com>2024-03-29 00:09:36 +0300
committerFedja Beader <fedja@protonmail.ch>2024-05-15 21:33:46 +0000
commitbaaf4e4f299573b951f377b421b2747a4f53e202 (patch)
treedde60c2efe1dd901242ae042dbf3a20856aa5373
parent99f361699e1c8bbc1e69f4d199863b836b3528a3 (diff)
downloadManaVerse-chat_scroll.tar.gz
ManaVerse-chat_scroll.tar.bz2
ManaVerse-chat_scroll.tar.xz
ManaVerse-chat_scroll.zip
Scroll #General chat tab to bottom on joinchat_scroll
Add ChatTab::scrollToBottom utility method Implement scrolling logic in loadFromLogFile
-rw-r--r--src/gui/widgets/tabs/chat/chattab.cpp19
-rw-r--r--src/gui/widgets/tabs/chat/chattab.h5
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();