Allow char.ini to override the chat font and font size with chat_font = and chat_size =

Scream at the coders that decided hard-coding fonts and colors was a good idea (gotta properly let the themes modify that later)
Fix a lot of ui elements not properly respecting the themes and their colors
add a set_qfont method for those situations that need it
Allow the theme to change sender colors for ooc and ms chatlogs
rename url parser variable to something more immediately apparent as to what it is for readability's sake
This commit is contained in:
Crystalwarrior 2019-09-16 06:09:39 +03:00
parent 03ebad6bb6
commit 9b39b7d6aa
8 changed files with 63 additions and 18 deletions

View File

@ -261,9 +261,15 @@ public:
//Returns the showname from the ini of p_char
QString get_showname(QString p_char);
//Returns the value of chat from the specific p_char's ini file
//Returns the value of chat image from the specific p_char's ini file
QString get_chat(QString p_char);
//Returns the value of chat font from the specific p_char's ini file
QString get_chat_font(QString p_char);
//Returns the value of chat font size from the specific p_char's ini file
int get_chat_size(QString p_char);
//Returns the value of shouts from the specified p_char's ini file
QString get_char_shouts(QString p_char);

View File

@ -16,7 +16,7 @@ public:
void append_error(QString p_message);
private:
const QRegExp omnis_dank_url_regex = QRegExp("\\b(https?://\\S+\\.\\S+)\\b");
const QRegExp url_parser_regex = QRegExp("\\b(https?://\\S+\\.\\S+)\\b");
void auto_scroll(QTextCursor old_cursor, int scrollbar_value, bool is_scrolled_down);
};

View File

@ -117,8 +117,13 @@ public:
//sets position of widgets based on theme ini files
void set_widgets();
//sets font size based on theme ini files
void set_font(QWidget *widget, QString p_identifier);
//actual operation of setting the font on a widget
void set_qfont(QWidget *widget, QFont font, QColor f_color = Qt::black, bool bold = false);
//helper function that calls above function on the relevant widgets
void set_fonts();

View File

