Salome HOME
#1189 Tab - Cancel - Enter validate not cancel
authornds <nds@opencascade.com>
Sat, 26 Dec 2015 16:47:21 +0000 (19:47 +0300)
committernds <nds@opencascade.com>
Sat, 26 Dec 2015 16:47:51 +0000 (19:47 +0300)
src/PartSet/PartSet_SketcherReetntrantMgr.cpp
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_PropertyPanel.cpp

index c04847d5f6d09ca996bd9e4f981fddb5f45f5325..d491b9a57caa522a11cc426f09870d4c39e8b535 100755 (executable)
@@ -25,6 +25,8 @@
 #include <XGUI_OperationMgr.h>
 #include <XGUI_PropertyPanel.h>
 
+#include <QToolButton>
+
 PartSet_SketcherReetntrantMgr::PartSet_SketcherReetntrantMgr(ModuleBase_IWorkshop* theWorkshop)
 : QObject(theWorkshop),
   myWorkshop(theWorkshop),
@@ -324,9 +326,18 @@ bool PartSet_SketcherReetntrantMgr::startInternalEdit(const std::string& thePrev
             aPreviousAttributeWidget = aWidgets[i];
         }
         // If the current widget is a selector, do nothing, it processes the mouse press
-        if (aPreviousAttributeWidget && !aPreviousAttributeWidget->isViewerSelector()) {
-          aPreviousAttributeWidget->focusTo();
-          aPreviousAttributeWidget->selectContent();
+        if (aPreviousAttributeWidget) {
+          if (!aPreviousAttributeWidget->isViewerSelector()) {
+            aPreviousAttributeWidget->focusTo();
+            aPreviousAttributeWidget->selectContent();
+          }
+          else {
+            // if there is no the next widget to be automatically activated, the Ok button in property
+            // panel should accept the focus(example is parallel constraint on sketch lines)
+            QToolButton* anOkBtn = aPanel->findChild<QToolButton*>(PROP_PANEL_OK);
+            if (anOkBtn)
+              anOkBtn->setFocus(Qt::TabFocusReason);
+          }
         }
       }
     }
index b8bc93c952ce4f3d3aa9cfbd7efa41b87a8f3502..15f90b947906cb81852dba24da26aa4b28173696 100644 (file)
@@ -22,6 +22,9 @@
 #include "ModelAPI_CompositeFeature.h"
 #include "ModelAPI_Session.h"
 
+#include <XGUI_PropertyPanel.h>
+#include <QToolButton>
+
 #include <QMessageBox>
 #include <QApplication>
 #include <QKeyEvent>
@@ -540,15 +543,26 @@ bool XGUI_OperationMgr::onProcessEnter()
   ModuleBase_Operation* aOperation = currentOperation();
   ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
   ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
-  if (!aActiveWgt || !aActiveWgt->processEnter()) {
-    if (!myWorkshop->module()->processEnter(aActiveWgt ? aActiveWgt->attributeID() : "")) {
-      ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
-      if (!aFOperation || myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty()) {
-        emit keyEnterReleased();
-        commitOperation();
+  bool isAborted = false;
+  if (!aActiveWgt) {
+    QWidget* aFocusWidget = aPanel->focusWidget();
+    QToolButton* aCancelBtn = aPanel->findChild<QToolButton*>(PROP_PANEL_CANCEL);
+    if (aFocusWidget && aCancelBtn && aFocusWidget == aCancelBtn) {
+      abortOperation(aOperation);
+      isAborted = true;
+    }
+  }
+  if (!isAborted) {
+    if (!aActiveWgt || !aActiveWgt->processEnter()) {
+      if (!myWorkshop->module()->processEnter(aActiveWgt ? aActiveWgt->attributeID() : "")) {
+        ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(currentOperation());
+        if (!aFOperation || myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty()) {
+          emit keyEnterReleased();
+          commitOperation();
+        }
+        else
+          isAccepted = false;
       }
-      else
-        isAccepted = false;
     }
   }
   return isAccepted;
index 3e7db245c53121de048ba19dff6925321d67b064..2902755d4ef9dd9e2d2f3160474aa3fcf9524dd7 100755 (executable)
@@ -35,6 +35,8 @@
 #include <iostream>
 #endif
 
+//#define DEBUG_TAB_WIDGETS
+
 XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent, XGUI_OperationMgr* theMgr)
     : ModuleBase_IPropertyPanel(theParent), 
     myActiveWidget(NULL),
@@ -208,17 +210,8 @@ void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget,
     isFoundWidget = isFoundWidget || (*anIt) == theWidget;
   }
   activateWidget(NULL);
-  // if there is no the next widget to be automatically activated, the Ok button in property
-  // panel should accept the focus(example is parallel constraint on sketch lines)
-  QToolButton* anOkBtn = findChild<QToolButton*>(PROP_PANEL_OK);
-  if (anOkBtn)
-    anOkBtn->setFocus(Qt::TabFocusReason);
 }
 
