#endif
#include "controller_widget.hpp"
+#include "controller.hpp"
#include "input_manager.hpp" /* Get notification of Volume Change */
#include "util/input_slider.hpp" /* SoundSlider */
#include <QLabel>
#include <QHBoxLayout>
#include <QSpinBox>
+#include <QMenu>
+#include <QWidgetAction>
+#include <QMouseEvent>
SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
- bool b_shiny )
- : QWidget( _parent ), b_my_volume( false )
+ bool b_shiny, bool b_special )
+ : QWidget( _parent ), p_intf( _p_intf),
+ b_is_muted( false )
{
- p_intf = _p_intf;
+ /* We need a layout for this widget */
QHBoxLayout *layout = new QHBoxLayout( this );
layout->setSpacing( 0 ); layout->setMargin( 0 );
- hVolLabel = new VolumeClickHandler( p_intf, this );
+ /* We need a Label for the pix */
volMuteLabel = new QLabel;
- volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
- volMuteLabel->installEventFilter( hVolLabel );
+ volMuteLabel->setPixmap( QPixmap( ":/toolbar/volume-medium" ) );
+
+ /* We might need a subLayout too */
+ QVBoxLayout *subLayout;
+
+ volMuteLabel->installEventFilter( this );
+
+ /* Normal View, click on icon mutes */
+ if( !b_special )
+ {
+ volumeMenu = NULL; subLayout = NULL;
+ volumeControlWidget = NULL;
+ }
+ else
+ {
+ /* Special view, click on button shows the slider */
+ b_shiny = false;
+
+ volumeControlWidget = new QFrame;
+ subLayout = new QVBoxLayout( volumeControlWidget );
+ subLayout->setContentsMargins( 4, 4, 4, 4 );
+ volumeMenu = new QMenu( this );
+
+ QWidgetAction *widgetAction = new QWidgetAction( volumeControlWidget );
+ widgetAction->setDefaultWidget( volumeControlWidget );
+ volumeMenu->addAction( widgetAction );
+ }
+
+ /* And add the label */
layout->addWidget( volMuteLabel );
+ /* Slider creation: shiny or clean */
if( b_shiny )
{
volumeSlider = new SoundSlider( this,
}
else
{
- volumeSlider = new QSlider( this );
- volumeSlider->setOrientation( Qt::Horizontal );
+ volumeSlider = new QSlider( NULL );
+ volumeSlider->setOrientation( b_special ? Qt::Vertical
+ : Qt::Horizontal );
volumeSlider->setMaximum( config_GetInt( p_intf, "qt-volume-complete" )
? 400 : 200 );
}
- volumeSlider->setMaximumSize( QSize( 200, 40 ) );
- volumeSlider->setMinimumSize( QSize( 85, 30 ) );
+ if( volumeSlider->orientation() == Qt::Horizontal )
+ {
+ volumeSlider->setMaximumSize( QSize( 200, 40 ) );
+ volumeSlider->setMinimumSize( QSize( 85, 30 ) );
+ }
+
volumeSlider->setFocusPolicy( Qt::NoFocus );
- layout->addWidget( volumeSlider );
+ if( b_special )
+ subLayout->addWidget( volumeSlider );
+ else
+ 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) );
-
+ libUpdateVolume();
/* Force the update at build time in order to have a muted icon if needed */
- updateVolume( volumeSlider->value() );
+ updateMuteStatus();
/* Volume control connection */
- CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
- CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
+ 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 ) );
}
-void SoundWidget::updateVolume( int i_sliderVolume )
+SoundWidget::~SoundWidget()
{
- if( !b_my_volume )
- {
- int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
- aout_VolumeSet( p_intf, i_res );
- }
- if( i_sliderVolume == 0 )
+ delete volumeSlider;
+ delete volumeControlWidget;
+}
+
+void SoundWidget::refreshLabels()
+{
+ int i_sliderVolume = volumeSlider->value();
+
+ if( b_is_muted )
{
- volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
- volMuteLabel->setToolTip( qtr( "Unmute" ) );
+ volMuteLabel->setPixmap( QPixmap(":/toolbar/volume-muted" ) );
+ volMuteLabel->setToolTip(qfu(vlc_pgettext("Tooltip|Unmute", "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->setToolTip( qtr( "Mute" ) );
+ volMuteLabel->setPixmap( QPixmap( ":/toolbar/volume-high" ) );
+ else volMuteLabel->setPixmap( QPixmap( ":/toolbar/volume-medium" ) );
+ volMuteLabel->setToolTip( qfu(vlc_pgettext("Tooltip|Mute", "Mute")) );
+}
+
+/* volumeSlider changed value event slot */
+void SoundWidget::userUpdateVolume( int i_sliderVolume )
+{
+ /* 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 );
}
-void SoundWidget::updateVolume()
+/* libvlc changed value event slot */
+void SoundWidget::libUpdateVolume()
{
/* Audio part */
audio_volume_t i_volume;
- aout_VolumeGet( p_intf, &i_volume );
- i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
+ 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;
- 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;
volumeSlider->setValue( i_volume );
- b_my_volume = false;
}
}
-void TeletextController::toggleTeletextTransparency( bool b_transparent )
+/* libvlc mute/unmute event slot */
+void SoundWidget::updateMuteStatus()
{
- telexTransparent->setIcon( b_transparent ? QIcon( ":/tvtelx" )
- : QIcon( ":/tvtelx-trans" ) );
+ 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 TeletextController::enableTeletextButtons( bool b_enabled )
+void SoundWidget::showVolumeMenu( QPoint pos )
{
- telexOn->setChecked( b_enabled );
- telexTransparent->setEnabled( b_enabled );
- telexPage->setEnabled( b_enabled );
+ volumeMenu->setFixedHeight( volumeMenu->sizeHint().height() );
+ volumeMenu->exec( QCursor::pos() - pos - QPoint( 0, volumeMenu->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 )
+{
+ VLC_UNUSED( obj );
+ if (e->type() == QEvent::MouseButtonPress )
+ {
+ if( volumeSlider->orientation() == Qt::Vertical )
+ {
+ QMouseEvent *event = static_cast<QMouseEvent*>(e);
+ showVolumeMenu( event->pos() );
+ }
+ else
+ {
+ setMuted( !b_is_muted );
+ }
+ e->accept();
+ return true;
+ }
+ else
+ {
+ e->ignore();
+ return false;
+ }
+}
+
+/**
+ * Play Button
+ **/
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 ) );
}
{
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" ) );
}
}
-bool VolumeClickHandler::eventFilter( QObject *obj, QEvent *e )
+void LoopButton::updateIcons( int value )
{
- VLC_UNUSED( obj );
- if (e->type() == QEvent::MouseButtonPress )
- {
- aout_VolumeMute( p_intf, NULL );
- audio_volume_t i_volume;
- aout_VolumeGet( p_intf, &i_volume );
-// m->updateVolume( i_volume * VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
- e->accept();
- return true;
- }
- else
- {
- e->ignore();
- return false;
- }
+ setChecked( value != NORMAL );
+ setIcon( ( value == REPEAT_ALL ) ? QIcon( ":/buttons/playlist/repeat_all" )
+ : QIcon( ":/buttons/playlist/repeat_one" ) );
}
-