]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
Break compilation on Qt4.2
[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 #ifdef Q_WS_X11
51 # include <X11/Xlib.h>
52 # include <qx11info_x11.h>
53 #endif
54
55 /**********************************************************************
56  * Video Widget. A simple frame on which video is drawn
57  * This class handles resize issues
58  **********************************************************************/
59
60 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
61 {
62     /* Init */
63     vlc_mutex_init( &lock );
64     p_vout = NULL;
65     hide(); setMinimumSize( 16, 16 );
66     videoSize.rwidth() = -1;
67     videoSize.rheight() = -1;
68     setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
69
70     /* Black background is more coherent for a Video Widget IMVHO */
71     QPalette plt =  palette();
72     plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
73     plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
74     setPalette( plt );
75     setAttribute( Qt::WA_PaintOnScreen, true );
76
77     /* The core can ask through a callback to show the video. */
78 #if HAS_QT43
79     connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
80              this, SLOT(SetSizing(unsigned int, unsigned int )),
81              Qt::BlockingQueuedConnection );
82 #else
83 #error This is broken. Fix it with a QEventLoop with a processEvents () 
84     connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
85              this, SLOT(SetSizing(unsigned int, unsigned int )) );
86 #endif
87
88
89 }
90
91 void VideoWidget::paintEvent(QPaintEvent *ev)
92 {
93     QFrame::paintEvent(ev);
94 #ifdef Q_WS_X11
95     XFlush( QX11Info::display() );
96 #endif
97 }
98
99 VideoWidget::~VideoWidget()
100 {
101     vlc_mutex_lock( &lock );
102     if( p_vout )
103     {
104         if( !p_intf->psz_switch_intf )
105         {
106             if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
107                 vout_Control( p_vout, VOUT_REPARENT );
108         }
109         else
110         {
111             if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
112                 vout_Control( p_vout, VOUT_CLOSE );
113         }
114     }
115     vlc_mutex_unlock( &lock );
116     vlc_mutex_destroy( &lock );
117 }
118
119 /**
120  * Request the video to avoid the conflicts
121  **/
122 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
123                            unsigned int *pi_width, unsigned int *pi_height )
124 {
125     msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
126     emit askVideoWidgetToShow( *pi_width, *pi_height );
127     if( p_vout )
128     {
129         msg_Dbg( p_intf, "embedded video already in use" );
130         return NULL;
131     }
132     p_vout = p_nvout;
133     msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );
134     return ( void* )winId();
135 }
136
137 /* Set the Widget to the correct Size */
138 /* Function has to be called by the parent
139    Parent has to care about resizing himself*/
140 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
141 {
142     msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
143     videoSize.rwidth() = w;
144     videoSize.rheight() = h;
145     if( isHidden() ) show();
146     updateGeometry(); // Needed for deinterlace
147 }
148
149 void VideoWidget::release( void *p_win )
150 {
151     msg_Dbg( p_intf, "Video is non needed anymore" );
152     p_vout = NULL;
153     videoSize.rwidth() = 0;
154     videoSize.rheight() = 0;
155     hide();
156     updateGeometry(); // Needed for deinterlace
157 }
158
159 QSize VideoWidget::sizeHint() const
160 {
161     return videoSize;
162 }
163
164 /**********************************************************************
165  * Background Widget. Show a simple image background. Currently,
166  * it's album art if present or cone.
167  **********************************************************************/
168 #define ICON_SIZE 128
169 #define MAX_BG_SIZE 400
170 #define MIN_BG_SIZE 64
171
172 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
173                  :QWidget( NULL ), p_intf( _p_i )
174 {
175     /* We should use that one to take the more size it can */
176 //    setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
177
178     /* A dark background */
179     setAutoFillBackground( true );
180     plt =  palette();
181     plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
182     plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
183     setPalette( plt );
184
185     /* A cone in the middle */
186     label = new QLabel;
187     label->setMargin( 5 );
188     label->setMaximumHeight( MAX_BG_SIZE );
189     label->setMaximumWidth( MAX_BG_SIZE );
190     label->setMinimumHeight( MIN_BG_SIZE );
191     label->setMinimumWidth( MIN_BG_SIZE );
192     if( QDate::currentDate().dayOfYear() >= 354 )
193         label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
194     else
195         label->setPixmap( QPixmap( ":/vlc128.png" ) );
196
197     QGridLayout *backgroundLayout = new QGridLayout( this );
198     backgroundLayout->addWidget( label, 0, 1 );
199     backgroundLayout->setColumnStretch( 0, 1 );
200     backgroundLayout->setColumnStretch( 2, 1 );
201
202     CONNECT( THEMIM->getIM(), artChanged( QString ), this, updateArt( QString ) );
203 }
204
205 BackgroundWidget::~BackgroundWidget()
206 {
207 }
208
209 void BackgroundWidget::resizeEvent( QResizeEvent * event )
210 {
211     if( event->size().height() <= MIN_BG_SIZE )
212         label->hide();
213     else
214         label->show();
215 }
216
217 void BackgroundWidget::updateArt( QString url )
218 {
219     if( url.isEmpty() )
220     {
221         if( QDate::currentDate().dayOfYear() >= 354 )
222             label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
223         else
224             label->setPixmap( QPixmap( ":/vlc128.png" ) );
225         return;
226     }
227     else
228     {
229         label->setPixmap( QPixmap( url ) );
230     }
231 }
232
233 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
234 {
235     QVLCMenu::PopupMenu( p_intf, true );
236 }
237
238 /**********************************************************************
239  * Visualization selector panel
240  **********************************************************************/
241 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
242                                 QFrame( NULL ), p_intf( _p_i )
243 {
244     QHBoxLayout *layout = new QHBoxLayout( this );
245     layout->setMargin( 0 );
246     QPushButton *prevButton = new QPushButton( "Prev" );
247     QPushButton *nextButton = new QPushButton( "Next" );
248     layout->addWidget( prevButton );
249     layout->addWidget( nextButton );
250
251     layout->addItem( new QSpacerItem( 40,20,
252                               QSizePolicy::Expanding, QSizePolicy::Minimum ) );
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
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              telexFrame, setVisible( 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
688 void ControlsWidget::toggleTeletextTransparency()
689 {
690     if( b_telexTransparent )
691     {
692         telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx.png" ) );
693         telexTransparent->setToolTip( qtr( "Teletext" ) );
694         b_telexTransparent = false;
695     }
696     else
697     {
698         telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx-transparent.png" ) );
699         telexTransparent->setToolTip( qtr( "Transparent" ) );
700         b_telexTransparent = true;
701     }
702 }
703
704 void ControlsWidget::stop()
705 {
706     THEMIM->stop();
707 }
708
709 void ControlsWidget::play()
710 {
711     if( THEPL->current.i_size == 0 )
712     {
713         /* The playlist is empty, open a file requester */
714         THEDP->openFileDialog();
715         setStatus( 0 );
716         return;
717     }
718     THEMIM->togglePlayPause();
719 }
720
721 void ControlsWidget::prev()
722 {
723     THEMIM->prev();
724 }
725
726 void ControlsWidget::next()
727 {
728     THEMIM->next();
729 }
730
731 void ControlsWidget::setNavigation( int navigation )
732 {
733 #define HELP_PCH N_( "Previous chapter" )
734 #define HELP_NCH N_( "Next chapter" )
735
736     // 1 = chapter, 2 = title, 0 = no
737     if( navigation == 0 )
738     {
739         discFrame->hide();
740     } else if( navigation == 1 ) {
741         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
742         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
743         menuButton->show();
744         discFrame->show();
745     } else {
746         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
747         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
748         menuButton->hide();
749         discFrame->show();
750     }
751 }
752
753 static bool b_my_volume;
754 void ControlsWidget::updateVolume( int i_sliderVolume )
755 {
756     if( !b_my_volume )
757     {
758         int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
759         aout_VolumeSet( p_intf, i_res );
760     }
761     if( i_sliderVolume == 0 )
762         volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
763     else if( i_sliderVolume < VOLUME_MAX / 3 )
764         volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
765     else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
766         volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
767     else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
768 }
769
770 void ControlsWidget::updateVolume()
771 {
772     /* Audio part */
773     audio_volume_t i_volume;
774     aout_VolumeGet( p_intf, &i_volume );
775     i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
776     int i_gauge = volumeSlider->value();
777     b_my_volume = false;
778     if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
779     {
780         b_my_volume = true;
781         volumeSlider->setValue( i_volume );
782         b_my_volume = false;
783     }
784 }
785
786 void ControlsWidget::updateInput()
787 {
788     /* Activate the interface buttons according to the presence of the input */
789     enableInput( THEMIM->getIM()->hasInput() );
790     enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
791 }
792
793 void ControlsWidget::setStatus( int status )
794 {
795     if( status == PLAYING_S ) /* Playing */
796     {
797         playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
798         playButton->setToolTip( qtr( "Pause" ) );
799     }
800     else
801     {
802         playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
803         playButton->setToolTip( qtr( "Play" ) );
804     }
805 }
806
807 /**
808  * TODO
809  * This functions toggle the fullscreen mode
810  * If there is no video, it should first activate Visualisations...
811  *  This has also to be fixed in enableVideo()
812  */
813 void ControlsWidget::fullscreen()
814 {
815     vout_thread_t *p_vout =
816         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
817     if( p_vout)
818     {
819         var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
820         vlc_object_release( p_vout );
821     }
822 }
823
824 void ControlsWidget::extSettings()
825 {
826     THEDP->extendedDialog();
827 }
828
829 void ControlsWidget::slower()
830 {
831     THEMIM->getIM()->slower();
832 }
833
834 void ControlsWidget::faster()
835 {
836     THEMIM->getIM()->faster();
837 }
838
839 void ControlsWidget::enableInput( bool enable )
840 {
841     slowerButton->setEnabled( enable );
842     slider->setEnabled( enable );
843     fasterButton->setEnabled( enable );
844
845     /* Advanced Buttons too */
846     advControls->enableInput( enable );
847 }
848
849 void ControlsWidget::enableVideo( bool enable )
850 {
851     // TODO Later make the fullscreenButton toggle Visualisation and so on.
852     fullscreenButton->setEnabled( enable );
853
854     /* Advanced Buttons too */
855     advControls->enableVideo( enable );
856 }
857
858 void ControlsWidget::toggleAdvanced()
859 {
860     if( !VISIBLE( advControls ) )
861     {
862         advControls->show();
863         b_advancedVisible = true;
864     }
865     else
866     {
867         advControls->hide();
868         b_advancedVisible = false;
869     }
870     emit advancedControlsToggled( b_advancedVisible );
871 }
872
873
874 /**********************************************************************
875  * Fullscrenn control widget
876  **********************************************************************/
877 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
878         MainInterface *_p_mi, bool b_advControls, bool b_shiny )
879         : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
880         i_lastPosX( -1 ), i_lastPosY( -1 ), i_hideTimeout( 1 ),
881         b_mouseIsOver( false )
882 {
883     setWindowFlags( Qt::ToolTip );
884
885     setFrameShape( QFrame::StyledPanel );
886     setFrameStyle( QFrame::Sunken );
887     setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
888
889     QGridLayout *fsLayout = new QGridLayout( this );
890     controlLayout->setSpacing( 0 );
891     controlLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
892
893     fsLayout->addWidget( slowerButton, 0, 0 );
894     slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
895     fsLayout->addWidget( slider, 0, 1, 1, 6 );
896     fsLayout->addWidget( fasterButton, 0, 7 );
897
898     fsLayout->addWidget( volMuteLabel, 1, 0);
899     fsLayout->addWidget( volumeSlider, 1, 1 );
900
901     fsLayout->addLayout( controlButLayout, 1, 2 );
902
903     fsLayout->addWidget( playButton, 1, 3 );
904
905     fsLayout->addWidget( discFrame, 1, 4 );
906
907     fsLayout->addWidget( telexFrame, 1, 5 );
908
909     fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
910
911     fsLayout->addWidget( fullscreenButton, 1, 7 );
912
913     /* hiding timer */
914     p_hideTimer = new QTimer( this );
915     CONNECT( p_hideTimer, timeout(), this, hideFSControllerWidget() );
916     p_hideTimer->setSingleShot( true );
917
918     /* slow hiding timer */
919 #if HAVE_TRANSPARENCY
920     p_slowHideTimer = new QTimer( this );
921     CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
922 #endif
923
924     adjustSize ();  /* need to get real width and height for moving */
925
926     /* center down */
927     QDesktopWidget * p_desktop = QApplication::desktop();
928
929     move( p_desktop->width() / 2 - width() / 2,
930           p_desktop->height() - height() );
931
932     #ifdef WIN32TRICK
933     setWindowOpacity( 0.0 );
934     fscHidden = true;
935     show();
936     #endif
937 }
938
939 FullscreenControllerWidget::~FullscreenControllerWidget()
940 {
941 }
942
943 /**
944  * Hide fullscreen controller
945  * FIXME: under windows it have to be done by moving out of screen
946  *        because hide() doesnt work
947  */
948 void FullscreenControllerWidget::hideFSControllerWidget()
949 {
950     #ifdef WIN32TRICK
951     fscHidden = true;
952     setWindowOpacity( 0.0 );    // simulate hidding
953     #else
954     hide();
955     #endif
956 }
957
958 /**
959  * Hidding fullscreen controller slowly
960  * Linux: need composite manager
961  * Windows: it is blinking, so it can be enabled by define TRASPARENCY
962  */
963 void FullscreenControllerWidget::slowHideFSC()
964 {
965 #if HAVE_TRANSPARENCY
966     static bool first_call = true;
967
968     if ( first_call )
969     {
970         first_call = false;
971
972         p_slowHideTimer->stop();
973         /* the last part of time divided to 100 pieces */
974         p_slowHideTimer->start(
975             (int) ( i_hideTimeout / 2 / ( windowOpacity() * 100 ) ) );
976     }
977     else
978     {
979          if ( windowOpacity() > 0.0 )
980          {
981              /* we should use 0.01 because of 100 pieces ^^^
982                 but than it cannt be done in time */
983              setWindowOpacity( windowOpacity() - 0.02 );
984          }
985
986          if ( windowOpacity() == 0.0 )
987          {
988              first_call = true;
989              p_slowHideTimer->stop();
990          }
991     }
992 #endif
993 }
994
995 /**
996  * Get state of visibility of FS controller on screen
997  * On windows control if it is on hidden position
998  */
999 bool FullscreenControllerWidget::isFSCHidden()
1000 {
1001     #ifdef WIN32TRICK
1002     return fscHidden;
1003     #endif
1004
1005     return isHidden();
1006 }
1007
1008 /**
1009  * event handling
1010  * events: show, hide, start timer for hidding
1011  */
1012 void FullscreenControllerWidget::customEvent( QEvent *event )
1013 {
1014     int type = event->type();
1015
1016     if ( type == FullscreenControlShow_Type )
1017     {
1018         #ifdef WIN32TRICK
1019         // after quiting and going to fs, we need to call show()
1020         if ( isHidden() )
1021             show();
1022
1023         if ( fscHidden )
1024         {
1025             fscHidden = false;
1026             setWindowOpacity( 1.0 );
1027         }
1028         #else
1029         show();
1030         #endif
1031
1032 #if HAVE_TRANSPARENCY
1033         setWindowOpacity( DEFAULT_OPACITY );
1034 #endif
1035     }
1036     else if ( type == FullscreenControlHide_Type )
1037     {
1038         hideFSControllerWidget();
1039     }
1040     else if ( type == FullscreenControlPlanHide_Type && !b_mouseIsOver )
1041     {
1042         p_hideTimer->start( i_hideTimeout );
1043 #if HAVE_TRANSPARENCY
1044         p_slowHideTimer->start( i_hideTimeout / 2 );
1045 #endif
1046     }
1047 }
1048
1049 /**
1050  * On mouse move
1051  * moving with FSC
1052  */
1053 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1054 {
1055     if ( event->buttons() == Qt::LeftButton )
1056     {
1057         int i_moveX = event->globalX() - i_lastPosX;
1058         int i_moveY = event->globalY() - i_lastPosY;
1059
1060         move( x() + i_moveX, y() + i_moveY );
1061
1062         i_lastPosX = event->globalX();
1063         i_lastPosY = event->globalY();
1064     }
1065 }
1066
1067 /**
1068  * On mouse press
1069  * store position of cursor
1070  */
1071 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1072 {
1073     i_lastPosX = event->globalX();
1074     i_lastPosY = event->globalY();
1075 }
1076
1077 /**
1078  * On mouse go above FSC
1079  */
1080 void FullscreenControllerWidget::enterEvent( QEvent *event )
1081 {
1082     p_hideTimer->stop();
1083 #if HAVE_TRANSPARENCY
1084     p_slowHideTimer->stop();
1085 #endif
1086     b_mouseIsOver = true;
1087 }
1088
1089 /**
1090  * On mouse go out from FSC
1091  */
1092 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1093 {
1094     p_hideTimer->start( i_hideTimeout );
1095 #if HAVE_TRANSPARENCY
1096     p_slowHideTimer->start( i_hideTimeout / 2 );
1097 #endif
1098     b_mouseIsOver = false;
1099 }
1100
1101 /**
1102  * When you get pressed key, send it to video output
1103  * FIXME: clearing focus by clearFocus() to not getting
1104  * key press events didnt work
1105  */
1106 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1107 {
1108     int i_vlck = qtEventToVLCKey( event );
1109     if( i_vlck > 0 )
1110     {
1111         var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1112         event->accept();
1113     }
1114     else
1115         event->ignore();
1116 }
1117
1118 /**
1119  * It is called when video start
1120  */
1121 void FullscreenControllerWidget::regFullscreenCallback( vout_thread_t *p_vout )
1122 {
1123     if ( p_vout )
1124     {
1125         var_AddCallback( p_vout, "fullscreen", regMouseMoveCallback, this );
1126     }
1127 }
1128
1129 /**
1130  * It is called after turn off video, because p_vout is NULL now
1131  * we cannt delete callback, just hide if FScontroller is visible
1132  */
1133 void FullscreenControllerWidget::unregFullscreenCallback()
1134 {
1135     if ( isVisible() )
1136         hide();
1137 }
1138
1139 /**
1140  * Register and unregister callback for mouse moving
1141  */
1142 static int regMouseMoveCallback( vlc_object_t *vlc_object, const char *variable,
1143                                  vlc_value_t old_val, vlc_value_t new_val,
1144                                  void *data )
1145 {
1146     vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1147
1148     static bool b_registered = false;
1149     FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1150
1151     if ( var_GetBool( p_vout, "fullscreen" ) && !b_registered )
1152     {
1153         p_fs->SetHideTimeout( var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1154         var_AddCallback( p_vout, "mouse-moved",
1155                         showFullscreenControllCallback, (void *) p_fs );
1156         b_registered = true;
1157     }
1158
1159     if ( !var_GetBool( p_vout, "fullscreen" ) && b_registered )
1160     {
1161         var_DelCallback( p_vout, "mouse-moved",
1162                         showFullscreenControllCallback, (void *) p_fs );
1163         b_registered = false;
1164     }
1165
1166     if ( !var_GetBool( p_vout, "fullscreen" ) )
1167         p_fs->hide();
1168
1169     return VLC_SUCCESS;
1170 }
1171
1172 /**
1173  * Show fullscreen controller after mouse move
1174  * after show immediately plan hide event
1175  */
1176 static int showFullscreenControllCallback( vlc_object_t *vlc_object, const char *variable,
1177                                            vlc_value_t old_val, vlc_value_t new_val,
1178                                            void *data )
1179 {
1180     FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1181
1182     if ( p_fs->isFSCHidden() || p_fs->windowOpacity() < DEFAULT_OPACITY )
1183     {
1184         IMEvent *event = new IMEvent( FullscreenControlShow_Type, 0 );
1185         QApplication::postEvent( p_fs, static_cast<QEvent *>(event) );
1186     }
1187
1188     IMEvent *e = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1189     QApplication::postEvent( p_fs, static_cast<QEvent *>(e) );
1190
1191     return VLC_SUCCESS;
1192 }
1193
1194 /**********************************************************************
1195  * Speed control widget
1196  **********************************************************************/
1197 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1198                              QFrame( NULL ), p_intf( _p_i )
1199 {
1200     QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1201     sizePolicy.setHorizontalStretch( 0 );
1202     sizePolicy.setVerticalStretch( 0 );
1203
1204     speedSlider = new QSlider;
1205     speedSlider->setSizePolicy( sizePolicy );
1206     speedSlider->setMaximumSize( QSize( 80, 200 ) );
1207     speedSlider->setOrientation( Qt::Vertical );
1208     speedSlider->setTickPosition( QSlider::TicksRight );
1209
1210     speedSlider->setRange( -100, 100 );
1211     speedSlider->setSingleStep( 10 );
1212     speedSlider->setPageStep( 20 );
1213     speedSlider->setTickInterval( 20 );
1214
1215     CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1216
1217     QToolButton *normalSpeedButton = new QToolButton( this );
1218     normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1219     normalSpeedButton->setAutoRaise( true );
1220     normalSpeedButton->setText( "N" );
1221     normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1222
1223     CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1224
1225     QVBoxLayout *speedControlLayout = new QVBoxLayout;
1226     speedControlLayout->addWidget( speedSlider );
1227     speedControlLayout->addWidget( normalSpeedButton );
1228     setLayout( speedControlLayout );
1229 }
1230
1231 SpeedControlWidget::~SpeedControlWidget()
1232 {}
1233
1234 void SpeedControlWidget::setEnable( bool b_enable )
1235 {
1236     speedSlider->setEnabled( b_enable );
1237 }
1238
1239 #define RATE_SLIDER_MAXIMUM 3.0
1240 #define RATE_SLIDER_MINIMUM 0.3
1241 #define RATE_SLIDER_LENGTH 100.0
1242
1243 void SpeedControlWidget::updateControls( int rate )
1244 {
1245     if( speedSlider->isSliderDown() )
1246     {
1247         //We don't want to change anything if the user is using the slider
1248         return;
1249     }
1250
1251     int sliderValue;
1252     double speed = INPUT_RATE_DEFAULT / (double)rate;
1253
1254     if( rate >= INPUT_RATE_DEFAULT )
1255     {
1256         if( speed < RATE_SLIDER_MINIMUM )
1257         {
1258             sliderValue = speedSlider->minimum();
1259         }
1260         else
1261         {
1262             sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
1263                                         / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
1264         }
1265     }
1266     else
1267     {
1268         if( speed > RATE_SLIDER_MAXIMUM )
1269         {
1270             sliderValue = speedSlider->maximum();
1271         }
1272         else
1273         {
1274             sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
1275                                         / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
1276         }
1277     }
1278
1279     //Block signals to avoid feedback loop
1280     speedSlider->blockSignals( true );
1281     speedSlider->setValue( sliderValue );
1282     speedSlider->blockSignals( false );
1283 }
1284
1285 void SpeedControlWidget::updateRate( int sliderValue )
1286 {
1287     int rate;
1288
1289     if( sliderValue < 0.0 )
1290     {
1291         rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
1292             ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ));
1293     }
1294     else
1295     {
1296         rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
1297             ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH ));
1298     }
1299
1300     THEMIM->getIM()->setRate(rate);
1301 }
1302
1303 void SpeedControlWidget::resetRate()
1304 {
1305     THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
1306 }