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