Added file and path function files + started working on the lobby

This commit is contained in:
David Skoland 2016-12-29 02:48:02 +01:00
parent 78c5e1563d
commit edf37fba49
8 changed files with 91 additions and 3 deletions

View File

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

View File

@ -1,8 +1,22 @@
#include <QDebug>
#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()

View File

@ -2,6 +2,7 @@
#define LOBBY_H
#include <QMainWindow>
#include <QLabel>
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

View File

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

15
path_functions.cpp Normal file
View File

@ -0,0 +1,15 @@
#include <QDir>
#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() + "/";
}

9
path_functions.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef PATH_FUNCTIONS_H
#define PATH_FUNCTIONS_H
#include <QString>
QString get_base_path();
QString get_theme_path();
#endif // PATH_FUNCTIONS_H

29
text_file_functions.cpp Normal file
View File

@ -0,0 +1,29 @@
#include <QTextStream>
#include <QStringList>
#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";
}

9
text_file_functions.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef TEXT_FILE_FUNCTIONS_H
#define TEXT_FILE_FUNCTIONS_H
#include <QString>
#include <QFile>
QString get_user_theme();
#endif // TEXT_FILE_FUNCTIONS_H