You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
5.2 KiB

9 years ago
////////////////////////////////////////////////////////////////////////////////
/**
* \file projectwizard.cpp
* \version v1.0
* \author Ing. Dominik Malcik
*/
////////////////////////////////////////////////////////////////////////////////
#include <QtGui>
#include <QVBoxLayout>
#include <QLineEdit>
#include <QPushButton>
#include "projectwizard.h"
#include "xmlparser.h"
#include "mainwindow.h"
ProjectWizard::ProjectWizard(QWidget *parent) : QWizard(parent) {
addPage(new WelcomePage);
addPage(new ProjectInfoPage);
setWindowTitle(tr("New Project Wizard"));
}
void ProjectWizard::accept() {
QString projectName = field("projectName").toString();
QString projectDir = field("projectDir").toString();
bool checkBox = field("importFileCheck").toBool();
QString imageFileName = field("imageFile").toString();
std::vector<QString> imagesVect;
std::vector<QString> layersVect;
// import of a file
if (checkBox) {
imagesVect.push_back(imageFileName);
}
QString projectFileName = projectName + Project::PROJ_FILE_EXT;
// make the new project file in the project root
cProject::Instance()->prepareProject(projectDir, projectName, projectFileName, checkBox, imagesVect, layersVect);
bool removeSubDirs = true;
cProject::Instance()->saveToFile(removeSubDirs);
QDialog::accept();
QMessageBox::information(this, tr("microAnalyzer :: PROJECT CREATED"), tr("The project \"%1\" was successfully created.").arg(projectName));
}
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
WelcomePage::WelcomePage(QWidget *parent): QWizardPage(parent) {
setTitle(tr("Welcome to New Project Wizard!"));
label = new QLabel(tr("<p>This wizard will create a New Project directory "
"with basic configuration. It is needed to fill only few information.</p>"
"<p>Click <strong>next</strong> to continue, please.</p>"));
label->setWordWrap(true);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(label);
setLayout(layout);
}
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
ProjectInfoPage::ProjectInfoPage(QWidget *parent): QWizardPage(parent) {
setTitle(tr("Project details<br />"));
// name of the project
projectNameLabel = new QLabel(tr("Project name:"));
projectNameLineEdit = new QLineEdit;
projectNameLabel->setBuddy(projectNameLineEdit);
// root dir of the project
projectDirLabel = new QLabel(tr("Choose &project root directory:"));
projectDirLineEdit = new QLineEdit;
projectDirLabel->setBuddy(projectDirLineEdit);
chooseDirBtn = new QPushButton("Choose dir");
connect(chooseDirBtn, SIGNAL(clicked()), this, SLOT(browseDirs()));
// image import
imageImportLabel = new QLabel(tr("Choose &image file to import:"));
imageImportLineEdit = new QLineEdit;
imageImportLineEdit->setEnabled(false);
imageImportLabel->setBuddy(imageImportLineEdit);
importFileCheckBox = new QCheckBox(tr("Import image file now."));
importImageBtn = new QPushButton("Import image");
importImageBtn->setEnabled(false);
connect(importImageBtn, SIGNAL(clicked()), this, SLOT(openImageFile()));
connect(importFileCheckBox, SIGNAL(toggled(bool)), importImageBtn, SLOT(setEnabled(bool)));
connect(importFileCheckBox, SIGNAL(toggled(bool)), imageImportLineEdit, SLOT(setEnabled(bool)));
registerField("projectName*", projectNameLineEdit);
registerField("projectDir*", projectDirLineEdit);
registerField("importFileCheck", importFileCheckBox);
registerField("imageFile", imageImportLineEdit);
// UI wizard
QGridLayout *layout = new QGridLayout;
layout->addWidget(projectNameLabel, 0, 0);
layout->addWidget(projectNameLineEdit, 0, 1, 1, 3);
QLabel *separatorLabel1 = new QLabel(tr(" "));
layout->addWidget(separatorLabel1, 1, 0);
layout->addWidget(projectDirLabel, 2, 0);
layout->addWidget(projectDirLineEdit, 3, 0, 1, 3);
layout->addWidget(chooseDirBtn, 3, 3);
QLabel *separatorLabel = new QLabel(tr(" "));
layout->addWidget(separatorLabel, 4, 0);
layout->addWidget(importFileCheckBox, 5, 0);
layout->addWidget(imageImportLabel, 6, 0);
layout->addWidget(imageImportLineEdit, 7, 0, 1, 3);
layout->addWidget(importImageBtn, 7, 3);
setLayout(layout);
}
void ProjectInfoPage::browseDirs() {
QString directory = QFileDialog::getExistingDirectory(0 , "Choose project root directory", QDir::currentPath());
if (!directory.isEmpty()) {
projectDirLineEdit->setText(directory);
}
}
/*
* Load image
*/
void ProjectInfoPage::openImageFile() {
QString imageFileName = QFileDialog::getOpenFileName(this, tr("Open Image"), QDir::currentPath(), "*.bmp *.png *.tif *.jpg *.jpeg");
if (!imageFileName.isEmpty()) {
imageImportLineEdit->setText(imageFileName);
}
}
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------