@ -18,7 +18,7 @@ void AOTextArea::append_chatmessage(QString p_name, QString p_message, QString p
//cheap workarounds ahoy
p_message += " ";
QString result = p_message.toHtmlEscaped().replace("\n", "<br>").replace(omnis_dank_url_regex, "<a href='\\1'>\\1</a>" );
QString result = p_message.toHtmlEscaped().replace("\n", "<br>").replace(url_parser_regex, "<a href='\\1'>\\1</a>" );
this->insertHtml(result);
@ -36,7 +36,7 @@ void AOTextArea::append_error(QString p_message)
this->append("");
p_message += " ";
QString result = p_message.replace("\n", "<br>").replace(omnis_dank_url_regex, "<a href='\\1'>\\1</a>" );
QString result = p_message.replace("\n", "<br>").replace(url_parser_regex, "<a href='\\1'>\\1</a>" );
this->insertHtml("<font color='red'>" + result + "</font>");

View File

@ -86,6 +86,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
ui_vp_chatbox = new AOImage(this, ao_app);
ui_vp_showname = new QLabel(ui_vp_chatbox);
ui_vp_showname->setAlignment(Qt::AlignHCenter);
ui_vp_message = new QTextEdit(this);
ui_vp_message->setFrameStyle(QFrame::NoFrame);
ui_vp_message->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
@ -482,8 +483,8 @@ void Courtroom::set_widgets()
//We detached the text as parent from the chatbox so it doesn't get affected by the screenshake.
ui_vp_message->move(ui_vp_message->x() + ui_vp_chatbox->x(), ui_vp_message->y() + ui_vp_chatbox->y());
ui_vp_message->setTextInteractionFlags(Qt::NoTextInteraction);
ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);"
"color: white");
// ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);"
// "color: white");
ui_vp_testimony->move(ui_viewport->x(), ui_viewport->y());
ui_vp_testimony->combo_resize(ui_viewport->width(), ui_viewport->height());
@ -514,8 +515,6 @@ void Courtroom::set_widgets()
ui_pair_button->set_image("pair_button.png");
set_size_and_pos(ui_area_list, "music_list");
ui_area_list->setStyleSheet("background-color: rgba(0, 0, 0, 0);");
set_size_and_pos(ui_music_list, "music_list");
if (is_ao2_bg)
@ -739,18 +738,20 @@ void Courtroom::set_font(QWidget *widget, QString p_identifier)
{
QString design_file = "courtroom_fonts.ini";
int f_weight = ao_app->get_font_size(p_identifier, design_file);
QString class_name = widget->metaObject()->className();
QString font_name = ao_app->get_font_name(p_identifier + "_font", design_file);
widget->setFont(QFont(font_name, f_weight));
QColor f_color = ao_app->get_color(p_identifier + "_color", design_file);
int bold = ao_app->get_font_size(p_identifier + "_bold", design_file); // is the font bold or not?
bool bold = static_cast<bool>(ao_app->get_font_size(p_identifier + "_bold", design_file)); // is the font bold or not?
this->set_qfont(widget, QFont(font_name, f_weight), f_color, bold);
}
void Courtroom::set_qfont(QWidget *widget, QFont font, QColor f_color, bool bold)
{
QString class_name = widget->metaObject()->className();
widget->setFont(font);
QString is_bold = "";
if(bold == 1) is_bold = "bold";
if(bold) is_bold = "bold";
QString style_sheet_string = class_name + " { background-color: rgba(0, 0, 0, 0);\n" +
"color: rgba(" +
@ -1094,7 +1095,7 @@ void Courtroom::list_areas()
void Courtroom::append_ms_chatmessage(QString f_name, QString f_message)
{
ui_ms_chatlog->append_chatmessage(f_name, f_message, ao_app->get_color("ooc_default_color", "courtroom_design.ini").name());
ui_ms_chatlog->append_chatmessage(f_name, f_message, ao_app->get_color("ms_chatlog_sender_color", "courtroom_fonts.ini").name());
}
void Courtroom::append_server_chatmessage(QString p_name, QString p_message, QString p_colour)
@ -1102,9 +1103,9 @@ void Courtroom::append_server_chatmessage(QString p_name, QString p_message, QSt
QString colour = "#000000";
if (p_colour == "0")
colour = ao_app->get_color("ooc_default_color", "courtroom_design.ini").name();
colour = ao_app->get_color("ms_chatlog_sender_color", "courtroom_fonts.ini").name();
if (p_colour == "1")
colour = ao_app->get_color("ooc_server_color", "courtroom_design.ini").name();
colour = ao_app->get_color("server_chatlog_sender_color", "courtroom_fonts.ini").name();
if(p_message == "Logged in as a moderator.")
{
ui_guard->show();
@ -1505,6 +1506,21 @@ void Courtroom::handle_chatmessage_2()
ui_vp_chatbox->set_image_from_path(chatbox_path);
}
QString design_file = "courtroom_fonts.ini";
int f_weight = ao_app->get_font_size("message", design_file);
QString font_name = ao_app->get_font_name("message_font", design_file);
QColor f_color = ao_app->get_color("message_color", design_file);
bool bold = static_cast<bool>(ao_app->get_font_size("message_bold", design_file)); // is the font bold or not?
QString chatfont = ao_app->get_chat_font(m_chatmessage[CHAR_NAME]);
if (chatfont != "")
font_name = chatfont;
int chatsize = ao_app->get_chat_size(m_chatmessage[CHAR_NAME]);
if (chatsize != -1)
f_weight = chatsize;
this->set_qfont(ui_vp_message, QFont(font_name, f_weight), f_color, bold);
ui_vp_showname->setStyleSheet("QLabel { color : " + get_text_color("_showname").name() + "; }");
set_scene();

View File

@ -7,6 +7,7 @@ void Courtroom::construct_evidence()
//ui_evidence_name = new QLabel(ui_evidence);
ui_evidence_name = new AOLineEdit(ui_evidence);
ui_evidence_name->setAlignment(Qt::AlignCenter);
//WHY IS THIS FONT HARDCODED, WHAT IS WRONG WITH YOU
ui_evidence_name->setFont(QFont("Arial", 14, QFont::Bold));
ui_evidence_name->setStyleSheet("background-color: rgba(0, 0, 0, 0);"
"color: rgba(255, 128, 0, 255);");

View File

@ -139,6 +139,7 @@ void Lobby::set_widgets()
set_size_and_pos(ui_loading_text, "loading_label");
//WHY IS THIS FONT HARDCODED, WHAT IS WRONG WITH YOU
ui_loading_text->setFont(QFont("Arial", 20, QFont::Bold));
ui_loading_text->setReadOnly(true);
ui_loading_text->setAlignment(Qt::AlignCenter);

View File

@ -576,6 +576,22 @@ QString AOApplication::get_chat(QString p_char)
return f_result;
}
QString AOApplication::get_chat_font(QString p_char)
{
QString f_result = read_char_ini(p_char, "chat_font", "Options");
return f_result;
}
int AOApplication::get_chat_size(QString p_char)
{
QString f_result = read_char_ini(p_char, "chat_size", "Options");
if (f_result == "")
return -1;
return f_result.toInt();
}
QString AOApplication::get_char_shouts(QString p_char)
{
QString f_result = read_char_ini(p_char, "shouts", "Options");