Salome HOME
Split circle. Remain coincidence with newly created arc (issue #1725)
[modules/shaper.git] / src / ModuleBase / ModuleBase_DoubleSpinBox.cpp
index e436875bf5da34f40345db76ed51fc80857548c2..856c5d1937188755d8ee1070c2859c6f82278465 100644 (file)
@@ -8,6 +8,7 @@
 #include <QLineEdit>
 #include <QDoubleValidator>
 #include <QVariant>
+#include <QKeyEvent>
 
 #include <limits>
 
@@ -58,7 +59,7 @@ 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
   // (to avoid inconsistency of double-2-string and string-2-double conversion)
@@ -77,8 +78,7 @@ 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&)));
-  connect(this, SIGNAL(editingFinished()), this, SLOT(onEditingFinished()));
+  myEnabledBaseColor = palette().color(QPalette::Active, QPalette::Base);
 }
 
 /*!
@@ -200,29 +200,40 @@ QString ModuleBase_DoubleSpinBox::removeTrailingZeroes(const QString& src) const
   return res;
 }
 
-#include <QKeyEvent>
-void ModuleBase_DoubleSpinBox::keyPressEvent(QKeyEvent *theEvent)
+void ModuleBase_DoubleSpinBox::keyPressEvent(QKeyEvent* theEvent)
 {
-  myProcessedEvent = 0;
-
-  bool anIsModified = myIsModified;
+  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: {
-      if (anIsModified)
-        myProcessedEvent = theEvent;
-      /*qDebug("ModuleBase_DoubleSpinBox::keyPressEvent");
-      if (anIsModified) // we should not perform this event outside
-        theEvent->setAccepted(true);
-      else
-        theEvent->setAccepted(false);*/
+      // 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);
 }
 
 /*!
@@ -335,20 +346,22 @@ 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)
+bool ModuleBase_DoubleSpinBox::enableKeyPressEvent(const bool& theEnable)
 {
-  myIsModified = true;
-}
+  bool aPreviousValue = myIsEmitKeyPressEvent;
+  myIsEmitKeyPressEvent = theEnable;
 
-void ModuleBase_DoubleSpinBox::onEditingFinished()
-{
-  myIsModified = false;
+  return aPreviousValue;
 }
 
-bool ModuleBase_DoubleSpinBox::isEventProcessed(QKeyEvent* theEvent)
+void ModuleBase_DoubleSpinBox::setValueEnabled(const bool& theEnable)
 {
-  return myProcessedEvent && myProcessedEvent == theEvent;
+  setReadOnly(!theEnable);
+  
+  QPalette aPal = palette();
+  aPal.setColor(QPalette::All, QPalette::Base,
+                theEnable? myEnabledBaseColor : aPal.color(QPalette::Disabled, QPalette::Base));
+  setPalette(aPal);
 }