diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 8cdc60193..0c6691a06 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include "divelistview.h" #include "starwidget.h" @@ -31,6 +33,7 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()), ui->ListWidget->setModel(sortModel); setWindowIcon(QIcon(":subsurface-icon")); + readSettings(); } void MainWindow::on_actionNew_triggered() @@ -138,6 +141,11 @@ void MainWindow::on_actionPreferences_triggered() void MainWindow::on_actionQuit_triggered() { qDebug("actionQuit"); + if (unsaved_changes() && (askSaveChanges() == FALSE)) + { + return; + } + } void MainWindow::on_actionDownloadDC_triggered() @@ -284,3 +292,32 @@ bool MainWindow::askSaveChanges() } return false; } + +void MainWindow::readSettings() +{ + QSettings settings("hohndel.org","subsurface"); + + /* note: section/key i.e. forward slash to separate */ + QSize sz = settings.value("MainWindow/size").value(); + resize(sz); +} + +void MainWindow::writeSettings() +{ + QSettings settings("hohndel.org","subsurface"); + settings.beginGroup("MainWindow"); + settings.setValue("size",size()); + settings.endGroup(); + /* other groups here; avoid '/' and '\' in keys with setValue(...) please */ +} + +void MainWindow::closeEvent(QCloseEvent *event) +{ + if (unsaved_changes() && (askSaveChanges() == FALSE)) + { + event->ignore(); + return; + } + event->accept(); + writeSettings(); +} \ No newline at end of file diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index fdb100c7a..eece91ade 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -66,12 +66,17 @@ private Q_SLOTS: void on_actionAboutSubsurface_triggered(); void on_actionUserManual_triggered(); +protected: + void closeEvent(QCloseEvent *); + private: Ui::MainWindow *ui; DiveTripModel *model; QSortFilterProxyModel *sortModel; QString filter(); bool askSaveChanges(); + void readSettings(); + void writeSettings(); };