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