194 lines
3.9 KiB
C++
194 lines
3.9 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
#include "path.h"
|
|
|
|
#include <QFileDialog>
|
|
#include <QMessageBox>
|
|
|
|
|
|
#include <QFile>
|
|
#include <QJsonDocument>
|
|
#include <QJsonObject>
|
|
#include <QJsonArray>
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete ui;
|
|
delete currentPath;
|
|
|
|
for(Path* p : path) {
|
|
delete p;
|
|
}
|
|
}
|
|
|
|
void MainWindow::updatePathView()
|
|
{
|
|
|
|
}
|
|
|
|
void MainWindow::updateStepView(size_t num)
|
|
{
|
|
|
|
}
|
|
|
|
void MainWindow::onTextChanged()
|
|
{
|
|
textChanged = true;
|
|
}
|
|
|
|
void MainWindow::loadPath()
|
|
{
|
|
QString fileName = QFileDialog::getOpenFileName(this, "Open the file");
|
|
if(fileName.isEmpty()) return;
|
|
QFile file(fileName);
|
|
if(!file.open(QIODevice::ReadOnly | QFile::Text)) {
|
|
QMessageBox::warning(this, "Warning", "Fichier non valide" + file.errorString());
|
|
return;
|
|
}
|
|
|
|
file.close();
|
|
Path* p = new Path(&file);
|
|
currentPath = p;
|
|
path.append(p);
|
|
|
|
ui->titleEdit->setText(p->getName());
|
|
ui->locEdit->setText(p->getCity());
|
|
ui->diffSpin->setValue(p->getDifficulty());
|
|
ui->lengthSpin->setValue(p->getLength());
|
|
ui->durationSpin->setValue(p->getDuration());
|
|
ui->imagePath->setText(p->getImage());
|
|
ui->depSpin->setValue(p->getDepartement());
|
|
|
|
loadImage(p->getImage());
|
|
}
|
|
|
|
void MainWindow::addNewPath()
|
|
{
|
|
|
|
}
|
|
|
|
void MainWindow::addNewStep()
|
|
{
|
|
|
|
}
|
|
|
|
void MainWindow::exportHTMLMap()
|
|
{
|
|
|
|
}
|
|
|
|
void MainWindow::loadImage(QString fileName) {
|
|
|
|
QString ext[] = {"png", "jpeg", "jpg"};
|
|
|
|
QFile file(fileName);
|
|
if (!file.open(QIODevice::ReadOnly | QFile::Text)) {
|
|
QMessageBox::warning(this, "Warning", "Cannot open file: " +
|
|
file.errorString());
|
|
return;
|
|
}
|
|
QString text = file.fileName();
|
|
|
|
bool acceptedExt = false;
|
|
for(QString e : ext) {
|
|
if(text.endsWith(e)) acceptedExt = true;
|
|
}
|
|
|
|
if(!acceptedExt) {
|
|
QMessageBox::warning(this, "Warning", "Format de fichier incorrect");
|
|
return;
|
|
}
|
|
|
|
|
|
ui->imagePath->setText(text);
|
|
|
|
|
|
QPixmap px(fileName);
|
|
|
|
ui->imageLbl->setPixmap(px);
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
void MainWindow::on_pushButton_clicked()
|
|
{
|
|
QString fileName = QFileDialog::getOpenFileName(this, "Open the file");
|
|
if (fileName.isEmpty()) return;
|
|
this->loadImage(fileName);
|
|
}
|
|
|
|
|
|
void MainWindow::on_actionOpen_triggered()
|
|
{
|
|
this->loadPath();
|
|
}
|
|
|
|
void MainWindow::on_toolButton_clicked()
|
|
{
|
|
QString fileName = ui->imagePath->text();
|
|
if(fileName.isEmpty()) return;
|
|
loadImage(fileName);
|
|
}
|
|
|
|
void MainWindow::saveFile(){
|
|
QString fileName;
|
|
if (currentFile.isEmpty()) {
|
|
fileName = QFileDialog::getSaveFileName(this, "Save");
|
|
currentFile = fileName;
|
|
} else {
|
|
fileName = currentFile;
|
|
}
|
|
QFile file(fileName);
|
|
if (!file.open(QIODevice::WriteOnly | QFile::Text)) {
|
|
QMessageBox::warning(this, "Warning", "Cannot save file: " + file.errorString());
|
|
return;
|
|
}
|
|
setWindowTitle(fileName);
|
|
QJsonObject json;
|
|
json["name"] = ui->titleEdit->text();
|
|
json["city"] =ui->locEdit->text();
|
|
json["departement"] = ui->depSpin->text();
|
|
json["difficulty"] = ui->diffSpin->value();
|
|
json["duration"] = ui->durationSpin->value();
|
|
json["length"] = ui->lengthSpin->value();
|
|
json["image"] = ui->imagePath->text();
|
|
|
|
|
|
QJsonArray steps;
|
|
QJsonObject step1;
|
|
step1["numero"] = "3";
|
|
step1["title"] = "ok ca marche";
|
|
step1["GPS"] = "S 45 37.199 E 1 2.009";
|
|
step1["reponse"] = "34";
|
|
|
|
QJsonArray dialogues;
|
|
QJsonObject dialogue1;
|
|
dialogue1["personnage"] = "Quentin";
|
|
dialogue1["texte"] = "ok c'est cool";
|
|
|
|
dialogues.append(dialogue1);
|
|
step1["dialogue"] = dialogues;
|
|
steps.append(step1);
|
|
json["steps"] = steps;
|
|
|
|
QJsonDocument doc(json);
|
|
file.write(doc.toJson());
|
|
|
|
file.close();
|
|
}
|
|
|
|
void MainWindow::on_actionSave_triggered()
|
|
{
|
|
this->saveFile();
|
|
}
|
|
|