]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
1bf430a0453f4f8c2e401002744bebd5951ee56b
[vlc] / modules / gui / qt4 / components / interface_widgets.cpp
1 /*****************************************************************************
2  * interface_widgets.cpp : Custom widgets for the main interface
3  ****************************************************************************
4  * Copyright ( C ) 2006 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
33 #include "dialogs_provider.hpp"
34 #include "components/interface_widgets.hpp"
35 #include "main_interface.hpp"
36 #include "input_manager.hpp"
37 #include "menus.hpp"
38 #include "util/input_slider.hpp"
39 #include "util/customwidgets.hpp"
40
41 #include <QLabel>
42 #include <QSpacerItem>
43 #include <QCursor>
44 #include <QPushButton>
45 #include <QToolButton>
46 #include <QHBoxLayout>
47 #include <QMenu>
48 #include <QPalette>
49 #include <QResizeEvent>
50 #include <QDate>
51
52 #ifdef Q_WS_X11
53 # include <X11/Xlib.h>
54 # include <qx11info_x11.h>
55 #endif
56
57 #include <math.h>
58
59 #define I_PLAY_TOOLTIP N_("Play\nIf the playlist is empty, open a media")
60
61 /**********************************************************************
62  * Video Widget. A simple frame on which video is drawn
63  * This class handles resize issues
64  **********************************************************************/
65
66 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
67 {
68     /* Init */
69     i_vout = 0;
70     hide(); setMinimumSize( 16, 16 );
71     videoSize.rwidth() = -1;
72     videoSize.rheight() = -1;
73     setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
74
75     /* Black background is more coherent for a Video Widget IMVHO */
76     QPalette plt =  palette();
77     plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
78     plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
79     setPalette( plt );
80     setAttribute( Qt::WA_PaintOnScreen, true );
81
82     /* The core can ask through a callback to show the video. */
83 #if HAS_QT43
84     connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
85              this, SLOT(SetSizing(unsigned int, unsigned int )),
86              Qt::BlockingQueuedConnection );
87 #else
88 #error This is broken. Fix it with a QEventLoop with a processEvents () 
89     connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
90              this, SLOT(SetSizing(unsigned int, unsigned int )) );
91 #endif
92 }
93
94 void VideoWidget::paintEvent(QPaintEvent *ev)
95 {
96     QFrame::paintEvent(ev);
97 #ifdef Q_WS_X11
98     XFlush( QX11Info::display() );
99 #endif
100 }
101
102 VideoWidget::~VideoWidget()
103 {
104     vout_thread_t *p_vout = i_vout
105         ? (vout_thread_t *)vlc_object_get( i_vout ) : NULL;
106
107     if( p_vout )
108     {
109         if( !p_intf->psz_switch_intf )
110         {
111             if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
112                 vout_Control( p_vout, VOUT_REPARENT );
113         }
114         else
115         {
116             if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
117                 vout_Control( p_vout, VOUT_CLOSE );
118         }
119         vlc_object_release( p_vout );
120     }
121 }
122
123 /**
124  * Request the video to avoid the conflicts
125  **/
126 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
127                             unsigned int *pi_width, unsigned int *pi_height )
128 {
129     msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
130     emit askVideoWidgetToShow( *pi_width, *pi_height );
131     if( i_vout )
132     {
133         msg_Dbg( p_intf, "embedded video already in use" );
134         return NULL;
135     }
136     i_vout = p_nvout->i_object_id;
137     msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );
138     return ( void* )winId();
139 }
140
141 /* Set the Widget to the correct Size */
142 /* Function has to be called by the parent
143    Parent has to care about resizing himself*/
144 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
145 {
146     msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
147     videoSize.rwidth() = w;
148     videoSize.rheight() = h;
149     if( isHidden() ) show();
150     updateGeometry(); // Needed for deinterlace
151 }
152
153 void VideoWidget::release( void *p_win )
154 {
155     msg_Dbg( p_intf, "Video is not needed anymore" );
156     i_vout = 0;
157     videoSize.rwidth() = 0;
158     videoSize.rheight() = 0;
159     hide();
160     updateGeometry(); // Needed for deinterlace
161 }
162
163 QSize VideoWidget::sizeHint() const
164 {
165     return videoSize;
166 }
167
168 /**********************************************************************
169  * Background Widget. Show a simple image background. Currently,
170  * it's album art if present or cone.
171  **********************************************************************/
172 #define ICON_SIZE 128
173 #define MAX_BG_SIZE 400
174 #define MIN_BG_SIZE 64
175
176 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
177                  :QWidget( NULL ), p_intf( _p_i )
178 {
179     /* We should use that one to take the more size it can */
180     setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding);
181
182     /* A dark background */
183     setAutoFillBackground( true );
184     plt =  palette();
185     plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
186     plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
187     setPalette( plt );
188
189     /* A cone in the middle */
190     label = new QLabel;
191     label->setMargin( 5 );
192     label->setMaximumHeight( MAX_BG_SIZE );
193     label->setMaximumWidth( MAX_BG_SIZE );
194     label->setMinimumHeight( MIN_BG_SIZE );
195     label->setMinimumWidth( MIN_BG_SIZE );
196     if( QDate::currentDate().dayOfYear() >= 354 )
197         label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
198     else
199         label->setPixmap( QPixmap( ":/vlc128.png" ) );
200
201     QGridLayout *backgroundLayout = new QGridLayout( this );
202     backgroundLayout->addWidget( label, 0, 1 );
203     backgroundLayout->setColumnStretch( 0, 1 );
204     backgroundLayout->setColumnStretch( 2, 1 );
205
206     CONNECT( THEMIM->getIM(), artChanged( QString ), this, updateArt( QString ) );
207 }
208
209 BackgroundWidget::~BackgroundWidget()
210 {}
211
212 void BackgroundWidget::resizeEvent( QResizeEvent * event )
213 {
214     if( event->size().height() <= MIN_BG_SIZE )
215         label->hide();
216     else
217         label->show();
218 }
219
220 void BackgroundWidget::updateArt( QString url )
221 {
222     if( url.isEmpty() )
223     {
224         if( QDate::currentDate().dayOfYear() >= 354 )
225             label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
226         else
227             label->setPixmap( QPixmap( ":/vlc128.png" ) );
228         return;
229     }
230     else
231     {
232         label->setPixmap( QPixmap( url ) );
233     }
234 }
235
236 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
237 {
238     QVLCMenu::PopupMenu( p_intf, true );
239 }
240
241 #if 0
242 /**********************************************************************
243  * Visualization selector panel
244  **********************************************************************/
245 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
246                                 QFrame( NULL ), p_intf( _p_i )
247 {
248     QHBoxLayout *layout = new QHBoxLayout( this );
249     layout->setMargin( 0 );
250     QPushButton *prevButton = new QPushButton( "Prev" );
251     QPushButton *nextButton = new QPushButton( "Next" );
252     layout->addWidget( prevButton );
253     layout->addWidget( nextButton );
254
255     layout->addStretch( 10 );
256     layout->addWidget( new QLabel( qtr( "Current visualization" ) ) );
257
258     current = new QLabel( qtr( "None" ) );
259     layout->addWidget( current );
260
261     BUTTONACT( prevButton, prev() );
262     BUTTONACT( nextButton, next() );
263
264     setLayout( layout );
265     setMaximumHeight( 35 );
266 }
267
268 VisualSelector::~VisualSelector()
269 {}
270
271 void VisualSelector::prev()
272 {
273     char *psz_new = aout_VisualPrev( p_intf );
274     if( psz_new )
275     {
276         current->setText( qfu( psz_new ) );
277         free( psz_new );
278     }
279 }
280
281 void VisualSelector::next()
282 {
283     char *psz_new = aout_VisualNext( p_intf );
284     if( psz_new )
285     {
286         current->setText( qfu( psz_new ) );
287         free( psz_new );
288     }
289 }
290 #endif
291
292 /**********************************************************************
293  * TEH controls
294  **********************************************************************/
295
296 #define setupSmallButton( aButton ){  \
297     aButton->setMaximumSize( QSize( 26, 26 ) ); \
298     aButton->setMinimumSize( QSize( 26, 26 ) ); \
299     aButton->setIconSize( QSize( 20, 20 ) ); }
300
301 /* init static variables in advanced controls */
302 mtime_t AdvControlsWidget::timeA = 0;
303 mtime_t AdvControlsWidget::timeB = 0;
304
305 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, bool b_fsCreation = false ) :
306                                            QFrame( NULL ), p_intf( _p_i )
307 {
308     QHBoxLayout *advLayout = new QHBoxLayout( this );
309     advLayout->setMargin( 0 );
310     advLayout->setSpacing( 0 );
311     advLayout->setAlignment( Qt::AlignBottom );
312
313     /* A to B Button */
314     ABButton = new QPushButton;
315     setupSmallButton( ABButton );
316     advLayout->addWidget( ABButton );
317     BUTTON_SET_ACT_I( ABButton, "", atob_nob,
318       qtr( "Loop from point A to point B continuously.\nClick to set point A" ),
319       fromAtoB() );
320     timeA = timeB = 0;
321     i_last_input_id = 0;
322     /* in FS controller we skip this, because we dont want to have it double
323        controlled */
324     if( !b_fsCreation )
325         CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
326                  this, AtoBLoop( float, int, int ) );
327     /* set up synchronization between main controller and fs controller */
328     CONNECT( THEMIM->getIM(), advControlsSetIcon(), this, setIcon() );
329     connect( this, SIGNAL( timeChanged() ),
330         THEMIM->getIM(), SIGNAL( advControlsSetIcon()));
331 #if 0
332     frameButton = new QPushButton( "Fr" );
333     frameButton->setMaximumSize( QSize( 26, 26 ) );
334     frameButton->setIconSize( QSize( 20, 20 ) );
335     advLayout->addWidget( frameButton );
336     BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by frame" ), frame() );
337 #endif
338
339     recordButton = new QPushButton;
340     setupSmallButton( recordButton );
341     advLayout->addWidget( recordButton );
342     BUTTON_SET_ACT_I( recordButton, "", record,
343             qtr( "Record" ), record() );
344
345     /* Snapshot Button */
346     snapshotButton = new QPushButton;
347     setupSmallButton( snapshotButton );
348     advLayout->addWidget( snapshotButton );
349     BUTTON_SET_ACT_I( snapshotButton, "", snapshot,
350             qtr( "Take a snapshot" ), snapshot() );
351 }
352
353 AdvControlsWidget::~AdvControlsWidget()
354 {}
355
356 void AdvControlsWidget::enableInput( bool enable )
357 {
358     int i_input_id = 0;
359     if( THEMIM->getInput() != NULL )
360     {
361         input_item_t *p_item = input_GetItem( THEMIM->getInput() );
362         i_input_id = p_item->i_id;
363     }
364     ABButton->setEnabled( enable );
365     recordButton->setEnabled( enable );
366
367     if( enable && ( i_last_input_id != i_input_id ) )
368     {
369         timeA = timeB = 0;
370         i_last_input_id = i_input_id;
371         emit timeChanged();
372     }
373 }
374
375 void AdvControlsWidget::enableVideo( bool enable )
376 {
377     snapshotButton->setEnabled( enable );
378 #if 0
379     frameButton->setEnabled( enable );
380 #endif
381 }
382
383 void AdvControlsWidget::snapshot()
384 {
385     vout_thread_t *p_vout =
386         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
387     if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
388 }
389
390 /* Function called when the button is clicked() */
391 void AdvControlsWidget::fromAtoB()
392 {
393     if( !timeA )
394     {
395         timeA = var_GetTime( THEMIM->getInput(), "time"  );
396         emit timeChanged();
397         return;
398     }
399     if( !timeB )
400     {
401         timeB = var_GetTime( THEMIM->getInput(), "time"  );
402         var_SetTime( THEMIM->getInput(), "time" , timeA );
403         emit timeChanged();
404         return;
405     }
406     timeA = 0;
407     timeB = 0;
408     emit timeChanged();
409 }
410
411 /* setting/synchro icons after click on main or fs controller */
412 void AdvControlsWidget::setIcon()
413 {
414     if( !timeA && !timeB)
415     {
416         ABButton->setIcon( QIcon( ":/atob_nob" ) );
417         ABButton->setToolTip( qtr( "Loop from point A to point B continuously\nClick to set point A" ) );
418     }
419     else if( timeA && !timeB )
420     {
421         ABButton->setIcon( QIcon( ":/atob_noa" ) );
422         ABButton->setToolTip( qtr( "Click to set point B" ) );
423     }
424     else if( timeA && timeB )
425     {
426         ABButton->setIcon( QIcon( ":/atob" ) );
427         ABButton->setToolTip( qtr( "Stop the A to B loop" ) );
428     }
429 }
430
431 /* Function called regularly when in an AtoB loop */
432 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
433 {
434     if( timeB )
435     {
436         if( ( i_time >= (int)( timeB/1000000 ) )
437             || ( i_time < (int)( timeA/1000000 ) ) )
438             var_SetTime( THEMIM->getInput(), "time" , timeA );
439     }
440 }
441
442 /* FIXME Record function */
443 void AdvControlsWidget::record(){}
444
445 #if 0
446 //FIXME Frame by frame function
447 void AdvControlsWidget::frame(){}
448 #endif
449
450 /*****************************
451  * DA Control Widget !
452  *****************************/
453 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
454                                 MainInterface *_p_mi,
455                                 bool b_advControls,
456                                 bool b_shiny,
457                                 bool b_fsCreation) :
458                                 QFrame( _p_mi ), p_intf( _p_i )
459 {
460     setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
461
462     /** The main Slider **/
463     slider = new InputSlider( Qt::Horizontal, NULL );
464     /* Update the position when the IM has changed */
465     CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
466              slider, setPosition( float, int, int ) );
467     /* And update the IM, when the position has changed */
468     CONNECT( slider, sliderDragged( float ),
469              THEMIM->getIM(), sliderUpdate( float ) );
470
471     /** Slower and faster Buttons **/
472     slowerButton = new QToolButton;
473     slowerButton->setAutoRaise( true );
474     slowerButton->setMaximumSize( QSize( 26, 20 ) );
475
476     BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
477
478     fasterButton = new QToolButton;
479     fasterButton->setAutoRaise( true );
480     fasterButton->setMaximumSize( QSize( 26, 20 ) );
481
482     BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
483
484     /* advanced Controls handling */
485     b_advancedVisible = b_advControls;
486
487     advControls = new AdvControlsWidget( p_intf, b_fsCreation );
488     if( !b_advancedVisible ) advControls->hide();
489
490     /** Disc and Menus handling */
491     discFrame = new QWidget( this );
492
493     QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
494     discLayout->setSpacing( 0 );
495     discLayout->setMargin( 0 );
496
497     prevSectionButton = new QPushButton( discFrame );
498     setupSmallButton( prevSectionButton );
499     discLayout->addWidget( prevSectionButton );
500
501     menuButton = new QPushButton( discFrame );
502     setupSmallButton( menuButton );
503     discLayout->addWidget( menuButton );
504
505     nextSectionButton = new QPushButton( discFrame );
506     setupSmallButton( nextSectionButton );
507     discLayout->addWidget( nextSectionButton );
508
509     BUTTON_SET_IMG( prevSectionButton, "", dvd_prev, "" );
510     BUTTON_SET_IMG( nextSectionButton, "", dvd_next, "" );
511     BUTTON_SET_IMG( menuButton, "", dvd_menu, qtr( "Menu" ) );
512
513     discFrame->hide();
514
515     /* Change the navigation button display when the IM navigation changes */
516     CONNECT( THEMIM->getIM(), navigationChanged( int ),
517              this, setNavigation( int ) );
518     /* Changes the IM navigation when triggered on the nav buttons */
519     CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
520              sectionPrev() );
521     CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
522              sectionNext() );
523     CONNECT( menuButton, clicked(), THEMIM->getIM(),
524              sectionMenu() );
525
526     /**
527      * Telextext QFrame
528      * TODO: Merge with upper menu in a StackLayout
529      **/
530     telexFrame = new QWidget( this );
531     QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
532     telexLayout->setSpacing( 0 );
533     telexLayout->setMargin( 0 );
534
535     telexOn = new QPushButton;
536     setupSmallButton( telexOn );
537     telexLayout->addWidget( telexOn );
538
539     telexTransparent = new QPushButton;
540     setupSmallButton( telexTransparent );
541     telexLayout->addWidget( telexTransparent );
542     b_telexTransparent = false;
543
544     telexPage = new QSpinBox;
545     telexPage->setRange( 0, 999 );
546     telexPage->setValue( 100 );
547     telexPage->setAccelerated( true );
548     telexPage->setWrapping( true );
549     telexPage->setAlignment( Qt::AlignRight );
550     telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
551     telexLayout->addWidget( telexPage );
552
553     telexFrame->hide(); /* default hidden */
554
555     CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
556              telexGotoPage( int ) );
557     CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
558               telexPage, setValue( int ) );
559
560     BUTTON_SET_IMG( telexOn, "", tv, qtr( "Teletext on" ) );
561
562     CONNECT( telexOn, clicked(), THEMIM->getIM(),
563              telexToggleButtons() );
564     CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
565              telexToggle( bool ) );
566     CONNECT( THEMIM->getIM(), toggleTelexButtons(),
567               this, toggleTeletext() );
568     b_telexEnabled = false;
569     telexTransparent->setEnabled( false );
570     telexPage->setEnabled( false );
571
572     BUTTON_SET_IMG( telexTransparent, "", tvtelx, qtr( "Teletext" ) );
573     CONNECT( telexTransparent, clicked( bool ),
574              THEMIM->getIM(), telexSetTransparency() );
575     CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
576               this, toggleTeletextTransparency() );
577     CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
578              this, enableTeletext( bool ) );
579
580     /** Play Buttons **/
581     QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
582     sizePolicy.setHorizontalStretch( 0 );
583     sizePolicy.setVerticalStretch( 0 );
584
585     /* Play */
586     playButton = new QPushButton;
587     playButton->setSizePolicy( sizePolicy );
588     playButton->setMaximumSize( QSize( 36, 36 ) );
589     playButton->setMinimumSize( QSize( 36, 36 ) );
590     playButton->setIconSize( QSize( 30, 30 ) );
591
592
593     /** Prev + Stop + Next Block **/
594     controlButLayout = new QHBoxLayout;
595     controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
596
597     /* Prev */
598     QPushButton *prevButton = new QPushButton;
599     prevButton->setSizePolicy( sizePolicy );
600     setupSmallButton( prevButton );
601
602     controlButLayout->addWidget( prevButton );
603
604     /* Stop */
605     QPushButton *stopButton = new QPushButton;
606     stopButton->setSizePolicy( sizePolicy );
607     setupSmallButton( stopButton );
608
609     controlButLayout->addWidget( stopButton );
610
611     /* next */
612     QPushButton *nextButton = new QPushButton;
613     nextButton->setSizePolicy( sizePolicy );
614     setupSmallButton( nextButton );
615
616     controlButLayout->addWidget( nextButton );
617
618     /* Add this block to the main layout */
619
620     BUTTON_SET_ACT_I( playButton, "", play_b, qtr( I_PLAY_TOOLTIP ), play() );
621     BUTTON_SET_ACT_I( prevButton, "" , previous_b,
622                       qtr( "Previous media in the playlist" ), prev() );
623     BUTTON_SET_ACT_I( nextButton, "", next_b,
624                       qtr( "Next media in the playlist" ), next() );
625     BUTTON_SET_ACT_I( stopButton, "", stop_b, qtr( "Stop playback" ), stop() );
626
627     /*
628      * Other first Line buttons
629      */
630     /** Fullscreen/Visualisation **/
631     fullscreenButton = new QPushButton;
632     BUTTON_SET_ACT_I( fullscreenButton, "", fullscreen,
633             qtr( "Toggle the video in fullscreen" ), fullscreen() );
634     setupSmallButton( fullscreenButton );
635
636     if( !b_fsCreation )
637     {
638         /** Playlist Button **/
639         playlistButton = new QPushButton;
640         setupSmallButton( playlistButton );
641         BUTTON_SET_IMG( playlistButton, "" , playlist, qtr( "Show playlist" ) );
642         CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
643
644         /** extended Settings **/
645         extSettingsButton = new QPushButton;
646         BUTTON_SET_ACT_I( extSettingsButton, "", extended,
647                 qtr( "Show extended settings" ), extSettings() );
648         setupSmallButton( extSettingsButton );
649     }
650
651     /* Volume */
652     hVolLabel = new VolumeClickHandler( p_intf, this );
653
654     volMuteLabel = new QLabel;
655     volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
656     volMuteLabel->installEventFilter( hVolLabel );
657
658     if( b_shiny )
659     {
660         volumeSlider = new SoundSlider( this,
661             config_GetInt( p_intf, "volume-step" ),
662             config_GetInt( p_intf, "qt-volume-complete" ),
663             config_GetPsz( p_intf, "qt-slider-colours" ) );
664     }
665     else
666     {
667         volumeSlider = new QSlider( this );
668         volumeSlider->setOrientation( Qt::Horizontal );
669     }
670     volumeSlider->setMaximumSize( QSize( 200, 40 ) );
671     volumeSlider->setMinimumSize( QSize( 85, 30 ) );
672     volumeSlider->setFocusPolicy( Qt::NoFocus );
673
674     /* Set the volume from the config */
675     volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
676                               VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
677
678     /* Force the update at build time in order to have a muted icon if needed */
679     updateVolume( volumeSlider->value() );
680
681     /* Volume control connection */
682     CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
683     CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
684
685     if( !b_fsCreation )
686     {
687         controlLayout = new QGridLayout( this );
688
689         controlLayout->setSpacing( 0 );
690         controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
691
692         controlLayout->addWidget( slider, 0, 1, 1, 18 );
693         controlLayout->addWidget( slowerButton, 0, 0 );
694         controlLayout->addWidget( fasterButton, 0, 19 );
695
696         controlLayout->addWidget( discFrame, 1, 8, 2, 3, Qt::AlignBottom );
697         controlLayout->addWidget( telexFrame, 1, 8, 2, 5, Qt::AlignBottom );
698
699         controlLayout->addWidget( playButton, 2, 0, 2, 2, Qt::AlignBottom );
700         controlLayout->setColumnMinimumWidth( 2, 10 );
701         controlLayout->setColumnStretch( 2, 0 );
702
703         controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
704         /* Column 6 is unused */
705         controlLayout->setColumnStretch( 6, 0 );
706         controlLayout->setColumnStretch( 7, 0 );
707         controlLayout->setColumnMinimumWidth( 7, 10 );
708
709         controlLayout->addWidget( fullscreenButton, 3, 8, Qt::AlignBottom );
710         controlLayout->addWidget( playlistButton, 3, 9, Qt::AlignBottom );
711         controlLayout->addWidget( extSettingsButton, 3, 10, Qt::AlignBottom );
712         controlLayout->setColumnStretch( 11, 0 ); /* telex alignment */
713
714         controlLayout->setColumnStretch( 12, 0 );
715         controlLayout->setColumnMinimumWidth( 12, 10 );
716
717         controlLayout->addWidget( advControls, 3, 13, 1, 3, Qt::AlignBottom );
718
719         controlLayout->setColumnStretch( 16, 10 );
720         controlLayout->setColumnMinimumWidth( 16, 10 );
721
722         controlLayout->addWidget( volMuteLabel, 3, 17, Qt::AlignBottom );
723         controlLayout->addWidget( volumeSlider, 3, 18, 1 , 2, Qt::AlignBottom );
724     }
725
726     updateInput();
727 }
728
729 ControlsWidget::~ControlsWidget()
730 {}
731
732 void ControlsWidget::toggleTeletext()
733 {
734     bool b_enabled = THEMIM->teletextState();
735     if( b_telexEnabled )
736     {
737         telexTransparent->setEnabled( false );
738         telexPage->setEnabled( false );
739         b_telexEnabled = false;
740     }
741     else if( b_enabled )
742     {
743         telexTransparent->setEnabled( true );
744         telexPage->setEnabled( true );
745         b_telexEnabled = true;
746     }
747 }
748
749 void ControlsWidget::enableTeletext( bool b_enable )
750 {
751     telexFrame->setVisible( b_enable );
752     bool b_on = THEMIM->teletextState();
753
754     telexOn->setChecked( b_on );
755     telexTransparent->setEnabled( b_on );
756     telexPage->setEnabled( b_on );
757     b_telexEnabled = b_on;
758 }
759
760 void ControlsWidget::toggleTeletextTransparency()
761 {
762     if( b_telexTransparent )
763     {
764         telexTransparent->setIcon( QIcon( ":/tvtelx" ) );
765         telexTransparent->setToolTip( qtr( "Teletext" ) );
766         b_telexTransparent = false;
767     }
768     else
769     {
770         telexTransparent->setIcon( QIcon( ":/tvtelx-transparent" ) );
771         telexTransparent->setToolTip( qtr( "Transparent" ) );
772         b_telexTransparent = true;
773     }
774 }
775
776 void ControlsWidget::stop()
777 {
778     THEMIM->stop();
779 }
780
781 void ControlsWidget::play()
782 {
783     if( THEPL->current.i_size == 0 )
784     {
785         /* The playlist is empty, open a file requester */
786         THEDP->openFileDialog();
787         setStatus( 0 );
788         return;
789     }
790     THEMIM->togglePlayPause();
791 }
792
793 void ControlsWidget::prev()
794 {
795     THEMIM->prev();
796 }
797
798 void ControlsWidget::next()
799 {
800     THEMIM->next();
801 }
802
803 void ControlsWidget::setNavigation( int navigation )
804 {
805 #define HELP_PCH N_( "Previous chapter" )
806 #define HELP_NCH N_( "Next chapter" )
807
808     // 1 = chapter, 2 = title, 0 = no
809     if( navigation == 0 )
810     {
811         discFrame->hide();
812     } else if( navigation == 1 ) {
813         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
814         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
815         menuButton->show();
816         discFrame->show();
817     } else {
818         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
819         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
820         menuButton->hide();
821         discFrame->show();
822     }
823 }
824
825 static bool b_my_volume;
826 void ControlsWidget::updateVolume( int i_sliderVolume )
827 {
828     if( !b_my_volume )
829     {
830         int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
831         aout_VolumeSet( p_intf, i_res );
832     }
833     if( i_sliderVolume == 0 )
834     {
835         volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
836         volMuteLabel->setToolTip( qtr( "Unmute" ) );
837         return;
838     }
839
840     if( i_sliderVolume < VOLUME_MAX / 3 )
841         volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
842     else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
843         volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
844     else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
845     volMuteLabel->setToolTip( qtr( "Mute" ) );
846 }
847
848 void ControlsWidget::updateVolume()
849 {
850     /* Audio part */
851     audio_volume_t i_volume;
852     aout_VolumeGet( p_intf, &i_volume );
853     i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
854     int i_gauge = volumeSlider->value();
855     b_my_volume = false;
856     if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
857     {
858         b_my_volume = true;
859         volumeSlider->setValue( i_volume );
860         b_my_volume = false;
861     }
862 }
863
864 void ControlsWidget::updateInput()
865 {
866     /* Activate the interface buttons according to the presence of the input */
867     enableInput( THEMIM->getIM()->hasInput() );
868     enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
869 }
870
871 void ControlsWidget::setStatus( int status )
872 {
873     if( status == PLAYING_S ) /* Playing */
874     {
875         playButton->setIcon( QIcon( ":/pause_b" ) );
876         playButton->setToolTip( qtr( "Pause the playback" ) );
877     }
878     else
879     {
880         playButton->setIcon( QIcon( ":/play_b" ) );
881         playButton->setToolTip( qtr( I_PLAY_TOOLTIP ) );
882     }
883 }
884
885 /**
886  * TODO
887  * This functions toggle the fullscreen mode
888  * If there is no video, it should first activate Visualisations...
889  *  This has also to be fixed in enableVideo()
890  */
891 void ControlsWidget::fullscreen()
892 {
893     vout_thread_t *p_vout =
894         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
895     if( p_vout)
896     {
897         var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
898         vlc_object_release( p_vout );
899     }
900 }
901
902 void ControlsWidget::extSettings()
903 {
904     THEDP->extendedDialog();
905 }
906
907 void ControlsWidget::slower()
908 {
909     THEMIM->getIM()->slower();
910 }
911
912 void ControlsWidget::faster()
913 {
914     THEMIM->getIM()->faster();
915 }
916
917 void ControlsWidget::enableInput( bool enable )
918 {
919     slowerButton->setEnabled( enable );
920     slider->setEnabled( enable );
921     slider->setSliderPosition ( 0 );
922     fasterButton->setEnabled( enable );
923
924     /* Advanced Buttons too */
925     advControls->enableInput( enable );
926 }
927
928 void ControlsWidget::enableVideo( bool enable )
929 {
930     // TODO Later make the fullscreenButton toggle Visualisation and so on.
931     fullscreenButton->setEnabled( enable );
932
933     /* Advanced Buttons too */
934     advControls->enableVideo( enable );
935 }
936
937 void ControlsWidget::toggleAdvanced()
938 {
939     if( advControls && !b_advancedVisible )
940     {
941         advControls->show();
942         b_advancedVisible = true;
943     }
944     else
945     {
946         advControls->hide();
947         b_advancedVisible = false;
948     }
949     emit advancedControlsToggled( b_advancedVisible );
950 }
951
952
953 /**********************************************************************
954  * Fullscrenn control widget
955  **********************************************************************/
956 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
957         MainInterface *_p_mi, bool b_advControls, bool b_shiny )
958         : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
959           i_mouse_last_x( -1 ), i_mouse_last_y( -1 ), b_mouse_over(false),
960           b_slow_hide_begin(false), i_slow_hide_timeout(1),
961           b_fullscreen( false ), i_hide_timeout( 1 ), p_vout(NULL)
962 {
963     setWindowFlags( Qt::ToolTip );
964
965     setFrameShape( QFrame::StyledPanel );
966     setFrameStyle( QFrame::Sunken );
967     setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
968
969     QGridLayout *fsLayout = new QGridLayout( this );
970     fsLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
971
972     /* First line */
973     slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
974     fsLayout->addWidget( slowerButton, 0, 0 );
975     fsLayout->addWidget( slider, 0, 1, 1, 8 );
976     fsLayout->addWidget( fasterButton, 0, 9 );
977
978     fsLayout->addWidget( playButton, 1, 0, 1, 2 );
979     fsLayout->addLayout( controlButLayout, 1, 2 );
980
981     fsLayout->addWidget( discFrame, 1, 3 );
982     fsLayout->addWidget( telexFrame, 1, 4 );
983     fsLayout->addWidget( advControls, 1, 5, Qt::AlignVCenter );
984     fsLayout->addWidget( fullscreenButton, 1, 6 );
985
986     fsLayout->addWidget( volMuteLabel, 1, 7 );
987     fsLayout->addWidget( volumeSlider, 1, 8, 1, 2 );
988
989     /* hiding timer */
990     p_hideTimer = new QTimer( this );
991     CONNECT( p_hideTimer, timeout(), this, hideFSC() );
992     p_hideTimer->setSingleShot( true );
993
994     /* slow hiding timer */
995 #if HAVE_TRANSPARENCY
996     p_slowHideTimer = new QTimer( this );
997     CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
998 #endif
999
1000     adjustSize ();  /* need to get real width and height for moving */
1001
1002     /* center down */
1003     QDesktopWidget * p_desktop = QApplication::desktop();
1004
1005     move( p_desktop->width() / 2 - width() / 2,
1006           p_desktop->height() - height() );
1007
1008 #ifdef WIN32TRICK
1009     setWindowOpacity( 0.0 );
1010     b_fscHidden = true;
1011     adjustSize();
1012     show();
1013 #endif
1014
1015     vlc_mutex_init_recursive( &lock );
1016 }
1017
1018 FullscreenControllerWidget::~FullscreenControllerWidget()
1019 {
1020     detachVout();
1021     vlc_mutex_destroy( &lock );
1022 }
1023
1024 /**
1025  * Show fullscreen controller
1026  */
1027 void FullscreenControllerWidget::showFSC()
1028 {
1029     adjustSize();
1030 #ifdef WIN32TRICK
1031     // after quiting and going to fs, we need to call show()
1032     if( isHidden() )
1033         show();
1034
1035     if( b_fscHidden )
1036     {
1037         b_fscHidden = false;
1038         setWindowOpacity( 1.0 );
1039     }
1040 #else
1041     show();
1042 #endif
1043
1044 #if HAVE_TRANSPARENCY
1045     setWindowOpacity( DEFAULT_OPACITY );
1046 #endif
1047 }
1048
1049 /**
1050  * Hide fullscreen controller
1051  * FIXME: under windows it have to be done by moving out of screen
1052  *        because hide() doesnt work
1053  */
1054 void FullscreenControllerWidget::hideFSC()
1055 {
1056 #ifdef WIN32TRICK
1057     b_fscHidden = true;
1058     setWindowOpacity( 0.0 );    // simulate hidding
1059 #else
1060     hide();
1061 #endif
1062 }
1063
1064 /**
1065  * Plane to hide fullscreen controller
1066  */
1067 void FullscreenControllerWidget::planHideFSC()
1068 {
1069     vlc_mutex_lock( &lock );
1070     int i_timeout = i_hide_timeout;
1071     vlc_mutex_unlock( &lock );
1072
1073     p_hideTimer->start( i_timeout );
1074
1075 #if HAVE_TRANSPARENCY
1076     b_slow_hide_begin = true;
1077     i_slow_hide_timeout = i_timeout;
1078     p_slowHideTimer->start( i_slow_hide_timeout / 2 );
1079 #endif
1080 }
1081
1082 /**
1083  * Hidding fullscreen controller slowly
1084  * Linux: need composite manager
1085  * Windows: it is blinking, so it can be enabled by define TRASPARENCY
1086  */
1087 void FullscreenControllerWidget::slowHideFSC()
1088 {
1089 #if HAVE_TRANSPARENCY
1090     if( b_slow_hide_begin )
1091     {
1092         b_slow_hide_begin = false;
1093
1094         p_slowHideTimer->stop();
1095         /* the last part of time divided to 100 pieces */
1096         p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
1097
1098     }
1099     else
1100     {
1101 #ifdef WIN32TRICK
1102          if ( windowOpacity() > 0.0 && !b_fscHidden )
1103 #else
1104          if ( windowOpacity() > 0.0 )
1105 #endif
1106          {
1107              /* we should use 0.01 because of 100 pieces ^^^
1108                 but than it cannt be done in time */
1109              setWindowOpacity( windowOpacity() - 0.02 );
1110          }
1111
1112          if ( windowOpacity() <= 0.0 )
1113              p_slowHideTimer->stop();
1114     }
1115 #endif
1116 }
1117
1118 /**
1119  * event handling
1120  * events: show, hide, start timer for hidding
1121  */
1122 void FullscreenControllerWidget::customEvent( QEvent *event )
1123 {
1124     bool b_fs;
1125
1126     switch( event->type() )
1127     {
1128         case FullscreenControlToggle_Type:
1129             vlc_mutex_lock( &lock );
1130             b_fs = b_fullscreen;
1131             vlc_mutex_unlock( &lock );
1132             if( b_fs )
1133 #ifdef WIN32TRICK
1134                 if( b_fscHidden )
1135 #else
1136                 if( isHidden() )
1137 #endif
1138                 {
1139                     p_hideTimer->stop();
1140                     showFSC();
1141                 }
1142                 else
1143                     hideFSC();
1144             break;
1145         case FullscreenControlShow_Type:
1146             vlc_mutex_lock( &lock );
1147             b_fs = b_fullscreen;
1148             vlc_mutex_unlock( &lock );
1149
1150             if( b_fs )  // FIXME I am not sure about that one
1151                 showFSC();
1152             break;
1153         case FullscreenControlHide_Type:
1154             hideFSC();
1155             break;
1156         case FullscreenControlPlanHide_Type:
1157             if( !b_mouse_over ) // Only if the mouse is not over FSC
1158                 planHideFSC();
1159             break;
1160     }
1161 }
1162
1163 /**
1164  * On mouse move
1165  * moving with FSC
1166  */
1167 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1168 {
1169     if ( event->buttons() == Qt::LeftButton )
1170     {
1171         int i_moveX = event->globalX() - i_mouse_last_x;
1172         int i_moveY = event->globalY() - i_mouse_last_y;
1173
1174         move( x() + i_moveX, y() + i_moveY );
1175
1176         i_mouse_last_x = event->globalX();
1177         i_mouse_last_y = event->globalY();
1178     }
1179 }
1180
1181 /**
1182  * On mouse press
1183  * store position of cursor
1184  */
1185 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1186 {
1187     i_mouse_last_x = event->globalX();
1188     i_mouse_last_y = event->globalY();
1189 }
1190
1191 /**
1192  * On mouse go above FSC
1193  */
1194 void FullscreenControllerWidget::enterEvent( QEvent *event )
1195 {
1196     b_mouse_over = true;
1197
1198     p_hideTimer->stop();
1199 #if HAVE_TRANSPARENCY
1200     p_slowHideTimer->stop();
1201 #endif
1202 }
1203
1204 /**
1205  * On mouse go out from FSC
1206  */
1207 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1208 {
1209     planHideFSC();
1210
1211     b_mouse_over = false;
1212 }
1213
1214 /**
1215  * When you get pressed key, send it to video output
1216  * FIXME: clearing focus by clearFocus() to not getting
1217  * key press events didnt work
1218  */
1219 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1220 {
1221     int i_vlck = qtEventToVLCKey( event );
1222     if( i_vlck > 0 )
1223     {
1224         var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1225         event->accept();
1226     }
1227     else
1228         event->ignore();
1229 }
1230
1231 /* */
1232 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object, const char *variable,
1233                                                         vlc_value_t old_val, vlc_value_t new_val,
1234                                                         void *data )
1235 {
1236     vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1237     FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1238
1239     p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1240
1241     return VLC_SUCCESS;
1242 }
1243 /* */
1244 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1245                                                  vlc_value_t old_val, vlc_value_t new_val,
1246                                                  void *data )
1247 {
1248     FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1249
1250     /* Show event */
1251     IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1252     QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1253
1254     /* Plan hide event */
1255     IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1256     QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1257
1258     return VLC_SUCCESS;
1259 }
1260
1261
1262 /**
1263  * It is called when video start
1264  */
1265 void FullscreenControllerWidget::attachVout( vout_thread_t *p_nvout )
1266 {
1267     assert( p_nvout && !p_vout );
1268
1269     p_vout = p_nvout;
1270
1271     vlc_mutex_lock( &lock );
1272     var_AddCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this ); /* I miss a add and fire */
1273     fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ), var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1274     vlc_mutex_unlock( &lock );
1275 }
1276 /**
1277  * It is called after turn off video.
1278  */
1279 void FullscreenControllerWidget::detachVout()
1280 {
1281     if( p_vout )
1282     {
1283         var_DelCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this );
1284         vlc_mutex_lock( &lock );
1285         fullscreenChanged( p_vout, false, 0 );
1286         vlc_mutex_unlock( &lock );
1287         p_vout = NULL;
1288     }
1289 }
1290
1291 /**
1292  * Register and unregister callback for mouse moving
1293  */
1294 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout, bool b_fs, int i_timeout )
1295 {
1296     vlc_mutex_lock( &lock );
1297     if( b_fs && !b_fullscreen )
1298     {
1299         b_fullscreen = true;
1300         i_hide_timeout = i_timeout;
1301         var_AddCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1302     }
1303     else if( !b_fs && b_fullscreen )
1304     {
1305         b_fullscreen = false;
1306         i_hide_timeout = i_timeout;
1307         var_DelCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1308
1309         /* Force fs hidding */
1310         IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1311         QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1312     }
1313     vlc_mutex_unlock( &lock );
1314 }
1315
1316 /**********************************************************************
1317  * Speed control widget
1318  **********************************************************************/
1319 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1320                              QFrame( NULL ), p_intf( _p_i )
1321 {
1322     QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1323     sizePolicy.setHorizontalStretch( 0 );
1324     sizePolicy.setVerticalStretch( 0 );
1325
1326     speedSlider = new QSlider;
1327     speedSlider->setSizePolicy( sizePolicy );
1328     speedSlider->setMaximumSize( QSize( 80, 200 ) );
1329     speedSlider->setOrientation( Qt::Vertical );
1330     speedSlider->setTickPosition( QSlider::TicksRight );
1331
1332     speedSlider->setRange( -24, 24 );
1333     speedSlider->setSingleStep( 1 );
1334     speedSlider->setPageStep( 1 );
1335     speedSlider->setTickInterval( 12 );
1336
1337     CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1338
1339     QToolButton *normalSpeedButton = new QToolButton( this );
1340     normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1341     normalSpeedButton->setAutoRaise( true );
1342     normalSpeedButton->setText( "1x" );
1343     normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1344
1345     CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1346
1347     QVBoxLayout *speedControlLayout = new QVBoxLayout;
1348     speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
1349     speedControlLayout->setSpacing( 4 );
1350     speedControlLayout->addWidget( speedSlider );
1351     speedControlLayout->addWidget( normalSpeedButton );
1352     setLayout( speedControlLayout );
1353 }
1354
1355 SpeedControlWidget::~SpeedControlWidget()
1356 {}
1357
1358 void SpeedControlWidget::setEnable( bool b_enable )
1359 {
1360     speedSlider->setEnabled( b_enable );
1361 }
1362
1363 void SpeedControlWidget::updateControls( int rate )
1364 {
1365     if( speedSlider->isSliderDown() )
1366     {
1367         //We don't want to change anything if the user is using the slider
1368         return;
1369     }
1370
1371     double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
1372     int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
1373
1374     if( sliderValue < speedSlider->minimum() )
1375     {
1376         sliderValue = speedSlider->minimum();
1377     }
1378     else if( sliderValue > speedSlider->maximum() )
1379     {
1380         sliderValue = speedSlider->maximum();
1381     }
1382
1383     //Block signals to avoid feedback loop
1384     speedSlider->blockSignals( true );
1385     speedSlider->setValue( sliderValue );
1386     speedSlider->blockSignals( false );
1387 }
1388
1389 void SpeedControlWidget::updateRate( int sliderValue )
1390 {
1391     double speed = pow( 2, (double)sliderValue / 12 );
1392     int rate = INPUT_RATE_DEFAULT / speed;
1393
1394     THEMIM->getIM()->setRate(rate);
1395 }
1396
1397 void SpeedControlWidget::resetRate()
1398 {
1399     THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
1400 }