+// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA 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.
+//
+// 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/
+//
// File: QtxDblSpinBox.cxx
// Author: Sergey TELKOV
setValidator( new Validator( this, "double_spinbox_validator" ) );
rangeChange();
updateDisplay();
+
+ connect( editor(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) );
}
QtxDblSpinBox::QtxDblSpinBox( double min, double max, double step, QWidget* parent, const char* name )
setValidator( new Validator( this, "double_spinbox_validator" ) );
rangeChange();
updateDisplay();
+
+ connect( editor(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) );
}
QtxDblSpinBox::~QtxDblSpinBox()
double QtxDblSpinBox::value() const
{
+ QSpinBox::value();
+
return myValue;
}
{
if ( myBlocked )
return;
-
+
+ bool upd = editor()->isUpdatesEnabled();
+ editor()->setUpdatesEnabled( false );
+
bool isBlock = myBlocked;
myBlocked = true;
QSpinBox::setValue( QSpinBox::minValue() );
else
QSpinBox::setValue( ( QSpinBox::minValue() + QSpinBox::maxValue() ) / 2 );
-
+
QSpinBox::updateDisplay();
-
+
+ editor()->setUpdatesEnabled( upd );
+
editor()->setText( myCleared ? QString::null : txt );
-
+ if ( !myCleared && editor()->hasFocus() )
+ {
+ if ( editor()->text() == specialValueText() )
+ editor()->selectAll();
+ else
+ editor()->setSelection( prefix().length(), editor()->text().length() - prefix().length() - suffix().length() );
+ }
+
myBlocked = isBlock;
}
void QtxDblSpinBox::valueChange()
{
updateDisplay();
- emit valueChanged( value() );
+ emit valueChanged( myValue );
emit valueChanged( currentValueText() );
}
QString QtxDblSpinBox::mapValueToText( double v )
{
QString s;
- s.setNum( v, myPrecision < 0 ? 'f' : 'g', myPrecision == 0 ? 6 : QABS( myPrecision ) );
- return s;
+ s.setNum( v, myPrecision >= 0 ? 'f' : 'g', myPrecision == 0 ? 6 : QABS( myPrecision ) );
+ return removeTrailingZeroes( s );
}
QString QtxDblSpinBox::mapValueToText( int )
{
QString s;
- s.setNum( myValue, myPrecision < 0 ? 'f' : 'g', myPrecision == 0 ? 6 : QABS( myPrecision ) );
- return s;
+ s.setNum( myValue, myPrecision >= 0 ? 'f' : 'g', myPrecision == 0 ? 6 : QABS( myPrecision ) );
+ return removeTrailingZeroes( s );
}
double QtxDblSpinBox::mapTextToDoubleValue( bool* ok )
QSpinBox::wheelEvent( e );
updateDisplay();
}
+
+void QtxDblSpinBox::onTextChanged( const QString& str )
+{
+ if ( !myBlocked )
+ myCleared = false;
+}
+
+QString QtxDblSpinBox::removeTrailingZeroes( const QString& src ) const
+{
+ QString delim( "." );
+
+ int idx = src.findRev( delim );
+ if ( idx == -1 )
+ return src;
+
+ QString iPart = src.left( idx );
+ QString fPart = src.mid( idx + 1 );
+
+ while ( !fPart.isEmpty() && fPart.at( fPart.length() - 1 ) == '0' )
+ fPart.remove( fPart.length() - 1, 1 );
+
+ QString res = iPart;
+ if ( !fPart.isEmpty() )
+ res += delim + fPart;
+
+ return res;
+}