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 );
59 CONNECT( this, askResize(), this, SetMinSize() );
60 CONNECT( this, askVideoToShow(), this, show() );
61 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
64 VideoWidget::~VideoWidget()
66 vlc_mutex_lock( &lock );
69 if( !p_intf->psz_switch_intf )
71 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
72 vout_Control( p_vout, VOUT_REPARENT );
76 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
77 vout_Control( p_vout, VOUT_CLOSE );
80 vlc_mutex_unlock( &lock );
81 vlc_mutex_destroy( &lock );
84 QSize VideoWidget::sizeHint() const
89 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
90 unsigned int *pi_width, unsigned int *pi_height )
92 emit askVideoToShow();
95 msg_Dbg( p_intf, "embedded video already in use" );
100 return ( void* )winId();
103 void VideoWidget::SetMinSize()
105 setMinimumSize( 16, 16 );
108 void VideoWidget::release( void *p_win )
114 /**********************************************************************
115 * Background Widget. Show a simple image background. Currently,
116 * it's a static cone.
117 **********************************************************************/
118 #define ICON_SIZE 128
119 #define MAX_BG_SIZE 400
120 #define MIN_BG_SIZE 64
122 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
123 QFrame( NULL ), p_intf( _p_i )
125 /* We should use that one to take the more size it can */
126 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding );
128 /* A dark background */
129 setAutoFillBackground( true );
131 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
132 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
135 /* A cone in the middle */
137 label->setScaledContents( true );
138 label->setMargin( 5 );
139 label->setMaximumHeight( MAX_BG_SIZE );
140 label->setMaximumWidth( MAX_BG_SIZE );
141 label->setMinimumHeight( MIN_BG_SIZE );
142 label->setMinimumWidth( MIN_BG_SIZE );
143 label->setPixmap( QPixmap( ":/vlc128.png" ) );
145 QHBoxLayout *backgroundLayout = new QHBoxLayout( this );
146 backgroundLayout->addWidget( label );
150 CONNECT( THEMIM, inputChanged( input_thread_t *), this, update( input_thread_t * ) );
153 BackgroundWidget::~BackgroundWidget()
158 void BackgroundWidget::update( input_thread_t *p_input )
160 if( !p_input || p_input->b_dead )
162 label->setPixmap( QPixmap( ":/vlc128.png" ) );
167 vlc_object_yield( p_input );
168 char *psz_arturl = input_item_GetArtURL( input_GetItem(p_input) );
169 vlc_object_release( p_input );
170 QString url = qfu( psz_arturl );
171 QString arturl = url.replace( "file://",QString("" ) );
172 if( arturl.isNull() )
173 label->setPixmap( QPixmap( ":/vlc128.png" ) );
176 label->setPixmap( QPixmap( arturl ) );
177 msg_Dbg( p_intf, "changing input b_need_update done %s", psz_arturl );
182 QSize BackgroundWidget::sizeHint() const
184 return label->size();
187 void BackgroundWidget::resizeEvent( QResizeEvent *e )
189 if( e->size().height() < MAX_BG_SIZE -1 )
191 label->setMaximumWidth( e->size().height() );
192 label->setMaximumHeight( e->size().width() );
196 label->setMaximumHeight( MAX_BG_SIZE );
197 label->setMaximumWidth( MAX_BG_SIZE );
201 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
203 QVLCMenu::PopupMenu( p_intf, true );
206 /**********************************************************************
207 * Visualization selector panel
208 **********************************************************************/
209 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
210 QFrame( NULL ), p_intf( _p_i )
212 QHBoxLayout *layout = new QHBoxLayout( this );
213 layout->setMargin( 0 );
214 QPushButton *prevButton = new QPushButton( "Prev" );
215 QPushButton *nextButton = new QPushButton( "Next" );
216 layout->addWidget( prevButton );
217 layout->addWidget( nextButton );
219 layout->addItem( new QSpacerItem( 40,20,
220 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
221 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
223 current = new QLabel( qtr( "None" ) );
224 layout->addWidget( current );
226 BUTTONACT( prevButton, prev() );
227 BUTTONACT( nextButton, next() );
230 setMaximumHeight( 35 );
233 VisualSelector::~VisualSelector()
237 void VisualSelector::prev()
239 char *psz_new = aout_VisualPrev( p_intf );
242 current->setText( qfu( psz_new ) );
247 void VisualSelector::next()
249 char *psz_new = aout_VisualNext( p_intf );
252 current->setText( qfu( psz_new ) );
257 /**********************************************************************
259 **********************************************************************/
261 #define setupSmallButton( aButton ){ \
262 aButton->setMaximumSize( QSize( 26, 26 ) ); \
263 aButton->setMinimumSize( QSize( 26, 26 ) ); \
264 aButton->setIconSize( QSize( 20, 20 ) ); }
266 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
267 QFrame( NULL ), p_intf( _p_i )
269 QHBoxLayout *advLayout = new QHBoxLayout( this );
270 advLayout->setMargin( 0 );
271 advLayout->setSpacing( 0 );
274 ABButton = new QPushButton( "AB" );
275 ABButton->setMaximumSize( QSize( 26, 26 ) );
276 ABButton->setIconSize( QSize( 20, 20 ) );
277 advLayout->addWidget( ABButton );
278 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
280 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
281 this, AtoBLoop( float, int, int ) );
283 frameButton = new QPushButton( "Fr" );
284 frameButton->setMaximumSize( QSize( 26, 26 ) );
285 frameButton->setIconSize( QSize( 20, 20 ) );
286 advLayout->addWidget( frameButton );
287 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
289 recordButton = new QPushButton( "R" );
290 recordButton->setMaximumSize( QSize( 26, 26 ) );
291 recordButton->setIconSize( QSize( 20, 20 ) );
292 advLayout->addWidget( recordButton );
293 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
294 qtr( "Record" ), record() );
296 /* Snapshot Button */
297 snapshotButton = new QPushButton( "S" );
298 snapshotButton->setMaximumSize( QSize( 26, 26 ) );
299 snapshotButton->setIconSize( QSize( 20, 20 ) );
300 advLayout->addWidget( snapshotButton );
301 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
304 AdvControlsWidget::~AdvControlsWidget()
307 void AdvControlsWidget::enableInput( bool enable )
309 ABButton->setEnabled( enable );
310 recordButton->setEnabled( enable );
313 void AdvControlsWidget::enableVideo( bool enable )
315 snapshotButton->setEnabled( enable );
316 frameButton->setEnabled( enable );
319 void AdvControlsWidget::snapshot()
321 vout_thread_t *p_vout =
322 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
323 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
326 /* Function called when the button is clicked() */
327 void AdvControlsWidget::fromAtoB()
331 timeA = var_GetTime( THEMIM->getInput(), "time" );
332 ABButton->setText( "A->..." );
337 timeB = var_GetTime( THEMIM->getInput(), "time" );
338 var_SetTime( THEMIM->getInput(), "time" , timeA );
339 ABButton->setText( "A<=>B" );
344 ABButton->setText( "AB" );
347 /* Function called regularly when in an AtoB loop */
348 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
352 if( i_time >= (int)(timeB/1000000) )
353 var_SetTime( THEMIM->getInput(), "time" , timeA );
357 /* FIXME Record function */
358 void AdvControlsWidget::record(){}
360 //FIXME Frame by frame function
361 void AdvControlsWidget::frame(){}
363 /*****************************
364 * DA Control Widget !
365 *****************************/
366 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
367 MainInterface *_p_mi,
370 QFrame( NULL ), p_intf( _p_i )
372 controlLayout = new QGridLayout( this );
373 controlLayout->setSpacing( 0 );
374 //controlLayout->setMargin( 0 );
376 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
378 /** The main Slider **/
379 slider = new InputSlider( Qt::Horizontal, NULL );
380 controlLayout->addWidget( slider, 0, 1, 1, 16 );
381 /* Update the position when the IM has changed */
382 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
383 slider, setPosition( float, int, int ) );
384 /* And update the IM, when the position has changed */
385 CONNECT( slider, sliderDragged( float ),
386 THEMIM->getIM(), sliderUpdate( float ) );
388 /** Slower and faster Buttons **/
389 slowerButton = new QPushButton;
390 slowerButton->setFlat( true );
391 slowerButton->setMaximumSize( QSize( 26, 20 ) );
393 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
394 controlLayout->addWidget( slowerButton, 0, 0 );
396 fasterButton = new QPushButton;
397 fasterButton->setFlat( true );
398 fasterButton->setMaximumSize( QSize( 26, 20 ) );
400 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
401 controlLayout->addWidget( fasterButton, 0, 17 );
403 /* advanced Controls handling */
404 b_advancedVisible = b_advControls;
406 advControls = new AdvControlsWidget( p_intf );
407 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
408 if( !b_advancedVisible ) advControls->hide();
410 /** Disc and Menus handling */
411 discFrame = new QFrame( this );
413 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
414 discLayout->setSpacing( 0 );
415 discLayout->setMargin( 0 );
417 prevSectionButton = new QPushButton( discFrame );
418 setupSmallButton( prevSectionButton );
419 discLayout->addWidget( prevSectionButton );
421 menuButton = new QPushButton( discFrame );
422 setupSmallButton( menuButton );
423 discLayout->addWidget( menuButton );
425 nextSectionButton = new QPushButton( discFrame );
426 setupSmallButton( nextSectionButton );
427 discLayout->addWidget( nextSectionButton );
429 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
431 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
432 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
433 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
437 /* Change the navigation button display when the IM navigation changes */
438 CONNECT( THEMIM->getIM(), navigationChanged( int ),
439 this, setNavigation( int ) );
440 /* Changes the IM navigation when triggered on the nav buttons */
441 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
443 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
445 CONNECT( menuButton, clicked(), THEMIM->getIM(),
450 * Merge with upper menu in a StackLayout
454 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
455 sizePolicy.setHorizontalStretch( 0 );
456 sizePolicy.setVerticalStretch( 0 );
459 playButton = new QPushButton;
460 playButton->setSizePolicy( sizePolicy );
461 playButton->setMaximumSize( QSize( 36, 36 ) );
462 playButton->setMinimumSize( QSize( 36, 36 ) );
463 playButton->setIconSize( QSize( 30, 30 ) );
465 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
467 controlLayout->setColumnMinimumWidth( 2, 20 );
468 controlLayout->setColumnStretch( 2, 0 );
470 /** Prev + Stop + Next Block **/
471 QHBoxLayout *controlButLayout = new QHBoxLayout;
472 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
475 QPushButton *prevButton = new QPushButton;
476 prevButton->setSizePolicy( sizePolicy );
477 setupSmallButton( prevButton );
479 controlButLayout->addWidget( prevButton );
482 QPushButton *stopButton = new QPushButton;
483 stopButton->setSizePolicy( sizePolicy );
484 setupSmallButton( stopButton );
486 controlButLayout->addWidget( stopButton );
489 QPushButton *nextButton = new QPushButton;
490 nextButton->setSizePolicy( sizePolicy );
491 setupSmallButton( nextButton );
493 controlButLayout->addWidget( nextButton );
495 /* Add this block to the main layout */
496 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
498 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
499 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
500 qtr( "Previous" ), prev() );
501 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
502 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
504 controlLayout->setColumnMinimumWidth( 7, 20 );
505 controlLayout->setColumnStretch( 7, 0 );
506 controlLayout->setColumnStretch( 8, 0 );
507 controlLayout->setColumnStretch( 9, 0 );
509 * Other first Line buttons
511 /** Fullscreen/Visualisation **/
512 fullscreenButton = new QPushButton( "F" );
513 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
514 setupSmallButton( fullscreenButton );
515 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
517 /** Playlist Button **/
518 playlistButton = new QPushButton;
519 setupSmallButton( playlistButton );
520 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
521 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
522 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
524 /** extended Settings **/
525 QPushButton *extSettingsButton = new QPushButton( "F" );
526 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
528 setupSmallButton( extSettingsButton );
529 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
531 controlLayout->setColumnStretch( 13, 0 );
532 controlLayout->setColumnStretch( 14, 5 );
535 VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
537 volMuteLabel = new QLabel;
538 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
539 volMuteLabel->setToolTip( qtr( "Mute" ) );
540 volMuteLabel->installEventFilter( hVolLabel );
541 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
545 volumeSlider = new SoundSlider( this,
546 config_GetInt( p_intf, "volume-step" ),
547 config_GetInt( p_intf, "qt-volume-complete" ) );
551 volumeSlider = new QSlider( this );
552 volumeSlider->setOrientation( Qt::Horizontal );
554 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
555 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
556 volumeSlider->setFocusPolicy( Qt::NoFocus );
557 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
559 /* Set the volume from the config */
560 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
561 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
563 /* Volume control connection */
564 resize( QSize( 400, 60 ) );
565 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
566 msg_Dbg( p_intf, "controls size: %i - %i", size().width(), size().height() );
569 ControlsWidget::~ControlsWidget()
573 QSize ControlsWidget::sizeHint() const
575 return QSize( 300, 50 );
579 void ControlsWidget::stop()
584 void ControlsWidget::play()
586 if( THEPL->current.i_size == 0 )
588 /* The playlist is empty, open a file requester */
589 THEDP->openFileDialog();
593 THEMIM->togglePlayPause();
596 void ControlsWidget::prev()
601 void ControlsWidget::next()
606 void ControlsWidget::setNavigation( int navigation )
608 #define HELP_MENU N_( "Menu" )
609 #define HELP_PCH N_( "Previous chapter" )
610 #define HELP_NCH N_( "Next chapter" )
611 #define HELP_PTR N_( "Previous track" )
612 #define HELP_NTR N_( "Next track" )
614 // 1 = chapter, 2 = title, 0 = no
615 if( navigation == 0 )
618 } else if( navigation == 1 ) {
619 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
620 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
624 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
625 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
631 static bool b_my_volume;
632 void ControlsWidget::updateVolume( int i_sliderVolume )
636 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
637 aout_VolumeSet( p_intf, i_res );
639 if( i_sliderVolume == 0 )
640 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
641 else if( i_sliderVolume < VOLUME_MAX / 2 )
642 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
643 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
646 void ControlsWidget::updateOnTimer()
649 audio_volume_t i_volume;
650 aout_VolumeGet( p_intf, &i_volume );
651 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
652 int i_gauge = volumeSlider->value();
654 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
657 volumeSlider->setValue( i_volume );
661 /* Activate the interface buttons according to the presence of the input */
662 enableInput( THEMIM->getIM()->hasInput() );
663 //enableVideo( THEMIM->getIM()->hasVideo() );
667 void ControlsWidget::setStatus( int status )
669 if( status == PLAYING_S ) // Playing
670 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
672 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
677 * This functions toggle the fullscreen mode
678 * If there is no video, it should first activate Visualisations...
679 * This has also to be fixed in enableVideo()
681 void ControlsWidget::fullscreen()
683 vout_thread_t *p_vout =
684 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
687 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
688 vlc_object_release( p_vout );
692 void ControlsWidget::extSettings()
694 THEDP->extendedDialog();
697 void ControlsWidget::slower()
699 THEMIM->getIM()->slower();
702 void ControlsWidget::faster()
704 THEMIM->getIM()->faster();
707 void ControlsWidget::enableInput( bool enable )
709 slowerButton->setEnabled( enable );
710 slider->setEnabled( enable );
711 fasterButton->setEnabled( enable );
713 /* Advanced Buttons too */
714 advControls->enableInput( enable );
717 void ControlsWidget::enableVideo( bool enable )
719 // TODO Later make the fullscreenButton toggle Visualisation and so on.
720 fullscreenButton->setEnabled( enable );
722 /* Advanced Buttons too */
723 advControls->enableVideo( enable );
726 void ControlsWidget::toggleAdvanced()
728 if( !VISIBLE( advControls ) )
731 b_advancedVisible = true;
736 b_advancedVisible = false;
738 emit advancedControlsToggled( b_advancedVisible );
742 /**********************************************************************
743 * Speed control widget
744 **********************************************************************/
745 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
746 QFrame( NULL ), p_intf( _p_i )
748 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
749 sizePolicy.setHorizontalStretch( 0 );
750 sizePolicy.setVerticalStretch( 0 );
752 speedSlider = new QSlider;
753 speedSlider->setSizePolicy( sizePolicy );
754 speedSlider->setMaximumSize( QSize( 80, 200 ) );
755 speedSlider->setOrientation( Qt::Vertical );
756 speedSlider->setTickPosition( QSlider::TicksRight );
758 speedSlider->setRange( -100, 100 );
759 speedSlider->setSingleStep( 10 );
760 speedSlider->setPageStep( 20 );
761 speedSlider->setTickInterval( 20 );
763 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
765 normalSpeedButton = new QPushButton( "N" );
766 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
767 normalSpeedButton->setFlat( true );
768 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
770 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
772 QVBoxLayout *speedControlLayout = new QVBoxLayout;
773 speedControlLayout->addWidget(speedSlider);
774 speedControlLayout->addWidget(normalSpeedButton);
775 setLayout(speedControlLayout);
778 SpeedControlWidget::~SpeedControlWidget()
781 #define RATE_SLIDER_MAXIMUM 3.0
782 #define RATE_SLIDER_MINIMUM 0.3
783 #define RATE_SLIDER_LENGTH 100.0
785 void SpeedControlWidget::updateControls( int rate )
787 if( speedSlider->isSliderDown() )
789 //We don't want to change anything if the user is using the slider
794 double speed = INPUT_RATE_DEFAULT / (double)rate;
796 if( rate >= INPUT_RATE_DEFAULT )
798 if( speed < RATE_SLIDER_MINIMUM )
800 sliderValue = speedSlider->minimum();
804 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
805 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
810 if( speed > RATE_SLIDER_MAXIMUM )
812 sliderValue = speedSlider->maximum();
816 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
817 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
821 //Block signals to avoid feedback loop
822 speedSlider->blockSignals( true );
823 speedSlider->setValue( sliderValue );
824 speedSlider->blockSignals( false );
827 void SpeedControlWidget::updateRate( int sliderValue )
831 if( sliderValue < 0.0 )
833 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
834 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH );
838 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
839 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
842 THEMIM->getIM()->setRate(rate);
845 void SpeedControlWidget::resetRate()
847 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);