diff options
| author | David Skoland <davidskoland@gmail.com> | 2017-01-01 16:14:29 +0100 |
|---|---|---|
| committer | David Skoland <davidskoland@gmail.com> | 2017-01-01 16:14:29 +0100 |
| commit | ca732f27a1352ec656b2b7680c6ee2b61762c38d (patch) | |
| tree | aea88eb3f60d69c3dcca8c8bfd9729ee820bc0b5 | |
| parent | 05a48bd104dc3e1b88bf4aba8477f02274757d69 (diff) | |
-
| -rw-r--r-- | Attorney_Online_remake.pro | 12 | ||||
| -rw-r--r-- | aobutton.cpp | 22 | ||||
| -rw-r--r-- | aobutton.h | 10 | ||||
| -rw-r--r-- | aoimage.cpp | 23 | ||||
| -rw-r--r-- | aoimage.h | 10 | ||||
| -rw-r--r-- | file_functions.cpp | 10 | ||||
| -rw-r--r-- | file_functions.h | 4 | ||||
| -rw-r--r-- | global_variables.cpp | 3 | ||||
| -rw-r--r-- | global_variables.h | 4 | ||||
| -rw-r--r-- | lobby.cpp | 20 | ||||
| -rw-r--r-- | lobby.h | 7 | ||||
| -rw-r--r-- | path_functions.cpp | 6 |
12 files changed, 112 insertions, 19 deletions
diff --git a/Attorney_Online_remake.pro b/Attorney_Online_remake.pro index 176ebb57..8f92ab1a 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 f2d7012a..b96af678 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 + "\")"); +} + @@ -1,11 +1,17 @@ #ifndef AOBUTTON_H #define AOBUTTON_H +#include <QPushButton> 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 507137f6..0997e767 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); } @@ -1,11 +1,17 @@ +//This class represents a static theme-dependent image + #ifndef AOIMAGE_H #define AOIMAGE_H +#include <QLabel> 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 e69de29b..a191d67f 100644 --- a/file_functions.cpp +++ b/file_functions.cpp @@ -0,0 +1,10 @@ +#include <QFileInfo> + +#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 aa3f95eb..5ecf14ac 100644 --- a/file_functions.h +++ b/file_functions.h @@ -1,4 +1,8 @@ #ifndef FILE_FUNCTIONS_H #define FILE_FUNCTIONS_H +#include <QString> + +bool file_exists(QString file_path); + #endif // FILE_FUNCTIONS_H diff --git a/global_variables.cpp b/global_variables.cpp index e69de29b..cfef8bec 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 f66bc3d6..7b8a469b 100644 --- a/global_variables.h +++ b/global_variables.h @@ -1,4 +1,8 @@ #ifndef GLOBAL_VARIABLES_H #define GLOBAL_VARIABLES_H +#include <QString> + +extern QString g_user_theme; + #endif // GLOBAL_VARIABLES_H @@ -1,25 +1,31 @@ #include <QDebug> #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; } @@ -2,7 +2,8 @@ #define LOBBY_H #include <QMainWindow> -#include <QLabel> +#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 8766656b..936060e1 100644 --- a/path_functions.cpp +++ b/path_functions.cpp @@ -1,5 +1,6 @@ #include <QDir> +#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() + "/"; } |
