/* * Copyright 2016 - 2018 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 #include #include #include namespace nostalgia { namespace studio { struct WizardMaker { QString name; std::function()> make; std::function onAccept = [](QWizard*) { return 0; }; }; class WizardSelect: public QWizardPage { Q_OBJECT private: struct WizardFuncs { std::function()> make; std::function onAccept; }; QHash m_options; QListWidget *m_listWidget = nullptr; bool m_complete = false; public: WizardSelect(); void addOption(WizardMaker wm); void initializePage() override; bool isComplete() const override; private slots: void itemSelected(int row); }; class WizardFormPage: public QWizardPage { Q_OBJECT private: struct Field { QString defaultValue = ""; QString value = ""; QWidget *valueControl = nullptr; std::function validator; void setDisplayText(QString text); QString getDisplayText(); }; QLabel *m_errorMsg = nullptr; QGridLayout *m_layout = nullptr; QVector m_subLayout; QMap m_fields; int m_currentLine = 0; int m_validFields = 0; public: WizardFormPage(); ~WizardFormPage(); virtual int accept(); void initializePage() override; bool validatePage() override; void addComboBox(QString displayName, QString fieldName, QVector options); void addLineEdit(QString displayName, QString fieldName, QString defaultVal = "", std::function validator = [](QString) { return 0; }); void addPathBrowse(QString displayName, QString fieldName, QString defaultVal = QDir::homePath(), QFileDialog::FileMode fileMode = QFileDialog::AnyFile, QString fileExtensions = ""); void showValidationError(QString msg); }; class WizardConclusionPage: public QWizardPage { Q_OBJECT private: QString m_baseMsg = ""; QLabel *m_text = nullptr; QVector m_fields; public: WizardConclusionPage(QString msg, QVector field); virtual ~WizardConclusionPage(); void initializePage() override; }; class Wizard: public QWizard { Q_OBJECT private: std::function m_acceptFunc; public: Wizard(QString windowTitle, QWidget *parent = 0); void setAccept(std::function acceptFunc); void accept(); }; } }