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