Add Nostalgia Studio profile option

This commit is contained in:
Gary Talent 2017-04-16 02:56:47 -05:00
parent 60b4a32995
commit b447d4c329
3 changed files with 41 additions and 9 deletions

View File

@ -7,14 +7,33 @@
*/ */
#include <QApplication> #include <QApplication>
#include "studio/mainwindow.hpp" #include <QFile>
#include <QTextStream>
#include <ox/clargs/clargs.hpp>
#include "json/json.hpp"
#include "mainwindow.hpp"
using namespace nostalgia::studio; using namespace nostalgia::studio;
using namespace ox::clargs;
int main(int argc, char **argv) { int main(int argc, char **args) {
QApplication app(argc, argv); ClArgs clargs(argc, (const char**) args);
QString argProfilePath = clargs.getString("profile").c_str();
MainWindow w; NostalgiaStudioProfile config;
// load in config file
QFile file(argProfilePath);
if (file.exists()) {
file.open(QIODevice::ReadOnly);
QTextStream in(&file);
read(in.readAll(), &config);
}
QApplication app(argc, args);
app.setApplicationName(config.app_name);
MainWindow w(config);
w.show(); w.show();
return app.exec(); return app.exec();

View File

@ -8,21 +8,21 @@
#include <QApplication> #include <QApplication>
#include <QDesktopWidget> #include <QDesktopWidget>
#include "studio/mainwindow.hpp" #include "mainwindow.hpp"
namespace nostalgia { namespace nostalgia {
namespace studio { namespace studio {
MainWindow::MainWindow(QWidget *parent) { MainWindow::MainWindow(NostalgiaStudioProfile config, QWidget *parent) {
auto screenSize = QApplication::desktop()->screenGeometry(); auto screenSize = QApplication::desktop()->screenGeometry();
// set window to 70% of screen width, and center it // set window to 70% of screen width, and center NostalgiaStudioProfile
auto sizePct = 0.7; auto sizePct = 0.7;
resize(screenSize.width() * sizePct, screenSize.height() * sizePct); resize(screenSize.width() * sizePct, screenSize.height() * sizePct);
move(-x(), -y()); move(-x(), -y());
move(screenSize.width() * (1 - sizePct) / 2, screenSize.height() * (1 - sizePct) / 2); move(screenSize.width() * (1 - sizePct) / 2, screenSize.height() * (1 - sizePct) / 2);
setWindowTitle("Nostalgia Studio"); setWindowTitle(config.app_name);
} }
MainWindow::~MainWindow() { MainWindow::~MainWindow() {

View File

@ -7,6 +7,7 @@
*/ */
#pragma once #pragma once
#include <ox/std/types.hpp>
#include <QModelIndex> #include <QModelIndex>
#include <QMainWindow> #include <QMainWindow>
#include <QPoint> #include <QPoint>
@ -15,6 +16,18 @@
namespace nostalgia { namespace nostalgia {
namespace studio { namespace studio {
struct NostalgiaStudioProfile {
QString app_name;
};
template<typename T>
int ioOp(T *io, NostalgiaStudioProfile *obj) {
ox::Error err = 0;
err |= io->op("app_name", &obj->app_name);
return err;
}
class MainWindow: public QMainWindow { class MainWindow: public QMainWindow {
Q_OBJECT Q_OBJECT
public: public:
@ -25,7 +38,7 @@ class MainWindow: public QMainWindow {
QString m_projectPath; QString m_projectPath;
public: public:
explicit MainWindow(QWidget *parent = 0); MainWindow(NostalgiaStudioProfile config, QWidget *parent = 0);
virtual ~MainWindow(); virtual ~MainWindow();
void openProject(QString); void openProject(QString);