diff --git a/Attorney_Online_remake.pro b/Attorney_Online_remake.pro index 176ebb5..8f92ab1 100644 --- a/Attorney_Online_remake.pro +++ b/Attorney_Online_remake.pro @@ -15,8 +15,16 @@ TEMPLATE = app SOURCES += main.cpp\ lobby.cpp \ text_file_functions.cpp \ - path_functions.cpp + path_functions.cpp \ + aoimage.cpp \ + file_functions.cpp \ + aobutton.cpp \ + global_variables.cpp HEADERS += lobby.h \ text_file_functions.h \ - path_functions.h + path_functions.h \ + aoimage.h \ + file_functions.h \ + aobutton.h \ + global_variables.h diff --git a/aobutton.cpp b/aobutton.cpp index f2d7012..b96af67 100644 --- a/aobutton.cpp +++ b/aobutton.cpp @@ -1,6 +1,26 @@ +#include "path_functions.h" +#include "file_functions.h" + #include "aobutton.h" -AOButton::AOButton() +AOButton::AOButton(QWidget *parent) : QPushButton(parent) { } + +AOButton::~AOButton() +{ + +} + +void AOButton::set_image(QString p_image) +{ + QString image_path = get_theme_path() + p_image; + QString default_image_path = get_base_path() + "themes/default/"; + + if (file_exists(image_path)) + this->setStyleSheet("border-image:url(\"" + image_path + "\")"); + else + this->setStyleSheet("border-image:url(\"" + default_image_path + "\")"); +} + diff --git a/aobutton.h b/aobutton.h index 72bebf8..f0c5697 100644 --- a/aobutton.h +++ b/aobutton.h @@ -1,11 +1,17 @@ #ifndef AOBUTTON_H #define AOBUTTON_H +#include class AOButton : public QPushButton { + Q_OBJECT + public: - AOButton(); + AOButton(QWidget *parent); + ~AOButton(); + + void set_image(QString p_image); }; -#endif // AOBUTTON_H \ No newline at end of file +#endif // AOBUTTON_H diff --git a/aoimage.cpp b/aoimage.cpp index 507137f..0997e76 100644 --- a/aoimage.cpp +++ b/aoimage.cpp @@ -1,6 +1,27 @@ +#include "file_functions.h" +#include "path_functions.h" +#include "global_variables.h" + #include "aoimage.h" -AOImage::AOImage() +AOImage::AOImage(QWidget *parent, int x_pos, int y_pos, int x_size, int y_size) : QLabel(parent) +{ + this->move(x_pos, y_pos); + this->resize(x_size, y_size); +} + +AOImage::~AOImage() { } + +void AOImage::set_image(QString p_image) +{ + QString theme_image_path = get_theme_path() + p_image; + QString default_image_path = get_base_path() + "themes/default/" + p_image; + + if (file_exists(theme_image_path)) + this->setPixmap(theme_image_path); + else + this->setPixmap(default_image_path); +} diff --git a/aoimage.h b/aoimage.h index d35eca0..631375d 100644 --- a/aoimage.h +++ b/aoimage.h @@ -1,11 +1,17 @@ +//This class represents a static theme-dependent image + #ifndef AOIMAGE_H #define AOIMAGE_H +#include class AOImage : public QLabel { public: - AOImage(); + AOImage(QWidget *parent, int x_pos, int y_pos, int x_size, int y_size); + ~AOImage(); + + void set_image(QString p_image); }; -#endif // AOIMAGE_H \ No newline at end of file +#endif // AOIMAGE_H diff --git a/file_functions.cpp b/file_functions.cpp index e69de29..a191d67 100644 --- a/file_functions.cpp +++ b/file_functions.cpp @@ -0,0 +1,10 @@ +#include + +#include "file_functions.h" + +bool file_exists(QString file_path) +{ + QFileInfo check_file(file_path); + + return check_file.exists() && check_file.isFile(); +} diff --git a/file_functions.h b/file_functions.h index aa3f95e..5ecf14a 100644 --- a/file_functions.h +++ b/file_functions.h @@ -1,4 +1,8 @@ #ifndef FILE_FUNCTIONS_H #define FILE_FUNCTIONS_H +#include + +bool file_exists(QString file_path); + #endif // FILE_FUNCTIONS_H diff --git a/global_variables.cpp b/global_variables.cpp index e69de29..cfef8be 100644 --- a/global_variables.cpp +++ b/global_variables.cpp @@ -0,0 +1,3 @@ +#include "global_variables.h" + +QString g_user_theme = "default"; diff --git a/global_variables.h b/global_variables.h index f66bc3d..7b8a469 100644 --- a/global_variables.h +++ b/global_variables.h @@ -1,4 +1,8 @@ #ifndef GLOBAL_VARIABLES_H #define GLOBAL_VARIABLES_H +#include + +extern QString g_user_theme; + #endif // GLOBAL_VARIABLES_H diff --git a/lobby.cpp b/lobby.cpp index fec063d..5140c07 100644 --- a/lobby.cpp +++ b/lobby.cpp @@ -1,25 +1,31 @@ #include #include "path_functions.h" +#include "text_file_functions.h" +#include "global_variables.h" #include "lobby.h" Lobby::Lobby(QWidget *parent) : QMainWindow(parent) { - this->resize(517, 666); - ui_background = new QLabel(this); + const int lobby_width = 517; + const int lobby_height = 666; + + this->resize(lobby_width, lobby_height); + + ui_background = new AOImage(this, 0, 0, lobby_width, lobby_height); } void Lobby::set_theme_images() { - QString theme_path = get_theme_path(); + g_user_theme = get_user_theme(); - ui_background->move(0, 0); - ui_background->resize(517, 666); - ui_background->setPixmap(theme_path + "lobbybackground.png"); + ui_background->set_image("lobbybackground.png"); + ui_public_servers->set_image("publicservers.png"); + ui_favorites->set_image("favorites.png"); } Lobby::~Lobby() { - + delete ui_background; } diff --git a/lobby.h b/lobby.h index 7a4df7b..ed7ca50 100644 --- a/lobby.h +++ b/lobby.h @@ -2,7 +2,8 @@ #define LOBBY_H #include -#include +#include "aoimage.h" +#include "aobutton.h" class Lobby : public QMainWindow { @@ -16,7 +17,9 @@ public: ~Lobby(); private: - QLabel *ui_background; + AOImage *ui_background; + AOButton *ui_public_servers; + AOButton *ui_favorites; }; #endif // LOBBY_H diff --git a/path_functions.cpp b/path_functions.cpp index 8766656..936060e 100644 --- a/path_functions.cpp +++ b/path_functions.cpp @@ -1,5 +1,6 @@ #include +#include "global_variables.h" #include "text_file_functions.h" #include "path_functions.h" @@ -8,8 +9,9 @@ QString get_base_path(){ return (QDir::currentPath() + "/base/"); } -QString get_theme_path(){ - return get_base_path() + "themes/" + get_user_theme() + "/"; +QString get_theme_path() +{ + return get_base_path() + "themes/" + g_user_theme.toLower() + "/"; }