]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
49cda26567f850c8bf6fbb712894c90400aaba00
[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     /* 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( 85, 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, 18 );
678         controlLayout->addWidget( slowerButton, 0, 0 );
679         controlLayout->addWidget( fasterButton, 0, 19 );
680
681         controlLayout->addWidget( discFrame, 1, 8, 2, 3, Qt::AlignBottom );
682         controlLayout->addWidget( telexFrame, 1, 8, 2, 5, Qt::AlignBottom );
683
684         controlLayout->addWidget( playButton, 2, 0, 2, 2, Qt::AlignBottom );
685         controlLayout->setColumnMinimumWidth( 2, 10 );
686         controlLayout->setColumnStretch( 2, 0 );
687
688         controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
689         /* Column 6 is unused */
690         controlLayout->setColumnStretch( 6, 0 );
691         controlLayout->setColumnStretch( 7, 0 );
692         controlLayout->setColumnMinimumWidth( 7, 10 );
693
694         controlLayout->addWidget( fullscreenButton, 3, 8, Qt::AlignBottom );
695         controlLayout->addWidget( playlistButton, 3, 9, Qt::AlignBottom );
696         controlLayout->addWidget( extSettingsButton, 3, 10, Qt::AlignBottom );
697         controlLayout->setColumnStretch( 11, 0 ); /* telex alignment */
698
699         controlLayout->setColumnStretch( 12, 0 );
700         controlLayout->setColumnMinimumWidth( 12, 10 );
701
702         controlLayout->addWidget( advControls, 3, 13, 1, 3, Qt::AlignBottom );
703
704         controlLayout->setColumnStretch( 16, 10 );
705         controlLayout->setColumnMinimumWidth( 16, 10 );
706
707         controlLayout->addWidget( volMuteLabel, 3, 17, Qt::AlignBottom );
708         controlLayout->addWidget( volumeSlider, 3, 18, 1 , 2, Qt::AlignBottom );
709     }
710
711     updateInput();
712 }
713
714 ControlsWidget::~ControlsWidget()
715 {}
716
717 void ControlsWidget::toggleTeletext()
718 {
719     bool b_enabled = THEMIM->teletextState();
720     if( b_telexEnabled )
721     {
722         telexTransparent->setEnabled( false );
723         telexPage->setEnabled( false );
724         b_telexEnabled = false;
725     }
726     else if( b_enabled )
727     {
728         telexTransparent->setEnabled( true );
729         telexPage->setEnabled( true );
730         b_telexEnabled = true;
731     }
732 }
733
734 void ControlsWidget::enableTeletext( bool b_enable )
735 {
736     telexFrame->setVisible( b_enable );
737     bool b_on = THEMIM->teletextState();
738
739     telexOn->setChecked( b_on );
740     telexTransparent->setEnabled( b_on );
741     telexPage->setEnabled( b_on );
742     b_telexEnabled = b_on;
743 }
744
745 void ControlsWidget::toggleTeletextTransparency()
746 {
747     if( b_telexTransparent )
748     {
749         telexTransparent->setIcon( QIcon( ":/tvtelx" ) );
750         telexTransparent->setToolTip( qtr( "Teletext" ) );
751         b_telexTransparent = false;
752     }
753     else
754     {
755         telexTransparent->setIcon( QIcon( ":/tvtelx-transparent" ) );
756         telexTransparent->setToolTip( qtr( "Transparent" ) );
757         b_telexTransparent = true;
758     }
759 }
760
761 void ControlsWidget::stop()
762 {
763     THEMIM->stop();
764 }
765
766 void ControlsWidget::play()
767 {
768     if( THEPL->current.i_size == 0 )
769     {
770         /* The playlist is empty, open a file requester */
771         THEDP->openFileDialog();
772         setStatus( 0 );
773         return;
774     }
775     THEMIM->togglePlayPause();
776 }
777
778 void ControlsWidget::prev()
779 {
780     THEMIM->prev();
781 }
782
783 void ControlsWidget::next()
784 {
785     THEMIM->next();
786 }
787
788 void ControlsWidget::setNavigation( int navigation )
789 {
790 #define HELP_PCH N_( "Previous chapter" )
791 #define HELP_NCH N_( "Next chapter" )
792
793     // 1 = chapter, 2 = title, 0 = no
794     if( navigation == 0 )
795     {
796         discFrame->hide();
797     } else if( navigation == 1 ) {
798         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
799         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
800         menuButton->show();
801         discFrame->show();
802     } else {
803         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
804         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
805         menuButton->hide();
806         discFrame->show();
807     }
808 }
809
810 static bool b_my_volume;
811 void ControlsWidget::updateVolume( int i_sliderVolume )
812 {
813     if( !b_my_volume )
814     {
815         int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
816         aout_VolumeSet( p_intf, i_res );
817     }
818     if( i_sliderVolume == 0 )
819     {
820         volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
821         volMuteLabel->setToolTip( qtr( "Unmute" ) );
822         return;
823     }
824
825     if( i_sliderVolume < VOLUME_MAX / 3 )
826         volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
827     else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
828         volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
829     else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
830     volMuteLabel->setToolTip( qtr( "Mute" ) );
831 }
832
833 void ControlsWidget::updateVolume()
834 {
835     /* Audio part */
836     audio_volume_t i_volume;
837     aout_VolumeGet( p_intf, &i_volume );
838     i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
839     int i_gauge = volumeSlider->value();
840     b_my_volume = false;
841     if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
842     {
843         b_my_volume = true;
844         volumeSlider->setValue( i_volume );
845         b_my_volume = false;
846     }
847 }
848
849 void ControlsWidget::updateInput()
850 {
851     /* Activate the interface buttons according to the presence of the input */
852     enableInput( THEMIM->getIM()->hasInput() );
853     enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
854 }
855
856 void ControlsWidget::setStatus( int status )
857 {
858     if( status == PLAYING_S ) /* Playing */
859     {
860         playButton->setIcon( QIcon( ":/pause_b" ) );
861         playButton->setToolTip( qtr( "Pause the playback" ) );
862     }
863     else
864     {
865         playButton->setIcon( QIcon( ":/play_b" ) );
866         playButton->setToolTip( qtr( I_PLAY_TOOLTIP ) );
867     }
868 }
869
870 /**
871  * TODO
872  * This functions toggle the fullscreen mode
873  * If there is no video, it should first activate Visualisations...
874  *  This has also to be fixed in enableVideo()
875  */
876 void ControlsWidget::fullscreen()
877 {
878     vout_thread_t *p_vout =
879         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
880     if( p_vout)
881     {
882         var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
883         vlc_object_release( p_vout );
884     }
885 }
886
887 void ControlsWidget::extSettings()
888 {
889     THEDP->extendedDialog();
890 }
891
892 void ControlsWidget::slower()
893 {
894     THEMIM->getIM()->slower();
895 }
896
897 void ControlsWidget::faster()
898 {
899     THEMIM->getIM()->faster();
900 }
901
902 void ControlsWidget::enableInput( bool enable )
903 {
904     slowerButton->setEnabled( enable );
905     slider->setEnabled( enable );
906     slider->setSliderPosition ( 0 );
907     fasterButton->setEnabled( enable );
908
909     /* Advanced Buttons too */
910     advControls->enableInput( enable );
911 }
912
913 void ControlsWidget::enableVideo( bool enable )
914 {
915     // TODO Later make the fullscreenButton toggle Visualisation and so on.
916     fullscreenButton->setEnabled( enable );
917
918     /* Advanced Buttons too */
919     advControls->enableVideo( enable );
920 }
921
922 void ControlsWidget::toggleAdvanced()
923 {
924     if( advControls && !b_advancedVisible )
925     {
926         advControls->show();
927         b_advancedVisible = true;
928     }
929     else
930     {
931         advControls->hide();
932         b_advancedVisible = false;
933     }
934     emit advancedControlsToggled( b_advancedVisible );
935 }
936
937
938 /**********************************************************************
939  * Fullscrenn control widget
940  **********************************************************************/
941 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
942         MainInterface *_p_mi, bool b_advControls, bool b_shiny )
943         : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
944           i_mouse_last_x( -1 ), i_mouse_last_y( -1 ), b_mouse_over(false),
945           b_slow_hide_begin(false), i_slow_hide_timeout(1),
946           b_fullscreen( false ), i_hide_timeout( 1 ), p_vout(NULL)
947 {
948     setWindowFlags( Qt::ToolTip );
949
950     setFrameShape( QFrame::StyledPanel );
951     setFrameStyle( QFrame::Sunken );
952     setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
953
954     QGridLayout *fsLayout = new QGridLayout( this );
955     fsLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
956
957     /* First line */
958     slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
959     fsLayout->addWidget( slowerButton, 0, 0 );
960     fsLayout->addWidget( slider, 0, 1, 1, 8 );
961     fsLayout->addWidget( fasterButton, 0, 9 );
962
963     fsLayout->addWidget( playButton, 1, 0, 1, 2 );
964     fsLayout->addLayout( controlButLayout, 1, 2 );
965
966     fsLayout->addWidget( discFrame, 1, 3 );
967     fsLayout->addWidget( telexFrame, 1, 4 );
968     fsLayout->addWidget( advControls, 1, 5, Qt::AlignVCenter );
969     fsLayout->addWidget( fullscreenButton, 1, 6 );
970
971     fsLayout->addWidget( volMuteLabel, 1, 7 );
972     fsLayout->addWidget( volumeSlider, 1, 8, 1, 2 );
973
974     /* hiding timer */
975     p_hideTimer = new QTimer( this );
976     CONNECT( p_hideTimer, timeout(), this, hideFSC() );
977     p_hideTimer->setSingleShot( true );
978
979     /* slow hiding timer */
980 #if HAVE_TRANSPARENCY
981     p_slowHideTimer = new QTimer( this );
982     CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
983 #endif
984
985     adjustSize ();  /* need to get real width and height for moving */
986
987     /* center down */
988     QDesktopWidget * p_desktop = QApplication::desktop();
989
990     move( p_desktop->width() / 2 - width() / 2,
991           p_desktop->height() - height() );
992
993 #ifdef WIN32TRICK
994     setWindowOpacity( 0.0 );
995     fscHidden = true;
996     adjustSize();
997     show();
998 #endif
999
1000     vlc_mutex_init_recursive( &lock );
1001 }
1002
1003 FullscreenControllerWidget::~FullscreenControllerWidget()
1004 {
1005     detachVout();
1006     vlc_mutex_destroy( &lock );
1007 }
1008
1009 /**
1010  * Show fullscreen controller
1011  */
1012 void FullscreenControllerWidget::showFSC()
1013 {
1014     adjustSize();
1015 #ifdef WIN32TRICK
1016     // after quiting and going to fs, we need to call show()
1017     if( isHidden() )
1018         show();
1019
1020     if( fscHidden )
1021     {
1022         fscHidden = false;
1023         setWindowOpacity( 1.0 );
1024     }
1025 #else
1026     show();
1027 #endif
1028
1029 #if HAVE_TRANSPARENCY
1030     setWindowOpacity( DEFAULT_OPACITY );
1031 #endif
1032 }
1033
1034 /**
1035  * Hide fullscreen controller
1036  * FIXME: under windows it have to be done by moving out of screen
1037  *        because hide() doesnt work
1038  */
1039 void FullscreenControllerWidget::hideFSC()
1040 {
1041 #ifdef WIN32TRICK
1042     fscHidden = true;
1043     setWindowOpacity( 0.0 );    // simulate hidding
1044 #else
1045     hide();
1046 #endif
1047 }
1048
1049 /**
1050  * Plane to hide fullscreen controller
1051  */
1052 void FullscreenControllerWidget::planHideFSC()
1053 {
1054     vlc_mutex_lock( &lock );
1055     int i_timeout = i_hide_timeout;
1056     vlc_mutex_unlock( &lock );
1057
1058     p_hideTimer->start( i_timeout );
1059
1060 #if HAVE_TRANSPARENCY
1061     b_slow_hide_begin = true;
1062     i_slow_hide_timeout = i_timeout;
1063     p_slowHideTimer->start( i_slow_hide_timeout / 2 );
1064 #endif
1065 }
1066
1067 /**
1068  * Hidding fullscreen controller slowly
1069  * Linux: need composite manager
1070  * Windows: it is blinking, so it can be enabled by define TRASPARENCY
1071  */
1072 void FullscreenControllerWidget::slowHideFSC()
1073 {
1074 #if HAVE_TRANSPARENCY
1075     if( b_slow_hide_begin )
1076     {
1077         b_slow_hide_begin = false;
1078
1079         p_slowHideTimer->stop();
1080         /* the last part of time divided to 100 pieces */
1081         p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
1082
1083     }
1084     else
1085     {
1086 #ifdef WIN32TRICK
1087          if ( windowOpacity() > 0.0 && !fscHidden )
1088 #else
1089          if ( windowOpacity() > 0.0 )
1090 #endif
1091          {
1092              /* we should use 0.01 because of 100 pieces ^^^
1093                 but than it cannt be done in time */
1094              setWindowOpacity( windowOpacity() - 0.02 );
1095          }
1096
1097          if ( windowOpacity() <= 0.0 )
1098              p_slowHideTimer->stop();
1099     }
1100 #endif
1101 }
1102
1103 /**
1104  * event handling
1105  * events: show, hide, start timer for hidding
1106  */
1107 void FullscreenControllerWidget::customEvent( QEvent *event )
1108 {
1109     bool b_fs;
1110
1111     switch( event->type() )
1112     {
1113     case FullscreenControlToggle_Type:
1114          // FIXME 
1115          TOGGLEV( this );
1116          break;
1117     case FullscreenControlShow_Type:
1118         vlc_mutex_lock( &lock );
1119         b_fs = b_fullscreen;
1120         vlc_mutex_unlock( &lock );
1121
1122         if( b_fs )  // FIXME I am not sure about that one
1123             showFSC();
1124         break;
1125     case FullscreenControlHide_Type:
1126         hideFSC();
1127         break;
1128     case FullscreenControlPlanHide_Type:
1129         if( !b_mouse_over ) // Only if the mouse is not over FSC
1130             planHideFSC();
1131         break;
1132     }
1133 }
1134
1135 /**
1136  * On mouse move
1137  * moving with FSC
1138  */
1139 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1140 {
1141     if ( event->buttons() == Qt::LeftButton )
1142     {
1143         int i_moveX = event->globalX() - i_mouse_last_x;
1144         int i_moveY = event->globalY() - i_mouse_last_y;
1145
1146         move( x() + i_moveX, y() + i_moveY );
1147
1148         i_mouse_last_x = event->globalX();
1149         i_mouse_last_y = event->globalY();
1150     }
1151 }
1152
1153 /**
1154  * On mouse press
1155  * store position of cursor
1156  */
1157 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1158 {
1159     i_mouse_last_x = event->globalX();
1160     i_mouse_last_y = event->globalY();
1161 }
1162
1163 /**
1164  * On mouse go above FSC
1165  */
1166 void FullscreenControllerWidget::enterEvent( QEvent *event )
1167 {
1168     b_mouse_over = true;
1169
1170     p_hideTimer->stop();
1171 #if HAVE_TRANSPARENCY
1172     p_slowHideTimer->stop();
1173 #endif
1174 }
1175
1176 /**
1177  * On mouse go out from FSC
1178  */
1179 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1180 {
1181     planHideFSC();
1182
1183     b_mouse_over = false;
1184 }
1185
1186 /**
1187  * When you get pressed key, send it to video output
1188  * FIXME: clearing focus by clearFocus() to not getting
1189  * key press events didnt work
1190  */
1191 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1192 {
1193     int i_vlck = qtEventToVLCKey( event );
1194     if( i_vlck > 0 )
1195     {
1196         var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1197         event->accept();
1198     }
1199     else
1200         event->ignore();
1201 }
1202
1203 /* */
1204 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object, const char *variable,
1205                                                         vlc_value_t old_val, vlc_value_t new_val,
1206                                                         void *data )
1207 {
1208     vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1209     FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1210
1211     p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1212
1213     return VLC_SUCCESS;
1214 }
1215 /* */
1216 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1217                                                  vlc_value_t old_val, vlc_value_t new_val,
1218                                                  void *data )
1219 {
1220     FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1221
1222     /* Show event */
1223     IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1224     QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1225
1226     /* Plan hide event */
1227     IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1228     QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1229
1230     return VLC_SUCCESS;
1231 }
1232
1233
1234 /**
1235  * It is called when video start
1236  */
1237 void FullscreenControllerWidget::attachVout( vout_thread_t *p_nvout )
1238 {
1239     assert( p_nvout && !p_vout );
1240
1241     p_vout = p_nvout;
1242
1243     vlc_mutex_lock( &lock );
1244     var_AddCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this ); /* I miss a add and fire */
1245     fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ), var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1246     vlc_mutex_unlock( &lock );
1247 }
1248 /**
1249  * It is called after turn off video.
1250  */
1251 void FullscreenControllerWidget::detachVout()
1252 {
1253     if( p_vout )
1254     {
1255         var_DelCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this );
1256         vlc_mutex_lock( &lock );
1257         fullscreenChanged( p_vout, false, 0 );
1258         vlc_mutex_unlock( &lock );
1259         p_vout = NULL;
1260     }
1261 }
1262
1263 /**
1264  * Register and unregister callback for mouse moving
1265  */
1266 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout, bool b_fs, int i_timeout )
1267 {
1268     vlc_mutex_lock( &lock );
1269     if( b_fs && !b_fullscreen )
1270     {
1271         b_fullscreen = true;
1272         i_hide_timeout = i_timeout;
1273         var_AddCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1274     }
1275     else if( !b_fs && b_fullscreen )
1276     {
1277         b_fullscreen = false;
1278         i_hide_timeout = i_timeout;
1279         var_DelCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1280
1281         /* Force fs hidding */
1282         IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1283         QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1284     }
1285     vlc_mutex_unlock( &lock );
1286 }
1287
1288 /**********************************************************************
1289  * Speed control widget
1290  **********************************************************************/
1291 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1292                              QFrame( NULL ), p_intf( _p_i )
1293 {
1294     QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1295     sizePolicy.setHorizontalStretch( 0 );
1296     sizePolicy.setVerticalStretch( 0 );
1297
1298     speedSlider = new QSlider;
1299     speedSlider->setSizePolicy( sizePolicy );
1300     speedSlider->setMaximumSize( QSize( 80, 200 ) );
1301     speedSlider->setOrientation( Qt::Vertical );
1302     speedSlider->setTickPosition( QSlider::TicksRight );
1303
1304     speedSlider->setRange( -24, 24 );
1305     speedSlider->setSingleStep( 1 );
1306     speedSlider->setPageStep( 1 );
1307     speedSlider->setTickInterval( 12 );
1308
1309     CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1310
1311     QToolButton *normalSpeedButton = new QToolButton( this );
1312     normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1313     normalSpeedButton->setAutoRaise( true );
1314     normalSpeedButton->setText( "1x" );
1315     normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1316
1317     CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1318
1319     QVBoxLayout *speedControlLayout = new QVBoxLayout;
1320     speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
1321     speedControlLayout->setSpacing( 4 );
1322     speedControlLayout->addWidget( speedSlider );
1323     speedControlLayout->addWidget( normalSpeedButton );
1324     setLayout( speedControlLayout );
1325 }
1326
1327 SpeedControlWidget::~SpeedControlWidget()
1328 {}
1329
1330 void SpeedControlWidget::setEnable( bool b_enable )
1331 {
1332     speedSlider->setEnabled( b_enable );
1333 }
1334
1335 void SpeedControlWidget::updateControls( int rate )
1336 {
1337     if( speedSlider->isSliderDown() )
1338     {
1339         //We don't want to change anything if the user is using the slider
1340         return;
1341     }
1342
1343     double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
1344     int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
1345
1346     if( sliderValue < speedSlider->minimum() )
1347     {
1348         sliderValue = speedSlider->minimum();
1349     }
1350     else if( sliderValue > speedSlider->maximum() )
1351     {
1352         sliderValue = speedSlider->maximum();
1353     }
1354
1355     //Block signals to avoid feedback loop
1356     speedSlider->blockSignals( true );
1357     speedSlider->setValue( sliderValue );
1358     speedSlider->blockSignals( false );
1359 }
1360
1361 void SpeedControlWidget::updateRate( int sliderValue )
1362 {
1363     double speed = pow( 2, (double)sliderValue / 12 );
1364     int rate = INPUT_RATE_DEFAULT / speed;
1365
1366     THEMIM->getIM()->setRate(rate);
1367 }
1368
1369 void SpeedControlWidget::resetRate()
1370 {
1371     THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
1372 }