#include "mainwindow.h" #include "ui_mainwindow.h" #include "path.h" #include #include #include int MainWindow::indexPath = 0; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); indexPath++; } 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()); loadImage(p->getImage()); } void MainWindow::addNewPath() { path.append(currentPath); } void MainWindow::addNewStep() { } void MainWindow::exportHTMLMap(int index) { std::ofstream file("./pages/parcours" + std::to_string(index) + ".html"); if (!file.is_open()) { QMessageBox::warning(this, "Erreur", "Impossible d'ouvrir le fichier."); return; } file << R"( Carte du parcours

Fiche du parcours

)"; if (currentPath) { Path* p = currentPath; file << "

" << p->getName().toStdString() << "

\n"; file << "

Ville : " << p->getCity().toStdString() << "

\n"; file << "

Département : " << p->getDepartement() << "

\n"; file << "

Difficulté : " << p->getDifficulty() << "

\n"; file << "

Durée (heures) : " << p->getDuration() << "

\n"; file << "

Longueur (km) : " << p->getLength() << "

\n"; if (!p->getImage().isEmpty()) { file << "getImage().toStdString() << "\">\n"; } int stepNum = 1; for (const Step& s : p->getStep()) { file << "

Étape " << stepNum << "

\n"; const QList persos = s.getPersonnage(); const QList textes = s.getTexte(); if (!persos.isEmpty()) { file << "

Personnages :

\n
    "; for (const QString& pers : persos) { file << "
  • " << pers.toStdString() << "
  • \n"; } file << "
\n"; } if (!textes.isEmpty()) { file << "

Dialogues :

\n
    "; for (const QString& txt : textes) { file << "
  • " << txt.toStdString() << "
  • \n"; } file << "
\n"; } stepNum++; } } file << R"(
)"; file.close(); } 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); } int MainWindow::getIndexPath() const { return indexPath; } void MainWindow::setIndexPath(int newIndexPath) { indexPath = newIndexPath; } QString MainWindow::getCurrentFile() const { return currentFile; } void MainWindow::setCurrentFile(const QString &newCurrentFile) { currentFile = newCurrentFile; } QList MainWindow::getPath() const { return path; } void MainWindow::setPath(const QList &newPath) { path = newPath; } Path *MainWindow::getCurrentPath() const { return currentPath; } void MainWindow::setCurrentPath(Path *newCurrentPath) { currentPath = newCurrentPath; }