]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
add artChanged signal to inputmanager and change backgroundwidget to use
[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
175     QString arturl = url.replace( "file://",QString("" ) );
176     if( arturl.isNull() )
177     {
178         if( QDate::currentDate().dayOfYear() >= 354 )
179             label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
180         else
181             label->setPixmap( QPixmap( ":/vlc128.png" ) );
182     }
183     else
184     {
185         label->setPixmap( QPixmap( arturl ) );
186         msg_Dbg( p_intf, "changing input b_need_update done ");
187     }
188 }
189
190 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
191 {
192     QVLCMenu::PopupMenu( p_intf, true );
193 }
194
195 /**********************************************************************
196  * Visualization selector panel
197  **********************************************************************/
198 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
199                                 QFrame( NULL ), p_intf( _p_i )
200 {
201     QHBoxLayout *layout = new QHBoxLayout( this );
202     layout->setMargin( 0 );
203     QPushButton *prevButton = new QPushButton( "Prev" );
204     QPushButton *nextButton = new QPushButton( "Next" );
205     layout->addWidget( prevButton );
206     layout->addWidget( nextButton );
207
208     layout->addItem( new QSpacerItem( 40,20,
209                               QSizePolicy::Expanding, QSizePolicy::Minimum ) );
210     layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
211
212     current = new QLabel( qtr( "None" ) );
213     layout->addWidget( current );
214
215     BUTTONACT( prevButton, prev() );
216     BUTTONACT( nextButton, next() );
217
218     setLayout( layout );
219     setMaximumHeight( 35 );
220 }
221
222 VisualSelector::~VisualSelector()
223 {
224 }
225
226 void VisualSelector::prev()
227 {
228     char *psz_new = aout_VisualPrev( p_intf );
229     if( psz_new )
230     {
231         current->setText( qfu( psz_new ) );
232         free( psz_new );
233     }
234 }
235
236 void VisualSelector::next()
237 {
238     char *psz_new = aout_VisualNext( p_intf );
239     if( psz_new )
240     {
241         current->setText( qfu( psz_new ) );
242         free( psz_new );
243     }
244 }
245
246 /**********************************************************************
247  * TEH controls
248  **********************************************************************/
249
250 #define setupSmallButton( aButton ){  \
251     aButton->setMaximumSize( QSize( 26, 26 ) ); \
252     aButton->setMinimumSize( QSize( 26, 26 ) ); \
253     aButton->setIconSize( QSize( 20, 20 ) ); }
254
255 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
256                                            QFrame( NULL ), p_intf( _p_i )
257 {
258     QHBoxLayout *advLayout = new QHBoxLayout( this );
259     advLayout->setMargin( 0 );
260     advLayout->setSpacing( 0 );
261
262     /* A to B Button */
263     ABButton = new QPushButton( "AB" );
264     ABButton->setMaximumSize( QSize( 26, 26 ) );
265     ABButton->setIconSize( QSize( 20, 20 ) );
266     advLayout->addWidget( ABButton );
267     BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
268     timeA = timeB = 0;
269     CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
270              this, AtoBLoop( float, int, int ) );
271
272     frameButton = new QPushButton( "Fr" );
273     frameButton->setMaximumSize( QSize( 26, 26 ) );
274     frameButton->setIconSize( QSize( 20, 20 ) );
275     advLayout->addWidget( frameButton );
276     BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
277
278     recordButton = new QPushButton( "R" );
279     recordButton->setMaximumSize( QSize( 26, 26 ) );
280     recordButton->setIconSize( QSize( 20, 20 ) );
281     advLayout->addWidget( recordButton );
282     BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
283             qtr( "Record" ), record() );
284
285     /* Snapshot Button */
286     snapshotButton = new QPushButton( "S" );
287     snapshotButton->setMaximumSize( QSize( 26, 26 ) );
288     snapshotButton->setIconSize( QSize( 20, 20 ) );
289     advLayout->addWidget( snapshotButton );
290     BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
291 }
292
293 AdvControlsWidget::~AdvControlsWidget()
294 {}
295
296 void AdvControlsWidget::enableInput( bool enable )
297 {
298     ABButton->setEnabled( enable );
299     recordButton->setEnabled( enable );
300 }
301
302 void AdvControlsWidget::enableVideo( bool enable )
303 {
304     snapshotButton->setEnabled( enable );
305     frameButton->setEnabled( enable );
306 }
307
308 void AdvControlsWidget::snapshot()
309 {
310     vout_thread_t *p_vout =
311         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
312     if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
313 }
314
315 /* Function called when the button is clicked() */
316 void AdvControlsWidget::fromAtoB()
317 {
318     if( !timeA )
319     {
320         timeA = var_GetTime( THEMIM->getInput(), "time"  );
321         ABButton->setText( "A->..." );
322         return;
323     }
324     if( !timeB )
325     {
326         timeB = var_GetTime( THEMIM->getInput(), "time"  );
327         var_SetTime( THEMIM->getInput(), "time" , timeA );
328         ABButton->setText( "A<=>B" );
329         return;
330     }
331     timeA = 0;
332     timeB = 0;
333     ABButton->setText( "AB" );
334 }
335
336 /* Function called regularly when in an AtoB loop */
337 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
338 {
339     if( timeB )
340     {
341         if( i_time >= (int)(timeB/1000000) )
342             var_SetTime( THEMIM->getInput(), "time" , timeA );
343     }
344 }
345
346 /* FIXME Record function */
347 void AdvControlsWidget::record(){}
348
349 //FIXME Frame by frame function
350 void AdvControlsWidget::frame(){}
351
352 /*****************************
353  * DA Control Widget !
354  *****************************/
355 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
356                                 MainInterface *_p_mi,
357                                 bool b_advControls,
358                                 bool b_shiny ) :
359                                 QFrame( NULL ), p_intf( _p_i )
360 {
361     controlLayout = new QGridLayout( this );
362     controlLayout->setSpacing( 0 );
363 #if QT43
364     controlLayout->setContentsMargins( 9, 6, 9, 6 );
365 #else
366     controlLayout->setMargin( 6 );
367 #endif
368
369     setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
370
371     /** The main Slider **/
372     slider = new InputSlider( Qt::Horizontal, NULL );
373     controlLayout->addWidget( slider, 0, 1, 1, 16 );
374     /* Update the position when the IM has changed */
375     CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
376              slider, setPosition( float, int, int ) );
377     /* And update the IM, when the position has changed */
378     CONNECT( slider, sliderDragged( float ),
379              THEMIM->getIM(), sliderUpdate( float ) );
380
381     /** Slower and faster Buttons **/
382     slowerButton = new QToolButton;
383     slowerButton->setAutoRaise( true );
384     slowerButton->setMaximumSize( QSize( 26, 20 ) );
385
386     BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
387     controlLayout->addWidget( slowerButton, 0, 0 );
388
389     fasterButton = new QToolButton;
390     fasterButton->setAutoRaise( true );
391     fasterButton->setMaximumSize( QSize( 26, 20 ) );
392
393     BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
394     controlLayout->addWidget( fasterButton, 0, 17 );
395
396     /* advanced Controls handling */
397     b_advancedVisible = b_advControls;
398
399     advControls = new AdvControlsWidget( p_intf );
400     controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
401     if( !b_advancedVisible ) advControls->hide();
402
403     /** Disc and Menus handling */
404     discFrame = new QWidget( this );
405
406     QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
407     discLayout->setSpacing( 0 );
408     discLayout->setMargin( 0 );
409
410     prevSectionButton = new QPushButton( discFrame );
411     setupSmallButton( prevSectionButton );
412     discLayout->addWidget( prevSectionButton );
413
414     menuButton = new QPushButton( discFrame );
415     setupSmallButton( menuButton );
416     discLayout->addWidget( menuButton );
417
418     nextSectionButton = new QPushButton( discFrame );
419     setupSmallButton( nextSectionButton );
420     discLayout->addWidget( nextSectionButton );
421
422     controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
423
424     BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
425     BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
426     BUTTON_SET_IMG( menuButton, "", previous.png, "" );
427
428     discFrame->hide();
429
430     /* Change the navigation button display when the IM navigation changes */
431     CONNECT( THEMIM->getIM(), navigationChanged( int ),
432              this, setNavigation( int ) );
433     /* Changes the IM navigation when triggered on the nav buttons */
434     CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
435              sectionPrev() );
436     CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
437              sectionNext() );
438     CONNECT( menuButton, clicked(), THEMIM->getIM(),
439              sectionMenu() );
440     /**
441      * Telextext QFrame
442      * TODO: Merge with upper menu in a StackLayout
443      **/
444 #ifdef ZVBI_COMPILED
445     telexFrame = new QWidget( this );
446     QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
447     telexLayout->setSpacing( 0 );
448     telexLayout->setMargin( 0 );
449
450     QToolButton *telexOn = new QToolButton;
451     telexOn->setText( qtr( "On" ) );
452     setupSmallButton( telexOn );
453     telexLayout->addWidget( telexOn );
454
455     QToolButton *telexTransparent = new QToolButton;
456     telexTransparent->setText( qtr( "Transparent" ) );
457     setupSmallButton( telexTransparent );
458     telexLayout->addWidget( telexTransparent );
459
460     QSpinBox *telexPage = new QSpinBox;
461     telexPage->setRange( 0, 999 );
462     telexPage->setValue( 100 );
463     telexPage->setAlignment( Qt::AlignRight );
464     telexLayout->addWidget( telexPage );
465
466     controlLayout->addWidget( telexFrame, 1, 10, 2, 3, Qt::AlignBottom );
467     telexFrame->hide();
468
469     CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
470              telexGotoPage( int ) );
471     CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
472              telexToggle( bool ) );
473     CONNECT( telexTransparent, clicked( bool ),
474              THEMIM->getIM(), telexSetTransparency( bool ) );
475     CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
476              telexFrame, setVisible( bool ) );
477 #endif
478
479     /** Play Buttons **/
480     QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
481     sizePolicy.setHorizontalStretch( 0 );
482     sizePolicy.setVerticalStretch( 0 );
483
484     /* Play */
485     playButton = new QPushButton;
486     playButton->setSizePolicy( sizePolicy );
487     playButton->setMaximumSize( QSize( 36, 36 ) );
488     playButton->setMinimumSize( QSize( 36, 36 ) );
489     playButton->setIconSize( QSize( 30, 30 ) );
490
491     controlLayout->addWidget( playButton, 2, 0, 2, 2 );
492
493     controlLayout->setColumnMinimumWidth( 2, 20 );
494     controlLayout->setColumnStretch( 2, 0 );
495
496     /** Prev + Stop + Next Block **/
497     QHBoxLayout *controlButLayout = new QHBoxLayout;
498     controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
499
500     /* Prev */
501     QPushButton *prevButton = new QPushButton;
502     prevButton->setSizePolicy( sizePolicy );
503     setupSmallButton( prevButton );
504
505     controlButLayout->addWidget( prevButton );
506
507     /* Stop */
508     QPushButton *stopButton = new QPushButton;
509     stopButton->setSizePolicy( sizePolicy );
510     setupSmallButton( stopButton );
511
512     controlButLayout->addWidget( stopButton );
513
514     /* next */
515     QPushButton *nextButton = new QPushButton;
516     nextButton->setSizePolicy( sizePolicy );
517     setupSmallButton( nextButton );
518
519     controlButLayout->addWidget( nextButton );
520
521     /* Add this block to the main layout */
522     controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
523
524     BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
525     BUTTON_SET_ACT_I( prevButton, "" , previous.png,
526                       qtr( "Previous" ), prev() );
527     BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
528     BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
529
530     controlLayout->setColumnMinimumWidth( 7, 20 );
531     controlLayout->setColumnStretch( 7, 0 );
532     controlLayout->setColumnStretch( 8, 0 );
533     controlLayout->setColumnStretch( 9, 0 );
534
535     /*
536      * Other first Line buttons
537      */
538     /** Fullscreen/Visualisation **/
539     fullscreenButton = new QPushButton( "F" );
540     BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
541     setupSmallButton( fullscreenButton );
542     controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
543
544     /** Playlist Button **/
545     playlistButton = new QPushButton;
546     setupSmallButton( playlistButton );
547     controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
548     BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
549     CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
550
551     /** extended Settings **/
552     QPushButton *extSettingsButton = new QPushButton( "F" );
553     BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
554             extSettings() );
555     setupSmallButton( extSettingsButton );
556     controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
557
558     controlLayout->setColumnStretch( 13, 0 );
559     controlLayout->setColumnMinimumWidth( 13, 24 );
560     controlLayout->setColumnStretch( 14, 5 );
561
562     /* Volume */
563     VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
564
565     volMuteLabel = new QLabel;
566     volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
567     volMuteLabel->setToolTip( qtr( "Mute" ) );
568     volMuteLabel->installEventFilter( hVolLabel );
569     controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
570
571     if( b_shiny )
572     {
573         volumeSlider = new SoundSlider( this,
574             config_GetInt( p_intf, "volume-step" ),
575             config_GetInt( p_intf, "qt-volume-complete" ) );
576     }
577     else
578     {
579         volumeSlider = new QSlider( this );
580         volumeSlider->setOrientation( Qt::Horizontal );
581     }
582     volumeSlider->setMaximumSize( QSize( 200, 40 ) );
583     volumeSlider->setMinimumSize( QSize( 106, 30 ) );
584     volumeSlider->setFocusPolicy( Qt::NoFocus );
585     controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
586
587     /* Set the volume from the config */
588     volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
589                               VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
590
591     /* Volume control connection */
592     CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
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::updateOnTimer()
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 = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
856             ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH );
857     }
858     else
859     {
860         rate = 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 }