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"
28 #include "components/interface_widgets.hpp"
29 #include "main_interface.hpp"
30 #include "input_manager.hpp"
32 #include "util/input_slider.hpp"
36 #include <QSpacerItem>
38 #include <QPushButton>
39 #include <QHBoxLayout>
42 #include <QResizeEvent>
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 )
93 msg_Dbg( p_intf, "embedded video already in use" );
98 return ( void* )winId();
101 void VideoWidget::SetMinSize()
103 setMinimumSize( 16, 16 );
106 void VideoWidget::release( void *p_win )
110 /**********************************************************************
111 * Background Widget. Show a simple image background. Currently,
112 * it's a static cone.
113 **********************************************************************/
114 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
115 QFrame( NULL ), p_intf( _p_i )
118 setAutoFillBackground( true );
120 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
121 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
124 label = new QLabel( "" );
125 label->setMaximumHeight( ICON_SIZE );
126 label->setMaximumWidth( ICON_SIZE );
127 label->setScaledContents( true );
128 label->setPixmap( QPixmap( ":/vlc128.png" ) );
129 backgroundLayout = new QHBoxLayout;
130 backgroundLayout->addWidget( label );
131 setLayout( backgroundLayout );
134 BackgroundWidget::~BackgroundWidget()
136 backgroundLayout->takeAt( 0 );
137 delete backgroundLayout;
140 void BackgroundWidget::setArt( QString url )
143 label->setPixmap( QPixmap( ":/vlc128.png" ) );
145 label->setPixmap( QPixmap( url ) );
148 QSize BackgroundWidget::sizeHint() const
153 void BackgroundWidget::resizeEvent( QResizeEvent *e )
155 if( e->size().height() < ICON_SIZE -1 )
156 label->setMaximumWidth( e->size().height() );
158 label->setMaximumWidth( ICON_SIZE );
161 /**********************************************************************
162 * Visualization selector panel
163 **********************************************************************/
164 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
165 QFrame( NULL ), p_intf( _p_i )
167 QHBoxLayout *layout = new QHBoxLayout( this );
168 layout->setMargin( 0 );
169 QPushButton *prevButton = new QPushButton( "Prev" );
170 QPushButton *nextButton = new QPushButton( "Next" );
171 layout->addWidget( prevButton );
172 layout->addWidget( nextButton );
174 layout->addItem( new QSpacerItem( 40,20,
175 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
176 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
178 current = new QLabel( qtr( "None" ) );
179 layout->addWidget( current );
181 BUTTONACT( prevButton, prev() );
182 BUTTONACT( nextButton, next() );
185 setMaximumHeight( 35 );
188 VisualSelector::~VisualSelector()
192 void VisualSelector::prev()
194 char *psz_new = aout_VisualPrev( p_intf );
197 current->setText( qfu( psz_new ) );
202 void VisualSelector::next()
204 char *psz_new = aout_VisualNext( p_intf );
207 current->setText( qfu( psz_new ) );
212 /**********************************************************************
214 **********************************************************************/
216 #define setupSmallButton( aButton ){ \
217 aButton->setMaximumSize( QSize( 26, 26 ) ); \
218 aButton->setMinimumSize( QSize( 26, 26 ) ); \
219 aButton->setIconSize( QSize( 20, 20 ) ); }
221 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
222 QFrame( NULL ), p_intf( _p_i )
224 QHBoxLayout *advLayout = new QHBoxLayout( this );
225 advLayout->setMargin( 0 );
226 advLayout->setSpacing( 0 );
228 /* FIXME A to B function */
229 ABButton = new QPushButton( "AB" );
230 ABButton->setMaximumSize( QSize( 26, 26 ) );
231 ABButton->setIconSize( QSize( 20, 20 ) );
232 advLayout->addWidget( ABButton );
233 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
235 snapshotButton = new QPushButton( "S" );
236 snapshotButton->setMaximumSize( QSize( 26, 26 ) );
237 snapshotButton->setIconSize( QSize( 20, 20 ) );
238 advLayout->addWidget( snapshotButton );
239 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
241 //FIXME Frame by frame function
242 frameButton = new QPushButton( "Fr" );
243 frameButton->setMaximumSize( QSize( 26, 26 ) );
244 frameButton->setIconSize( QSize( 20, 20 ) );
245 advLayout->addWidget( frameButton );
246 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
248 /* FIXME Record function */
249 recordButton = new QPushButton( "R" );
250 recordButton->setMaximumSize( QSize( 26, 26 ) );
251 recordButton->setIconSize( QSize( 20, 20 ) );
252 advLayout->addWidget( recordButton );
253 BUTTON_SET_ACT( recordButton, "R", qtr( "Record" ), record() );
255 normalButton = new QPushButton( "N" );
256 normalButton->setMaximumSize( QSize( 26, 26 ) );
257 normalButton->setIconSize( QSize( 20, 20 ) );
258 advLayout->addWidget( normalButton );
259 BUTTON_SET_ACT( normalButton, "N", qtr( "Normal rate" ), normal() );
263 AdvControlsWidget::~AdvControlsWidget()
267 void AdvControlsWidget::enableInput( bool enable )
269 ABButton->setEnabled( enable );
270 recordButton->setEnabled( enable );
271 normalButton->setEnabled( enable );
273 void AdvControlsWidget::enableVideo( bool enable )
275 snapshotButton->setEnabled( enable );
276 frameButton->setEnabled( enable );
279 void AdvControlsWidget::normal()
281 THEMIM->getIM()->normalRate();
284 void AdvControlsWidget::snapshot()
286 vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
287 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
290 void AdvControlsWidget::frame(){}
291 void AdvControlsWidget::fromAtoB(){}
292 void AdvControlsWidget::record(){}
294 /*****************************
295 * DA Control Widget !
296 *****************************/
297 ControlsWidget::ControlsWidget( intf_thread_t *_p_i, bool b_advControls ) :
298 QFrame( NULL ), p_intf( _p_i )
300 //QSize size( 500, 200 );
302 controlLayout = new QGridLayout( this );
306 palette2.setColor(this->backgroundRole(), Qt::magenta);
307 setPalette(palette2);
310 /** The main Slider **/
311 slider = new InputSlider( Qt::Horizontal, NULL );
312 controlLayout->addWidget( slider, 0, 1, 1, 16 );
313 /* Update the position when the IM has changed */
314 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
315 slider, setPosition( float,int, int ) );
316 /* And update the IM, when the position has changed */
317 CONNECT( slider, sliderDragged( float ),
318 THEMIM->getIM(), sliderUpdate( float ) );
320 /** Slower and faster Buttons **/
321 slowerButton = new QPushButton( "S" );
322 BUTTON_SET_ACT( slowerButton, "S", qtr( "Slower" ), slower() );
323 controlLayout->addWidget( slowerButton, 0, 0 );
324 slowerButton->setMaximumSize( QSize( 26, 20 ) );
326 fasterButton = new QPushButton( "F" );
327 BUTTON_SET_ACT( fasterButton, "F", qtr( "Faster" ), faster() );
328 controlLayout->addWidget( fasterButton, 0, 17 );
329 fasterButton->setMaximumSize( QSize( 26, 20 ) );
331 /** TODO: Insert here the AdvControls Widget
332 * Then fix all the size issues in main_interface.cpp
334 /* advanced Controls handling */
335 b_advancedVisible = b_advControls;
337 advControls = new AdvControlsWidget( p_intf );
338 controlLayout->addWidget( advControls, 1, 3, 2, 5, Qt::AlignBottom );
339 if( !b_advancedVisible ) advControls->hide();
340 //THIS should be removed. need_components_update = true;
342 /** Disc and Menus handling */
343 discFrame = new QFrame( this );
345 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
346 discLayout->setSpacing( 0 );
347 discLayout->setMargin( 0 );
349 prevSectionButton = new QPushButton( discFrame );
350 setupSmallButton( prevSectionButton );
351 discLayout->addWidget( prevSectionButton );
353 menuButton = new QPushButton( discFrame );
354 setupSmallButton( menuButton );
355 discLayout->addWidget( menuButton );
357 nextSectionButton = new QPushButton( discFrame );
358 setupSmallButton( nextSectionButton );
359 discLayout->addWidget( nextSectionButton );
361 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
363 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
364 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
365 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
369 /* Change the navigation button display when the IM navigation changes */
370 CONNECT( THEMIM->getIM(), navigationChanged( int ),
371 this, setNavigation( int ) );
372 /* Changes the IM navigation when triggered on the nav buttons */
373 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
375 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
377 CONNECT( menuButton, clicked(), THEMIM->getIM(),
385 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
386 sizePolicy.setHorizontalStretch( 0 );
387 sizePolicy.setVerticalStretch( 0 );
390 playButton = new QPushButton;
391 playButton->setSizePolicy( sizePolicy );
392 playButton->setMaximumSize( QSize( 45, 45 ) );
393 playButton->setIconSize( QSize( 30, 30 ) );
395 controlLayout->addWidget( playButton, 2, 0, 2, 2, Qt::AlignBottom );
397 controlLayout->setColumnMinimumWidth( 2, 20 );
398 controlLayout->setColumnStretch( 2, 0 );
400 /** Prev + Stop + Next Block **/
401 QHBoxLayout *controlButLayout = new QHBoxLayout;
402 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
405 QPushButton *prevButton = new QPushButton;
406 prevButton->setSizePolicy( sizePolicy );
407 setupSmallButton( prevButton );
409 controlButLayout->addWidget( prevButton );
412 QPushButton *stopButton = new QPushButton;
413 stopButton->setSizePolicy( sizePolicy );
414 setupSmallButton( stopButton );
416 controlButLayout->addWidget( stopButton );
419 QPushButton *nextButton = new QPushButton;
420 nextButton->setSizePolicy( sizePolicy );
421 setupSmallButton( nextButton );
423 controlButLayout->addWidget( nextButton );
425 /* Add this block to the main layout */
426 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
428 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
429 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
430 qtr( "Previous" ), prev() );
431 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
432 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
434 controlLayout->setColumnStretch( 8 , 10 );
435 controlLayout->setColumnStretch( 9, 0 );
438 * Other first Line buttons
439 * Might need to be inside a frame to avoid a few resizing pb
442 /** Fullscreen/Visualisation **/
443 fullscreenButton = new QPushButton( "F" );
444 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
445 setupSmallButton( fullscreenButton );
446 controlLayout->addWidget( fullscreenButton, 3, 10 );
448 /** Playlist Button **/
449 playlistButton = new QPushButton;
450 setupSmallButton( playlistButton );
451 controlLayout->addWidget( playlistButton, 3, 11 );
453 /** extended Settings **/
454 QPushButton *extSettingsButton = new QPushButton( "F" );
455 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
457 setupSmallButton( extSettingsButton );
458 controlLayout->addWidget( extSettingsButton, 3, 12 );
460 controlLayout->setColumnStretch( 14, 5 );
463 VolumeClickHandler *h = new VolumeClickHandler( p_intf, this );
465 volMuteLabel = new QLabel;
466 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
467 volMuteLabel->setToolTip( qtr( "Mute" ) );
468 volMuteLabel->installEventFilter( h );
471 * Change this slider to use a nice Amarok-like one
472 * Add a Context menu to change to the most useful %
475 * THis percerntage thing has to be handled correctly
476 * This has to match to the OSD
478 volumeSlider = new QSlider;
479 volumeSlider->setSizePolicy( sizePolicy );
480 volumeSlider->setMaximumSize( QSize( 80, 200 ) );
481 volumeSlider->setOrientation( Qt::Horizontal );
483 volumeSlider->setMaximum( VOLUME_MAX );
484 volumeSlider->setFocusPolicy( Qt::NoFocus );
485 controlLayout->addWidget( volMuteLabel, 3, 15 );
486 controlLayout->addWidget( volumeSlider, 3, 16, 1, 2 );
488 /* Volume control connection */
489 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
491 ControlsWidget::~ControlsWidget()
494 void ControlsWidget::stop()
499 void ControlsWidget::play()
502 msg_Dbg( p_intf, "There is %i playlist items", THEPL->items.i_size ); /* FIXME: remove me */
503 if( playlist_IsEmpty( THEPL ) )
505 /* The playlist is empty, open a file requester */
506 THEDP->openFileDialog();
510 THEMIM->togglePlayPause();
513 void ControlsWidget::prev()
518 void ControlsWidget::next()
523 void ControlsWidget::setNavigation( int navigation )
525 #define HELP_MENU N_( "Menu" )
526 #define HELP_PCH N_( "Previous chapter" )
527 #define HELP_NCH N_( "Next chapter" )
528 #define HELP_PTR N_( "Previous track" )
529 #define HELP_NTR N_( "Next track" )
531 // 1 = chapter, 2 = title, 0 = no
532 if( navigation == 0 )
535 } else if( navigation == 1 ) {
536 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
537 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
541 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
542 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
548 static bool b_my_volume;
549 void ControlsWidget::updateVolume( int i_sliderVolume )
553 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
554 aout_VolumeSet( p_intf, i_res );
556 if( i_sliderVolume == 0 )
557 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
558 else if( i_sliderVolume < VOLUME_MAX / 2 )
559 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
560 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
563 void ControlsWidget::updateOnTimer()
566 audio_volume_t i_volume;
567 aout_VolumeGet( p_intf, &i_volume );
568 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2) ;
569 int i_gauge = volumeSlider->value();
571 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
574 volumeSlider->setValue( i_volume );
578 /* Activate the interface buttons according to the presence of the input */
579 enableInput( THEMIM->getIM()->hasInput() );
580 //enableVideo( THEMIM->getIM()->hasVideo() );
584 void ControlsWidget::setStatus( int status )
586 if( status == PLAYING_S ) // Playing
587 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
589 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
594 * This functions toggle the fullscreen mode
595 * If there is no video, it should first activate Visualisations...
596 * This has also to be fixed in enableVideo()
598 void ControlsWidget::fullscreen()
600 vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
603 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
604 vlc_object_release( p_vout );
608 void ControlsWidget::extSettings()
610 THEDP->extendedDialog();
613 void ControlsWidget::slower()
615 THEMIM->getIM()->slower();
618 void ControlsWidget::faster()
620 THEMIM->getIM()->faster();
623 void ControlsWidget::enableInput( bool enable )
625 slowerButton->setEnabled( enable );
626 slider->setEnabled( enable );
627 fasterButton->setEnabled( enable );
629 /* Advanced Buttons too */
630 advControls->enableInput( enable );
633 void ControlsWidget::enableVideo( bool enable )
635 // TODO Later make the fullscreenButton toggle Visualisation and so on.
636 fullscreenButton->setEnabled( enable );
638 /* Advanced Buttons too */
639 advControls->enableVideo( enable );
642 void ControlsWidget::toggleAdvanced()
644 if( !VISIBLE( advControls ) )
647 b_advancedVisible = true;
652 b_advancedVisible = false;
654 //FIXME connect this one :D
655 emit advancedControlsToggled( b_advancedVisible ); // doComponentsUpdate();
658 /**********************************************************************
659 * Playlist Widget. The embedded playlist
660 **********************************************************************/
661 #include "components/playlist/panels.hpp"
662 #include "components/playlist/selector.hpp"
664 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i ) :
667 /* Left Part and design */
668 QWidget *leftW = new QWidget( this );
669 QVBoxLayout *left = new QVBoxLayout( leftW );
671 /* Source Selector */
672 selector = new PLSelector( this, p_intf, THEPL );
673 left->addWidget( selector );
676 art = new QLabel( "" );
677 art->setMinimumHeight( 128 );
678 art->setMinimumWidth( 128 );
679 art->setMaximumHeight( 128 );
680 art->setMaximumWidth( 128 );
681 art->setScaledContents( true );
682 art->setPixmap( QPixmap( ":/noart.png" ) );
683 left->addWidget( art );
685 /* Initialisation of the playlist */
686 playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
687 THEPL->p_local_category );
689 rightPanel = qobject_cast<PLPanel *>( new StandardPLPanel( this,
690 p_intf, THEPL, p_root ) );
693 CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
695 CONNECT( qobject_cast<StandardPLPanel *>( rightPanel )->model,
696 artSet( QString ) , this, setArt( QString ) );
697 /* Forward removal requests from the selector to the main panel */
698 CONNECT( qobject_cast<PLSelector *>( selector )->model,
700 qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );
702 connect( selector, SIGNAL( activated( int ) ),
703 this, SIGNAL( rootChanged( int ) ) );
704 emit rootChanged( p_root->i_id );
706 /* Add the two sides of the QSplitter */
708 addWidget( rightPanel );
710 leftW->setMaximumWidth( 250 );
711 setCollapsible( 1, false );
714 sizeList << 180 << 520 ;
715 setSizes( sizeList );
718 void PlaylistWidget::setArt( QString url )
721 art->setPixmap( QPixmap( ":/noart.png" ) );
722 else if( prevArt != url )
723 art->setPixmap( QPixmap( url ) );
728 PlaylistWidget::~PlaylistWidget()
732 QSize PlaylistWidget::sizeHint() const
737 /**********************************************************************
738 * Speed control widget
739 **********************************************************************/
740 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
741 QFrame( NULL ), p_intf( _p_i )
743 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
744 sizePolicy.setHorizontalStretch( 0 );
745 sizePolicy.setVerticalStretch( 0 );
747 speedSlider = new QSlider;
748 speedSlider->setSizePolicy( sizePolicy );
749 speedSlider->setMaximumSize( QSize( 80, 200 ) );
750 speedSlider->setOrientation( Qt::Vertical );
751 speedSlider->setTickPosition( QSlider::TicksRight );
753 speedSlider->setRange( -100, 100 );
754 speedSlider->setSingleStep( 10 );
755 speedSlider->setPageStep( 20 );
756 speedSlider->setTickInterval( 20 );
758 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
760 normalSpeedButton = new QPushButton( "N" );
761 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
762 normalSpeedButton->setFlat( true );
763 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
765 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
767 QVBoxLayout *speedControlLayout = new QVBoxLayout;
768 speedControlLayout->addWidget(speedSlider);
769 speedControlLayout->addWidget(normalSpeedButton);
770 setLayout(speedControlLayout);
773 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);