X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_DoubleSpinBox.cpp;h=294a2b01f5550678b7a7d4bedf8492b4571d2dcb;hb=745c72679f6346375d5e886b25cc3865f3c4daae;hp=081ca65b3fb12dad6800a131d18cda5e0c95a9c1;hpb=f34fba2433c87ccdf824df0dc8c34099054b1715;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp b/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp index 081ca65b3..294a2b01f 100644 --- a/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp +++ b/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp @@ -1,9 +1,24 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: ModuleBase_DoubleSpinBox.cxx -// Author: Sergey TELKOV +// Copyright (C) 2014-2021 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 @@ -58,17 +73,12 @@ const double PSEUDO_ZERO = 1.e-20; */ ModuleBase_DoubleSpinBox::ModuleBase_DoubleSpinBox(QWidget* theParent, int thePrecision) : QDoubleSpinBox(theParent), - myCleared(false), - myIsModified(false), - myIsEmitKeyPressEvent(false) + 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 @@ -79,7 +89,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&))); + myEnabledBaseColor = palette().color(QPalette::Active, QPalette::Base); } /*! @@ -201,22 +211,6 @@ QString ModuleBase_DoubleSpinBox::removeTrailingZeroes(const QString& src) const return res; } -void ModuleBase_DoubleSpinBox::keyPressEvent(QKeyEvent *theEvent) -{ - 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); -} - /*! \brief Perform \a steps increment/decrement steps. @@ -271,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); @@ -327,28 +323,14 @@ 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) +void ModuleBase_DoubleSpinBox::setValueEnabled(const bool& theEnable) { - bool aPreviousValue = myIsEmitKeyPressEvent; - myIsEmitKeyPressEvent = theEnable; + setReadOnly(!theEnable); - return aPreviousValue; + QPalette aPal = palette(); + aPal.setColor(QPalette::All, QPalette::Base, + theEnable? myEnabledBaseColor : aPal.color(QPalette::Disabled, QPalette::Base)); + setPalette(aPal); }