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