Salome HOME
Merge remote-tracking branch 'remotes/origin/Filters_Development_2'
[modules/shaper.git] / src / ModuleBase / ModuleBase_DoubleSpinBox.cpp
index 080138f5483b0314722ba314cb4c0ed73a4b7a93..6bede9a5cd60595e20081d91c4741a9813d51d23 100644 (file)
@@ -1,13 +1,29 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:      ModuleBase_DoubleSpinBox.cxx
-// Author:    Sergey TELKOV
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 #include "ModuleBase_DoubleSpinBox.h"
+#include "ModuleBase_Tools.h"
 
 #include <QLineEdit>
 #include <QDoubleValidator>
 #include <QVariant>
+#include <QKeyEvent>
 
 #include <limits>
 
@@ -59,13 +75,10 @@ ModuleBase_DoubleSpinBox::ModuleBase_DoubleSpinBox(QWidget* theParent, int thePr
     : QDoubleSpinBox(theParent),
       myCleared(false)
 {
-  // VSR 01/07/2010: Disable thousands separator for spin box
-  // (to avoid inconsistency of double-2-string and string-2-double conversion)
-  QLocale loc;
-  loc.setNumberOptions(loc.numberOptions() | QLocale::OmitGroupSeparator | QLocale::RejectGroupSeparator);
-  setLocale(loc);
+  setLocale(ModuleBase_Tools::doubleLocale());
 
-  // MPV 15/09/2014: this must be set before setDecimals; otherwise in release mode setDecimals may crash
+  // MPV 15/09/2014: this must be set before setDecimals;
+  // otherwise in release mode setDecimals may crash
   myPrecision = thePrecision;
 
   // Use precision equal to default Qt decimals
@@ -75,6 +88,8 @@ ModuleBase_DoubleSpinBox::ModuleBase_DoubleSpinBox(QWidget* theParent, int thePr
 
   connect(lineEdit(), SIGNAL(textChanged( const QString& )), this,
           SLOT(onTextChanged( const QString& )));
+
+  myEnabledBaseColor = palette().color(QPalette::Active, QPalette::Base);
 }
 
 /*!
@@ -250,7 +265,9 @@ QValidator::State ModuleBase_DoubleSpinBox::validate(QString& str, int& pos) con
   if (overhead == 0)
     state = v.validate(str, pos);
   else {
-    if ((uint)(str.length()) >= overhead && str.startsWith(pref) && str.right(suff.length()) == suff) {
+    if ((uint)(str.length()) >= overhead &&
+         str.startsWith(pref) &&
+         str.right(suff.length()) == suff) {
       QString core = str.mid(pref.length(), str.length() - overhead);
       int corePos = pos - pref.length();
       state = v.validate(core, corePos);
@@ -307,3 +324,13 @@ void ModuleBase_DoubleSpinBox::onTextChanged(const QString& )
 {
   myCleared = false;
 }
+
+void ModuleBase_DoubleSpinBox::setValueEnabled(const bool& theEnable)
+{
+  setReadOnly(!theEnable);
+
+  QPalette aPal = palette();
+  aPal.setColor(QPalette::All, QPalette::Base,
+                theEnable? myEnabledBaseColor : aPal.color(QPalette::Disabled, QPalette::Base));
+  setPalette(aPal);
+}