1 /*****************************************************************************
2 * controller_widget.cpp : Controller Widget for the controllers
3 ****************************************************************************
4 * Copyright (C) 2006-2008 the VideoLAN team
7 * Authors: Jean-Baptiste Kempf <jb@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * ( at your option ) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
28 #include "controller_widget.hpp"
29 #include "controller.hpp"
31 #include "input_manager.hpp" /* Get notification of Volume Change */
32 #include "util/input_slider.hpp" /* SoundSlider */
35 #include <vlc_aout_intf.h> /* Volume functions */
38 #include <QHBoxLayout>
40 #include <QWidgetAction>
41 #include <QMouseEvent>
43 SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
44 bool b_shiny, bool b_special )
45 : QWidget( _parent ), p_intf( _p_intf),
46 b_is_muted( false ), b_ignore_valuechanged( false )
48 /* We need a layout for this widget */
49 QHBoxLayout *layout = new QHBoxLayout( this );
50 layout->setSpacing( 0 ); layout->setMargin( 0 );
52 /* We need a Label for the pix */
53 volMuteLabel = new QLabel;
54 volMuteLabel->setPixmap( QPixmap( ":/toolbar/volume-medium" ) );
56 /* We might need a subLayout too */
57 QVBoxLayout *subLayout;
59 volMuteLabel->installEventFilter( this );
61 /* Normal View, click on icon mutes */
64 volumeMenu = NULL; subLayout = NULL;
65 volumeControlWidget = NULL;
67 /* And add the label */
68 layout->addWidget( volMuteLabel, 0, Qt::AlignBottom );
72 /* Special view, click on button shows the slider */
75 volumeControlWidget = new QFrame;
76 subLayout = new QVBoxLayout( volumeControlWidget );
77 subLayout->setContentsMargins( 4, 4, 4, 4 );
78 volumeMenu = new QMenu( this );
80 QWidgetAction *widgetAction = new QWidgetAction( volumeControlWidget );
81 widgetAction->setDefaultWidget( volumeControlWidget );
82 volumeMenu->addAction( widgetAction );
84 /* And add the label */
85 layout->addWidget( volMuteLabel );
88 /* Slider creation: shiny or clean */
91 volumeSlider = new SoundSlider( this,
92 config_GetInt( p_intf, "volume-step" ),
94 var_InheritString( p_intf, "qt-slider-colours" ) );
98 volumeSlider = new QSlider( NULL );
99 volumeSlider->setAttribute( Qt::WA_MacSmallSize);
100 volumeSlider->setOrientation( b_special ? Qt::Vertical
102 volumeSlider->setMaximum( 200 );
105 volumeSlider->setFocusPolicy( Qt::NoFocus );
107 subLayout->addWidget( volumeSlider );
109 layout->addWidget( volumeSlider, 0, Qt::AlignBottom );
111 /* Set the volume from the config */
112 float volume = aout_VolumeGet( THEPL );
113 libUpdateVolume( (volume >= 0.f) ? volume : 1.f );
114 /* Sync mute status */
115 if( aout_MuteGet( THEPL ) > 0 )
116 updateMuteStatus( true );
118 /* Volume control connection */
119 volumeSlider->setTracking( true );
120 CONNECT( volumeSlider, valueChanged( int ), this, valueChangedFilter( int ) );
121 CONNECT( this, valueReallyChanged( int ), this, userUpdateVolume( int ) );
122 CONNECT( THEMIM, volumeChanged( float ), this, libUpdateVolume( float ) );
123 CONNECT( THEMIM, soundMuteChanged( bool ), this, updateMuteStatus( bool ) );
126 SoundWidget::~SoundWidget()
129 delete volumeControlWidget;
132 void SoundWidget::refreshLabels()
134 int i_sliderVolume = volumeSlider->value();
138 volMuteLabel->setPixmap( QPixmap(":/toolbar/volume-muted" ) );
139 volMuteLabel->setToolTip(qfu(vlc_pgettext("Tooltip|Unmute", "Unmute")));
143 if( i_sliderVolume < VOLUME_MAX / 3 )
144 volMuteLabel->setPixmap( QPixmap( ":/toolbar/volume-low" ) );
145 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
146 volMuteLabel->setPixmap( QPixmap( ":/toolbar/volume-high" ) );
147 else volMuteLabel->setPixmap( QPixmap( ":/toolbar/volume-medium" ) );
148 volMuteLabel->setToolTip( qfu(vlc_pgettext("Tooltip|Mute", "Mute")) );
151 /* volumeSlider changed value event slot */
152 void SoundWidget::userUpdateVolume( int i_sliderVolume )
154 /* Only if volume is set by user action on slider */
156 aout_VolumeSet( THEPL, i_sliderVolume / 100.f );
160 /* libvlc changed value event slot */
161 void SoundWidget::libUpdateVolume( float volume )
163 long i_volume = lroundf(volume * 100.f);
164 if( i_volume != volumeSlider->value() )
166 b_ignore_valuechanged = true;
167 volumeSlider->setValue( i_volume );
168 b_ignore_valuechanged = false;
173 void SoundWidget::valueChangedFilter( int i_val )
175 /* valueChanged is also emitted when the lib setValue() */
176 if ( !b_ignore_valuechanged ) emit valueReallyChanged( i_val );
179 /* libvlc mute/unmute event slot */
180 void SoundWidget::updateMuteStatus( bool mute )
184 SoundSlider *soundSlider = qobject_cast<SoundSlider *>(volumeSlider);
186 soundSlider->setMuted( mute );
190 void SoundWidget::showVolumeMenu( QPoint pos )
192 volumeMenu->setFixedHeight( volumeMenu->sizeHint().height() );
193 volumeMenu->exec( QCursor::pos() - pos - QPoint( 0, volumeMenu->height()/2 )
194 + QPoint( width(), height() /2) );
197 void SoundWidget::setMuted( bool mute )
200 playlist_t *p_playlist = pl_Get( p_intf );
201 aout_MuteSet( VLC_OBJECT(p_playlist), mute );
204 bool SoundWidget::eventFilter( QObject *obj, QEvent *e )
207 if( e->type() == QEvent::MouseButtonPress )
209 QMouseEvent *event = static_cast<QMouseEvent*>(e);
210 if( event->button() == Qt::LeftButton )
212 if( volumeSlider->orientation() == Qt::Vertical )
214 showVolumeMenu( event->pos() );
218 setMuted( !b_is_muted );
231 void PlayButton::updateButtonIcons( bool b_playing )
233 setIcon( b_playing ? QIcon( ":/toolbar/pause_b" ) : QIcon( ":/toolbar/play_b" ) );
234 setToolTip( b_playing ? qtr( "Pause the playback" )
235 : qtr( I_PLAY_TOOLTIP ) );
238 void AtoB_Button::updateButtonIcons( bool timeA, bool timeB )
240 if( !timeA && !timeB)
242 setIcon( QIcon( ":/toolbar/atob_nob" ) );
243 setToolTip( qtr( "Loop from point A to point B continuously\n"
244 "Click to set point A" ) );
246 else if( timeA && !timeB )
248 setIcon( QIcon( ":/toolbar/atob_noa" ) );
249 setToolTip( qtr( "Click to set point B" ) );
251 else if( timeA && timeB )
253 setIcon( QIcon( ":/toolbar/atob" ) );
254 setToolTip( qtr( "Stop the A to B loop" ) );
258 void LoopButton::updateButtonIcons( int value )
260 setChecked( value != NORMAL );
261 setIcon( ( value == REPEAT_ONE ) ? QIcon( ":/buttons/playlist/repeat_one" )
262 : QIcon( ":/buttons/playlist/repeat_all" ) );
265 void AspectRatioComboBox::updateRatios()
267 /* Clear the list before updating */
269 vlc_value_t val_list, text_list;
270 vout_thread_t* p_vout = THEMIM->getVout();
272 /* Disable if there is no vout */
275 addItem( qtr("Aspect Ratio") );
280 var_Change( p_vout, "aspect-ratio", VLC_VAR_GETLIST, &val_list, &text_list );
281 for( int i = 0; i < val_list.p_list->i_count; i++ )
282 addItem( qfu( text_list.p_list->p_values[i].psz_string ),
283 QString( val_list.p_list->p_values[i].psz_string ) );
285 var_FreeList( &val_list, &text_list );
286 vlc_object_release( p_vout );
289 void AspectRatioComboBox::updateAspectRatio( int x )
291 vout_thread_t* p_vout = THEMIM->getVout();
292 if( p_vout && x >= 0 )
294 var_SetString( p_vout, "aspect-ratio", qtu( itemData(x).toString() ) );
297 vlc_object_release( p_vout );