This commit is contained in:
David Skoland 2017-01-01 16:14:29 +01:00
parent 05a48bd104
commit ca732f27a1
12 changed files with 112 additions and 19 deletions

View File

@ -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

View File

@ -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 + "\")");
}

View File

@ -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

View File

@ -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);
}

View File

@ -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

View File

@ -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();
}

View File

@ -1,4 +1,8 @@
#ifndef FILE_FUNCTIONS_H
#define FILE_FUNCTIONS_H
#include <QString>
bool file_exists(QString file_path);
#endif // FILE_FUNCTIONS_H

View File

@ -0,0 +1,3 @@
#include "global_variables.h"
QString g_user_theme = "default";

View File

@ -1,4 +1,8 @@
#ifndef GLOBAL_VARIABLES_H
#define GLOBAL_VARIABLES_H
#include <QString>
extern QString g_user_theme;
#endif // GLOBAL_VARIABLES_H

View File

@ -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;
}

View File

@ -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

View File

@ -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() + "/";
}