X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_DoubleSpinBox.cpp;h=7f3b896b68ef62893945117fa8f3e5c8aa4f3e65;hb=63d86e00e1e6a482fcad527ae0b883deccceed11;hp=a8489408dc6bec240b76ccaf602e7552d6523ac5;hpb=db0e21ea2f1117dd9af3320009ba8b50dc2e828b;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp b/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp index a8489408d..7f3b896b6 100644 --- a/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp +++ b/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp @@ -1,13 +1,29 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: ModuleBase_DoubleSpinBox.cxx -// Author: Sergey TELKOV +// Copyright (C) 2014-2020 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 #include #include +#include #include @@ -36,7 +52,7 @@ const double PSEUDO_ZERO = 1.e-20; \endcode Another useful feature is possibility to use scientific notation (e.g. 1.234e+18) - for the widegt text. To enable this, negative precision should be specified either + for the widget text. To enable this, negative precision should be specified either through a constructor or using setPrecision() method. Note that "decimals" property of QDoubleSpinBox is almost completely substituted @@ -59,22 +75,21 @@ ModuleBase_DoubleSpinBox::ModuleBase_DoubleSpinBox(QWidget* theParent, int thePr : QDoubleSpinBox(theParent), myCleared(false) { - // VSR 01/07/2010: Disable thousands separator for spin box - // (to avoid incosistency 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 // it's necessary to set decimals before the range setting, // by default Qt rounds boundaries to 2 decimals at setRange - setDecimals(thePrecision); + setDecimals(qAbs(myPrecision)); connect(lineEdit(), SIGNAL(textChanged( const QString& )), this, SLOT(onTextChanged( const QString& ))); + + myEnabledBaseColor = palette().color(QPalette::Active, QPalette::Base); } /*! @@ -119,8 +134,8 @@ void ModuleBase_DoubleSpinBox::setCleared(const bool on) */ void ModuleBase_DoubleSpinBox::setPrecision(const int prec) { - int newPrec = qMax(prec, 0); - int oldPrec = qMax(myPrecision, 0); + int newPrec = qAbs(prec); + int oldPrec = qAbs(myPrecision); myPrecision = prec; if (newPrec != oldPrec) update(); @@ -128,7 +143,7 @@ void ModuleBase_DoubleSpinBox::setPrecision(const int prec) /*! \brief Get precision value of the spin box - \return current prevision value + \return current precision value \sa setPrecision() */ int ModuleBase_DoubleSpinBox::getPrecision() const @@ -240,6 +255,7 @@ QValidator::State ModuleBase_DoubleSpinBox::validate(QString& str, int& pos) con // Otherwise, expect myPrecision digits after the decimal point. int decs = myPrecision < 0 ? qAbs(myPrecision) - 1 : myPrecision; + v.setLocale(this->locale()); v.setDecimals(decs); v.setBottom(minimum()); v.setTop(maximum()); @@ -249,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); @@ -270,7 +288,7 @@ QValidator::State ModuleBase_DoubleSpinBox::validate(QString& str, int& pos) con } } - // Treat values ouside (min; max) range as Invalid + // Treat values outside (min; max) range as Invalid // This check is enabled by assigning "strict_validity_check" dynamic property // with value "true" to the spin box instance. if (state == QValidator::Intermediate) { @@ -306,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); +}