]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/controller_widget.cpp
71b99a744eebf1fa1456bc0b9805014571a1dfe6
[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: Clément Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste Kempf <jb@videolan.org>
9  *          Rafaël Carré <funman@videolanorg>
10  *          Ilkka Ollakka <ileoo@videolan.org>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * ( at your option ) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25  *****************************************************************************/
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 //#include <vlc_vout.h>
32 //#include <vlc_keys.h>
33
34 #include "controller_widget.hpp"
35
36 #include "dialogs_provider.hpp"
37 #include "components/interface_widgets.hpp"
38 #include "main_interface.hpp"
39 #include "input_manager.hpp"
40 #include "menus.hpp"
41 #include "util/input_slider.hpp"
42 #include "util/customwidgets.hpp"
43
44 #include <QLabel>
45 #include <QSpacerItem>
46 #include <QCursor>
47 #include <QToolButton>
48 #include <QHBoxLayout>
49 #include <QMenu>
50 #include <QPalette>
51 #include <QResizeEvent>
52 #include <QDate>
53 #include <QSignalMapper>
54 #include <QTimer>
55
56
57 SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
58                           bool b_shiny )
59                          : b_my_volume( false ), QWidget( _parent )
60 {
61     p_intf = _p_intf;
62     QHBoxLayout *layout = new QHBoxLayout( this );
63     layout->setSpacing( 0 ); layout->setMargin( 0 );
64     hVolLabel = new VolumeClickHandler( p_intf, this );
65
66     volMuteLabel = new QLabel;
67     volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
68     volMuteLabel->installEventFilter( hVolLabel );
69     layout->addWidget( volMuteLabel );
70
71     if( b_shiny )
72     {
73         volumeSlider = new SoundSlider( this,
74             config_GetInt( p_intf, "volume-step" ),
75             config_GetInt( p_intf, "qt-volume-complete" ),
76             config_GetPsz( p_intf, "qt-slider-colours" ) );
77     }
78     else
79     {
80         volumeSlider = new QSlider( this );
81         volumeSlider->setOrientation( Qt::Horizontal );
82     }
83     volumeSlider->setMaximumSize( QSize( 200, 40 ) );
84     volumeSlider->setMinimumSize( QSize( 85, 30 ) );
85     volumeSlider->setFocusPolicy( Qt::NoFocus );
86     layout->addWidget( volumeSlider );
87
88     /* Set the volume from the config */
89     volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
90                               VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
91
92     /* Force the update at build time in order to have a muted icon if needed */
93     updateVolume( volumeSlider->value() );
94
95     /* Volume control connection */
96     CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
97     CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
98 }
99
100 void SoundWidget::updateVolume( int i_sliderVolume )
101 {
102     if( !b_my_volume )
103     {
104         int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
105         aout_VolumeSet( p_intf, i_res );
106     }
107     if( i_sliderVolume == 0 )
108     {
109         volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
110         volMuteLabel->setToolTip( qtr( "Unmute" ) );
111         return;
112     }
113
114     if( i_sliderVolume < VOLUME_MAX / 3 )
115         volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
116     else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
117         volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
118     else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
119     volMuteLabel->setToolTip( qtr( "Mute" ) );
120 }
121
122 void SoundWidget::updateVolume()
123 {
124     /* Audio part */
125     audio_volume_t i_volume;
126     aout_VolumeGet( p_intf, &i_volume );
127     i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
128     int i_gauge = volumeSlider->value();
129     b_my_volume = false;
130     if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
131     {
132         b_my_volume = true;
133         volumeSlider->setValue( i_volume );
134         b_my_volume = false;
135     }
136 }
137
138 void TeletextController::toggleTeletextTransparency( bool b_transparent )
139 {
140     telexTransparent->setIcon( b_transparent ? QIcon( ":/tvtelx" )
141                                              : QIcon( ":/tvtelx-trans" ) );
142 }
143
144 void TeletextController::enableTeletextButtons( bool b_enabled )
145 {
146     telexOn->setChecked( b_enabled );
147     telexTransparent->setEnabled( b_enabled );
148     telexPage->setEnabled( b_enabled );
149 }
150
151 void PlayButton::updateButton( bool b_playing )
152 {
153     setIcon( b_playing ? QIcon( ":/pause_b" ) : QIcon( ":/play_b" ) );
154     setToolTip( b_playing ? qtr( "Pause the playback" )
155                           : qtr( I_PLAY_TOOLTIP ) );
156 }
157
158 void AtoB_Button::setIcons( bool timeA, bool timeB )
159 {
160     if( !timeA && !timeB)
161     {
162         setIcon( QIcon( ":/atob_nob" ) );
163         setToolTip( qtr( "Loop from point A to point B continuously\n"
164                          "Click to set point A" ) );
165     }
166     else if( timeA && !timeB )
167     {
168         setIcon( QIcon( ":/atob_noa" ) );
169         setToolTip( qtr( "Click to set point B" ) );
170     }
171     else if( timeA && timeB )
172     {
173         setIcon( QIcon( ":/atob" ) );
174         setToolTip( qtr( "Stop the A to B loop" ) );
175     }
176 }
177