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