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