diff --git a/courtroom.cpp b/courtroom.cpp
index ca94f43..decb772 100644
--- a/courtroom.cpp
+++ b/courtroom.cpp
@@ -83,6 +83,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
ui_ic_chatlog = new QTextEdit(this);
ui_ic_chatlog->setReadOnly(true);
+ ui_ic_chatlog->document()->setMaximumBlockCount(ao_app->get_max_log_size());
ui_ms_chatlog = new AOTextArea(this);
ui_ms_chatlog->setReadOnly(true);
@@ -1039,6 +1040,25 @@ void Courtroom::handle_chatmessage_2()
set_scene();
set_text_color();
+ // Check if the message needs to be centered.
+ QString f_message = m_chatmessage[MESSAGE];
+ if (f_message.size() >= 2)
+ {
+ if (f_message.startsWith("~~"))
+ {
+ message_is_centered = true;
+ }
+ else
+ {
+ message_is_centered = false;
+ }
+ }
+ else
+ {
+ ui_vp_message->setAlignment(Qt::AlignLeft);
+ }
+
+
int emote_mod = m_chatmessage[EMOTE_MOD].toInt();
if (ao_app->flipping_enabled && m_chatmessage[FLIP].toInt() == 1)
@@ -1156,14 +1176,22 @@ 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();
+ const bool is_scrolled_down = old_scrollbar_value == ui_ic_chatlog->verticalScrollBar()->maximum();
- ui_ic_chatlog->moveCursor(QTextCursor::Start);
+ ui_ic_chatlog->moveCursor(QTextCursor::End);
- ui_ic_chatlog->textCursor().insertText(p_name, bold);
- ui_ic_chatlog->textCursor().insertText(p_text + '\n', normal);
+ 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);
- if (old_cursor.hasSelection() || !is_scrolled_up)
+ 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);
@@ -1172,8 +1200,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(QTextCursor::End);
+ ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->maximum());
}
}
@@ -1238,6 +1266,13 @@ void Courtroom::start_chat_ticking()
return;
}
+ // At this point, we'd do well to clear the inline colour stack.
+ // This stops it from flowing into next messages.
+ while (!inline_colour_stack.empty())
+ {
+ inline_colour_stack.pop();
+ }
+
ui_vp_chatbox->show();
tick_pos = 0;
@@ -1301,8 +1336,94 @@ void Courtroom::chat_tick()
ui_vp_message->insertHtml("" + f_character + "");
}
+
+ else if (f_character == "\\" and !next_character_is_not_special)
+ {
+ next_character_is_not_special = true;
+ }
+
+ else if (f_character == "{" and !next_character_is_not_special)
+ {
+ inline_colour_stack.push(INLINE_ORANGE);
+ }
+ else if (f_character == "}" and !next_character_is_not_special
+ and !inline_colour_stack.empty())
+ {
+ if (inline_colour_stack.top() == INLINE_ORANGE)
+ {
+ inline_colour_stack.pop();
+ }
+ }
+
+ else if (f_character == "(" and !next_character_is_not_special)
+ {
+ inline_colour_stack.push(INLINE_BLUE);
+ ui_vp_message->insertHtml("" + f_character + "");
+ }
+ else if (f_character == ")" and !next_character_is_not_special
+ and !inline_colour_stack.empty())
+ {
+ if (inline_colour_stack.top() == INLINE_BLUE)
+ {
+ inline_colour_stack.pop();
+ ui_vp_message->insertHtml("" + f_character + "");
+ }
+ }
+
+ else if (f_character == "$" and !next_character_is_not_special)
+ {
+ if (!inline_colour_stack.empty())
+ {
+ if (inline_colour_stack.top() == INLINE_GREEN)
+ {
+ inline_colour_stack.pop();
+ }
+ else
+ {
+ inline_colour_stack.push(INLINE_GREEN);
+ }
+ }
+ else
+ {
+ inline_colour_stack.push(INLINE_GREEN);
+ }
+ }
+
else
- ui_vp_message->insertHtml(f_character);
+ {
+ next_character_is_not_special = false;
+ if (!inline_colour_stack.empty())
+ {
+ switch (inline_colour_stack.top()) {
+ case INLINE_ORANGE:
+ ui_vp_message->insertHtml("" + f_character + "");
+ break;
+ case INLINE_BLUE:
+ ui_vp_message->insertHtml("" + f_character + "");
+ break;
+ case INLINE_GREEN:
+ ui_vp_message->insertHtml("" + f_character + "");
+ break;
+ default:
+ ui_vp_message->insertHtml(f_character);
+ break;
+ }
+
+ }
+ else
+ {
+ ui_vp_message->insertHtml(f_character);
+ }
+
+ if (message_is_centered)
+ {
+ ui_vp_message->setAlignment(Qt::AlignCenter);
+ }
+ else
+ {
+ ui_vp_message->setAlignment(Qt::AlignLeft);
+ }
+ }
QScrollBar *scroll = ui_vp_message->verticalScrollBar();
scroll->setValue(scroll->maximum());
@@ -1975,6 +2096,9 @@ void Courtroom::on_reload_theme_clicked()
{
ao_app->reload_theme();
+ //Refresh IC chat limits.
+ ui_ic_chatlog->document()->setMaximumBlockCount(ao_app->get_max_log_size());
+
//to update status on the background
set_background(current_background);
enter_courtroom(m_cid);
diff --git a/courtroom.h b/courtroom.h
index 85554a0..a4e08df 100644
--- a/courtroom.h
+++ b/courtroom.h
@@ -32,6 +32,8 @@
#include
#include
+#include
+
class AOApplication;
class Courtroom : public QMainWindow
@@ -147,6 +149,26 @@ private:
int m_viewport_width = 256;
int m_viewport_height = 192;
+ bool first_message_sent = false;
+ int maximumMessages = 0;
+
+ // This is for inline message-colouring.
+ enum INLINE_COLOURS {
+ INLINE_BLUE,
+ INLINE_GREEN,
+ INLINE_ORANGE
+ };
+
+ // A stack of inline colours.
+ std::stack inline_colour_stack;
+
+ bool centre_text = false;
+
+ bool next_character_is_not_special = false; // If true, write the
+ // next character as it is.
+
+ bool message_is_centered = false;
+
QVector char_list;
QVector evidence_list;
QVector music_list;