From 88b2abea2c66eabdb32af017fb15cc90643e7664 Mon Sep 17 00:00:00 2001 From: sbh Date: Fri, 23 May 2014 09:03:04 +0400 Subject: [PATCH] Handle Alt+F4 as regular exit action. Do not exit on exit->save->cancel. Fixes #43 --- src/XGUI/XGUI_MainWindow.cpp | 9 ++++++++- src/XGUI/XGUI_MainWindow.h | 7 +++++++ src/XGUI/XGUI_Workshop.cpp | 23 ++++++++++++++--------- src/XGUI/XGUI_Workshop.h | 4 ++-- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/XGUI/XGUI_MainWindow.cpp b/src/XGUI/XGUI_MainWindow.cpp index 4b8c9e091..1400fc0cc 100644 --- a/src/XGUI/XGUI_MainWindow.cpp +++ b/src/XGUI/XGUI_MainWindow.cpp @@ -14,6 +14,7 @@ #include #include #include +#include XGUI_MainWindow::XGUI_MainWindow(QWidget* parent) : QMainWindow(parent), @@ -197,4 +198,10 @@ void XGUI_MainWindow::onViewActivated(QMdiSubWindow* theSubWnd) if (aAct->isCheckable()) aAct->setChecked(aAct->text() == aWndTitle); } -} \ No newline at end of file +} + +void XGUI_MainWindow::closeEvent(QCloseEvent * event) +{ + emit exitKeySequence(); + event->ignore(); +} diff --git a/src/XGUI/XGUI_MainWindow.h b/src/XGUI/XGUI_MainWindow.h index 9b29ec3ea..010f9e309 100644 --- a/src/XGUI/XGUI_MainWindow.h +++ b/src/XGUI/XGUI_MainWindow.h @@ -11,6 +11,7 @@ class XGUI_ViewWindow; class QMdiArea; class QMdiSubWindow; class PyConsole_EnhConsole; +class QCloseEvent; /**\class XGUI_MainWindow * \ingroup GUI @@ -53,6 +54,12 @@ private slots: void activateView(); void onViewActivated(QMdiSubWindow* theSubWnd); +signals: + void exitKeySequence(); + +protected: + void closeEvent(QCloseEvent* event); + private: XGUI_MainMenu* myMenuBar; XGUI_Viewer* myViewer; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 14a965db7..08713ee47 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -95,6 +95,7 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) connect(myOperationMgr, SIGNAL(operationStarted()), SLOT(onOperationStarted())); connect(myOperationMgr, SIGNAL(operationResumed()), SLOT(onOperationStarted())); connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), SLOT(onOperationStopped(ModuleBase_Operation*))); + connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit())); connect(myOperationMgr, SIGNAL(operationStarted()), myActionsMgr, SLOT(update())); connect(myOperationMgr, SIGNAL(operationStopped()), myActionsMgr, SLOT(update())); connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&))); @@ -411,7 +412,10 @@ void XGUI_Workshop::onExit() tr("The document is modified, save before exit?"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel); if(anAnswer == QMessageBox::Save) { - onSave(); + bool saved = onSave(); + if(!saved) { + return; + } } else if (anAnswer == QMessageBox::Cancel) { return; } @@ -476,18 +480,18 @@ void XGUI_Workshop::onOpen() } //****************************************************** -void XGUI_Workshop::onSave() +bool XGUI_Workshop::onSave() { if(myCurrentDir.isEmpty()) { - onSaveAs(); - return; + return onSaveAs(); } saveDocument(myCurrentDir); updateCommandStatus(); + return true; } //****************************************************** -void XGUI_Workshop::onSaveAs() +bool XGUI_Workshop::onSaveAs() { QFileDialog dialog(mainWindow()); dialog.setWindowTitle(tr("Select directory to save files...")); @@ -497,7 +501,7 @@ void XGUI_Workshop::onSaveAs() dialog.setViewMode(QFileDialog::Detail); if(!dialog.exec()) { - return; + return false; } QString aTempDir = dialog.selectedFiles().first(); QDir aDir(aTempDir); @@ -506,11 +510,12 @@ void XGUI_Workshop::onSaveAs() QString(), tr("The folder already contains some files, save anyway?"), QMessageBox::Save|QMessageBox::Cancel); - if(answer == QMessageBox::Cancel) - return; + if(answer == QMessageBox::Cancel) { + return false; + } } myCurrentDir = aTempDir; - onSave(); + return onSave(); } //****************************************************** diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 8ffb703b8..42d893f1d 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -113,8 +113,8 @@ public slots: void onNew(); void onOpen(); - void onSave(); - void onSaveAs(); + bool onSave(); + bool onSaveAs(); void onExit(); void onUndo(); void onRedo(); -- 2.39.2