Salome HOME
Issue #1525: Disable Ok button if parameters are not valid
[modules/shaper.git] / src / ModuleBase / ModuleBase_DoubleSpinBox.cpp
index 081ca65b3fb12dad6800a131d18cda5e0c95a9c1..dba8c5d0f22aec40deef9ddff35ad64c8fd30f56 100644 (file)
@@ -59,7 +59,6 @@ const double PSEUDO_ZERO = 1.e-20;
 ModuleBase_DoubleSpinBox::ModuleBase_DoubleSpinBox(QWidget* theParent, int thePrecision)
     : QDoubleSpinBox(theParent),
       myCleared(false),
-      myIsModified(false),
       myIsEmitKeyPressEvent(false)
 {
   // VSR 01/07/2010: Disable thousands separator for spin box
@@ -78,8 +77,6 @@ ModuleBase_DoubleSpinBox::ModuleBase_DoubleSpinBox(QWidget* theParent, int thePr
 
   connect(lineEdit(), SIGNAL(textChanged( const QString& )), this,
           SLOT(onTextChanged( const QString& )));
-
-  connect(this, SIGNAL(valueChanged(const QString&)), this, SLOT(onValueChanged(const QString&)));
 }
 
 /*!
@@ -201,7 +198,7 @@ QString ModuleBase_DoubleSpinBox::removeTrailingZeroes(const QString& src) const
   return res;
 }
 
-void ModuleBase_DoubleSpinBox::keyPressEvent(QKeyEvent *theEvent)
+void ModuleBase_DoubleSpinBox::keyPressEvent(QKeyEventtheEvent)
 {
   switch (theEvent->key()) {
     case Qt::Key_Enter:
@@ -217,6 +214,26 @@ void ModuleBase_DoubleSpinBox::keyPressEvent(QKeyEvent *theEvent)
   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.
 
@@ -327,22 +344,6 @@ QValidator::State ModuleBase_DoubleSpinBox::validate(QString& str, int& pos) con
 void ModuleBase_DoubleSpinBox::onTextChanged(const QString& )
 {
   myCleared = false;
-  myIsModified = true;
-}
-
-void ModuleBase_DoubleSpinBox::onValueChanged(const QString& theValue)
-{
-  myIsModified = true;
-}
-
-bool ModuleBase_DoubleSpinBox::isModified() const
-{
-  return myIsModified;
-}
-
-void ModuleBase_DoubleSpinBox::clearModified()
-{
-  myIsModified = false;
 }
 
 bool ModuleBase_DoubleSpinBox::enableKeyPressEvent(const bool& theEnable)