]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
Qt4 - SHould Fix -- Videos are always started with an incredibly small size.
[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     //controlLayout->setMargin( 0 );
382
383     setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
384
385     /** The main Slider **/
386     slider = new InputSlider( Qt::Horizontal, NULL );
387     controlLayout->addWidget( slider, 0, 1, 1, 16 );
388     /* Update the position when the IM has changed */
389     CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
390              slider, setPosition( float, int, int ) );
391     /* And update the IM, when the position has changed */
392     CONNECT( slider, sliderDragged( float ),
393              THEMIM->getIM(), sliderUpdate( float ) );
394
395     /** Slower and faster Buttons **/
396     slowerButton = new QPushButton;
397     slowerButton->setFlat( true );
398     slowerButton->setMaximumSize( QSize( 26, 20 ) );
399
400     BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
401     controlLayout->addWidget( slowerButton, 0, 0 );
402
403     fasterButton = new QPushButton;
404     fasterButton->setFlat( true );
405     fasterButton->setMaximumSize( QSize( 26, 20 ) );
406
407     BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
408     controlLayout->addWidget( fasterButton, 0, 17 );
409
410     /* advanced Controls handling */
411     b_advancedVisible = b_advControls;
412
413     advControls = new AdvControlsWidget( p_intf );
414     controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
415     if( !b_advancedVisible ) advControls->hide();
416
417     /** Disc and Menus handling */
418     discFrame = new QFrame( this );
419
420     QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
421     discLayout->setSpacing( 0 );
422     discLayout->setMargin( 0 );
423
424     prevSectionButton = new QPushButton( discFrame );
425     setupSmallButton( prevSectionButton );
426     discLayout->addWidget( prevSectionButton );
427
428     menuButton = new QPushButton( discFrame );
429     setupSmallButton( menuButton );
430     discLayout->addWidget( menuButton );
431
432     nextSectionButton = new QPushButton( discFrame );
433     setupSmallButton( nextSectionButton );
434     discLayout->addWidget( nextSectionButton );
435
436     controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
437
438     BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
439     BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
440     BUTTON_SET_IMG( menuButton, "", previous.png, "" );
441
442     discFrame->hide();
443
444     /* Change the navigation button display when the IM navigation changes */
445     CONNECT( THEMIM->getIM(), navigationChanged( int ),
446              this, setNavigation( int ) );
447     /* Changes the IM navigation when triggered on the nav buttons */
448     CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
449              sectionPrev() );
450     CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
451              sectionNext() );
452     CONNECT( menuButton, clicked(), THEMIM->getIM(),
453              sectionMenu() );
454
455     /** TODO
456      * Telextext QFrame
457      * Merge with upper menu in a StackLayout
458      **/
459
460     /** Play Buttons **/
461     QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
462     sizePolicy.setHorizontalStretch( 0 );
463     sizePolicy.setVerticalStretch( 0 );
464
465     /* Play */
466     playButton = new QPushButton;
467     playButton->setSizePolicy( sizePolicy );
468     playButton->setMaximumSize( QSize( 36, 36 ) );
469     playButton->setMinimumSize( QSize( 36, 36 ) );
470     playButton->setIconSize( QSize( 30, 30 ) );
471
472     controlLayout->addWidget( playButton, 2, 0, 2, 2 );
473
474     controlLayout->setColumnMinimumWidth( 2, 20 );
475     controlLayout->setColumnStretch( 2, 0 );
476
477     /** Prev + Stop + Next Block **/
478     QHBoxLayout *controlButLayout = new QHBoxLayout;
479     controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
480
481     /* Prev */
482     QPushButton *prevButton = new QPushButton;
483     prevButton->setSizePolicy( sizePolicy );
484     setupSmallButton( prevButton );
485
486     controlButLayout->addWidget( prevButton );
487
488     /* Stop */
489     QPushButton *stopButton = new QPushButton;
490     stopButton->setSizePolicy( sizePolicy );
491     setupSmallButton( stopButton );
492
493     controlButLayout->addWidget( stopButton );
494
495     /* next */
496     QPushButton *nextButton = new QPushButton;
497     nextButton->setSizePolicy( sizePolicy );
498     setupSmallButton( nextButton );
499
500     controlButLayout->addWidget( nextButton );
501
502     /* Add this block to the main layout */
503     controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
504
505     BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
506     BUTTON_SET_ACT_I( prevButton, "" , previous.png,
507                       qtr( "Previous" ), prev() );
508     BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
509     BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
510
511     controlLayout->setColumnMinimumWidth( 7, 20 );
512     controlLayout->setColumnStretch( 7, 0 );
513     controlLayout->setColumnStretch( 8, 0 );
514     controlLayout->setColumnStretch( 9, 0 );
515
516     /*
517      * Other first Line buttons
518      */
519     /** Fullscreen/Visualisation **/
520     fullscreenButton = new QPushButton( "F" );
521     BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
522     setupSmallButton( fullscreenButton );
523     controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
524
525     /** Playlist Button **/
526     playlistButton = new QPushButton;
527     setupSmallButton( playlistButton );
528     controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
529     BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
530     CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
531
532     /** extended Settings **/
533     QPushButton *extSettingsButton = new QPushButton( "F" );
534     BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
535             extSettings() );
536     setupSmallButton( extSettingsButton );
537     controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
538
539     controlLayout->setColumnStretch( 13, 0 );
540     controlLayout->setColumnMinimumWidth( 13, 24 );
541     controlLayout->setColumnStretch( 14, 5 );
542
543     /* Volume */
544     VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
545
546     volMuteLabel = new QLabel;
547     volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
548     volMuteLabel->setToolTip( qtr( "Mute" ) );
549     volMuteLabel->installEventFilter( hVolLabel );
550     controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
551
552     if( b_shiny )
553     {
554         volumeSlider = new SoundSlider( this,
555             config_GetInt( p_intf, "volume-step" ),
556             config_GetInt( p_intf, "qt-volume-complete" ) );
557     }
558     else
559     {
560         volumeSlider = new QSlider( this );
561         volumeSlider->setOrientation( Qt::Horizontal );
562     }
563     volumeSlider->setMaximumSize( QSize( 200, 40 ) );
564     volumeSlider->setMinimumSize( QSize( 106, 30 ) );
565     volumeSlider->setFocusPolicy( Qt::NoFocus );
566     controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
567
568     /* Set the volume from the config */
569     volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
570                               VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
571
572     /* Volume control connection */
573     //resize( QSize( 300, 60 ) );
574     CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
575     msg_Dbg( p_intf, "controls size: %i - %i", size().width(), size().height() );
576 }
577
578 ControlsWidget::~ControlsWidget()
579 {}
580
581 /*
582 QSize ControlsWidget::sizeHint() const
583 {
584     return QSize( 300, 50 );
585 }
586 */
587
588 void ControlsWidget::stop()
589 {
590     THEMIM->stop();
591 }
592
593 void ControlsWidget::play()
594 {
595     if( THEPL->current.i_size == 0 )
596     {
597         /* The playlist is empty, open a file requester */
598         THEDP->openFileDialog();
599         setStatus( 0 );
600         return;
601     }
602     THEMIM->togglePlayPause();
603 }
604
605 void ControlsWidget::prev()
606 {
607     THEMIM->prev();
608 }
609
610 void ControlsWidget::next()
611 {
612     THEMIM->next();
613 }
614
615 void ControlsWidget::setNavigation( int navigation )
616 {
617 #define HELP_MENU N_( "Menu" )
618 #define HELP_PCH N_( "Previous chapter" )
619 #define HELP_NCH N_( "Next chapter" )
620 #define HELP_PTR N_( "Previous track" )
621 #define HELP_NTR N_( "Next track" )
622
623     // 1 = chapter, 2 = title, 0 = no
624     if( navigation == 0 )
625     {
626         discFrame->hide();
627     } else if( navigation == 1 ) {
628         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
629         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
630         menuButton->show();
631         discFrame->show();
632     } else {
633         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
634         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
635         menuButton->hide();
636         discFrame->show();
637     }
638 }
639
640 static bool b_my_volume;
641 void ControlsWidget::updateVolume( int i_sliderVolume )
642 {
643     if( !b_my_volume )
644     {
645         int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
646         aout_VolumeSet( p_intf, i_res );
647     }
648     if( i_sliderVolume == 0 )
649         volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
650     else if( i_sliderVolume < VOLUME_MAX / 2 )
651         volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
652     else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
653 }
654
655 void ControlsWidget::updateOnTimer()
656 {
657     /* Audio part */
658     audio_volume_t i_volume;
659     aout_VolumeGet( p_intf, &i_volume );
660     i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
661     int i_gauge = volumeSlider->value();
662     b_my_volume = false;
663     if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
664     {
665         b_my_volume = true;
666         volumeSlider->setValue( i_volume );
667         b_my_volume = false;
668     }
669
670     /* Activate the interface buttons according to the presence of the input */
671     enableInput( THEMIM->getIM()->hasInput() );
672     //enableVideo( THEMIM->getIM()->hasVideo() );
673     enableVideo( true );
674 }
675
676 void ControlsWidget::setStatus( int status )
677 {
678     if( status == PLAYING_S ) // Playing
679         playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
680     else
681         playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
682 }
683
684 /**
685  * TODO
686  * This functions toggle the fullscreen mode
687  * If there is no video, it should first activate Visualisations...
688  *  This has also to be fixed in enableVideo()
689  */
690 void ControlsWidget::fullscreen()
691 {
692     vout_thread_t *p_vout =
693         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
694     if( p_vout)
695     {
696         var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
697         vlc_object_release( p_vout );
698     }
699 }
700
701 void ControlsWidget::extSettings()
702 {
703     THEDP->extendedDialog();
704 }
705
706 void ControlsWidget::slower()
707 {
708     THEMIM->getIM()->slower();
709 }
710
711 void ControlsWidget::faster()
712 {
713     THEMIM->getIM()->faster();
714 }
715
716 void ControlsWidget::enableInput( bool enable )
717 {
718     slowerButton->setEnabled( enable );
719     slider->setEnabled( enable );
720     fasterButton->setEnabled( enable );
721
722     /* Advanced Buttons too */
723     advControls->enableInput( enable );
724 }
725
726 void ControlsWidget::enableVideo( bool enable )
727 {
728     // TODO Later make the fullscreenButton toggle Visualisation and so on.
729     fullscreenButton->setEnabled( enable );
730
731     /* Advanced Buttons too */
732     advControls->enableVideo( enable );
733 }
734
735 void ControlsWidget::toggleAdvanced()
736 {
737     if( !VISIBLE( advControls ) )
738     {
739         advControls->show();
740         b_advancedVisible = true;
741     }
742     else
743     {
744         advControls->hide();
745         b_advancedVisible = false;
746     }
747     emit advancedControlsToggled( b_advancedVisible );
748 }
749
750
751 /**********************************************************************
752  * Speed control widget
753  **********************************************************************/
754 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
755                              QFrame( NULL ), p_intf( _p_i )
756 {
757     QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
758     sizePolicy.setHorizontalStretch( 0 );
759     sizePolicy.setVerticalStretch( 0 );
760
761     speedSlider = new QSlider;
762     speedSlider->setSizePolicy( sizePolicy );
763     speedSlider->setMaximumSize( QSize( 80, 200 ) );
764     speedSlider->setOrientation( Qt::Vertical );
765     speedSlider->setTickPosition( QSlider::TicksRight );
766
767     speedSlider->setRange( -100, 100 );
768     speedSlider->setSingleStep( 10 );
769     speedSlider->setPageStep( 20 );
770     speedSlider->setTickInterval( 20 );
771
772     CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
773
774     normalSpeedButton = new QPushButton( "N" );
775     normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
776     normalSpeedButton->setFlat( true );
777     normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
778
779     CONNECT( normalSpeedButton, clicked(), this, resetRate() );
780
781     QVBoxLayout *speedControlLayout = new QVBoxLayout;
782     speedControlLayout->addWidget(speedSlider);
783     speedControlLayout->addWidget(normalSpeedButton);
784     setLayout(speedControlLayout);
785 }
786
787 SpeedControlWidget::~SpeedControlWidget()
788 {}
789
790 #define RATE_SLIDER_MAXIMUM 3.0
791 #define RATE_SLIDER_MINIMUM 0.3
792 #define RATE_SLIDER_LENGTH 100.0
793
794 void SpeedControlWidget::updateControls( int rate )
795 {
796     if( speedSlider->isSliderDown() )
797     {
798         //We don't want to change anything if the user is using the slider
799         return;
800     }
801
802     int sliderValue;
803     double speed = INPUT_RATE_DEFAULT / (double)rate;
804
805     if( rate >= INPUT_RATE_DEFAULT )
806     {
807         if( speed < RATE_SLIDER_MINIMUM )
808         {
809             sliderValue = speedSlider->minimum();
810         }
811         else
812         {
813             sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
814                                         / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
815         }
816     }
817     else
818     {
819         if( speed > RATE_SLIDER_MAXIMUM )
820         {
821             sliderValue = speedSlider->maximum();
822         }
823         else
824         {
825             sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
826                                         / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
827         }
828     }
829
830     //Block signals to avoid feedback loop
831     speedSlider->blockSignals( true );
832     speedSlider->setValue( sliderValue );
833     speedSlider->blockSignals( false );
834 }
835
836 void SpeedControlWidget::updateRate( int sliderValue )
837 {
838     int rate;
839
840     if( sliderValue < 0.0 )
841     {
842         rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
843             ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH );
844     }
845     else
846     {
847         rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
848             ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
849     }
850
851     THEMIM->getIM()->setRate(rate);
852 }
853
854 void SpeedControlWidget::resetRate()
855 {
856     THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
857 }