diff --git a/src/studio/CMakeLists.txt b/src/studio/CMakeLists.txt index 29ed79f9..0e871afe 100644 --- a/src/studio/CMakeLists.txt +++ b/src/studio/CMakeLists.txt @@ -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) diff --git a/src/studio/lib/CMakeLists.txt b/src/studio/lib/CMakeLists.txt new file mode 100644 index 00000000..03843aad --- /dev/null +++ b/src/studio/lib/CMakeLists.txt @@ -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 +) diff --git a/src/studio/lib/newwizard.cpp b/src/studio/lib/newwizard.cpp new file mode 100644 index 00000000..06db3431 --- /dev/null +++ b/src/studio/lib/newwizard.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#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 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...")); +} + +} +} diff --git a/src/studio/lib/newwizard.hpp b/src/studio/lib/newwizard.hpp new file mode 100644 index 00000000..46ae5b4e --- /dev/null +++ b/src/studio/lib/newwizard.hpp @@ -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 +#include +#include +#include +#include +#include + +namespace nostalgia { +namespace studio { + +class WizardSelect: public QWizardPage { + Q_OBJECT + + private: + QMap> m_options; + QListWidget *m_listWidget = nullptr; + bool m_complete = false; + int m_nextId = -1; + + public: + WizardSelect(); + + void initializePage(); + + void addOption(QString name, std::function 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 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); +}; + +} +} diff --git a/src/studio/mainwindow.cpp b/src/studio/mainwindow.cpp index 6938ba76..71c0feb7 100644 --- a/src/studio/mainwindow.cpp +++ b/src/studio/mainwindow.cpp @@ -10,7 +10,11 @@ #include #include #include +#include +#include +#include #include +#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(); } } diff --git a/src/studio/mainwindow.hpp b/src/studio/mainwindow.hpp index acd13448..d91da39c 100644 --- a/src/studio/mainwindow.hpp +++ b/src/studio/mainwindow.hpp @@ -63,7 +63,7 @@ class MainWindow: public QMainWindow { int writeSettings(QString path); private slots: - void showNewDialog(); + void showNewWizard(); }; }