From 03ebad6bb6c922323b16b3ae6a701ddc34ba538b Mon Sep 17 00:00:00 2001 From: Crystalwarrior Date: Mon, 16 Sep 2019 04:16:59 +0300 Subject: [PATCH] Add expanded style sheet support Allow lobby fonts to happen --- include/aoapplication.h | 3 ++ include/courtroom.h | 6 ++++ include/lobby.h | 4 +++ src/courtroom.cpp | 38 ++++++++++++++++++----- src/lobby.cpp | 62 +++++++++++++++++++++++++++++++++++++ src/text_file_functions.cpp | 39 +++++++++++++++++++++++ 6 files changed, 145 insertions(+), 7 deletions(-) diff --git a/include/aoapplication.h b/include/aoapplication.h index 24dc35c..fcee38f 100644 --- a/include/aoapplication.h +++ b/include/aoapplication.h @@ -252,6 +252,9 @@ public: //Returns a QStringList of all key=value definitions on a given tag. QStringList read_char_ini_tag(QString p_char, QString target_tag); + //Returns the text between target_tag and terminator_tag in p_file + QString get_stylesheet(QString target_tag, QString p_file); + //Returns the side of the p_char character from that characters ini file QString get_char_side(QString p_char); diff --git a/include/courtroom.h b/include/courtroom.h index 7fbde27..9d33a91 100644 --- a/include/courtroom.h +++ b/include/courtroom.h @@ -122,6 +122,12 @@ public: //helper function that calls above function on the relevant widgets void set_fonts(); + //sets dropdown menu stylesheet + void set_dropdown(QWidget *widget, QString target_tag); + + //helper funciton that call above function on the relevant widgets + void set_dropdowns(); + void set_window_title(QString p_title); //reads theme inis and sets size and pos based on the identifier diff --git a/include/lobby.h b/include/lobby.h index 4293ac3..e0cd03d 100644 --- a/include/lobby.h +++ b/include/lobby.h @@ -32,6 +32,10 @@ public: void append_chatmessage(QString f_name, QString f_message); void append_error(QString f_message); void set_player_count(int players_online, int max_players); + void set_stylesheet(QWidget *widget, QString target_tag); + void set_stylesheets(); + void set_fonts(); + void set_font(QWidget *widget, QString p_identifier); void set_loading_text(QString p_text); void show_loading_overlay(){ui_loading_background->show();} void hide_loading_overlay(){ui_loading_background->hide();} diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 433041c..c87da55 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -709,6 +709,8 @@ void Courtroom::set_widgets() ui_char_select_right->set_image("arrow_right.png"); set_size_and_pos(ui_spectator, "spectator"); + + set_dropdowns(); } void Courtroom::set_fonts() @@ -719,7 +721,7 @@ void Courtroom::set_fonts() set_font(ui_ms_chatlog, "ms_chatlog"); set_font(ui_server_chatlog, "server_chatlog"); set_font(ui_music_list, "music_list"); - set_font(ui_area_list, "music_list"); + set_font(ui_area_list, "area_list"); // Set color of labels and checkboxes const QString design_file = "courtroom_fonts.ini"; @@ -739,21 +741,43 @@ void Courtroom::set_font(QWidget *widget, QString p_identifier) int f_weight = ao_app->get_font_size(p_identifier, design_file); QString class_name = widget->metaObject()->className(); - QString fontt = ao_app->get_font_name(p_identifier + "_font", design_file); - widget->setFont(QFont(fontt, f_weight)); + 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? + + QString is_bold = ""; + if(bold == 1) is_bold = "bold"; + QString style_sheet_string = class_name + " { background-color: rgba(0, 0, 0, 0);\n" + - "color: rgba(" + - QString::number(f_color.red()) + ", " + - QString::number(f_color.green()) + ", " + - QString::number(f_color.blue()) + ", 255); }"; + "color: rgba(" + + QString::number(f_color.red()) + ", " + + QString::number(f_color.green()) + ", " + + QString::number(f_color.blue()) + ", 255);\n" + "font: " + is_bold + "; }"; widget->setStyleSheet(style_sheet_string); } +void Courtroom::set_dropdown(QWidget *widget, QString target_tag) +{ + QString f_file = "courtroom_stylesheets.css"; + QString style_sheet_string = ao_app->get_stylesheet(target_tag, f_file); + if (style_sheet_string != "") + widget->setStyleSheet(style_sheet_string); +} + +void Courtroom::set_dropdowns() +{ + set_dropdown(ui_text_color, "[TEXT COLOR]"); + set_dropdown(ui_pos_dropdown, "[POS DROPDOWN]"); + set_dropdown(ui_emote_dropdown, "[EMOTE DROPDOWN]"); + set_dropdown(ui_mute_list, "[MUTE LIST]"); +} + void Courtroom::set_window_title(QString p_title) { this->setWindowTitle(p_title); diff --git a/src/lobby.cpp b/src/lobby.cpp index 6f257ce..7df2cdc 100644 --- a/src/lobby.cpp +++ b/src/lobby.cpp @@ -153,6 +153,8 @@ void Lobby::set_widgets() ui_loading_background->hide(); + set_fonts(); + set_stylesheets(); } void Lobby::set_size_and_pos(QWidget *p_widget, QString p_identifier) @@ -173,6 +175,66 @@ void Lobby::set_size_and_pos(QWidget *p_widget, QString p_identifier) } } +void Lobby::set_fonts() +{ + set_font(ui_player_count, "player_count"); + set_font(ui_description, "description"); + set_font(ui_chatbox, "chatbox"); + set_font(ui_chatname, "chatname"); + set_font(ui_chatmessage, "chatmessage"); + set_font(ui_loading_text, "loading_text"); + set_font(ui_server_list, "server_list"); +} + +void Lobby::set_stylesheet(QWidget *widget, QString target_tag) +{ + QString f_file = "lobby_stylesheets.css"; + QString style_sheet_string = ao_app->get_stylesheet(target_tag, f_file); + if (style_sheet_string != "") + widget->setStyleSheet(style_sheet_string); +} + +void Lobby::set_stylesheets() +{ + set_stylesheet(ui_player_count, "[PLAYER COUNT]"); + set_stylesheet(ui_description, "[DESCRIPTION]"); + set_stylesheet(ui_chatbox, "[CHAT BOX]"); + set_stylesheet(ui_chatname, "[CHAT NAME]"); + set_stylesheet(ui_chatmessage, "[CHAT MESSAGE]"); + set_stylesheet(ui_loading_text, "[LOADING TEXT]"); + set_stylesheet(ui_server_list, "[SERVER LIST]"); +} + +void Lobby::set_font(QWidget *widget, QString p_identifier) +{ + QString design_file = "lobby_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("font_" + p_identifier, design_file); + QFont font(font_name, f_weight); + bool use = static_cast(ao_app->get_font_size("use_custom_fonts", design_file)); + if(use) + { + widget->setFont(font); + QColor f_color = ao_app->get_color(p_identifier + "_color", design_file); + bool bold = static_cast(ao_app->get_font_size(p_identifier + "_bold", design_file)); // is the font bold or not? + bool center = static_cast(ao_app->get_font_size(p_identifier + "_center", design_file)); // should it be centered? + QString is_bold = ""; + if(bold) is_bold = "bold"; + QString is_center = ""; + if(center) is_center = "qproperty-alignment: AlignCenter;"; + QString style_sheet_string = class_name + " { background-color: rgba(0, 0, 0, 0);\n" + + "color: rgba(" + + QString::number(f_color.red()) + ", " + + QString::number(f_color.green()) + ", " + + QString::number(f_color.blue()) + ", 255);\n" + + is_center + "\n" + + "font: " + is_bold + "; }"; + widget->setStyleSheet(style_sheet_string); + } + return; +} + void Lobby::set_loading_text(QString p_text) { ui_loading_text->clear(); diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp index ae17ac5..ad82581 100644 --- a/src/text_file_functions.cpp +++ b/src/text_file_functions.cpp @@ -350,6 +350,45 @@ QColor AOApplication::get_color(QString p_identifier, QString p_file) return return_color; } +QString AOApplication::get_stylesheet(QString target_tag, QString p_file) +{ + QString design_ini_path = get_theme_path(p_file); + + QFile design_ini; + + design_ini.setFileName(design_ini_path); + + if(!design_ini.open(QIODevice::ReadOnly)) + return ""; + + QTextStream in(&design_ini); + + QString f_text; + + bool tag_found = false; + + while(!in.atEnd()) + { + QString line = in.readLine(); + + if (line.startsWith(target_tag, Qt::CaseInsensitive)) + { + tag_found = true; + continue; + } + + if(tag_found) + { + if((line.startsWith("[") && line.endsWith("]"))) + break; + f_text.append(line); + } + } + + design_ini.close(); + return f_text; +} + QColor AOApplication::get_chat_color(QString p_identifier, QString p_chat) { QColor return_color(255, 255, 255);