#include "numberator.h" #include "ui_numberator.h" #include "ui_TagListDock.h" #include Numberator::Numberator(QWidget *parent) : QMainWindow(parent) , ui(new Ui::Numberator) , tagsDockUi(new Ui::TagListDock) , settings("jaseg.de", "Numberator") , loadImageDialog(this) , proj() , tagListModel(proj) , tagPropTableModel(proj) { ui->setupUi(this); connect(&proj, &SQLiteSaveFile::fileIOError, [=](auto e, QString errorName, QString description) { Q_UNUSED(e); qDebug() << errorName << ": " << description; QMessageBox::critical(this, errorName, description); }); QDockWidget *dock = new QDockWidget(this); tagsDockUi->setupUi(dock); addDockWidget(Qt::LeftDockWidgetArea, dock); ui->menuView->addAction(dock->toggleViewAction()); connect(ui->actionReload_Image, &QAction::triggered, &proj, &SQLiteSaveFile::reloadImageFromDisk); ui->graphicsView->setProject(&proj); tagsDockUi->tagList->setModel(&tagListModel); tagsDockUi->propertyTable->setModel(&tagPropTableModel); loadImageDialog.setWindowModality(Qt::ApplicationModal); loadImageDialog.setWindowTitle("Load Image..."); loadImageDialog.setNameFilter("Images (*.png, *.xpm, *.jpg)"); loadImageDialog.setFileMode(QFileDialog::ExistingFile); loadImageDialog.restoreState(settings.value("MainWindow/LoadImageFileDialogState").toByteArray()); connect(&loadImageDialog, &QFileDialog::accepted, [=]() { settings.setValue("MainWindow/LoadImageFileDialogState", this->loadImageDialog.saveState()); }); connect(&loadImageDialog, &QFileDialog::fileSelected, &proj, &SQLiteSaveFile::loadImageFromDisk); connect(ui->actionImport_Image, &QAction::triggered, [=](bool checked){ Q_UNUSED(checked); this->loadImageDialog.open(); }); saveOpenDialog.setWindowModality(Qt::ApplicationModal); saveOpenDialog.setNameFilter("Project Files (*.npr);;Any File (*)"); saveOpenDialog.setFileMode(QFileDialog::AnyFile); saveOpenDialog.restoreState(settings.value("MainWindow/SaveAsFileDialogState").toByteArray()); connect(&saveOpenDialog, &QFileDialog::accepted, [=]() { settings.setValue("MainWindow/SaveAsFileDialogState", this->saveOpenDialog.saveState()); }); connect(ui->actionSave_Project, &QAction::triggered, this, &Numberator::showSaveDialog); connect(ui->actionOpen_Project, &QAction::triggered, [=](){ if (!showConfirmDiscardDialog()) return; saveOpenDialog.setWindowTitle("Open Project..."); saveOpenDialog.setAcceptMode(QFileDialog::AcceptOpen); if (saveOpenDialog.exec() == QDialog::Accepted) proj.open(saveOpenDialog.selectedFiles().value(0)); }); connect(ui->actionNew_Project, &QAction::triggered, [=]() { if (!showConfirmDiscardDialog()) return; proj.clearNew(); }); connect(ui->actionQuit, &QAction::triggered, [=]() { if (!showConfirmDiscardDialog()) return; QApplication::quit(); }); connect(ui->actionAbout, &QAction::triggered, &aboutDialog, &AboutDialog::open); connect(tagsDockUi->tagList->selectionModel(), &QItemSelectionModel::selectionChanged, [=](const QItemSelection &selected, const QItemSelection &deselected) { Q_UNUSED(deselected); tagPropTableModel.showTag(tagListModel.getTag(selected.indexes().first())); }); connect(ui->actionZoom_to_fit, &QAction::triggered, ui->graphicsView, &TagView::zoomToFit); connect(ui->actionZoom_in, &QAction::triggered, ui->graphicsView, &TagView::zoomIn); connect(ui->actionZoom_out, &QAction::triggered, ui->graphicsView, &TagView::zoomOut); } Numberator::~Numberator() { delete ui; } bool Numberator::showConfirmDiscardDialog() { if (!proj.isMemory() || !proj.isDirty()) return true; auto btn = QMessageBox::warning(this, "Discard unsaved changes?", "This document contains unsaved changes. Do you want to save these changes?", QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); if (btn == QMessageBox::Cancel) return false; if (btn == QMessageBox::Save) return showSaveDialog(); /* else, the discard button was clicked */ return true; } bool Numberator::showSaveDialog() { saveOpenDialog.setWindowTitle("Save Project as..."); saveOpenDialog.setAcceptMode(QFileDialog::AcceptSave); if (saveOpenDialog.exec() == QDialog::Accepted) { QString fn = this->saveOpenDialog.selectedFiles().value(0); qDebug() << QString("Calling saveas(%1)").arg(fn); return proj.saveAs(fn); } return false; }