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