aboutsummaryrefslogtreecommitdiff
path: root/lobby.cpp
diff options
context:
space:
mode:
authorDavid Skoland <davidskoland@gmail.com>2017-01-31 00:20:08 +0100
committerDavid Skoland <davidskoland@gmail.com>2017-01-31 00:20:08 +0100
commit9031779bc93c376596d98ae1e3fb7df1c8742399 (patch)
tree5daacdd3f948868ab1dc54ecd440ddeed82f630c /lobby.cpp
parentba8b0e59d8ef62415331161a589fa88f1af4e21e (diff)
added custom classes, started working on viewport. wt/ce sfx done
Diffstat (limited to 'lobby.cpp')
-rw-r--r--lobby.cpp24
1 files changed, 22 insertions, 2 deletions
diff --git a/lobby.cpp b/lobby.cpp
index 836c5ac3..e73345c1 100644
--- a/lobby.cpp
+++ b/lobby.cpp
@@ -5,6 +5,7 @@
#include "networkmanager.h"
#include <QDebug>
+#include <QScrollBar>
Lobby::Lobby(AOApplication *p_ao_app) : QMainWindow()
{
@@ -307,9 +308,28 @@ void Lobby::list_favorites()
}
}
-void Lobby::append_chatmessage(QString p_message_line)
+void Lobby::append_chatmessage(QString f_message)
{
- ui_chatbox->appendPlainText(p_message_line);
+ const QTextCursor old_cursor = ui_chatbox->textCursor();
+ const int old_scrollbar_value = ui_chatbox->verticalScrollBar()->value();
+ const bool is_scrolled_down = old_scrollbar_value == ui_chatbox->verticalScrollBar()->maximum();
+
+ ui_chatbox->moveCursor(QTextCursor::End);
+
+ ui_chatbox->appendPlainText(f_message);
+
+ if (old_cursor.hasSelection() || !is_scrolled_down)
+ {
+ // The user has selected text or scrolled away from the bottom: maintain position.
+ ui_chatbox->setTextCursor(old_cursor);
+ ui_chatbox->verticalScrollBar()->setValue(old_scrollbar_value);
+ }
+ else
+ {
+ // The user hasn't selected any text and the scrollbar is at the bottom: scroll to the bottom.
+ ui_chatbox->moveCursor(QTextCursor::End);
+ ui_chatbox->verticalScrollBar()->setValue(ui_chatbox->verticalScrollBar()->maximum());
+ }
}
void Lobby::set_player_count(int players_online, int max_players)