]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/controller_widget.cpp
Qt: Fix the bug where the volume was losing 1% at each start
[vlc] / modules / gui / qt4 / components / controller_widget.cpp
index 1b907ffadfe352fc5364eea06f252e2556174042..db295423b69f3765db64d7a4ba4eff79ca71cb45 100644 (file)
@@ -26,6 +26,7 @@
 #endif
 
 #include "controller_widget.hpp"
+#include "controller.hpp"
 
 #include "input_manager.hpp"         /* Get notification of Volume Change */
 #include "util/input_slider.hpp"     /* SoundSlider */
@@ -41,8 +42,8 @@
 
 SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
                           bool b_shiny, bool b_special )
-                         : QWidget( _parent ), b_my_volume( false ),
-                           p_intf( _p_intf)
+                         : QWidget( _parent ), p_intf( _p_intf),
+                           b_my_volume( false )
 {
     /* We need a layout for this widget */
     QHBoxLayout *layout = new QHBoxLayout( this );
@@ -50,7 +51,7 @@ SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
 
     /* We need a Label for the pix */
     volMuteLabel = new QLabel;
-    volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
+    volMuteLabel->setPixmap( QPixmap( ":/toolbar/volume-medium" ) );
 
     /* We might need a subLayout too */
     QVBoxLayout *subLayout;
@@ -61,13 +62,14 @@ SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
     if( !b_special )
     {
         volumeMenu = NULL; subLayout = NULL;
+        volumeControlWidget = NULL;
     }
     else
     {
         /* Special view, click on button shows the slider */
         b_shiny = false;
 
-        QFrame *volumeControlWidget = new QFrame;
+        volumeControlWidget = new QFrame;
         subLayout = new QVBoxLayout( volumeControlWidget );
         subLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
         volumeMenu = new QMenu( this );
@@ -106,11 +108,11 @@ SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
     if( b_special )
         subLayout->addWidget( volumeSlider );
     else
-        layout->addWidget( volumeSlider );
+        layout->addWidget( volumeSlider, 0, Qt::AlignBottom  );
 
     /* Set the volume from the config */
-    volumeSlider->setValue( config_GetInt( p_intf, "volume" ) ) *
-                              VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
+    volumeSlider->setValue( qRound( ( (qreal)config_GetInt( p_intf, "volume" ) ) *
+                              VOLUME_MAX / (AOUT_VOLUME_MAX/2) ) );
 
     /* Force the update at build time in order to have a muted icon if needed */
     updateVolume( volumeSlider->value() );
@@ -120,25 +122,33 @@ SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
     CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
 }
 
+SoundWidget::~SoundWidget()
+{
+    delete volumeSlider;
+    delete volumeControlWidget;
+}
+
 void SoundWidget::updateVolume( int i_sliderVolume )
 {
     if( !b_my_volume )
     {
         int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
-        aout_VolumeSet( p_intf, i_res );
+        playlist_t *p_playlist = pl_Hold( p_intf );
+        aout_VolumeSet( p_playlist, i_res );
+        pl_Release( p_intf );
     }
     if( i_sliderVolume == 0 )
     {
-        volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
+        volMuteLabel->setPixmap( QPixmap(":/toolbar/volume-muted" ) );
         volMuteLabel->setToolTip( qtr( "Unmute" ) );
         return;
     }
 
     if( i_sliderVolume < VOLUME_MAX / 3 )
-        volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
+        volMuteLabel->setPixmap( QPixmap( ":/toolbar/volume-low" ) );
     else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
-        volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
-    else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
+        volMuteLabel->setPixmap( QPixmap( ":/toolbar/volume-high" ) );
+    else volMuteLabel->setPixmap( QPixmap( ":/toolbar/volume-medium" ) );
     volMuteLabel->setToolTip( qtr( "Mute" ) );
 }
 
@@ -146,7 +156,10 @@ void SoundWidget::updateVolume()
 {
     /* Audio part */
     audio_volume_t i_volume;
-    aout_VolumeGet( p_intf, &i_volume );
+    playlist_t *p_playlist = pl_Hold( p_intf );
+
+    aout_VolumeGet( p_playlist, &i_volume );
+    pl_Release( p_intf );
     i_volume = ( ( i_volume + 1 ) *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
     int i_gauge = volumeSlider->value();
     b_my_volume = false;
@@ -176,7 +189,10 @@ bool SoundWidget::eventFilter( QObject *obj, QEvent *e )
         }
         else
         {
-            aout_VolumeMute( p_intf, NULL );
+            playlist_t *p_playlist = pl_Hold( p_intf );
+
+            aout_ToggleMute( p_playlist, NULL );
+            pl_Release( p_intf );
         }
         e->accept();
         return true;
@@ -193,7 +209,7 @@ bool SoundWidget::eventFilter( QObject *obj, QEvent *e )
  **/
 void PlayButton::updateButton( bool b_playing )
 {
-    setIcon( b_playing ? QIcon( ":/pause_b" ) : QIcon( ":/play_b" ) );
+    setIcon( b_playing ? QIcon( ":/toolbar/pause_b" ) : QIcon( ":/toolbar/play_b" ) );
     setToolTip( b_playing ? qtr( "Pause the playback" )
                           : qtr( I_PLAY_TOOLTIP ) );
 }
@@ -202,18 +218,18 @@ void AtoB_Button::setIcons( bool timeA, bool timeB )
 {
     if( !timeA && !timeB)
     {
-        setIcon( QIcon( ":/atob_nob" ) );
+        setIcon( QIcon( ":/toolbar/atob_nob" ) );
         setToolTip( qtr( "Loop from point A to point B continuously\n"
                          "Click to set point A" ) );
     }
     else if( timeA && !timeB )
     {
-        setIcon( QIcon( ":/atob_noa" ) );
+        setIcon( QIcon( ":/toolbar/atob_noa" ) );
         setToolTip( qtr( "Click to set point B" ) );
     }
     else if( timeA && timeB )
     {
-        setIcon( QIcon( ":/atob" ) );
+        setIcon( QIcon( ":/toolbar/atob" ) );
         setToolTip( qtr( "Stop the A to B loop" ) );
     }
 }