]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
Update qt4 interface to use new "teletex-es". It fixes the unwanted display
[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->addItem( new QSpacerItem( 40,20,
253                               QSizePolicy::Expanding, QSizePolicy::Minimum ) );
254     layout->addWidget( new QLabel( qtr( "Current visualization" ) ) );
255
256     current = new QLabel( qtr( "None" ) );
257     layout->addWidget( current );
258
259     BUTTONACT( prevButton, prev() );
260     BUTTONACT( nextButton, next() );
261
262     setLayout( layout );
263     setMaximumHeight( 35 );
264 }
265
266 VisualSelector::~VisualSelector()
267 {}
268
269 void VisualSelector::prev()
270 {
271     char *psz_new = aout_VisualPrev( p_intf );
272     if( psz_new )
273     {
274         current->setText( qfu( psz_new ) );
275         free( psz_new );
276     }
277 }
278
279 void VisualSelector::next()
280 {
281     char *psz_new = aout_VisualNext( p_intf );
282     if( psz_new )
283     {
284         current->setText( qfu( psz_new ) );
285         free( psz_new );
286     }
287 }
288
289 /**********************************************************************
290  * TEH controls
291  **********************************************************************/
292
293 #define setupSmallButton( aButton ){  \
294     aButton->setMaximumSize( QSize( 26, 26 ) ); \
295     aButton->setMinimumSize( QSize( 26, 26 ) ); \
296     aButton->setIconSize( QSize( 20, 20 ) ); }
297
298 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
299                                            QFrame( NULL ), p_intf( _p_i )
300 {
301     QHBoxLayout *advLayout = new QHBoxLayout( this );
302     advLayout->setMargin( 0 );
303     advLayout->setSpacing( 0 );
304     advLayout->setAlignment( Qt::AlignBottom );
305
306     /* A to B Button */
307     ABButton = new QPushButton( "AB" );
308     setupSmallButton( ABButton );
309     advLayout->addWidget( ABButton );
310     BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), 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_16px.png,
326             qtr( "Record" ), record() );
327
328     /* Snapshot Button */
329     snapshotButton = new QPushButton( "S" );
330     setupSmallButton( snapshotButton );
331     advLayout->addWidget( snapshotButton );
332     BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
333 }
334
335 AdvControlsWidget::~AdvControlsWidget()
336 {}
337
338 void AdvControlsWidget::enableInput( bool enable )
339 {
340     ABButton->setEnabled( enable );
341     recordButton->setEnabled( enable );
342 }
343
344 void AdvControlsWidget::enableVideo( bool enable )
345 {
346     snapshotButton->setEnabled( enable );
347 #if 0
348     frameButton->setEnabled( enable );
349 #endif
350 }
351
352 void AdvControlsWidget::snapshot()
353 {
354     vout_thread_t *p_vout =
355         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
356     if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
357 }
358
359 /* Function called when the button is clicked() */
360 void AdvControlsWidget::fromAtoB()
361 {
362     if( !timeA )
363     {
364         timeA = var_GetTime( THEMIM->getInput(), "time"  );
365         ABButton->setText( "A->..." );
366         return;
367     }
368     if( !timeB )
369     {
370         timeB = var_GetTime( THEMIM->getInput(), "time"  );
371         var_SetTime( THEMIM->getInput(), "time" , timeA );
372         ABButton->setText( "A<=>B" );
373         return;
374     }
375     timeA = 0;
376     timeB = 0;
377     ABButton->setText( "AB" );
378 }
379
380 /* Function called regularly when in an AtoB loop */
381 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
382 {
383     if( timeB )
384     {
385         if( i_time >= (int)(timeB/1000000) )
386             var_SetTime( THEMIM->getInput(), "time" , timeA );
387     }
388 }
389
390 /* FIXME Record function */
391 void AdvControlsWidget::record(){}
392
393 #if 0
394 //FIXME Frame by frame function
395 void AdvControlsWidget::frame(){}
396 #endif
397
398 /*****************************
399  * DA Control Widget !
400  *****************************/
401 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
402                                 MainInterface *_p_mi,
403                                 bool b_advControls,
404                                 bool b_shiny,
405                                 bool b_fsCreation) :
406                                 QFrame( _p_mi ), p_intf( _p_i )
407 {
408     controlLayout = new QGridLayout( );
409
410     controlLayout->setSpacing( 0 );
411     controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
412
413     if( !b_fsCreation )
414         setLayout( controlLayout );
415
416     setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
417
418     /** The main Slider **/
419     slider = new InputSlider( Qt::Horizontal, NULL );
420     controlLayout->addWidget( slider, 0, 1, 1, 16 );
421     /* Update the position when the IM has changed */
422     CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
423              slider, setPosition( float, int, int ) );
424     /* And update the IM, when the position has changed */
425     CONNECT( slider, sliderDragged( float ),
426              THEMIM->getIM(), sliderUpdate( float ) );
427
428     /** Slower and faster Buttons **/
429     slowerButton = new QToolButton;
430     slowerButton->setAutoRaise( true );
431     slowerButton->setMaximumSize( QSize( 26, 20 ) );
432
433     BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
434     controlLayout->addWidget( slowerButton, 0, 0 );
435
436     fasterButton = new QToolButton;
437     fasterButton->setAutoRaise( true );
438     fasterButton->setMaximumSize( QSize( 26, 20 ) );
439
440     BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
441     controlLayout->addWidget( fasterButton, 0, 17 );
442
443     /* advanced Controls handling */
444     b_advancedVisible = b_advControls;
445
446     advControls = new AdvControlsWidget( p_intf );
447     controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
448     if( !b_advancedVisible ) advControls->hide();
449
450     /** Disc and Menus handling */
451     discFrame = new QWidget( this );
452
453     QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
454     discLayout->setSpacing( 0 );
455     discLayout->setMargin( 0 );
456
457     prevSectionButton = new QPushButton( discFrame );
458     setupSmallButton( prevSectionButton );
459     discLayout->addWidget( prevSectionButton );
460
461     menuButton = new QPushButton( discFrame );
462     setupSmallButton( menuButton );
463     discLayout->addWidget( menuButton );
464
465     nextSectionButton = new QPushButton( discFrame );
466     setupSmallButton( nextSectionButton );
467     discLayout->addWidget( nextSectionButton );
468
469     controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
470
471     BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
472     BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
473     BUTTON_SET_IMG( menuButton, "", previous.png, qtr( "Menu" ) );
474
475     discFrame->hide();
476
477     /* Change the navigation button display when the IM navigation changes */
478     CONNECT( THEMIM->getIM(), navigationChanged( int ),
479              this, setNavigation( int ) );
480     /* Changes the IM navigation when triggered on the nav buttons */
481     CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
482              sectionPrev() );
483     CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
484              sectionNext() );
485     CONNECT( menuButton, clicked(), THEMIM->getIM(),
486              sectionMenu() );
487
488     /**
489      * Telextext QFrame
490      * TODO: Merge with upper menu in a StackLayout
491      **/
492     telexFrame = new QWidget( this );
493     QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
494     telexLayout->setSpacing( 0 );
495     telexLayout->setMargin( 0 );
496
497     telexOn = new QPushButton;
498     setupSmallButton( telexOn );
499     telexLayout->addWidget( telexOn );
500
501     telexTransparent = new QPushButton;
502     setupSmallButton( telexTransparent );
503     telexLayout->addWidget( telexTransparent );
504     b_telexTransparent = false;
505
506     telexPage = new QSpinBox;
507     telexPage->setRange( 0, 999 );
508     telexPage->setValue( 100 );
509     telexPage->setAccelerated( true );
510     telexPage->setWrapping( true );
511     telexPage->setAlignment( Qt::AlignRight );
512     telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
513     telexLayout->addWidget( telexPage );
514
515     if( !b_fsCreation )
516         controlLayout->addWidget( telexFrame, 1, 10, 2, 4, Qt::AlignBottom );
517     telexFrame->hide(); /* default hidden */
518
519     CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
520              telexGotoPage( int ) );
521     CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
522               telexPage, setValue( int ) );
523
524     BUTTON_SET_IMG( telexOn, "", tv.png, qtr( "Teletext on" ) );
525
526     CONNECT( telexOn, clicked(), THEMIM->getIM(),
527              telexToggleButtons() );
528     CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
529              telexToggle( bool ) );
530     CONNECT( THEMIM->getIM(), toggleTelexButtons(),
531               this, toggleTeletext() );
532     b_telexEnabled = false;
533     telexTransparent->setEnabled( false );
534     telexPage->setEnabled( false );
535
536     BUTTON_SET_IMG( telexTransparent, "", tvtelx.png, qtr( "Teletext" ) );
537     CONNECT( telexTransparent, clicked( bool ),
538              THEMIM->getIM(), telexSetTransparency() );
539     CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
540               this, toggleTeletextTransparency() );
541     CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
542              this, enableTeletext( bool ) );
543
544     /** Play Buttons **/
545     QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
546     sizePolicy.setHorizontalStretch( 0 );
547     sizePolicy.setVerticalStretch( 0 );
548
549     /* Play */
550     playButton = new QPushButton;
551     playButton->setSizePolicy( sizePolicy );
552     playButton->setMaximumSize( QSize( 36, 36 ) );
553     playButton->setMinimumSize( QSize( 36, 36 ) );
554     playButton->setIconSize( QSize( 30, 30 ) );
555
556     controlLayout->addWidget( playButton, 2, 0, 2, 2 );
557
558     controlLayout->setColumnMinimumWidth( 2, 20 );
559     controlLayout->setColumnStretch( 2, 0 );
560
561     /** Prev + Stop + Next Block **/
562     controlButLayout = new QHBoxLayout;
563     controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
564
565     /* Prev */
566     QPushButton *prevButton = new QPushButton;
567     prevButton->setSizePolicy( sizePolicy );
568     setupSmallButton( prevButton );
569
570     controlButLayout->addWidget( prevButton );
571
572     /* Stop */
573     QPushButton *stopButton = new QPushButton;
574     stopButton->setSizePolicy( sizePolicy );
575     setupSmallButton( stopButton );
576
577     controlButLayout->addWidget( stopButton );
578
579     /* next */
580     QPushButton *nextButton = new QPushButton;
581     nextButton->setSizePolicy( sizePolicy );
582     setupSmallButton( nextButton );
583
584     controlButLayout->addWidget( nextButton );
585
586     /* Add this block to the main layout */
587     if( !b_fsCreation )
588         controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
589
590     BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
591     BUTTON_SET_ACT_I( prevButton, "" , previous.png,
592                       qtr( "Previous" ), prev() );
593     BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
594     BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
595
596     controlLayout->setColumnMinimumWidth( 7, 20 );
597     controlLayout->setColumnStretch( 7, 0 );
598     controlLayout->setColumnStretch( 8, 0 );
599     controlLayout->setColumnStretch( 9, 0 );
600
601     /*
602      * Other first Line buttons
603      */
604     /** Fullscreen/Visualisation **/
605     fullscreenButton = new QPushButton( "F" );
606     BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
607     setupSmallButton( fullscreenButton );
608     controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
609
610     /** Playlist Button **/
611     playlistButton = new QPushButton;
612     setupSmallButton( playlistButton );
613     controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
614     BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
615     CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
616
617     /** extended Settings **/
618     extSettingsButton = new QPushButton;
619     BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended settings" ),
620             extSettings() );
621     setupSmallButton( extSettingsButton );
622     controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
623
624     controlLayout->setColumnStretch( 13, 0 );
625     controlLayout->setColumnMinimumWidth( 13, 24 );
626     controlLayout->setColumnStretch( 14, 5 );
627
628     /* Volume */
629     hVolLabel = new VolumeClickHandler( p_intf, this );
630
631     volMuteLabel = new QLabel;
632     volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
633     volMuteLabel->setToolTip( qtr( "Mute" ) );
634     volMuteLabel->installEventFilter( hVolLabel );
635     controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
636
637     if( b_shiny )
638     {
639         volumeSlider = new SoundSlider( this,
640             config_GetInt( p_intf, "volume-step" ),
641             config_GetInt( p_intf, "qt-volume-complete" ),
642             config_GetPsz( p_intf, "qt-slider-colours" ) );
643     }
644     else
645     {
646         volumeSlider = new QSlider( this );
647         volumeSlider->setOrientation( Qt::Horizontal );
648     }
649     volumeSlider->setMaximumSize( QSize( 200, 40 ) );
650     volumeSlider->setMinimumSize( QSize( 106, 30 ) );
651     volumeSlider->setFocusPolicy( Qt::NoFocus );
652     controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
653
654     /* Set the volume from the config */
655     volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
656                               VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
657
658     /* Force the update at build time in order to have a muted icon if needed */
659     updateVolume( volumeSlider->value() );
660
661     /* Volume control connection */
662     CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
663     CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
664
665     updateInput();
666 }
667
668 ControlsWidget::~ControlsWidget()
669 {}
670
671 void ControlsWidget::toggleTeletext()
672 {
673     bool b_enabled = THEMIM->teletextState();
674     if( b_telexEnabled )
675     {
676         telexTransparent->setEnabled( false );
677         telexPage->setEnabled( false );
678         b_telexEnabled = false;
679     }
680     else if( b_enabled )
681     {
682         telexTransparent->setEnabled( true );
683         telexPage->setEnabled( true );
684         b_telexEnabled = true;
685     }
686 }
687 void ControlsWidget::enableTeletext( bool b_enable )
688 {
689     telexFrame->setVisible( b_enable );
690     bool b_on = THEMIM->teletextState();
691
692     telexOn->setChecked( b_on );
693     telexTransparent->setEnabled( b_on );
694     telexPage->setEnabled( b_on );
695     b_telexEnabled = b_on;
696 }
697
698 void ControlsWidget::toggleTeletextTransparency()
699 {
700     if( b_telexTransparent )
701     {
702         telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx.png" ) );
703         telexTransparent->setToolTip( qtr( "Teletext" ) );
704         b_telexTransparent = false;
705     }
706     else
707     {
708         telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx-transparent.png" ) );
709         telexTransparent->setToolTip( qtr( "Transparent" ) );
710         b_telexTransparent = true;
711     }
712 }
713
714 void ControlsWidget::stop()
715 {
716     THEMIM->stop();
717 }
718
719 void ControlsWidget::play()
720 {
721     if( THEPL->current.i_size == 0 )
722     {
723         /* The playlist is empty, open a file requester */
724         THEDP->openFileDialog();
725         setStatus( 0 );
726         return;
727     }
728     THEMIM->togglePlayPause();
729 }
730
731 void ControlsWidget::prev()
732 {
733     THEMIM->prev();
734 }
735
736 void ControlsWidget::next()
737 {
738     THEMIM->next();
739 }
740
741 void ControlsWidget::setNavigation( int navigation )
742 {
743 #define HELP_PCH N_( "Previous chapter" )
744 #define HELP_NCH N_( "Next chapter" )
745
746     // 1 = chapter, 2 = title, 0 = no
747     if( navigation == 0 )
748     {
749         discFrame->hide();
750     } else if( navigation == 1 ) {
751         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
752         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
753         menuButton->show();
754         discFrame->show();
755     } else {
756         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
757         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
758         menuButton->hide();
759         discFrame->show();
760     }
761 }
762
763 static bool b_my_volume;
764 void ControlsWidget::updateVolume( int i_sliderVolume )
765 {
766     if( !b_my_volume )
767     {
768         int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
769         aout_VolumeSet( p_intf, i_res );
770     }
771     if( i_sliderVolume == 0 )
772         volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
773     else if( i_sliderVolume < VOLUME_MAX / 3 )
774         volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
775     else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
776         volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
777     else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
778 }
779
780 void ControlsWidget::updateVolume()
781 {
782     /* Audio part */
783     audio_volume_t i_volume;
784     aout_VolumeGet( p_intf, &i_volume );
785     i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
786     int i_gauge = volumeSlider->value();
787     b_my_volume = false;
788     if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
789     {
790         b_my_volume = true;
791         volumeSlider->setValue( i_volume );
792         b_my_volume = false;
793     }
794 }
795
796 void ControlsWidget::updateInput()
797 {
798     /* Activate the interface buttons according to the presence of the input */
799     enableInput( THEMIM->getIM()->hasInput() );
800     enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
801 }
802
803 void ControlsWidget::setStatus( int status )
804 {
805     if( status == PLAYING_S ) /* Playing */
806     {
807         playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
808         playButton->setToolTip( qtr( "Pause" ) );
809     }
810     else
811     {
812         playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
813         playButton->setToolTip( qtr( "Play" ) );
814     }
815 }
816
817 /**
818  * TODO
819  * This functions toggle the fullscreen mode
820  * If there is no video, it should first activate Visualisations...
821  *  This has also to be fixed in enableVideo()
822  */
823 void ControlsWidget::fullscreen()
824 {
825     vout_thread_t *p_vout =
826         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
827     if( p_vout)
828     {
829         var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
830         vlc_object_release( p_vout );
831     }
832 }
833
834 void ControlsWidget::extSettings()
835 {
836     THEDP->extendedDialog();
837 }
838
839 void ControlsWidget::slower()
840 {
841     THEMIM->getIM()->slower();
842 }
843
844 void ControlsWidget::faster()
845 {
846     THEMIM->getIM()->faster();
847 }
848
849 void ControlsWidget::enableInput( bool enable )
850 {
851     slowerButton->setEnabled( enable );
852     slider->setEnabled( enable );
853     fasterButton->setEnabled( enable );
854
855     /* Advanced Buttons too */
856     advControls->enableInput( enable );
857 }
858
859 void ControlsWidget::enableVideo( bool enable )
860 {
861     // TODO Later make the fullscreenButton toggle Visualisation and so on.
862     fullscreenButton->setEnabled( enable );
863
864     /* Advanced Buttons too */
865     advControls->enableVideo( enable );
866 }
867
868 void ControlsWidget::toggleAdvanced()
869 {
870     if( !VISIBLE( advControls ) )
871     {
872         advControls->show();
873         b_advancedVisible = true;
874     }
875     else
876     {
877         advControls->hide();
878         b_advancedVisible = false;
879     }
880     emit advancedControlsToggled( b_advancedVisible );
881 }
882
883
884 /**********************************************************************
885  * Fullscrenn control widget
886  **********************************************************************/
887 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
888         MainInterface *_p_mi, bool b_advControls, bool b_shiny )
889         : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
890         i_lastPosX( -1 ), i_lastPosY( -1 ), i_hideTimeout( 1 ),
891         b_mouseIsOver( false ), b_isFullscreen( false )
892 {
893     setWindowFlags( Qt::ToolTip );
894
895     setFrameShape( QFrame::StyledPanel );
896     setFrameStyle( QFrame::Sunken );
897     setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
898
899     QGridLayout *fsLayout = new QGridLayout( this );
900     controlLayout->setSpacing( 0 );
901     controlLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
902
903     fsLayout->addWidget( slowerButton, 0, 0 );
904     slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
905     fsLayout->addWidget( slider, 0, 1, 1, 6 );
906     fsLayout->addWidget( fasterButton, 0, 7 );
907
908     fsLayout->addWidget( volMuteLabel, 1, 0);
909     fsLayout->addWidget( volumeSlider, 1, 1 );
910
911     fsLayout->addLayout( controlButLayout, 1, 2 );
912
913     fsLayout->addWidget( playButton, 1, 3 );
914
915     fsLayout->addWidget( discFrame, 1, 4 );
916
917     fsLayout->addWidget( telexFrame, 1, 5 );
918
919     fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
920
921     fsLayout->addWidget( fullscreenButton, 1, 7 );
922
923     /* hiding timer */
924     p_hideTimer = new QTimer( this );
925     CONNECT( p_hideTimer, timeout(), this, hideFSControllerWidget() );
926     p_hideTimer->setSingleShot( true );
927
928     /* slow hiding timer */
929 #if HAVE_TRANSPARENCY
930     p_slowHideTimer = new QTimer( this );
931     CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
932 #endif
933
934     adjustSize ();  /* need to get real width and height for moving */
935
936     /* center down */
937     QDesktopWidget * p_desktop = QApplication::desktop();
938
939     move( p_desktop->width() / 2 - width() / 2,
940           p_desktop->height() - height() );
941
942     #ifdef WIN32TRICK
943     setWindowOpacity( 0.0 );
944     fscHidden = true;
945     show();
946     #endif
947 }
948
949 FullscreenControllerWidget::~FullscreenControllerWidget()
950 {
951 }
952
953 /**
954  * Hide fullscreen controller
955  * FIXME: under windows it have to be done by moving out of screen
956  *        because hide() doesnt work
957  */
958 void FullscreenControllerWidget::hideFSControllerWidget()
959 {
960     #ifdef WIN32TRICK
961     fscHidden = true;
962     setWindowOpacity( 0.0 );    // simulate hidding
963     #else
964     hide();
965     #endif
966 }
967
968 /**
969  * Hidding fullscreen controller slowly
970  * Linux: need composite manager
971  * Windows: it is blinking, so it can be enabled by define TRASPARENCY
972  */
973 void FullscreenControllerWidget::slowHideFSC()
974 {
975 #if HAVE_TRANSPARENCY
976     static bool first_call = true;
977
978     if ( first_call )
979     {
980         first_call = false;
981
982         p_slowHideTimer->stop();
983         /* the last part of time divided to 100 pieces */
984         p_slowHideTimer->start(
985             (int) ( i_hideTimeout / 2 / ( windowOpacity() * 100 ) ) );
986     }
987     else
988     {
989 #ifdef WIN32TRICK
990          if ( windowOpacity() > 0.0 && !fscHidden )
991 #else
992          if ( windowOpacity() > 0.0 )
993 #endif
994          {
995              /* we should use 0.01 because of 100 pieces ^^^
996                 but than it cannt be done in time */
997              setWindowOpacity( windowOpacity() - 0.02 );
998          }
999
1000          if ( windowOpacity() == 0.0 )
1001          {
1002              first_call = true;
1003              p_slowHideTimer->stop();
1004          }
1005     }
1006 #endif
1007 }
1008
1009 /**
1010  * Get state of visibility of FS controller on screen
1011  * On windows control if it is on hidden position
1012  */
1013 bool FullscreenControllerWidget::isFSCHidden()
1014 {
1015     #ifdef WIN32TRICK
1016     return fscHidden;
1017     #endif
1018
1019     return isHidden();
1020 }
1021
1022 /**
1023  * event handling
1024  * events: show, hide, start timer for hidding
1025  */
1026 void FullscreenControllerWidget::customEvent( QEvent *event )
1027 {
1028     int type = event->type();
1029
1030     if ( type == FullscreenControlShow_Type && b_isFullscreen )
1031     {
1032         #ifdef WIN32TRICK
1033         // after quiting and going to fs, we need to call show()
1034         if ( isHidden() )
1035             show();
1036
1037         if ( fscHidden )
1038         {
1039             fscHidden = false;
1040             setWindowOpacity( 1.0 );
1041         }
1042         #else
1043         show();
1044         #endif
1045
1046 #if HAVE_TRANSPARENCY
1047         setWindowOpacity( DEFAULT_OPACITY );
1048 #endif
1049     }
1050     else if ( type == FullscreenControlHide_Type )
1051     {
1052         hideFSControllerWidget();
1053     }
1054     else if ( type == FullscreenControlPlanHide_Type && !b_mouseIsOver )
1055     {
1056         p_hideTimer->start( i_hideTimeout );
1057 #if HAVE_TRANSPARENCY
1058         p_slowHideTimer->start( i_hideTimeout / 2 );
1059 #endif
1060     }
1061 }
1062
1063 /**
1064  * On mouse move
1065  * moving with FSC
1066  */
1067 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1068 {
1069     if ( event->buttons() == Qt::LeftButton )
1070     {
1071         int i_moveX = event->globalX() - i_lastPosX;
1072         int i_moveY = event->globalY() - i_lastPosY;
1073
1074         move( x() + i_moveX, y() + i_moveY );
1075
1076         i_lastPosX = event->globalX();
1077         i_lastPosY = event->globalY();
1078     }
1079 }
1080
1081 /**
1082  * On mouse press
1083  * store position of cursor
1084  */
1085 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1086 {
1087     i_lastPosX = event->globalX();
1088     i_lastPosY = event->globalY();
1089 }
1090
1091 /**
1092  * On mouse go above FSC
1093  */
1094 void FullscreenControllerWidget::enterEvent( QEvent *event )
1095 {
1096     p_hideTimer->stop();
1097 #if HAVE_TRANSPARENCY
1098     p_slowHideTimer->stop();
1099 #endif
1100     b_mouseIsOver = true;
1101 }
1102
1103 /**
1104  * On mouse go out from FSC
1105  */
1106 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1107 {
1108     p_hideTimer->start( i_hideTimeout );
1109 #if HAVE_TRANSPARENCY
1110     p_slowHideTimer->start( i_hideTimeout / 2 );
1111 #endif
1112     b_mouseIsOver = false;
1113 }
1114
1115 /**
1116  * When you get pressed key, send it to video output
1117  * FIXME: clearing focus by clearFocus() to not getting
1118  * key press events didnt work
1119  */
1120 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1121 {
1122     int i_vlck = qtEventToVLCKey( event );
1123     if( i_vlck > 0 )
1124     {
1125         var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1126         event->accept();
1127     }
1128     else
1129         event->ignore();
1130 }
1131
1132 /**
1133  * It is called when video start
1134  */
1135 void FullscreenControllerWidget::regFullscreenCallback( vout_thread_t *p_vout )
1136 {
1137     if ( p_vout )
1138     {
1139         var_AddCallback( p_vout, "fullscreen", regMouseMoveCallback, this );
1140     }
1141 }
1142
1143 /**
1144  * It is called after turn off video, because p_vout is NULL now
1145  * we cannt delete callback, just hide if FScontroller is visible
1146  */
1147 void FullscreenControllerWidget::unregFullscreenCallback()
1148 {
1149     if ( isVisible() )
1150         hide();
1151 }
1152
1153 /**
1154  * Register and unregister callback for mouse moving
1155  */
1156 static int regMouseMoveCallback( 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
1162     static bool b_registered = false;
1163     FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1164
1165     if ( var_GetBool( p_vout, "fullscreen" ) && !b_registered )
1166     {
1167         p_fs->setHideTimeout( var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1168         p_fs->setIsFullscreen( true );
1169         var_AddCallback( p_vout, "mouse-moved",
1170                         showFullscreenControllCallback, (void *) p_fs );
1171         b_registered = true;
1172     }
1173
1174     if ( !var_GetBool( p_vout, "fullscreen" ) && b_registered )
1175     {
1176         p_fs->setIsFullscreen( false );
1177         p_fs->hide();
1178         var_DelCallback( p_vout, "mouse-moved",
1179                         showFullscreenControllCallback, (void *) p_fs );
1180         b_registered = false;
1181     }
1182
1183     return VLC_SUCCESS;
1184 }
1185
1186 /**
1187  * Show fullscreen controller after mouse move
1188  * after show immediately plan hide event
1189  */
1190 static int showFullscreenControllCallback( vlc_object_t *vlc_object, const char *variable,
1191                                            vlc_value_t old_val, vlc_value_t new_val,
1192                                            void *data )
1193 {
1194     FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1195
1196     if ( p_fs->isFSCHidden() || p_fs->windowOpacity() < DEFAULT_OPACITY )
1197     {
1198         IMEvent *event = new IMEvent( FullscreenControlShow_Type, 0 );
1199         QApplication::postEvent( p_fs, static_cast<QEvent *>(event) );
1200     }
1201
1202     IMEvent *e = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1203     QApplication::postEvent( p_fs, static_cast<QEvent *>(e) );
1204
1205     return VLC_SUCCESS;
1206 }
1207
1208 /**********************************************************************
1209  * Speed control widget
1210  **********************************************************************/
1211 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1212                              QFrame( NULL ), p_intf( _p_i )
1213 {
1214     QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1215     sizePolicy.setHorizontalStretch( 0 );
1216     sizePolicy.setVerticalStretch( 0 );
1217
1218     speedSlider = new QSlider;
1219     speedSlider->setSizePolicy( sizePolicy );
1220     speedSlider->setMaximumSize( QSize( 80, 200 ) );
1221     speedSlider->setOrientation( Qt::Vertical );
1222     speedSlider->setTickPosition( QSlider::TicksRight );
1223
1224     speedSlider->setRange( -24, 24 );
1225     speedSlider->setSingleStep( 1 );
1226     speedSlider->setPageStep( 1 );
1227     speedSlider->setTickInterval( 12 );
1228
1229     CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1230
1231     QToolButton *normalSpeedButton = new QToolButton( this );
1232     normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1233     normalSpeedButton->setAutoRaise( true );
1234     normalSpeedButton->setText( "1x" );
1235     normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1236
1237     CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1238
1239     QVBoxLayout *speedControlLayout = new QVBoxLayout;
1240     speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
1241     speedControlLayout->setSpacing( 4 );
1242     speedControlLayout->addWidget( speedSlider );
1243     speedControlLayout->addWidget( normalSpeedButton );
1244     setLayout( speedControlLayout );
1245 }
1246
1247 SpeedControlWidget::~SpeedControlWidget()
1248 {}
1249
1250 void SpeedControlWidget::setEnable( bool b_enable )
1251 {
1252     speedSlider->setEnabled( b_enable );
1253 }
1254
1255 void SpeedControlWidget::updateControls( int rate )
1256 {
1257     if( speedSlider->isSliderDown() )
1258     {
1259         //We don't want to change anything if the user is using the slider
1260         return;
1261     }
1262
1263     double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
1264     int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
1265
1266     if( sliderValue < speedSlider->minimum() )
1267     {
1268         sliderValue = speedSlider->minimum();
1269     }
1270     else if( sliderValue > speedSlider->maximum() )
1271     {
1272         sliderValue = speedSlider->maximum();
1273     }
1274
1275     //Block signals to avoid feedback loop
1276     speedSlider->blockSignals( true );
1277     speedSlider->setValue( sliderValue );
1278     speedSlider->blockSignals( false );
1279 }
1280
1281 void SpeedControlWidget::updateRate( int sliderValue )
1282 {
1283     double speed = pow( 2, (double)sliderValue / 12 );
1284     int rate = INPUT_RATE_DEFAULT / speed;
1285
1286     THEMIM->getIM()->setRate(rate);
1287 }
1288
1289 void SpeedControlWidget::resetRate()
1290 {
1291     THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
1292 }