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