Salome HOME
Merge branch 'Dev_0.6' of newgeom:newgeom into Dev_0.6
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetDoubleValue.cpp
index 692c949042868d2433ff502cc6d84177c21f347e..7400d7f7d48db95bc329456d6a75aa6c7a567282 100644 (file)
@@ -3,6 +3,8 @@
 // Author:      Vitaly Smetannikov
 
 #include <ModuleBase_WidgetDoubleValue.h>
+#include <ModuleBase_DoubleSpinBox.h>
+#include <ModuleBase_Tools.h>
 
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Data.h>
 #include <QWidget>
 #include <QLayout>
 #include <QLabel>
-#include <QDoubleSpinBox>
 #include <QEvent>
-#include <QKeyEvent>
+#include <QTimer>
+
+#include <math.h>
 
 #ifndef DBL_MAX
 #define DBL_MAX 1.7976931348623158e+308 
 #endif
+#ifdef _DEBUG
+#include <iostream>
+#endif
 
 ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent,
                                                            const Config_WidgetAPI* theData,
@@ -31,7 +37,7 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent,
 {
   myContainer = new QWidget(theParent);
   QHBoxLayout* aControlLay = new QHBoxLayout(myContainer);
-  aControlLay->setContentsMargins(0, 0, 0, 0);
+  ModuleBase_Tools::adjustMargins(aControlLay);
 
   QString aLabelText = QString::fromStdString(theData->widgetLabel());
   QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
@@ -40,7 +46,7 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent,
     myLabel->setPixmap(QPixmap(aLabelIcon));
   aControlLay->addWidget(myLabel);
 
-  mySpinBox = new QDoubleSpinBox(myContainer);
+  mySpinBox = new ModuleBase_DoubleSpinBox(myContainer);
   QString anObjName = QString::fromStdString(attributeID());
   mySpinBox->setObjectName(anObjName);
 
@@ -64,10 +70,14 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent,
   aProp = theData->getProperty(DOUBLE_WDG_STEP);
   double aStepVal = QString::fromStdString(aProp).toDouble(&isOk);
   if (isOk) {
+    double aMinStep = pow(10, -1. * (double) mySpinBox->decimals());
+    if(aStepVal < aMinStep){
+      aStepVal = aMinStep;
+    }
     mySpinBox->setSingleStep(aStepVal);
   }
 
-  aProp = theData->getProperty(DOUBLE_WDG_DEFAULT);
+  aProp = theData->getProperty(ANY_WDG_DEFAULT);
   double aDefVal = QString::fromStdString(aProp).toDouble(&isOk);
   if (isOk) {
     mySpinBox->setValue(aDefVal);
@@ -82,8 +92,6 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent,
   aControlLay->setStretch(1, 1);
 
   connect(mySpinBox, SIGNAL(valueChanged(double)), this, SIGNAL(valuesChanged()));
-
-  mySpinBox->installEventFilter(this);
 }
 
 ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue()
@@ -114,23 +122,6 @@ bool ModuleBase_WidgetDoubleValue::restoreValue()
 QList<QWidget*> ModuleBase_WidgetDoubleValue::getControls() const
 {
   QList<QWidget*> aList;
-  aList.append(myLabel);
   aList.append(mySpinBox);
   return aList;
 }
-
-bool ModuleBase_WidgetDoubleValue::eventFilter(QObject *theObject, QEvent *theEvent)
-{
-  if (theObject == mySpinBox) {
-    if (theEvent->type() == QEvent::KeyRelease) {
-      QKeyEvent* aKeyEvent = (QKeyEvent*) theEvent;
-      if (aKeyEvent && (aKeyEvent->key() == Qt::Key_Return ||
-                        aKeyEvent->key() == Qt::Key_Enter)) {
-        emit focusOutWidget(this);
-      }
-      emit keyReleased((QKeyEvent*) theEvent);
-      return true;
-    }
-  }
-  return ModuleBase_ModelWidget::eventFilter(theObject, theEvent);
-}