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