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>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * ( at your option ) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 #include "dialogs_provider.hpp"
27 #include "components/interface_widgets.hpp"
28 #include "main_interface.hpp"
29 #include "input_manager.hpp"
31 #include "util/input_slider.hpp"
32 #include "util/customwidgets.hpp"
36 #include <QSpacerItem>
38 #include <QPushButton>
39 #include <QHBoxLayout>
42 #include <QResizeEvent>
45 #define MAX_BG_SIZE 300
47 /**********************************************************************
48 * Video Widget. A simple frame on which video is drawn
49 * This class handles resize issues
50 **********************************************************************/
51 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
52 unsigned int *, unsigned int * );
53 static void DoRelease( intf_thread_t *, void * );
54 static int DoControl( intf_thread_t *, void *, int, va_list );
56 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
58 vlc_mutex_init( p_intf, &lock );
60 CONNECT( this, askResize(), this, SetMinSize() );
61 CONNECT( this, askVideoToShow(), 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
90 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
91 unsigned int *pi_width, unsigned int *pi_height )
93 emit askVideoToShow();
96 msg_Dbg( p_intf, "embedded video already in use" );
101 return ( void* )winId();
104 void VideoWidget::SetMinSize()
106 setMinimumSize( 16, 16 );
109 void VideoWidget::release( void *p_win )
113 /**********************************************************************
114 * Background Widget. Show a simple image background. Currently,
115 * it's a static cone.
116 **********************************************************************/
117 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
118 QFrame( NULL ), p_intf( _p_i )
121 setAutoFillBackground( true );
123 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
124 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
128 label->setMaximumHeight( ICON_SIZE );
129 label->setMaximumWidth( ICON_SIZE );
130 label->setScaledContents( true );
131 label->setPixmap( QPixmap( ":/vlc128.png" ) );
132 backgroundLayout = new QHBoxLayout;
133 backgroundLayout->addWidget( label );
134 setLayout( backgroundLayout );
137 BackgroundWidget::~BackgroundWidget()
139 backgroundLayout->takeAt( 0 );
140 delete backgroundLayout;
143 void BackgroundWidget::setArt( QString url )
146 label->setPixmap( QPixmap( ":/vlc128.png" ) );
148 label->setPixmap( QPixmap( url ) );
151 QSize BackgroundWidget::sizeHint() const
156 void BackgroundWidget::resizeEvent( QResizeEvent *e )
158 if( e->size().height() < ICON_SIZE -1 )
159 label->setMaximumWidth( e->size().height() );
161 label->setMaximumWidth( ICON_SIZE );
164 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
166 QVLCMenu::PopupMenu( p_intf, true );
168 /**********************************************************************
169 * Visualization selector panel
170 **********************************************************************/
171 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
172 QFrame( NULL ), p_intf( _p_i )
174 QHBoxLayout *layout = new QHBoxLayout( this );
175 layout->setMargin( 0 );
176 QPushButton *prevButton = new QPushButton( "Prev" );
177 QPushButton *nextButton = new QPushButton( "Next" );
178 layout->addWidget( prevButton );
179 layout->addWidget( nextButton );
181 layout->addItem( new QSpacerItem( 40,20,
182 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
183 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
185 current = new QLabel( qtr( "None" ) );
186 layout->addWidget( current );
188 BUTTONACT( prevButton, prev() );
189 BUTTONACT( nextButton, next() );
192 setMaximumHeight( 35 );
195 VisualSelector::~VisualSelector()
199 void VisualSelector::prev()
201 char *psz_new = aout_VisualPrev( p_intf );
204 current->setText( qfu( psz_new ) );
209 void VisualSelector::next()
211 char *psz_new = aout_VisualNext( p_intf );
214 current->setText( qfu( psz_new ) );
219 /**********************************************************************
221 **********************************************************************/
223 #define setupSmallButton( aButton ){ \
224 aButton->setMaximumSize( QSize( 26, 26 ) ); \
225 aButton->setMinimumSize( QSize( 26, 26 ) ); \
226 aButton->setIconSize( QSize( 20, 20 ) ); }
228 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
229 QFrame( NULL ), p_intf( _p_i )
231 QHBoxLayout *advLayout = new QHBoxLayout( this );
232 advLayout->setMargin( 0 );
233 advLayout->setSpacing( 0 );
235 /* FIXME A to B function */
236 ABButton = new QPushButton( "AB" );
237 ABButton->setMaximumSize( QSize( 26, 26 ) );
238 ABButton->setIconSize( QSize( 20, 20 ) );
239 advLayout->addWidget( ABButton );
240 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
243 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
244 this, AtoBLoop( float, int, int ) );
246 //FIXME Frame by frame function
247 frameButton = new QPushButton( "Fr" );
248 frameButton->setMaximumSize( QSize( 26, 26 ) );
249 frameButton->setIconSize( QSize( 20, 20 ) );
250 advLayout->addWidget( frameButton );
251 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
253 /* FIXME Record function */
254 recordButton = new QPushButton( "R" );
255 recordButton->setMaximumSize( QSize( 26, 26 ) );
256 recordButton->setIconSize( QSize( 20, 20 ) );
257 advLayout->addWidget( recordButton );
258 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
259 qtr( "Record" ), record() );
261 snapshotButton = new QPushButton( "S" );
262 snapshotButton->setMaximumSize( QSize( 26, 26 ) );
263 snapshotButton->setIconSize( QSize( 20, 20 ) );
264 advLayout->addWidget( snapshotButton );
265 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
269 AdvControlsWidget::~AdvControlsWidget()
273 void AdvControlsWidget::enableInput( bool enable )
275 ABButton->setEnabled( enable );
276 recordButton->setEnabled( enable );
278 void AdvControlsWidget::enableVideo( bool enable )
280 snapshotButton->setEnabled( enable );
281 frameButton->setEnabled( enable );
284 void AdvControlsWidget::snapshot()
286 vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
287 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
290 void AdvControlsWidget::frame()
294 void AdvControlsWidget::fromAtoB()
298 timeA = var_GetTime( THEMIM->getInput(), "time" );
299 ABButton->setText( "A->..." );
304 timeB = var_GetTime( THEMIM->getInput(), "time" );
305 var_SetTime( THEMIM->getInput(), "time" , timeA );
306 ABButton->setText( "A<=>B" );
311 ABButton->setText( "AB" );
314 void AdvControlsWidget::record(){}
316 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
320 if( i_time >= (int)(timeB/1000000) )
321 var_SetTime( THEMIM->getInput(), "time" , timeA );
325 /*****************************
326 * DA Control Widget !
327 *****************************/
328 ControlsWidget::ControlsWidget( intf_thread_t *_p_i, bool b_advControls ) :
329 QFrame( NULL ), p_intf( _p_i )
331 controlLayout = new QGridLayout( this );
332 controlLayout->setSpacing( 0 );
333 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
335 /** The main Slider **/
336 slider = new InputSlider( Qt::Horizontal, NULL );
337 controlLayout->addWidget( slider, 0, 1, 1, 16 );
338 /* Update the position when the IM has changed */
339 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
340 slider, setPosition( float,int, int ) );
341 /* And update the IM, when the position has changed */
342 CONNECT( slider, sliderDragged( float ),
343 THEMIM->getIM(), sliderUpdate( float ) );
345 /** Slower and faster Buttons **/
346 slowerButton = new QPushButton;
347 slowerButton->setFlat( true );
348 slowerButton->setMaximumSize( QSize( 26, 20 ) );
350 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
351 controlLayout->addWidget( slowerButton, 0, 0 );
353 fasterButton = new QPushButton;
354 fasterButton->setFlat( true );
355 fasterButton->setMaximumSize( QSize( 26, 20 ) );
357 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
358 controlLayout->addWidget( fasterButton, 0, 17 );
360 /* advanced Controls handling */
361 b_advancedVisible = b_advControls;
363 advControls = new AdvControlsWidget( p_intf );
364 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
365 if( !b_advancedVisible ) advControls->hide();
367 /** Disc and Menus handling */
368 discFrame = new QFrame( this );
370 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
371 discLayout->setSpacing( 0 );
372 discLayout->setMargin( 0 );
374 prevSectionButton = new QPushButton( discFrame );
375 setupSmallButton( prevSectionButton );
376 discLayout->addWidget( prevSectionButton );
378 menuButton = new QPushButton( discFrame );
379 setupSmallButton( menuButton );
380 discLayout->addWidget( menuButton );
382 nextSectionButton = new QPushButton( discFrame );
383 setupSmallButton( nextSectionButton );
384 discLayout->addWidget( nextSectionButton );
386 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
388 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
389 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
390 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
394 /* Change the navigation button display when the IM navigation changes */
395 CONNECT( THEMIM->getIM(), navigationChanged( int ),
396 this, setNavigation( int ) );
397 /* Changes the IM navigation when triggered on the nav buttons */
398 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
400 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
402 CONNECT( menuButton, clicked(), THEMIM->getIM(),
407 * Merge with upper menu in a StackLayout
411 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
412 sizePolicy.setHorizontalStretch( 0 );
413 sizePolicy.setVerticalStretch( 0 );
416 playButton = new QPushButton;
417 playButton->setSizePolicy( sizePolicy );
418 playButton->setMaximumSize( QSize( 38, 38 ) );
419 playButton->setMinimumSize( QSize( 45, 45 ) );
420 playButton->setIconSize( QSize( 30, 30 ) );
422 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
424 controlLayout->setColumnMinimumWidth( 2, 20 );
425 controlLayout->setColumnStretch( 2, 0 );
427 /** Prev + Stop + Next Block **/
428 QHBoxLayout *controlButLayout = new QHBoxLayout;
429 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
432 QPushButton *prevButton = new QPushButton;
433 prevButton->setSizePolicy( sizePolicy );
434 setupSmallButton( prevButton );
436 controlButLayout->addWidget( prevButton );
439 QPushButton *stopButton = new QPushButton;
440 stopButton->setSizePolicy( sizePolicy );
441 setupSmallButton( stopButton );
443 controlButLayout->addWidget( stopButton );
446 QPushButton *nextButton = new QPushButton;
447 nextButton->setSizePolicy( sizePolicy );
448 setupSmallButton( nextButton );
450 controlButLayout->addWidget( nextButton );
452 /* Add this block to the main layout */
453 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
455 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
456 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
457 qtr( "Previous" ), prev() );
458 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
459 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
461 controlLayout->setColumnStretch( 7 , 2 );
464 * Other first Line buttons
465 * Might need to be inside a frame to avoid a few resizing pb
468 /** Fullscreen/Visualisation **/
469 fullscreenButton = new QPushButton( "F" );
470 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
471 setupSmallButton( fullscreenButton );
472 controlLayout->addWidget( fullscreenButton, 3, 10 );
474 /** Playlist Button **/
475 playlistButton = new QPushButton;
476 setupSmallButton( playlistButton );
477 controlLayout->addWidget( playlistButton, 3, 11 );
478 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
480 /** extended Settings **/
481 QPushButton *extSettingsButton = new QPushButton( "F" );
482 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
484 setupSmallButton( extSettingsButton );
485 controlLayout->addWidget( extSettingsButton, 3, 12 );
487 controlLayout->setColumnStretch( 14, 5 );
490 VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
492 volMuteLabel = new QLabel;
493 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
494 volMuteLabel->setToolTip( qtr( "Mute" ) );
495 volMuteLabel->installEventFilter( hVolLabel );
496 controlLayout->addWidget( volMuteLabel, 3, 15 );
498 volumeSlider = new SoundSlider( this, config_GetInt( p_intf, "qt-volume-complete" ) );
499 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
500 volumeSlider->setMinimumSize( QSize( 80, 20 ) );
501 volumeSlider->setFocusPolicy( Qt::NoFocus );
502 controlLayout->addWidget( volumeSlider, 3, 16, 1, 2 );
504 /* Set the volume from the config */
505 volumeSlider->setValue( (config_GetInt( p_intf, "volume" ) )* VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
507 /* Volume control connection */
508 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
509 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
511 ControlsWidget::~ControlsWidget()
514 void ControlsWidget::stop()
519 void ControlsWidget::play()
521 if( THEPL->current.i_size == 0 )
523 /* The playlist is empty, open a file requester */
524 THEDP->openFileDialog();
528 THEMIM->togglePlayPause();
531 void ControlsWidget::prev()
536 void ControlsWidget::next()
541 void ControlsWidget::setNavigation( int navigation )
543 #define HELP_MENU N_( "Menu" )
544 #define HELP_PCH N_( "Previous chapter" )
545 #define HELP_NCH N_( "Next chapter" )
546 #define HELP_PTR N_( "Previous track" )
547 #define HELP_NTR N_( "Next track" )
549 // 1 = chapter, 2 = title, 0 = no
550 if( navigation == 0 )
553 } else if( navigation == 1 ) {
554 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
555 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
559 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
560 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
566 static bool b_my_volume;
567 void ControlsWidget::updateVolume( int i_sliderVolume )
571 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
572 aout_VolumeSet( p_intf, i_res );
574 if( i_sliderVolume == 0 )
575 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
576 else if( i_sliderVolume < VOLUME_MAX / 2 )
577 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
578 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
581 void ControlsWidget::updateOnTimer()
584 audio_volume_t i_volume;
585 aout_VolumeGet( p_intf, &i_volume );
586 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2) ;
587 int i_gauge = volumeSlider->value();
589 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
592 volumeSlider->setValue( i_volume );
596 /* Activate the interface buttons according to the presence of the input */
597 enableInput( THEMIM->getIM()->hasInput() );
598 //enableVideo( THEMIM->getIM()->hasVideo() );
602 void ControlsWidget::setStatus( int status )
604 if( status == PLAYING_S ) // Playing
605 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
607 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
612 * This functions toggle the fullscreen mode
613 * If there is no video, it should first activate Visualisations...
614 * This has also to be fixed in enableVideo()
616 void ControlsWidget::fullscreen()
618 vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
621 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
622 vlc_object_release( p_vout );
626 void ControlsWidget::extSettings()
628 THEDP->extendedDialog();
631 void ControlsWidget::slower()
633 THEMIM->getIM()->slower();
636 void ControlsWidget::faster()
638 THEMIM->getIM()->faster();
641 void ControlsWidget::enableInput( bool enable )
643 slowerButton->setEnabled( enable );
644 slider->setEnabled( enable );
645 fasterButton->setEnabled( enable );
647 /* Advanced Buttons too */
648 advControls->enableInput( enable );
651 void ControlsWidget::enableVideo( bool enable )
653 // TODO Later make the fullscreenButton toggle Visualisation and so on.
654 fullscreenButton->setEnabled( enable );
656 /* Advanced Buttons too */
657 advControls->enableVideo( enable );
660 void ControlsWidget::toggleAdvanced()
662 if( !VISIBLE( advControls ) )
665 b_advancedVisible = true;
670 b_advancedVisible = false;
672 //FIXME connect this one :D
673 emit advancedControlsToggled( b_advancedVisible ); // doComponentsUpdate();
676 /**********************************************************************
677 * Playlist Widget. The embedded playlist
678 **********************************************************************/
679 #include "components/playlist/panels.hpp"
680 #include "components/playlist/selector.hpp"
682 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i ) :
685 /* Left Part and design */
686 QWidget *leftW = new QWidget( this );
687 QVBoxLayout *left = new QVBoxLayout( leftW );
689 /* Source Selector */
690 selector = new PLSelector( this, p_intf, THEPL );
691 left->addWidget( selector );
694 art = new QLabel( "" );
695 art->setMinimumHeight( 128 );
696 art->setMinimumWidth( 128 );
697 art->setMaximumHeight( 128 );
698 art->setMaximumWidth( 128 );
699 art->setScaledContents( true );
700 art->setPixmap( QPixmap( ":/noart.png" ) );
701 left->addWidget( art );
703 /* Initialisation of the playlist */
704 playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
705 THEPL->p_local_category );
707 rightPanel = qobject_cast<PLPanel *>( new StandardPLPanel( this,
708 p_intf, THEPL, p_root ) );
711 CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
713 CONNECT( qobject_cast<StandardPLPanel *>( rightPanel )->model,
714 artSet( QString ) , this, setArt( QString ) );
715 /* Forward removal requests from the selector to the main panel */
716 CONNECT( qobject_cast<PLSelector *>( selector )->model,
718 qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );
720 connect( selector, SIGNAL( activated( int ) ),
721 this, SIGNAL( rootChanged( int ) ) );
722 emit rootChanged( p_root->i_id );
724 /* Add the two sides of the QSplitter */
726 addWidget( rightPanel );
728 leftW->setMaximumWidth( 250 );
729 setCollapsible( 1, false );
732 sizeList << 180 << 520 ;
733 setSizes( sizeList );
736 void PlaylistWidget::setArt( QString url )
739 art->setPixmap( QPixmap( ":/noart.png" ) );
740 else if( prevArt != url )
742 art->setPixmap( QPixmap( url ) );
748 PlaylistWidget::~PlaylistWidget()
752 /**********************************************************************
753 * Speed control widget
754 **********************************************************************/
755 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
756 QFrame( NULL ), p_intf( _p_i )
758 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
759 sizePolicy.setHorizontalStretch( 0 );
760 sizePolicy.setVerticalStretch( 0 );
762 speedSlider = new QSlider;
763 speedSlider->setSizePolicy( sizePolicy );
764 speedSlider->setMaximumSize( QSize( 80, 200 ) );
765 speedSlider->setOrientation( Qt::Vertical );
766 speedSlider->setTickPosition( QSlider::TicksRight );
768 speedSlider->setRange( -100, 100 );
769 speedSlider->setSingleStep( 10 );
770 speedSlider->setPageStep( 20 );
771 speedSlider->setTickInterval( 20 );
773 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
775 normalSpeedButton = new QPushButton( "N" );
776 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
777 normalSpeedButton->setFlat( true );
778 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
780 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
782 QVBoxLayout *speedControlLayout = new QVBoxLayout;
783 speedControlLayout->addWidget(speedSlider);
784 speedControlLayout->addWidget(normalSpeedButton);
785 setLayout(speedControlLayout);
788 SpeedControlWidget::~SpeedControlWidget()
792 #define RATE_SLIDER_MAXIMUM 3.0
793 #define RATE_SLIDER_MINIMUM 0.3
794 #define RATE_SLIDER_LENGTH 100.0
796 void SpeedControlWidget::updateControls( int rate )
798 if( speedSlider->isSliderDown() )
800 //We don't want to change anything if the user is using the slider
805 double speed = INPUT_RATE_DEFAULT / (double)rate;
807 if( rate >= INPUT_RATE_DEFAULT )
809 if( speed < RATE_SLIDER_MINIMUM )
811 sliderValue = speedSlider->minimum();
815 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
816 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
821 if( speed > RATE_SLIDER_MAXIMUM )
823 sliderValue = speedSlider->maximum();
827 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
828 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
832 //Block signals to avoid feedback loop
833 speedSlider->blockSignals( true );
834 speedSlider->setValue( sliderValue );
835 speedSlider->blockSignals( false );
838 void SpeedControlWidget::updateRate( int sliderValue )
842 if( sliderValue < 0.0 )
844 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
845 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ) ;
849 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
850 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
853 THEMIM->getIM()->setRate(rate);
856 void SpeedControlWidget::resetRate()
858 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);