From 4bc6c9e69170f2e4aa9bdcd908fda7027bcae044 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 2 Oct 2015 07:16:56 +0200 Subject: ui: confirm exit if tracking in progress Sponsored-by: TrackHat --- facetracknoir/ui.cpp | 25 ++++++++++++++++++++++++- facetracknoir/ui.h | 2 ++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/facetracknoir/ui.cpp b/facetracknoir/ui.cpp index 15fdd308..eb6cf7e1 100644 --- a/facetracknoir/ui.cpp +++ b/facetracknoir/ui.cpp @@ -93,6 +93,14 @@ MainWindow::MainWindow() : QMessageBox::Ok, QMessageBox::NoButton); } +void MainWindow::closeEvent(QCloseEvent *e) +{ + if (maybe_not_close_tracking()) + e->ignore(); + else + e->accept(); +} + bool MainWindow::get_new_config_name_from_dialog(QString& ret) { new_file_dialog dlg; @@ -410,8 +418,23 @@ void MainWindow::showCurveConfiguration() { mk_window(&mapping_widget, pose, s); } +bool MainWindow::maybe_not_close_tracking() +{ + if (work != nullptr) + { + auto btn = QMessageBox::warning(this, "Tracking active", + "Are you sure you want to exit? This will terminate tracking.", + QMessageBox::Yes, QMessageBox::No); + if (btn == QMessageBox::No) + return true; + } + return false; +} + void MainWindow::exit() { - QCoreApplication::exit(0); + + if (!maybe_not_close_tracking()) + QCoreApplication::exit(0); } void MainWindow::profileSelected(QString name) diff --git a/facetracknoir/ui.h b/facetracknoir/ui.h index 1abd92ff..1b71b7f8 100644 --- a/facetracknoir/ui.h +++ b/facetracknoir/ui.h @@ -66,6 +66,8 @@ class MainWindow : public QMainWindow, private State static bool get_new_config_name_from_dialog(QString &ret); void set_profile(const QString& profile); void maybe_save(); + bool maybe_not_close_tracking(); + void closeEvent(QCloseEvent *e) override; private slots: void _save(); void save(); -- cgit v1.2.3