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