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 */
34 #include <vlc_aout.h> /* Volume functions */
37 #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),
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;
69 /* Special view, click on button shows the slider */
72 volumeControlWidget = new QFrame;
73 subLayout = new QVBoxLayout( volumeControlWidget );
74 subLayout->setContentsMargins( 4, 4, 4, 4 );
75 volumeMenu = new QMenu( this );
77 QWidgetAction *widgetAction = new QWidgetAction( volumeControlWidget );
78 widgetAction->setDefaultWidget( volumeControlWidget );
79 volumeMenu->addAction( widgetAction );
82 /* And add the label */
83 layout->addWidget( volMuteLabel );
85 /* Slider creation: shiny or clean */
88 volumeSlider = new SoundSlider( this,
89 config_GetInt( p_intf, "volume-step" ),
90 var_InheritBool( p_intf, "qt-volume-complete" ),
91 var_InheritString( p_intf, "qt-slider-colours" ) );
95 volumeSlider = new QSlider( NULL );
96 volumeSlider->setAttribute( Qt::WA_MacSmallSize);
97 volumeSlider->setOrientation( b_special ? Qt::Vertical
99 volumeSlider->setMaximum( var_InheritBool( p_intf, "qt-volume-complete" )
103 volumeSlider->setFocusPolicy( Qt::NoFocus );
105 subLayout->addWidget( volumeSlider );
107 layout->addWidget( volumeSlider, 0, Qt::AlignBottom );
109 /* Set the volume from the config */
111 /* Force the update at build time in order to have a muted icon if needed */
114 /* Volume control connection */
115 CONNECT( volumeSlider, valueChanged( int ), this, refreshLabels( void ) );
116 CONNECT( volumeSlider, sliderMoved( int ), this, userUpdateVolume( int ) );
117 CONNECT( THEMIM, volumeChanged( void ), this, libUpdateVolume( void ) );
118 CONNECT( THEMIM, soundMuteChanged( void ), this, updateMuteStatus( void ) );
121 SoundWidget::~SoundWidget()
124 delete volumeControlWidget;
127 void SoundWidget::refreshLabels()
129 int i_sliderVolume = volumeSlider->value();
133 volMuteLabel->setPixmap( QPixmap(":/toolbar/volume-muted" ) );
134 volMuteLabel->setToolTip(qfu(vlc_pgettext("Tooltip|Unmute", "Unmute")));
138 if( i_sliderVolume < VOLUME_MAX / 3 )
139 volMuteLabel->setPixmap( QPixmap( ":/toolbar/volume-low" ) );
140 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
141 volMuteLabel->setPixmap( QPixmap( ":/toolbar/volume-high" ) );
142 else volMuteLabel->setPixmap( QPixmap( ":/toolbar/volume-medium" ) );
143 volMuteLabel->setToolTip( qfu(vlc_pgettext("Tooltip|Mute", "Mute")) );
146 /* volumeSlider changed value event slot */
147 void SoundWidget::userUpdateVolume( int i_sliderVolume )
149 /* Only if volume is set by user action on slider */
151 playlist_t *p_playlist = pl_Get( p_intf );
152 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
153 aout_VolumeSet( p_playlist, i_res );
156 /* libvlc changed value event slot */
157 void SoundWidget::libUpdateVolume()
160 audio_volume_t i_volume;
161 playlist_t *p_playlist = pl_Get( p_intf );
163 aout_VolumeGet( p_playlist, &i_volume );
164 i_volume = ( ( i_volume + 1 ) * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
165 int i_gauge = volumeSlider->value();
166 if ( !b_is_muted && /* do not show mute effect on volume (set to 0) */
167 ( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
170 volumeSlider->setValue( i_volume );
174 /* libvlc mute/unmute event slot */
175 void SoundWidget::updateMuteStatus()
177 playlist_t *p_playlist = pl_Get( p_intf );
178 b_is_muted = aout_IsMuted( VLC_OBJECT(p_playlist) );
180 SoundSlider *soundSlider = qobject_cast<SoundSlider *>(volumeSlider);
182 soundSlider->setMuted( b_is_muted );
186 void SoundWidget::showVolumeMenu( QPoint pos )
188 volumeMenu->setFixedHeight( volumeMenu->sizeHint().height() );
189 volumeMenu->exec( QCursor::pos() - pos - QPoint( 0, volumeMenu->height()/2 )
190 + QPoint( width(), height() /2) );
193 void SoundWidget::setMuted( bool mute )
196 playlist_t *p_playlist = pl_Get( p_intf );
197 aout_SetMute( VLC_OBJECT(p_playlist), NULL, mute );
200 bool SoundWidget::eventFilter( QObject *obj, QEvent *e )
203 if (e->type() == QEvent::MouseButtonPress )
205 if( volumeSlider->orientation() == Qt::Vertical )
207 QMouseEvent *event = static_cast<QMouseEvent*>(e);
208 showVolumeMenu( event->pos() );
212 setMuted( !b_is_muted );
227 void PlayButton::updateButton( bool b_playing )
229 setIcon( b_playing ? QIcon( ":/toolbar/pause_b" ) : QIcon( ":/toolbar/play_b" ) );
230 setToolTip( b_playing ? qtr( "Pause the playback" )
231 : qtr( I_PLAY_TOOLTIP ) );
234 void AtoB_Button::setIcons( bool timeA, bool timeB )
236 if( !timeA && !timeB)
238 setIcon( QIcon( ":/toolbar/atob_nob" ) );
239 setToolTip( qtr( "Loop from point A to point B continuously\n"
240 "Click to set point A" ) );
242 else if( timeA && !timeB )
244 setIcon( QIcon( ":/toolbar/atob_noa" ) );
245 setToolTip( qtr( "Click to set point B" ) );
247 else if( timeA && timeB )
249 setIcon( QIcon( ":/toolbar/atob" ) );
250 setToolTip( qtr( "Stop the A to B loop" ) );
254 void LoopButton::updateIcons( int value )
256 setChecked( value != NORMAL );
257 setIcon( ( value == REPEAT_ONE ) ? QIcon( ":/buttons/playlist/repeat_one" )
258 : QIcon( ":/buttons/playlist/repeat_all" ) );