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