Commit 6e670ff2 authored by Clément Stenac's avatar Clément Stenac

Volume control

parent 159fa24a
......@@ -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 )
......
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment