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