1 /*****************************************************************************
2 * interface_widgets.cpp : Custom widgets for the main interface
3 ****************************************************************************
4 * Copyright ( C ) 2006 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
9 * Rafaël Carré <funman@videolanorg>
10 * Ilkka Ollakka <ileoo@videolan.org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * ( at your option ) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 #include "dialogs_provider.hpp"
28 #include "components/interface_widgets.hpp"
29 #include "main_interface.hpp"
30 #include "input_manager.hpp"
32 #include "util/input_slider.hpp"
33 #include "util/customwidgets.hpp"
37 #include <QSpacerItem>
39 #include <QPushButton>
40 #include <QHBoxLayout>
43 #include <QResizeEvent>
45 /**********************************************************************
46 * Video Widget. A simple frame on which video is drawn
47 * This class handles resize issues
48 **********************************************************************/
49 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
50 unsigned int *, unsigned int * );
51 static void DoRelease( intf_thread_t *, void * );
52 static int DoControl( intf_thread_t *, void *, int, va_list );
54 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
56 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 )
114 /**********************************************************************
115 * Background Widget. Show a simple image background. Currently,
116 * it's a static cone.
117 **********************************************************************/
118 #define ICON_SIZE 128
119 #define MAX_BG_SIZE 400
120 #define MIN_BG_SIZE 64
122 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
123 QFrame( NULL ), p_intf( _p_i )
125 /* We should use that one to take the more size it can */
126 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding );
128 /* A dark background */
129 setAutoFillBackground( true );
131 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
132 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
135 /* A cone in the middle */
137 label->setScaledContents( true );
138 label->setMargin( 5 );
139 label->setMaximumHeight( MAX_BG_SIZE );
140 label->setMaximumWidth( MAX_BG_SIZE );
141 label->setMinimumHeight( MIN_BG_SIZE );
142 label->setMinimumWidth( MIN_BG_SIZE );
143 label->setPixmap( QPixmap( ":/vlc128.png" ) );
145 QHBoxLayout *backgroundLayout = new QHBoxLayout( this );
146 backgroundLayout->addWidget( label );
150 CONNECT( THEMIM, inputChanged( input_thread_t *), this, update( input_thread_t * ) );
153 BackgroundWidget::~BackgroundWidget()
158 void BackgroundWidget::update( input_thread_t *p_input )
160 if( !p_input || p_input->b_dead )
162 label->setPixmap( QPixmap( ":/vlc128.png" ) );
167 vlc_object_yield( p_input );
168 char *psz_arturl = input_item_GetArtURL( input_GetItem(p_input) );
169 vlc_object_release( p_input );
170 QString url = qfu( psz_arturl );
171 QString arturl = url.replace( "file://",QString("" ) );
172 if( arturl.isNull() )
173 label->setPixmap( QPixmap( ":/vlc128.png" ) );
176 label->setPixmap( QPixmap( arturl ) );
177 msg_Dbg( p_intf, "changing input b_need_update done %s", psz_arturl );
182 QSize BackgroundWidget::sizeHint() const
184 return label->size();
187 void BackgroundWidget::resizeEvent( QResizeEvent *e )
189 if( e->size().height() < MAX_BG_SIZE -1 )
191 label->setMaximumWidth( e->size().height() );
192 label->setMaximumHeight( e->size().width() );
196 label->setMaximumHeight( MAX_BG_SIZE );
197 label->setMaximumWidth( MAX_BG_SIZE );
201 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
203 QVLCMenu::PopupMenu( p_intf, true );
206 /**********************************************************************
207 * Visualization selector panel
208 **********************************************************************/
209 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
210 QFrame( NULL ), p_intf( _p_i )
212 QHBoxLayout *layout = new QHBoxLayout( this );
213 layout->setMargin( 0 );
214 QPushButton *prevButton = new QPushButton( "Prev" );
215 QPushButton *nextButton = new QPushButton( "Next" );
216 layout->addWidget( prevButton );
217 layout->addWidget( nextButton );
219 layout->addItem( new QSpacerItem( 40,20,
220 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
221 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
223 current = new QLabel( qtr( "None" ) );
224 layout->addWidget( current );
226 BUTTONACT( prevButton, prev() );
227 BUTTONACT( nextButton, next() );
230 setMaximumHeight( 35 );
233 VisualSelector::~VisualSelector()
237 void VisualSelector::prev()
239 char *psz_new = aout_VisualPrev( p_intf );
242 current->setText( qfu( psz_new ) );
247 void VisualSelector::next()
249 char *psz_new = aout_VisualNext( p_intf );
252 current->setText( qfu( psz_new ) );
257 /**********************************************************************
259 **********************************************************************/
261 #define setupSmallButton( aButton ){ \
262 aButton->setMaximumSize( QSize( 26, 26 ) ); \
263 aButton->setMinimumSize( QSize( 26, 26 ) ); \
264 aButton->setIconSize( QSize( 20, 20 ) ); }
266 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
267 QFrame( NULL ), p_intf( _p_i )
269 QHBoxLayout *advLayout = new QHBoxLayout( this );
270 advLayout->setMargin( 0 );
271 advLayout->setSpacing( 0 );
274 ABButton = new QPushButton( "AB" );
275 ABButton->setMaximumSize( QSize( 26, 26 ) );
276 ABButton->setIconSize( QSize( 20, 20 ) );
277 advLayout->addWidget( ABButton );
278 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
280 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
281 this, AtoBLoop( float, int, int ) );
283 frameButton = new QPushButton( "Fr" );
284 frameButton->setMaximumSize( QSize( 26, 26 ) );
285 frameButton->setIconSize( QSize( 20, 20 ) );
286 advLayout->addWidget( frameButton );
287 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
289 recordButton = new QPushButton( "R" );
290 recordButton->setMaximumSize( QSize( 26, 26 ) );
291 recordButton->setIconSize( QSize( 20, 20 ) );
292 advLayout->addWidget( recordButton );
293 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
294 qtr( "Record" ), record() );
296 /* Snapshot Button */
297 snapshotButton = new QPushButton( "S" );
298 snapshotButton->setMaximumSize( QSize( 26, 26 ) );
299 snapshotButton->setIconSize( QSize( 20, 20 ) );
300 advLayout->addWidget( snapshotButton );
301 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
304 AdvControlsWidget::~AdvControlsWidget()
307 void AdvControlsWidget::enableInput( bool enable )
309 ABButton->setEnabled( enable );
310 recordButton->setEnabled( enable );
313 void AdvControlsWidget::enableVideo( bool enable )
315 snapshotButton->setEnabled( enable );
316 frameButton->setEnabled( enable );
319 void AdvControlsWidget::snapshot()
321 vout_thread_t *p_vout =
322 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
323 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
326 /* Function called when the button is clicked() */
327 void AdvControlsWidget::fromAtoB()
331 timeA = var_GetTime( THEMIM->getInput(), "time" );
332 ABButton->setText( "A->..." );
337 timeB = var_GetTime( THEMIM->getInput(), "time" );
338 var_SetTime( THEMIM->getInput(), "time" , timeA );
339 ABButton->setText( "A<=>B" );
344 ABButton->setText( "AB" );
347 /* Function called regularly when in an AtoB loop */
348 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
352 if( i_time >= (int)(timeB/1000000) )
353 var_SetTime( THEMIM->getInput(), "time" , timeA );
357 /* FIXME Record function */
358 void AdvControlsWidget::record(){}
360 //FIXME Frame by frame function
361 void AdvControlsWidget::frame(){}
363 /*****************************
364 * DA Control Widget !
365 *****************************/
366 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
367 MainInterface *_p_mi,
370 QFrame( NULL ), p_intf( _p_i )
372 controlLayout = new QGridLayout( this );
373 controlLayout->setSpacing( 0 );
374 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Minimum );
376 /** The main Slider **/
377 slider = new InputSlider( Qt::Horizontal, NULL );
378 controlLayout->addWidget( slider, 0, 1, 1, 16 );
379 /* Update the position when the IM has changed */
380 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
381 slider, setPosition( float, int, int ) );
382 /* And update the IM, when the position has changed */
383 CONNECT( slider, sliderDragged( float ),
384 THEMIM->getIM(), sliderUpdate( float ) );
386 /** Slower and faster Buttons **/
387 slowerButton = new QPushButton;
388 slowerButton->setFlat( true );
389 slowerButton->setMaximumSize( QSize( 26, 20 ) );
391 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
392 controlLayout->addWidget( slowerButton, 0, 0 );
394 fasterButton = new QPushButton;
395 fasterButton->setFlat( true );
396 fasterButton->setMaximumSize( QSize( 26, 20 ) );
398 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
399 controlLayout->addWidget( fasterButton, 0, 17 );
401 /* advanced Controls handling */
402 b_advancedVisible = b_advControls;
404 advControls = new AdvControlsWidget( p_intf );
405 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
406 if( !b_advancedVisible ) advControls->hide();
408 /** Disc and Menus handling */
409 discFrame = new QFrame( this );
411 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
412 discLayout->setSpacing( 0 );
413 discLayout->setMargin( 0 );
415 prevSectionButton = new QPushButton( discFrame );
416 setupSmallButton( prevSectionButton );
417 discLayout->addWidget( prevSectionButton );
419 menuButton = new QPushButton( discFrame );
420 setupSmallButton( menuButton );
421 discLayout->addWidget( menuButton );
423 nextSectionButton = new QPushButton( discFrame );
424 setupSmallButton( nextSectionButton );
425 discLayout->addWidget( nextSectionButton );
427 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
429 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
430 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
431 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
435 /* Change the navigation button display when the IM navigation changes */
436 CONNECT( THEMIM->getIM(), navigationChanged( int ),
437 this, setNavigation( int ) );
438 /* Changes the IM navigation when triggered on the nav buttons */
439 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
441 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
443 CONNECT( menuButton, clicked(), THEMIM->getIM(),
448 * Merge with upper menu in a StackLayout
452 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
453 sizePolicy.setHorizontalStretch( 0 );
454 sizePolicy.setVerticalStretch( 0 );
457 playButton = new QPushButton;
458 playButton->setSizePolicy( sizePolicy );
459 playButton->setMaximumSize( QSize( 38, 38 ) );
460 playButton->setMinimumSize( QSize( 45, 45 ) );
461 playButton->setIconSize( QSize( 30, 30 ) );
463 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
465 controlLayout->setColumnMinimumWidth( 2, 20 );
466 controlLayout->setColumnStretch( 2, 0 );
468 /** Prev + Stop + Next Block **/
469 QHBoxLayout *controlButLayout = new QHBoxLayout;
470 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
473 QPushButton *prevButton = new QPushButton;
474 prevButton->setSizePolicy( sizePolicy );
475 setupSmallButton( prevButton );
477 controlButLayout->addWidget( prevButton );
480 QPushButton *stopButton = new QPushButton;
481 stopButton->setSizePolicy( sizePolicy );
482 setupSmallButton( stopButton );
484 controlButLayout->addWidget( stopButton );
487 QPushButton *nextButton = new QPushButton;
488 nextButton->setSizePolicy( sizePolicy );
489 setupSmallButton( nextButton );
491 controlButLayout->addWidget( nextButton );
493 /* Add this block to the main layout */
494 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
496 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
497 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
498 qtr( "Previous" ), prev() );
499 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
500 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
502 controlLayout->setColumnStretch( 7 , 2 );
505 * Other first Line buttons
507 /** Fullscreen/Visualisation **/
508 fullscreenButton = new QPushButton( "F" );
509 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
510 setupSmallButton( fullscreenButton );
511 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
513 /** Playlist Button **/
514 playlistButton = new QPushButton;
515 setupSmallButton( playlistButton );
516 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
517 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
518 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
520 /** extended Settings **/
521 QPushButton *extSettingsButton = new QPushButton( "F" );
522 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
524 setupSmallButton( extSettingsButton );
525 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
527 controlLayout->setColumnStretch( 14, 5 );
530 VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
532 volMuteLabel = new QLabel;
533 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
534 volMuteLabel->setToolTip( qtr( "Mute" ) );
535 volMuteLabel->installEventFilter( hVolLabel );
536 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
540 volumeSlider = new SoundSlider( this,
541 config_GetInt( p_intf, "volume-step" ),
542 config_GetInt( p_intf, "qt-volume-complete" ) );
546 volumeSlider = new QSlider( this );
547 volumeSlider->setOrientation( Qt::Horizontal );
549 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
550 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
551 volumeSlider->setFocusPolicy( Qt::NoFocus );
552 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
554 /* Set the volume from the config */
555 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
556 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
558 /* Volume control connection */
559 resize( QSize( 400, 60 ) );
560 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
561 msg_Dbg( p_intf, "controls size: %i - %i", size().width(), size().height() );
564 ControlsWidget::~ControlsWidget()
569 QSize ControlsWidget::sizeHint() const
571 return QSize( 300, 50 );
575 void ControlsWidget::stop()
580 void ControlsWidget::play()
582 if( THEPL->current.i_size == 0 )
584 /* The playlist is empty, open a file requester */
585 THEDP->openFileDialog();
589 THEMIM->togglePlayPause();
592 void ControlsWidget::prev()
597 void ControlsWidget::next()
602 void ControlsWidget::setNavigation( int navigation )
604 #define HELP_MENU N_( "Menu" )
605 #define HELP_PCH N_( "Previous chapter" )
606 #define HELP_NCH N_( "Next chapter" )
607 #define HELP_PTR N_( "Previous track" )
608 #define HELP_NTR N_( "Next track" )
610 // 1 = chapter, 2 = title, 0 = no
611 if( navigation == 0 )
614 } else if( navigation == 1 ) {
615 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
616 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
620 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
621 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
627 static bool b_my_volume;
628 void ControlsWidget::updateVolume( int i_sliderVolume )
632 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
633 aout_VolumeSet( p_intf, i_res );
635 if( i_sliderVolume == 0 )
636 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
637 else if( i_sliderVolume < VOLUME_MAX / 2 )
638 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
639 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
642 void ControlsWidget::updateOnTimer()
645 audio_volume_t i_volume;
646 aout_VolumeGet( p_intf, &i_volume );
647 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
648 int i_gauge = volumeSlider->value();
650 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
653 volumeSlider->setValue( i_volume );
657 /* Activate the interface buttons according to the presence of the input */
658 enableInput( THEMIM->getIM()->hasInput() );
659 //enableVideo( THEMIM->getIM()->hasVideo() );
663 void ControlsWidget::setStatus( int status )
665 if( status == PLAYING_S ) // Playing
666 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
668 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
673 * This functions toggle the fullscreen mode
674 * If there is no video, it should first activate Visualisations...
675 * This has also to be fixed in enableVideo()
677 void ControlsWidget::fullscreen()
679 vout_thread_t *p_vout =
680 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
683 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
684 vlc_object_release( p_vout );
688 void ControlsWidget::extSettings()
690 THEDP->extendedDialog();
693 void ControlsWidget::slower()
695 THEMIM->getIM()->slower();
698 void ControlsWidget::faster()
700 THEMIM->getIM()->faster();
703 void ControlsWidget::enableInput( bool enable )
705 slowerButton->setEnabled( enable );
706 slider->setEnabled( enable );
707 fasterButton->setEnabled( enable );
709 /* Advanced Buttons too */
710 advControls->enableInput( enable );
713 void ControlsWidget::enableVideo( bool enable )
715 // TODO Later make the fullscreenButton toggle Visualisation and so on.
716 fullscreenButton->setEnabled( enable );
718 /* Advanced Buttons too */
719 advControls->enableVideo( enable );
722 void ControlsWidget::toggleAdvanced()
724 if( !VISIBLE( advControls ) )
727 b_advancedVisible = true;
732 b_advancedVisible = false;
734 emit advancedControlsToggled( b_advancedVisible );
738 /**********************************************************************
739 * Speed control widget
740 **********************************************************************/
741 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
742 QFrame( NULL ), p_intf( _p_i )
744 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
745 sizePolicy.setHorizontalStretch( 0 );
746 sizePolicy.setVerticalStretch( 0 );
748 speedSlider = new QSlider;
749 speedSlider->setSizePolicy( sizePolicy );
750 speedSlider->setMaximumSize( QSize( 80, 200 ) );
751 speedSlider->setOrientation( Qt::Vertical );
752 speedSlider->setTickPosition( QSlider::TicksRight );
754 speedSlider->setRange( -100, 100 );
755 speedSlider->setSingleStep( 10 );
756 speedSlider->setPageStep( 20 );
757 speedSlider->setTickInterval( 20 );
759 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
761 normalSpeedButton = new QPushButton( "N" );
762 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
763 normalSpeedButton->setFlat( true );
764 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
766 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
768 QVBoxLayout *speedControlLayout = new QVBoxLayout;
769 speedControlLayout->addWidget(speedSlider);
770 speedControlLayout->addWidget(normalSpeedButton);
771 setLayout(speedControlLayout);
774 SpeedControlWidget::~SpeedControlWidget()
777 #define RATE_SLIDER_MAXIMUM 3.0
778 #define RATE_SLIDER_MINIMUM 0.3
779 #define RATE_SLIDER_LENGTH 100.0
781 void SpeedControlWidget::updateControls( int rate )
783 if( speedSlider->isSliderDown() )
785 //We don't want to change anything if the user is using the slider
790 double speed = INPUT_RATE_DEFAULT / (double)rate;
792 if( rate >= INPUT_RATE_DEFAULT )
794 if( speed < RATE_SLIDER_MINIMUM )
796 sliderValue = speedSlider->minimum();
800 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
801 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
806 if( speed > RATE_SLIDER_MAXIMUM )
808 sliderValue = speedSlider->maximum();
812 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
813 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
817 //Block signals to avoid feedback loop
818 speedSlider->blockSignals( true );
819 speedSlider->setValue( sliderValue );
820 speedSlider->blockSignals( false );
823 void SpeedControlWidget::updateRate( int sliderValue )
827 if( sliderValue < 0.0 )
829 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
830 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH );
834 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
835 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
838 THEMIM->getIM()->setRate(rate);
841 void SpeedControlWidget::resetRate()
843 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);