Merge branch 'main' into 'feature/save'
# Conflicts: # mainwindow.cpp # mainwindow.h # mainwindow.ui # step.h
This commit is contained in:
+141
-7
@@ -1,9 +1,12 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "path.h"
|
||||
|
||||
#include "step.h"
|
||||
#include "Undo.h"
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QLineEdit>
|
||||
#include <QTimer>
|
||||
|
||||
|
||||
#include <QFile>
|
||||
@@ -15,8 +18,41 @@
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
, undoStack(new QUndoStack(this))
|
||||
, Clipboard(QGuiApplication::clipboard())
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
|
||||
connect(ui->titleEdit, &QLineEdit::editingFinished, this, [this]() {
|
||||
static QString previousText;
|
||||
QString currentText = ui->titleEdit->text();
|
||||
if(previousText != currentText) {
|
||||
undoStack->push(new LineEditCommand(ui->titleEdit, previousText, currentText));
|
||||
previousText = currentText;
|
||||
}
|
||||
});
|
||||
|
||||
connect(ui->locEdit, &QLineEdit::editingFinished, this, [this]() {
|
||||
static QString previousText;
|
||||
QString currentText = ui->locEdit->text();
|
||||
if(previousText != currentText) {
|
||||
undoStack->push(new LineEditCommand(ui->locEdit, previousText, currentText));
|
||||
previousText = currentText;
|
||||
}
|
||||
});
|
||||
|
||||
connect(ui->imagePath, &QLineEdit::editingFinished, this, [this]() {
|
||||
static QString previousText;
|
||||
QString currentText = ui->imagePath->text();
|
||||
if(previousText != currentText) {
|
||||
undoStack->push(new LineEditCommand(ui->imagePath, previousText, currentText));
|
||||
previousText = currentText;
|
||||
}
|
||||
});
|
||||
|
||||
connect(ui->actionEditUndo, &QAction::triggered, undoStack, &QUndoStack::undo);
|
||||
connect(ui->actionEditRedo, &QAction::triggered, undoStack, &QUndoStack::redo);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@@ -44,7 +80,7 @@ void MainWindow::onTextChanged()
|
||||
textChanged = true;
|
||||
}
|
||||
|
||||
void MainWindow::loadPath()
|
||||
void MainWindow::loadNewPath()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, "Open the file");
|
||||
if(fileName.isEmpty()) return;
|
||||
@@ -58,6 +94,18 @@ void MainWindow::loadPath()
|
||||
Path* p = new Path(&file);
|
||||
currentPath = p;
|
||||
path.append(p);
|
||||
loadPath(p);
|
||||
|
||||
int pathCount = path.length();
|
||||
ui->pathNumber->setMaximum(pathCount);
|
||||
ui->pathNumber->setSuffix("/" + QString::number(pathCount));
|
||||
ui->pathNumber->setValue(path.indexOf(currentPath)+1);
|
||||
}
|
||||
|
||||
void MainWindow::loadPath(Path* p) {
|
||||
|
||||
QList<Step> steps = p->getStep();
|
||||
|
||||
|
||||
ui->titleEdit->setText(p->getName());
|
||||
ui->locEdit->setText(p->getCity());
|
||||
@@ -66,8 +114,36 @@ void MainWindow::loadPath()
|
||||
ui->durationSpin->setValue(p->getDuration());
|
||||
ui->imagePath->setText(p->getImage());
|
||||
ui->depSpin->setValue(p->getDepartement());
|
||||
|
||||
loadImage(p->getImage());
|
||||
|
||||
ui->dialogEdit->clear();
|
||||
|
||||
if(!steps.isEmpty()) {
|
||||
Step firstStep = p->getStep().first();
|
||||
ui->stepTitle->setText(firstStep.getTitle());
|
||||
ui->LatitudeSpin->setValue(firstStep.getLatitude());
|
||||
ui->longitudeSpin->setValue(firstStep.getLongitude());
|
||||
|
||||
for(int i = 0; i < firstStep.getTexte().length(); i++) {
|
||||
QString q = firstStep.getPersonnage().at(i) + ": " + firstStep.getTexte().at(i);
|
||||
ui->dialogEdit->appendPlainText(q);
|
||||
}
|
||||
|
||||
ui->stepNumber->setValue(1);
|
||||
ui->stepNumber->setSuffix("/" + QString::number(steps.length()));
|
||||
ui->stepNumber->setMaximum(steps.length());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::loadStep(Step s) {
|
||||
ui->stepTitle->setText(s.getTitle());
|
||||
ui->LatitudeSpin->setValue(s.getLatitude());
|
||||
ui->longitudeSpin->setValue(s.getLongitude());
|
||||
|
||||
for(int i = 0; i < s.getTexte().length(); i++) {
|
||||
QString q = s.getPersonnage().at(i) + ": " + s.getTexte().at(i);
|
||||
ui->dialogEdit->appendPlainText(q);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::addNewPath()
|
||||
@@ -129,7 +205,7 @@ void MainWindow::on_pushButton_clicked()
|
||||
|
||||
void MainWindow::on_actionOpen_triggered()
|
||||
{
|
||||
this->loadPath();
|
||||
this->loadNewPath();
|
||||
}
|
||||
|
||||
void MainWindow::on_toolButton_clicked()
|
||||
@@ -139,6 +215,7 @@ void MainWindow::on_toolButton_clicked()
|
||||
loadImage(fileName);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::saveFile(){
|
||||
QString fileName;
|
||||
if (currentFile.isEmpty()) {
|
||||
@@ -172,10 +249,10 @@ void MainWindow::saveFile(){
|
||||
stepObject["GPS"] = step.toGPSFormat();
|
||||
stepObject["reponse"] = step.getResponse();
|
||||
QJsonArray dialogues;
|
||||
for(int i=0; i<step.getListeDialogue().size(); i++){
|
||||
for(int i=0; i<step.getTexte().size(); i++){
|
||||
QJsonObject dialogueObject;
|
||||
dialogueObject["personnage"] = step.getListePersonnage()[i];
|
||||
dialogueObject["texte"] = step.getListeDialogue()[i];
|
||||
dialogueObject["personnage"] = step.getPersonnage()[i];
|
||||
dialogueObject["texte"] = step.getTexte()[i];
|
||||
dialogues.append(dialogueObject);
|
||||
}
|
||||
stepObject["dialogue"] = dialogues;
|
||||
@@ -194,3 +271,60 @@ void MainWindow::on_actionSave_triggered()
|
||||
this->saveFile();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionopenFile_triggered()
|
||||
{
|
||||
this->loadNewPath();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionEditCopy_triggered()
|
||||
{
|
||||
QWidget *focused = QApplication::focusWidget();
|
||||
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(focused);
|
||||
|
||||
if(lineEdit) {
|
||||
Clipboard->setText(lineEdit->selectedText());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_actionEditPaste_triggered()
|
||||
{
|
||||
QWidget *focused = QApplication::focusWidget();
|
||||
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(focused);
|
||||
|
||||
if(lineEdit) {
|
||||
QString text = lineEdit->text();
|
||||
int pos = lineEdit->cursorPosition();
|
||||
text.insert(pos, Clipboard->text());
|
||||
lineEdit->setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_actionEditCut_triggered()
|
||||
{
|
||||
QWidget *focused = QApplication::focusWidget();
|
||||
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(focused);
|
||||
|
||||
if(lineEdit) {
|
||||
QString text = lineEdit->text();
|
||||
QString selectedText = lineEdit->selectedText();
|
||||
int pos = lineEdit->selectionStart();
|
||||
text.remove(pos, selectedText.length());
|
||||
Clipboard->setText(selectedText);
|
||||
lineEdit->setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_pathNumber_valueChanged(int arg1)
|
||||
{
|
||||
this->loadPath(path.at(ui->pathNumber->value()-1));
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_stepNumber_valueChanged(int arg1)
|
||||
{
|
||||
this->loadStep(currentPath->getStep().at(arg1-1));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user