Salome HOME
Fix for bug 10438: Crash during Explode on Blocks operation (Global selection on...
[modules/gui.git] / src / Qtx / QtxIntSpinBox.cxx
index f94c951aa66aa68fa4d6e227e813c0f911a9426c..70aab81c12407148691b287ef2bb85573284a264 100755 (executable)
@@ -8,14 +8,18 @@
 
 QtxIntSpinBox::QtxIntSpinBox( QWidget* parent, const char* name )
 : QSpinBox( parent, name ),
-myCleared( false )
+myCleared( false ),
+myBlocked( false )
 {
+  connect( editor(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) );
 }
 
 QtxIntSpinBox::QtxIntSpinBox( int min, int max, int step, QWidget* parent, const char* name )
 : QSpinBox( min, max, step, parent, name ),
-myCleared( false )
+myCleared( false ),
+myBlocked( false )
 {
+  connect( editor(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) );
 }
 
 QtxIntSpinBox::~QtxIntSpinBox()
@@ -24,66 +28,90 @@ QtxIntSpinBox::~QtxIntSpinBox()
 
 bool QtxIntSpinBox::isCleared() const
 {
-    return myCleared;
+  return myCleared;
 }
 
 void QtxIntSpinBox::setCleared( const bool on )
 {
-    if ( myCleared == on )
-        return;
+  if ( myCleared == on )
+    return;
     
-    myCleared = on;
-    updateDisplay();
+  myCleared = on;
+  updateDisplay();
 }
 
 void QtxIntSpinBox::setValue( int value )
 {
-    myCleared = false;
-    QSpinBox::setValue( value );
+  myCleared = false;
+
+  QSpinBox::setValue( value );
 }
 
 bool QtxIntSpinBox::eventFilter( QObject* o, QEvent* e )
 {
-    if ( !myCleared || o != editor() || !editor()->text().stripWhiteSpace().isEmpty() )
-        return QSpinBox::eventFilter( o, e );
+  if ( !myCleared || o != editor() || !editor()->text().stripWhiteSpace().isEmpty() )
+    return QSpinBox::eventFilter( o, e );
 
-    if ( e->type() == QEvent::FocusOut || e->type() == QEvent::Leave || e->type() == QEvent::Hide )
-        return false;
+  if ( e->type() == QEvent::FocusOut || e->type() == QEvent::Leave || e->type() == QEvent::Hide )
+    return false;
 
-    if ( e->type() == QEvent::KeyPress &&
+  if ( e->type() == QEvent::KeyPress &&
             ( ((QKeyEvent*)e)->key() == Key_Tab || ((QKeyEvent*)e)->key() == Key_BackTab ) )
-    {
-        QApplication::sendEvent( this, e );
-        return true;
-    }
+  {
+    QApplication::sendEvent( this, e );
+    return true;
+  }
 
-    return QSpinBox::eventFilter( o, e );
+  return QSpinBox::eventFilter( o, e );
 }
 
 void QtxIntSpinBox::interpretText()
 {
-    myCleared = false;
-    QSpinBox::interpretText();
+  myCleared = false;
+
+  QSpinBox::interpretText();
 }
 
 void QtxIntSpinBox::updateDisplay()
 {
-    QSpinBox::updateDisplay();
-    if ( myCleared )
-        editor()->clear();
+  if ( myBlocked )
+    return;
+
+  bool block = myBlocked;
+  myBlocked = true;
+
+  QSpinBox::updateDisplay();
+
+  if ( myCleared )
+    editor()->clear();
+  else if ( editor()->hasFocus() )
+  {
+    if ( editor()->text() == specialValueText() )
+      editor()->selectAll();
+    else
+      editor()->setSelection( prefix().length(), editor()->text().length() - prefix().length() - suffix().length() );
+  }
+
+  myBlocked = block;
 }
 
 void QtxIntSpinBox::leaveEvent( QEvent* e )
 {
-    if ( !myCleared )
-        QSpinBox::leaveEvent( e );
+  if ( !myCleared )
+    QSpinBox::leaveEvent( e );
 }
 
 void QtxIntSpinBox::wheelEvent( QWheelEvent* e )
 {
-    if ( !isEnabled() )
-        return;
+  if ( !isEnabled() )
+    return;
 
-    QSpinBox::wheelEvent( e );
-    updateDisplay();
+  QSpinBox::wheelEvent( e );
+  updateDisplay();
+}
+
+void QtxIntSpinBox::onTextChanged( const QString& )
+{
+  if ( !myBlocked )
+    myCleared = false;
 }