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