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"
35 #include <QSpacerItem>
37 #include <QPushButton>
38 #include <QHBoxLayout>
41 #include <QResizeEvent>
44 #define MAX_BG_SIZE 300
46 /**********************************************************************
47 * Video Widget. A simple frame on which video is drawn
48 * This class handles resize issues
49 **********************************************************************/
50 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
51 unsigned int *, unsigned int * );
52 static void DoRelease( intf_thread_t *, void * );
53 static int DoControl( intf_thread_t *, void *, int, va_list );
55 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
57 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 )
112 /**********************************************************************
113 * Background Widget. Show a simple image background. Currently,
114 * it's a static cone.
115 **********************************************************************/
116 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
117 QFrame( NULL ), p_intf( _p_i )
120 setAutoFillBackground( true );
122 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
123 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
127 label->setMaximumHeight( ICON_SIZE );
128 label->setMaximumWidth( ICON_SIZE );
129 label->setScaledContents( true );
130 label->setPixmap( QPixmap( ":/vlc128.png" ) );
131 backgroundLayout = new QHBoxLayout;
132 backgroundLayout->addWidget( label );
133 setLayout( backgroundLayout );
136 BackgroundWidget::~BackgroundWidget()
138 backgroundLayout->takeAt( 0 );
139 delete backgroundLayout;
142 void BackgroundWidget::setArt( QString url )
145 label->setPixmap( QPixmap( ":/vlc128.png" ) );
147 label->setPixmap( QPixmap( url ) );
150 QSize BackgroundWidget::sizeHint() const
155 void BackgroundWidget::resizeEvent( QResizeEvent *e )
157 if( e->size().height() < ICON_SIZE -1 )
158 label->setMaximumWidth( e->size().height() );
160 label->setMaximumWidth( ICON_SIZE );
163 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
165 QVLCMenu::PopupMenu( p_intf, true );
167 /**********************************************************************
168 * Visualization selector panel
169 **********************************************************************/
170 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
171 QFrame( NULL ), p_intf( _p_i )
173 QHBoxLayout *layout = new QHBoxLayout( this );
174 layout->setMargin( 0 );
175 QPushButton *prevButton = new QPushButton( "Prev" );
176 QPushButton *nextButton = new QPushButton( "Next" );
177 layout->addWidget( prevButton );
178 layout->addWidget( nextButton );
180 layout->addItem( new QSpacerItem( 40,20,
181 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
182 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
184 current = new QLabel( qtr( "None" ) );
185 layout->addWidget( current );
187 BUTTONACT( prevButton, prev() );
188 BUTTONACT( nextButton, next() );
191 setMaximumHeight( 35 );
194 VisualSelector::~VisualSelector()
198 void VisualSelector::prev()
200 char *psz_new = aout_VisualPrev( p_intf );
203 current->setText( qfu( psz_new ) );
208 void VisualSelector::next()
210 char *psz_new = aout_VisualNext( p_intf );
213 current->setText( qfu( psz_new ) );
218 /**********************************************************************
220 **********************************************************************/
222 #define setupSmallButton( aButton ){ \
223 aButton->setMaximumSize( QSize( 26, 26 ) ); \
224 aButton->setMinimumSize( QSize( 26, 26 ) ); \
225 aButton->setIconSize( QSize( 20, 20 ) ); }
227 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
228 QFrame( NULL ), p_intf( _p_i )
230 QHBoxLayout *advLayout = new QHBoxLayout( this );
231 advLayout->setMargin( 0 );
232 advLayout->setSpacing( 0 );
234 /* FIXME A to B function */
235 ABButton = new QPushButton( "AB" );
236 ABButton->setMaximumSize( QSize( 26, 26 ) );
237 ABButton->setIconSize( QSize( 20, 20 ) );
238 advLayout->addWidget( ABButton );
239 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
242 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
243 this, AtoBLoop( float, int, int ) );
245 //FIXME Frame by frame function
246 frameButton = new QPushButton( "Fr" );
247 frameButton->setMaximumSize( QSize( 26, 26 ) );
248 frameButton->setIconSize( QSize( 20, 20 ) );
249 advLayout->addWidget( frameButton );
250 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
252 /* FIXME Record function */
253 recordButton = new QPushButton( "R" );
254 recordButton->setMaximumSize( QSize( 26, 26 ) );
255 recordButton->setIconSize( QSize( 20, 20 ) );
256 advLayout->addWidget( recordButton );
257 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
258 qtr( "Record" ), record() );
260 snapshotButton = new QPushButton( "S" );
261 snapshotButton->setMaximumSize( QSize( 26, 26 ) );
262 snapshotButton->setIconSize( QSize( 20, 20 ) );
263 advLayout->addWidget( snapshotButton );
264 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
268 AdvControlsWidget::~AdvControlsWidget()
272 void AdvControlsWidget::enableInput( bool enable )
274 ABButton->setEnabled( enable );
275 recordButton->setEnabled( enable );
277 void AdvControlsWidget::enableVideo( bool enable )
279 snapshotButton->setEnabled( enable );
280 frameButton->setEnabled( enable );
283 void AdvControlsWidget::snapshot()
285 vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
286 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
289 void AdvControlsWidget::frame()
293 void AdvControlsWidget::fromAtoB()
297 timeA = var_GetTime( THEMIM->getInput(), "time" );
298 ABButton->setText( "A->..." );
303 timeB = var_GetTime( THEMIM->getInput(), "time" );
304 var_SetTime( THEMIM->getInput(), "time" , timeA );
305 ABButton->setText( "A<=>B" );
310 ABButton->setText( "AB" );
313 void AdvControlsWidget::record(){}
315 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
319 if( i_time == (int)(timeB/1000000) )
320 var_SetTime( THEMIM->getInput(), "time" , timeA );
323 /*****************************
324 * DA Control Widget !
325 *****************************/
326 ControlsWidget::ControlsWidget( intf_thread_t *_p_i, bool b_advControls ) :
327 QFrame( NULL ), p_intf( _p_i )
329 controlLayout = new QGridLayout( this );
330 controlLayout->setSpacing( 0 );
331 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
333 /** The main Slider **/
334 slider = new InputSlider( Qt::Horizontal, NULL );
335 controlLayout->addWidget( slider, 0, 1, 1, 16 );
336 /* Update the position when the IM has changed */
337 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
338 slider, setPosition( float,int, int ) );
339 /* And update the IM, when the position has changed */
340 CONNECT( slider, sliderDragged( float ),
341 THEMIM->getIM(), sliderUpdate( float ) );
343 /** Slower and faster Buttons **/
344 slowerButton = new QPushButton;
345 slowerButton->setFlat( true );
346 slowerButton->setMaximumSize( QSize( 26, 20 ) );
348 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
349 controlLayout->addWidget( slowerButton, 0, 0 );
351 fasterButton = new QPushButton;
352 fasterButton->setFlat( true );
353 fasterButton->setMaximumSize( QSize( 26, 20 ) );
355 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
356 controlLayout->addWidget( fasterButton, 0, 17 );
358 /* advanced Controls handling */
359 b_advancedVisible = b_advControls;
361 advControls = new AdvControlsWidget( p_intf );
362 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
363 if( !b_advancedVisible ) advControls->hide();
365 /** Disc and Menus handling */
366 discFrame = new QFrame( this );
368 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
369 discLayout->setSpacing( 0 );
370 discLayout->setMargin( 0 );
372 prevSectionButton = new QPushButton( discFrame );
373 setupSmallButton( prevSectionButton );
374 discLayout->addWidget( prevSectionButton );
376 menuButton = new QPushButton( discFrame );
377 setupSmallButton( menuButton );
378 discLayout->addWidget( menuButton );
380 nextSectionButton = new QPushButton( discFrame );
381 setupSmallButton( nextSectionButton );
382 discLayout->addWidget( nextSectionButton );
384 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
386 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
387 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
388 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
392 /* Change the navigation button display when the IM navigation changes */
393 CONNECT( THEMIM->getIM(), navigationChanged( int ),
394 this, setNavigation( int ) );
395 /* Changes the IM navigation when triggered on the nav buttons */
396 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
398 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
400 CONNECT( menuButton, clicked(), THEMIM->getIM(),
405 * Merge with upper menu in a StackLayout
409 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
410 sizePolicy.setHorizontalStretch( 0 );
411 sizePolicy.setVerticalStretch( 0 );
414 playButton = new QPushButton;
415 playButton->setSizePolicy( sizePolicy );
416 playButton->setMaximumSize( QSize( 38, 38 ) );
417 playButton->setMinimumSize( QSize( 45, 45 ) );
418 playButton->setIconSize( QSize( 30, 30 ) );
420 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
422 controlLayout->setColumnMinimumWidth( 2, 20 );
423 controlLayout->setColumnStretch( 2, 0 );
425 /** Prev + Stop + Next Block **/
426 QHBoxLayout *controlButLayout = new QHBoxLayout;
427 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
430 QPushButton *prevButton = new QPushButton;
431 prevButton->setSizePolicy( sizePolicy );
432 setupSmallButton( prevButton );
434 controlButLayout->addWidget( prevButton );
437 QPushButton *stopButton = new QPushButton;
438 stopButton->setSizePolicy( sizePolicy );
439 setupSmallButton( stopButton );
441 controlButLayout->addWidget( stopButton );
444 QPushButton *nextButton = new QPushButton;
445 nextButton->setSizePolicy( sizePolicy );
446 setupSmallButton( nextButton );
448 controlButLayout->addWidget( nextButton );
450 /* Add this block to the main layout */
451 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
453 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
454 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
455 qtr( "Previous" ), prev() );
456 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
457 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
459 controlLayout->setColumnStretch( 7 , 2 );
462 * Other first Line buttons
463 * Might need to be inside a frame to avoid a few resizing pb
466 /** Fullscreen/Visualisation **/
467 fullscreenButton = new QPushButton( "F" );
468 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
469 setupSmallButton( fullscreenButton );
470 controlLayout->addWidget( fullscreenButton, 3, 10 );
472 /** Playlist Button **/
473 playlistButton = new QPushButton;
474 setupSmallButton( playlistButton );
475 controlLayout->addWidget( playlistButton, 3, 11 );
476 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
478 /** extended Settings **/
479 QPushButton *extSettingsButton = new QPushButton( "F" );
480 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
482 setupSmallButton( extSettingsButton );
483 controlLayout->addWidget( extSettingsButton, 3, 12 );
485 controlLayout->setColumnStretch( 14, 5 );
488 VolumeClickHandler *h = new VolumeClickHandler( p_intf, this );
490 volMuteLabel = new QLabel;
491 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
492 volMuteLabel->setToolTip( qtr( "Mute" ) );
493 volMuteLabel->installEventFilter( h );
496 * Change this slider to use a nice Amarok-like one
499 * THis percerntage thing has to be handled correctly
500 * This has to match to the OSD
502 volumeSlider = new QSlider;
503 volumeSlider->setSizePolicy( sizePolicy );
504 volumeSlider->setMaximumSize( QSize( 80, 200 ) );
505 volumeSlider->setOrientation( Qt::Horizontal );
507 volumeSlider->setMaximum( VOLUME_MAX );
508 volumeSlider->setFocusPolicy( Qt::NoFocus );
509 controlLayout->addWidget( volMuteLabel, 3, 15 );
510 controlLayout->addWidget( volumeSlider, 3, 16, 1, 2 );
512 /* Volume control connection */
513 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
514 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
516 ControlsWidget::~ControlsWidget()
519 void ControlsWidget::stop()
524 void ControlsWidget::play()
526 if( THEPL->current.i_size == 0 )
528 /* The playlist is empty, open a file requester */
529 THEDP->openFileDialog();
533 THEMIM->togglePlayPause();
536 void ControlsWidget::prev()
541 void ControlsWidget::next()
546 void ControlsWidget::setNavigation( int navigation )
548 #define HELP_MENU N_( "Menu" )
549 #define HELP_PCH N_( "Previous chapter" )
550 #define HELP_NCH N_( "Next chapter" )
551 #define HELP_PTR N_( "Previous track" )
552 #define HELP_NTR N_( "Next track" )
554 // 1 = chapter, 2 = title, 0 = no
555 if( navigation == 0 )
558 } else if( navigation == 1 ) {
559 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
560 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
564 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
565 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
571 static bool b_my_volume;
572 void ControlsWidget::updateVolume( int i_sliderVolume )
576 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
577 aout_VolumeSet( p_intf, i_res );
579 if( i_sliderVolume == 0 )
580 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
581 else if( i_sliderVolume < VOLUME_MAX / 2 )
582 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
583 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
586 void ControlsWidget::updateOnTimer()
589 audio_volume_t i_volume;
590 aout_VolumeGet( p_intf, &i_volume );
591 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2) ;
592 int i_gauge = volumeSlider->value();
594 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
597 volumeSlider->setValue( i_volume );
601 /* Activate the interface buttons according to the presence of the input */
602 enableInput( THEMIM->getIM()->hasInput() );
603 //enableVideo( THEMIM->getIM()->hasVideo() );
607 void ControlsWidget::setStatus( int status )
609 if( status == PLAYING_S ) // Playing
610 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
612 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
617 * This functions toggle the fullscreen mode
618 * If there is no video, it should first activate Visualisations...
619 * This has also to be fixed in enableVideo()
621 void ControlsWidget::fullscreen()
623 vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
626 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
627 vlc_object_release( p_vout );
631 void ControlsWidget::extSettings()
633 THEDP->extendedDialog();
636 void ControlsWidget::slower()
638 THEMIM->getIM()->slower();
641 void ControlsWidget::faster()
643 THEMIM->getIM()->faster();
646 void ControlsWidget::enableInput( bool enable )
648 slowerButton->setEnabled( enable );
649 slider->setEnabled( enable );
650 fasterButton->setEnabled( enable );
652 /* Advanced Buttons too */
653 advControls->enableInput( enable );
656 void ControlsWidget::enableVideo( bool enable )
658 // TODO Later make the fullscreenButton toggle Visualisation and so on.
659 fullscreenButton->setEnabled( enable );
661 /* Advanced Buttons too */
662 advControls->enableVideo( enable );
665 void ControlsWidget::toggleAdvanced()
667 if( !VISIBLE( advControls ) )
670 b_advancedVisible = true;
675 b_advancedVisible = false;
677 //FIXME connect this one :D
678 emit advancedControlsToggled( b_advancedVisible ); // doComponentsUpdate();
681 /**********************************************************************
682 * Playlist Widget. The embedded playlist
683 **********************************************************************/
684 #include "components/playlist/panels.hpp"
685 #include "components/playlist/selector.hpp"
687 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i ) :
690 /* Left Part and design */
691 QWidget *leftW = new QWidget( this );
692 QVBoxLayout *left = new QVBoxLayout( leftW );
694 /* Source Selector */
695 selector = new PLSelector( this, p_intf, THEPL );
696 left->addWidget( selector );
699 art = new QLabel( "" );
700 art->setMinimumHeight( 128 );
701 art->setMinimumWidth( 128 );
702 art->setMaximumHeight( 128 );
703 art->setMaximumWidth( 128 );
704 art->setScaledContents( true );
705 art->setPixmap( QPixmap( ":/noart.png" ) );
706 left->addWidget( art );
708 /* Initialisation of the playlist */
709 playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
710 THEPL->p_local_category );
712 rightPanel = qobject_cast<PLPanel *>( new StandardPLPanel( this,
713 p_intf, THEPL, p_root ) );
716 CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
718 CONNECT( qobject_cast<StandardPLPanel *>( rightPanel )->model,
719 artSet( QString ) , this, setArt( QString ) );
720 /* Forward removal requests from the selector to the main panel */
721 CONNECT( qobject_cast<PLSelector *>( selector )->model,
723 qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );
725 connect( selector, SIGNAL( activated( int ) ),
726 this, SIGNAL( rootChanged( int ) ) );
727 emit rootChanged( p_root->i_id );
729 /* Add the two sides of the QSplitter */
731 addWidget( rightPanel );
733 leftW->setMaximumWidth( 250 );
734 setCollapsible( 1, false );
737 sizeList << 180 << 520 ;
738 setSizes( sizeList );
741 void PlaylistWidget::setArt( QString url )
744 art->setPixmap( QPixmap( ":/noart.png" ) );
745 else if( prevArt != url )
747 art->setPixmap( QPixmap( url ) );
753 PlaylistWidget::~PlaylistWidget()
757 /**********************************************************************
758 * Speed control widget
759 **********************************************************************/
760 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
761 QFrame( NULL ), p_intf( _p_i )
763 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
764 sizePolicy.setHorizontalStretch( 0 );
765 sizePolicy.setVerticalStretch( 0 );
767 speedSlider = new QSlider;
768 speedSlider->setSizePolicy( sizePolicy );
769 speedSlider->setMaximumSize( QSize( 80, 200 ) );
770 speedSlider->setOrientation( Qt::Vertical );
771 speedSlider->setTickPosition( QSlider::TicksRight );
773 speedSlider->setRange( -100, 100 );
774 speedSlider->setSingleStep( 10 );
775 speedSlider->setPageStep( 20 );
776 speedSlider->setTickInterval( 20 );
778 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
780 normalSpeedButton = new QPushButton( "N" );
781 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
782 normalSpeedButton->setFlat( true );
783 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
785 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
787 QVBoxLayout *speedControlLayout = new QVBoxLayout;
788 speedControlLayout->addWidget(speedSlider);
789 speedControlLayout->addWidget(normalSpeedButton);
790 setLayout(speedControlLayout);
793 SpeedControlWidget::~SpeedControlWidget()
797 #define RATE_SLIDER_MAXIMUM 3.0
798 #define RATE_SLIDER_MINIMUM 0.3
799 #define RATE_SLIDER_LENGTH 100.0
801 void SpeedControlWidget::updateControls( int rate )
803 if( speedSlider->isSliderDown() )
805 //We don't want to change anything if the user is using the slider
810 double speed = INPUT_RATE_DEFAULT / (double)rate;
812 if( rate >= INPUT_RATE_DEFAULT )
814 if( speed < RATE_SLIDER_MINIMUM )
816 sliderValue = speedSlider->minimum();
820 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
821 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
826 if( speed > RATE_SLIDER_MAXIMUM )
828 sliderValue = speedSlider->maximum();
832 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
833 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
837 //Block signals to avoid feedback loop
838 speedSlider->blockSignals( true );
839 speedSlider->setValue( sliderValue );
840 speedSlider->blockSignals( false );
843 void SpeedControlWidget::updateRate( int sliderValue )
847 if( sliderValue < 0.0 )
849 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
850 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ) ;
854 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
855 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
858 THEMIM->getIM()->setRate(rate);
861 void SpeedControlWidget::resetRate()
863 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);