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 <QHBoxLayout>
43 #include <QResizeEvent>
45 /**********************************************************************
46 * Video Widget. A simple frame on which video is drawn
47 * This class handles resize issues
48 **********************************************************************/
49 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
50 unsigned int *, unsigned int * );
51 static void DoRelease( intf_thread_t *, void * );
52 static int DoControl( intf_thread_t *, void *, int, va_list );
54 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
56 vlc_mutex_init( p_intf, &lock );
58 hide(); setMinimumSize( 16, 16 );
60 // CONNECT( this, askResize( int, int ), this, SetSizing( int, int ) );
61 CONNECT( this, askVideoWidgetToShow(), this, show() );
62 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
65 VideoWidget::~VideoWidget()
67 vlc_mutex_lock( &lock );
70 if( !p_intf->psz_switch_intf )
72 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
73 vout_Control( p_vout, VOUT_REPARENT );
77 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
78 vout_Control( p_vout, VOUT_CLOSE );
81 vlc_mutex_unlock( &lock );
82 vlc_mutex_destroy( &lock );
85 QSize VideoWidget::sizeHint() const
91 * Request the video to avoid the conflicts
93 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
94 unsigned int *pi_width, unsigned int *pi_height )
96 emit askVideoWidgetToShow();
99 msg_Dbg( p_intf, "embedded video already in use" );
103 return ( void* )winId();
106 /* Set the Widget to the correct Size */
107 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
110 //updateGeometry(); // Needed for deinterlace
111 msg_Dbg( p_intf, "%i %i", sizeHint().height(), sizeHint().width() );
115 void VideoWidget::release( void *p_win )
121 /**********************************************************************
122 * Background Widget. Show a simple image background. Currently,
123 * it's a static cone.
124 **********************************************************************/
125 #define ICON_SIZE 128
126 #define MAX_BG_SIZE 400
127 #define MIN_BG_SIZE 64
129 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
130 QFrame( NULL ), p_intf( _p_i )
132 /* We should use that one to take the more size it can */
133 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding );
135 /* A dark background */
136 setAutoFillBackground( true );
138 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
139 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
142 /* A cone in the middle */
144 label->setScaledContents( true );
145 label->setMargin( 5 );
146 label->setMaximumHeight( MAX_BG_SIZE );
147 label->setMaximumWidth( MAX_BG_SIZE );
148 label->setMinimumHeight( MIN_BG_SIZE );
149 label->setMinimumWidth( MIN_BG_SIZE );
150 label->setPixmap( QPixmap( ":/vlc128.png" ) );
152 QHBoxLayout *backgroundLayout = new QHBoxLayout( this );
153 backgroundLayout->addWidget( label );
157 CONNECT( THEMIM, inputChanged( input_thread_t *), this, update( input_thread_t * ) );
160 BackgroundWidget::~BackgroundWidget()
165 void BackgroundWidget::update( input_thread_t *p_input )
167 if( !p_input || p_input->b_dead )
169 label->setPixmap( QPixmap( ":/vlc128.png" ) );
174 vlc_object_yield( p_input );
175 char *psz_arturl = input_item_GetArtURL( input_GetItem(p_input) );
176 vlc_object_release( p_input );
177 QString url = qfu( psz_arturl );
178 QString arturl = url.replace( "file://",QString("" ) );
179 if( arturl.isNull() )
180 label->setPixmap( QPixmap( ":/vlc128.png" ) );
183 label->setPixmap( QPixmap( arturl ) );
184 msg_Dbg( p_intf, "changing input b_need_update done %s", psz_arturl );
189 QSize BackgroundWidget::sizeHint() const
191 return label->size();
194 void BackgroundWidget::resizeEvent( QResizeEvent *e )
196 if( e->size().height() < MAX_BG_SIZE -1 )
198 label->setMaximumWidth( e->size().height() );
199 label->setMaximumHeight( e->size().width() );
203 label->setMaximumHeight( MAX_BG_SIZE );
204 label->setMaximumWidth( MAX_BG_SIZE );
208 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
210 QVLCMenu::PopupMenu( p_intf, true );
213 /**********************************************************************
214 * Visualization selector panel
215 **********************************************************************/
216 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
217 QFrame( NULL ), p_intf( _p_i )
219 QHBoxLayout *layout = new QHBoxLayout( this );
220 layout->setMargin( 0 );
221 QPushButton *prevButton = new QPushButton( "Prev" );
222 QPushButton *nextButton = new QPushButton( "Next" );
223 layout->addWidget( prevButton );
224 layout->addWidget( nextButton );
226 layout->addItem( new QSpacerItem( 40,20,
227 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
228 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
230 current = new QLabel( qtr( "None" ) );
231 layout->addWidget( current );
233 BUTTONACT( prevButton, prev() );
234 BUTTONACT( nextButton, next() );
237 setMaximumHeight( 35 );
240 VisualSelector::~VisualSelector()
244 void VisualSelector::prev()
246 char *psz_new = aout_VisualPrev( p_intf );
249 current->setText( qfu( psz_new ) );
254 void VisualSelector::next()
256 char *psz_new = aout_VisualNext( p_intf );
259 current->setText( qfu( psz_new ) );
264 /**********************************************************************
266 **********************************************************************/
268 #define setupSmallButton( aButton ){ \
269 aButton->setMaximumSize( QSize( 26, 26 ) ); \
270 aButton->setMinimumSize( QSize( 26, 26 ) ); \
271 aButton->setIconSize( QSize( 20, 20 ) ); }
273 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
274 QFrame( NULL ), p_intf( _p_i )
276 QHBoxLayout *advLayout = new QHBoxLayout( this );
277 advLayout->setMargin( 0 );
278 advLayout->setSpacing( 0 );
281 ABButton = new QPushButton( "AB" );
282 ABButton->setMaximumSize( QSize( 26, 26 ) );
283 ABButton->setIconSize( QSize( 20, 20 ) );
284 advLayout->addWidget( ABButton );
285 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
287 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
288 this, AtoBLoop( float, int, int ) );
290 frameButton = new QPushButton( "Fr" );
291 frameButton->setMaximumSize( QSize( 26, 26 ) );
292 frameButton->setIconSize( QSize( 20, 20 ) );
293 advLayout->addWidget( frameButton );
294 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
296 recordButton = new QPushButton( "R" );
297 recordButton->setMaximumSize( QSize( 26, 26 ) );
298 recordButton->setIconSize( QSize( 20, 20 ) );
299 advLayout->addWidget( recordButton );
300 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
301 qtr( "Record" ), record() );
303 /* Snapshot Button */
304 snapshotButton = new QPushButton( "S" );
305 snapshotButton->setMaximumSize( QSize( 26, 26 ) );
306 snapshotButton->setIconSize( QSize( 20, 20 ) );
307 advLayout->addWidget( snapshotButton );
308 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
311 AdvControlsWidget::~AdvControlsWidget()
314 void AdvControlsWidget::enableInput( bool enable )
316 ABButton->setEnabled( enable );
317 recordButton->setEnabled( enable );
320 void AdvControlsWidget::enableVideo( bool enable )
322 snapshotButton->setEnabled( enable );
323 frameButton->setEnabled( enable );
326 void AdvControlsWidget::snapshot()
328 vout_thread_t *p_vout =
329 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
330 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
333 /* Function called when the button is clicked() */
334 void AdvControlsWidget::fromAtoB()
338 timeA = var_GetTime( THEMIM->getInput(), "time" );
339 ABButton->setText( "A->..." );
344 timeB = var_GetTime( THEMIM->getInput(), "time" );
345 var_SetTime( THEMIM->getInput(), "time" , timeA );
346 ABButton->setText( "A<=>B" );
351 ABButton->setText( "AB" );
354 /* Function called regularly when in an AtoB loop */
355 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
359 if( i_time >= (int)(timeB/1000000) )
360 var_SetTime( THEMIM->getInput(), "time" , timeA );
364 /* FIXME Record function */
365 void AdvControlsWidget::record(){}
367 //FIXME Frame by frame function
368 void AdvControlsWidget::frame(){}
370 /*****************************
371 * DA Control Widget !
372 *****************************/
373 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
374 MainInterface *_p_mi,
377 QFrame( NULL ), p_intf( _p_i )
379 controlLayout = new QGridLayout( this );
380 controlLayout->setSpacing( 0 );
382 controlLayout->setContentsMargins( 9, 6, 9, 6 );
384 controlLayout->setMargin( 6 );
387 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
389 /** The main Slider **/
390 slider = new InputSlider( Qt::Horizontal, NULL );
391 controlLayout->addWidget( slider, 0, 1, 1, 16 );
392 /* Update the position when the IM has changed */
393 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
394 slider, setPosition( float, int, int ) );
395 /* And update the IM, when the position has changed */
396 CONNECT( slider, sliderDragged( float ),
397 THEMIM->getIM(), sliderUpdate( float ) );
399 /** Slower and faster Buttons **/
400 slowerButton = new QPushButton;
401 slowerButton->setFlat( true );
402 slowerButton->setMaximumSize( QSize( 26, 20 ) );
404 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
405 controlLayout->addWidget( slowerButton, 0, 0 );
407 fasterButton = new QPushButton;
408 fasterButton->setFlat( true );
409 fasterButton->setMaximumSize( QSize( 26, 20 ) );
411 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
412 controlLayout->addWidget( fasterButton, 0, 17 );
414 /* advanced Controls handling */
415 b_advancedVisible = b_advControls;
417 advControls = new AdvControlsWidget( p_intf );
418 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
419 if( !b_advancedVisible ) advControls->hide();
421 /** Disc and Menus handling */
422 discFrame = new QFrame( this );
424 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
425 discLayout->setSpacing( 0 );
426 discLayout->setMargin( 0 );
428 prevSectionButton = new QPushButton( discFrame );
429 setupSmallButton( prevSectionButton );
430 discLayout->addWidget( prevSectionButton );
432 menuButton = new QPushButton( discFrame );
433 setupSmallButton( menuButton );
434 discLayout->addWidget( menuButton );
436 nextSectionButton = new QPushButton( discFrame );
437 setupSmallButton( nextSectionButton );
438 discLayout->addWidget( nextSectionButton );
440 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
442 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
443 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
444 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
448 /* Change the navigation button display when the IM navigation changes */
449 CONNECT( THEMIM->getIM(), navigationChanged( int ),
450 this, setNavigation( int ) );
451 /* Changes the IM navigation when triggered on the nav buttons */
452 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
454 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
456 CONNECT( menuButton, clicked(), THEMIM->getIM(),
461 * Merge with upper menu in a StackLayout
465 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
466 sizePolicy.setHorizontalStretch( 0 );
467 sizePolicy.setVerticalStretch( 0 );
470 playButton = new QPushButton;
471 playButton->setSizePolicy( sizePolicy );
472 playButton->setMaximumSize( QSize( 36, 36 ) );
473 playButton->setMinimumSize( QSize( 36, 36 ) );
474 playButton->setIconSize( QSize( 30, 30 ) );
476 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
478 controlLayout->setColumnMinimumWidth( 2, 20 );
479 controlLayout->setColumnStretch( 2, 0 );
481 /** Prev + Stop + Next Block **/
482 QHBoxLayout *controlButLayout = new QHBoxLayout;
483 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
486 QPushButton *prevButton = new QPushButton;
487 prevButton->setSizePolicy( sizePolicy );
488 setupSmallButton( prevButton );
490 controlButLayout->addWidget( prevButton );
493 QPushButton *stopButton = new QPushButton;
494 stopButton->setSizePolicy( sizePolicy );
495 setupSmallButton( stopButton );
497 controlButLayout->addWidget( stopButton );
500 QPushButton *nextButton = new QPushButton;
501 nextButton->setSizePolicy( sizePolicy );
502 setupSmallButton( nextButton );
504 controlButLayout->addWidget( nextButton );
506 /* Add this block to the main layout */
507 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
509 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
510 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
511 qtr( "Previous" ), prev() );
512 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
513 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
515 controlLayout->setColumnMinimumWidth( 7, 20 );
516 controlLayout->setColumnStretch( 7, 0 );
517 controlLayout->setColumnStretch( 8, 0 );
518 controlLayout->setColumnStretch( 9, 0 );
521 * Other first Line buttons
523 /** Fullscreen/Visualisation **/
524 fullscreenButton = new QPushButton( "F" );
525 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
526 setupSmallButton( fullscreenButton );
527 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
529 /** Playlist Button **/
530 playlistButton = new QPushButton;
531 setupSmallButton( playlistButton );
532 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
533 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
534 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
536 /** extended Settings **/
537 QPushButton *extSettingsButton = new QPushButton( "F" );
538 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
540 setupSmallButton( extSettingsButton );
541 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
543 controlLayout->setColumnStretch( 13, 0 );
544 controlLayout->setColumnMinimumWidth( 13, 24 );
545 controlLayout->setColumnStretch( 14, 5 );
548 VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
550 volMuteLabel = new QLabel;
551 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
552 volMuteLabel->setToolTip( qtr( "Mute" ) );
553 volMuteLabel->installEventFilter( hVolLabel );
554 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
558 volumeSlider = new SoundSlider( this,
559 config_GetInt( p_intf, "volume-step" ),
560 config_GetInt( p_intf, "qt-volume-complete" ) );
564 volumeSlider = new QSlider( this );
565 volumeSlider->setOrientation( Qt::Horizontal );
567 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
568 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
569 volumeSlider->setFocusPolicy( Qt::NoFocus );
570 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
572 /* Set the volume from the config */
573 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
574 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
576 /* Volume control connection */
577 //resize( QSize( 300, 60 ) );
578 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
579 msg_Dbg( p_intf, "controls size: %i - %i", size().width(), size().height() );
582 ControlsWidget::~ControlsWidget()
586 QSize ControlsWidget::sizeHint() const
588 return QSize( 300, 50 );
592 void ControlsWidget::stop()
597 void ControlsWidget::play()
599 if( THEPL->current.i_size == 0 )
601 /* The playlist is empty, open a file requester */
602 THEDP->openFileDialog();
606 THEMIM->togglePlayPause();
609 void ControlsWidget::prev()
614 void ControlsWidget::next()
619 void ControlsWidget::setNavigation( int navigation )
621 #define HELP_MENU N_( "Menu" )
622 #define HELP_PCH N_( "Previous chapter" )
623 #define HELP_NCH N_( "Next chapter" )
624 #define HELP_PTR N_( "Previous track" )
625 #define HELP_NTR N_( "Next track" )
627 // 1 = chapter, 2 = title, 0 = no
628 if( navigation == 0 )
631 } else if( navigation == 1 ) {
632 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
633 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
637 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
638 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
644 static bool b_my_volume;
645 void ControlsWidget::updateVolume( int i_sliderVolume )
649 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
650 aout_VolumeSet( p_intf, i_res );
652 if( i_sliderVolume == 0 )
653 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
654 else if( i_sliderVolume < VOLUME_MAX / 2 )
655 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
656 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
659 void ControlsWidget::updateOnTimer()
662 audio_volume_t i_volume;
663 aout_VolumeGet( p_intf, &i_volume );
664 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
665 int i_gauge = volumeSlider->value();
667 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
670 volumeSlider->setValue( i_volume );
674 /* Activate the interface buttons according to the presence of the input */
675 enableInput( THEMIM->getIM()->hasInput() );
676 //enableVideo( THEMIM->getIM()->hasVideo() );
680 void ControlsWidget::setStatus( int status )
682 if( status == PLAYING_S ) // Playing
683 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
685 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
690 * This functions toggle the fullscreen mode
691 * If there is no video, it should first activate Visualisations...
692 * This has also to be fixed in enableVideo()
694 void ControlsWidget::fullscreen()
696 vout_thread_t *p_vout =
697 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
700 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
701 vlc_object_release( p_vout );
705 void ControlsWidget::extSettings()
707 THEDP->extendedDialog();
710 void ControlsWidget::slower()
712 THEMIM->getIM()->slower();
715 void ControlsWidget::faster()
717 THEMIM->getIM()->faster();
720 void ControlsWidget::enableInput( bool enable )
722 slowerButton->setEnabled( enable );
723 slider->setEnabled( enable );
724 fasterButton->setEnabled( enable );
726 /* Advanced Buttons too */
727 advControls->enableInput( enable );
730 void ControlsWidget::enableVideo( bool enable )
732 // TODO Later make the fullscreenButton toggle Visualisation and so on.
733 fullscreenButton->setEnabled( enable );
735 /* Advanced Buttons too */
736 advControls->enableVideo( enable );
739 void ControlsWidget::toggleAdvanced()
741 if( !VISIBLE( advControls ) )
744 b_advancedVisible = true;
749 b_advancedVisible = false;
751 emit advancedControlsToggled( b_advancedVisible );
755 /**********************************************************************
756 * Speed control widget
757 **********************************************************************/
758 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
759 QFrame( NULL ), p_intf( _p_i )
761 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
762 sizePolicy.setHorizontalStretch( 0 );
763 sizePolicy.setVerticalStretch( 0 );
765 speedSlider = new QSlider;
766 speedSlider->setSizePolicy( sizePolicy );
767 speedSlider->setMaximumSize( QSize( 80, 200 ) );
768 speedSlider->setOrientation( Qt::Vertical );
769 speedSlider->setTickPosition( QSlider::TicksRight );
771 speedSlider->setRange( -100, 100 );
772 speedSlider->setSingleStep( 10 );
773 speedSlider->setPageStep( 20 );
774 speedSlider->setTickInterval( 20 );
776 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
778 normalSpeedButton = new QPushButton( "N" );
779 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
780 normalSpeedButton->setFlat( true );
781 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
783 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
785 QVBoxLayout *speedControlLayout = new QVBoxLayout;
786 speedControlLayout->addWidget(speedSlider);
787 speedControlLayout->addWidget(normalSpeedButton);
788 setLayout(speedControlLayout);
791 SpeedControlWidget::~SpeedControlWidget()
794 #define RATE_SLIDER_MAXIMUM 3.0
795 #define RATE_SLIDER_MINIMUM 0.3
796 #define RATE_SLIDER_LENGTH 100.0
798 void SpeedControlWidget::updateControls( int rate )
800 if( speedSlider->isSliderDown() )
802 //We don't want to change anything if the user is using the slider
807 double speed = INPUT_RATE_DEFAULT / (double)rate;
809 if( rate >= INPUT_RATE_DEFAULT )
811 if( speed < RATE_SLIDER_MINIMUM )
813 sliderValue = speedSlider->minimum();
817 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
818 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
823 if( speed > RATE_SLIDER_MAXIMUM )
825 sliderValue = speedSlider->maximum();
829 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
830 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
834 //Block signals to avoid feedback loop
835 speedSlider->blockSignals( true );
836 speedSlider->setValue( sliderValue );
837 speedSlider->blockSignals( false );
840 void SpeedControlWidget::updateRate( int sliderValue )
844 if( sliderValue < 0.0 )
846 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
847 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH );
851 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
852 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
855 THEMIM->getIM()->setRate(rate);
858 void SpeedControlWidget::resetRate()
860 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);