aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--aoapplication.h4
-rw-r--r--courtroom.cpp68
-rw-r--r--text_file_functions.cpp12
3 files changed, 64 insertions, 20 deletions
diff --git a/aoapplication.h b/aoapplication.h
index 947bb1df..d94cd2af 100644
--- a/aoapplication.h
+++ b/aoapplication.h
@@ -133,6 +133,10 @@ public:
//may contain, from config.ini.
int get_max_log_size();
+ // Returns whether the log should go upwards (new behaviour)
+ // or downwards (vanilla behaviour).
+ bool get_log_goes_downwards();
+
// Returns the username the user may have set in config.ini.
QString get_default_username();
diff --git a/courtroom.cpp b/courtroom.cpp
index 4e1529b7..fda29cec 100644
--- a/courtroom.cpp
+++ b/courtroom.cpp
@@ -1175,15 +1175,14 @@ void Courtroom::handle_chatmessage_3()
void Courtroom::append_ic_text(QString p_text, QString p_name)
{
+ bool downwards = ao_app->get_log_goes_downwards();
+
QTextCharFormat bold;
QTextCharFormat normal;
bold.setFontWeight(QFont::Bold);
normal.setFontWeight(QFont::Normal);
const QTextCursor old_cursor = ui_ic_chatlog->textCursor();
const int old_scrollbar_value = ui_ic_chatlog->verticalScrollBar()->value();
- const bool is_scrolled_down = old_scrollbar_value == ui_ic_chatlog->verticalScrollBar()->maximum();
-
- ui_ic_chatlog->moveCursor(QTextCursor::End);
// Get rid of centering.
if(p_text.startsWith(": ~~"))
@@ -1313,29 +1312,58 @@ void Courtroom::append_ic_text(QString p_text, QString p_name)
// After all of that, let's jot down the message into the IC chatlog.
- if (!first_message_sent)
- {
- ui_ic_chatlog->textCursor().insertText(p_name, bold);
- first_message_sent = true;
- }
- else
+ if (downwards)
{
- ui_ic_chatlog->textCursor().insertText('\n' + p_name, bold);
- }
+ const bool is_scrolled_down = old_scrollbar_value == ui_ic_chatlog->verticalScrollBar()->maximum();
+
+ ui_ic_chatlog->moveCursor(QTextCursor::End);
+
+ if (!first_message_sent)
+ {
+ ui_ic_chatlog->textCursor().insertText(p_name, bold);
+ first_message_sent = true;
+ }
+ else
+ {
+ ui_ic_chatlog->textCursor().insertText('\n' + p_name, bold);
+ }
- ui_ic_chatlog->textCursor().insertText(p_text, normal);
+ ui_ic_chatlog->textCursor().insertText(p_text, normal);
- if (old_cursor.hasSelection() || !is_scrolled_down)
- {
- // The user has selected text or scrolled away from the top: maintain position.
- ui_ic_chatlog->setTextCursor(old_cursor);
- ui_ic_chatlog->verticalScrollBar()->setValue(old_scrollbar_value);
+ if (old_cursor.hasSelection() || !is_scrolled_down)
+ {
+ // 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 bottom: scroll to the top.
+ ui_ic_chatlog->moveCursor(QTextCursor::End);
+ ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->maximum());
+ }
}
else
{
- // The user hasn't selected any text and the scrollbar is at the top: scroll to the top.
- ui_ic_chatlog->moveCursor(QTextCursor::End);
- ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->maximum());
+ const bool is_scrolled_up = old_scrollbar_value == ui_ic_chatlog->verticalScrollBar()->minimum();
+
+ ui_ic_chatlog->moveCursor(QTextCursor::Start);
+
+ ui_ic_chatlog->textCursor().insertText(p_name, bold);
+ ui_ic_chatlog->textCursor().insertText(p_text + '\n', normal);
+
+ if (old_cursor.hasSelection() || !is_scrolled_up)
+ {
+ // The user has selected text or scrolled away from the top: 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(ui_ic_chatlog->verticalScrollBar()->minimum());
+ }
}
}
diff --git a/text_file_functions.cpp b/text_file_functions.cpp
index db858cb9..1389cf58 100644
--- a/text_file_functions.cpp
+++ b/text_file_functions.cpp
@@ -99,6 +99,18 @@ int AOApplication::get_max_log_size()
else return f_result.toInt();
}
+bool AOApplication::get_log_goes_downwards()
+{
+ QString f_result = read_config("log_goes_downwards");
+
+ if (f_result == "true")
+ return true;
+ else if (f_result == "false")
+ return false;
+ else
+ return true;
+}
+
QString AOApplication::get_default_username()
{
QString f_result = read_config("default_username");