00001 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE 00002 // 00003 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, 00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 00005 // 00006 // This library is free software; you can redistribute it and/or 00007 // modify it under the terms of the GNU Lesser General Public 00008 // License as published by the Free Software Foundation; either 00009 // version 2.1 of the License. 00010 // 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // Lesser General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public 00017 // License along with this library; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 // 00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com 00021 // 00022 00023 // SMESH SMESHGUI : GUI for SMESH component 00024 // File : SMESHGUI_SpinBox.cxx 00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S. 00026 // SMESH includes 00027 // 00028 #include "SMESHGUI_SpinBox.h" 00029 00030 #include <SUIT_Session.h> 00031 #include <SUIT_ResourceMgr.h> 00032 00033 // Qt includes 00034 #include <QLineEdit> 00035 #include <QVariant> 00036 00037 //================================================================================= 00038 // class : SMESHGUI_SpinBox() 00039 // purpose : constructor of specific widget accepting floats in double precision. 00040 //================================================================================= 00041 SMESHGUI_SpinBox::SMESHGUI_SpinBox( QWidget* parent ) 00042 : SalomeApp_DoubleSpinBox( parent ) 00043 { 00044 } 00045 00046 //================================================================================= 00047 // function : ~SMESHGUI_SpinBox() 00048 // purpose : destructor 00049 //================================================================================= 00050 SMESHGUI_SpinBox::~SMESHGUI_SpinBox() 00051 { 00052 } 00053 00054 //================================================================================= 00055 // function : SetStep() [SLOT] 00056 // purpose : 00057 //================================================================================= 00058 void SMESHGUI_SpinBox::SetStep( double newStep ) 00059 { 00060 setSingleStep( newStep ); 00061 } 00062 00063 //================================================================================= 00064 // function : SetValue() 00065 // purpose : 00066 //================================================================================= 00067 void SMESHGUI_SpinBox::SetValue( double v ) 00068 { 00069 setValue(valueFromText(textFromValue(v))); 00070 editor()->setCursorPosition( 0 ); 00071 } 00072 00073 //================================================================================= 00074 // function : GetValue() 00075 // purpose : returns a double 00076 //================================================================================= 00077 double SMESHGUI_SpinBox::GetValue() const 00078 { 00079 return value(); 00080 } 00081 00082 //================================================================================= 00083 // function : GetString() 00084 // purpose : returns a QString 00085 //================================================================================= 00086 QString SMESHGUI_SpinBox::GetString() const 00087 { 00088 return cleanText(); 00089 } 00090 00091 //================================================================================= 00092 // function : editor() 00093 // purpose : returns editor 00094 //================================================================================= 00095 QLineEdit* SMESHGUI_SpinBox::editor() const 00096 { 00097 return SalomeApp_DoubleSpinBox::lineEdit(); 00098 } 00099 00100 //================================================================================= 00101 // function : RangeStepAndValidator() 00102 // purpose : 00103 //================================================================================= 00104 void SMESHGUI_SpinBox::RangeStepAndValidator( double min, 00105 double max, 00106 double step, 00107 const char* quantity ) 00108 { 00109 // Obtain precision from preferences 00110 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); 00111 int precision = resMgr->integerValue( "SMESH", quantity, -3 ); 00112 00113 setPrecision(precision); // PAL8769. Minus is for using 'g' double->string conversion specifier, 00114 // see QtxDoubleSpinBox::mapValueToText( double v ) 00115 // san: this can be achieved using preferences 00116 setDecimals( 20 ); // qAbs(precision) 00117 setRange(min, max); 00118 setSingleStep( step ); 00119 setDefaultValue( min ); 00120 00121 // Add a hint for the user saying how to tune precision 00122 QString userPropName = QObject::tr( QString( "SMESH_PREF_%1" ).arg( quantity ).toLatin1().constData() ); 00123 setProperty( "validity_tune_hint", 00124 QVariant( QObject::tr( "SMESH_PRECISION_HINT" ).arg( userPropName ) ) ); 00125 }