]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
d5d9b68636c14f7ad7c3c5e9f6dbd70454d8e841
[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         recordButton->setVisible( var_GetBool( THEMIM->getInput(), "can-record" ) );
376     }
377     else
378     {
379         recordButton->setVisible( false );
380     }
381
382     ABButton->setEnabled( enable );
383     recordButton->setEnabled( enable );
384
385     if( enable && ( i_last_input_id != i_input_id ) )
386     {
387         timeA = timeB = 0;
388         i_last_input_id = i_input_id;
389         emit timeChanged();
390     }
391 }
392
393 void AdvControlsWidget::enableVideo( bool enable )
394 {
395     snapshotButton->setEnabled( enable );
396 #if 0
397     frameButton->setEnabled( enable );
398 #endif
399 }
400
401 void AdvControlsWidget::snapshot()
402 {
403     vout_thread_t *p_vout =
404         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
405     if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
406 }
407
408 /* Function called when the button is clicked() */
409 void AdvControlsWidget::fromAtoB()
410 {
411     if( !timeA )
412     {
413         timeA = var_GetTime( THEMIM->getInput(), "time"  );
414         emit timeChanged();
415         return;
416     }
417     if( !timeB )
418     {
419         timeB = var_GetTime( THEMIM->getInput(), "time"  );
420         var_SetTime( THEMIM->getInput(), "time" , timeA );
421         emit timeChanged();
422         return;
423     }
424     timeA = 0;
425     timeB = 0;
426     emit timeChanged();
427 }
428
429 /* setting/synchro icons after click on main or fs controller */
430 void AdvControlsWidget::setIcon()
431 {
432     if( !timeA && !timeB)
433     {
434         ABButton->setIcon( QIcon( ":/atob_nob" ) );
435         ABButton->setToolTip( qtr( "Loop from point A to point B continuously\nClick to set point A" ) );
436     }
437     else if( timeA && !timeB )
438     {
439         ABButton->setIcon( QIcon( ":/atob_noa" ) );
440         ABButton->setToolTip( qtr( "Click to set point B" ) );
441     }
442     else if( timeA && timeB )
443     {
444         ABButton->setIcon( QIcon( ":/atob" ) );
445         ABButton->setToolTip( qtr( "Stop the A to B loop" ) );
446     }
447 }
448
449 /* Function called regularly when in an AtoB loop */
450 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
451 {
452     if( timeB )
453     {
454         if( ( i_time >= (int)( timeB/1000000 ) )
455             || ( i_time < (int)( timeA/1000000 ) ) )
456             var_SetTime( THEMIM->getInput(), "time" , timeA );
457     }
458 }
459
460 void AdvControlsWidget::record()
461 {
462     input_thread_t *p_input = THEMIM->getInput();
463     if( p_input )
464     {
465         /* This method won't work fine if the stream can't be cut anywhere */
466         const bool b_recording = var_GetBool( p_input, "record" );
467         var_SetBool( p_input, "record", !b_recording );
468 #if 0
469         else
470         {
471             /* 'record' access-filter is not loaded, we open Save dialog */
472             input_item_t *p_item = input_GetItem( p_input );
473             if( !p_item )
474                 return;
475
476             char *psz = input_item_GetURI( p_item );
477             if( psz )
478                 THEDP->streamingDialog( NULL, psz, true );
479         }
480 #endif
481     }
482 }
483
484 #if 0
485 //FIXME Frame by frame function
486 void AdvControlsWidget::frame(){}
487 #endif
488
489 /*****************************
490  * DA Control Widget !
491  *****************************/
492 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
493                                 MainInterface *_p_mi,
494                                 bool b_advControls,
495                                 bool b_shiny,
496                                 bool b_fsCreation) :
497                                 QFrame( _p_mi ), p_intf( _p_i )
498 {
499     setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
500
501     /** The main Slider **/
502     slider = new InputSlider( Qt::Horizontal, NULL );
503     /* Update the position when the IM has changed */
504     CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
505              slider, setPosition( float, int, int ) );
506     /* And update the IM, when the position has changed */
507     CONNECT( slider, sliderDragged( float ),
508              THEMIM->getIM(), sliderUpdate( float ) );
509
510     /** Slower and faster Buttons **/
511     slowerButton = new QToolButton;
512     slowerButton->setAutoRaise( true );
513     slowerButton->setMaximumSize( QSize( 26, 20 ) );
514
515     BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
516
517     fasterButton = new QToolButton;
518     fasterButton->setAutoRaise( true );
519     fasterButton->setMaximumSize( QSize( 26, 20 ) );
520
521     BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
522
523     /* advanced Controls handling */
524     b_advancedVisible = b_advControls;
525
526     advControls = new AdvControlsWidget( p_intf, b_fsCreation );
527     if( !b_advancedVisible ) advControls->hide();
528
529     /** Disc and Menus handling */
530     discFrame = new QWidget( this );
531
532     QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
533     discLayout->setSpacing( 0 );
534     discLayout->setMargin( 0 );
535
536     prevSectionButton = new QPushButton( discFrame );
537     setupSmallButton( prevSectionButton );
538     discLayout->addWidget( prevSectionButton );
539
540     menuButton = new QPushButton( discFrame );
541     setupSmallButton( menuButton );
542     discLayout->addWidget( menuButton );
543
544     nextSectionButton = new QPushButton( discFrame );
545     setupSmallButton( nextSectionButton );
546     discLayout->addWidget( nextSectionButton );
547
548     BUTTON_SET_IMG( prevSectionButton, "", dvd_prev, "" );
549     BUTTON_SET_IMG( nextSectionButton, "", dvd_next, "" );
550     BUTTON_SET_IMG( menuButton, "", dvd_menu, qtr( "Menu" ) );
551
552     discFrame->hide();
553
554     /* Change the navigation button display when the IM navigation changes */
555     CONNECT( THEMIM->getIM(), navigationChanged( int ),
556              this, setNavigation( int ) );
557     /* Changes the IM navigation when triggered on the nav buttons */
558     CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
559              sectionPrev() );
560     CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
561              sectionNext() );
562     CONNECT( menuButton, clicked(), THEMIM->getIM(),
563              sectionMenu() );
564
565     /**
566      * Telextext QFrame
567      * TODO: Merge with upper menu in a StackLayout
568      **/
569     telexFrame = new QWidget( this );
570     QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
571     telexLayout->setSpacing( 0 );
572     telexLayout->setMargin( 0 );
573
574     telexOn = new QPushButton;
575     setupSmallButton( telexOn );
576     telexLayout->addWidget( telexOn );
577
578     telexTransparent = new QPushButton;
579     setupSmallButton( telexTransparent );
580     telexLayout->addWidget( telexTransparent );
581     b_telexTransparent = false;
582
583     telexPage = new QSpinBox;
584     telexPage->setRange( 0, 999 );
585     telexPage->setValue( 100 );
586     telexPage->setAccelerated( true );
587     telexPage->setWrapping( true );
588     telexPage->setAlignment( Qt::AlignRight );
589     telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
590     telexLayout->addWidget( telexPage );
591
592     telexFrame->hide(); /* default hidden */
593
594     CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
595              telexGotoPage( int ) );
596     CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
597               telexPage, setValue( int ) );
598
599     BUTTON_SET_IMG( telexOn, "", tv, qtr( "Teletext on" ) );
600
601     CONNECT( telexOn, clicked(), THEMIM->getIM(),
602              telexToggleButtons() );
603     CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
604              telexToggle( bool ) );
605     CONNECT( THEMIM->getIM(), toggleTelexButtons(),
606               this, toggleTeletext() );
607     b_telexEnabled = false;
608     telexTransparent->setEnabled( false );
609     telexPage->setEnabled( false );
610
611     BUTTON_SET_IMG( telexTransparent, "", tvtelx, qtr( "Teletext" ) );
612     CONNECT( telexTransparent, clicked( bool ),
613              THEMIM->getIM(), telexSetTransparency() );
614     CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
615               this, toggleTeletextTransparency() );
616     CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
617              this, enableTeletext( bool ) );
618
619     /** Play Buttons **/
620     QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
621     sizePolicy.setHorizontalStretch( 0 );
622     sizePolicy.setVerticalStretch( 0 );
623
624     /* Play */
625     playButton = new QPushButton;
626     playButton->setSizePolicy( sizePolicy );
627     playButton->setMaximumSize( QSize( 36, 36 ) );
628     playButton->setMinimumSize( QSize( 36, 36 ) );
629     playButton->setIconSize( QSize( 30, 30 ) );
630
631
632     /** Prev + Stop + Next Block **/
633     controlButLayout = new QHBoxLayout;
634     controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
635
636     /* Prev */
637     QPushButton *prevButton = new QPushButton;
638     prevButton->setSizePolicy( sizePolicy );
639     setupSmallButton( prevButton );
640
641     controlButLayout->addWidget( prevButton );
642
643     /* Stop */
644     QPushButton *stopButton = new QPushButton;
645     stopButton->setSizePolicy( sizePolicy );
646     setupSmallButton( stopButton );
647
648     controlButLayout->addWidget( stopButton );
649
650     /* next */
651     QPushButton *nextButton = new QPushButton;
652     nextButton->setSizePolicy( sizePolicy );
653     setupSmallButton( nextButton );
654
655     controlButLayout->addWidget( nextButton );
656
657     /* Add this block to the main layout */
658
659     BUTTON_SET_ACT_I( playButton, "", play_b, qtr( I_PLAY_TOOLTIP ), play() );
660     BUTTON_SET_ACT_I( prevButton, "" , previous_b,
661                       qtr( "Previous media in the playlist" ), prev() );
662     BUTTON_SET_ACT_I( nextButton, "", next_b,
663                       qtr( "Next media in the playlist" ), next() );
664     BUTTON_SET_ACT_I( stopButton, "", stop_b, qtr( "Stop playback" ), stop() );
665
666     /*
667      * Other first Line buttons
668      */
669     /** Fullscreen/Visualisation **/
670     fullscreenButton = new QPushButton;
671     BUTTON_SET_ACT_I( fullscreenButton, "", fullscreen,
672             qtr( "Toggle the video in fullscreen" ), fullscreen() );
673     setupSmallButton( fullscreenButton );
674
675     if( !b_fsCreation )
676     {
677         /** Playlist Button **/
678         playlistButton = new QPushButton;
679         setupSmallButton( playlistButton );
680         BUTTON_SET_IMG( playlistButton, "" , playlist, qtr( "Show playlist" ) );
681         CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
682
683         /** extended Settings **/
684         extSettingsButton = new QPushButton;
685         BUTTON_SET_ACT_I( extSettingsButton, "", extended,
686                 qtr( "Show extended settings" ), extSettings() );
687         setupSmallButton( extSettingsButton );
688     }
689
690     /* Volume */
691     hVolLabel = new VolumeClickHandler( p_intf, this );
692
693     volMuteLabel = new QLabel;
694     volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
695     volMuteLabel->installEventFilter( hVolLabel );
696
697     if( b_shiny )
698     {
699         volumeSlider = new SoundSlider( this,
700             config_GetInt( p_intf, "volume-step" ),
701             config_GetInt( p_intf, "qt-volume-complete" ),
702             config_GetPsz( p_intf, "qt-slider-colours" ) );
703     }
704     else
705     {
706         volumeSlider = new QSlider( this );
707         volumeSlider->setOrientation( Qt::Horizontal );
708     }
709     volumeSlider->setMaximumSize( QSize( 200, 40 ) );
710     volumeSlider->setMinimumSize( QSize( 85, 30 ) );
711     volumeSlider->setFocusPolicy( Qt::NoFocus );
712
713     /* Set the volume from the config */
714     volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
715                               VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
716
717     /* Force the update at build time in order to have a muted icon if needed */
718     updateVolume( volumeSlider->value() );
719
720     /* Volume control connection */
721     CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
722     CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
723
724     if( !b_fsCreation )
725     {
726         controlLayout = new QGridLayout( this );
727
728         controlLayout->setSpacing( 0 );
729         controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
730
731         controlLayout->addWidget( slider, 0, 1, 1, 18 );
732         controlLayout->addWidget( slowerButton, 0, 0 );
733         controlLayout->addWidget( fasterButton, 0, 19 );
734
735         controlLayout->addWidget( discFrame, 1, 8, 2, 3, Qt::AlignBottom );
736         controlLayout->addWidget( telexFrame, 1, 8, 2, 5, Qt::AlignBottom );
737
738         controlLayout->addWidget( playButton, 2, 0, 2, 2, Qt::AlignBottom );
739         controlLayout->setColumnMinimumWidth( 2, 10 );
740         controlLayout->setColumnStretch( 2, 0 );
741
742         controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
743         /* Column 6 is unused */
744         controlLayout->setColumnStretch( 6, 0 );
745         controlLayout->setColumnStretch( 7, 0 );
746         controlLayout->setColumnMinimumWidth( 7, 10 );
747
748         controlLayout->addWidget( fullscreenButton, 3, 8, Qt::AlignBottom );
749         controlLayout->addWidget( playlistButton, 3, 9, Qt::AlignBottom );
750         controlLayout->addWidget( extSettingsButton, 3, 10, Qt::AlignBottom );
751         controlLayout->setColumnStretch( 11, 0 ); /* telex alignment */
752
753         controlLayout->setColumnStretch( 12, 0 );
754         controlLayout->setColumnMinimumWidth( 12, 10 );
755
756         controlLayout->addWidget( advControls, 3, 13, 1, 3, Qt::AlignBottom );
757
758         controlLayout->setColumnStretch( 16, 10 );
759         controlLayout->setColumnMinimumWidth( 16, 10 );
760
761         controlLayout->addWidget( volMuteLabel, 3, 17, Qt::AlignBottom );
762         controlLayout->addWidget( volumeSlider, 3, 18, 1 , 2, Qt::AlignBottom );
763     }
764
765     updateInput();
766 }
767
768 ControlsWidget::~ControlsWidget()
769 {}
770
771 void ControlsWidget::toggleTeletext()
772 {
773     bool b_enabled = THEMIM->teletextState();
774     if( b_telexEnabled )
775     {
776         telexTransparent->setEnabled( false );
777         telexPage->setEnabled( false );
778         b_telexEnabled = false;
779     }
780     else if( b_enabled )
781     {
782         telexTransparent->setEnabled( true );
783         telexPage->setEnabled( true );
784         b_telexEnabled = true;
785     }
786 }
787
788 void ControlsWidget::enableTeletext( bool b_enable )
789 {
790     telexFrame->setVisible( b_enable );
791     bool b_on = THEMIM->teletextState();
792
793     telexOn->setChecked( b_on );
794     telexTransparent->setEnabled( b_on );
795     telexPage->setEnabled( b_on );
796     b_telexEnabled = b_on;
797 }
798
799 void ControlsWidget::toggleTeletextTransparency()
800 {
801     if( b_telexTransparent )
802     {
803         telexTransparent->setIcon( QIcon( ":/tvtelx" ) );
804         telexTransparent->setToolTip( qtr( "Teletext" ) );
805         b_telexTransparent = false;
806     }
807     else
808     {
809         telexTransparent->setIcon( QIcon( ":/tvtelx-transparent" ) );
810         telexTransparent->setToolTip( qtr( "Transparent" ) );
811         b_telexTransparent = true;
812     }
813 }
814
815 void ControlsWidget::stop()
816 {
817     THEMIM->stop();
818 }
819
820 void ControlsWidget::play()
821 {
822     if( THEPL->current.i_size == 0 )
823     {
824         /* The playlist is empty, open a file requester */
825         THEDP->openFileDialog();
826         setStatus( 0 );
827         return;
828     }
829     THEMIM->togglePlayPause();
830 }
831
832 void ControlsWidget::prev()
833 {
834     THEMIM->prev();
835 }
836
837 void ControlsWidget::next()
838 {
839     THEMIM->next();
840 }
841
842 void ControlsWidget::setNavigation( int navigation )
843 {
844 #define HELP_PCH N_( "Previous chapter" )
845 #define HELP_NCH N_( "Next chapter" )
846
847     // 1 = chapter, 2 = title, 0 = no
848     if( navigation == 0 )
849     {
850         discFrame->hide();
851     } else if( navigation == 1 ) {
852         prevSectionButton->setToolTip( qtr( HELP_PCH ) );
853         nextSectionButton->setToolTip( qtr( HELP_NCH ) );
854         menuButton->show();
855         discFrame->show();
856     } else {
857         prevSectionButton->setToolTip( qtr( HELP_PCH ) );
858         nextSectionButton->setToolTip( qtr( HELP_NCH ) );
859         menuButton->hide();
860         discFrame->show();
861     }
862 }
863
864 static bool b_my_volume;
865 void ControlsWidget::updateVolume( int i_sliderVolume )
866 {
867     if( !b_my_volume )
868     {
869         int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
870         aout_VolumeSet( p_intf, i_res );
871     }
872     if( i_sliderVolume == 0 )
873     {
874         volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
875         volMuteLabel->setToolTip( qtr( "Unmute" ) );
876         return;
877     }
878
879     if( i_sliderVolume < VOLUME_MAX / 3 )
880         volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
881     else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
882         volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
883     else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
884     volMuteLabel->setToolTip( qtr( "Mute" ) );
885 }
886
887 void ControlsWidget::updateVolume()
888 {
889     /* Audio part */
890     audio_volume_t i_volume;
891     aout_VolumeGet( p_intf, &i_volume );
892     i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
893     int i_gauge = volumeSlider->value();
894     b_my_volume = false;
895     if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
896     {
897         b_my_volume = true;
898         volumeSlider->setValue( i_volume );
899         b_my_volume = false;
900     }
901 }
902
903 void ControlsWidget::updateInput()
904 {
905     /* Activate the interface buttons according to the presence of the input */
906     enableInput( THEMIM->getIM()->hasInput() );
907     enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
908 }
909
910 void ControlsWidget::setStatus( int status )
911 {
912     if( status == PLAYING_S ) /* Playing */
913     {
914         playButton->setIcon( QIcon( ":/pause_b" ) );
915         playButton->setToolTip( qtr( "Pause the playback" ) );
916     }
917     else
918     {
919         playButton->setIcon( QIcon( ":/play_b" ) );
920         playButton->setToolTip( qtr( I_PLAY_TOOLTIP ) );
921     }
922 }
923
924 /**
925  * TODO
926  * This functions toggle the fullscreen mode
927  * If there is no video, it should first activate Visualisations...
928  *  This has also to be fixed in enableVideo()
929  */
930 void ControlsWidget::fullscreen()
931 {
932     vout_thread_t *p_vout =
933         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
934     if( p_vout)
935     {
936         var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
937         vlc_object_release( p_vout );
938     }
939 }
940
941 void ControlsWidget::extSettings()
942 {
943     THEDP->extendedDialog();
944 }
945
946 void ControlsWidget::slower()
947 {
948     THEMIM->getIM()->slower();
949 }
950
951 void ControlsWidget::faster()
952 {
953     THEMIM->getIM()->faster();
954 }
955
956 void ControlsWidget::enableInput( bool enable )
957 {
958     slowerButton->setEnabled( enable );
959     slider->setEnabled( enable );
960     slider->setSliderPosition ( 0 );
961     fasterButton->setEnabled( enable );
962
963     /* Advanced Buttons too */
964     advControls->enableInput( enable );
965 }
966
967 void ControlsWidget::enableVideo( bool enable )
968 {
969     // TODO Later make the fullscreenButton toggle Visualisation and so on.
970     fullscreenButton->setEnabled( enable );
971
972     /* Advanced Buttons too */
973     advControls->enableVideo( enable );
974 }
975
976 void ControlsWidget::toggleAdvanced()
977 {
978     if( advControls && !b_advancedVisible )
979     {
980         advControls->show();
981         b_advancedVisible = true;
982     }
983     else
984     {
985         advControls->hide();
986         b_advancedVisible = false;
987     }
988     emit advancedControlsToggled( b_advancedVisible );
989 }
990
991
992 /**********************************************************************
993  * Fullscrenn control widget
994  **********************************************************************/
995 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
996         MainInterface *_p_mi, bool b_advControls, bool b_shiny )
997         : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
998           i_mouse_last_x( -1 ), i_mouse_last_y( -1 ), b_mouse_over(false),
999           b_slow_hide_begin(false), i_slow_hide_timeout(1),
1000           b_fullscreen( false ), i_hide_timeout( 1 ), p_vout(NULL)
1001 {
1002     setWindowFlags( Qt::ToolTip );
1003
1004     setFrameShape( QFrame::StyledPanel );
1005     setFrameStyle( QFrame::Sunken );
1006     setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
1007
1008     QGridLayout *fsLayout = new QGridLayout( this );
1009     fsLayout->setLayoutMargins( 5, 2, 5, 2, 5 );
1010
1011     /* First line */
1012     slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
1013     slider->setMinimumWidth( 220 );
1014     fsLayout->addWidget( slowerButton, 0, 0 );
1015     fsLayout->addWidget( slider, 0, 1, 1, 9 );
1016     fsLayout->addWidget( fasterButton, 0, 10 );
1017
1018     fsLayout->addWidget( playButton, 1, 0, 1, 2 );
1019     fsLayout->addLayout( controlButLayout, 1, 2 );
1020
1021     fsLayout->addWidget( discFrame, 1, 3 );
1022     fsLayout->addWidget( telexFrame, 1, 4 );
1023     fsLayout->addWidget( fullscreenButton, 1, 5 );
1024     fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
1025
1026     fsLayout->setColumnStretch( 7, 10 );
1027     fsLayout->addWidget( volMuteLabel, 1, 8 );
1028     fsLayout->addWidget( volumeSlider, 1, 9, 1, 2 );
1029
1030     /* hiding timer */
1031     p_hideTimer = new QTimer( this );
1032     CONNECT( p_hideTimer, timeout(), this, hideFSC() );
1033     p_hideTimer->setSingleShot( true );
1034
1035     /* slow hiding timer */
1036 #if HAVE_TRANSPARENCY
1037     p_slowHideTimer = new QTimer( this );
1038     CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
1039 #endif
1040
1041     adjustSize ();  /* need to get real width and height for moving */
1042
1043     /* center down */
1044     QDesktopWidget * p_desktop = QApplication::desktop();
1045
1046     move( p_desktop->width() / 2 - width() / 2,
1047           p_desktop->height() - height() );
1048
1049 #ifdef WIN32TRICK
1050     setWindowOpacity( 0.0 );
1051     b_fscHidden = true;
1052     adjustSize();
1053     show();
1054 #endif
1055
1056     fullscreenButton->setIcon( QIcon( ":/defullscreen" ) );
1057
1058     vlc_mutex_init_recursive( &lock );
1059 }
1060
1061 FullscreenControllerWidget::~FullscreenControllerWidget()
1062 {
1063     detachVout();
1064     vlc_mutex_destroy( &lock );
1065 }
1066
1067 /**
1068  * Show fullscreen controller
1069  */
1070 void FullscreenControllerWidget::showFSC()
1071 {
1072     adjustSize();
1073 #ifdef WIN32TRICK
1074     // after quiting and going to fs, we need to call show()
1075     if( isHidden() )
1076         show();
1077
1078     if( b_fscHidden )
1079     {
1080         b_fscHidden = false;
1081         setWindowOpacity( 1.0 );
1082     }
1083 #else
1084     show();
1085 #endif
1086
1087 #if HAVE_TRANSPARENCY
1088     setWindowOpacity( DEFAULT_OPACITY );
1089 #endif
1090 }
1091
1092 /**
1093  * Hide fullscreen controller
1094  * FIXME: under windows it have to be done by moving out of screen
1095  *        because hide() doesnt work
1096  */
1097 void FullscreenControllerWidget::hideFSC()
1098 {
1099 #ifdef WIN32TRICK
1100     b_fscHidden = true;
1101     setWindowOpacity( 0.0 );    // simulate hidding
1102 #else
1103     hide();
1104 #endif
1105 }
1106
1107 /**
1108  * Plane to hide fullscreen controller
1109  */
1110 void FullscreenControllerWidget::planHideFSC()
1111 {
1112     vlc_mutex_lock( &lock );
1113     int i_timeout = i_hide_timeout;
1114     vlc_mutex_unlock( &lock );
1115
1116     p_hideTimer->start( i_timeout );
1117
1118 #if HAVE_TRANSPARENCY
1119     b_slow_hide_begin = true;
1120     i_slow_hide_timeout = i_timeout;
1121     p_slowHideTimer->start( i_slow_hide_timeout / 2 );
1122 #endif
1123 }
1124
1125 /**
1126  * Hidding fullscreen controller slowly
1127  * Linux: need composite manager
1128  * Windows: it is blinking, so it can be enabled by define TRASPARENCY
1129  */
1130 void FullscreenControllerWidget::slowHideFSC()
1131 {
1132 #if HAVE_TRANSPARENCY
1133     if( b_slow_hide_begin )
1134     {
1135         b_slow_hide_begin = false;
1136
1137         p_slowHideTimer->stop();
1138         /* the last part of time divided to 100 pieces */
1139         p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
1140
1141     }
1142     else
1143     {
1144 #ifdef WIN32TRICK
1145          if ( windowOpacity() > 0.0 && !b_fscHidden )
1146 #else
1147          if ( windowOpacity() > 0.0 )
1148 #endif
1149          {
1150              /* we should use 0.01 because of 100 pieces ^^^
1151                 but than it cannt be done in time */
1152              setWindowOpacity( windowOpacity() - 0.02 );
1153          }
1154
1155          if ( windowOpacity() <= 0.0 )
1156              p_slowHideTimer->stop();
1157     }
1158 #endif
1159 }
1160
1161 /**
1162  * event handling
1163  * events: show, hide, start timer for hidding
1164  */
1165 void FullscreenControllerWidget::customEvent( QEvent *event )
1166 {
1167     bool b_fs;
1168
1169     switch( event->type() )
1170     {
1171         case FullscreenControlToggle_Type:
1172             vlc_mutex_lock( &lock );
1173             b_fs = b_fullscreen;
1174             vlc_mutex_unlock( &lock );
1175             if( b_fs )
1176 #ifdef WIN32TRICK
1177                 if( b_fscHidden )
1178 #else
1179                 if( isHidden() )
1180 #endif
1181                 {
1182                     p_hideTimer->stop();
1183                     showFSC();
1184                 }
1185                 else
1186                     hideFSC();
1187             break;
1188         case FullscreenControlShow_Type:
1189             vlc_mutex_lock( &lock );
1190             b_fs = b_fullscreen;
1191             vlc_mutex_unlock( &lock );
1192
1193             if( b_fs )  // FIXME I am not sure about that one
1194                 showFSC();
1195             break;
1196         case FullscreenControlHide_Type:
1197             hideFSC();
1198             break;
1199         case FullscreenControlPlanHide_Type:
1200             if( !b_mouse_over ) // Only if the mouse is not over FSC
1201                 planHideFSC();
1202             break;
1203     }
1204 }
1205
1206 /**
1207  * On mouse move
1208  * moving with FSC
1209  */
1210 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1211 {
1212     if ( event->buttons() == Qt::LeftButton )
1213     {
1214         int i_moveX = event->globalX() - i_mouse_last_x;
1215         int i_moveY = event->globalY() - i_mouse_last_y;
1216
1217         move( x() + i_moveX, y() + i_moveY );
1218
1219         i_mouse_last_x = event->globalX();
1220         i_mouse_last_y = event->globalY();
1221     }
1222 }
1223
1224 /**
1225  * On mouse press
1226  * store position of cursor
1227  */
1228 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1229 {
1230     i_mouse_last_x = event->globalX();
1231     i_mouse_last_y = event->globalY();
1232 }
1233
1234 /**
1235  * On mouse go above FSC
1236  */
1237 void FullscreenControllerWidget::enterEvent( QEvent *event )
1238 {
1239     b_mouse_over = true;
1240
1241     p_hideTimer->stop();
1242 #if HAVE_TRANSPARENCY
1243     p_slowHideTimer->stop();
1244 #endif
1245 }
1246
1247 /**
1248  * On mouse go out from FSC
1249  */
1250 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1251 {
1252     planHideFSC();
1253
1254     b_mouse_over = false;
1255 }
1256
1257 /**
1258  * When you get pressed key, send it to video output
1259  * FIXME: clearing focus by clearFocus() to not getting
1260  * key press events didnt work
1261  */
1262 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1263 {
1264     int i_vlck = qtEventToVLCKey( event );
1265     if( i_vlck > 0 )
1266     {
1267         var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1268         event->accept();
1269     }
1270     else
1271         event->ignore();
1272 }
1273
1274 /* */
1275 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object, const char *variable,
1276                                                         vlc_value_t old_val, vlc_value_t new_val,
1277                                                         void *data )
1278 {
1279     vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1280     FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1281
1282     p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1283
1284     return VLC_SUCCESS;
1285 }
1286 /* */
1287 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1288                                                  vlc_value_t old_val, vlc_value_t new_val,
1289                                                  void *data )
1290 {
1291     FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1292
1293     /* Show event */
1294     IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1295     QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1296
1297     /* Plan hide event */
1298     IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1299     QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1300
1301     return VLC_SUCCESS;
1302 }
1303
1304
1305 /**
1306  * It is called when video start
1307  */
1308 void FullscreenControllerWidget::attachVout( vout_thread_t *p_nvout )
1309 {
1310     assert( p_nvout && !p_vout );
1311
1312     p_vout = p_nvout;
1313
1314     vlc_mutex_lock( &lock );
1315     var_AddCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this ); /* I miss a add and fire */
1316     fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ), var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1317     vlc_mutex_unlock( &lock );
1318 }
1319 /**
1320  * It is called after turn off video.
1321  */
1322 void FullscreenControllerWidget::detachVout()
1323 {
1324     if( p_vout )
1325     {
1326         var_DelCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this );
1327         vlc_mutex_lock( &lock );
1328         fullscreenChanged( p_vout, false, 0 );
1329         vlc_mutex_unlock( &lock );
1330         p_vout = NULL;
1331     }
1332 }
1333
1334 /**
1335  * Register and unregister callback for mouse moving
1336  */
1337 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout, bool b_fs, int i_timeout )
1338 {
1339     vlc_mutex_lock( &lock );
1340     if( b_fs && !b_fullscreen )
1341     {
1342         b_fullscreen = true;
1343         i_hide_timeout = i_timeout;
1344         var_AddCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1345     }
1346     else if( !b_fs && b_fullscreen )
1347     {
1348         b_fullscreen = false;
1349         i_hide_timeout = i_timeout;
1350         var_DelCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1351
1352         /* Force fs hidding */
1353         IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1354         QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1355     }
1356     vlc_mutex_unlock( &lock );
1357 }
1358
1359 /**********************************************************************
1360  * Speed control widget
1361  **********************************************************************/
1362 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1363                              QFrame( NULL ), p_intf( _p_i )
1364 {
1365     QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1366     sizePolicy.setHorizontalStretch( 0 );
1367     sizePolicy.setVerticalStretch( 0 );
1368
1369     speedSlider = new QSlider;
1370     speedSlider->setSizePolicy( sizePolicy );
1371     speedSlider->setMaximumSize( QSize( 80, 200 ) );
1372     speedSlider->setOrientation( Qt::Vertical );
1373     speedSlider->setTickPosition( QSlider::TicksRight );
1374
1375     speedSlider->setRange( -24, 24 );
1376     speedSlider->setSingleStep( 1 );
1377     speedSlider->setPageStep( 1 );
1378     speedSlider->setTickInterval( 12 );
1379
1380     CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1381
1382     QToolButton *normalSpeedButton = new QToolButton( this );
1383     normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1384     normalSpeedButton->setAutoRaise( true );
1385     normalSpeedButton->setText( "1x" );
1386     normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1387
1388     CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1389
1390     QVBoxLayout *speedControlLayout = new QVBoxLayout;
1391     speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
1392     speedControlLayout->setSpacing( 4 );
1393     speedControlLayout->addWidget( speedSlider );
1394     speedControlLayout->addWidget( normalSpeedButton );
1395     setLayout( speedControlLayout );
1396 }
1397
1398 SpeedControlWidget::~SpeedControlWidget()
1399 {}
1400
1401 void SpeedControlWidget::setEnable( bool b_enable )
1402 {
1403     speedSlider->setEnabled( b_enable );
1404 }
1405
1406 void SpeedControlWidget::updateControls( int rate )
1407 {
1408     if( speedSlider->isSliderDown() )
1409     {
1410         //We don't want to change anything if the user is using the slider
1411         return;
1412     }
1413
1414     double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
1415     int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
1416
1417     if( sliderValue < speedSlider->minimum() )
1418     {
1419         sliderValue = speedSlider->minimum();
1420     }
1421     else if( sliderValue > speedSlider->maximum() )
1422     {
1423         sliderValue = speedSlider->maximum();
1424     }
1425
1426     //Block signals to avoid feedback loop
1427     speedSlider->blockSignals( true );
1428     speedSlider->setValue( sliderValue );
1429     speedSlider->blockSignals( false );
1430 }
1431
1432 void SpeedControlWidget::updateRate( int sliderValue )
1433 {
1434     double speed = pow( 2, (double)sliderValue / 12 );
1435     int rate = INPUT_RATE_DEFAULT / speed;
1436
1437     THEMIM->getIM()->setRate(rate);
1438 }
1439
1440 void SpeedControlWidget::resetRate()
1441 {
1442     THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
1443 }