1 /*****************************************************************************
2 * interface_widgets.cpp : Custom widgets for the main interface
3 ****************************************************************************
4 * Copyright ( C ) 2006 the VideoLAN team
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>
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.
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.
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 *****************************************************************************/
27 #include "dialogs_provider.hpp"
28 #include "components/interface_widgets.hpp"
29 #include "main_interface.hpp"
30 #include "input_manager.hpp"
32 #include "util/input_slider.hpp"
33 #include "util/customwidgets.hpp"
37 #include <QSpacerItem>
39 #include <QPushButton>
40 #include <QToolButton>
41 #include <QHBoxLayout>
44 #include <QResizeEvent>
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 );
55 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
57 vlc_mutex_init( p_intf, &lock );
59 hide(); setMinimumSize( 16, 16 );
61 // CONNECT( this, askResize( int, int ), this, SetSizing( int, int ) );
62 CONNECT( this, askVideoWidgetToShow(), this, show() );
63 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
66 VideoWidget::~VideoWidget()
68 vlc_mutex_lock( &lock );
71 if( !p_intf->psz_switch_intf )
73 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
74 vout_Control( p_vout, VOUT_REPARENT );
78 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
79 vout_Control( p_vout, VOUT_CLOSE );
82 vlc_mutex_unlock( &lock );
83 vlc_mutex_destroy( &lock );
86 QSize VideoWidget::sizeHint() const
92 * Request the video to avoid the conflicts
94 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
95 unsigned int *pi_width, unsigned int *pi_height )
97 emit askVideoWidgetToShow();
100 msg_Dbg( p_intf, "embedded video already in use" );
104 return ( void* )winId();
107 /* Set the Widget to the correct Size */
108 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
111 //updateGeometry(); // Needed for deinterlace
112 msg_Dbg( p_intf, "%i %i", sizeHint().height(), sizeHint().width() );
116 void VideoWidget::release( void *p_win )
122 /**********************************************************************
123 * Background Widget. Show a simple image background. Currently,
124 * it's a static cone.
125 **********************************************************************/
126 #define ICON_SIZE 128
127 #define MAX_BG_SIZE 400
128 #define MIN_BG_SIZE 64
130 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
131 QFrame( NULL ), p_intf( _p_i )
133 /* We should use that one to take the more size it can */
134 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding );
136 /* A dark background */
137 setAutoFillBackground( true );
139 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
140 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
143 /* A cone in the middle */
145 label->setScaledContents( true );
146 label->setMargin( 5 );
147 label->setMaximumHeight( MAX_BG_SIZE );
148 label->setMaximumWidth( MAX_BG_SIZE );
149 label->setMinimumHeight( MIN_BG_SIZE );
150 label->setMinimumWidth( MIN_BG_SIZE );
151 label->setPixmap( QPixmap( ":/vlc128.png" ) );
153 QHBoxLayout *backgroundLayout = new QHBoxLayout( this );
154 backgroundLayout->addWidget( label );
158 CONNECT( THEMIM, inputChanged( input_thread_t *), this, update( input_thread_t * ) );
161 BackgroundWidget::~BackgroundWidget()
166 void BackgroundWidget::update( input_thread_t *p_input )
168 if( !p_input || p_input->b_dead )
170 label->setPixmap( QPixmap( ":/vlc128.png" ) );
175 vlc_object_yield( p_input );
176 char *psz_arturl = input_item_GetArtURL( input_GetItem(p_input) );
177 vlc_object_release( p_input );
178 QString url = qfu( psz_arturl );
179 QString arturl = url.replace( "file://",QString("" ) );
180 if( arturl.isNull() )
181 label->setPixmap( QPixmap( ":/vlc128.png" ) );
184 label->setPixmap( QPixmap( arturl ) );
185 msg_Dbg( p_intf, "changing input b_need_update done %s", psz_arturl );
190 QSize BackgroundWidget::sizeHint() const
192 return label->size();
195 void BackgroundWidget::resizeEvent( QResizeEvent *e )
197 if( e->size().height() < MAX_BG_SIZE -1 )
199 label->setMaximumWidth( e->size().height() );
200 label->setMaximumHeight( e->size().width() );
204 label->setMaximumHeight( MAX_BG_SIZE );
205 label->setMaximumWidth( MAX_BG_SIZE );
209 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
211 QVLCMenu::PopupMenu( p_intf, true );
214 /**********************************************************************
215 * Visualization selector panel
216 **********************************************************************/
217 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
218 QFrame( NULL ), p_intf( _p_i )
220 QHBoxLayout *layout = new QHBoxLayout( this );
221 layout->setMargin( 0 );
222 QPushButton *prevButton = new QPushButton( "Prev" );
223 QPushButton *nextButton = new QPushButton( "Next" );
224 layout->addWidget( prevButton );
225 layout->addWidget( nextButton );
227 layout->addItem( new QSpacerItem( 40,20,
228 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
229 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
231 current = new QLabel( qtr( "None" ) );
232 layout->addWidget( current );
234 BUTTONACT( prevButton, prev() );
235 BUTTONACT( nextButton, next() );
238 setMaximumHeight( 35 );
241 VisualSelector::~VisualSelector()
245 void VisualSelector::prev()
247 char *psz_new = aout_VisualPrev( p_intf );
250 current->setText( qfu( psz_new ) );
255 void VisualSelector::next()
257 char *psz_new = aout_VisualNext( p_intf );
260 current->setText( qfu( psz_new ) );
265 /**********************************************************************
267 **********************************************************************/
269 #define setupSmallButton( aButton ){ \
270 aButton->setMaximumSize( QSize( 26, 26 ) ); \
271 aButton->setMinimumSize( QSize( 26, 26 ) ); \
272 aButton->setIconSize( QSize( 20, 20 ) ); }
274 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
275 QFrame( NULL ), p_intf( _p_i )
277 QHBoxLayout *advLayout = new QHBoxLayout( this );
278 advLayout->setMargin( 0 );
279 advLayout->setSpacing( 0 );
282 ABButton = new QPushButton( "AB" );
283 ABButton->setMaximumSize( QSize( 26, 26 ) );
284 ABButton->setIconSize( QSize( 20, 20 ) );
285 advLayout->addWidget( ABButton );
286 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
288 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
289 this, AtoBLoop( float, int, int ) );
291 frameButton = new QPushButton( "Fr" );
292 frameButton->setMaximumSize( QSize( 26, 26 ) );
293 frameButton->setIconSize( QSize( 20, 20 ) );
294 advLayout->addWidget( frameButton );
295 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
297 recordButton = new QPushButton( "R" );
298 recordButton->setMaximumSize( QSize( 26, 26 ) );
299 recordButton->setIconSize( QSize( 20, 20 ) );
300 advLayout->addWidget( recordButton );
301 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
302 qtr( "Record" ), record() );
304 /* Snapshot Button */
305 snapshotButton = new QPushButton( "S" );
306 snapshotButton->setMaximumSize( QSize( 26, 26 ) );
307 snapshotButton->setIconSize( QSize( 20, 20 ) );
308 advLayout->addWidget( snapshotButton );
309 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
312 AdvControlsWidget::~AdvControlsWidget()
315 void AdvControlsWidget::enableInput( bool enable )
317 ABButton->setEnabled( enable );
318 recordButton->setEnabled( enable );
321 void AdvControlsWidget::enableVideo( bool enable )
323 snapshotButton->setEnabled( enable );
324 frameButton->setEnabled( enable );
327 void AdvControlsWidget::snapshot()
329 vout_thread_t *p_vout =
330 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
331 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
334 /* Function called when the button is clicked() */
335 void AdvControlsWidget::fromAtoB()
339 timeA = var_GetTime( THEMIM->getInput(), "time" );
340 ABButton->setText( "A->..." );
345 timeB = var_GetTime( THEMIM->getInput(), "time" );
346 var_SetTime( THEMIM->getInput(), "time" , timeA );
347 ABButton->setText( "A<=>B" );
352 ABButton->setText( "AB" );
355 /* Function called regularly when in an AtoB loop */
356 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
360 if( i_time >= (int)(timeB/1000000) )
361 var_SetTime( THEMIM->getInput(), "time" , timeA );
365 /* FIXME Record function */
366 void AdvControlsWidget::record(){}
368 //FIXME Frame by frame function
369 void AdvControlsWidget::frame(){}
371 /*****************************
372 * DA Control Widget !
373 *****************************/
374 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
375 MainInterface *_p_mi,
378 QFrame( NULL ), p_intf( _p_i )
380 controlLayout = new QGridLayout( this );
381 controlLayout->setSpacing( 0 );
383 controlLayout->setContentsMargins( 9, 6, 9, 6 );
385 controlLayout->setMargin( 6 );
388 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
390 /** The main Slider **/
391 slider = new InputSlider( Qt::Horizontal, NULL );
392 controlLayout->addWidget( slider, 0, 1, 1, 16 );
393 /* Update the position when the IM has changed */
394 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
395 slider, setPosition( float, int, int ) );
396 /* And update the IM, when the position has changed */
397 CONNECT( slider, sliderDragged( float ),
398 THEMIM->getIM(), sliderUpdate( float ) );
400 /** Slower and faster Buttons **/
401 slowerButton = new QPushButton;
402 slowerButton->setFlat( true );
403 slowerButton->setMaximumSize( QSize( 26, 20 ) );
405 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
406 controlLayout->addWidget( slowerButton, 0, 0 );
408 fasterButton = new QPushButton;
409 fasterButton->setFlat( true );
410 fasterButton->setMaximumSize( QSize( 26, 20 ) );
412 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
413 controlLayout->addWidget( fasterButton, 0, 17 );
415 /* advanced Controls handling */
416 b_advancedVisible = b_advControls;
418 advControls = new AdvControlsWidget( p_intf );
419 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
420 if( !b_advancedVisible ) advControls->hide();
422 /** Disc and Menus handling */
423 discFrame = new QWidget( this );
425 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
426 discLayout->setSpacing( 0 );
427 discLayout->setMargin( 0 );
429 prevSectionButton = new QPushButton( discFrame );
430 setupSmallButton( prevSectionButton );
431 discLayout->addWidget( prevSectionButton );
433 menuButton = new QPushButton( discFrame );
434 setupSmallButton( menuButton );
435 discLayout->addWidget( menuButton );
437 nextSectionButton = new QPushButton( discFrame );
438 setupSmallButton( nextSectionButton );
439 discLayout->addWidget( nextSectionButton );
441 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
443 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
444 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
445 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
449 /* Change the navigation button display when the IM navigation changes */
450 CONNECT( THEMIM->getIM(), navigationChanged( int ),
451 this, setNavigation( int ) );
452 /* Changes the IM navigation when triggered on the nav buttons */
453 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
455 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
457 CONNECT( menuButton, clicked(), THEMIM->getIM(),
461 * Merge with upper menu in a StackLayout
463 telexFrame = new QWidget( this );
464 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
465 telexLayout->setSpacing( 0 );
466 telexLayout->setMargin( 0 );
468 QToolButton *telexOn = new QToolButton;
469 telexOn->setText( qtr( "On" ) );
470 setupSmallButton( telexOn );
471 telexLayout->addWidget( telexOn );
473 QToolButton *telexTransparent = new QToolButton;
474 telexTransparent->setText( qtr( "Transparent" ) );
475 setupSmallButton( telexTransparent );
476 telexLayout->addWidget( telexTransparent );
478 QSpinBox *telexPage = new QSpinBox;
479 telexPage->setRange( 0, 999 );
480 telexPage->setAlignment( Qt::AlignRight );
481 telexLayout->addWidget( telexPage );
483 controlLayout->addWidget( telexFrame, 1, 10, 2, 3, Qt::AlignBottom );
486 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
487 telexGotoPage( int ) );
488 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
489 telexToggle( bool ) );
490 CONNECT( telexTransparent, clicked( bool ),
491 THEMIM->getIM(), telexSetTransparency( bool ) );
492 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
493 telexFrame, setVisible( bool ) );
496 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
497 sizePolicy.setHorizontalStretch( 0 );
498 sizePolicy.setVerticalStretch( 0 );
501 playButton = new QPushButton;
502 playButton->setSizePolicy( sizePolicy );
503 playButton->setMaximumSize( QSize( 36, 36 ) );
504 playButton->setMinimumSize( QSize( 36, 36 ) );
505 playButton->setIconSize( QSize( 30, 30 ) );
507 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
509 controlLayout->setColumnMinimumWidth( 2, 20 );
510 controlLayout->setColumnStretch( 2, 0 );
512 /** Prev + Stop + Next Block **/
513 QHBoxLayout *controlButLayout = new QHBoxLayout;
514 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
517 QPushButton *prevButton = new QPushButton;
518 prevButton->setSizePolicy( sizePolicy );
519 setupSmallButton( prevButton );
521 controlButLayout->addWidget( prevButton );
524 QPushButton *stopButton = new QPushButton;
525 stopButton->setSizePolicy( sizePolicy );
526 setupSmallButton( stopButton );
528 controlButLayout->addWidget( stopButton );
531 QPushButton *nextButton = new QPushButton;
532 nextButton->setSizePolicy( sizePolicy );
533 setupSmallButton( nextButton );
535 controlButLayout->addWidget( nextButton );
537 /* Add this block to the main layout */
538 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
540 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
541 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
542 qtr( "Previous" ), prev() );
543 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
544 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
546 controlLayout->setColumnMinimumWidth( 7, 20 );
547 controlLayout->setColumnStretch( 7, 0 );
548 controlLayout->setColumnStretch( 8, 0 );
549 controlLayout->setColumnStretch( 9, 0 );
552 * Other first Line buttons
554 /** Fullscreen/Visualisation **/
555 fullscreenButton = new QPushButton( "F" );
556 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
557 setupSmallButton( fullscreenButton );
558 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
560 /** Playlist Button **/
561 playlistButton = new QPushButton;
562 setupSmallButton( playlistButton );
563 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
564 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
565 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
567 /** extended Settings **/
568 QPushButton *extSettingsButton = new QPushButton( "F" );
569 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
571 setupSmallButton( extSettingsButton );
572 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
574 controlLayout->setColumnStretch( 13, 0 );
575 controlLayout->setColumnMinimumWidth( 13, 24 );
576 controlLayout->setColumnStretch( 14, 5 );
579 VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
581 volMuteLabel = new QLabel;
582 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
583 volMuteLabel->setToolTip( qtr( "Mute" ) );
584 volMuteLabel->installEventFilter( hVolLabel );
585 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
589 volumeSlider = new SoundSlider( this,
590 config_GetInt( p_intf, "volume-step" ),
591 config_GetInt( p_intf, "qt-volume-complete" ) );
595 volumeSlider = new QSlider( this );
596 volumeSlider->setOrientation( Qt::Horizontal );
598 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
599 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
600 volumeSlider->setFocusPolicy( Qt::NoFocus );
601 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
603 /* Set the volume from the config */
604 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
605 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
607 /* Volume control connection */
608 //resize( QSize( 300, 60 ) );
609 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
610 msg_Dbg( p_intf, "controls size: %i - %i", size().width(), size().height() );
613 ControlsWidget::~ControlsWidget()
617 QSize ControlsWidget::sizeHint() const
619 return QSize( 300, 50 );
623 void ControlsWidget::stop()
628 void ControlsWidget::play()
630 if( THEPL->current.i_size == 0 )
632 /* The playlist is empty, open a file requester */
633 THEDP->openFileDialog();
637 THEMIM->togglePlayPause();
640 void ControlsWidget::prev()
645 void ControlsWidget::next()
650 void ControlsWidget::setNavigation( int navigation )
652 #define HELP_MENU N_( "Menu" )
653 #define HELP_PCH N_( "Previous chapter" )
654 #define HELP_NCH N_( "Next chapter" )
655 #define HELP_PTR N_( "Previous track" )
656 #define HELP_NTR N_( "Next track" )
658 // 1 = chapter, 2 = title, 0 = no
659 if( navigation == 0 )
662 } else if( navigation == 1 ) {
663 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
664 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
668 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
669 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
675 static bool b_my_volume;
676 void ControlsWidget::updateVolume( int i_sliderVolume )
680 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
681 aout_VolumeSet( p_intf, i_res );
683 if( i_sliderVolume == 0 )
684 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
685 else if( i_sliderVolume < VOLUME_MAX / 2 )
686 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
687 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
690 void ControlsWidget::updateOnTimer()
693 audio_volume_t i_volume;
694 aout_VolumeGet( p_intf, &i_volume );
695 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
696 int i_gauge = volumeSlider->value();
698 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
701 volumeSlider->setValue( i_volume );
705 /* Activate the interface buttons according to the presence of the input */
706 enableInput( THEMIM->getIM()->hasInput() );
707 //enableVideo( THEMIM->getIM()->hasVideo() );
711 void ControlsWidget::setStatus( int status )
713 if( status == PLAYING_S ) // Playing
714 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
716 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
721 * This functions toggle the fullscreen mode
722 * If there is no video, it should first activate Visualisations...
723 * This has also to be fixed in enableVideo()
725 void ControlsWidget::fullscreen()
727 vout_thread_t *p_vout =
728 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
731 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
732 vlc_object_release( p_vout );
736 void ControlsWidget::extSettings()
738 THEDP->extendedDialog();
741 void ControlsWidget::slower()
743 THEMIM->getIM()->slower();
746 void ControlsWidget::faster()
748 THEMIM->getIM()->faster();
751 void ControlsWidget::enableInput( bool enable )
753 slowerButton->setEnabled( enable );
754 slider->setEnabled( enable );
755 fasterButton->setEnabled( enable );
757 /* Advanced Buttons too */
758 advControls->enableInput( enable );
761 void ControlsWidget::enableVideo( bool enable )
763 // TODO Later make the fullscreenButton toggle Visualisation and so on.
764 fullscreenButton->setEnabled( enable );
766 /* Advanced Buttons too */
767 advControls->enableVideo( enable );
770 void ControlsWidget::toggleAdvanced()
772 if( !VISIBLE( advControls ) )
775 b_advancedVisible = true;
780 b_advancedVisible = false;
782 emit advancedControlsToggled( b_advancedVisible );
786 /**********************************************************************
787 * Speed control widget
788 **********************************************************************/
789 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
790 QFrame( NULL ), p_intf( _p_i )
792 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
793 sizePolicy.setHorizontalStretch( 0 );
794 sizePolicy.setVerticalStretch( 0 );
796 speedSlider = new QSlider;
797 speedSlider->setSizePolicy( sizePolicy );
798 speedSlider->setMaximumSize( QSize( 80, 200 ) );
799 speedSlider->setOrientation( Qt::Vertical );
800 speedSlider->setTickPosition( QSlider::TicksRight );
802 speedSlider->setRange( -100, 100 );
803 speedSlider->setSingleStep( 10 );
804 speedSlider->setPageStep( 20 );
805 speedSlider->setTickInterval( 20 );
807 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
809 normalSpeedButton = new QPushButton( "N" );
810 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
811 normalSpeedButton->setFlat( true );
812 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
814 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
816 QVBoxLayout *speedControlLayout = new QVBoxLayout;
817 speedControlLayout->addWidget(speedSlider);
818 speedControlLayout->addWidget(normalSpeedButton);
819 setLayout(speedControlLayout);
822 SpeedControlWidget::~SpeedControlWidget()
825 #define RATE_SLIDER_MAXIMUM 3.0
826 #define RATE_SLIDER_MINIMUM 0.3
827 #define RATE_SLIDER_LENGTH 100.0
829 void SpeedControlWidget::updateControls( int rate )
831 if( speedSlider->isSliderDown() )
833 //We don't want to change anything if the user is using the slider
838 double speed = INPUT_RATE_DEFAULT / (double)rate;
840 if( rate >= INPUT_RATE_DEFAULT )
842 if( speed < RATE_SLIDER_MINIMUM )
844 sliderValue = speedSlider->minimum();
848 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
849 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
854 if( speed > RATE_SLIDER_MAXIMUM )
856 sliderValue = speedSlider->maximum();
860 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
861 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
865 //Block signals to avoid feedback loop
866 speedSlider->blockSignals( true );
867 speedSlider->setValue( sliderValue );
868 speedSlider->blockSignals( false );
871 void SpeedControlWidget::updateRate( int sliderValue )
875 if( sliderValue < 0.0 )
877 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
878 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH );
882 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
883 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
886 THEMIM->getIM()->setRate(rate);
889 void SpeedControlWidget::resetRate()
891 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);