Merge branch 'dev' into 'feature/addStep'

# Conflicts:
#   mainwindow.cpp
This commit is contained in:
T'JAMPENS QUENTIN p2406187
2025-06-21 11:18:03 +00:00
9 changed files with 215 additions and 375 deletions
+180 -113
View File
@@ -137,7 +137,7 @@ void MainWindow::loadPath(Path* p) {
ui->longitudeSpin->setValue(firstStep.getLongitude());
for(int i = 0; i < firstStep.getTexte().length(); i++) {
QString q = firstStep.getPersonnage().at(i) + ": " + firstStep.getTexte().at(i);
QString q = "[" + firstStep.getPersonnage().at(i) + "] : " + firstStep.getTexte().at(i);
ui->dialogEdit->appendPlainText(q);
}
@@ -174,13 +174,29 @@ 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.");
if (index < 0 || index >= path.size()) {
QMessageBox::warning(this, "Erreur", "Index de parcours invalide.");
return;
}
Path* p = path[index];
if (!p) {
QMessageBox::warning(this, "Erreur", "Le parcours sélectionné est nul.");
return;
}
QString safeName = p->getName().simplified().replace(" ", "_");
std::string fileName = "./pages/parcours_" + safeName.toStdString() + ".html";
std::ofstream file(fileName);
if (!file.is_open()) {
QMessageBox::warning(this, "Erreur", "Impossible d'ouvrir le fichier HTML.");
return;
}
// Début HTML
file << R"(<!DOCTYPE html>
<html lang="fr">
<head>
@@ -216,18 +232,17 @@ void MainWindow::exportHTMLMap(int index)
border-radius: 5%;
}
#fiche ul {
padding-left: 20px;
list-style-type: disc;
overflow-wrap: break-word;
word-wrap: break-word;
word-break: break-word;
white-space: normal;
max-width: 90%;
}
padding-left: 20px;
list-style-type: disc;
overflow-wrap: break-word;
word-wrap: break-word;
word-break: break-word;
white-space: normal;
max-width: 90%;
}
#fiche li {
white-space: normal;
overflow-wrap: break-word;
white-space: normal;
overflow-wrap: break-word;
}
body h1 {
display:flex;
@@ -253,114 +268,122 @@ void MainWindow::exportHTMLMap(int index)
</style>
</head>
<body>
<h1>Fiche du parcours</h1>
<div id="container">
<div id="map"></div>
<div id="fiche">
<a href="../index.html"><button>Revenir en arrière</button></a>
<h1>Fiche du parcours</h1>
<div id="container">
<div id="map"></div>
<div id="fiche">
)";
if (currentPath) {
Path* p = currentPath;
file << "<h2>" << p->getName().toStdString() << "</h2>\n";
file << "<p><strong>Ville :</strong> " << p->getCity().toStdString() << "</p>\n";
file << "<p><strong>Département :</strong> " << p->getDepartement() << "</p>\n";
file << "<p><strong>Difficulté :</strong> " << p->getDifficulty() << "</p>\n";
file << "<p><strong>Durée (heures) :</strong> " << p->getDuration() << "</p>\n";
file << "<p><strong>Longueur (km) :</strong> " << p->getLength() << "</p>\n";
if (!p->getImage().isEmpty()) {
file << "<img src=\"" << p->getImage().toStdString() << "\">\n";
}
int stepNum = 1;
for (const Step& s : p->getStep()) {
file << "<h3>Étape " << stepNum << "</h3>\n";
const QList<QString> persos = s.getPersonnage();
const QList<QString> textes = s.getTexte();
// Infos du parcours
file << "<h2>" << p->getName().toStdString() << "</h2>\n";
file << "<p><strong>Ville :</strong> " << p->getCity().toStdString() << "</p>\n";
file << "<p><strong>Département :</strong> " << p->getDepartement() << "</p>\n";
file << "<p><strong>Difficulté :</strong> " << p->getDifficulty() << "</p>\n";
file << "<p><strong>Durée (heures) :</strong> " << p->getDuration() << "</p>\n";
file << "<p><strong>Longueur (km) :</strong> " << p->getLength() << "</p>\n";
if (!persos.isEmpty()) {
file << "<p><strong>Personnages :</strong></p>\n<ul>";
for (const QString& pers : persos) {
file << "<li>" << pers.toStdString() << "</li>\n";
}
file << "</ul>\n";
if (!p->getImage().isEmpty()) {
QString imagePath = p->getImage();
QFileInfo fileInfo(imagePath);
QString imageName = fileInfo.fileName();
QString destPath = "./pages/images/" + imageName;
// Crée le dossier images sil nexiste pas
QDir().mkpath("./pages/images");
// Copie limage dans le dossier pages/images
QFile::copy(imagePath, destPath);
// Utilisation dans le HTML
file << "<img src=\"images/" << imageName.toStdString() << "\">\n";
}
int stepNum = 1;
for (const Step& s : p->getStep()) {
file << "<h3>Étape " << stepNum << "</h3>\n";
const QList<QString> persos = s.getPersonnage();
const QList<QString> textes = s.getTexte();
if (!persos.isEmpty()) {
file << "<p><strong>Personnages :</strong></p>\n<ul>";
for (const QString& pers : persos) {
file << "<li>" << pers.toStdString() << "</li>\n";
}
if (!textes.isEmpty()) {
file << "<p><strong>Dialogues :</strong></p>\n<ul>";
for (const QString& txt : textes) {
file << "<li>" << txt.toStdString() << "</li>\n";
}
file << "</ul>\n";
}
stepNum++;
file << "</ul>\n";
}
if (!textes.isEmpty()) {
file << "<p><strong>Dialogues :</strong></p>\n<ul>";
for (const QString& txt : textes) {
file << "<li>" << txt.toStdString() << "</li>\n";
}
file << "</ul>\n";
}
stepNum++;
}
file << R"(
</div>
</div>
</div>
</div>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script>
var map = L.map('map').setView([45.5, 1.5], 10); // Vue centrée
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script>
var map = L.map('map').setView([45.5, 1.5], 10);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
)";
if (!path.isEmpty() && path[0]) {
Path* p = path[0];
int stepNum = 1;
// Ajout des étapes sur la carte
stepNum = 1;
for (const Step& s : p->getStep()) {
float lat = s.getLatitude();
float lon = s.getLongitude();
QList<QString> personnages = s.getPersonnage();
QList<QString> textes = s.getTexte();
for (const Step& s : p->getStep()) {
float lat = s.getLatitude();
float lon = s.getLongitude();
QList<QString> personnages = s.getPersonnage();
QList<QString> textes = s.getTexte();
QString popupHtml = "<b>Étape " + QString::number(stepNum) + "</b><br>";
if (!personnages.isEmpty()) {
popupHtml += "<b>Personnages :</b><ul>";
for (const QString& pers : personnages) {
popupHtml += "<li>" + pers + "</li>";
}
popupHtml += "</ul>";
QString popupHtml = "<b>Étape " + QString::number(stepNum) + "</b><br>";
if (!personnages.isEmpty()) {
popupHtml += "<b>Personnages :</b><ul>";
for (const QString& pers : personnages) {
popupHtml += "<li>" + pers + "</li>";
}
if (!textes.isEmpty()) {
popupHtml += "<b>Textes :</b><ul>";
for (const QString& txt : textes) {
popupHtml += "<li>" + txt + "</li>";
}
popupHtml += "</ul>";
popupHtml += "</ul>";
}
if (!textes.isEmpty()) {
popupHtml += "<b>Textes :</b><ul>";
for (const QString& txt : textes) {
popupHtml += "<li>" + txt + "</li>";
}
file << "L.marker([" << lat << ", " << lon << "]).addTo(map)"
<< ".bindPopup(\"" << popupHtml.toStdString() << "\");\n";
++stepNum;
popupHtml += "</ul>";
}
file << "var latlngs = [\n";
for (const Step& s : p->getStep()) {
float lat = s.getLatitude();
float lon = s.getLongitude();
file << " [" << lat << ", " << lon << "],\n";
}
file << "];\n";
file << "L.marker([" << lat << ", " << lon << "]).addTo(map)"
<< ".bindPopup(\"" << popupHtml.toStdString() << "\");\n";
file << R"(
var polyline = L.polyline(latlngs, {
color: 'purple',
weight: 2,
dashArray: '10, 10',
opacity: 0.7
}).addTo(map);
map.fitBounds(polyline.getBounds());
)";
++stepNum;
}
file << "var latlngs = [\n";
for (const Step& s : p->getStep()) {
file << " [" << s.getLatitude() << ", " << s.getLongitude() << "],\n";
}
file << "];\n";
file << R"(
</script>
var polyline = L.polyline(latlngs, {
color: 'purple',
weight: 2,
dashArray: '10, 10',
opacity: 0.7
}).addTo(map);
map.fitBounds(polyline.getBounds());
</script>
</body>
</html>
)";
@@ -369,6 +392,7 @@ void MainWindow::exportHTMLMap(int index)
void MainWindow::loadImage(QString fileName) {
QString ext[] = {"png", "jpeg", "jpg"};
@@ -599,16 +623,59 @@ void MainWindow::on_stepNumber_valueChanged(int arg1)
void MainWindow::on_validateBtn_clicked()
{
currentPath->setName(ui->titleEdit->text());
currentPath->setCity(ui->locEdit->text());
currentPath->setImage(ui->imagePath->text());
currentPath->setLength(ui->lengthSpin->value());
currentPath->setDifficulty(ui->diffSpin->value());
currentPath->setDuration(ui->durationSpin->value());
currentPath->getStep()[ui->stepNumber->value()-1].setTitle(ui->stepTitle->text());
currentPath->getStep()[ui->stepNumber->value()-1].setResponse(ui->responseSpin->value());
this->currentPath->setName(ui->titleEdit->text());
this->currentPath->setCity(ui->locEdit->text());
this->currentPath->setImage(ui->imagePath->text());
this->currentPath->setLength(ui->lengthSpin->value());
this->currentPath->setDifficulty(ui->diffSpin->value());
this->currentPath->setDuration(ui->durationSpin->value());
this->currentPath->getStep()[ui->stepNumber->value()-1].setTitle(ui->stepTitle->text());
this->currentPath->getStep()[ui->stepNumber->value()-1].setResponse(ui->responseSpin->value());
this->currentPath->getStep()[ui->stepNumber->value()-1].clearPersonnages();
this->currentPath->getStep()[ui->stepNumber->value()-1].clearTextes();
extractDialogue();
}
void MainWindow::extractDialogue() {
std::string texte = ui->dialogEdit->toPlainText().toStdString();
size_t currentPosition = 0;
while (currentPosition < texte.length()) {
size_t startPersonnage = texte.find('[', currentPosition);
if (startPersonnage == std::string::npos) break;
size_t endPersonnage = texte.find(']', startPersonnage);
if (endPersonnage == std::string::npos) break;
std::string nomPersonnage = texte.substr(startPersonnage + 1, endPersonnage - startPersonnage - 1);
size_t startDialogue = texte.find(':', endPersonnage);
if (startDialogue == std::string::npos) break;
startDialogue += 2;
size_t endDialogue = startDialogue;
while (endDialogue < texte.length()) {
size_t nextNewLine = texte.find('\n', endDialogue);
if (nextNewLine == std::string::npos) {
endDialogue = texte.length();
break;
}
size_t nextPersonnageStart = texte.find('[', nextNewLine);
if (nextPersonnageStart != std::string::npos && nextPersonnageStart < nextNewLine + nomPersonnage.length() + 3) {
endDialogue = nextNewLine;
break;
}
endDialogue = nextNewLine + 1;
}
std::string dialogue = texte.substr(startDialogue, endDialogue - startDialogue);
currentPath->getStep()[ui->stepNumber->value()-1].addPersonnage(QString::fromStdString(nomPersonnage));
currentPath->getStep()[ui->stepNumber->value()-1].addTexte(QString::fromStdString(dialogue));
currentPosition = endDialogue;
}
}
void MainWindow::loadAndExportPaths(QStringList fichiers) {
@@ -902,6 +969,7 @@ void MainWindow::newPath(){
currentPath = p;
path.append(p);
loadPath(p);
p->addStep();
int pathCount = path.length();
ui->pathNumber->setMaximum(pathCount);
@@ -929,5 +997,4 @@ void MainWindow::on_actionFont_color_triggered()
void MainWindow::on_addStep_clicked()
{
this->addNewStep();
}
}