]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/interface_widgets.cpp
Logarithmic slider for speed.
[vlc] / modules / gui / qt4 / components / interface_widgets.cpp
index 66cafb173960718c8a2dbeb3e5b1107777ddff7b..c53d8fbe876ce152f91a278af049f434bbf6967f 100644 (file)
@@ -52,6 +52,8 @@
 # include <qx11info_x11.h>
 #endif
 
+#include <math.h>
+
 /**********************************************************************
  * Video Widget. A simple frame on which video is drawn
  * This class handles resize issues
@@ -60,7 +62,7 @@
 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
 {
     /* Init */
-    p_vout = NULL;
+    i_vout = 0;
     hide(); setMinimumSize( 16, 16 );
     videoSize.rwidth() = -1;
     videoSize.rheight() = -1;
@@ -97,6 +99,9 @@ void VideoWidget::paintEvent(QPaintEvent *ev)
 
 VideoWidget::~VideoWidget()
 {
+    vout_thread_t *p_vout = i_vout
+        ? (vout_thread_t *)vlc_object_get( i_vout ) : NULL;
+
     if( p_vout )
     {
         if( !p_intf->psz_switch_intf )
@@ -109,6 +114,7 @@ VideoWidget::~VideoWidget()
             if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
                 vout_Control( p_vout, VOUT_CLOSE );
         }
+        vlc_object_release( p_vout );
     }
 }
 
@@ -120,12 +126,12 @@ void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
 {
     msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
     emit askVideoWidgetToShow( *pi_width, *pi_height );
-    if( p_vout )
+    if( i_vout )
     {
         msg_Dbg( p_intf, "embedded video already in use" );
         return NULL;
     }
-    p_vout = p_nvout;
+    i_vout = p_nvout->i_object_id;
     msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );
     return ( void* )winId();
 }
@@ -145,7 +151,7 @@ void VideoWidget::SetSizing( unsigned int w, unsigned int h )
 void VideoWidget::release( void *p_win )
 {
     msg_Dbg( p_intf, "Video is not needed anymore" );
-    p_vout = NULL;
+    i_vout = 0;
     videoSize.rwidth() = 0;
     videoSize.rheight() = 0;
     hide();
@@ -169,7 +175,7 @@ BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
                  :QWidget( NULL ), p_intf( _p_i )
 {
     /* We should use that one to take the more size it can */
-//    setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
+    setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding);
 
     /* A dark background */
     setAutoFillBackground( true );
@@ -1207,22 +1213,24 @@ SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
     speedSlider->setOrientation( Qt::Vertical );
     speedSlider->setTickPosition( QSlider::TicksRight );
 
-    speedSlider->setRange( -100, 100 );
-    speedSlider->setSingleStep( 10 );
-    speedSlider->setPageStep( 20 );
-    speedSlider->setTickInterval( 20 );
+    speedSlider->setRange( -24, 24 );
+    speedSlider->setSingleStep( 1 );
+    speedSlider->setPageStep( 1 );
+    speedSlider->setTickInterval( 12 );
 
     CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
 
     QToolButton *normalSpeedButton = new QToolButton( this );
     normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
     normalSpeedButton->setAutoRaise( true );
-    normalSpeedButton->setText( "N" );
+    normalSpeedButton->setText( "1x" );
     normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
 
     CONNECT( normalSpeedButton, clicked(), this, resetRate() );
 
     QVBoxLayout *speedControlLayout = new QVBoxLayout;
+    speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
+    speedControlLayout->setSpacing( 4 );
     speedControlLayout->addWidget( speedSlider );
     speedControlLayout->addWidget( normalSpeedButton );
     setLayout( speedControlLayout );
@@ -1236,10 +1244,6 @@ void SpeedControlWidget::setEnable( bool b_enable )
     speedSlider->setEnabled( b_enable );
 }
 
-#define RATE_SLIDER_MAXIMUM 3.0
-#define RATE_SLIDER_MINIMUM 0.3
-#define RATE_SLIDER_LENGTH 100.0
-
 void SpeedControlWidget::updateControls( int rate )
 {
     if( speedSlider->isSliderDown() )
@@ -1248,32 +1252,16 @@ void SpeedControlWidget::updateControls( int rate )
         return;
     }
 
-    int sliderValue;
-    double speed = INPUT_RATE_DEFAULT / (double)rate;
+    double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
+    int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
 
-    if( rate >= INPUT_RATE_DEFAULT )
+    if( sliderValue < speedSlider->minimum() )
     {
-        if( speed < RATE_SLIDER_MINIMUM )
-        {
-            sliderValue = speedSlider->minimum();
-        }
-        else
-        {
-            sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
-                                        / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
-        }
+        sliderValue = speedSlider->minimum();
     }
-    else
+    else if( sliderValue > speedSlider->maximum() )
     {
-        if( speed > RATE_SLIDER_MAXIMUM )
-        {
-            sliderValue = speedSlider->maximum();
-        }
-        else
-        {
-            sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
-                                        / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
-        }
+        sliderValue = speedSlider->maximum();
     }
 
     //Block signals to avoid feedback loop
@@ -1284,18 +1272,8 @@ void SpeedControlWidget::updateControls( int rate )
 
 void SpeedControlWidget::updateRate( int sliderValue )
 {
-    int rate;
-
-    if( sliderValue < 0.0 )
-    {
-        rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
-            ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ));
-    }
-    else
-    {
-        rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
-            ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH ));
-    }
+    double speed = pow( 2, (double)sliderValue / 12 );
+    int rate = INPUT_RATE_DEFAULT / speed;
 
     THEMIM->getIM()->setRate(rate);
 }