2018-05-10 16:41:14 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
|
2019-01-30 20:41:03 +00:00
|
|
|
#include "version.h"
|
|
|
|
|
2018-05-15 11:11:40 +00:00
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QFileDialog>
|
2018-05-15 12:24:15 +00:00
|
|
|
#include <QDataWidgetMapper>
|
2018-09-29 11:31:23 +00:00
|
|
|
#include <QCloseEvent>
|
|
|
|
#include <QMessageBox>
|
2018-10-29 20:53:52 +00:00
|
|
|
#include <QtPrintSupport/QPrinter>
|
|
|
|
#include <QtPrintSupport/QPrintDialog>
|
2018-10-29 21:05:34 +00:00
|
|
|
#include <QTextDocument>
|
2019-01-12 15:50:04 +00:00
|
|
|
#include <QPainter>
|
2018-10-29 21:05:34 +00:00
|
|
|
|
2018-09-29 11:31:23 +00:00
|
|
|
#include <QDebug>
|
2018-05-15 11:11:40 +00:00
|
|
|
|
2018-11-03 21:29:38 +00:00
|
|
|
#include <fstream>
|
|
|
|
|
2018-05-10 16:41:14 +00:00
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
2018-10-29 20:53:52 +00:00
|
|
|
: QMainWindow(parent)
|
|
|
|
, ui(new Ui::MainWindow)
|
2018-12-02 14:22:44 +00:00
|
|
|
, m_dataModel(this)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
setupUi();
|
|
|
|
|
|
|
|
newFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent, const QString &filename)
|
|
|
|
: QMainWindow(parent)
|
|
|
|
, ui(new Ui::MainWindow)
|
|
|
|
, m_dataModel(this)
|
2018-05-10 16:41:14 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2018-12-02 14:22:44 +00:00
|
|
|
setupUi();
|
|
|
|
|
|
|
|
openFile(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::setupUi()
|
|
|
|
{
|
|
|
|
ui->metaDataWidget->setModel(&m_dataModel.m_metaData);
|
|
|
|
ui->verbEndWidget->setModel(&m_dataModel.m_verbEnd);
|
|
|
|
ui->genusWidget->setModel(&m_dataModel.m_genus);
|
|
|
|
ui->pluralWidget->setModel(&m_dataModel.m_plural);
|
|
|
|
ui->akkusativDativWidget->setAkkusativModel(&m_dataModel.m_akkusativ);
|
|
|
|
ui->akkusativDativWidget->setDativModel(&m_dataModel.m_dativ);
|
2019-01-31 19:14:38 +00:00
|
|
|
|
|
|
|
ui->v2SvkWidget->setWFModel(&m_dataModel.m_wfModel);
|
|
|
|
ui->v2SvkWidget->setOTModel(&m_dataModel.m_otModel);
|
|
|
|
ui->v2SvkWidget->setTPrModel(&m_dataModel.m_tPrModel);
|
2019-01-30 22:07:11 +00:00
|
|
|
ui->v2SvkWidget->setTPeModel(&m_dataModel.m_tPeModel);
|
2019-01-31 19:14:38 +00:00
|
|
|
|
2018-12-02 14:22:44 +00:00
|
|
|
ui->lateSkillsWidget->setPassivModel(&m_dataModel.m_passiv);
|
|
|
|
ui->lateSkillsWidget->setGenitivModel(&m_dataModel.m_genitiv);
|
|
|
|
ui->resultWidget->setModel(&m_dataModel.m_results);
|
2018-05-15 11:11:40 +00:00
|
|
|
|
2018-09-29 11:42:38 +00:00
|
|
|
connect(ui->actionNew, &QAction::triggered, this, &MainWindow::newFile);
|
2018-12-02 14:22:44 +00:00
|
|
|
connect(ui->actionOpen, &QAction::triggered, this, qOverload<>(&MainWindow::openFile));
|
2018-10-29 20:53:52 +00:00
|
|
|
connect(ui->actionSave, &QAction::triggered, this, qOverload<>(&MainWindow::saveFile));
|
|
|
|
connect(ui->actionSave_as, &QAction::triggered, this, &MainWindow::saveFileAs);
|
|
|
|
connect(ui->actionPrint, &QAction::triggered, this, &MainWindow::print);
|
2018-12-09 10:11:55 +00:00
|
|
|
connect(ui->actionExport_PDF, &QAction::triggered, this, qOverload<>(&MainWindow::savePdf));
|
2018-05-15 12:24:15 +00:00
|
|
|
|
2019-01-30 20:41:03 +00:00
|
|
|
connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::aboutDialog);
|
|
|
|
|
2018-12-02 14:22:44 +00:00
|
|
|
connect(&m_dataModel, &DataModel::modelChanged, this, &MainWindow::dataModelChanged);
|
2018-05-10 16:41:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2018-05-20 10:04:21 +00:00
|
|
|
void MainWindow::newFile()
|
2018-05-15 11:11:40 +00:00
|
|
|
{
|
2018-09-30 09:38:30 +00:00
|
|
|
closeFile();
|
|
|
|
|
2018-09-29 11:31:23 +00:00
|
|
|
setWindowModified(false);
|
|
|
|
setWindowTitle("untitled[*]");
|
2018-06-25 21:04:32 +00:00
|
|
|
m_filename = "";
|
2018-09-29 11:31:23 +00:00
|
|
|
m_saveOnClose = false;
|
2018-05-15 11:11:40 +00:00
|
|
|
}
|
2018-05-16 05:02:12 +00:00
|
|
|
|
2018-05-20 10:04:21 +00:00
|
|
|
void MainWindow::openFile()
|
2018-05-16 05:02:12 +00:00
|
|
|
{
|
2018-10-29 20:53:52 +00:00
|
|
|
QString filename =
|
|
|
|
QFileDialog::getOpenFileName(this, "Open file", "", "ESGRAF 4-8 (*.esgraf48)");
|
2018-05-16 05:02:12 +00:00
|
|
|
if (filename.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-29 19:55:16 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
openFile(filename);
|
|
|
|
}
|
|
|
|
catch (std::exception &e)
|
|
|
|
{
|
|
|
|
QString errorMessage = QString("Error loading \"") + filename + "\": " + e.what();
|
|
|
|
QMessageBox::critical(this, "Error", errorMessage);
|
|
|
|
}
|
2018-12-02 14:22:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::openFile(const QString &filename)
|
|
|
|
{
|
2018-09-30 09:38:30 +00:00
|
|
|
closeFile();
|
|
|
|
|
2019-01-29 19:14:24 +00:00
|
|
|
m_dataModel.read(filename);
|
2018-05-16 05:02:12 +00:00
|
|
|
|
2018-09-29 11:31:23 +00:00
|
|
|
setWindowModified(false);
|
|
|
|
setWindowTitle(filename + "[*]");
|
|
|
|
m_saveOnClose = false;
|
2018-06-25 21:04:32 +00:00
|
|
|
m_filename = filename;
|
2018-05-24 09:54:24 +00:00
|
|
|
|
2018-06-25 21:04:32 +00:00
|
|
|
ui->metaDataWidget->toFirst();
|
2018-05-24 09:54:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::saveFile()
|
|
|
|
{
|
2018-06-25 21:04:32 +00:00
|
|
|
if (m_filename.isEmpty())
|
|
|
|
{
|
|
|
|
saveFileAs();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
saveFile(m_filename);
|
|
|
|
}
|
2018-05-16 05:02:12 +00:00
|
|
|
}
|
2018-05-20 10:04:21 +00:00
|
|
|
|
|
|
|
void MainWindow::saveFileAs()
|
|
|
|
{
|
2018-11-21 20:40:59 +00:00
|
|
|
QFileDialog saveFilenameDialog(this);
|
2019-01-29 20:19:05 +00:00
|
|
|
saveFilenameDialog.setAcceptMode(QFileDialog::AcceptSave);
|
2018-11-21 20:40:59 +00:00
|
|
|
saveFilenameDialog.setDefaultSuffix("esgraf48");
|
|
|
|
saveFilenameDialog.setFileMode(QFileDialog::AnyFile);
|
|
|
|
saveFilenameDialog.setNameFilter("ESGRAF 4-8 (*.esgraf48)");
|
|
|
|
saveFilenameDialog.setWindowTitle("Save file");
|
|
|
|
|
|
|
|
if (!saveFilenameDialog.exec())
|
2018-05-20 10:04:21 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-21 20:40:59 +00:00
|
|
|
saveFile(saveFilenameDialog.selectedFiles().first());
|
2018-05-24 09:54:24 +00:00
|
|
|
}
|
|
|
|
|
2018-09-30 09:38:30 +00:00
|
|
|
void MainWindow::closeFile()
|
2018-09-29 11:31:23 +00:00
|
|
|
{
|
2018-09-30 09:38:30 +00:00
|
|
|
if (m_saveOnClose == true)
|
|
|
|
{
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setText("The document has been modified.");
|
|
|
|
msgBox.setInformativeText("Do you want to save your changes?");
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard);
|
|
|
|
msgBox.setDefaultButton(QMessageBox::Save);
|
|
|
|
|
|
|
|
if (msgBox.exec() == QMessageBox::Save)
|
|
|
|
{
|
|
|
|
saveFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-29 11:31:23 +00:00
|
|
|
|
2018-10-29 20:53:52 +00:00
|
|
|
void MainWindow::print() const
|
|
|
|
{
|
|
|
|
QPrinter printer;
|
2019-01-12 15:50:04 +00:00
|
|
|
printer.setPaperSize(QPrinter::A4);
|
2019-01-13 17:44:07 +00:00
|
|
|
printer.setPageMargins(20, 20, 20, 20, QPrinter::Millimeter);
|
2018-10-29 20:53:52 +00:00
|
|
|
|
|
|
|
QPrintDialog dialog(&printer);
|
2018-10-29 21:05:34 +00:00
|
|
|
if (dialog.exec() != QDialog::Accepted)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-12 15:50:04 +00:00
|
|
|
QPainter painter;
|
|
|
|
painter.begin(&printer);
|
2018-10-29 21:05:34 +00:00
|
|
|
|
2019-01-12 15:50:04 +00:00
|
|
|
m_dataModel.printTo(painter);
|
|
|
|
|
|
|
|
painter.end();
|
2018-10-29 20:53:52 +00:00
|
|
|
}
|
|
|
|
|
2018-09-30 09:38:30 +00:00
|
|
|
void MainWindow::dataModelChanged()
|
|
|
|
{
|
2018-09-29 11:31:23 +00:00
|
|
|
m_saveOnClose = true;
|
|
|
|
setWindowModified(true);
|
|
|
|
}
|
|
|
|
|
2018-12-09 10:11:55 +00:00
|
|
|
void MainWindow::savePdf()
|
|
|
|
{
|
|
|
|
QFileDialog saveFilenameDialog(this);
|
|
|
|
saveFilenameDialog.setDefaultSuffix("pdf");
|
|
|
|
saveFilenameDialog.setFileMode(QFileDialog::AnyFile);
|
|
|
|
saveFilenameDialog.setNameFilter("PDF File (*.pdf)");
|
|
|
|
saveFilenameDialog.setWindowTitle("Save file");
|
|
|
|
|
|
|
|
if (!saveFilenameDialog.exec())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
savePdf(saveFilenameDialog.selectedFiles().first());
|
|
|
|
}
|
|
|
|
|
2018-09-29 11:31:23 +00:00
|
|
|
void MainWindow::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
2018-09-30 09:38:30 +00:00
|
|
|
closeFile();
|
2018-09-29 11:31:23 +00:00
|
|
|
}
|
|
|
|
|
2018-05-24 09:54:24 +00:00
|
|
|
void MainWindow::saveFile(const QString &filename)
|
|
|
|
{
|
2019-01-29 19:55:16 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
m_dataModel.write(filename);
|
|
|
|
}
|
|
|
|
catch (std::exception &e)
|
|
|
|
{
|
|
|
|
QString errorMessage = QString("Error saving \"") + filename + "\": " + e.what();
|
|
|
|
QMessageBox::critical(this, "Error", errorMessage);
|
|
|
|
return;
|
|
|
|
}
|
2018-05-20 10:04:21 +00:00
|
|
|
|
2018-09-30 09:38:30 +00:00
|
|
|
qDebug() << "Wrote" << filename;
|
|
|
|
|
2018-09-29 11:31:23 +00:00
|
|
|
setWindowTitle(filename + "[*]");
|
|
|
|
setWindowModified(false);
|
2018-06-25 21:04:32 +00:00
|
|
|
m_filename = filename;
|
2018-09-29 11:31:23 +00:00
|
|
|
m_saveOnClose = false;
|
2018-05-20 10:04:21 +00:00
|
|
|
}
|
2018-12-09 10:11:55 +00:00
|
|
|
|
|
|
|
void MainWindow::savePdf(const QString &filename)
|
|
|
|
{
|
|
|
|
QPrinter printer;
|
|
|
|
printer.setOutputFormat(QPrinter::PdfFormat);
|
|
|
|
printer.setPaperSize(QPrinter::A4);
|
2019-01-13 17:44:07 +00:00
|
|
|
printer.setPageMargins(20, 20, 20, 20, QPrinter::Millimeter);
|
2018-12-09 10:11:55 +00:00
|
|
|
printer.setOutputFileName(filename);
|
|
|
|
|
2019-01-12 15:50:04 +00:00
|
|
|
QPainter painter;
|
|
|
|
painter.begin(&printer);
|
|
|
|
|
|
|
|
m_dataModel.printTo(painter);
|
2018-12-09 10:11:55 +00:00
|
|
|
|
2019-01-12 15:50:04 +00:00
|
|
|
painter.end();
|
2018-12-09 10:11:55 +00:00
|
|
|
}
|
2019-01-30 20:41:03 +00:00
|
|
|
|
|
|
|
void MainWindow::aboutDialog()
|
|
|
|
{
|
|
|
|
QString infoString =
|
|
|
|
QString::fromUtf8(ESGRAF48_DESCRIPTION) + " Version " + QString::fromUtf8(ESGRAF48_VERSION);
|
|
|
|
QMessageBox::information(this, ESGRAF48_DESCRIPTION, infoString);
|
|
|
|
}
|