diff --git a/mainwindow.cpp b/mainwindow.cpp index c947ab4..61c7ef6 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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); } @@ -626,8 +626,51 @@ void MainWindow::on_validateBtn_clicked() 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) { @@ -921,6 +964,7 @@ void MainWindow::newPath(){ currentPath = p; path.append(p); loadPath(p); + p->addStep(); int pathCount = path.length(); ui->pathNumber->setMaximum(pathCount); @@ -944,6 +988,3 @@ void MainWindow::on_actionFont_color_triggered() { this->setColor(); } - - - diff --git a/mainwindow.h b/mainwindow.h index 8090e39..f7c92a3 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -51,6 +51,7 @@ public: void setFont(); void saveFile(); void newPath(); + void extractDialogue(); private slots: void on_pushButton_clicked(); diff --git a/step.cpp b/step.cpp index 419f676..18c87b5 100644 --- a/step.cpp +++ b/step.cpp @@ -37,6 +37,22 @@ QList Step::getTexte() const return texte; } +void Step::addPersonnage(const QString& pers) { + personnage.append(pers); +} + +void Step::addTexte(const QString& txt) { + texte.append(txt); +} + +void Step::clearPersonnages() { + personnage.clear(); +} + +void Step::clearTextes() { + texte.clear(); +} + void Step::setTitle(const QString &newTitle) { title = newTitle; diff --git a/step.h b/step.h index eb2bc9e..6746ed9 100644 --- a/step.h +++ b/step.h @@ -33,6 +33,10 @@ public: void setPersonnage(const QList &newPersonnage); void setTexte(const QList &newTexte); QString toGPSFormat(); + void addPersonnage(const QString& pers) ; + void addTexte(const QString& txt); + void clearPersonnages(); + void clearTextes(); }; #endif // STEP_H