]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
Qt4 - Try to fix the detection of video tracks and show of related buttons, fix a...
[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     CONNECT( THEMIM->getIM(), statusChanged( int ), this, updateInput() );
595
596     updateInput();
597 }
598
599 ControlsWidget::~ControlsWidget()
600 {}
601
602 void ControlsWidget::stop()
603 {
604     THEMIM->stop();
605 }
606
607 void ControlsWidget::play()
608 {
609     if( THEPL->current.i_size == 0 )
610     {
611         /* The playlist is empty, open a file requester */
612         THEDP->openFileDialog();
613         setStatus( 0 );
614         return;
615     }
616     THEMIM->togglePlayPause();
617 }
618
619 void ControlsWidget::prev()
620 {
621     THEMIM->prev();
622 }
623
624 void ControlsWidget::next()
625 {
626     THEMIM->next();
627 }
628
629 void ControlsWidget::setNavigation( int navigation )
630 {
631 #define HELP_MENU N_( "Menu" )
632 #define HELP_PCH N_( "Previous chapter" )
633 #define HELP_NCH N_( "Next chapter" )
634 #define HELP_PTR N_( "Previous track" )
635 #define HELP_NTR N_( "Next track" )
636
637     // 1 = chapter, 2 = title, 0 = no
638     if( navigation == 0 )
639     {
640         discFrame->hide();
641     } else if( navigation == 1 ) {
642         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
643         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
644         menuButton->show();
645         discFrame->show();
646     } else {
647         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
648         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
649         menuButton->hide();
650         discFrame->show();
651     }
652 }
653
654 static bool b_my_volume;
655 void ControlsWidget::updateVolume( int i_sliderVolume )
656 {
657     if( !b_my_volume )
658     {
659         int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
660         aout_VolumeSet( p_intf, i_res );
661     }
662     if( i_sliderVolume == 0 )
663         volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
664     else if( i_sliderVolume < VOLUME_MAX / 3 )
665         volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
666     else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
667         volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
668     else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
669 }
670
671 void ControlsWidget::updateVolume()
672 {
673     /* Audio part */
674     audio_volume_t i_volume;
675     aout_VolumeGet( p_intf, &i_volume );
676     i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
677     int i_gauge = volumeSlider->value();
678     b_my_volume = false;
679     if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
680     {
681         b_my_volume = true;
682         volumeSlider->setValue( i_volume );
683         b_my_volume = false;
684     }
685 }
686
687 void ControlsWidget::updateInput()
688 {
689     /* Activate the interface buttons according to the presence of the input */
690     enableInput( THEMIM->getIM()->hasInput() );
691     enableVideo( THEMIM->getIM()->hasVideo() );
692 }
693
694 void ControlsWidget::setStatus( int status )
695 {
696     if( status == PLAYING_S ) // Playing
697         playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
698     else
699         playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
700 }
701
702 /**
703  * TODO
704  * This functions toggle the fullscreen mode
705  * If there is no video, it should first activate Visualisations...
706  *  This has also to be fixed in enableVideo()
707  */
708 void ControlsWidget::fullscreen()
709 {
710     vout_thread_t *p_vout =
711         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
712     if( p_vout)
713     {
714         var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
715         vlc_object_release( p_vout );
716     }
717 }
718
719 void ControlsWidget::extSettings()
720 {
721     THEDP->extendedDialog();
722 }
723
724 void ControlsWidget::slower()
725 {
726     THEMIM->getIM()->slower();
727 }
728
729 void ControlsWidget::faster()
730 {
731     THEMIM->getIM()->faster();
732 }
733
734 void ControlsWidget::enableInput( bool enable )
735 {
736     slowerButton->setEnabled( enable );
737     slider->setEnabled( enable );
738     fasterButton->setEnabled( enable );
739
740     /* Advanced Buttons too */
741     advControls->enableInput( enable );
742 }
743
744 void ControlsWidget::enableVideo( bool enable )
745 {
746     // TODO Later make the fullscreenButton toggle Visualisation and so on.
747     fullscreenButton->setEnabled( enable );
748
749     /* Advanced Buttons too */
750     advControls->enableVideo( enable );
751 }
752
753 void ControlsWidget::toggleAdvanced()
754 {
755     if( !VISIBLE( advControls ) )
756     {
757         advControls->show();
758         b_advancedVisible = true;
759     }
760     else
761     {
762         advControls->hide();
763         b_advancedVisible = false;
764     }
765     emit advancedControlsToggled( b_advancedVisible );
766 }
767
768
769 /**********************************************************************
770  * Speed control widget
771  **********************************************************************/
772 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
773                              QFrame( NULL ), p_intf( _p_i )
774 {
775     QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
776     sizePolicy.setHorizontalStretch( 0 );
777     sizePolicy.setVerticalStretch( 0 );
778
779     speedSlider = new QSlider;
780     speedSlider->setSizePolicy( sizePolicy );
781     speedSlider->setMaximumSize( QSize( 80, 200 ) );
782     speedSlider->setOrientation( Qt::Vertical );
783     speedSlider->setTickPosition( QSlider::TicksRight );
784
785     speedSlider->setRange( -100, 100 );
786     speedSlider->setSingleStep( 10 );
787     speedSlider->setPageStep( 20 );
788     speedSlider->setTickInterval( 20 );
789
790     CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
791
792     QToolButton *normalSpeedButton = new QToolButton( this );
793     normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
794     normalSpeedButton->setAutoRaise( true );
795     normalSpeedButton->setText( "N" );
796     normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
797
798     CONNECT( normalSpeedButton, clicked(), this, resetRate() );
799
800     QVBoxLayout *speedControlLayout = new QVBoxLayout;
801     speedControlLayout->addWidget( speedSlider );
802     speedControlLayout->addWidget( normalSpeedButton );
803     setLayout( speedControlLayout );
804 }
805
806 SpeedControlWidget::~SpeedControlWidget()
807 {}
808
809 #define RATE_SLIDER_MAXIMUM 3.0
810 #define RATE_SLIDER_MINIMUM 0.3
811 #define RATE_SLIDER_LENGTH 100.0
812
813 void SpeedControlWidget::updateControls( int rate )
814 {
815     if( speedSlider->isSliderDown() )
816     {
817         //We don't want to change anything if the user is using the slider
818         return;
819     }
820
821     int sliderValue;
822     double speed = INPUT_RATE_DEFAULT / (double)rate;
823
824     if( rate >= INPUT_RATE_DEFAULT )
825     {
826         if( speed < RATE_SLIDER_MINIMUM )
827         {
828             sliderValue = speedSlider->minimum();
829         }
830         else
831         {
832             sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
833                                         / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
834         }
835     }
836     else
837     {
838         if( speed > RATE_SLIDER_MAXIMUM )
839         {
840             sliderValue = speedSlider->maximum();
841         }
842         else
843         {
844             sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
845                                         / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
846         }
847     }
848
849     //Block signals to avoid feedback loop
850     speedSlider->blockSignals( true );
851     speedSlider->setValue( sliderValue );
852     speedSlider->blockSignals( false );
853 }
854
855 void SpeedControlWidget::updateRate( int sliderValue )
856 {
857     int rate;
858
859     if( sliderValue < 0.0 )
860     {
861         rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
862             ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ));
863     }
864     else
865     {
866         rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
867             ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH ));
868     }
869
870     THEMIM->getIM()->setRate(rate);
871 }
872
873 void SpeedControlWidget::resetRate()
874 {
875     THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
876 }