Commit 1a4bb059 authored by Francois Cartegnie's avatar Francois Cartegnie Committed by Rémi Denis-Courmont

Qt: Audio control widget changes

Signed-off-by: default avatarRémi Denis-Courmont <remi@remlab.net>
parent f870d44c
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf, SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
bool b_shiny, bool b_special ) bool b_shiny, bool b_special )
: QWidget( _parent ), p_intf( _p_intf), : QWidget( _parent ), p_intf( _p_intf),
b_my_volume( false ) b_my_volume( false ), b_is_muted( false )
{ {
/* We need a layout for this widget */ /* We need a layout for this widget */
QHBoxLayout *layout = new QHBoxLayout( this ); QHBoxLayout *layout = new QHBoxLayout( this );
...@@ -120,6 +120,7 @@ SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf, ...@@ -120,6 +120,7 @@ SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
/* Volume control connection */ /* Volume control connection */
CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) ); CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) ); CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
CONNECT( THEMIM, soundMuteChanged( void ), this, updateMuteStatus( void ) );
} }
SoundWidget::~SoundWidget() SoundWidget::~SoundWidget()
...@@ -128,16 +129,11 @@ SoundWidget::~SoundWidget() ...@@ -128,16 +129,11 @@ SoundWidget::~SoundWidget()
delete volumeControlWidget; delete volumeControlWidget;
} }
void SoundWidget::updateVolume( int i_sliderVolume ) void SoundWidget::refreshLabels()
{ {
if( !b_my_volume ) int i_sliderVolume = volumeSlider->value();
{
int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX; if( b_is_muted )
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(":/toolbar/volume-muted" ) ); volMuteLabel->setPixmap( QPixmap(":/toolbar/volume-muted" ) );
volMuteLabel->setToolTip(qfu(vlc_pgettext("Tooltip|Unmute", "Unmute"))); volMuteLabel->setToolTip(qfu(vlc_pgettext("Tooltip|Unmute", "Unmute")));
...@@ -152,6 +148,21 @@ void SoundWidget::updateVolume( int i_sliderVolume ) ...@@ -152,6 +148,21 @@ void SoundWidget::updateVolume( int i_sliderVolume )
volMuteLabel->setToolTip( qfu(vlc_pgettext("Tooltip|Mute", "Mute")) ); volMuteLabel->setToolTip( qfu(vlc_pgettext("Tooltip|Mute", "Mute")) );
} }
/* volumeSlider changed value event slot */
void SoundWidget::updateVolume( int i_sliderVolume )
{
if( !b_my_volume ) /* Only if volume is set by user action on slider */
{
setMuted( false );
playlist_t *p_playlist = pl_Hold( 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 */
void SoundWidget::updateVolume() void SoundWidget::updateVolume()
{ {
/* Audio part */ /* Audio part */
...@@ -163,7 +174,9 @@ void SoundWidget::updateVolume() ...@@ -163,7 +174,9 @@ void SoundWidget::updateVolume()
i_volume = ( ( i_volume + 1 ) * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2); i_volume = ( ( i_volume + 1 ) * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
int i_gauge = volumeSlider->value(); int i_gauge = volumeSlider->value();
b_my_volume = false; b_my_volume = false;
if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 ) if ( !b_is_muted && /* do not show mute effect on volume (set to 0) */
( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
)
{ {
b_my_volume = true; b_my_volume = true;
volumeSlider->setValue( i_volume ); volumeSlider->setValue( i_volume );
...@@ -171,6 +184,16 @@ void SoundWidget::updateVolume() ...@@ -171,6 +184,16 @@ void SoundWidget::updateVolume()
} }
} }
/* libvlc mute/unmute event slot */
void SoundWidget::updateMuteStatus()
{
playlist_t *p_playlist = pl_Hold( p_intf );
b_is_muted = aout_IsMuted( VLC_OBJECT(p_playlist) );
pl_Release( p_intf );
(qobject_cast<SoundSlider *>(volumeSlider))->setMuted( b_is_muted );
refreshLabels();
}
void SoundWidget::showVolumeMenu( QPoint pos ) void SoundWidget::showVolumeMenu( QPoint pos )
{ {
volumeMenu->setFixedHeight( volumeMenu->sizeHint().height() ); volumeMenu->setFixedHeight( volumeMenu->sizeHint().height() );
...@@ -178,6 +201,14 @@ void SoundWidget::showVolumeMenu( QPoint pos ) ...@@ -178,6 +201,14 @@ void SoundWidget::showVolumeMenu( QPoint pos )
+ QPoint( width(), height() /2) ); + QPoint( width(), height() /2) );
} }
void SoundWidget::setMuted( bool mute )
{
b_is_muted = mute;
playlist_t *p_playlist = pl_Hold( p_intf );
aout_SetMute( VLC_OBJECT(p_playlist), NULL, mute );
pl_Release( p_intf );
}
bool SoundWidget::eventFilter( QObject *obj, QEvent *e ) bool SoundWidget::eventFilter( QObject *obj, QEvent *e )
{ {
VLC_UNUSED( obj ); VLC_UNUSED( obj );
...@@ -190,10 +221,7 @@ bool SoundWidget::eventFilter( QObject *obj, QEvent *e ) ...@@ -190,10 +221,7 @@ bool SoundWidget::eventFilter( QObject *obj, QEvent *e )
} }
else else
{ {
playlist_t *p_playlist = pl_Hold( p_intf ); setMuted( !b_is_muted );
aout_ToggleMute( p_playlist, NULL );
pl_Release( p_intf );
} }
e->accept(); e->accept();
return true; return true;
......
...@@ -76,6 +76,7 @@ public: ...@@ -76,6 +76,7 @@ public:
SoundWidget( QWidget *parent, intf_thread_t *_p_i, bool, SoundWidget( QWidget *parent, intf_thread_t *_p_i, bool,
bool b_special = false ); bool b_special = false );
virtual ~SoundWidget(); virtual ~SoundWidget();
void setMuted( bool );
private: private:
intf_thread_t *p_intf; intf_thread_t *p_intf;
...@@ -85,9 +86,13 @@ private: ...@@ -85,9 +86,13 @@ private:
bool b_my_volume; bool b_my_volume;
QMenu *volumeMenu; QMenu *volumeMenu;
virtual bool eventFilter( QObject *obj, QEvent *e ); virtual bool eventFilter( QObject *obj, QEvent *e );
bool b_is_muted;
protected slots: protected slots:
void updateVolume( int ); void updateVolume( int );
void updateVolume( void ); void updateVolume( void );
void updateMuteStatus( void );
void refreshLabels( void );
void showVolumeMenu( QPoint pos ); void showVolumeMenu( QPoint pos );
}; };
......
...@@ -45,6 +45,8 @@ static int PLItemRemoved( vlc_object_t *, const char *, ...@@ -45,6 +45,8 @@ static int PLItemRemoved( vlc_object_t *, const char *,
vlc_value_t, vlc_value_t, void * ); vlc_value_t, vlc_value_t, void * );
static int VolumeChanged( vlc_object_t *, const char *, static int VolumeChanged( vlc_object_t *, const char *,
vlc_value_t, vlc_value_t, void * ); vlc_value_t, vlc_value_t, void * );
static int SoundMuteChanged( vlc_object_t *, const char *,
vlc_value_t, vlc_value_t, void * );
static int RandomChanged( vlc_object_t *, const char *, static int RandomChanged( vlc_object_t *, const char *,
vlc_value_t, vlc_value_t, void * ); vlc_value_t, vlc_value_t, void * );
...@@ -901,6 +903,7 @@ MainInputManager::MainInputManager( intf_thread_t *_p_intf ) ...@@ -901,6 +903,7 @@ MainInputManager::MainInputManager( intf_thread_t *_p_intf )
var_AddCallback( THEPL, "loop", LoopChanged, this ); var_AddCallback( THEPL, "loop", LoopChanged, this );
var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, this ); var_AddCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, this );
var_AddCallback( p_intf->p_libvlc, "volume-muted", SoundMuteChanged, this );
/* Warn our embedded IM about input changes */ /* Warn our embedded IM about input changes */
CONNECT( this, inputChanged( input_thread_t * ), CONNECT( this, inputChanged( input_thread_t * ),
...@@ -931,6 +934,7 @@ MainInputManager::~MainInputManager() ...@@ -931,6 +934,7 @@ MainInputManager::~MainInputManager()
} }
var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, this ); var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, this );
var_DelCallback( p_intf->p_libvlc, "volume-muted", SoundMuteChanged, this );
var_DelCallback( THEPL, "activity", PLItemChanged, this ); var_DelCallback( THEPL, "activity", PLItemChanged, this );
var_DelCallback( THEPL, "item-change", ItemChanged, im ); var_DelCallback( THEPL, "item-change", ItemChanged, im );
...@@ -966,6 +970,9 @@ void MainInputManager::customEvent( QEvent *event ) ...@@ -966,6 +970,9 @@ void MainInputManager::customEvent( QEvent *event )
case VolumeChanged_Type: case VolumeChanged_Type:
emit volumeChanged(); emit volumeChanged();
return; return;
case SoundMuteChanged_Type:
emit soundMuteChanged();
return;
case PLItemAppended_Type: case PLItemAppended_Type:
plEv = static_cast<PLEvent*>( event ); plEv = static_cast<PLEvent*>( event );
emit playlistItemAppended( plEv->i_item, plEv->i_parent ); emit playlistItemAppended( plEv->i_item, plEv->i_parent );
...@@ -1107,6 +1114,16 @@ static int VolumeChanged( vlc_object_t *p_this, const char *psz_var, ...@@ -1107,6 +1114,16 @@ static int VolumeChanged( vlc_object_t *p_this, const char *psz_var,
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static int SoundMuteChanged( vlc_object_t *p_this, const char *psz_var,
vlc_value_t oldval, vlc_value_t newval, void *param )
{
MainInputManager *mim = (MainInputManager*)param;
IMEvent *event = new IMEvent( SoundMuteChanged_Type );
QApplication::postEvent( mim, event );
return VLC_SUCCESS;
}
static int PLItemAppended static int PLItemAppended
( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data ) ( vlc_object_t * obj, const char *var, vlc_value_t old, vlc_value_t cur, void *data )
{ {
......
...@@ -44,6 +44,7 @@ enum { ...@@ -44,6 +44,7 @@ enum {
ItemTitleChanged_Type, ItemTitleChanged_Type,
ItemRateChanged_Type, ItemRateChanged_Type,
VolumeChanged_Type, VolumeChanged_Type,
SoundMuteChanged_Type,
ItemEsChanged_Type, ItemEsChanged_Type,
ItemTeletextChanged_Type, ItemTeletextChanged_Type,
InterfaceVoutUpdate_Type, InterfaceVoutUpdate_Type,
...@@ -278,6 +279,7 @@ public slots: ...@@ -278,6 +279,7 @@ public slots:
signals: signals:
void inputChanged( input_thread_t * ); void inputChanged( input_thread_t * );
void volumeChanged(); void volumeChanged();
void soundMuteChanged();
void playlistItemAppended( int itemId, int parentId ); void playlistItemAppended( int itemId, int parentId );
void playlistItemRemoved( int itemId ); void playlistItemRemoved( int itemId );
void randomChanged( bool ); void randomChanged( bool );
......
...@@ -166,6 +166,7 @@ SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard, ...@@ -166,6 +166,7 @@ SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard,
setMouseTracking( true ); setMouseTracking( true );
b_isSliding = false; b_isSliding = false;
b_mouseOutside = true; b_mouseOutside = true;
b_isMuted = false;
pixOutside = QPixmap( ":/toolbar/volslide-outside" ); pixOutside = QPixmap( ":/toolbar/volslide-outside" );
...@@ -175,9 +176,11 @@ SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard, ...@@ -175,9 +176,11 @@ SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard,
setMinimumSize( pixOutside.size() ); setMinimumSize( pixOutside.size() );
pixGradient = QPixmap( mask.size() ); pixGradient = QPixmap( mask.size() );
pixGradient2 = QPixmap( mask.size() );
/* Gradient building from the preferences */ /* Gradient building from the preferences */
QLinearGradient gradient( paddingL, 2, WLENGTH + paddingL , 2 ); QLinearGradient gradient( paddingL, 2, WLENGTH + paddingL , 2 );
QLinearGradient gradient2( paddingL, 2, WLENGTH + paddingL , 2 );
QStringList colorList = qfu( psz_colors ).split( ";" ); QStringList colorList = qfu( psz_colors ).split( ";" );
free( psz_colors ); free( psz_colors );
...@@ -187,11 +190,28 @@ SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard, ...@@ -187,11 +190,28 @@ SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard,
for( int i = colorList.size(); i < 12; i++) for( int i = colorList.size(); i < 12; i++)
colorList.append( "255" ); colorList.append( "255" );
/* Regular colors */
#define c(i) colorList.at(i).toInt() #define c(i) colorList.at(i).toInt()
gradient.setColorAt( 0.0, QColor( c(0), c(1), c(2) ) ); #define add_color(gradient, range, c1, c2, c3) \
gradient.setColorAt( 0.22, QColor( c(3), c(4), c(5) ) ); gradient.setColorAt( range, QColor( c(c1), c(c2), c(c3) ) );
gradient.setColorAt( 0.5, QColor( c(6), c(7), c(8) ) );
gradient.setColorAt( 1.0, QColor( c(9), c(10), c(11) ) ); /* Desaturated colors */
#define desaturate(c) c->setHsvF( c->hueF(), 0.2 , 0.5, 1.0 )
#define add_desaturated_color(gradient, range, c1, c2, c3) \
foo = new QColor( c(c1), c(c2), c(c3) );\
desaturate( foo ); gradient.setColorAt( range, *foo );\
delete foo;
/* combine the two helpers */
#define add_colors( gradient1, gradient2, range, c1, c2, c3 )\
add_color( gradient1, range, c1, c2, c3 ); \
add_desaturated_color( gradient2, range, c1, c2, c3 );
QColor * foo;
add_colors( gradient, gradient2, 0.0, 0, 1, 2 );
add_colors( gradient, gradient2, 0.22, 3, 4, 5 );
add_colors( gradient, gradient2, 0.5, 6, 7, 8 );
add_colors( gradient, gradient2, 1.0, 9, 10, 11 );
QPainter painter( &pixGradient ); QPainter painter( &pixGradient );
painter.setPen( Qt::NoPen ); painter.setPen( Qt::NoPen );
...@@ -199,7 +219,14 @@ SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard, ...@@ -199,7 +219,14 @@ SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard,
painter.drawRect( pixGradient.rect() ); painter.drawRect( pixGradient.rect() );
painter.end(); painter.end();
painter.begin( &pixGradient2 );
painter.setPen( Qt::NoPen );
painter.setBrush( gradient2 );
painter.drawRect( pixGradient2.rect() );
painter.end();
pixGradient.setMask( mask ); pixGradient.setMask( mask );
pixGradient2.setMask( mask );
} }
void SoundSlider::wheelEvent( QWheelEvent *event ) void SoundSlider::wheelEvent( QWheelEvent *event )
...@@ -268,13 +295,25 @@ void SoundSlider::changeValue( int x ) ...@@ -268,13 +295,25 @@ void SoundSlider::changeValue( int x )
setValue( (x * maximum() + 40 ) / WLENGTH ); setValue( (x * maximum() + 40 ) / WLENGTH );
} }
void SoundSlider::setMuted( bool m )
{
b_isMuted = m;
update();
}
void SoundSlider::paintEvent( QPaintEvent *e ) void SoundSlider::paintEvent( QPaintEvent *e )
{ {
QPainter painter( this ); QPainter painter( this );
QPixmap *pixGradient;
if (b_isMuted)
pixGradient = &this->pixGradient2;
else
pixGradient = &this->pixGradient;
const int offset = int( ( WLENGTH * value() + 100 ) / maximum() ) + paddingL; const int offset = int( ( WLENGTH * value() + 100 ) / maximum() ) + paddingL;
const QRectF boundsG( 0, 0, offset , pixGradient.height() ); const QRectF boundsG( 0, 0, offset , pixGradient->height() );
painter.drawPixmap( boundsG, pixGradient, boundsG ); painter.drawPixmap( boundsG, *pixGradient, boundsG );
const QRectF boundsO( 0, 0, pixOutside.width(), pixOutside.height() ); const QRectF boundsO( 0, 0, pixOutside.width(), pixOutside.height() );
painter.drawPixmap( boundsO, pixOutside, boundsO ); painter.drawPixmap( boundsO, pixOutside, boundsO );
......
...@@ -73,6 +73,7 @@ class SoundSlider : public QAbstractSlider ...@@ -73,6 +73,7 @@ class SoundSlider : public QAbstractSlider
public: public:
SoundSlider( QWidget *_parent, int _i_step, bool b_softamp, char * ); SoundSlider( QWidget *_parent, int _i_step, bool b_softamp, char * );
virtual ~SoundSlider() {}; virtual ~SoundSlider() {};
void setMuted( bool ); /* Set Mute status */
protected: protected:
const static int paddingL = 3; const static int paddingL = 3;
...@@ -89,8 +90,10 @@ private: ...@@ -89,8 +90,10 @@ private:
bool b_mouseOutside; /* Whether the mouse is outside or inside the Widget */ bool b_mouseOutside; /* Whether the mouse is outside or inside the Widget */
int i_oldvalue; /* Store the old Value before changing */ int i_oldvalue; /* Store the old Value before changing */
float f_step; /* How much do we increase each time we wheel */ float f_step; /* How much do we increase each time we wheel */
bool b_isMuted;
QPixmap pixGradient; /* Gradient pix storage */ QPixmap pixGradient; /* Gradient pix storage */
QPixmap pixGradient2; /* Muted Gradient pix storage */
QPixmap pixOutside; /* OutLine pix storage */ QPixmap pixOutside; /* OutLine pix storage */
void changeValue( int x ); /* Function to modify the value from pixel x() */ void changeValue( int x ); /* Function to modify the value from pixel x() */
......
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