From edf37fba4949ec902644c5e5937fa62e66c323c9 Mon Sep 17 00:00:00 2001 From: David Skoland Date: Thu, 29 Dec 2016 02:48:02 +0100 Subject: [PATCH] Added file and path function files + started working on the lobby --- Attorney_Online_remake.pro | 8 ++++++-- lobby.cpp | 16 +++++++++++++++- lobby.h | 7 +++++++ main.cpp | 1 + path_functions.cpp | 15 +++++++++++++++ path_functions.h | 9 +++++++++ text_file_functions.cpp | 29 +++++++++++++++++++++++++++++ text_file_functions.h | 9 +++++++++ 8 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 path_functions.cpp create mode 100644 path_functions.h create mode 100644 text_file_functions.cpp create mode 100644 text_file_functions.h diff --git a/Attorney_Online_remake.pro b/Attorney_Online_remake.pro index a88a051..176ebb5 100644 --- a/Attorney_Online_remake.pro +++ b/Attorney_Online_remake.pro @@ -13,6 +13,10 @@ TEMPLATE = app SOURCES += main.cpp\ - lobby.cpp + lobby.cpp \ + text_file_functions.cpp \ + path_functions.cpp -HEADERS += lobby.h +HEADERS += lobby.h \ + text_file_functions.h \ + path_functions.h diff --git a/lobby.cpp b/lobby.cpp index 8fa6501..fec063d 100644 --- a/lobby.cpp +++ b/lobby.cpp @@ -1,8 +1,22 @@ +#include + +#include "path_functions.h" + #include "lobby.h" Lobby::Lobby(QWidget *parent) : QMainWindow(parent) { - //this->resize(); + this->resize(517, 666); + ui_background = new QLabel(this); +} + +void Lobby::set_theme_images() +{ + QString theme_path = get_theme_path(); + + ui_background->move(0, 0); + ui_background->resize(517, 666); + ui_background->setPixmap(theme_path + "lobbybackground.png"); } Lobby::~Lobby() diff --git a/lobby.h b/lobby.h index 310ac9c..7a4df7b 100644 --- a/lobby.h +++ b/lobby.h @@ -2,6 +2,7 @@ #define LOBBY_H #include +#include class Lobby : public QMainWindow { @@ -9,7 +10,13 @@ class Lobby : public QMainWindow public: Lobby(QWidget *parent = nullptr); + + void set_theme_images(); + ~Lobby(); + +private: + QLabel *ui_background; }; #endif // LOBBY_H diff --git a/main.cpp b/main.cpp index 9a058dc..bbb10bb 100644 --- a/main.cpp +++ b/main.cpp @@ -6,6 +6,7 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); Lobby w; + w.set_theme_images(); w.show(); return a.exec(); diff --git a/path_functions.cpp b/path_functions.cpp new file mode 100644 index 0000000..8766656 --- /dev/null +++ b/path_functions.cpp @@ -0,0 +1,15 @@ +#include + +#include "text_file_functions.h" + +#include "path_functions.h" + +QString get_base_path(){ + return (QDir::currentPath() + "/base/"); +} + +QString get_theme_path(){ + return get_base_path() + "themes/" + get_user_theme() + "/"; +} + + diff --git a/path_functions.h b/path_functions.h new file mode 100644 index 0000000..3912c17 --- /dev/null +++ b/path_functions.h @@ -0,0 +1,9 @@ +#ifndef PATH_FUNCTIONS_H +#define PATH_FUNCTIONS_H + +#include + +QString get_base_path(); +QString get_theme_path(); + +#endif // PATH_FUNCTIONS_H diff --git a/text_file_functions.cpp b/text_file_functions.cpp new file mode 100644 index 0000000..336b76c --- /dev/null +++ b/text_file_functions.cpp @@ -0,0 +1,29 @@ +#include +#include + +#include "path_functions.h" + +#include "text_file_functions.h" + +QString get_user_theme(){ + QFile config_file(get_base_path() + "config.ini"); + if (!config_file.open(QIODevice::ReadOnly)) + return "default"; + + QTextStream in(&config_file); + + while(!in.atEnd()) + { + QString line = in.readLine(); + + if (line.startsWith("theme")) + { + QStringList line_elements = line.split("="); + + if (line_elements.size() > 1) + return line_elements.at(1).trimmed(); + } + } + + return "default"; +} diff --git a/text_file_functions.h b/text_file_functions.h new file mode 100644 index 0000000..99abe08 --- /dev/null +++ b/text_file_functions.h @@ -0,0 +1,9 @@ +#ifndef TEXT_FILE_FUNCTIONS_H +#define TEXT_FILE_FUNCTIONS_H + +#include +#include + +QString get_user_theme(); + +#endif // TEXT_FILE_FUNCTIONS_H