-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCNewProjectWizard.cpp
More file actions
120 lines (101 loc) · 3.17 KB
/
CNewProjectWizard.cpp
File metadata and controls
120 lines (101 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "CNewProjectWizard.h"
#include "ui_CNewProjectWizard.h"
#include <QDebug>
#include <QFileDialog>
#include <QFileInfo>
#include <QDir>
#include <QDirIterator>
#include <QPropertyAnimation>
#include <CProjectManager.h>
#include <UtilsQt.h>
CNewProjectWizard::CNewProjectWizard(QWidget *parent) :
QWidget(parent),
ui(new Ui::CNewProjectWizard)
{
ui->setupUi(this);
connect(ui->acceptButton, SIGNAL(clicked(bool)), this, SLOT(clickOnValidate()));
connect(ui->pathExplorerButton, SIGNAL(clicked(bool)), this, SLOT(clickOnPathExplorer()));
this->AnimatedOpening();
}
CNewProjectWizard::~CNewProjectWizard()
{
delete ui;
}
void CNewProjectWizard::ClearError()
{
ui->errorLabel->setText("");
}
void CNewProjectWizard::AnimatedOpening()
{
this->setMaximumWidth(0);
this->setVisible(true);
QPropertyAnimation *animation = new QPropertyAnimation(this, "maximumWidth");
animation->setDuration(350);
animation->setStartValue(0);
animation->setEndValue(800);
animation->start();
}
bool CNewProjectWizard::CheckMandatoryFields()
{
QString text = "";
int numberMissingFields = 0;
if(ui->pathLineEdit->text().isEmpty())
{
text += " Le chemin du projet \r\n";
numberMissingFields++;
}
if(ui->projectNameLineEdit->text().isEmpty())
{
text += " Le nom du projet \r\n";
numberMissingFields++;
}
if(numberMissingFields > 0)
{
if(numberMissingFields > 1)
{
text = "Veuillez remplir les champs suivants : \r\n" + text;
}
else
{
text = "Veuillez remplir le champ suivant : \r\n" + text;
}
ui->errorLabel->setText(text);
return false;
}
else
{
return true;
}
}
void CNewProjectWizard::clickOnValidate()
{
// Test mandatory fields
if(!this->CheckMandatoryFields())
{
return;
}
// Create all directories
QDir dir(ui->pathLineEdit->text());
QString projectName = ui->projectNameLineEdit->text();
QString projectPath = ui->pathLineEdit->text() + "/" + projectName;
dir.mkdir(projectName);
dir.cd(projectName);
dir.mkdir("cache");
dir.mkdir("ui");
dir.mkdir("fonts");
QFile::copy(CProjectManager::Instance()->QGetInstallPath() + "/default/default.json", projectPath + "/" + projectName + ".json");
// Copy file from /cache to /cache
CopyFolder(CProjectManager::Instance()->QGetInstallPath() + "/default/cache", projectPath + "/cache/");
CopyFolder(CProjectManager::Instance()->QGetInstallPath() + "/default/ui", projectPath + "/ui/");
CopyFolder(CProjectManager::Instance()->QGetInstallPath() + "/default/fonts", projectPath + "/fonts/");
emit createNewProject(projectPath + "/" + projectName + ".json");
}
void CNewProjectWizard::clickOnPathExplorer()
{
QString dialogPath = ui->pathLineEdit->text() == "" ? QDir::homePath() : ui->pathLineEdit->text();
QString projectPath = QFileDialog::getExistingDirectory(this, "Sélectionner le chemin vers lequel créer le scénario", dialogPath, QFileDialog::ShowDirsOnly);
if (projectPath != "")
{
ui->pathLineEdit->setText(projectPath);
}
}