| 1 | #include "abstractwizard.h" | 
 
 
 
 
 | 2 |  | 
 
 
 
 
 | 3 | AbstractWizard::AbstractWizard(const QString &appDir, const QString &workspaceWizardLocation, QSettings *vagoSettings, const bool hasRestartButton) | 
 
 
 
 
 | 4 | { | 
 
 
 
 
 | 5 | this->appDir = appDir; | 
 
 
 
 
 | 6 | this->workspaceWizardLocation=workspaceWizardLocation; | 
 
 
 
 
 | 7 | this->vagoSettings=vagoSettings; | 
 
 
 
 
 | 8 | this->hasRestartButton = hasRestartButton; | 
 
 
 
 
 | 9 | this->myWizard.setWindowFlags(Qt::Window); // add minimize button in QWizard | 
 
 
 
 
 | 10 | } | 
 
 
 
 
 | 11 |  | 
 
 
 
 
 | 12 | void AbstractWizard::showWizard(const QString &windowsTitle, const QString &windowsIcon){ | 
 
 
 
 
 | 13 | // Connect finished signal to our function | 
 
 
 
 
 | 14 | QObject::connect(&myWizard, SIGNAL(finished(int)), this, SLOT(wizardFinished(int))); | 
 
 
 
 
 | 15 |  | 
 
 
 
 
 | 16 | // If it has a restart button setup it | 
 
 
 
 
 | 17 | if(this->hasRestartButton){ | 
 
 
 
 
 | 18 | QPushButton *restartButton = new QPushButton("Restart"); | 
 
 
 
 
 | 19 | this->myWizard.setButton(QWizard::CustomButton1,restartButton); | 
 
 
 
 
 | 20 | this->myWizard.setOption(QWizard::HaveCustomButton1, true); | 
 
 
 
 
 | 21 |  | 
 
 
 
 
 | 22 | connect(&this->myWizard, SIGNAL(currentIdChanged(int)), this, SLOT(pageChanged(int))); | 
 
 
 
 
 | 23 | connect(restartButton, SIGNAL(clicked(bool)), this, SLOT(restartWizard())); | 
 
 
 
 
 | 24 | } | 
 
 
 
 
 | 25 |  | 
 
 
 
 
 | 26 | myWizard.setWindowIcon(QIcon(windowsIcon)); | 
 
 
 
 
 | 27 | myWizard.setWindowTitle(windowsTitle); | 
 
 
 
 
 | 28 |  | 
 
 
 
 
 | 29 | //Center and resize QWizard (http://www.thedazzlersinc.com/source/2012/06/04/qt-center-window-in-screen/) | 
 
 
 
 
 | 30 | #ifdef Q_OS_WIN | 
 
 
 
 
 | 31 | myWizard.resize(640,480); | 
 
 
 
 
 | 32 | #else | 
 
 
 
 
 | 33 | myWizard.resize(800,600); // Mac OS pcs should be able to render this resolution without any problem. It's also better | 
 
 
 
 
 | 34 | // because the components on mac use more space | 
 
 
 
 
 | 35 | #endif | 
 
 
 
 
 | 36 | QRect position = myWizard.frameGeometry(); | 
 
 
 
 
 | 37 | position.moveCenter(QDesktopWidget().availableGeometry().center()); | 
 
 
 
 
 | 38 | myWizard.move(position.topLeft()); | 
 
 
 
 
 | 39 | // | 
 
 
 
 
 | 40 |  | 
 
 
 
 
 | 41 | // Show non modal window | 
 
 
 
 
 | 42 | myWizard.show(); | 
 
 
 
 
 | 43 | } | 
 
 
 
 
 | 44 |  | 
 
 
 
 
 | 45 | QWizardPage* AbstractWizard::createIntroPage(const QString &text) { | 
 
 
 
 
 | 46 | QWizardPage *page = new QWizardPage; | 
 
 
 
 
 | 47 | page->setTitle("Introduction"); | 
 
 
 
 
 | 48 |  | 
 
 
 
 
 | 49 | QLabel *label = new QLabel(text); | 
 
 
 
 
 | 50 | label->setWordWrap(true); | 
 
 
 
 
 | 51 |  | 
 
 
 
 
 | 52 | QVBoxLayout *layout = new QVBoxLayout; | 
 
 
 
 
 | 53 | layout->addWidget(label); | 
 
 
 
 
 | 54 | page->setLayout(layout); | 
 
 
 
 
 | 55 |  | 
 
 
 
 
 | 56 | return page; | 
 
 
 
 
 | 57 | } | 
 
 
 
 
 | 58 |  | 
 
 
 
 
 | 59 | void AbstractWizard::wizardFinished(int resultStatus){ | 
 
 
 
 
 | 60 | beforeClose(static_cast<QDialog::DialogCode>(resultStatus)); | 
 
 
 
 
 | 61 |  | 
 
 
 
 
 | 62 | // delete itself | 
 
 
 
 
 | 63 | delete this; | 
 
 
 
 
 | 64 | } | 
 
 
 
 
 | 65 |  | 
 
 
 
 
 | 66 | void AbstractWizard::restartWizard(){ | 
 
 
 
 
 | 67 | this->myWizard.restart(); | 
 
 
 
 
 | 68 | } | 
 
 
 
 
 | 69 |  | 
 
 
 
 
 | 70 | void AbstractWizard::pageChanged(int pageId){ | 
 
 
 
 
 | 71 | // Last page? | 
 
 
 
 
 | 72 | if(pageId==this->myWizard.pageIds().size()-1){ | 
 
 
 
 
 | 73 | this->myWizard.setOption(QWizard::HaveCustomButton1, true); // set visible | 
 
 
 
 
 | 74 | this->myWizard.button(QWizard::BackButton)->setEnabled(false); // disable back button, use restart if needed | 
 
 
 
 
 | 75 | return; | 
 
 
 
 
 | 76 | } | 
 
 
 
 
 | 77 | this->myWizard.setOption(QWizard::HaveCustomButton1, false); // set invisible | 
 
 
 
 
 | 78 | this->myWizard.button(QWizard::BackButton)->setEnabled(true); // set enable back button | 
 
 
 
 
 | 79 | } |