X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fqt4%2Fcomponents%2Fcontroller_widget.cpp;h=90b36a1efa4141ce34a888134a671cd0546b6841;hb=b092d34b5912504ea8653b106c4ec02ca9f45978;hp=71b99a744eebf1fa1456bc0b9805014571a1dfe6;hpb=d525a3531364577c561e6fbb33e9319326dbb0be;p=vlc diff --git a/modules/gui/qt4/components/controller_widget.cpp b/modules/gui/qt4/components/controller_widget.cpp index 71b99a744e..90b36a1efa 100644 --- a/modules/gui/qt4/components/controller_widget.cpp +++ b/modules/gui/qt4/components/controller_widget.cpp @@ -1,13 +1,10 @@ /***************************************************************************** - * Controller_widget.cpp : Controller Widget for the controllers + * controller_widget.cpp : Controller Widget for the controllers **************************************************************************** - * Copyright ( C ) 2006-2008 the VideoLAN team + * Copyright (C) 2006-2008 the VideoLAN team * $Id$ * - * Authors: Clément Stenac - * Jean-Baptiste Kempf - * Rafaël Carré - * Ilkka Ollakka + * Authors: Jean-Baptiste Kempf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,150 +25,278 @@ # include "config.h" #endif -//#include -//#include - #include "controller_widget.hpp" +#include "controller.hpp" + +#include "input_manager.hpp" /* Get notification of Volume Change */ +#include "util/input_slider.hpp" /* SoundSlider */ -#include "dialogs_provider.hpp" -#include "components/interface_widgets.hpp" -#include "main_interface.hpp" -#include "input_manager.hpp" -#include "menus.hpp" -#include "util/input_slider.hpp" -#include "util/customwidgets.hpp" +#include +#include /* Volume functions */ #include -#include -#include -#include #include #include -#include -#include -#include -#include -#include - +#include +#include SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf, - bool b_shiny ) - : b_my_volume( false ), QWidget( _parent ) + bool b_shiny, bool b_special ) + : QWidget( _parent ), p_intf( _p_intf), + b_is_muted( false ), b_ignore_valuechanged( 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 ); - layout->addWidget( volMuteLabel ); + 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; + + /* And add the label */ + layout->addWidget( volMuteLabel, 0, Qt::AlignBottom ); + } + 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, config_GetInt( p_intf, "volume-step" ), - config_GetInt( p_intf, "qt-volume-complete" ), - config_GetPsz( p_intf, "qt-slider-colours" ) ); + false, + var_InheritString( p_intf, "qt-slider-colours" ) ); } else { - volumeSlider = new QSlider( this ); - volumeSlider->setOrientation( Qt::Horizontal ); + volumeSlider = new QSlider( NULL ); + volumeSlider->setAttribute( Qt::WA_MacSmallSize); + volumeSlider->setOrientation( b_special ? Qt::Vertical + : Qt::Horizontal ); + volumeSlider->setMaximum( 200 ); } - 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) ); - - /* Force the update at build time in order to have a muted icon if needed */ - updateVolume( volumeSlider->value() ); + libUpdateVolume(); + /* Sync mute status */ + if( aout_MuteGet( THEPL ) > 0 ) + updateMuteStatus( true ); /* Volume control connection */ - CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) ); - CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) ); + volumeSlider->setTracking( true ); + CONNECT( volumeSlider, valueChanged( int ), this, valueChangedFilter( int ) ); + CONNECT( this, valueReallyChanged( int ), this, userUpdateVolume( int ) ); + CONNECT( THEMIM, volumeChanged( void ), this, libUpdateVolume( void ) ); + CONNECT( THEMIM, soundMuteChanged( bool ), this, updateMuteStatus( bool ) ); } -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")) ); } -void SoundWidget::updateVolume() +/* 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_Get( p_intf ); + aout_VolumeSet( p_playlist, i_sliderVolume / 100.f ); + refreshLabels(); +} + +/* 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); - int i_gauge = volumeSlider->value(); - b_my_volume = false; - if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 ) + playlist_t *p_playlist = pl_Get( p_intf ); + long i_volume = lroundf(aout_VolumeGet( p_playlist ) * 100.f); + + if ( i_volume - volumeSlider->value() != 0 ) { - b_my_volume = true; + b_ignore_valuechanged = true; volumeSlider->setValue( i_volume ); - b_my_volume = false; + b_ignore_valuechanged = false; } + refreshLabels(); } -void TeletextController::toggleTeletextTransparency( bool b_transparent ) +void SoundWidget::valueChangedFilter( int i_val ) { - telexTransparent->setIcon( b_transparent ? QIcon( ":/tvtelx" ) - : QIcon( ":/tvtelx-trans" ) ); + /* valueChanged is also emitted when the lib setValue() */ + if ( !b_ignore_valuechanged ) emit valueReallyChanged( i_val ); } -void TeletextController::enableTeletextButtons( bool b_enabled ) +/* libvlc mute/unmute event slot */ +void SoundWidget::updateMuteStatus( bool mute ) { - telexOn->setChecked( b_enabled ); - telexTransparent->setEnabled( b_enabled ); - telexPage->setEnabled( b_enabled ); + b_is_muted = mute; + + SoundSlider *soundSlider = qobject_cast(volumeSlider); + if( soundSlider ) + soundSlider->setMuted( mute ); + refreshLabels(); +} + +void SoundWidget::showVolumeMenu( QPoint pos ) +{ + 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_Get( p_intf ); + aout_MuteSet( VLC_OBJECT(p_playlist), mute ); } -void PlayButton::updateButton( bool b_playing ) +bool SoundWidget::eventFilter( QObject *obj, QEvent *e ) { - setIcon( b_playing ? QIcon( ":/pause_b" ) : QIcon( ":/play_b" ) ); + VLC_UNUSED( obj ); + if( e->type() == QEvent::MouseButtonPress ) + { + QMouseEvent *event = static_cast(e); + if( event->button() == Qt::LeftButton ) + { + if( volumeSlider->orientation() == Qt::Vertical ) + { + showVolumeMenu( event->pos() ); + } + else + { + setMuted( !b_is_muted ); + } + e->accept(); + return true; + } + } + e->ignore(); + return false; +} + +/** + * Play Button + **/ +void PlayButton::updateButtonIcons( bool b_playing ) +{ + setIcon( b_playing ? QIcon( ":/toolbar/pause_b" ) : QIcon( ":/toolbar/play_b" ) ); setToolTip( b_playing ? qtr( "Pause the playback" ) : qtr( I_PLAY_TOOLTIP ) ); } -void AtoB_Button::setIcons( bool timeA, bool timeB ) +void AtoB_Button::updateButtonIcons( bool timeA, bool timeB ) { 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" ) ); } } +void LoopButton::updateButtonIcons( int value ) +{ + setChecked( value != NORMAL ); + setIcon( ( value == REPEAT_ONE ) ? QIcon( ":/buttons/playlist/repeat_one" ) + : QIcon( ":/buttons/playlist/repeat_all" ) ); +} + +void AspectRatioComboBox::updateRatios() +{ + /* Clear the list before updating */ + clear(); + vlc_value_t val_list, text_list; + vout_thread_t* p_vout = THEMIM->getVout(); + + /* Disable if there is no vout */ + if( p_vout == NULL ) + { + addItem( qtr("Aspect Ratio") ); + setDisabled( true ); + return; + } + + var_Change( p_vout, "aspect-ratio", VLC_VAR_GETLIST, &val_list, &text_list ); + for( int i = 0; i < val_list.p_list->i_count; i++ ) + addItem( qfu( text_list.p_list->p_values[i].psz_string ), + QString( val_list.p_list->p_values[i].psz_string ) ); + setEnabled( true ); + var_FreeList( &val_list, &text_list ); + vlc_object_release( p_vout ); +} + +void AspectRatioComboBox::updateAspectRatio( int x ) +{ + vout_thread_t* p_vout = THEMIM->getVout(); + if( p_vout && x >= 0 ) + { + var_SetString( p_vout, "aspect-ratio", qtu( itemData(x).toString() ) ); + } + if( p_vout ) + vlc_object_release( p_vout ); +} +