-//#define DEBUG_TAB_WIDGETS
-
-#define DEBUG_TAB
-#ifdef DEBUG_TAB
 void findDirectChildren(QWidget* theParent, QList<QWidget*>& theWidgets, const bool theDebug)
 {
   QList<QWidget*> aWidgets;
@@ -320,65 +313,7 @@ bool XGUI_PropertyPanel::focusNextPrevChild(bool theIsNext)
   }
   return isChangedFocus;
 }
-#else
-bool XGUI_PropertyPanel::focusNextPrevChild(bool theIsNext)
-{
-  // it wraps the Tabs clicking to follow in the chain:
-  // controls, last control, Apply, Cancel, first control, controls
-  bool isChangedFocus = false;
 
-  if (theIsNext) { // forward by Tab
-    QToolButton* aCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
-    if (aCancelBtn->hasFocus()) {
-      // after cancel, the first control should be focused
-      QWidget* aFirstControl = 0;
-      for (int i = 0, aSize = myWidgets.size(); i < aSize && !aFirstControl; i++)
-        aFirstControl = myWidgets[i]->getControlAcceptingFocus(true);
-      if (aFirstControl)
-        ModuleBase_Tools::setFocus(aFirstControl, "XGUI_PropertyPanel::focusNextPrevChild()");
-        isChangedFocus = true;
-    }
-    else {
-      // after the last control, the Apply button should be focused
-      QWidget* aLastControl = 0;
-      for (int i = myWidgets.size()-1; i >= 0 && !aLastControl; i--)
-        aLastControl = myWidgets[i]->getControlAcceptingFocus(false);
-      if (aLastControl && aLastControl->hasFocus()) {
-        setFocusOnOkButton();
-        isChangedFocus = true;
-      }
-    }
-  }
-  else { // backward by SHIFT + Tab
-    QToolButton* anOkBtn = findChild<QToolButton*>(PROP_PANEL_OK);
-    if (anOkBtn->hasFocus()) {
-      // after Apply, the last control should be focused
-      QWidget* aLastControl = 0;
-      for (int i = myWidgets.size()-1; i >= 0 && !aLastControl; i--)
-        aLastControl = myWidgets[i]->getControlAcceptingFocus(false);
-      if (aLastControl)
-        ModuleBase_Tools::setFocus(aLastControl, "XGUI_PropertyPanel::focusNextPrevChild()");
-        isChangedFocus = true;
-    }
-    else {
-      // after the first control, the Cancel button should be focused
-      QWidget* aFirstControl = 0;
-      for (int i = 0, aSize = myWidgets.size(); i < aSize && !aFirstControl; i++)
-        aFirstControl = myWidgets[i]->getControlAcceptingFocus(true);
-      if (aFirstControl && aFirstControl->hasFocus()) {
-        QToolButton* aCancelBtn = findChild<QToolButton*>(PROP_PANEL_CANCEL);
-        ModuleBase_Tools::setFocus(aCancelBtn, "XGUI_PropertyPanel::focusNextPrevChild()");
-        isChangedFocus = true;
-      }
-    }
-  }
-
-  if (!isChangedFocus)
-    isChangedFocus = ModuleBase_IPropertyPanel::focusNextPrevChild(theIsNext);
-  return isChangedFocus;
-}
-
-#endif
 void XGUI_PropertyPanel::activateNextWidget()
 {
   activateNextWidget(myActiveWidget);