]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/controller_widget.cpp
Qt: SoundSlider: always emit valuechange on slider move (fix #4658)
[vlc] / modules / gui / qt4 / components / controller_widget.cpp
index 7aac19d41e1b786038ae760d3f3678e177daa272..e77cdec08bd482def44cf5132bfae9218a75f973 100644 (file)
@@ -87,22 +87,18 @@ SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
     {
         volumeSlider = new SoundSlider( this,
             config_GetInt( p_intf, "volume-step" ),
-            config_GetInt( p_intf, "qt-volume-complete" ),
-            config_GetPsz( p_intf, "qt-slider-colours" ) );
+            var_InheritBool( p_intf, "qt-volume-complete" ),
+            var_InheritString( p_intf, "qt-slider-colours" ) );
     }
     else
     {
         volumeSlider = new QSlider( NULL );
+        volumeSlider->setAttribute( Qt::WA_MacSmallSize);
         volumeSlider->setOrientation( b_special ? Qt::Vertical
                                                 : Qt::Horizontal );
-        volumeSlider->setMaximum( config_GetInt( p_intf, "qt-volume-complete" )
+        volumeSlider->setMaximum( var_InheritBool( p_intf, "qt-volume-complete" )
                                   ? 400 : 200 );
     }
-    if( volumeSlider->orientation() ==  Qt::Horizontal )
-    {
-        volumeSlider->setMaximumSize( QSize( 200, 40 ) );
-        volumeSlider->setMinimumSize( QSize( 85, 30 ) );
-    }
 
     volumeSlider->setFocusPolicy( Qt::NoFocus );
     if( b_special )
@@ -111,15 +107,13 @@ SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
         layout->addWidget( volumeSlider, 0, Qt::AlignBottom  );
 
     /* Set the volume from the config */
-    volumeSlider->setValue( qRound( ( (qreal)config_GetInt( p_intf, "volume" ) ) *
-                              VOLUME_MAX / (AOUT_VOLUME_MAX/2) ) );
-
+    libUpdateVolume();
     /* Force the update at build time in order to have a muted icon if needed */
-    userUpdateVolume( volumeSlider->value() );
+    updateMuteStatus();
 
     /* Volume control connection */
-    CONNECT( volumeSlider, valueChanged( int ), this, refreshLabels( void ) );
-    CONNECT( volumeSlider, sliderMoved( int ), this, userUpdateVolume( int ) );
+    volumeSlider->setTracking( true );
+    CONNECT( volumeSlider, valueChanged( int ), this, userUpdateVolume( int ) );
     CONNECT( THEMIM, volumeChanged( void ), this, libUpdateVolume( void ) );
     CONNECT( THEMIM, soundMuteChanged( void ), this, updateMuteStatus( void ) );
 }
@@ -154,10 +148,10 @@ void SoundWidget::userUpdateVolume( int i_sliderVolume )
 {
     /* Only if volume is set by user action on slider */
     setMuted( false );
-    playlist_t *p_playlist = pl_Hold( p_intf );
+    playlist_t *p_playlist = pl_Get( p_intf );
     int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
     aout_VolumeSet( p_playlist, i_res );
-    pl_Release( p_intf );
+    refreshLabels();
 }
 
 /* libvlc changed value event slot */
@@ -165,10 +159,9 @@ void SoundWidget::libUpdateVolume()
 {
     /* Audio part */
     audio_volume_t i_volume;
-    playlist_t *p_playlist = pl_Hold( p_intf );
+    playlist_t *p_playlist = pl_Get( p_intf );
 
-    aout_VolumeGet( p_playlist, &i_volume );
-    pl_Release( p_intf );
+    i_volume = aout_VolumeGet( p_playlist );
     i_volume = ( ( i_volume + 1 ) *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
     int i_gauge = volumeSlider->value();
     if ( !b_is_muted && /* do not show mute effect on volume (set to 0) */
@@ -182,10 +175,12 @@ void SoundWidget::libUpdateVolume()
 /* libvlc mute/unmute event slot */
 void SoundWidget::updateMuteStatus()
 {
-    playlist_t *p_playlist = pl_Hold( p_intf );
+    playlist_t *p_playlist = pl_Get( p_intf );
     b_is_muted = aout_IsMuted( VLC_OBJECT(p_playlist) );
-    pl_Release( p_intf );
-    (qobject_cast<SoundSlider *>(volumeSlider))->setMuted( b_is_muted );
+
+    SoundSlider *soundSlider = qobject_cast<SoundSlider *>(volumeSlider);
+    if( soundSlider )
+        soundSlider->setMuted( b_is_muted );
     refreshLabels();
 }
 
@@ -199,9 +194,8 @@ void SoundWidget::showVolumeMenu( QPoint pos )
 void SoundWidget::setMuted( bool mute )
 {
     b_is_muted = mute;
-    playlist_t *p_playlist = pl_Hold( p_intf );
+    playlist_t *p_playlist = pl_Get( p_intf );
     aout_SetMute( VLC_OBJECT(p_playlist), NULL, mute );
-    pl_Release( p_intf );
 }
 
 bool SoundWidget::eventFilter( QObject *obj, QEvent *e )
@@ -261,6 +255,6 @@ void AtoB_Button::setIcons( bool timeA, bool timeB )
 void LoopButton::updateIcons( int value )
 {
     setChecked( value != NORMAL );
-    setIcon( ( value == REPEAT_ALL ) ? QIcon( ":/buttons/playlist/repeat_all" )
-                                     : QIcon( ":/buttons/playlist/repeat_one" ) );
+    setIcon( ( value == REPEAT_ONE ) ? QIcon( ":/buttons/playlist/repeat_one" )
+                                     : QIcon( ":/buttons/playlist/repeat_all" ) );
 }