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