]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/controller_widget.cpp
Qt: Teletext handling simplifications and change of the icons to more clear ones.
[vlc] / modules / gui / qt4 / components / controller_widget.cpp
1 /*****************************************************************************
2  * Controller_widget.cpp : Controller Widget for the controllers
3  ****************************************************************************
4  * Copyright (C) 2006-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Jean-Baptiste Kempf <jb@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include "controller_widget.hpp"
29
30 #include "input_manager.hpp"         /* Get notification of Volume Change */
31 #include "util/input_slider.hpp"     /* SoundSlider */
32
33 #include <vlc_aout.h>                /* Volume functions */
34
35 #include <QLabel>
36 #include <QHBoxLayout>
37 #include <QSpinBox>
38
39 SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
40                           bool b_shiny )
41                          : QWidget( _parent ), b_my_volume( false )
42 {
43     p_intf = _p_intf;
44     QHBoxLayout *layout = new QHBoxLayout( this );
45     layout->setSpacing( 0 ); layout->setMargin( 0 );
46     hVolLabel = new VolumeClickHandler( p_intf, this );
47
48     volMuteLabel = new QLabel;
49     volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
50     volMuteLabel->installEventFilter( hVolLabel );
51     layout->addWidget( volMuteLabel );
52
53     if( b_shiny )
54     {
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" ) );
59     }
60     else
61     {
62         volumeSlider = new QSlider( this );
63         volumeSlider->setOrientation( Qt::Horizontal );
64         volumeSlider->setMaximum( config_GetInt( p_intf, "qt-volume-complete" )
65                                   ? 400 : 200 );
66     }
67     volumeSlider->setMaximumSize( QSize( 200, 40 ) );
68     volumeSlider->setMinimumSize( QSize( 85, 30 ) );
69     volumeSlider->setFocusPolicy( Qt::NoFocus );
70     layout->addWidget( volumeSlider );
71
72     /* Set the volume from the config */
73     volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
74                               VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
75
76     /* Force the update at build time in order to have a muted icon if needed */
77     updateVolume( volumeSlider->value() );
78
79     /* Volume control connection */
80     CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
81     CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
82 }
83
84 void SoundWidget::updateVolume( int i_sliderVolume )
85 {
86     if( !b_my_volume )
87     {
88         int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
89         aout_VolumeSet( p_intf, i_res );
90     }
91     if( i_sliderVolume == 0 )
92     {
93         volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
94         volMuteLabel->setToolTip( qtr( "Unmute" ) );
95         return;
96     }
97
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" ) );
104 }
105
106 void SoundWidget::updateVolume()
107 {
108     /* Audio part */
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();
113     b_my_volume = false;
114     if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
115     {
116         b_my_volume = true;
117         volumeSlider->setValue( i_volume );
118         b_my_volume = false;
119     }
120 }
121
122 void TeletextController::enableTeletextButtons( bool b_enabled )
123 {
124     telexOn->setChecked( b_enabled );
125     telexTransparent->setEnabled( b_enabled );
126     telexPage->setEnabled( b_enabled );
127 }
128
129 void PlayButton::updateButton( bool b_playing )
130 {
131     setIcon( b_playing ? QIcon( ":/pause_b" ) : QIcon( ":/play_b" ) );
132     setToolTip( b_playing ? qtr( "Pause the playback" )
133                           : qtr( I_PLAY_TOOLTIP ) );
134 }
135
136 void AtoB_Button::setIcons( bool timeA, bool timeB )
137 {
138     if( !timeA && !timeB)
139     {
140         setIcon( QIcon( ":/atob_nob" ) );
141         setToolTip( qtr( "Loop from point A to point B continuously\n"
142                          "Click to set point A" ) );
143     }
144     else if( timeA && !timeB )
145     {
146         setIcon( QIcon( ":/atob_noa" ) );
147         setToolTip( qtr( "Click to set point B" ) );
148     }
149     else if( timeA && timeB )
150     {
151         setIcon( QIcon( ":/atob" ) );
152         setToolTip( qtr( "Stop the A to B loop" ) );
153     }
154 }
155
156 bool VolumeClickHandler::eventFilter( QObject *obj, QEvent *e )
157 {
158     VLC_UNUSED( obj );
159     if (e->type() == QEvent::MouseButtonPress  )
160     {
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) );
165         e->accept();
166         return true;
167     }
168     else
169     {
170         e->ignore();
171         return false;
172     }
173 }
174