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