aboutsummaryrefslogtreecommitdiff
path: root/courtroom.cpp
diff options
context:
space:
mode:
authorstonedDiscord <stoned@derpymail.org>2017-01-29 16:54:33 +0100
committerGitHub <noreply@github.com>2017-01-29 16:54:33 +0100
commit362ec49351e144a514551d4fcf61e1db58b2a8a7 (patch)
tree2eb414fe67d750a858b69ea2d749a021cfb82355 /courtroom.cpp
parent49f127ec8162a81caba9ea195a35b88276b4523d (diff)
parenteffd224b4498d419adc24d641eebce020cee9301 (diff)
Merge pull request #3 from OmniTroid/master
added more flexible scrollbar in courtroom
Diffstat (limited to 'courtroom.cpp')
-rw-r--r--courtroom.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/courtroom.cpp b/courtroom.cpp
index 70babcbe..ebd2ece6 100644
--- a/courtroom.cpp
+++ b/courtroom.cpp
@@ -6,6 +6,7 @@
#include "file_functions.h"
#include <QDebug>
+#include <QScrollBar>
Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
{
@@ -461,8 +462,30 @@ void Courtroom::handle_chatmessage(QStringList *p_contents)
{
QString f_message = p_contents->at(2) + ": " + p_contents->at(4) + '\n';
+ //ui_ic_chatlog->moveCursor(QTextCursor::Start);
+ //ui_ic_chatlog->insertPlainText(f_message);
+
+ const QTextCursor old_cursor = ui_ic_chatlog->textCursor();
+ const int old_scrollbar_value = ui_ic_chatlog->verticalScrollBar()->value();
+ const bool is_scrolled_up = old_scrollbar_value == ui_ic_chatlog->verticalScrollBar()->minimum();
+
ui_ic_chatlog->moveCursor(QTextCursor::Start);
- ui_ic_chatlog->insertPlainText(f_message);
+
+ ui_ic_chatlog->textCursor().insertText(f_message);
+
+ if (old_cursor.hasSelection() || !is_scrolled_up)
+ {
+ // The user has selected text or scrolled away from the bottom: maintain position.
+ ui_ic_chatlog->setTextCursor(old_cursor);
+ ui_ic_chatlog->verticalScrollBar()->setValue(old_scrollbar_value);
+ }
+ else
+ {
+ // The user hasn't selected any text and the scrollbar is at the top: scroll to the top.
+ ui_ic_chatlog->moveCursor(QTextCursor::Start);
+ //ui_ic_chatlog->verticalScrollBar()->setValue(verticalScrollBar()->minimum());
+ ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->minimum());
+ }
//T0D0: play objection gif->preanimation if there is any
}