]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/XGUI/XGUI_OperationMgr.cpp
Salome HOME
Merge branch 'Dev_2.8.0'
[modules/shaper.git] / src / XGUI / XGUI_OperationMgr.cpp
index 6abe0d130453c1908454cbc1f94cd3cb715357fa..12a9e1bd6affdfe992e3b9e381f8186b78e9caf2 100644 (file)
@@ -90,6 +90,13 @@ public:
       else if (theEvent->type() == QEvent::KeyPress) {
         QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
         myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
+        switch (aKeyEvent->key()) {
+          case Qt::Key_Escape:
+            isAccepted = myOperationMgr->onKeyPressed(theObject, aKeyEvent);
+          break;
+          default:
+            break;
+        }
       }
     }
     if (!isAccepted)
@@ -104,7 +111,7 @@ private:
 
 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent,
                                      ModuleBase_IWorkshop* theWorkshop)
-: QObject(theParent), myWorkshop(theWorkshop), mySHIFTPressed(false)
+: QObject(theParent), myWorkshop(theWorkshop), mySHIFTPressed(false), myActiveMessageBox(0)
 {
   /// we need to install filter to the application in order to react to 'Delete' key button
   /// this key can not be a short cut for a corresponded action because we need to set
@@ -628,14 +635,6 @@ bool XGUI_OperationMgr::onKeyReleased(QObject *theObject, QKeyEvent* theEvent)
   ModuleBase_Operation* anOperation = currentOperation();
   bool isAccepted = false;
   switch (theEvent->key()) {
-    case Qt::Key_Escape: {
-      ModuleBase_Operation* aOperation = currentOperation();
-      if (aOperation) {
-        onAbortOperation();
-        isAccepted = true;
-      }
-    }
-    break;
     case Qt::Key_Tab:
     case Qt::Key_Backtab:
     {
@@ -687,6 +686,38 @@ bool XGUI_OperationMgr::onKeyReleased(QObject *theObject, QKeyEvent* theEvent)
   return isAccepted;
 }
 
+bool XGUI_OperationMgr::onKeyPressed(QObject *theObject, QKeyEvent* theEvent)
+{
+  // Let the manager decide what to do with the given key combination.
+  ModuleBase_Operation* anOperation = currentOperation();
+  bool isAccepted = false;
+  switch (theEvent->key()) {
+    case Qt::Key_Escape: {
+      // processing in message box
+      if (myActiveMessageBox)
+      {
+        myActiveMessageBox->reject();
+        isAccepted = true;
+      }
+      // processing in the active widget
+      ModuleBase_Operation* aOperation = currentOperation();
+      if (!isAccepted && aOperation) {
+        ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+        ModuleBase_ModelWidget* anActiveWgt = aPanel->activeWidget();
+        if (anActiveWgt)
+          isAccepted = anActiveWgt && anActiveWgt->processEscape();
+      }
+      // default Escape button functionality
+      if (!isAccepted && aOperation) {
+        onAbortOperation();
+        isAccepted = true;
+      }
+    }
+    break;
+  }
+  return isAccepted;
+}
+
 bool XGUI_OperationMgr::onProcessEnter(QObject* theObject)
 {
   bool isAccepted = false;
@@ -815,3 +846,14 @@ bool XGUI_OperationMgr::isChildObject(const QObject* theObject, const QObject* t
   }
   return isPPChild;
 }
+
+QMessageBox* XGUI_OperationMgr::createMessageBox(const QString& theMessage)
+{
+  QMessageBox * aMessageBox = new QMessageBox(QMessageBox::Question,
+    QObject::tr("Abort operation"), theMessage, QMessageBox::Ok | QMessageBox::Cancel,
+    qApp->activeWindow());
+  aMessageBox->setDefaultButton(QMessageBox::Cancel);
+  aMessageBox->setEscapeButton(QMessageBox::No); // operation manager should process Esc key
+
+  return aMessageBox;
+}
\ No newline at end of file