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