]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
Qt4 - Include fix
[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 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include "dialogs_provider.hpp"
31 #include "components/interface_widgets.hpp"
32 #include "main_interface.hpp"
33 #include "input_manager.hpp"
34 #include "menus.hpp"
35 #include "util/input_slider.hpp"
36 #include "util/customwidgets.hpp"
37 #include <vlc_vout.h>
38
39 #include <QLabel>
40 #include <QSpacerItem>
41 #include <QCursor>
42 #include <QPushButton>
43 #include <QToolButton>
44 #include <QHBoxLayout>
45 #include <QMenu>
46 #include <QPalette>
47 #include <QResizeEvent>
48 #include <QDate>
49
50 /**********************************************************************
51  * Video Widget. A simple frame on which video is drawn
52  * This class handles resize issues
53  **********************************************************************/
54 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
55                         unsigned int *, unsigned int * );
56 static void DoRelease( intf_thread_t *, void * );
57 static int DoControl( intf_thread_t *, void *, int, va_list );
58
59 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
60 {
61     /* Init */
62     vlc_mutex_init( p_intf, &lock );
63     p_vout = NULL;
64     hide(); setMinimumSize( 16, 16 );
65     videoSize.rwidth() = -1;
66     videoSize.rheight() = -1;
67
68     /* Black background is more coherent for a Video Widget IMVHO */
69     QPalette plt =  palette();
70     plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
71     plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
72     setPalette( plt );
73
74     /* The core can ask through a callback to show the video */
75     CONNECT( this, askVideoWidgetToShow(), this, show() );
76     /* The core can ask through a callback to resize the video */
77    // CONNECT( this, askResize( int, int ), this, SetSizing( int, int ) );
78 }
79
80 VideoWidget::~VideoWidget()
81 {
82     vlc_mutex_lock( &lock );
83     if( p_vout )
84     {
85         if( !p_intf->psz_switch_intf )
86         {
87             if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
88                 vout_Control( p_vout, VOUT_REPARENT );
89         }
90         else
91         {
92             if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
93                 vout_Control( p_vout, VOUT_CLOSE );
94         }
95     }
96     vlc_mutex_unlock( &lock );
97     vlc_mutex_destroy( &lock );
98 }
99
100 /**
101  * Request the video to avoid the conflicts
102  **/
103 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
104                            unsigned int *pi_width, unsigned int *pi_height )
105 {
106     msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
107     emit askVideoWidgetToShow();
108     if( p_vout )
109     {
110         msg_Dbg( p_intf, "embedded video already in use" );
111         return NULL;
112     }
113     p_vout = p_nvout;
114     return ( void* )winId();
115 }
116
117 /* Set the Widget to the correct Size */
118 /* Function has to be called by the parent
119    Parent has to care about resizing himself*/
120 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
121 {
122     msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
123     videoSize.rwidth() = w;
124     videoSize.rheight() = h;
125     updateGeometry(); // Needed for deinterlace
126 }
127
128 void VideoWidget::release( void *p_win )
129 {
130     msg_Dbg( p_intf, "Video is non needed anymore" );
131     p_vout = NULL;
132     videoSize.rwidth() = 0;
133     videoSize.rheight() = 0;
134     hide();
135     updateGeometry(); // Needed for deinterlace
136 }
137
138 QSize VideoWidget::sizeHint() const
139 {
140     return videoSize;
141 }
142
143 /**********************************************************************
144  * Background Widget. Show a simple image background. Currently,
145  * it's album art if present or cone.
146  **********************************************************************/
147 #define ICON_SIZE 128
148 #define MAX_BG_SIZE 400
149 #define MIN_BG_SIZE 64
150
151 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
152                                         QWidget( NULL ), p_intf( _p_i )
153 {
154     /* We should use that one to take the more size it can */
155     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
156
157     /* A dark background */
158     setAutoFillBackground( true );
159     plt =  palette();
160     plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
161     plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
162     setPalette( plt );
163
164     /* A cone in the middle */
165     label = new QLabel;
166     label->setMargin( 5 );
167     label->setMaximumHeight( MAX_BG_SIZE );
168     label->setMaximumWidth( MAX_BG_SIZE );
169     label->setMinimumHeight( MIN_BG_SIZE );
170     label->setMinimumWidth( MIN_BG_SIZE );
171     if( QDate::currentDate().dayOfYear() >= 354 )
172         label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
173     else
174         label->setPixmap( QPixmap( ":/vlc128.png" ) );
175
176     QGridLayout *backgroundLayout = new QGridLayout( this );
177     backgroundLayout->addWidget( label, 0, 1 );
178     backgroundLayout->setColumnStretch( 0, 1 );
179     backgroundLayout->setColumnStretch( 2, 1 );
180
181     CONNECT( THEMIM->getIM(), artChanged( QString ), this, update( QString ) );
182     resize( 300, 150 );
183 }
184
185 BackgroundWidget::~BackgroundWidget()
186 {
187 }
188
189 void BackgroundWidget::update( QString url )
190 {
191     if( url.isNull() )
192     {
193         if( QDate::currentDate().dayOfYear() >= 354 )
194             label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
195         else
196             label->setPixmap( QPixmap( ":/vlc128.png" ) );
197         return;
198     }
199     else
200     {
201         label->setPixmap( QPixmap( url ) );
202         msg_Dbg( p_intf, "changing input b_need_update done ");
203     }
204 }
205
206 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
207 {
208     QVLCMenu::PopupMenu( p_intf, true );
209 }
210
211 /**********************************************************************
212  * Visualization selector panel
213  **********************************************************************/
214 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
215                                 QFrame( NULL ), p_intf( _p_i )
216 {
217     QHBoxLayout *layout = new QHBoxLayout( this );
218     layout->setMargin( 0 );
219     QPushButton *prevButton = new QPushButton( "Prev" );
220     QPushButton *nextButton = new QPushButton( "Next" );
221     layout->addWidget( prevButton );
222     layout->addWidget( nextButton );
223
224     layout->addItem( new QSpacerItem( 40,20,
225                               QSizePolicy::Expanding, QSizePolicy::Minimum ) );
226     layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
227
228     current = new QLabel( qtr( "None" ) );
229     layout->addWidget( current );
230
231     BUTTONACT( prevButton, prev() );
232     BUTTONACT( nextButton, next() );
233
234     setLayout( layout );
235     setMaximumHeight( 35 );
236 }
237
238 VisualSelector::~VisualSelector()
239 {
240 }
241
242 void VisualSelector::prev()
243 {
244     char *psz_new = aout_VisualPrev( p_intf );
245     if( psz_new )
246     {
247         current->setText( qfu( psz_new ) );
248         free( psz_new );
249     }
250 }
251
252 void VisualSelector::next()
253 {
254     char *psz_new = aout_VisualNext( p_intf );
255     if( psz_new )
256     {
257         current->setText( qfu( psz_new ) );
258         free( psz_new );
259     }
260 }
261
262 /**********************************************************************
263  * TEH controls
264  **********************************************************************/
265
266 #define setupSmallButton( aButton ){  \
267     aButton->setMaximumSize( QSize( 26, 26 ) ); \
268     aButton->setMinimumSize( QSize( 26, 26 ) ); \
269     aButton->setIconSize( QSize( 20, 20 ) ); }
270
271 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
272                                            QFrame( NULL ), p_intf( _p_i )
273 {
274     QHBoxLayout *advLayout = new QHBoxLayout( this );
275     advLayout->setMargin( 0 );
276     advLayout->setSpacing( 0 );
277
278     /* A to B Button */
279     ABButton = new QPushButton( "AB" );
280     ABButton->setMaximumSize( QSize( 26, 26 ) );
281     ABButton->setIconSize( QSize( 20, 20 ) );
282     advLayout->addWidget( ABButton );
283     BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
284     timeA = timeB = 0;
285     CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
286              this, AtoBLoop( float, int, int ) );
287 #if 0
288     frameButton = new QPushButton( "Fr" );
289     frameButton->setMaximumSize( QSize( 26, 26 ) );
290     frameButton->setIconSize( QSize( 20, 20 ) );
291     advLayout->addWidget( frameButton );
292     BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
293 #endif
294
295     recordButton = new QPushButton( "R" );
296     recordButton->setMaximumSize( QSize( 26, 26 ) );
297     recordButton->setIconSize( QSize( 20, 20 ) );
298     advLayout->addWidget( recordButton );
299     BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
300             qtr( "Record" ), record() );
301
302     /* Snapshot Button */
303     snapshotButton = new QPushButton( "S" );
304     snapshotButton->setMaximumSize( QSize( 26, 26 ) );
305     snapshotButton->setIconSize( QSize( 20, 20 ) );
306     advLayout->addWidget( snapshotButton );
307     BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
308 }
309
310 AdvControlsWidget::~AdvControlsWidget()
311 {}
312
313 void AdvControlsWidget::enableInput( bool enable )
314 {
315     ABButton->setEnabled( enable );
316     recordButton->setEnabled( enable );
317 }
318
319 void AdvControlsWidget::enableVideo( bool enable )
320 {
321     snapshotButton->setEnabled( enable );
322 #if 0
323     frameButton->setEnabled( enable );
324 #endif
325 }
326
327 void AdvControlsWidget::snapshot()
328 {
329     vout_thread_t *p_vout =
330         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
331     if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
332 }
333
334 /* Function called when the button is clicked() */
335 void AdvControlsWidget::fromAtoB()
336 {
337     if( !timeA )
338     {
339         timeA = var_GetTime( THEMIM->getInput(), "time"  );
340         ABButton->setText( "A->..." );
341         return;
342     }
343     if( !timeB )
344     {
345         timeB = var_GetTime( THEMIM->getInput(), "time"  );
346         var_SetTime( THEMIM->getInput(), "time" , timeA );
347         ABButton->setText( "A<=>B" );
348         return;
349     }
350     timeA = 0;
351     timeB = 0;
352     ABButton->setText( "AB" );
353 }
354
355 /* Function called regularly when in an AtoB loop */
356 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
357 {
358     if( timeB )
359     {
360         if( i_time >= (int)(timeB/1000000) )
361             var_SetTime( THEMIM->getInput(), "time" , timeA );
362     }
363 }
364
365 /* FIXME Record function */
366 void AdvControlsWidget::record(){}
367
368 #if 0
369 //FIXME Frame by frame function
370 void AdvControlsWidget::frame(){}
371 #endif
372
373 /*****************************
374  * DA Control Widget !
375  *****************************/
376 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
377                                 MainInterface *_p_mi,
378                                 bool b_advControls,
379                                 bool b_shiny ) :
380                                 QFrame( NULL ), p_intf( _p_i )
381 {
382     controlLayout = new QGridLayout( this );
383     controlLayout->setSpacing( 0 );
384 #if QT43
385     controlLayout->setContentsMargins( 9, 6, 9, 6 );
386 #else
387     controlLayout->setMargin( 6 );
388 #endif
389
390     setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
391
392     /** The main Slider **/
393     slider = new InputSlider( Qt::Horizontal, NULL );
394     controlLayout->addWidget( slider, 0, 1, 1, 16 );
395     /* Update the position when the IM has changed */
396     CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
397              slider, setPosition( float, int, int ) );
398     /* And update the IM, when the position has changed */
399     CONNECT( slider, sliderDragged( float ),
400              THEMIM->getIM(), sliderUpdate( float ) );
401
402     /** Slower and faster Buttons **/
403     slowerButton = new QToolButton;
404     slowerButton->setAutoRaise( true );
405     slowerButton->setMaximumSize( QSize( 26, 20 ) );
406
407     BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
408     controlLayout->addWidget( slowerButton, 0, 0 );
409
410     fasterButton = new QToolButton;
411     fasterButton->setAutoRaise( true );
412     fasterButton->setMaximumSize( QSize( 26, 20 ) );
413
414     BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
415     controlLayout->addWidget( fasterButton, 0, 17 );
416
417     /* advanced Controls handling */
418     b_advancedVisible = b_advControls;
419
420     advControls = new AdvControlsWidget( p_intf );
421     controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
422     if( !b_advancedVisible ) advControls->hide();
423
424     /** Disc and Menus handling */
425     discFrame = new QWidget( this );
426
427     QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
428     discLayout->setSpacing( 0 );
429     discLayout->setMargin( 0 );
430
431     prevSectionButton = new QPushButton( discFrame );
432     setupSmallButton( prevSectionButton );
433     discLayout->addWidget( prevSectionButton );
434
435     menuButton = new QPushButton( discFrame );
436     setupSmallButton( menuButton );
437     discLayout->addWidget( menuButton );
438
439     nextSectionButton = new QPushButton( discFrame );
440     setupSmallButton( nextSectionButton );
441     discLayout->addWidget( nextSectionButton );
442
443     controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
444
445     BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
446     BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
447     BUTTON_SET_IMG( menuButton, "", previous.png, "" );
448
449     discFrame->hide();
450
451     /* Change the navigation button display when the IM navigation changes */
452     CONNECT( THEMIM->getIM(), navigationChanged( int ),
453              this, setNavigation( int ) );
454     /* Changes the IM navigation when triggered on the nav buttons */
455     CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
456              sectionPrev() );
457     CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
458              sectionNext() );
459     CONNECT( menuButton, clicked(), THEMIM->getIM(),
460              sectionMenu() );
461     /**
462      * Telextext QFrame
463      * TODO: Merge with upper menu in a StackLayout
464      **/
465 #ifdef ZVBI_COMPILED
466     telexFrame = new QWidget( this );
467     QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
468     telexLayout->setSpacing( 0 );
469     telexLayout->setMargin( 0 );
470
471     QToolButton *telexOn = new QToolButton;
472     telexOn->setText( qtr( "On" ) );
473     setupSmallButton( telexOn );
474     telexLayout->addWidget( telexOn );
475
476     QToolButton *telexTransparent = new QToolButton;
477     telexTransparent->setText( qtr( "Transparent" ) );
478     setupSmallButton( telexTransparent );
479     telexLayout->addWidget( telexTransparent );
480
481     QSpinBox *telexPage = new QSpinBox;
482     telexPage->setRange( 0, 999 );
483     telexPage->setValue( 100 );
484     telexPage->setAlignment( Qt::AlignRight );
485     telexLayout->addWidget( telexPage );
486
487     controlLayout->addWidget( telexFrame, 1, 10, 2, 3, Qt::AlignBottom );
488     telexFrame->hide();
489
490     CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
491              telexGotoPage( int ) );
492     CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
493              telexToggle( bool ) );
494     CONNECT( telexTransparent, clicked( bool ),
495              THEMIM->getIM(), telexSetTransparency( bool ) );
496     CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
497              telexFrame, setVisible( bool ) );
498 #endif
499
500     /** Play Buttons **/
501     QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
502     sizePolicy.setHorizontalStretch( 0 );
503     sizePolicy.setVerticalStretch( 0 );
504
505     /* Play */
506     playButton = new QPushButton;
507     playButton->setSizePolicy( sizePolicy );
508     playButton->setMaximumSize( QSize( 36, 36 ) );
509     playButton->setMinimumSize( QSize( 36, 36 ) );
510     playButton->setIconSize( QSize( 30, 30 ) );
511
512     controlLayout->addWidget( playButton, 2, 0, 2, 2 );
513
514     controlLayout->setColumnMinimumWidth( 2, 20 );
515     controlLayout->setColumnStretch( 2, 0 );
516
517     /** Prev + Stop + Next Block **/
518     QHBoxLayout *controlButLayout = new QHBoxLayout;
519     controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
520
521     /* Prev */
522     QPushButton *prevButton = new QPushButton;
523     prevButton->setSizePolicy( sizePolicy );
524     setupSmallButton( prevButton );
525
526     controlButLayout->addWidget( prevButton );
527
528     /* Stop */
529     QPushButton *stopButton = new QPushButton;
530     stopButton->setSizePolicy( sizePolicy );
531     setupSmallButton( stopButton );
532
533     controlButLayout->addWidget( stopButton );
534
535     /* next */
536     QPushButton *nextButton = new QPushButton;
537     nextButton->setSizePolicy( sizePolicy );
538     setupSmallButton( nextButton );
539
540     controlButLayout->addWidget( nextButton );
541
542     /* Add this block to the main layout */
543     controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
544
545     BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
546     BUTTON_SET_ACT_I( prevButton, "" , previous.png,
547                       qtr( "Previous" ), prev() );
548     BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
549     BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
550
551     controlLayout->setColumnMinimumWidth( 7, 20 );
552     controlLayout->setColumnStretch( 7, 0 );
553     controlLayout->setColumnStretch( 8, 0 );
554     controlLayout->setColumnStretch( 9, 0 );
555
556     /*
557      * Other first Line buttons
558      */
559     /** Fullscreen/Visualisation **/
560     fullscreenButton = new QPushButton( "F" );
561     BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
562     setupSmallButton( fullscreenButton );
563     controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
564
565     /** Playlist Button **/
566     playlistButton = new QPushButton;
567     setupSmallButton( playlistButton );
568     controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
569     BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
570     CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
571
572     /** extended Settings **/
573     QPushButton *extSettingsButton = new QPushButton( "F" );
574     BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
575             extSettings() );
576     setupSmallButton( extSettingsButton );
577     controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
578
579     controlLayout->setColumnStretch( 13, 0 );
580     controlLayout->setColumnMinimumWidth( 13, 24 );
581     controlLayout->setColumnStretch( 14, 5 );
582
583     /* Volume */
584     VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
585
586     volMuteLabel = new QLabel;
587     volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
588     volMuteLabel->setToolTip( qtr( "Mute" ) );
589     volMuteLabel->installEventFilter( hVolLabel );
590     controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
591
592     if( b_shiny )
593     {
594         volumeSlider = new SoundSlider( this,
595             config_GetInt( p_intf, "volume-step" ),
596             config_GetInt( p_intf, "qt-volume-complete" ) );
597     }
598     else
599     {
600         volumeSlider = new QSlider( this );
601         volumeSlider->setOrientation( Qt::Horizontal );
602     }
603     volumeSlider->setMaximumSize( QSize( 200, 40 ) );
604     volumeSlider->setMinimumSize( QSize( 106, 30 ) );
605     volumeSlider->setFocusPolicy( Qt::NoFocus );
606     controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
607
608     /* Set the volume from the config */
609     volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
610                               VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
611
612     /* Volume control connection */
613     CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
614     CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
615
616     CONNECT( THEMIM->getIM(), statusChanged( int ), this, updateInput() );
617
618     updateInput();
619 }
620
621 ControlsWidget::~ControlsWidget()
622 {}
623
624 void ControlsWidget::stop()
625 {
626     THEMIM->stop();
627 }
628
629 void ControlsWidget::play()
630 {
631     if( THEPL->current.i_size == 0 )
632     {
633         /* The playlist is empty, open a file requester */
634         THEDP->openFileDialog();
635         setStatus( 0 );
636         return;
637     }
638     THEMIM->togglePlayPause();
639 }
640
641 void ControlsWidget::prev()
642 {
643     THEMIM->prev();
644 }
645
646 void ControlsWidget::next()
647 {
648     THEMIM->next();
649 }
650
651 void ControlsWidget::setNavigation( int navigation )
652 {
653 #define HELP_MENU N_( "Menu" )
654 #define HELP_PCH N_( "Previous chapter" )
655 #define HELP_NCH N_( "Next chapter" )
656 #define HELP_PTR N_( "Previous track" )
657 #define HELP_NTR N_( "Next track" )
658
659     // 1 = chapter, 2 = title, 0 = no
660     if( navigation == 0 )
661     {
662         discFrame->hide();
663     } else if( navigation == 1 ) {
664         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
665         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
666         menuButton->show();
667         discFrame->show();
668     } else {
669         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
670         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
671         menuButton->hide();
672         discFrame->show();
673     }
674 }
675
676 static bool b_my_volume;
677 void ControlsWidget::updateVolume( int i_sliderVolume )
678 {
679     if( !b_my_volume )
680     {
681         int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
682         aout_VolumeSet( p_intf, i_res );
683     }
684     if( i_sliderVolume == 0 )
685         volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
686     else if( i_sliderVolume < VOLUME_MAX / 3 )
687         volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
688     else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
689         volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
690     else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
691 }
692
693 void ControlsWidget::updateVolume()
694 {
695     /* Audio part */
696     audio_volume_t i_volume;
697     aout_VolumeGet( p_intf, &i_volume );
698     i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
699     int i_gauge = volumeSlider->value();
700     b_my_volume = false;
701     if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
702     {
703         b_my_volume = true;
704         volumeSlider->setValue( i_volume );
705         b_my_volume = false;
706     }
707 }
708
709 void ControlsWidget::updateInput()
710 {
711     /* Activate the interface buttons according to the presence of the input */
712     enableInput( THEMIM->getIM()->hasInput() );
713     enableVideo( THEMIM->getIM()->hasVideo() );
714 }
715
716 void ControlsWidget::setStatus( int status )
717 {
718     if( status == PLAYING_S ) // Playing
719         playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
720     else
721         playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
722 }
723
724 /**
725  * TODO
726  * This functions toggle the fullscreen mode
727  * If there is no video, it should first activate Visualisations...
728  *  This has also to be fixed in enableVideo()
729  */
730 void ControlsWidget::fullscreen()
731 {
732     vout_thread_t *p_vout =
733         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
734     if( p_vout)
735     {
736         var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
737         vlc_object_release( p_vout );
738     }
739 }
740
741 void ControlsWidget::extSettings()
742 {
743     THEDP->extendedDialog();
744 }
745
746 void ControlsWidget::slower()
747 {
748     THEMIM->getIM()->slower();
749 }
750
751 void ControlsWidget::faster()
752 {
753     THEMIM->getIM()->faster();
754 }
755
756 void ControlsWidget::enableInput( bool enable )
757 {
758     slowerButton->setEnabled( enable );
759     slider->setEnabled( enable );
760     fasterButton->setEnabled( enable );
761
762     /* Advanced Buttons too */
763     advControls->enableInput( enable );
764 }
765
766 void ControlsWidget::enableVideo( bool enable )
767 {
768     // TODO Later make the fullscreenButton toggle Visualisation and so on.
769     fullscreenButton->setEnabled( enable );
770
771     /* Advanced Buttons too */
772     advControls->enableVideo( enable );
773 }
774
775 void ControlsWidget::toggleAdvanced()
776 {
777     if( !VISIBLE( advControls ) )
778     {
779         advControls->show();
780         b_advancedVisible = true;
781     }
782     else
783     {
784         advControls->hide();
785         b_advancedVisible = false;
786     }
787     emit advancedControlsToggled( b_advancedVisible );
788 }
789
790
791 /**********************************************************************
792  * Speed control widget
793  **********************************************************************/
794 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
795                              QFrame( NULL ), p_intf( _p_i )
796 {
797     QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
798     sizePolicy.setHorizontalStretch( 0 );
799     sizePolicy.setVerticalStretch( 0 );
800
801     speedSlider = new QSlider;
802     speedSlider->setSizePolicy( sizePolicy );
803     speedSlider->setMaximumSize( QSize( 80, 200 ) );
804     speedSlider->setOrientation( Qt::Vertical );
805     speedSlider->setTickPosition( QSlider::TicksRight );
806
807     speedSlider->setRange( -100, 100 );
808     speedSlider->setSingleStep( 10 );
809     speedSlider->setPageStep( 20 );
810     speedSlider->setTickInterval( 20 );
811
812     CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
813
814     QToolButton *normalSpeedButton = new QToolButton( this );
815     normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
816     normalSpeedButton->setAutoRaise( true );
817     normalSpeedButton->setText( "N" );
818     normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
819
820     CONNECT( normalSpeedButton, clicked(), this, resetRate() );
821
822     QVBoxLayout *speedControlLayout = new QVBoxLayout;
823     speedControlLayout->addWidget( speedSlider );
824     speedControlLayout->addWidget( normalSpeedButton );
825     setLayout( speedControlLayout );
826 }
827
828 SpeedControlWidget::~SpeedControlWidget()
829 {}
830
831 void SpeedControlWidget::mouseDoubleClickEvent( QMouseEvent * event )
832 {
833     msg_Dbg( p_intf, "coin coin" );
834     resetRate();
835 }
836
837 #define RATE_SLIDER_MAXIMUM 3.0
838 #define RATE_SLIDER_MINIMUM 0.3
839 #define RATE_SLIDER_LENGTH 100.0
840
841 void SpeedControlWidget::updateControls( int rate )
842 {
843     if( speedSlider->isSliderDown() )
844     {
845         //We don't want to change anything if the user is using the slider
846         return;
847     }
848
849     int sliderValue;
850     double speed = INPUT_RATE_DEFAULT / (double)rate;
851
852     if( rate >= INPUT_RATE_DEFAULT )
853     {
854         if( speed < RATE_SLIDER_MINIMUM )
855         {
856             sliderValue = speedSlider->minimum();
857         }
858         else
859         {
860             sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
861                                         / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
862         }
863     }
864     else
865     {
866         if( speed > RATE_SLIDER_MAXIMUM )
867         {
868             sliderValue = speedSlider->maximum();
869         }
870         else
871         {
872             sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
873                                         / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
874         }
875     }
876
877     //Block signals to avoid feedback loop
878     speedSlider->blockSignals( true );
879     speedSlider->setValue( sliderValue );
880     speedSlider->blockSignals( false );
881 }
882
883 void SpeedControlWidget::updateRate( int sliderValue )
884 {
885     int rate;
886
887     if( sliderValue < 0.0 )
888     {
889         rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
890             ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ));
891     }
892     else
893     {
894         rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
895             ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH ));
896     }
897
898     THEMIM->getIM()->setRate(rate);
899 }
900
901 void SpeedControlWidget::resetRate()
902 {
903     THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
904 }