diff --git a/aoapplication.cpp b/aoapplication.cpp index e170c99..12e540c 100644 --- a/aoapplication.cpp +++ b/aoapplication.cpp @@ -86,15 +86,17 @@ void AOApplication::destruct_courtroom() courtroom_constructed = false; } -QString AOApplication::get_version_string(){ +QString AOApplication::get_version_string() +{ return QString::number(RELEASE) + "." + QString::number(MAJOR_VERSION) + "." + QString::number(MINOR_VERSION); } -void AOApplication::set_user_theme(){ - user_theme = read_user_theme(); +void AOApplication::reload_theme() +{ + current_theme = read_theme(); } void AOApplication::set_favorite_list() diff --git a/aoapplication.h b/aoapplication.h index 3d1936c..e124560 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -77,6 +77,8 @@ public: int get_minor_version() {return MINOR_VERSION;} QString get_version_string(); + /////////////////////////////////////////// + void set_favorite_list(); QVector& get_favorite_list() {return favorite_list;} void add_favorite_server(int p_server); @@ -84,8 +86,10 @@ public: void set_server_list(); QVector& get_server_list() {return server_list;} - void set_user_theme(); - QString get_user_theme() {return user_theme;} + //reads the theme from config.ini and sets it accordingly + void reload_theme(); + + //QString get_theme() {return current_theme;} QString get_current_char(); @@ -103,8 +107,10 @@ public: QString get_evidence_path(); //implementation in text_file_functions.cpp + + QString read_file(QString p_path); QString read_config(QString searchline); - QString read_user_theme(); + QString read_theme(); int read_blip_rate(); bool get_blank_blip(); int get_default_music(); @@ -143,7 +149,7 @@ private: const int MAJOR_VERSION = 4; const int MINOR_VERSION = 8; - QString user_theme = "default"; + QString current_theme = "default"; QVector server_list; QVector favorite_list; diff --git a/courtroom.cpp b/courtroom.cpp index 74ee6e9..ca94f43 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1973,7 +1973,7 @@ void Courtroom::on_change_character_clicked() void Courtroom::on_reload_theme_clicked() { - ao_app->set_user_theme(); + ao_app->reload_theme(); //to update status on the background set_background(current_background); diff --git a/lobby.cpp b/lobby.cpp index 1df765f..3a10439 100644 --- a/lobby.cpp +++ b/lobby.cpp @@ -4,6 +4,7 @@ #include "aoapplication.h" #include "networkmanager.h" #include "aosfxplayer.h" +#include "file_functions.h" #include #include @@ -51,14 +52,27 @@ Lobby::Lobby(AOApplication *p_ao_app) : QMainWindow() connect(ui_chatmessage, SIGNAL(returnPressed()), this, SLOT(on_chatfield_return_pressed())); connect(ui_cancel, SIGNAL(clicked()), ao_app, SLOT(loading_cancelled())); - set_widgets(); + //set_widgets(); + set_theme(); +} + +void Lobby::set_theme() +{ + ao_app->reload_theme(); + + //check if our current theme is a valid qss theme + if (!file_exists(ao_app->get_theme_path() + "lobby.qss")) + { + set_widgets(); + return; + } + + this->setStyleSheet(ao_app->read_file(ao_app->get_theme_path() + "lobby.qss")); } //sets images, position and size void Lobby::set_widgets() { - ao_app->set_user_theme(); - QString filename = "lobby_design.ini"; pos_size_type f_lobby = ao_app->get_element_dimensions("lobby", filename); diff --git a/lobby.h b/lobby.h index 2d3aee5..20b3734 100644 --- a/lobby.h +++ b/lobby.h @@ -23,6 +23,7 @@ class Lobby : public QMainWindow public: Lobby(AOApplication *p_ao_app); + void set_theme(); void set_widgets(); void list_servers(); void list_favorites(); diff --git a/path_functions.cpp b/path_functions.cpp index 754ce9e..6e772db 100644 --- a/path_functions.cpp +++ b/path_functions.cpp @@ -53,7 +53,7 @@ QString AOApplication::get_data_path() QString AOApplication::get_theme_path() { - return get_base_path() + "themes/" + user_theme.toLower() + "/"; + return get_base_path() + "themes/" + current_theme.toLower() + "/"; } QString AOApplication::get_default_theme_path() diff --git a/text_file_functions.cpp b/text_file_functions.cpp index 47a9df3..2bc8903 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -8,6 +8,15 @@ #include #include +QString AOApplication::read_file(QString p_path) +{ + QFile file(p_path); + if (!file.open(QFile::ReadOnly)) + return ""; + + return file.readAll(); +} + QString AOApplication::read_config(QString searchline) { QString return_value = ""; @@ -42,7 +51,7 @@ QString AOApplication::read_config(QString searchline) return return_value; } -QString AOApplication::read_user_theme() +QString AOApplication::read_theme() { QString result = read_config("theme");