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 );
510 * Other first Line buttons
512 /** Fullscreen/Visualisation **/
513 fullscreenButton = new QPushButton( "F" );
514 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
515 setupSmallButton( fullscreenButton );
516 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
518 /** Playlist Button **/
519 playlistButton = new QPushButton;
520 setupSmallButton( playlistButton );
521 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
522 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
523 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
525 /** extended Settings **/
526 QPushButton *extSettingsButton = new QPushButton( "F" );
527 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
529 setupSmallButton( extSettingsButton );
530 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
532 controlLayout->setColumnStretch( 13, 0 );
533 controlLayout->setColumnMinimumWidth( 13, 24 );
534 controlLayout->setColumnStretch( 14, 5 );
537 VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
539 volMuteLabel = new QLabel;
540 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
541 volMuteLabel->setToolTip( qtr( "Mute" ) );
542 volMuteLabel->installEventFilter( hVolLabel );
543 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
547 volumeSlider = new SoundSlider( this,
548 config_GetInt( p_intf, "volume-step" ),
549 config_GetInt( p_intf, "qt-volume-complete" ) );
553 volumeSlider = new QSlider( this );
554 volumeSlider->setOrientation( Qt::Horizontal );
556 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
557 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
558 volumeSlider->setFocusPolicy( Qt::NoFocus );
559 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
561 /* Set the volume from the config */
562 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
563 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
565 /* Volume control connection */
566 resize( QSize( 400, 60 ) );
567 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
568 msg_Dbg( p_intf, "controls size: %i - %i", size().width(), size().height() );
571 ControlsWidget::~ControlsWidget()
575 QSize ControlsWidget::sizeHint() const
577 return QSize( 300, 50 );
581 void ControlsWidget::stop()
586 void ControlsWidget::play()
588 if( THEPL->current.i_size == 0 )
590 /* The playlist is empty, open a file requester */
591 THEDP->openFileDialog();
595 THEMIM->togglePlayPause();
598 void ControlsWidget::prev()
603 void ControlsWidget::next()
608 void ControlsWidget::setNavigation( int navigation )
610 #define HELP_MENU N_( "Menu" )
611 #define HELP_PCH N_( "Previous chapter" )
612 #define HELP_NCH N_( "Next chapter" )
613 #define HELP_PTR N_( "Previous track" )
614 #define HELP_NTR N_( "Next track" )
616 // 1 = chapter, 2 = title, 0 = no
617 if( navigation == 0 )
620 } else if( navigation == 1 ) {
621 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
622 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
626 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
627 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
633 static bool b_my_volume;
634 void ControlsWidget::updateVolume( int i_sliderVolume )
638 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
639 aout_VolumeSet( p_intf, i_res );
641 if( i_sliderVolume == 0 )
642 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
643 else if( i_sliderVolume < VOLUME_MAX / 2 )
644 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
645 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
648 void ControlsWidget::updateOnTimer()
651 audio_volume_t i_volume;
652 aout_VolumeGet( p_intf, &i_volume );
653 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
654 int i_gauge = volumeSlider->value();
656 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
659 volumeSlider->setValue( i_volume );
663 /* Activate the interface buttons according to the presence of the input */
664 enableInput( THEMIM->getIM()->hasInput() );
665 //enableVideo( THEMIM->getIM()->hasVideo() );
669 void ControlsWidget::setStatus( int status )
671 if( status == PLAYING_S ) // Playing
672 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
674 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
679 * This functions toggle the fullscreen mode
680 * If there is no video, it should first activate Visualisations...
681 * This has also to be fixed in enableVideo()
683 void ControlsWidget::fullscreen()
685 vout_thread_t *p_vout =
686 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
689 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
690 vlc_object_release( p_vout );
694 void ControlsWidget::extSettings()
696 THEDP->extendedDialog();
699 void ControlsWidget::slower()
701 THEMIM->getIM()->slower();
704 void ControlsWidget::faster()
706 THEMIM->getIM()->faster();
709 void ControlsWidget::enableInput( bool enable )
711 slowerButton->setEnabled( enable );
712 slider->setEnabled( enable );
713 fasterButton->setEnabled( enable );
715 /* Advanced Buttons too */
716 advControls->enableInput( enable );
719 void ControlsWidget::enableVideo( bool enable )
721 // TODO Later make the fullscreenButton toggle Visualisation and so on.
722 fullscreenButton->setEnabled( enable );
724 /* Advanced Buttons too */
725 advControls->enableVideo( enable );
728 void ControlsWidget::toggleAdvanced()
730 if( !VISIBLE( advControls ) )
733 b_advancedVisible = true;
738 b_advancedVisible = false;
740 emit advancedControlsToggled( b_advancedVisible );
744 /**********************************************************************
745 * Speed control widget
746 **********************************************************************/
747 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
748 QFrame( NULL ), p_intf( _p_i )
750 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
751 sizePolicy.setHorizontalStretch( 0 );
752 sizePolicy.setVerticalStretch( 0 );
754 speedSlider = new QSlider;
755 speedSlider->setSizePolicy( sizePolicy );
756 speedSlider->setMaximumSize( QSize( 80, 200 ) );
757 speedSlider->setOrientation( Qt::Vertical );
758 speedSlider->setTickPosition( QSlider::TicksRight );
760 speedSlider->setRange( -100, 100 );
761 speedSlider->setSingleStep( 10 );
762 speedSlider->setPageStep( 20 );
763 speedSlider->setTickInterval( 20 );
765 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
767 normalSpeedButton = new QPushButton( "N" );
768 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
769 normalSpeedButton->setFlat( true );
770 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
772 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
774 QVBoxLayout *speedControlLayout = new QVBoxLayout;
775 speedControlLayout->addWidget(speedSlider);
776 speedControlLayout->addWidget(normalSpeedButton);
777 setLayout(speedControlLayout);
780 SpeedControlWidget::~SpeedControlWidget()
783 #define RATE_SLIDER_MAXIMUM 3.0
784 #define RATE_SLIDER_MINIMUM 0.3
785 #define RATE_SLIDER_LENGTH 100.0
787 void SpeedControlWidget::updateControls( int rate )
789 if( speedSlider->isSliderDown() )
791 //We don't want to change anything if the user is using the slider
796 double speed = INPUT_RATE_DEFAULT / (double)rate;
798 if( rate >= INPUT_RATE_DEFAULT )
800 if( speed < RATE_SLIDER_MINIMUM )
802 sliderValue = speedSlider->minimum();
806 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
807 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
812 if( speed > RATE_SLIDER_MAXIMUM )
814 sliderValue = speedSlider->maximum();
818 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
819 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
823 //Block signals to avoid feedback loop
824 speedSlider->blockSignals( true );
825 speedSlider->setValue( sliderValue );
826 speedSlider->blockSignals( false );
829 void SpeedControlWidget::updateRate( int sliderValue )
833 if( sliderValue < 0.0 )
835 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
836 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH );
840 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
841 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
844 THEMIM->getIM()->setRate(rate);
847 void SpeedControlWidget::resetRate()
849 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);