The log now has an option to go both ways.
- Due to the log's nature, this must be set manually in one's `config.ini`.
This commit is contained in:
parent
7d476867cb
commit
366389c6bc
@ -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();
|
||||
|
||||
|
@ -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,6 +1312,12 @@ 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 (downwards)
|
||||
{
|
||||
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);
|
||||
@ -1326,6 +1331,28 @@ void Courtroom::append_ic_text(QString p_text, QString p_name)
|
||||
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 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
|
||||
{
|
||||
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);
|
||||
@ -1334,8 +1361,9 @@ void Courtroom::append_ic_text(QString p_text, QString p_name)
|
||||
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());
|
||||
ui_ic_chatlog->moveCursor(QTextCursor::Start);
|
||||
ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->minimum());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user