Salome HOME
Merge branch 'Dev_2.8.0'
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetEditor.cpp
index a9c27367fe427b41fd6a0b0bcc29de33cfaebb79..be60db9d3b503a620ba69118b8e50af10ef2be79 100644 (file)
@@ -36,6 +36,7 @@
 #include <GeomDataAPI_Point2D.h>
 
 #include <QApplication>
+#include <QKeyEvent>
 #include <QLineEdit>
 #include <QMenu>
 #include <QWidget>
 #include <QDialog>
 #include <QLayout>
 
+// Dialog is redefined to avoid Escape key processing
+class ModuleBase_EditorDialog : public QDialog
+{
+public:
+  ModuleBase_EditorDialog(QWidget* theParent, Qt::WindowFlags theFlags)
+    : QDialog(theParent, theFlags) {}
+  ~ModuleBase_EditorDialog() {}
+
+protected:
+  // Do nothing if key pressed because it is processing on operation manager level
+  virtual void keyPressEvent(QKeyEvent* theEvent) {
+    if (theEvent->key() == Qt::Key_Escape)
+        return;
+    QDialog::keyPressEvent(theEvent);
+  }
+};
+
 ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
                                                  const Config_WidgetAPI* theData)
 : ModuleBase_WidgetDoubleValue(theParent, theData),
@@ -62,7 +80,7 @@ bool ModuleBase_WidgetEditor::editedValue(double theSpinMinValue, double theSpin
 {
   bool isValueAccepted = false;
 
-  myEditorDialog = new QDialog(QApplication::desktop(), Qt::FramelessWindowHint);
+  myEditorDialog = new ModuleBase_EditorDialog(QApplication::desktop(), Qt::FramelessWindowHint);
 
   QHBoxLayout* aLay = new QHBoxLayout(myEditorDialog);
   aLay->setContentsMargins(2, 2, 2, 2);
@@ -147,9 +165,9 @@ bool ModuleBase_WidgetEditor::showPopupEditor(const bool theSendSignals)
   }
   ModuleBase_Tools::setFocus(mySpinBox, "ModuleBase_WidgetEditor::editedValue");
   mySpinBox->selectAll();
-
-  if (theSendSignals && !myIsEditing)
-    emit enterClicked(this);
+  // enter is processed, so we need not anymore emit clicked signal
+  //if (theSendSignals && !myIsEditing && isValueAccepted)
+  //  emit enterClicked(this);
 
   return isValueAccepted;
 }
@@ -169,3 +187,13 @@ bool ModuleBase_WidgetEditor::processEnter()
 
   return ModuleBase_WidgetDoubleValue::processEnter();
 }
+
+bool ModuleBase_WidgetEditor::processEscape()
+{
+  if (myEditorDialog) {
+    myEditorDialog->reject();
+    return true;
+  }
+
+  return ModuleBase_WidgetDoubleValue::processEscape();
+}