2017-04-16 01:00:50 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2016-2017 gtalent2@gmail.com
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QDesktopWidget>
|
2017-04-19 00:41:08 -05:00
|
|
|
#include <QDialog>
|
2017-04-20 01:39:13 -05:00
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
2017-04-19 00:41:08 -05:00
|
|
|
#include <QMenuBar>
|
2017-05-03 23:20:53 -05:00
|
|
|
#include <QVector>
|
2017-04-20 01:39:13 -05:00
|
|
|
#include "lib/newwizard.hpp"
|
2017-04-20 23:15:25 -05:00
|
|
|
#include "lib/project.hpp"
|
2017-04-16 02:56:47 -05:00
|
|
|
#include "mainwindow.hpp"
|
2017-04-16 01:00:50 -05:00
|
|
|
|
|
|
|
namespace nostalgia {
|
|
|
|
namespace studio {
|
|
|
|
|
2017-04-16 02:56:47 -05:00
|
|
|
MainWindow::MainWindow(NostalgiaStudioProfile config, QWidget *parent) {
|
2017-04-16 01:00:50 -05:00
|
|
|
auto screenSize = QApplication::desktop()->screenGeometry();
|
|
|
|
|
2017-04-20 01:39:13 -05:00
|
|
|
// set window to 75% of screen width, and center NostalgiaStudioProfile
|
|
|
|
auto sizePct = 0.75;
|
2017-04-16 01:00:50 -05:00
|
|
|
resize(screenSize.width() * sizePct, screenSize.height() * sizePct);
|
|
|
|
move(-x(), -y());
|
|
|
|
move(screenSize.width() * (1 - sizePct) / 2, screenSize.height() * (1 - sizePct) / 2);
|
|
|
|
|
2017-04-16 02:56:47 -05:00
|
|
|
setWindowTitle(config.app_name);
|
2017-04-19 00:41:08 -05:00
|
|
|
|
|
|
|
setupMenu();
|
2017-04-16 01:00:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow() {
|
2017-04-19 00:41:08 -05:00
|
|
|
for (auto f : m_cleanupTasks) {
|
|
|
|
f();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::setupMenu() {
|
|
|
|
auto menu = menuBar();
|
|
|
|
auto fileMenu = menu->addMenu(tr("&File"));
|
|
|
|
|
|
|
|
// New...
|
|
|
|
addAction(
|
|
|
|
fileMenu,
|
|
|
|
tr("&New..."),
|
|
|
|
tr(""),
|
|
|
|
QKeySequence::New,
|
|
|
|
this,
|
2017-04-20 01:39:13 -05:00
|
|
|
SLOT(showNewWizard())
|
2017-04-19 00:41:08 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
// Exit
|
|
|
|
addAction(
|
|
|
|
fileMenu,
|
|
|
|
tr("E&xit"),
|
|
|
|
tr("Exit the application"),
|
|
|
|
QKeySequence::Quit,
|
|
|
|
QApplication::quit
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::addAction(QMenu *menu, QString text, QString toolTip,
|
|
|
|
QKeySequence::StandardKey key, const QObject *tgt, const char *cb) {
|
|
|
|
auto action = menu->addAction(text);
|
|
|
|
action->setShortcuts(key);
|
|
|
|
action->setStatusTip(toolTip);
|
|
|
|
auto conn = connect(action, SIGNAL(triggered()), tgt, cb);
|
|
|
|
m_cleanupTasks.push_back([this, conn]() {
|
|
|
|
QObject::disconnect(conn);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::addAction(QMenu *menu, QString text, QString toolTip,
|
|
|
|
QKeySequence::StandardKey key, void (*cb)()) {
|
|
|
|
auto action = menu->addAction(text);
|
|
|
|
action->setShortcuts(key);
|
|
|
|
action->setStatusTip(toolTip);
|
|
|
|
auto conn = connect(action, &QAction::triggered, cb);
|
|
|
|
m_cleanupTasks.push_back([this, conn]() {
|
|
|
|
QObject::disconnect(conn);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-04-20 01:39:13 -05:00
|
|
|
void MainWindow::showNewWizard() {
|
2017-04-20 23:15:25 -05:00
|
|
|
const QString PROJECT_NAME = "projectName";
|
|
|
|
const QString PROJECT_PATH = "projectPath";
|
2017-04-20 01:39:13 -05:00
|
|
|
Wizard wizard;
|
|
|
|
auto ws = new WizardSelect();
|
|
|
|
wizard.addPage(ws);
|
2017-05-03 23:20:53 -05:00
|
|
|
ws->addOption(tr("Project"),
|
|
|
|
[&wizard, PROJECT_NAME, PROJECT_PATH]() {
|
|
|
|
QVector<QWizardPage*> pgs;
|
2017-04-20 18:35:14 -05:00
|
|
|
auto pg = new WizardFormPage();
|
2017-05-03 23:20:53 -05:00
|
|
|
pg->addLineEdit(tr("Project &Name:"), PROJECT_NAME + "*", "", [PROJECT_PATH, pg, &wizard](QString projectName) {
|
|
|
|
auto projectPath = wizard.field(PROJECT_PATH).toString();
|
|
|
|
auto path = projectPath + "/" + projectName;
|
|
|
|
if (!QDir(path).exists()) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
pg->showValidationError(tr("This project directory already exists."));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2017-04-20 23:15:25 -05:00
|
|
|
pg->addDirBrowse(tr("Project &Path:"), PROJECT_PATH + "*");
|
2017-05-03 23:20:53 -05:00
|
|
|
pgs.push_back(pg);
|
2017-05-04 01:35:37 -05:00
|
|
|
pgs.push_back(new WizardConclusionPage(tr("Creating project: ") + "%1/%2", {PROJECT_PATH, PROJECT_NAME}));
|
2017-05-03 23:20:53 -05:00
|
|
|
|
|
|
|
return pgs;
|
2017-04-20 01:39:13 -05:00
|
|
|
}
|
|
|
|
);
|
2017-05-03 23:20:53 -05:00
|
|
|
wizard.setAccept([&wizard, ws, PROJECT_NAME, PROJECT_PATH]() {
|
2017-04-20 23:15:25 -05:00
|
|
|
auto projectName = wizard.field(PROJECT_NAME).toString();
|
|
|
|
auto projectPath = wizard.field(PROJECT_PATH).toString();
|
2017-04-21 06:04:42 -05:00
|
|
|
if (QDir(projectPath).exists()) {
|
|
|
|
auto path = projectPath + "/" + projectName;
|
2017-04-28 13:02:18 -05:00
|
|
|
if (!QDir(path).exists()) {
|
|
|
|
Project(path).create();
|
|
|
|
}
|
2017-04-21 06:04:42 -05:00
|
|
|
}
|
2017-04-20 23:15:25 -05:00
|
|
|
}
|
|
|
|
);
|
2017-04-20 01:39:13 -05:00
|
|
|
wizard.show();
|
|
|
|
wizard.exec();
|
2017-04-16 01:00:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|