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"
30 #include "input_manager.hpp" /* Get notification of Volume Change */
31 #include "util/input_slider.hpp" /* SoundSlider */
33 #include <vlc_aout.h> /* Volume functions */
36 #include <QHBoxLayout>
39 #include <QWidgetAction>
40 #include <QMouseEvent>
42 SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
43 bool b_shiny, bool b_special )
44 : QWidget( _parent ), b_my_volume( false ),
47 /* We need a layout for this widget */
48 QHBoxLayout *layout = new QHBoxLayout( this );
49 layout->setSpacing( 0 ); layout->setMargin( 0 );
51 /* We need a Label for the pix */
52 volMuteLabel = new QLabel;
53 volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
55 /* We might need a subLayout too */
56 QVBoxLayout *subLayout;
58 volMuteLabel->installEventFilter( this );
60 /* Normal View, click on icon mutes */
63 volumeMenu = NULL; subLayout = NULL;
67 /* Special view, click on button shows the slider */
70 QFrame *volumeControlWidget = new QFrame;
71 subLayout = new QVBoxLayout( volumeControlWidget );
72 subLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
73 volumeMenu = new QMenu( this );
75 QWidgetAction *widgetAction = new QWidgetAction( volumeControlWidget );
76 widgetAction->setDefaultWidget( volumeControlWidget );
77 volumeMenu->addAction( widgetAction );
80 /* And add the label */
81 layout->addWidget( volMuteLabel );
83 /* Slider creation: shiny or clean */
86 volumeSlider = new SoundSlider( this,
87 config_GetInt( p_intf, "volume-step" ),
88 config_GetInt( p_intf, "qt-volume-complete" ),
89 config_GetPsz( p_intf, "qt-slider-colours" ) );
93 volumeSlider = new QSlider( NULL );
94 volumeSlider->setOrientation( b_special ? Qt::Vertical
96 volumeSlider->setMaximum( config_GetInt( p_intf, "qt-volume-complete" )
99 if( volumeSlider->orientation() == Qt::Horizontal )
101 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
102 volumeSlider->setMinimumSize( QSize( 85, 30 ) );
105 volumeSlider->setFocusPolicy( Qt::NoFocus );
107 subLayout->addWidget( volumeSlider );
109 layout->addWidget( volumeSlider );
111 /* Set the volume from the config */
112 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
113 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
115 /* Force the update at build time in order to have a muted icon if needed */
116 updateVolume( volumeSlider->value() );
118 /* Volume control connection */
119 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
120 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
123 void SoundWidget::updateVolume( int i_sliderVolume )
127 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
128 aout_VolumeSet( p_intf, i_res );
130 if( i_sliderVolume == 0 )
132 volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
133 volMuteLabel->setToolTip( qtr( "Unmute" ) );
137 if( i_sliderVolume < VOLUME_MAX / 3 )
138 volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
139 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
140 volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
141 else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
142 volMuteLabel->setToolTip( qtr( "Mute" ) );
145 void SoundWidget::updateVolume()
148 audio_volume_t i_volume;
149 aout_VolumeGet( p_intf, &i_volume );
150 i_volume = ( ( i_volume + 1 ) * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
151 int i_gauge = volumeSlider->value();
153 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
156 volumeSlider->setValue( i_volume );
161 void SoundWidget::showVolumeMenu( QPoint pos )
163 volumeMenu->exec( QCursor::pos() - pos - QPoint( 0, volumeMenu->height()/2 )
164 + QPoint( width(), height() /2) );
167 bool SoundWidget::eventFilter( QObject *obj, QEvent *e )
170 if (e->type() == QEvent::MouseButtonPress )
172 if( volumeSlider->orientation() == Qt::Vertical )
174 QMouseEvent *event = static_cast<QMouseEvent*>(e);
175 showVolumeMenu( event->pos() );
179 aout_VolumeMute( p_intf, NULL );
194 void PlayButton::updateButton( bool b_playing )
196 setIcon( b_playing ? QIcon( ":/pause_b" ) : QIcon( ":/play_b" ) );
197 setToolTip( b_playing ? qtr( "Pause the playback" )
198 : qtr( I_PLAY_TOOLTIP ) );
201 void AtoB_Button::setIcons( bool timeA, bool timeB )
203 if( !timeA && !timeB)
205 setIcon( QIcon( ":/atob_nob" ) );
206 setToolTip( qtr( "Loop from point A to point B continuously\n"
207 "Click to set point A" ) );
209 else if( timeA && !timeB )
211 setIcon( QIcon( ":/atob_noa" ) );
212 setToolTip( qtr( "Click to set point B" ) );
214 else if( timeA && timeB )
216 setIcon( QIcon( ":/atob" ) );
217 setToolTip( qtr( "Stop the A to B loop" ) );