]> git.sesse.net Git - vlc/commitdiff
Volume control
authorClément Stenac <zorglub@videolan.org>
Sat, 26 Aug 2006 19:16:09 +0000 (19:16 +0000)
committerClément Stenac <zorglub@videolan.org>
Sat, 26 Aug 2006 19:16:09 +0000 (19:16 +0000)
modules/gui/qt4/main_interface.cpp
modules/gui/qt4/main_interface.hpp

index fcd175f6b5e79da4b6d731490ac17dac24be8146..dd9a357c66086e15ed3df94cab4b822d623e1d60 100644 (file)
@@ -59,6 +59,11 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     ui.stopButton->setIcon( QIcon( ":/pixmaps/stop.png" ) );
     ui.volLowLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
     ui.volHighLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
+    ui.volumeSlider->setMaximum( 100 );
+
+    VolumeClickHandler *h = new VolumeClickHandler( this );
+    ui.volLowLabel->installEventFilter(h);
+    ui.volHighLabel->installEventFilter(h);
 
     QVLCMenu::createMenuBar( menuBar(), p_intf );
 
@@ -99,6 +104,10 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
     /* Init input manager */
     MainInputManager::getInstance( p_intf );
 
+    /* Volume control */
+    connect( ui.volumeSlider, SIGNAL( valueChanged(int) ),
+             this, SLOT( updateVolume(int) ) );
+
     /* Get timer updates */
     connect( THEDP->fixed_timer, SIGNAL( timeout() ),
              this, SLOT(updateOnTimer() ) );
@@ -197,12 +206,25 @@ void MainInterface::setStatus( int status )
         ui.playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
 }
 
+static bool b_my_volume;
+
 void MainInterface::updateOnTimer()
 {
     if( p_intf->b_die )
     {
         QApplication::quit();
     }
+    audio_volume_t i_volume;
+    aout_VolumeGet( p_intf, &i_volume );
+    i_volume = (i_volume *  200 )/ AOUT_VOLUME_MAX ;
+    int i_gauge = ui.volumeSlider->value();
+    b_my_volume = false;
+    if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
+    {
+        b_my_volume = true;
+        ui.volumeSlider->setValue( i_volume );
+        b_my_volume = false;
+    }
 }
 
 void MainInterface::closeEvent( QCloseEvent *e )
@@ -211,6 +233,16 @@ void MainInterface::closeEvent( QCloseEvent *e )
     p_intf->b_die = VLC_TRUE;
 }
 
+void MainInterface::updateVolume( int sliderVolume )
+{
+    if( !b_my_volume )
+    {
+        int i_res = sliderVolume * AOUT_VOLUME_MAX /
+                            (2*ui.volumeSlider->maximum() );
+        aout_VolumeSet( p_intf, i_res );
+    }
+}
+
 static int InteractCallback( vlc_object_t *p_this,
                              const char *psz_var, vlc_value_t old_val,
                              vlc_value_t new_val, void *param )
index 33a43aacf90d542f430a26fb68a19e8fe41e5f58..1c26716f3d3e40e46ff3a060b4ef06ff20bb472e 100644 (file)
@@ -24,6 +24,7 @@
 #define _MAIN_INTERFACE_H_
 
 #include <vlc/intf.h>
+#include <vlc/aout.h>
 #include "ui/main_interface.h"
 #include "util/qvlcframe.hpp"
 
@@ -32,7 +33,7 @@ class QLabel;
 class InputManager;
 class InputSlider;
 class VideoWidget;
-
+class VolumeClickHandler;
 class MainInterface : public QVLCMW
 {
     Q_OBJECT;
@@ -46,6 +47,8 @@ public:
 
 protected:
     void closeEvent( QCloseEvent *);
+    Ui::MainInterfaceUI ui;
+    friend class VolumeClickHandler;
 private:
     VideoWidget *videoWidget;
     InputManager *main_input_manager;
@@ -54,7 +57,6 @@ private:
     InputSlider *slider;
     /// Main input associated to the playlist
     input_thread_t *p_input;
-    Ui::MainInterfaceUI ui;
 private slots:
     void setStatus( int );
     void setName( QString );
@@ -64,6 +66,31 @@ private slots:
     void stop();
     void prev();
     void next();
+    void updateVolume( int sliderVolume );
+};
+
+
+class VolumeClickHandler : public QObject
+{
+public:
+    VolumeClickHandler( MainInterface *_m ) :QObject(_m) {m = _m; }
+    virtual ~VolumeClickHandler() {};
+    bool eventFilter( QObject *obj, QEvent *e )
+    {
+        if (e->type() == QEvent::MouseButtonPress )
+        {
+            if( obj->objectName() == "volLowLabel" )
+            {
+                m->ui.volumeSlider->setValue( 0 );
+            }
+            else
+                m->ui.volumeSlider->setValue( 100 );
+            return true;
+        }
+        return false;
+    }
+private:
+    MainInterface *m;
 };
 
 #endif