[vlc-devel] [PATCH 2/3] Qt: Migrate SoundWidget to use abstraction classes
Francois Cartegnie
fcvlcdev at free.fr
Wed Mar 3 21:51:11 CET 2010
---
modules/gui/qt4/components/controller.cpp | 5 ++-
modules/gui/qt4/components/controller_widget.cpp | 44 +++++++++-------------
modules/gui/qt4/components/controller_widget.hpp | 18 +++++---
modules/gui/qt4/dialogs/toolbar.cpp | 4 +-
4 files changed, 36 insertions(+), 35 deletions(-)
diff --git a/modules/gui/qt4/components/controller.cpp b/modules/gui/qt4/components/controller.cpp
index a0cfc94..72ab0aa 100644
--- a/modules/gui/qt4/components/controller.cpp
+++ b/modules/gui/qt4/components/controller.cpp
@@ -309,7 +309,10 @@ QWidget *AbstractController::createWidget( buttonType_e button, int options )
b_special = true;
case VOLUME:
{
- SoundWidget *snd = new SoundWidget( this, p_intf, b_shiny, b_special );
+ SoundWidget *snd = new SoundWidget( this,
+ PrefsAdapter::getInstance( p_intf ),
+ AudioThreadAdapter::getInstance( p_intf ),
+ b_shiny, b_special );
widget = snd;
}
break;
diff --git a/modules/gui/qt4/components/controller_widget.cpp b/modules/gui/qt4/components/controller_widget.cpp
index 9ee7117..41986ff 100644
--- a/modules/gui/qt4/components/controller_widget.cpp
+++ b/modules/gui/qt4/components/controller_widget.cpp
@@ -40,9 +40,11 @@
#include <QWidgetAction>
#include <QMouseEvent>
-SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
+SoundWidget::SoundWidget( QWidget *_parent,
+ PrefsAdapter *_prefsA, AudioThreadAdapter *_atA,
bool b_shiny, bool b_special )
- : QWidget( _parent ), p_intf( _p_intf),
+ : QWidget( _parent ),
+ prefsA( _prefsA ), atA( _atA ),
b_is_muted( false )
{
/* We need a layout for this widget */
@@ -86,17 +88,17 @@ SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
if( b_shiny )
{
volumeSlider = new SoundSlider( this,
- config_GetInt( p_intf, "volume-step" ),
- var_InheritInteger( p_intf, "qt-volume-complete" ),
- var_InheritString( p_intf, "qt-slider-colours" ) );
+ prefsA->getInteger( "volume-step" ),
+ prefsA->getBool( "qt-volume-complete" ),
+ prefsA->getString( "qt-slider-colours" ) );
}
else
{
volumeSlider = new QSlider( NULL );
volumeSlider->setOrientation( b_special ? Qt::Vertical
: Qt::Horizontal );
- volumeSlider->setMaximum( var_InheritBool( p_intf, "qt-volume-complete" )
- ? 400 : 200 );
+ volumeSlider->setMaximum( prefsA->getBool( "qt-volume-complete" )
+ ? BOOSTED_VOLUME_MAX : VOLUME_MAX );
}
if( volumeSlider->orientation() == Qt::Horizontal )
{
@@ -111,15 +113,15 @@ SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
layout->addWidget( volumeSlider, 0, Qt::AlignBottom );
/* Set the volume from the config */
- libUpdateVolume();
+ onLibUpdateVolumeHandler( atA->getLibVolume() );
/* Force the update at build time in order to have a muted icon if needed */
- updateMuteStatus();
+ onLibUpdateMuteStatusHandler( atA->getLibMuteState() );
/* Volume control connection */
CONNECT( volumeSlider, valueChanged( int ), this, refreshLabels( void ) );
CONNECT( volumeSlider, sliderMoved( int ), this, userUpdateVolume( int ) );
- CONNECT( THEMIM, volumeChanged( void ), this, libUpdateVolume( void ) );
- CONNECT( THEMIM, soundMuteChanged( void ), this, updateMuteStatus( void ) );
+ CONNECT( atA, libUpdatedVolume( int ), this, onLibUpdateVolumeHandler( int ) );
+ CONNECT( atA, libUpdatedMuteStatus( bool ), this, onLibUpdateMuteStatusHandler( bool ) );
}
SoundWidget::~SoundWidget()
@@ -152,20 +154,13 @@ void SoundWidget::userUpdateVolume( int i_sliderVolume )
{
/* Only if volume is set by user action on slider */
setMuted( false );
- 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 );
+ atA->setLibVolume( i_sliderVolume );
}
/* libvlc changed value event slot */
-void SoundWidget::libUpdateVolume()
+void SoundWidget::onLibUpdateVolumeHandler( int i_volume )
{
/* Audio part */
- audio_volume_t i_volume;
- playlist_t *p_playlist = pl_Get( p_intf );
-
- aout_VolumeGet( p_playlist, &i_volume );
- 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) */
( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
@@ -176,11 +171,9 @@ void SoundWidget::libUpdateVolume()
}
/* libvlc mute/unmute event slot */
-void SoundWidget::updateMuteStatus()
+void SoundWidget::onLibUpdateMuteStatusHandler( bool _b_is_muted )
{
- playlist_t *p_playlist = pl_Get( p_intf );
- b_is_muted = aout_IsMuted( VLC_OBJECT(p_playlist) );
-
+ b_is_muted = _b_is_muted;
SoundSlider *soundSlider = qobject_cast<SoundSlider *>(volumeSlider);
if( soundSlider )
soundSlider->setMuted( b_is_muted );
@@ -197,8 +190,7 @@ void SoundWidget::showVolumeMenu( QPoint pos )
void SoundWidget::setMuted( bool mute )
{
b_is_muted = mute;
- playlist_t *p_playlist = pl_Get( p_intf );
- aout_SetMute( VLC_OBJECT(p_playlist), NULL, mute );
+ atA->setLibMuteState( mute );
}
bool SoundWidget::eventFilter( QObject *obj, QEvent *e )
diff --git a/modules/gui/qt4/components/controller_widget.hpp b/modules/gui/qt4/components/controller_widget.hpp
index 5727da3..d0cdbaf 100644
--- a/modules/gui/qt4/components/controller_widget.hpp
+++ b/modules/gui/qt4/components/controller_widget.hpp
@@ -29,6 +29,8 @@
#endif
#include "qt4.hpp"
+#include "../adapters/prefsadapter.hpp"
+#include "../adapters/audiothreadadapter.hpp"
#include <QWidget>
#include <QFrame>
@@ -67,30 +69,32 @@ private slots:
void setIcons( bool, bool );
};
-#define VOLUME_MAX 200
class SoundWidget : public QWidget
{
Q_OBJECT
public:
- SoundWidget( QWidget *parent, intf_thread_t *_p_i, bool,
- bool b_special = false );
+ SoundWidget( QWidget *parent,
+ PrefsAdapter *prefsA, AudioThreadAdapter *atA,
+ bool, bool b_special = false );
virtual ~SoundWidget();
void setMuted( bool );
private:
- intf_thread_t *p_intf;
+ PrefsAdapter *prefsA;
+ AudioThreadAdapter *atA;
QLabel *volMuteLabel;
QAbstractSlider *volumeSlider;
QFrame *volumeControlWidget;
QMenu *volumeMenu;
virtual bool eventFilter( QObject *obj, QEvent *e );
bool b_is_muted;
-
+ static const unsigned int VOLUME_MAX = 200;
+ static const unsigned int BOOSTED_VOLUME_MAX = 400;
protected slots:
void userUpdateVolume( int );
- void libUpdateVolume( void );
- void updateMuteStatus( void );
+ void onLibUpdateVolumeHandler( int );
+ void onLibUpdateMuteStatusHandler( bool );
void refreshLabels( void );
void showVolumeMenu( QPoint pos );
};
diff --git a/modules/gui/qt4/dialogs/toolbar.cpp b/modules/gui/qt4/dialogs/toolbar.cpp
index 0f67025..986c374 100644
--- a/modules/gui/qt4/dialogs/toolbar.cpp
+++ b/modules/gui/qt4/dialogs/toolbar.cpp
@@ -337,7 +337,9 @@ WidgetListing::WidgetListing( intf_thread_t *p_intf, QWidget *_parent )
break;
case VOLUME:
{
- SoundWidget *snd = new SoundWidget( this, p_intf,
+ SoundWidget *snd = new SoundWidget( this,
+ PrefsAdapter::getInstance( p_intf ),
+ AudioThreadAdapter::getInstance( p_intf ),
parent->getOptions() & WIDGET_SHINY );
widget = snd;
}
--
1.6.4.4
More information about the vlc-devel
mailing list