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 );
53 static int ItemChanged( vlc_object_t *, const char *,
54 vlc_value_t, vlc_value_t, void * );
56 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
58 vlc_mutex_init( p_intf, &lock );
61 CONNECT( this, askResize(), this, SetMinSize() );
62 CONNECT( this, askVideoToShow(), 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
91 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
92 unsigned int *pi_width, unsigned int *pi_height )
94 emit askVideoToShow();
97 msg_Dbg( p_intf, "embedded video already in use" );
102 return ( void* )winId();
105 void VideoWidget::SetMinSize()
107 setMinimumSize( 16, 16 );
110 void VideoWidget::release( void *p_win )
116 /**********************************************************************
117 * Background Widget. Show a simple image background. Currently,
118 * it's a static cone.
119 **********************************************************************/
120 #define ICON_SIZE 128
121 #define MAX_BG_SIZE 400
122 #define MIN_BG_SIZE 64
124 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
125 QFrame( NULL ), p_intf( _p_i )
127 /* We should use that one to take the more size it can */
128 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding );
130 /* A dark background */
131 setAutoFillBackground( true );
133 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
134 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
137 /* A cone in the middle */
139 label->setScaledContents( true );
140 label->setMargin( 5 );
141 label->setMaximumHeight( MAX_BG_SIZE );
142 label->setMaximumWidth( MAX_BG_SIZE );
143 label->setMinimumHeight( MIN_BG_SIZE );
144 label->setMinimumWidth( MIN_BG_SIZE );
145 label->setPixmap( QPixmap( ":/vlc128.png" ) );
147 QHBoxLayout *backgroundLayout = new QHBoxLayout( this );
148 backgroundLayout->addWidget( label );
153 b_need_update = VLC_FALSE;
154 var_AddCallback( THEPL, "item-change", ItemChanged, this );
155 ON_TIMEOUT( update() );
158 BackgroundWidget::~BackgroundWidget()
160 var_DelCallback( THEPL, "item-change", ItemChanged, this );
163 static int ItemChanged( vlc_object_t *p_this, const char *psz_var,
164 vlc_value_t oldval, vlc_value_t newval, void *param )
166 BackgroundWidget *p_d = (BackgroundWidget*)param;
167 p_d->b_need_update = VLC_TRUE;
171 void BackgroundWidget::update()
173 /* Timer runs at 150 ms, dont' update more than once every 750ms */
175 if( i_runs % 6 != 0 ) return;
177 /* Get Input and clear if non-existant */
178 input_thread_t *p_input =
179 MainInputManager::getInstance( p_intf )->getInput();
180 if( !p_input || p_input->b_dead )
182 label->setPixmap( QPixmap( ":/vlc128.png" ) );
189 vlc_object_yield( p_input );
190 char *psz_arturl = input_item_GetArtURL( input_GetItem(p_input) );
191 vlc_object_release( p_input );
192 QString url = qfu( psz_arturl );
193 QString arturl = url.replace( "file://",QString("" ) );
194 if( arturl.isNull() )
195 label->setPixmap( QPixmap( ":/vlc128.png" ) );
198 label->setPixmap( QPixmap( arturl ) );
199 msg_Dbg( p_intf, "changing input b_need_update done %s", psz_arturl );
203 b_need_update = false;
206 QSize BackgroundWidget::sizeHint() const
208 return label->size();
211 void BackgroundWidget::resizeEvent( QResizeEvent *e )
213 if( e->size().height() < MAX_BG_SIZE -1 )
215 label->setMaximumWidth( e->size().height() );
216 label->setMaximumHeight( e->size().width() );
220 label->setMaximumHeight( MAX_BG_SIZE );
221 label->setMaximumWidth( MAX_BG_SIZE );
225 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
227 QVLCMenu::PopupMenu( p_intf, true );
230 /**********************************************************************
231 * Visualization selector panel
232 **********************************************************************/
233 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
234 QFrame( NULL ), p_intf( _p_i )
236 QHBoxLayout *layout = new QHBoxLayout( this );
237 layout->setMargin( 0 );
238 QPushButton *prevButton = new QPushButton( "Prev" );
239 QPushButton *nextButton = new QPushButton( "Next" );
240 layout->addWidget( prevButton );
241 layout->addWidget( nextButton );
243 layout->addItem( new QSpacerItem( 40,20,
244 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
245 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
247 current = new QLabel( qtr( "None" ) );
248 layout->addWidget( current );
250 BUTTONACT( prevButton, prev() );
251 BUTTONACT( nextButton, next() );
254 setMaximumHeight( 35 );
257 VisualSelector::~VisualSelector()
261 void VisualSelector::prev()
263 char *psz_new = aout_VisualPrev( p_intf );
266 current->setText( qfu( psz_new ) );
271 void VisualSelector::next()
273 char *psz_new = aout_VisualNext( p_intf );
276 current->setText( qfu( psz_new ) );
281 /**********************************************************************
283 **********************************************************************/
285 #define setupSmallButton( aButton ){ \
286 aButton->setMaximumSize( QSize( 26, 26 ) ); \
287 aButton->setMinimumSize( QSize( 26, 26 ) ); \
288 aButton->setIconSize( QSize( 20, 20 ) ); }
290 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
291 QFrame( NULL ), p_intf( _p_i )
293 QHBoxLayout *advLayout = new QHBoxLayout( this );
294 advLayout->setMargin( 0 );
295 advLayout->setSpacing( 0 );
298 ABButton = new QPushButton( "AB" );
299 ABButton->setMaximumSize( QSize( 26, 26 ) );
300 ABButton->setIconSize( QSize( 20, 20 ) );
301 advLayout->addWidget( ABButton );
302 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
304 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
305 this, AtoBLoop( float, int, int ) );
307 frameButton = new QPushButton( "Fr" );
308 frameButton->setMaximumSize( QSize( 26, 26 ) );
309 frameButton->setIconSize( QSize( 20, 20 ) );
310 advLayout->addWidget( frameButton );
311 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
313 recordButton = new QPushButton( "R" );
314 recordButton->setMaximumSize( QSize( 26, 26 ) );
315 recordButton->setIconSize( QSize( 20, 20 ) );
316 advLayout->addWidget( recordButton );
317 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
318 qtr( "Record" ), record() );
320 /* Snapshot Button */
321 snapshotButton = new QPushButton( "S" );
322 snapshotButton->setMaximumSize( QSize( 26, 26 ) );
323 snapshotButton->setIconSize( QSize( 20, 20 ) );
324 advLayout->addWidget( snapshotButton );
325 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
328 AdvControlsWidget::~AdvControlsWidget()
331 void AdvControlsWidget::enableInput( bool enable )
333 ABButton->setEnabled( enable );
334 recordButton->setEnabled( enable );
337 void AdvControlsWidget::enableVideo( bool enable )
339 snapshotButton->setEnabled( enable );
340 frameButton->setEnabled( enable );
343 void AdvControlsWidget::snapshot()
345 vout_thread_t *p_vout =
346 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
347 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
350 /* Function called when the button is clicked() */
351 void AdvControlsWidget::fromAtoB()
355 timeA = var_GetTime( THEMIM->getInput(), "time" );
356 ABButton->setText( "A->..." );
361 timeB = var_GetTime( THEMIM->getInput(), "time" );
362 var_SetTime( THEMIM->getInput(), "time" , timeA );
363 ABButton->setText( "A<=>B" );
368 ABButton->setText( "AB" );
371 /* Function called regularly when in an AtoB loop */
372 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
376 if( i_time >= (int)(timeB/1000000) )
377 var_SetTime( THEMIM->getInput(), "time" , timeA );
381 /* FIXME Record function */
382 void AdvControlsWidget::record(){}
384 //FIXME Frame by frame function
385 void AdvControlsWidget::frame(){}
387 /*****************************
388 * DA Control Widget !
389 *****************************/
390 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
391 MainInterface *_p_mi,
394 QFrame( NULL ), p_intf( _p_i )
396 controlLayout = new QGridLayout( this );
397 controlLayout->setSpacing( 0 );
398 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Minimum );
400 /** The main Slider **/
401 slider = new InputSlider( Qt::Horizontal, NULL );
402 controlLayout->addWidget( slider, 0, 1, 1, 16 );
403 /* Update the position when the IM has changed */
404 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
405 slider, setPosition( float, int, int ) );
406 /* And update the IM, when the position has changed */
407 CONNECT( slider, sliderDragged( float ),
408 THEMIM->getIM(), sliderUpdate( float ) );
410 /** Slower and faster Buttons **/
411 slowerButton = new QPushButton;
412 slowerButton->setFlat( true );
413 slowerButton->setMaximumSize( QSize( 26, 20 ) );
415 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
416 controlLayout->addWidget( slowerButton, 0, 0 );
418 fasterButton = new QPushButton;
419 fasterButton->setFlat( true );
420 fasterButton->setMaximumSize( QSize( 26, 20 ) );
422 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
423 controlLayout->addWidget( fasterButton, 0, 17 );
425 /* advanced Controls handling */
426 b_advancedVisible = b_advControls;
428 advControls = new AdvControlsWidget( p_intf );
429 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
430 if( !b_advancedVisible ) advControls->hide();
432 /** Disc and Menus handling */
433 discFrame = new QFrame( this );
435 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
436 discLayout->setSpacing( 0 );
437 discLayout->setMargin( 0 );
439 prevSectionButton = new QPushButton( discFrame );
440 setupSmallButton( prevSectionButton );
441 discLayout->addWidget( prevSectionButton );
443 menuButton = new QPushButton( discFrame );
444 setupSmallButton( menuButton );
445 discLayout->addWidget( menuButton );
447 nextSectionButton = new QPushButton( discFrame );
448 setupSmallButton( nextSectionButton );
449 discLayout->addWidget( nextSectionButton );
451 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
453 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
454 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
455 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
459 /* Change the navigation button display when the IM navigation changes */
460 CONNECT( THEMIM->getIM(), navigationChanged( int ),
461 this, setNavigation( int ) );
462 /* Changes the IM navigation when triggered on the nav buttons */
463 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
465 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
467 CONNECT( menuButton, clicked(), THEMIM->getIM(),
472 * Merge with upper menu in a StackLayout
476 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
477 sizePolicy.setHorizontalStretch( 0 );
478 sizePolicy.setVerticalStretch( 0 );
481 playButton = new QPushButton;
482 playButton->setSizePolicy( sizePolicy );
483 playButton->setMaximumSize( QSize( 38, 38 ) );
484 playButton->setMinimumSize( QSize( 45, 45 ) );
485 playButton->setIconSize( QSize( 30, 30 ) );
487 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
489 controlLayout->setColumnMinimumWidth( 2, 20 );
490 controlLayout->setColumnStretch( 2, 0 );
492 /** Prev + Stop + Next Block **/
493 QHBoxLayout *controlButLayout = new QHBoxLayout;
494 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
497 QPushButton *prevButton = new QPushButton;
498 prevButton->setSizePolicy( sizePolicy );
499 setupSmallButton( prevButton );
501 controlButLayout->addWidget( prevButton );
504 QPushButton *stopButton = new QPushButton;
505 stopButton->setSizePolicy( sizePolicy );
506 setupSmallButton( stopButton );
508 controlButLayout->addWidget( stopButton );
511 QPushButton *nextButton = new QPushButton;
512 nextButton->setSizePolicy( sizePolicy );
513 setupSmallButton( nextButton );
515 controlButLayout->addWidget( nextButton );
517 /* Add this block to the main layout */
518 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
520 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
521 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
522 qtr( "Previous" ), prev() );
523 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
524 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
526 controlLayout->setColumnStretch( 7 , 2 );
529 * Other first Line buttons
531 /** Fullscreen/Visualisation **/
532 fullscreenButton = new QPushButton( "F" );
533 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
534 setupSmallButton( fullscreenButton );
535 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
537 /** Playlist Button **/
538 playlistButton = new QPushButton;
539 setupSmallButton( playlistButton );
540 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
541 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
542 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
544 /** extended Settings **/
545 QPushButton *extSettingsButton = new QPushButton( "F" );
546 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
548 setupSmallButton( extSettingsButton );
549 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
551 controlLayout->setColumnStretch( 14, 5 );
554 VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
556 volMuteLabel = new QLabel;
557 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
558 volMuteLabel->setToolTip( qtr( "Mute" ) );
559 volMuteLabel->installEventFilter( hVolLabel );
560 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
564 volumeSlider = new SoundSlider( this,
565 config_GetInt( p_intf, "volume-step" ),
566 config_GetInt( p_intf, "qt-volume-complete" ) );
570 volumeSlider = new QSlider( this );
571 volumeSlider->setOrientation( Qt::Horizontal );
573 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
574 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
575 volumeSlider->setFocusPolicy( Qt::NoFocus );
576 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
578 /* Set the volume from the config */
579 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
580 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
582 /* Volume control connection */
583 resize( QSize( 400, 60 ) );
584 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
585 msg_Dbg( p_intf, "controls size: %i - %i", size().width(), size().height() );
588 ControlsWidget::~ControlsWidget()
593 QSize ControlsWidget::sizeHint() const
595 return QSize( 300, 50 );
599 void ControlsWidget::stop()
604 void ControlsWidget::play()
606 if( THEPL->current.i_size == 0 )
608 /* The playlist is empty, open a file requester */
609 THEDP->openFileDialog();
613 THEMIM->togglePlayPause();
616 void ControlsWidget::prev()
621 void ControlsWidget::next()
626 void ControlsWidget::setNavigation( int navigation )
628 #define HELP_MENU N_( "Menu" )
629 #define HELP_PCH N_( "Previous chapter" )
630 #define HELP_NCH N_( "Next chapter" )
631 #define HELP_PTR N_( "Previous track" )
632 #define HELP_NTR N_( "Next track" )
634 // 1 = chapter, 2 = title, 0 = no
635 if( navigation == 0 )
638 } else if( navigation == 1 ) {
639 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
640 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
644 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
645 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
651 static bool b_my_volume;
652 void ControlsWidget::updateVolume( int i_sliderVolume )
656 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
657 aout_VolumeSet( p_intf, i_res );
659 if( i_sliderVolume == 0 )
660 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
661 else if( i_sliderVolume < VOLUME_MAX / 2 )
662 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
663 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
666 void ControlsWidget::updateOnTimer()
669 audio_volume_t i_volume;
670 aout_VolumeGet( p_intf, &i_volume );
671 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
672 int i_gauge = volumeSlider->value();
674 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
677 volumeSlider->setValue( i_volume );
681 /* Activate the interface buttons according to the presence of the input */
682 enableInput( THEMIM->getIM()->hasInput() );
683 //enableVideo( THEMIM->getIM()->hasVideo() );
687 void ControlsWidget::setStatus( int status )
689 if( status == PLAYING_S ) // Playing
690 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
692 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
697 * This functions toggle the fullscreen mode
698 * If there is no video, it should first activate Visualisations...
699 * This has also to be fixed in enableVideo()
701 void ControlsWidget::fullscreen()
703 vout_thread_t *p_vout =
704 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
707 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
708 vlc_object_release( p_vout );
712 void ControlsWidget::extSettings()
714 THEDP->extendedDialog();
717 void ControlsWidget::slower()
719 THEMIM->getIM()->slower();
722 void ControlsWidget::faster()
724 THEMIM->getIM()->faster();
727 void ControlsWidget::enableInput( bool enable )
729 slowerButton->setEnabled( enable );
730 slider->setEnabled( enable );
731 fasterButton->setEnabled( enable );
733 /* Advanced Buttons too */
734 advControls->enableInput( enable );
737 void ControlsWidget::enableVideo( bool enable )
739 // TODO Later make the fullscreenButton toggle Visualisation and so on.
740 fullscreenButton->setEnabled( enable );
742 /* Advanced Buttons too */
743 advControls->enableVideo( enable );
746 void ControlsWidget::toggleAdvanced()
748 if( !VISIBLE( advControls ) )
751 b_advancedVisible = true;
756 b_advancedVisible = false;
758 emit advancedControlsToggled( b_advancedVisible );
762 /**********************************************************************
763 * Speed control widget
764 **********************************************************************/
765 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
766 QFrame( NULL ), p_intf( _p_i )
768 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
769 sizePolicy.setHorizontalStretch( 0 );
770 sizePolicy.setVerticalStretch( 0 );
772 speedSlider = new QSlider;
773 speedSlider->setSizePolicy( sizePolicy );
774 speedSlider->setMaximumSize( QSize( 80, 200 ) );
775 speedSlider->setOrientation( Qt::Vertical );
776 speedSlider->setTickPosition( QSlider::TicksRight );
778 speedSlider->setRange( -100, 100 );
779 speedSlider->setSingleStep( 10 );
780 speedSlider->setPageStep( 20 );
781 speedSlider->setTickInterval( 20 );
783 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
785 normalSpeedButton = new QPushButton( "N" );
786 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
787 normalSpeedButton->setFlat( true );
788 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
790 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
792 QVBoxLayout *speedControlLayout = new QVBoxLayout;
793 speedControlLayout->addWidget(speedSlider);
794 speedControlLayout->addWidget(normalSpeedButton);
795 setLayout(speedControlLayout);
798 SpeedControlWidget::~SpeedControlWidget()
801 #define RATE_SLIDER_MAXIMUM 3.0
802 #define RATE_SLIDER_MINIMUM 0.3
803 #define RATE_SLIDER_LENGTH 100.0
805 void SpeedControlWidget::updateControls( int rate )
807 if( speedSlider->isSliderDown() )
809 //We don't want to change anything if the user is using the slider
814 double speed = INPUT_RATE_DEFAULT / (double)rate;
816 if( rate >= INPUT_RATE_DEFAULT )
818 if( speed < RATE_SLIDER_MINIMUM )
820 sliderValue = speedSlider->minimum();
824 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
825 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
830 if( speed > RATE_SLIDER_MAXIMUM )
832 sliderValue = speedSlider->maximum();
836 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
837 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
841 //Block signals to avoid feedback loop
842 speedSlider->blockSignals( true );
843 speedSlider->setValue( sliderValue );
844 speedSlider->blockSignals( false );
847 void SpeedControlWidget::updateRate( int sliderValue )
851 if( sliderValue < 0.0 )
853 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
854 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH );
858 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
859 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
862 THEMIM->getIM()->setRate(rate);
865 void SpeedControlWidget::resetRate()
867 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);