Salome HOME
A regression correction for the following case:
[modules/shaper.git] / src / ModuleBase / ModuleBase_DoubleSpinBox.cpp
index 080138f5483b0314722ba314cb4c0ed73a4b7a93..dba8c5d0f22aec40deef9ddff35ad64c8fd30f56 100644 (file)
@@ -8,6 +8,7 @@
 #include <QLineEdit>
 #include <QDoubleValidator>
 #include <QVariant>
+#include <QKeyEvent>
 
 #include <limits>
 
@@ -57,7 +58,8 @@ const double PSEUDO_ZERO = 1.e-20;
  */
 ModuleBase_DoubleSpinBox::ModuleBase_DoubleSpinBox(QWidget* theParent, int thePrecision)
     : QDoubleSpinBox(theParent),
-      myCleared(false)
+      myCleared(false),
+      myIsEmitKeyPressEvent(false)
 {
   // VSR 01/07/2010: Disable thousands separator for spin box
   // (to avoid inconsistency of double-2-string and string-2-double conversion)
@@ -196,6 +198,42 @@ QString ModuleBase_DoubleSpinBox::removeTrailingZeroes(const QString& src) const
   return res;
 }
 
+void ModuleBase_DoubleSpinBox::keyPressEvent(QKeyEvent* theEvent)
+{
+  switch (theEvent->key()) {
+    case Qt::Key_Enter:
+    case Qt::Key_Return: {
+      // do not react to the Enter key, the property panel processes it
+      if (!myIsEmitKeyPressEvent)
+        return;
+    }
+    break;
+    default:
+      break;
+  }
+  QDoubleSpinBox::keyPressEvent(theEvent);
+}
+
+void ModuleBase_DoubleSpinBox::keyReleaseEvent(QKeyEvent* theEvent)
+{
+  switch (theEvent->key()) {
+    case Qt::Key_Enter:
+    case Qt::Key_Return: {
+      // the enter has already been processed when key is pressed,
+      // key release should not be processed in operation manager
+      if (myIsEmitKeyPressEvent) {
+        theEvent->accept();
+        emit enterReleased();
+        return;
+      }
+    }
+    break;
+    default:
+      break;
+  }
+  QDoubleSpinBox::keyReleaseEvent(theEvent);
+}
+
 /*!
  \brief Perform \a steps increment/decrement steps.
 
@@ -307,3 +345,11 @@ void ModuleBase_DoubleSpinBox::onTextChanged(const QString& )
 {
   myCleared = false;
 }
+
+bool ModuleBase_DoubleSpinBox::enableKeyPressEvent(const bool& theEnable)
+{
+  bool aPreviousValue = myIsEmitKeyPressEvent;
+  myIsEmitKeyPressEvent = theEnable;
+
+  return aPreviousValue;
+}