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 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
63 VideoWidget::~VideoWidget()
65 vlc_mutex_lock( &lock );
68 if( !p_intf->psz_switch_intf )
70 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
71 vout_Control( p_vout, VOUT_REPARENT );
75 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
76 vout_Control( p_vout, VOUT_CLOSE );
79 vlc_mutex_unlock( &lock );
80 vlc_mutex_destroy( &lock );
83 QSize VideoWidget::sizeHint() const
88 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
89 unsigned int *pi_width, unsigned int *pi_height )
94 msg_Dbg( p_intf, "embedded video already in use" );
99 return ( void* )winId();
102 void VideoWidget::SetMinSize()
104 setMinimumSize( 16, 16 );
107 void VideoWidget::release( void *p_win )
111 /**********************************************************************
112 * Background Widget. Show a simple image background. Currently,
113 * it's a static cone.
114 **********************************************************************/
115 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
116 QFrame( NULL ), p_intf( _p_i )
119 setAutoFillBackground( true );
121 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
122 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
126 label->setMaximumHeight( ICON_SIZE );
127 label->setMaximumWidth( ICON_SIZE );
128 label->setScaledContents( true );
129 label->setPixmap( QPixmap( ":/vlc128.png" ) );
130 backgroundLayout = new QHBoxLayout;
131 backgroundLayout->addWidget( label );
132 setLayout( backgroundLayout );
135 BackgroundWidget::~BackgroundWidget()
137 backgroundLayout->takeAt( 0 );
138 delete backgroundLayout;
141 void BackgroundWidget::setArt( QString url )
144 label->setPixmap( QPixmap( ":/vlc128.png" ) );
146 label->setPixmap( QPixmap( url ) );
149 QSize BackgroundWidget::sizeHint() const
154 void BackgroundWidget::resizeEvent( QResizeEvent *e )
156 if( e->size().height() < ICON_SIZE -1 )
157 label->setMaximumWidth( e->size().height() );
159 label->setMaximumWidth( ICON_SIZE );
162 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
164 QVLCMenu::PopupMenu( p_intf, true );
166 /**********************************************************************
167 * Visualization selector panel
168 **********************************************************************/
169 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
170 QFrame( NULL ), p_intf( _p_i )
172 QHBoxLayout *layout = new QHBoxLayout( this );
173 layout->setMargin( 0 );
174 QPushButton *prevButton = new QPushButton( "Prev" );
175 QPushButton *nextButton = new QPushButton( "Next" );
176 layout->addWidget( prevButton );
177 layout->addWidget( nextButton );
179 layout->addItem( new QSpacerItem( 40,20,
180 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
181 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
183 current = new QLabel( qtr( "None" ) );
184 layout->addWidget( current );
186 BUTTONACT( prevButton, prev() );
187 BUTTONACT( nextButton, next() );
190 setMaximumHeight( 35 );
193 VisualSelector::~VisualSelector()
197 void VisualSelector::prev()
199 char *psz_new = aout_VisualPrev( p_intf );
202 current->setText( qfu( psz_new ) );
207 void VisualSelector::next()
209 char *psz_new = aout_VisualNext( p_intf );
212 current->setText( qfu( psz_new ) );
217 /**********************************************************************
219 **********************************************************************/
221 #define setupSmallButton( aButton ){ \
222 aButton->setMaximumSize( QSize( 26, 26 ) ); \
223 aButton->setMinimumSize( QSize( 26, 26 ) ); \
224 aButton->setIconSize( QSize( 20, 20 ) ); }
226 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
227 QFrame( NULL ), p_intf( _p_i )
229 QHBoxLayout *advLayout = new QHBoxLayout( this );
230 advLayout->setMargin( 0 );
231 advLayout->setSpacing( 0 );
233 /* FIXME A to B function */
234 ABButton = new QPushButton( "AB" );
235 ABButton->setMaximumSize( QSize( 26, 26 ) );
236 ABButton->setIconSize( QSize( 20, 20 ) );
237 advLayout->addWidget( ABButton );
238 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
240 snapshotButton = new QPushButton( "S" );
241 snapshotButton->setMaximumSize( QSize( 26, 26 ) );
242 snapshotButton->setIconSize( QSize( 20, 20 ) );
243 advLayout->addWidget( snapshotButton );
244 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
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 normalButton = new QPushButton( "N" );
262 normalButton->setMaximumSize( QSize( 26, 26 ) );
263 normalButton->setIconSize( QSize( 20, 20 ) );
264 advLayout->addWidget( normalButton );
265 BUTTON_SET_ACT( normalButton, "N", qtr( "Normal rate" ), normal() );
269 AdvControlsWidget::~AdvControlsWidget()
273 void AdvControlsWidget::enableInput( bool enable )
275 ABButton->setEnabled( enable );
276 recordButton->setEnabled( enable );
277 normalButton->setEnabled( enable );
279 void AdvControlsWidget::enableVideo( bool enable )
281 snapshotButton->setEnabled( enable );
282 frameButton->setEnabled( enable );
285 void AdvControlsWidget::normal()
287 THEMIM->getIM()->normalRate();
290 void AdvControlsWidget::snapshot()
292 vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
293 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
296 void AdvControlsWidget::frame(){}
297 void AdvControlsWidget::fromAtoB(){}
298 void AdvControlsWidget::record(){}
300 /*****************************
301 * DA Control Widget !
302 *****************************/
303 ControlsWidget::ControlsWidget( intf_thread_t *_p_i, bool b_advControls ) :
304 QFrame( NULL ), p_intf( _p_i )
306 //QSize size( 500, 200 );
308 controlLayout = new QGridLayout( this );
309 controlLayout->setSpacing( 0 );
310 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
314 palette2.setColor(this->backgroundRole(), Qt::magenta);
315 setPalette(palette2);
318 /** The main Slider **/
319 slider = new InputSlider( Qt::Horizontal, NULL );
320 controlLayout->addWidget( slider, 0, 1, 1, 16 );
321 /* Update the position when the IM has changed */
322 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
323 slider, setPosition( float,int, int ) );
324 /* And update the IM, when the position has changed */
325 CONNECT( slider, sliderDragged( float ),
326 THEMIM->getIM(), sliderUpdate( float ) );
328 /** Slower and faster Buttons **/
329 slowerButton = new QPushButton( "S" );
330 slowerButton->setFlat( true );
332 BUTTON_SET_ACT( slowerButton, "S", qtr( "Slower" ), slower() );
333 controlLayout->addWidget( slowerButton, 0, 0 );
334 slowerButton->setMaximumSize( QSize( 26, 20 ) );
336 fasterButton = new QPushButton( "F" );
337 fasterButton->setFlat( true );
339 BUTTON_SET_ACT( fasterButton, "F", qtr( "Faster" ), faster() );
340 controlLayout->addWidget( fasterButton, 0, 17 );
341 fasterButton->setMaximumSize( QSize( 26, 20 ) );
343 /* advanced Controls handling */
344 b_advancedVisible = b_advControls;
346 advControls = new AdvControlsWidget( p_intf );
347 controlLayout->addWidget( advControls, 1, 3, 2, 5, Qt::AlignBottom );
348 if( !b_advancedVisible ) advControls->hide();
349 // FIXME THIS should be removed. need_components_update = true;
351 /** Disc and Menus handling */
352 discFrame = new QFrame( this );
354 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
355 discLayout->setSpacing( 0 );
356 discLayout->setMargin( 0 );
358 prevSectionButton = new QPushButton( discFrame );
359 setupSmallButton( prevSectionButton );
360 discLayout->addWidget( prevSectionButton );
362 menuButton = new QPushButton( discFrame );
363 setupSmallButton( menuButton );
364 discLayout->addWidget( menuButton );
366 nextSectionButton = new QPushButton( discFrame );
367 setupSmallButton( nextSectionButton );
368 discLayout->addWidget( nextSectionButton );
370 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
372 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
373 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
374 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
378 /* Change the navigation button display when the IM navigation changes */
379 CONNECT( THEMIM->getIM(), navigationChanged( int ),
380 this, setNavigation( int ) );
381 /* Changes the IM navigation when triggered on the nav buttons */
382 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
384 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
386 CONNECT( menuButton, clicked(), THEMIM->getIM(),
394 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
395 sizePolicy.setHorizontalStretch( 0 );
396 sizePolicy.setVerticalStretch( 0 );
399 playButton = new QPushButton;
400 playButton->setSizePolicy( sizePolicy );
401 playButton->setMaximumSize( QSize( 38, 38 ) );
402 playButton->setMinimumSize( QSize( 45, 45 ) );
403 playButton->setIconSize( QSize( 30, 30 ) );
405 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
407 controlLayout->setColumnMinimumWidth( 2, 20 );
408 controlLayout->setColumnStretch( 2, 0 );
410 /** Prev + Stop + Next Block **/
411 QHBoxLayout *controlButLayout = new QHBoxLayout;
412 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
415 QPushButton *prevButton = new QPushButton;
416 prevButton->setSizePolicy( sizePolicy );
417 setupSmallButton( prevButton );
419 controlButLayout->addWidget( prevButton );
422 QPushButton *stopButton = new QPushButton;
423 stopButton->setSizePolicy( sizePolicy );
424 setupSmallButton( stopButton );
426 controlButLayout->addWidget( stopButton );
429 QPushButton *nextButton = new QPushButton;
430 nextButton->setSizePolicy( sizePolicy );
431 setupSmallButton( nextButton );
433 controlButLayout->addWidget( nextButton );
435 /* Add this block to the main layout */
436 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
438 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
439 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
440 qtr( "Previous" ), prev() );
441 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
442 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
444 controlLayout->setColumnStretch( 8 , 10 );
445 controlLayout->setColumnStretch( 9, 0 );
448 * Other first Line buttons
449 * Might need to be inside a frame to avoid a few resizing pb
452 /** Fullscreen/Visualisation **/
453 fullscreenButton = new QPushButton( "F" );
454 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
455 setupSmallButton( fullscreenButton );
456 controlLayout->addWidget( fullscreenButton, 3, 10 );
458 /** Playlist Button **/
459 playlistButton = new QPushButton;
460 setupSmallButton( playlistButton );
461 controlLayout->addWidget( playlistButton, 3, 11 );
462 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
464 /** extended Settings **/
465 QPushButton *extSettingsButton = new QPushButton( "F" );
466 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
468 setupSmallButton( extSettingsButton );
469 controlLayout->addWidget( extSettingsButton, 3, 12 );
471 controlLayout->setColumnStretch( 14, 5 );
474 VolumeClickHandler *h = new VolumeClickHandler( p_intf, this );
476 volMuteLabel = new QLabel;
477 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
478 volMuteLabel->setToolTip( qtr( "Mute" ) );
479 volMuteLabel->installEventFilter( h );
482 * Change this slider to use a nice Amarok-like one
483 * Add a Context menu to change to the most useful %
486 * THis percerntage thing has to be handled correctly
487 * This has to match to the OSD
489 volumeSlider = new QSlider;
490 volumeSlider->setSizePolicy( sizePolicy );
491 volumeSlider->setMaximumSize( QSize( 80, 200 ) );
492 volumeSlider->setOrientation( Qt::Horizontal );
494 volumeSlider->setMaximum( VOLUME_MAX );
495 volumeSlider->setFocusPolicy( Qt::NoFocus );
496 controlLayout->addWidget( volMuteLabel, 3, 15 );
497 controlLayout->addWidget( volumeSlider, 3, 16, 1, 2 );
499 /* Volume control connection */
500 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
501 msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
503 ControlsWidget::~ControlsWidget()
506 void ControlsWidget::stop()
511 void ControlsWidget::play()
514 msg_Dbg( p_intf, "There is %i playlist items", THEPL->items.i_size ); /* FIXME: remove me */
515 if( playlist_IsEmpty( THEPL ) )
517 /* The playlist is empty, open a file requester */
518 THEDP->openFileDialog();
522 THEMIM->togglePlayPause();
525 void ControlsWidget::prev()
530 void ControlsWidget::next()
535 void ControlsWidget::setNavigation( int navigation )
537 #define HELP_MENU N_( "Menu" )
538 #define HELP_PCH N_( "Previous chapter" )
539 #define HELP_NCH N_( "Next chapter" )
540 #define HELP_PTR N_( "Previous track" )
541 #define HELP_NTR N_( "Next track" )
543 // 1 = chapter, 2 = title, 0 = no
544 if( navigation == 0 )
547 } else if( navigation == 1 ) {
548 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
549 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
553 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
554 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
560 static bool b_my_volume;
561 void ControlsWidget::updateVolume( int i_sliderVolume )
565 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
566 aout_VolumeSet( p_intf, i_res );
568 if( i_sliderVolume == 0 )
569 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
570 else if( i_sliderVolume < VOLUME_MAX / 2 )
571 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
572 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
575 void ControlsWidget::updateOnTimer()
578 audio_volume_t i_volume;
579 aout_VolumeGet( p_intf, &i_volume );
580 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2) ;
581 int i_gauge = volumeSlider->value();
583 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
586 volumeSlider->setValue( i_volume );
590 /* Activate the interface buttons according to the presence of the input */
591 enableInput( THEMIM->getIM()->hasInput() );
592 //enableVideo( THEMIM->getIM()->hasVideo() );
596 void ControlsWidget::setStatus( int status )
598 if( status == PLAYING_S ) // Playing
599 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
601 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
606 * This functions toggle the fullscreen mode
607 * If there is no video, it should first activate Visualisations...
608 * This has also to be fixed in enableVideo()
610 void ControlsWidget::fullscreen()
612 vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
615 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
616 vlc_object_release( p_vout );
620 void ControlsWidget::extSettings()
622 THEDP->extendedDialog();
625 void ControlsWidget::slower()
627 THEMIM->getIM()->slower();
630 void ControlsWidget::faster()
632 THEMIM->getIM()->faster();
635 void ControlsWidget::enableInput( bool enable )
637 slowerButton->setEnabled( enable );
638 slider->setEnabled( enable );
639 fasterButton->setEnabled( enable );
641 /* Advanced Buttons too */
642 advControls->enableInput( enable );
645 void ControlsWidget::enableVideo( bool enable )
647 // TODO Later make the fullscreenButton toggle Visualisation and so on.
648 fullscreenButton->setEnabled( enable );
650 /* Advanced Buttons too */
651 advControls->enableVideo( enable );
654 void ControlsWidget::toggleAdvanced()
656 if( !VISIBLE( advControls ) )
659 b_advancedVisible = true;
664 b_advancedVisible = false;
666 //FIXME connect this one :D
667 emit advancedControlsToggled( b_advancedVisible ); // doComponentsUpdate();
670 /**********************************************************************
671 * Playlist Widget. The embedded playlist
672 **********************************************************************/
673 #include "components/playlist/panels.hpp"
674 #include "components/playlist/selector.hpp"
676 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i ) :
679 /* Left Part and design */
680 QWidget *leftW = new QWidget( this );
681 QVBoxLayout *left = new QVBoxLayout( leftW );
683 /* Source Selector */
684 selector = new PLSelector( this, p_intf, THEPL );
685 left->addWidget( selector );
688 art = new QLabel( "" );
689 art->setMinimumHeight( 128 );
690 art->setMinimumWidth( 128 );
691 art->setMaximumHeight( 128 );
692 art->setMaximumWidth( 128 );
693 art->setScaledContents( true );
694 art->setPixmap( QPixmap( ":/noart.png" ) );
695 left->addWidget( art );
697 /* Initialisation of the playlist */
698 playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
699 THEPL->p_local_category );
701 rightPanel = qobject_cast<PLPanel *>( new StandardPLPanel( this,
702 p_intf, THEPL, p_root ) );
705 CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
707 CONNECT( qobject_cast<StandardPLPanel *>( rightPanel )->model,
708 artSet( QString ) , this, setArt( QString ) );
709 /* Forward removal requests from the selector to the main panel */
710 CONNECT( qobject_cast<PLSelector *>( selector )->model,
712 qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );
714 connect( selector, SIGNAL( activated( int ) ),
715 this, SIGNAL( rootChanged( int ) ) );
716 emit rootChanged( p_root->i_id );
718 /* Add the two sides of the QSplitter */
720 addWidget( rightPanel );
722 leftW->setMaximumWidth( 250 );
723 setCollapsible( 1, false );
726 sizeList << 180 << 520 ;
727 setSizes( sizeList );
730 void PlaylistWidget::setArt( QString url )
733 art->setPixmap( QPixmap( ":/noart.png" ) );
734 else if( prevArt != url )
736 art->setPixmap( QPixmap( url ) );
742 PlaylistWidget::~PlaylistWidget()
746 QSize PlaylistWidget::sizeHint() const
751 /**********************************************************************
752 * Speed control widget
753 **********************************************************************/
754 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
755 QFrame( NULL ), p_intf( _p_i )
757 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
758 sizePolicy.setHorizontalStretch( 0 );
759 sizePolicy.setVerticalStretch( 0 );
761 speedSlider = new QSlider;
762 speedSlider->setSizePolicy( sizePolicy );
763 speedSlider->setMaximumSize( QSize( 80, 200 ) );
764 speedSlider->setOrientation( Qt::Vertical );
765 speedSlider->setTickPosition( QSlider::TicksRight );
767 speedSlider->setRange( -100, 100 );
768 speedSlider->setSingleStep( 10 );
769 speedSlider->setPageStep( 20 );
770 speedSlider->setTickInterval( 20 );
772 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
774 normalSpeedButton = new QPushButton( "N" );
775 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
776 normalSpeedButton->setFlat( true );
777 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
779 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
781 QVBoxLayout *speedControlLayout = new QVBoxLayout;
782 speedControlLayout->addWidget(speedSlider);
783 speedControlLayout->addWidget(normalSpeedButton);
784 setLayout(speedControlLayout);
787 SpeedControlWidget::~SpeedControlWidget()
791 #define RATE_SLIDER_MAXIMUM 3.0
792 #define RATE_SLIDER_MINIMUM 0.3
793 #define RATE_SLIDER_LENGTH 100.0
795 void SpeedControlWidget::updateControls( int rate )
797 if( speedSlider->isSliderDown() )
799 //We don't want to change anything if the user is using the slider
804 double speed = INPUT_RATE_DEFAULT / (double)rate;
806 if( rate >= INPUT_RATE_DEFAULT )
808 if( speed < RATE_SLIDER_MINIMUM )
810 sliderValue = speedSlider->minimum();
814 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
815 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
820 if( speed > RATE_SLIDER_MAXIMUM )
822 sliderValue = speedSlider->maximum();
826 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
827 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
831 //Block signals to avoid feedback loop
832 speedSlider->blockSignals( true );
833 speedSlider->setValue( sliderValue );
834 speedSlider->blockSignals( false );
837 void SpeedControlWidget::updateRate( int sliderValue )
841 if( sliderValue < 0.0 )
843 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
844 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ) ;
848 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
849 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
852 THEMIM->getIM()->setRate(rate);
855 void SpeedControlWidget::resetRate()
857 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);