diff --git a/.gitignore b/.gitignore index e19bf19..76265f9 100644 --- a/.gitignore +++ b/.gitignore @@ -454,3 +454,4 @@ compile_commands.json *creator.user* *_qmlcache.qrc +build diff --git a/data/parcours1.json b/data/parcours1.json new file mode 100644 index 0000000..bb5a755 --- /dev/null +++ b/data/parcours1.json @@ -0,0 +1,44 @@ +{ + "name": "parcous1", + "city": "Bourg en bresse", + "departement": 1, + "difficulty": 2, + "duration": 2.3, + "length": 17.3, + "image": "data/parcours1.png", + "steps": [ + { + "numero": 1, + "title": "Première étape", + "GPS": "N 45 37.199 W 1 2.009", + "reponse": -1, + "dialogue": [ + { + "personnage": "Quentin", + "texte": "ligne de dialogue 1" + }, + { + "personnage": "Malo", + "texte": "ligne de dialogue 2" + } + ] + }, + { + "numero": 2, + "title": "Deuxième étape", + "GPS": "S 45 37.199 E 1 2.009", + "reponse": 4156, + "dialogue": [ + { + "personnage": "Antoine", + "texte": "ligne de dialogue 1" + }, + { + "personnage": "Giovanni", + "texte": "ligne de dialogue 2" + } + ] + } + ] + +} diff --git a/data/parcours1.png b/data/parcours1.png new file mode 100644 index 0000000..11eb818 Binary files /dev/null and b/data/parcours1.png differ diff --git a/mainwindow.cpp b/mainwindow.cpp index 2740a6e..69a8d9e 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,6 +1,9 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include +#include + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) @@ -11,4 +14,98 @@ MainWindow::MainWindow(QWidget *parent) 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::on_pushButton_clicked() +{ + + QString ext[] = {"png", "jpeg", "jpg"}; + + 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", "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_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; + } + + +} + diff --git a/mainwindow.h b/mainwindow.h index f7a3da3..38e219a 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -3,6 +3,8 @@ #include +#include "path.h" + QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; @@ -16,8 +18,24 @@ class MainWindow : public QMainWindow public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); + void updatePathView(); + void updateStepView(size_t num); + void onTextChanged(); + void loadPath(QTextStream &in); + void addNewPath(); + void addNewStep(); + void exportHTMLMap(); + +private slots: + void on_pushButton_clicked(); + + void on_actionOpen_triggered(); private: Ui::MainWindow *ui; + QString currentFile; + bool textChanged; + QList path; + Path* currentPath; }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index c6854ca..8c3b28b 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -7,13 +7,281 @@ 0 0 800 - 600 + 626 MainWindow - + + + + 800 + 521 + + + + + + + + 0 + 0 + + + + + 16777215 + 20 + + + + Path information + + + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop + + + + + + + + 16777215 + 16777215 + + + + QFrame::Shape::StyledPanel + + + QFrame::Shadow::Raised + + + + + 10 + 20 + 45 + 27 + + + + + + + 60 + 20 + 391 + 26 + + + + + + + 10 + 60 + 441 + 45 + + + + + 0 + + + 0 + + + + + Localisation + + + + + + + + + + + + + + + 470 + 20 + 281 + 191 + + + + + + + + + + 0 + 110 + 451 + 63 + + + + + 0 + + + 0 + + + + + + + + Difficulty + + + + + + + /5 + + + 5 + + + + + + + + + + + + + Duration + + + + + + + h + + + 1 + + + 0.100000000000000 + + + + + + + + + + + + + Length + + + + + + + Km + + + 1 + + + 500.000000000000000 + + + 0.100000000000000 + + + + + + + + + + + + 0 + 180 + 451 + 44 + + + + + 9 + + + 0 + + + + + Image + + + + + + + + + + Select Image File + + + + + + + + + + + + 16777215 + 20 + + + + Step information + + + Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop + + + + + + + QFrame::Shape::StyledPanel + + + QFrame::Shadow::Raised + + + + + @@ -23,8 +291,192 @@ 23 + + + File + + + + + + + + Edit + + + + + + + toolBar + + + TopToolBarArea + + + false + + + + + + + + + + + + + + + + + + Open + + + Ctrl+O + + + + + Save + + + Ctrl+S + + + + + Save as + + + Ctrl+Shift+S + + + + + + + + NewFile + + + QAction::MenuRole::NoRole + + + + + + + + SaveFile + + + QAction::MenuRole::NoRole + + + + + + + + SaveAsFile + + + QAction::MenuRole::NoRole + + + + + + + + PrintFile + + + QAction::MenuRole::NoRole + + + + + + + + EditCopy + + + QAction::MenuRole::NoRole + + + + + + + + EditPaste + + + QAction::MenuRole::NoRole + + + + + + + + EditCut + + + QAction::MenuRole::NoRole + + + + + + + + EditDelete + + + QAction::MenuRole::NoRole + + + + + + + + EditUndo + + + QAction::MenuRole::NoRole + + + + + + + + EditRedo + + + QAction::MenuRole::NoRole + + + + + + + + New + + + QAction::MenuRole::NoRole + + diff --git a/path.cpp b/path.cpp index ab0fdfb..4f4fd97 100644 --- a/path.cpp +++ b/path.cpp @@ -1,13 +1,44 @@ #include "path.h" +#include "step.h" +#include +#include +#include +#include +#include + +#include + Path::Path(QFile *file){ - QTextStream in(&file); - QString text = in.readAll(); - ui->textEdit->setText(text); - file.close(); -} -void Path::addStep(){ + if (!file->open(QIODevice::ReadOnly)) { + qWarning() << "Could not open file:" << file->errorString(); + return; + } + QByteArray data = file->readAll(); + file->close(); + QJsonDocument doc = QJsonDocument::fromJson(data); + if (doc.isNull()) { + qWarning() << "Failed to create JSON document"; + return; + } + QJsonObject json = doc.object(); + + name = json["name"].toString(); + city = json["city"].toString(); + departement = json["departement"].toInt(); + difficulty = json["difficulty"].toInt(); + duration = json["duration"].toDouble(); + length = json["length"].toDouble(); + image = json["image"].toString(); + + QJsonArray stepsArray = json["steps"].toArray(); + for (const QJsonValue &stepValue : stepsArray) { + QJsonObject stepObj = stepValue.toObject(); + step.append(Step(stepObj)); + } } + +void Path::addStep(int indice){step.insert(indice, Step());} diff --git a/path.h b/path.h index 52ec154..b990bbb 100644 --- a/path.h +++ b/path.h @@ -2,6 +2,9 @@ #define PATH_H #include +#include +#include "step.h" + class Path { @@ -17,7 +20,7 @@ private: public: Path(); Path(QFile *file); - void addStep(); + void addStep(int indice=step.size()); }; #endif // PATH_H