Add UI for New Project wizard

This commit is contained in:
Gary Talent 2017-04-20 01:39:13 -05:00
parent 5644250e94
commit 681eb55db3
6 changed files with 245 additions and 8 deletions

View File

@ -20,6 +20,7 @@ target_link_libraries(
${OxStd_LIBRARY}
NostalgiaCommon
NostalgiaCore
NostalgiaStudio
NostalgiaStudioJson
)
@ -30,4 +31,5 @@ install(
bin
)
add_subdirectory(lib)
add_subdirectory(json)

View File

@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 2.8.11)
project(NostalgiaStudio)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
add_library(
NostalgiaStudio
SHARED
newwizard.cpp
)
target_link_libraries(
NostalgiaStudio
Qt5::Core
Qt5::Widgets
)
install(
FILES
newwizard.hpp
DESTINATION
include/nostalgia/studio/lib
)

View File

@ -0,0 +1,124 @@
/*
* 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 <iostream>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QListWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include "newwizard.hpp"
namespace nostalgia {
namespace studio {
using namespace std;
WizardSelect::WizardSelect() {
m_listWidget = new QListWidget(this);
auto layout = new QVBoxLayout(this);
layout->addWidget(m_listWidget);
setLayout(layout);
connect(m_listWidget, &QListWidget::activated, this, &WizardSelect::itemSelected);
connect(m_listWidget, &QListWidget::clicked, this, &WizardSelect::itemSelected);
}
void WizardSelect::initializePage() {
m_nextId = -1;
emit completeChanged();
}
void WizardSelect::addOption(QString name, std::function<QWizardPage*()> makePage) {
m_options[name] = makePage;
m_listWidget->addItem(name);
}
bool WizardSelect::isComplete() const {
return m_complete;
}
bool WizardSelect::isFinalPage() const {
return false;
}
int WizardSelect::nextId() const {
return m_nextId;
}
void WizardSelect::itemSelected(const QModelIndex &idx) {
m_complete = true;
auto w = wizard();
if (nextId() > -1) {
w->removePage(nextId());
m_nextId = -1;
}
auto selected = m_listWidget->currentItem()->text();
if (m_options.contains(selected)) {
m_nextId = w->addPage(m_options[selected]());
// for some reason the continue button only appears correctly after remove runs
w->removePage(nextId());
m_nextId = w->addPage(m_options[selected]());
}
}
Wizard::FormPage::FormPage() {
m_layout = new QGridLayout(this);
m_layout->setColumnMinimumWidth(0, 20);
this->setLayout(m_layout);
}
Wizard::FormPage::~FormPage() {
for (auto l : m_subLayout) {
delete l;
}
}
void Wizard::FormPage::addLineEdit(QString displayName, QString fieldName) {
auto lbl = new QLabel(displayName, this);
auto le = new QLineEdit(this);
lbl->setBuddy(le);
m_layout->addWidget(lbl, currentLine, 0);
m_layout->addWidget(le, currentLine, 1);
registerField(fieldName, le);
currentLine++;
}
void Wizard::FormPage::addFileBrowse(QString displayName, QString fieldName, QString defaultVal) {
auto layout = new QHBoxLayout();
auto lbl = new QLabel(displayName, this);
auto le = new QLineEdit(this);
auto btn = new QPushButton("Browse...", this);
lbl->setBuddy(le);
layout->addWidget(le);
layout->addWidget(btn);
m_layout->addWidget(lbl, currentLine, 0);
m_layout->addLayout(layout, currentLine, 1);
m_subLayout.push_back(layout);
registerField(fieldName, le);
currentLine++;
}
Wizard::Wizard(QWidget *parent): QWizard(parent) {
setWindowTitle(tr("New..."));
}
}
}

View File

@ -0,0 +1,73 @@
/*
* 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/.
*/
#pragma once
#include <functional>
#include <QGridLayout>
#include <QListWidget>
#include <QMap>
#include <QVector>
#include <QWizard>
namespace nostalgia {
namespace studio {
class WizardSelect: public QWizardPage {
Q_OBJECT
private:
QMap<QString, std::function<QWizardPage*()>> m_options;
QListWidget *m_listWidget = nullptr;
bool m_complete = false;
int m_nextId = -1;
public:
WizardSelect();
void initializePage();
void addOption(QString name, std::function<QWizardPage*()> makePage);
bool isComplete() const;
bool isFinalPage() const;
int nextId() const;
private slots:
void itemSelected(const QModelIndex &idx);
};
class Wizard: public QWizard {
Q_OBJECT
public:
class FormPage: public QWizardPage {
private:
QGridLayout *m_layout = nullptr;
QVector<QLayout*> m_subLayout;
int currentLine = 0;
public:
FormPage();
~FormPage();
void addLineEdit(QString displayName, QString fieldName);
void addFileBrowse(QString displayName, QString fieldName, QString defaultVal = "");
};
public:
Wizard(QWidget *parent = 0);
};
}
}

View File

@ -10,7 +10,11 @@
#include <QApplication>
#include <QDesktopWidget>
#include <QDialog>
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QMenuBar>
#include "lib/newwizard.hpp"
#include "mainwindow.hpp"
namespace nostalgia {
@ -21,8 +25,8 @@ using namespace std;
MainWindow::MainWindow(NostalgiaStudioProfile config, QWidget *parent) {
auto screenSize = QApplication::desktop()->screenGeometry();
// set window to 70% of screen width, and center NostalgiaStudioProfile
auto sizePct = 0.7;
// set window to 75% of screen width, and center NostalgiaStudioProfile
auto sizePct = 0.75;
resize(screenSize.width() * sizePct, screenSize.height() * sizePct);
move(-x(), -y());
move(screenSize.width() * (1 - sizePct) / 2, screenSize.height() * (1 - sizePct) / 2);
@ -49,7 +53,7 @@ void MainWindow::setupMenu() {
tr(""),
QKeySequence::New,
this,
SLOT(showNewDialog())
SLOT(showNewWizard())
);
// Exit
@ -84,10 +88,19 @@ void MainWindow::addAction(QMenu *menu, QString text, QString toolTip,
});
}
void MainWindow::showNewDialog() {
QDialog dialog;
dialog.show();
dialog.exec();
void MainWindow::showNewWizard() {
Wizard wizard;
auto ws = new WizardSelect();
wizard.addPage(ws);
ws->addOption(tr("Project"), []() {
auto pg = new Wizard::FormPage();
pg->addLineEdit(tr("Project &Name"), "projectName");
pg->addFileBrowse(tr("Project &Path"), "projectPath");
return pg;
}
);
wizard.show();
wizard.exec();
}
}

View File

@ -63,7 +63,7 @@ class MainWindow: public QMainWindow {
int writeSettings(QString path);
private slots:
void showNewDialog();
void showNewWizard();
};
}