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 SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
41 : QWidget( _parent ), b_my_volume( false )
44 QHBoxLayout *layout = new QHBoxLayout( this );
45 layout->setSpacing( 0 ); layout->setMargin( 0 );
46 hVolLabel = new VolumeClickHandler( p_intf, this );
48 volMuteLabel = new QLabel;
49 volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
50 volMuteLabel->installEventFilter( hVolLabel );
51 layout->addWidget( volMuteLabel );
55 volumeSlider = new SoundSlider( this,
56 config_GetInt( p_intf, "volume-step" ),
57 config_GetInt( p_intf, "qt-volume-complete" ),
58 config_GetPsz( p_intf, "qt-slider-colours" ) );
62 volumeSlider = new QSlider( this );
63 volumeSlider->setOrientation( Qt::Horizontal );
64 volumeSlider->setMaximum( config_GetInt( p_intf, "qt-volume-complete" )
67 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
68 volumeSlider->setMinimumSize( QSize( 85, 30 ) );
69 volumeSlider->setFocusPolicy( Qt::NoFocus );
70 layout->addWidget( volumeSlider );
72 /* Set the volume from the config */
73 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
74 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
76 /* Force the update at build time in order to have a muted icon if needed */
77 updateVolume( volumeSlider->value() );
79 /* Volume control connection */
80 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
81 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
84 void SoundWidget::updateVolume( int i_sliderVolume )
88 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
89 aout_VolumeSet( p_intf, i_res );
91 if( i_sliderVolume == 0 )
93 volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
94 volMuteLabel->setToolTip( qtr( "Unmute" ) );
98 if( i_sliderVolume < VOLUME_MAX / 3 )
99 volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
100 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
101 volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
102 else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
103 volMuteLabel->setToolTip( qtr( "Mute" ) );
106 void SoundWidget::updateVolume()
109 audio_volume_t i_volume;
110 aout_VolumeGet( p_intf, &i_volume );
111 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
112 int i_gauge = volumeSlider->value();
114 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
117 volumeSlider->setValue( i_volume );
122 void TeletextController::enableTeletextButtons( bool b_enabled )
124 telexOn->setChecked( b_enabled );
125 telexTransparent->setEnabled( b_enabled );
126 telexPage->setEnabled( b_enabled );
129 void PlayButton::updateButton( bool b_playing )
131 setIcon( b_playing ? QIcon( ":/pause_b" ) : QIcon( ":/play_b" ) );
132 setToolTip( b_playing ? qtr( "Pause the playback" )
133 : qtr( I_PLAY_TOOLTIP ) );
136 void AtoB_Button::setIcons( bool timeA, bool timeB )
138 if( !timeA && !timeB)
140 setIcon( QIcon( ":/atob_nob" ) );
141 setToolTip( qtr( "Loop from point A to point B continuously\n"
142 "Click to set point A" ) );
144 else if( timeA && !timeB )
146 setIcon( QIcon( ":/atob_noa" ) );
147 setToolTip( qtr( "Click to set point B" ) );
149 else if( timeA && timeB )
151 setIcon( QIcon( ":/atob" ) );
152 setToolTip( qtr( "Stop the A to B loop" ) );
156 bool VolumeClickHandler::eventFilter( QObject *obj, QEvent *e )
159 if (e->type() == QEvent::MouseButtonPress )
161 aout_VolumeMute( p_intf, NULL );
162 audio_volume_t i_volume;
163 aout_VolumeGet( p_intf, &i_volume );
164 // m->updateVolume( i_volume * VOLUME_MAX / (AOUT_VOLUME_MAX/2) );