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