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() );
241 snapshotButton = new QPushButton( "S" );
242 snapshotButton->setMaximumSize( QSize( 26, 26 ) );
243 snapshotButton->setIconSize( QSize( 20, 20 ) );
244 advLayout->addWidget( snapshotButton );
245 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
247 //FIXME Frame by frame function
248 frameButton = new QPushButton( "Fr" );
249 frameButton->setMaximumSize( QSize( 26, 26 ) );
250 frameButton->setIconSize( QSize( 20, 20 ) );
251 advLayout->addWidget( frameButton );
252 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
254 /* FIXME Record function */
255 recordButton = new QPushButton( "R" );
256 recordButton->setMaximumSize( QSize( 26, 26 ) );
257 recordButton->setIconSize( QSize( 20, 20 ) );
258 advLayout->addWidget( recordButton );
259 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
260 qtr( "Record" ), record() );
262 normalButton = new QPushButton( "N" );
263 normalButton->setMaximumSize( QSize( 26, 26 ) );
264 normalButton->setIconSize( QSize( 20, 20 ) );
265 advLayout->addWidget( normalButton );
266 BUTTON_SET_ACT( normalButton, "N", qtr( "Normal rate" ), normal() );
270 AdvControlsWidget::~AdvControlsWidget()
274 void AdvControlsWidget::enableInput( bool enable )
276 ABButton->setEnabled( enable );
277 recordButton->setEnabled( enable );
278 normalButton->setEnabled( enable );
280 void AdvControlsWidget::enableVideo( bool enable )
282 snapshotButton->setEnabled( enable );
283 frameButton->setEnabled( enable );
286 void AdvControlsWidget::normal()
288 THEMIM->getIM()->normalRate();
291 void AdvControlsWidget::snapshot()
293 vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
294 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
297 void AdvControlsWidget::frame(){}
298 void AdvControlsWidget::fromAtoB(){}
299 void AdvControlsWidget::record(){}
301 /*****************************
302 * DA Control Widget !
303 *****************************/
304 ControlsWidget::ControlsWidget( intf_thread_t *_p_i, bool b_advControls ) :
305 QFrame( NULL ), p_intf( _p_i )
307 //QSize size( 500, 200 );
309 controlLayout = new QGridLayout( this );
310 controlLayout->setSpacing( 0 );
311 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
315 palette2.setColor(this->backgroundRole(), Qt::magenta);
316 setPalette(palette2);
319 /** The main Slider **/
320 slider = new InputSlider( Qt::Horizontal, NULL );
321 controlLayout->addWidget( slider, 0, 1, 1, 16 );
322 /* Update the position when the IM has changed */
323 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
324 slider, setPosition( float,int, int ) );
325 /* And update the IM, when the position has changed */
326 CONNECT( slider, sliderDragged( float ),
327 THEMIM->getIM(), sliderUpdate( float ) );
329 /** Slower and faster Buttons **/
330 slowerButton = new QPushButton( "S" );
331 slowerButton->setFlat( true );
333 BUTTON_SET_ACT( slowerButton, "S", qtr( "Slower" ), slower() );
334 controlLayout->addWidget( slowerButton, 0, 0 );
335 slowerButton->setMaximumSize( QSize( 26, 20 ) );
337 fasterButton = new QPushButton( "F" );
338 fasterButton->setFlat( true );
340 BUTTON_SET_ACT( fasterButton, "F", qtr( "Faster" ), faster() );
341 controlLayout->addWidget( fasterButton, 0, 17 );
342 fasterButton->setMaximumSize( QSize( 26, 20 ) );
344 /* advanced Controls handling */
345 b_advancedVisible = b_advControls;
347 advControls = new AdvControlsWidget( p_intf );
348 controlLayout->addWidget( advControls, 1, 3, 2, 5, Qt::AlignBottom );
349 if( !b_advancedVisible ) advControls->hide();
350 // FIXME THIS should be removed. need_components_update = true;
352 /** Disc and Menus handling */
353 discFrame = new QFrame( this );
355 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
356 discLayout->setSpacing( 0 );
357 discLayout->setMargin( 0 );
359 prevSectionButton = new QPushButton( discFrame );
360 setupSmallButton( prevSectionButton );
361 discLayout->addWidget( prevSectionButton );
363 menuButton = new QPushButton( discFrame );
364 setupSmallButton( menuButton );
365 discLayout->addWidget( menuButton );
367 nextSectionButton = new QPushButton( discFrame );
368 setupSmallButton( nextSectionButton );
369 discLayout->addWidget( nextSectionButton );
371 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
373 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
374 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
375 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
379 /* Change the navigation button display when the IM navigation changes */
380 CONNECT( THEMIM->getIM(), navigationChanged( int ),
381 this, setNavigation( int ) );
382 /* Changes the IM navigation when triggered on the nav buttons */
383 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
385 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
387 CONNECT( menuButton, clicked(), THEMIM->getIM(),
395 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
396 sizePolicy.setHorizontalStretch( 0 );
397 sizePolicy.setVerticalStretch( 0 );
400 playButton = new QPushButton;
401 playButton->setSizePolicy( sizePolicy );
402 playButton->setMaximumSize( QSize( 38, 38 ) );
403 playButton->setMinimumSize( QSize( 45, 45 ) );
404 playButton->setIconSize( QSize( 30, 30 ) );
406 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
408 controlLayout->setColumnMinimumWidth( 2, 20 );
409 controlLayout->setColumnStretch( 2, 0 );
411 /** Prev + Stop + Next Block **/
412 QHBoxLayout *controlButLayout = new QHBoxLayout;
413 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
416 QPushButton *prevButton = new QPushButton;
417 prevButton->setSizePolicy( sizePolicy );
418 setupSmallButton( prevButton );
420 controlButLayout->addWidget( prevButton );
423 QPushButton *stopButton = new QPushButton;
424 stopButton->setSizePolicy( sizePolicy );
425 setupSmallButton( stopButton );
427 controlButLayout->addWidget( stopButton );
430 QPushButton *nextButton = new QPushButton;
431 nextButton->setSizePolicy( sizePolicy );
432 setupSmallButton( nextButton );
434 controlButLayout->addWidget( nextButton );
436 /* Add this block to the main layout */
437 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
439 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
440 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
441 qtr( "Previous" ), prev() );
442 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
443 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
445 controlLayout->setColumnStretch( 8 , 10 );
446 controlLayout->setColumnStretch( 9, 0 );
449 * Other first Line buttons
450 * Might need to be inside a frame to avoid a few resizing pb
453 /** Fullscreen/Visualisation **/
454 fullscreenButton = new QPushButton( "F" );
455 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
456 setupSmallButton( fullscreenButton );
457 controlLayout->addWidget( fullscreenButton, 3, 10 );
459 /** Playlist Button **/
460 playlistButton = new QPushButton;
461 setupSmallButton( playlistButton );
462 controlLayout->addWidget( playlistButton, 3, 11 );
463 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
465 /** extended Settings **/
466 QPushButton *extSettingsButton = new QPushButton( "F" );
467 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
469 setupSmallButton( extSettingsButton );
470 controlLayout->addWidget( extSettingsButton, 3, 12 );
472 controlLayout->setColumnStretch( 14, 5 );
475 VolumeClickHandler *h = new VolumeClickHandler( p_intf, this );
477 volMuteLabel = new QLabel;
478 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
479 volMuteLabel->setToolTip( qtr( "Mute" ) );
480 volMuteLabel->installEventFilter( h );
483 * Change this slider to use a nice Amarok-like one
484 * Add a Context menu to change to the most useful %
487 * THis percerntage thing has to be handled correctly
488 * This has to match to the OSD
490 volumeSlider = new QSlider;
491 volumeSlider->setSizePolicy( sizePolicy );
492 volumeSlider->setMaximumSize( QSize( 80, 200 ) );
493 volumeSlider->setOrientation( Qt::Horizontal );
495 volumeSlider->setMaximum( VOLUME_MAX );
496 volumeSlider->setFocusPolicy( Qt::NoFocus );
497 controlLayout->addWidget( volMuteLabel, 3, 15 );
498 controlLayout->addWidget( volumeSlider, 3, 16, 1, 2 );
500 /* Volume control connection */
501 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
502 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
504 ControlsWidget::~ControlsWidget()
507 void ControlsWidget::stop()
512 void ControlsWidget::play()
515 msg_Dbg( p_intf, "There is %i playlist items", THEPL->items.i_size ); /* FIXME: remove me */
516 if( playlist_IsEmpty( THEPL ) )
518 /* The playlist is empty, open a file requester */
519 THEDP->openFileDialog();
523 THEMIM->togglePlayPause();
526 void ControlsWidget::prev()
531 void ControlsWidget::next()
536 void ControlsWidget::setNavigation( int navigation )
538 #define HELP_MENU N_( "Menu" )
539 #define HELP_PCH N_( "Previous chapter" )
540 #define HELP_NCH N_( "Next chapter" )
541 #define HELP_PTR N_( "Previous track" )
542 #define HELP_NTR N_( "Next track" )
544 // 1 = chapter, 2 = title, 0 = no
545 if( navigation == 0 )
548 } else if( navigation == 1 ) {
549 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
550 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
554 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
555 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
561 static bool b_my_volume;
562 void ControlsWidget::updateVolume( int i_sliderVolume )
566 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
567 aout_VolumeSet( p_intf, i_res );
569 if( i_sliderVolume == 0 )
570 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
571 else if( i_sliderVolume < VOLUME_MAX / 2 )
572 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
573 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
576 void ControlsWidget::updateOnTimer()
579 audio_volume_t i_volume;
580 aout_VolumeGet( p_intf, &i_volume );
581 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2) ;
582 int i_gauge = volumeSlider->value();
584 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
587 volumeSlider->setValue( i_volume );
591 /* Activate the interface buttons according to the presence of the input */
592 enableInput( THEMIM->getIM()->hasInput() );
593 //enableVideo( THEMIM->getIM()->hasVideo() );
597 void ControlsWidget::setStatus( int status )
599 if( status == PLAYING_S ) // Playing
600 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
602 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
607 * This functions toggle the fullscreen mode
608 * If there is no video, it should first activate Visualisations...
609 * This has also to be fixed in enableVideo()
611 void ControlsWidget::fullscreen()
613 vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
616 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
617 vlc_object_release( p_vout );
621 void ControlsWidget::extSettings()
623 THEDP->extendedDialog();
626 void ControlsWidget::slower()
628 THEMIM->getIM()->slower();
631 void ControlsWidget::faster()
633 THEMIM->getIM()->faster();
636 void ControlsWidget::enableInput( bool enable )
638 slowerButton->setEnabled( enable );
639 slider->setEnabled( enable );
640 fasterButton->setEnabled( enable );
642 /* Advanced Buttons too */
643 advControls->enableInput( enable );
646 void ControlsWidget::enableVideo( bool enable )
648 // TODO Later make the fullscreenButton toggle Visualisation and so on.
649 fullscreenButton->setEnabled( enable );
651 /* Advanced Buttons too */
652 advControls->enableVideo( enable );
655 void ControlsWidget::toggleAdvanced()
657 if( !VISIBLE( advControls ) )
660 b_advancedVisible = true;
665 b_advancedVisible = false;
667 //FIXME connect this one :D
668 emit advancedControlsToggled( b_advancedVisible ); // doComponentsUpdate();
671 /**********************************************************************
672 * Playlist Widget. The embedded playlist
673 **********************************************************************/
674 #include "components/playlist/panels.hpp"
675 #include "components/playlist/selector.hpp"
677 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i ) :
680 /* Left Part and design */
681 QWidget *leftW = new QWidget( this );
682 QVBoxLayout *left = new QVBoxLayout( leftW );
684 /* Source Selector */
685 selector = new PLSelector( this, p_intf, THEPL );
686 left->addWidget( selector );
689 art = new QLabel( "" );
690 art->setMinimumHeight( 128 );
691 art->setMinimumWidth( 128 );
692 art->setMaximumHeight( 128 );
693 art->setMaximumWidth( 128 );
694 art->setScaledContents( true );
695 art->setPixmap( QPixmap( ":/noart.png" ) );
696 left->addWidget( art );
698 /* Initialisation of the playlist */
699 playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
700 THEPL->p_local_category );
702 rightPanel = qobject_cast<PLPanel *>( new StandardPLPanel( this,
703 p_intf, THEPL, p_root ) );
706 CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
708 CONNECT( qobject_cast<StandardPLPanel *>( rightPanel )->model,
709 artSet( QString ) , this, setArt( QString ) );
710 /* Forward removal requests from the selector to the main panel */
711 CONNECT( qobject_cast<PLSelector *>( selector )->model,
713 qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );
715 connect( selector, SIGNAL( activated( int ) ),
716 this, SIGNAL( rootChanged( int ) ) );
717 emit rootChanged( p_root->i_id );
719 /* Add the two sides of the QSplitter */
721 addWidget( rightPanel );
723 leftW->setMaximumWidth( 250 );
724 setCollapsible( 1, false );
727 sizeList << 180 << 520 ;
728 setSizes( sizeList );
731 void PlaylistWidget::setArt( QString url )
734 art->setPixmap( QPixmap( ":/noart.png" ) );
735 else if( prevArt != url )
737 art->setPixmap( QPixmap( url ) );
743 PlaylistWidget::~PlaylistWidget()
747 QSize PlaylistWidget::sizeHint() const
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);