From 3129d2aded8a323dce9a184e3da99daac8bea35a Mon Sep 17 00:00:00 2001 From: ghostfeesh Date: Sat, 28 Jul 2018 07:06:42 +0800 Subject: Reverse IC log config option (#22) The way it should have been. Reverse IC logs, now in configurable in config.ini. Set to false by default. Now you can go up or down as and when you please. (thanks argo for putting up with my trash code) --- courtroom.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'courtroom.cpp') diff --git a/courtroom.cpp b/courtroom.cpp index 717a13c3..76d6b03f 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1145,14 +1145,27 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) 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_up = old_scrollbar_value == ui_ic_chatlog->verticalScrollBar()->minimum(); - - ui_ic_chatlog->moveCursor(QTextCursor::Start); + + QTextCursor::MoveOperation move_op; + int scrollbar_limit; + + if(ao_app->ic_scroll_down_enabled()) { + scrollbar_limit = ui_ic_chatlog->verticalScrollBar()->maximum(); + move_op = QTextCursor::End; + } + else { + scrollbar_limit = ui_ic_chatlog->verticalScrollBar()->minimum(); + move_op = QTextCursor::Start; + } + + const bool is_fully_scrolled = old_scrollbar_value == scrollbar_limit; + + ui_ic_chatlog->moveCursor(move_op); ui_ic_chatlog->textCursor().insertText(p_name, bold); ui_ic_chatlog->textCursor().insertText(p_text + '\n', normal); - - if (old_cursor.hasSelection() || !is_scrolled_up) + + if (old_cursor.hasSelection() || !is_fully_scrolled) { // The user has selected text or scrolled away from the top: maintain position. ui_ic_chatlog->setTextCursor(old_cursor); @@ -1161,8 +1174,8 @@ 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::Start); - ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->minimum()); + ui_ic_chatlog->moveCursor(move_op); + ui_ic_chatlog->verticalScrollBar()->setValue(scrollbar_limit); } } -- cgit