]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
d91580f673c26dcbda0f857462a7836b969389db
[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 64
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 /* FIXME Record function */
462 void AdvControlsWidget::record()
463 {
464     input_thread_t *p_input = THEMIM->getInput();
465     if( p_input )
466     {
467         /* This method won't work fine if the stream can't be cut anywhere */
468         if( var_Type( p_input, "record-toggle" ) == VLC_VAR_VOID )
469             var_TriggerCallback( p_input, "record-toggle" );
470 #if 0
471         else
472         {
473             /* 'record' access-filter is not loaded, we open Save dialog */
474             input_item_t *p_item = input_GetItem( p_input );
475             if( !p_item )
476                 return;
477
478             char *psz = input_item_GetURI( p_item );
479             if( psz )
480                 THEDP->streamingDialog( NULL, psz, true );
481         }
482 #endif
483     }
484 }
485
486 #if 0
487 //FIXME Frame by frame function
488 void AdvControlsWidget::frame(){}
489 #endif
490
491 /*****************************
492  * DA Control Widget !
493  *****************************/
494 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
495                                 MainInterface *_p_mi,
496                                 bool b_advControls,
497                                 bool b_shiny,
498                                 bool b_fsCreation) :
499                                 QFrame( _p_mi ), p_intf( _p_i )
500 {
501     setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
502
503     /** The main Slider **/
504     slider = new InputSlider( Qt::Horizontal, NULL );
505     /* Update the position when the IM has changed */
506     CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
507              slider, setPosition( float, int, int ) );
508     /* And update the IM, when the position has changed */
509     CONNECT( slider, sliderDragged( float ),
510              THEMIM->getIM(), sliderUpdate( float ) );
511
512     /** Slower and faster Buttons **/
513     slowerButton = new QToolButton;
514     slowerButton->setAutoRaise( true );
515     slowerButton->setMaximumSize( QSize( 26, 20 ) );
516
517     BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
518
519     fasterButton = new QToolButton;
520     fasterButton->setAutoRaise( true );
521     fasterButton->setMaximumSize( QSize( 26, 20 ) );
522
523     BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
524
525     /* advanced Controls handling */
526     b_advancedVisible = b_advControls;
527
528     advControls = new AdvControlsWidget( p_intf, b_fsCreation );
529     if( !b_advancedVisible ) advControls->hide();
530
531     /** Disc and Menus handling */
532     discFrame = new QWidget( this );
533
534     QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
535     discLayout->setSpacing( 0 );
536     discLayout->setMargin( 0 );
537
538     prevSectionButton = new QPushButton( discFrame );
539     setupSmallButton( prevSectionButton );
540     discLayout->addWidget( prevSectionButton );
541
542     menuButton = new QPushButton( discFrame );
543     setupSmallButton( menuButton );
544     discLayout->addWidget( menuButton );
545
546     nextSectionButton = new QPushButton( discFrame );
547     setupSmallButton( nextSectionButton );
548     discLayout->addWidget( nextSectionButton );
549
550     BUTTON_SET_IMG( prevSectionButton, "", dvd_prev, "" );
551     BUTTON_SET_IMG( nextSectionButton, "", dvd_next, "" );
552     BUTTON_SET_IMG( menuButton, "", dvd_menu, qtr( "Menu" ) );
553
554     discFrame->hide();
555
556     /* Change the navigation button display when the IM navigation changes */
557     CONNECT( THEMIM->getIM(), navigationChanged( int ),
558              this, setNavigation( int ) );
559     /* Changes the IM navigation when triggered on the nav buttons */
560     CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
561              sectionPrev() );
562     CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
563              sectionNext() );
564     CONNECT( menuButton, clicked(), THEMIM->getIM(),
565              sectionMenu() );
566
567     /**
568      * Telextext QFrame
569      * TODO: Merge with upper menu in a StackLayout
570      **/
571     telexFrame = new QWidget( this );
572     QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
573     telexLayout->setSpacing( 0 );
574     telexLayout->setMargin( 0 );
575
576     telexOn = new QPushButton;
577     setupSmallButton( telexOn );
578     telexLayout->addWidget( telexOn );
579
580     telexTransparent = new QPushButton;
581     setupSmallButton( telexTransparent );
582     telexLayout->addWidget( telexTransparent );
583     b_telexTransparent = false;
584
585     telexPage = new QSpinBox;
586     telexPage->setRange( 0, 999 );
587     telexPage->setValue( 100 );
588     telexPage->setAccelerated( true );
589     telexPage->setWrapping( true );
590     telexPage->setAlignment( Qt::AlignRight );
591     telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
592     telexLayout->addWidget( telexPage );
593
594     telexFrame->hide(); /* default hidden */
595
596     CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
597              telexGotoPage( int ) );
598     CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
599               telexPage, setValue( int ) );
600
601     BUTTON_SET_IMG( telexOn, "", tv, qtr( "Teletext on" ) );
602
603     CONNECT( telexOn, clicked(), THEMIM->getIM(),
604              telexToggleButtons() );
605     CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
606              telexToggle( bool ) );
607     CONNECT( THEMIM->getIM(), toggleTelexButtons(),
608               this, toggleTeletext() );
609     b_telexEnabled = false;
610     telexTransparent->setEnabled( false );
611     telexPage->setEnabled( false );
612
613     BUTTON_SET_IMG( telexTransparent, "", tvtelx, qtr( "Teletext" ) );
614     CONNECT( telexTransparent, clicked( bool ),
615              THEMIM->getIM(), telexSetTransparency() );
616     CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
617               this, toggleTeletextTransparency() );
618     CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
619              this, enableTeletext( bool ) );
620
621     /** Play Buttons **/
622     QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
623     sizePolicy.setHorizontalStretch( 0 );
624     sizePolicy.setVerticalStretch( 0 );
625
626     /* Play */
627     playButton = new QPushButton;
628     playButton->setSizePolicy( sizePolicy );
629     playButton->setMaximumSize( QSize( 36, 36 ) );
630     playButton->setMinimumSize( QSize( 36, 36 ) );
631     playButton->setIconSize( QSize( 30, 30 ) );
632
633
634     /** Prev + Stop + Next Block **/
635     controlButLayout = new QHBoxLayout;
636     controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
637
638     /* Prev */
639     QPushButton *prevButton = new QPushButton;
640     prevButton->setSizePolicy( sizePolicy );
641     setupSmallButton( prevButton );
642
643     controlButLayout->addWidget( prevButton );
644
645     /* Stop */
646     QPushButton *stopButton = new QPushButton;
647     stopButton->setSizePolicy( sizePolicy );
648     setupSmallButton( stopButton );
649
650     controlButLayout->addWidget( stopButton );
651
652     /* next */
653     QPushButton *nextButton = new QPushButton;
654     nextButton->setSizePolicy( sizePolicy );
655     setupSmallButton( nextButton );
656
657     controlButLayout->addWidget( nextButton );
658
659     /* Add this block to the main layout */
660
661     BUTTON_SET_ACT_I( playButton, "", play_b, qtr( I_PLAY_TOOLTIP ), play() );
662     BUTTON_SET_ACT_I( prevButton, "" , previous_b,
663                       qtr( "Previous media in the playlist" ), prev() );
664     BUTTON_SET_ACT_I( nextButton, "", next_b,
665                       qtr( "Next media in the playlist" ), next() );
666     BUTTON_SET_ACT_I( stopButton, "", stop_b, qtr( "Stop playback" ), stop() );
667
668     /*
669      * Other first Line buttons
670      */
671     /** Fullscreen/Visualisation **/
672     fullscreenButton = new QPushButton;
673     BUTTON_SET_ACT_I( fullscreenButton, "", fullscreen,
674             qtr( "Toggle the video in fullscreen" ), fullscreen() );
675     setupSmallButton( fullscreenButton );
676
677     if( !b_fsCreation )
678     {
679         /** Playlist Button **/
680         playlistButton = new QPushButton;
681         setupSmallButton( playlistButton );
682         BUTTON_SET_IMG( playlistButton, "" , playlist, qtr( "Show playlist" ) );
683         CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
684
685         /** extended Settings **/
686         extSettingsButton = new QPushButton;
687         BUTTON_SET_ACT_I( extSettingsButton, "", extended,
688                 qtr( "Show extended settings" ), extSettings() );
689         setupSmallButton( extSettingsButton );
690     }
691
692     /* Volume */
693     hVolLabel = new VolumeClickHandler( p_intf, this );
694
695     volMuteLabel = new QLabel;
696     volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
697     volMuteLabel->installEventFilter( hVolLabel );
698
699     if( b_shiny )
700     {
701         volumeSlider = new SoundSlider( this,
702             config_GetInt( p_intf, "volume-step" ),
703             config_GetInt( p_intf, "qt-volume-complete" ),
704             config_GetPsz( p_intf, "qt-slider-colours" ) );
705     }
706     else
707     {
708         volumeSlider = new QSlider( this );
709         volumeSlider->setOrientation( Qt::Horizontal );
710     }
711     volumeSlider->setMaximumSize( QSize( 200, 40 ) );
712     volumeSlider->setMinimumSize( QSize( 85, 30 ) );
713     volumeSlider->setFocusPolicy( Qt::NoFocus );
714
715     /* Set the volume from the config */
716     volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
717                               VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
718
719     /* Force the update at build time in order to have a muted icon if needed */
720     updateVolume( volumeSlider->value() );
721
722     /* Volume control connection */
723     CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
724     CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
725
726     if( !b_fsCreation )
727     {
728         controlLayout = new QGridLayout( this );
729
730         controlLayout->setSpacing( 0 );
731         controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
732
733         controlLayout->addWidget( slider, 0, 1, 1, 18 );
734         controlLayout->addWidget( slowerButton, 0, 0 );
735         controlLayout->addWidget( fasterButton, 0, 19 );
736
737         controlLayout->addWidget( discFrame, 1, 8, 2, 3, Qt::AlignBottom );
738         controlLayout->addWidget( telexFrame, 1, 8, 2, 5, Qt::AlignBottom );
739
740         controlLayout->addWidget( playButton, 2, 0, 2, 2, Qt::AlignBottom );
741         controlLayout->setColumnMinimumWidth( 2, 10 );
742         controlLayout->setColumnStretch( 2, 0 );
743
744         controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
745         /* Column 6 is unused */
746         controlLayout->setColumnStretch( 6, 0 );
747         controlLayout->setColumnStretch( 7, 0 );
748         controlLayout->setColumnMinimumWidth( 7, 10 );
749
750         controlLayout->addWidget( fullscreenButton, 3, 8, Qt::AlignBottom );
751         controlLayout->addWidget( playlistButton, 3, 9, Qt::AlignBottom );
752         controlLayout->addWidget( extSettingsButton, 3, 10, Qt::AlignBottom );
753         controlLayout->setColumnStretch( 11, 0 ); /* telex alignment */
754
755         controlLayout->setColumnStretch( 12, 0 );
756         controlLayout->setColumnMinimumWidth( 12, 10 );
757
758         controlLayout->addWidget( advControls, 3, 13, 1, 3, Qt::AlignBottom );
759
760         controlLayout->setColumnStretch( 16, 10 );
761         controlLayout->setColumnMinimumWidth( 16, 10 );
762
763         controlLayout->addWidget( volMuteLabel, 3, 17, Qt::AlignBottom );
764         controlLayout->addWidget( volumeSlider, 3, 18, 1 , 2, Qt::AlignBottom );
765     }
766
767     updateInput();
768 }
769
770 ControlsWidget::~ControlsWidget()
771 {}
772
773 void ControlsWidget::toggleTeletext()
774 {
775     bool b_enabled = THEMIM->teletextState();
776     if( b_telexEnabled )
777     {
778         telexTransparent->setEnabled( false );
779         telexPage->setEnabled( false );
780         b_telexEnabled = false;
781     }
782     else if( b_enabled )
783     {
784         telexTransparent->setEnabled( true );
785         telexPage->setEnabled( true );
786         b_telexEnabled = true;
787     }
788 }
789
790 void ControlsWidget::enableTeletext( bool b_enable )
791 {
792     telexFrame->setVisible( b_enable );
793     bool b_on = THEMIM->teletextState();
794
795     telexOn->setChecked( b_on );
796     telexTransparent->setEnabled( b_on );
797     telexPage->setEnabled( b_on );
798     b_telexEnabled = b_on;
799 }
800
801 void ControlsWidget::toggleTeletextTransparency()
802 {
803     if( b_telexTransparent )
804     {
805         telexTransparent->setIcon( QIcon( ":/tvtelx" ) );
806         telexTransparent->setToolTip( qtr( "Teletext" ) );
807         b_telexTransparent = false;
808     }
809     else
810     {
811         telexTransparent->setIcon( QIcon( ":/tvtelx-transparent" ) );
812         telexTransparent->setToolTip( qtr( "Transparent" ) );
813         b_telexTransparent = true;
814     }
815 }
816
817 void ControlsWidget::stop()
818 {
819     THEMIM->stop();
820 }
821
822 void ControlsWidget::play()
823 {
824     if( THEPL->current.i_size == 0 )
825     {
826         /* The playlist is empty, open a file requester */
827         THEDP->openFileDialog();
828         setStatus( 0 );
829         return;
830     }
831     THEMIM->togglePlayPause();
832 }
833
834 void ControlsWidget::prev()
835 {
836     THEMIM->prev();
837 }
838
839 void ControlsWidget::next()
840 {
841     THEMIM->next();
842 }
843
844 void ControlsWidget::setNavigation( int navigation )
845 {
846 #define HELP_PCH N_( "Previous chapter" )
847 #define HELP_NCH N_( "Next chapter" )
848
849     // 1 = chapter, 2 = title, 0 = no
850     if( navigation == 0 )
851     {
852         discFrame->hide();
853     } else if( navigation == 1 ) {
854         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
855         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
856         menuButton->show();
857         discFrame->show();
858     } else {
859         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
860         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
861         menuButton->hide();
862         discFrame->show();
863     }
864 }
865
866 static bool b_my_volume;
867 void ControlsWidget::updateVolume( int i_sliderVolume )
868 {
869     if( !b_my_volume )
870     {
871         int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
872         aout_VolumeSet( p_intf, i_res );
873     }
874     if( i_sliderVolume == 0 )
875     {
876         volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
877         volMuteLabel->setToolTip( qtr( "Unmute" ) );
878         return;
879     }
880
881     if( i_sliderVolume < VOLUME_MAX / 3 )
882         volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
883     else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
884         volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
885     else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
886     volMuteLabel->setToolTip( qtr( "Mute" ) );
887 }
888
889 void ControlsWidget::updateVolume()
890 {
891     /* Audio part */
892     audio_volume_t i_volume;
893     aout_VolumeGet( p_intf, &i_volume );
894     i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
895     int i_gauge = volumeSlider->value();
896     b_my_volume = false;
897     if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
898     {
899         b_my_volume = true;
900         volumeSlider->setValue( i_volume );
901         b_my_volume = false;
902     }
903 }
904
905 void ControlsWidget::updateInput()
906 {
907     /* Activate the interface buttons according to the presence of the input */
908     enableInput( THEMIM->getIM()->hasInput() );
909     enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
910 }
911
912 void ControlsWidget::setStatus( int status )
913 {
914     if( status == PLAYING_S ) /* Playing */
915     {
916         playButton->setIcon( QIcon( ":/pause_b" ) );
917         playButton->setToolTip( qtr( "Pause the playback" ) );
918     }
919     else
920     {
921         playButton->setIcon( QIcon( ":/play_b" ) );
922         playButton->setToolTip( qtr( I_PLAY_TOOLTIP ) );
923     }
924 }
925
926 /**
927  * TODO
928  * This functions toggle the fullscreen mode
929  * If there is no video, it should first activate Visualisations...
930  *  This has also to be fixed in enableVideo()
931  */
932 void ControlsWidget::fullscreen()
933 {
934     vout_thread_t *p_vout =
935         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
936     if( p_vout)
937     {
938         var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
939         vlc_object_release( p_vout );
940     }
941 }
942
943 void ControlsWidget::extSettings()
944 {
945     THEDP->extendedDialog();
946 }
947
948 void ControlsWidget::slower()
949 {
950     THEMIM->getIM()->slower();
951 }
952
953 void ControlsWidget::faster()
954 {
955     THEMIM->getIM()->faster();
956 }
957
958 void ControlsWidget::enableInput( bool enable )
959 {
960     slowerButton->setEnabled( enable );
961     slider->setEnabled( enable );
962     slider->setSliderPosition ( 0 );
963     fasterButton->setEnabled( enable );
964
965     /* Advanced Buttons too */
966     advControls->enableInput( enable );
967 }
968
969 void ControlsWidget::enableVideo( bool enable )
970 {
971     // TODO Later make the fullscreenButton toggle Visualisation and so on.
972     fullscreenButton->setEnabled( enable );
973
974     /* Advanced Buttons too */
975     advControls->enableVideo( enable );
976 }
977
978 void ControlsWidget::toggleAdvanced()
979 {
980     if( advControls && !b_advancedVisible )
981     {
982         advControls->show();
983         b_advancedVisible = true;
984     }
985     else
986     {
987         advControls->hide();
988         b_advancedVisible = false;
989     }
990     emit advancedControlsToggled( b_advancedVisible );
991 }
992
993
994 /**********************************************************************
995  * Fullscrenn control widget
996  **********************************************************************/
997 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
998         MainInterface *_p_mi, bool b_advControls, bool b_shiny )
999         : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
1000           i_mouse_last_x( -1 ), i_mouse_last_y( -1 ), b_mouse_over(false),
1001           b_slow_hide_begin(false), i_slow_hide_timeout(1),
1002           b_fullscreen( false ), i_hide_timeout( 1 ), p_vout(NULL)
1003 {
1004     setWindowFlags( Qt::ToolTip );
1005
1006     setFrameShape( QFrame::StyledPanel );
1007     setFrameStyle( QFrame::Sunken );
1008     setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
1009
1010     QGridLayout *fsLayout = new QGridLayout( this );
1011     fsLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
1012
1013     /* First line */
1014     slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
1015     fsLayout->addWidget( slowerButton, 0, 0 );
1016     fsLayout->addWidget( slider, 0, 1, 1, 8 );
1017     fsLayout->addWidget( fasterButton, 0, 9 );
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->addWidget( volMuteLabel, 1, 7 );
1028     fsLayout->addWidget( volumeSlider, 1, 8, 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 }