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