#include "mainwindow.h" #include "ui_mainwindow.h" #include "path.h" #include #include 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(QTextStream &in) { } 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() { 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::on_toolButton_clicked() { QString fileName = ui->imagePath->text(); if(fileName.isEmpty()) return; loadImage(fileName); }