]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #18929(Tuleap): Make exclusion for processing key events in modal dialog boxes
authorvsv <vsv@opencascade.com>
Tue, 31 Mar 2020 18:27:44 +0000 (21:27 +0300)
committervsv <vsv@opencascade.com>
Tue, 31 Mar 2020 18:27:44 +0000 (21:27 +0300)
src/ModuleBase/ModuleBase_WidgetEditor.cpp
src/XGUI/XGUI_OperationMgr.cpp

index 017298b9634edfee11b217ea3b20aa68250e61f8..9ab66d197284b6c471ef42db6d51ee8d65e640a4 100644 (file)
@@ -53,6 +53,7 @@ public:
   ModuleBase_EditorDialog(QWidget* theParent, Qt::WindowFlags theFlags)
     : QDialog(theParent, theFlags)
   {
+    setObjectName("ModuleBase_EditorDialog");
     setMinimumWidth(100);
   }
   ~ModuleBase_EditorDialog() {}
index c199a2f6880180bed3238c642ad3637e66fe4237..a8813844bfd595d12ce5709f4d49dc082d7258df 100644 (file)
@@ -52,6 +52,7 @@
 #include <QMessageBox>
 #include <QApplication>
 #include <QKeyEvent>
+#include <QWindow>
 
 //#define DEBUG_CURRENT_FEATURE
 
@@ -78,26 +79,37 @@ public:
   virtual bool eventFilter(QObject *theObject, QEvent *theEvent)
   {
     bool isAccepted = false;
-    if (myIsActive && (!qApp->modalWindow())) {
-      if (theEvent->type() == QEvent::KeyRelease) {
-        QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
-        if (aKeyEvent) {
-          myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
-          switch (aKeyEvent->key()) {
+
+    if (myIsActive) {
+      // Do not process keys for modal dialogues: all keys has to be processed within the dialog
+      // There is only one exception: ModuleBase_EditorDialog
+      QWindow* aWnd = qApp->modalWindow();
+      QString aName = "NoModal";
+      if (aWnd) {
+        if (!aWnd->objectName().startsWith("ModuleBase_EditorDialog"))
+          aName = aWnd->objectName();
+      }
+      if (aName == "NoModal") {
+        if (theEvent->type() == QEvent::KeyRelease) {
+          QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
+          if (aKeyEvent) {
+            myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
+            switch (aKeyEvent->key()) {
             case Qt::Key_Delete:
               isAccepted = myOperationMgr->onProcessDelete(theObject);
-            break;
+              break;
             default:
               isAccepted = myOperationMgr->onKeyReleased(theObject, aKeyEvent);
               break;
+            }
           }
         }
-      }
-      else if (theEvent->type() == QEvent::KeyPress) {
-        if (myOperationMgr->hasOperation()) {
-          QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
-          myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
-          isAccepted = myOperationMgr->onKeyPressed(theObject, aKeyEvent);
+        else if (theEvent->type() == QEvent::KeyPress) {
+          if (myOperationMgr->hasOperation()) {
+            QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
+            myOperationMgr->setSHIFTPressed(aKeyEvent->modifiers() & Qt::ShiftModifier);
+            isAccepted = myOperationMgr->onKeyPressed(theObject, aKeyEvent);
+          }
         }
       }
     }