Qt4 - volumeSlider: correct the sliders functions and calculus...
authorJean-Baptiste Kempf <jb@videolan.org>
Sun, 9 Sep 2007 21:45:04 +0000 (21:45 +0000)
committerJean-Baptiste Kempf <jb@videolan.org>
Sun, 9 Sep 2007 21:45:04 +0000 (21:45 +0000)
modules/gui/qt4/components/interface_widgets.cpp

index 469249b..7825b34 100644 (file)
@@ -760,38 +760,24 @@ SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
     speedSlider->setMaximumSize( QSize( 80, 200 ) );
     speedSlider->setOrientation( Qt::Vertical );
     speedSlider->setTickPosition( QSlider::TicksRight );
-    speedSlider->setFocusPolicy( Qt::NoFocus );
 
-    speedSlider->setMinimum( -100 );
-    speedSlider->setMaximum( 100 );
+    speedSlider->setRange( -100, 100 );
     speedSlider->setSingleStep( 10 );
     speedSlider->setPageStep( 20 );
     speedSlider->setTickInterval( 20 );
     
     CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
-    
-    //QWidgetAction *wa = new QWidgetAction( this );
-    //wa->setDefaultWidget( playSpeedSlider );
-    //menu.addAction( wa ); 
        
     normalSpeedButton = new QPushButton( "N" );
-    //BUTTON_SET_ACT( revertToNormalButton, "N", qtr( "Normal" ), slower() );
-    //controlLayout->addWidget( revertToNormalButton, 0, 0 );
     normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
-    normalSpeedButton->setFlat(true);
+    normalSpeedButton->setFlat( true );
+    normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
     
     CONNECT( normalSpeedButton, clicked(), this, resetRate() );
     
-    QLabel *volMuteLabel = new QLabel("N");
-    //volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
-    volMuteLabel->setToolTip( qtr( "Revert to normal play speed" ) );
-    //volMuteLabel->installEventFilter( h );
-    
-    
     QVBoxLayout *speedControlLayout = new QVBoxLayout;
        speedControlLayout->addWidget(speedSlider);
        speedControlLayout->addWidget(normalSpeedButton);
-       //speedControlLayout->addWidget(volMuteLabel);
        setLayout(speedControlLayout);
 }
 
@@ -799,12 +785,9 @@ SpeedControlWidget::~SpeedControlWidget()
 {
 }
 
-#define RATE_SLIDER_CONSTANT 3.0
-
-#define SLIDER_MIN_SPEED 1.0 / RATE_SLIDER_CONSTANT
-#define SLIDER_SLOW_RANGE 1.0 - SLIDER_MIN_SPEED
-#define SLIDER_MAX_SPEED RATE_SLIDER_CONSTANT
-#define SLIDER_FAST_RANGE 1.0 - SLIDER_MAX_SPEED
+#define RATE_SLIDER_MAXIMUM 3.0
+#define RATE_SLIDER_MINIMUM 0.3
+#define RATE_SLIDER_LENGTH 100.0
 
 void SpeedControlWidget::updateControls( int rate )
 {
@@ -819,49 +802,48 @@ void SpeedControlWidget::updateControls( int rate )
        
        if( rate >= INPUT_RATE_DEFAULT )
        {               
-               if( speed < SLIDER_MIN_SPEED )
+               if( speed < RATE_SLIDER_MINIMUM )
                {
                        sliderValue = speedSlider->minimum();
                }
                else
                {
-                       double currPos = speed / (double)(SLIDER_SLOW_RANGE);
-                       sliderValue = (int)( currPos * speedSlider->minimum() );
+                       sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH 
+                                        / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
                }
        }
        else
        {
-               if( speed > SLIDER_MAX_SPEED )
+               if( speed > RATE_SLIDER_MAXIMUM )
                {
                        sliderValue = speedSlider->maximum();
                }
                else
                {
-                       double currPos = ( 1.0 - speed ) / (double)(SLIDER_FAST_RANGE);
-                       sliderValue = (int)( currPos * speedSlider->maximum() );
+                       sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
+                                        / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
                }
        }
        
        //Block signals to avoid feedback loop
-       speedSlider->blockSignals(true);
-       speedSlider->setValue(sliderValue);
-       speedSlider->blockSignals(false);
+       speedSlider->blockSignals( true );
+       speedSlider->setValue( sliderValue );
+       speedSlider->blockSignals( false );
 }
 
 void SpeedControlWidget::updateRate( int sliderValue )
 {
        int rate;
-       double var;
        
        if( sliderValue < 0.0 )
        {
-               var = 1.0 + ((-sliderValue/100.0) * RATE_SLIDER_CONSTANT-1.0);
-               rate = INPUT_RATE_DEFAULT * var;
+               rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
+                ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ) ;
        }
        else
        {
-               var = 1.0 + ((sliderValue/100.0) * RATE_SLIDER_CONSTANT-1.0);
-               rate = INPUT_RATE_DEFAULT / var;
+        rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
+                ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
        }
 
     THEMIM->getIM()->setRate(rate);