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