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