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"
32 #include "util/customwidgets.hpp"
36 #include <QSpacerItem>
38 #include <QPushButton>
39 #include <QHBoxLayout>
42 #include <QResizeEvent>
45 #define MAX_BG_SIZE 300
47 /**********************************************************************
48 * Video Widget. A simple frame on which video is drawn
49 * This class handles resize issues
50 **********************************************************************/
51 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
52 unsigned int *, unsigned int * );
53 static void DoRelease( intf_thread_t *, void * );
54 static int DoControl( intf_thread_t *, void *, int, va_list );
56 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
58 vlc_mutex_init( p_intf, &lock );
60 CONNECT( this, askResize(), this, SetMinSize() );
61 CONNECT( this, askVideoToShow(), this, show() );
62 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
65 VideoWidget::~VideoWidget()
67 vlc_mutex_lock( &lock );
70 if( !p_intf->psz_switch_intf )
72 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
73 vout_Control( p_vout, VOUT_REPARENT );
77 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
78 vout_Control( p_vout, VOUT_CLOSE );
81 vlc_mutex_unlock( &lock );
82 vlc_mutex_destroy( &lock );
85 QSize VideoWidget::sizeHint() const
90 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
91 unsigned int *pi_width, unsigned int *pi_height )
93 emit askVideoToShow();
96 msg_Dbg( p_intf, "embedded video already in use" );
101 return ( void* )winId();
104 void VideoWidget::SetMinSize()
106 setMinimumSize( 16, 16 );
109 void VideoWidget::release( void *p_win )
113 /**********************************************************************
114 * Background Widget. Show a simple image background. Currently,
115 * it's a static cone.
116 **********************************************************************/
117 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
118 QFrame( NULL ), p_intf( _p_i )
121 setAutoFillBackground( true );
123 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
124 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
126 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred);
129 label->setMaximumHeight( MAX_BG_SIZE );
130 label->setMaximumWidth( MAX_BG_SIZE );
131 label->setScaledContents( true );
132 label->setPixmap( QPixmap( ":/vlc128.png" ) );
133 backgroundLayout = new QHBoxLayout;
134 backgroundLayout->addWidget( label );
135 setLayout( backgroundLayout );
139 BackgroundWidget::~BackgroundWidget()
141 backgroundLayout->takeAt( 0 );
142 delete backgroundLayout;
145 void BackgroundWidget::setArt( QString url )
148 label->setPixmap( QPixmap( ":/vlc128.png" ) );
150 label->setPixmap( QPixmap( url ) );
154 QSize BackgroundWidget::sizeHint() const
156 return label->maximumSize();
159 void BackgroundWidget::resizeEvent( QResizeEvent *e )
161 if( e->size().height() < MAX_BG_SIZE -1 )
163 label->setMaximumWidth( e->size().height() );
164 label->setMaximumHeight( e->size().width() );
168 label->setMaximumHeight( MAX_BG_SIZE );
169 label->setMaximumWidth( MAX_BG_SIZE );
173 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
175 QVLCMenu::PopupMenu( p_intf, true );
177 /**********************************************************************
178 * Visualization selector panel
179 **********************************************************************/
180 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
181 QFrame( NULL ), p_intf( _p_i )
183 QHBoxLayout *layout = new QHBoxLayout( this );
184 layout->setMargin( 0 );
185 QPushButton *prevButton = new QPushButton( "Prev" );
186 QPushButton *nextButton = new QPushButton( "Next" );
187 layout->addWidget( prevButton );
188 layout->addWidget( nextButton );
190 layout->addItem( new QSpacerItem( 40,20,
191 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
192 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
194 current = new QLabel( qtr( "None" ) );
195 layout->addWidget( current );
197 BUTTONACT( prevButton, prev() );
198 BUTTONACT( nextButton, next() );
201 setMaximumHeight( 35 );
204 VisualSelector::~VisualSelector()
209 void VisualSelector::prev()
211 char *psz_new = aout_VisualPrev( p_intf );
214 current->setText( qfu( psz_new ) );
219 void VisualSelector::next()
221 char *psz_new = aout_VisualNext( p_intf );
224 current->setText( qfu( psz_new ) );
229 /**********************************************************************
231 **********************************************************************/
233 #define setupSmallButton( aButton ){ \
234 aButton->setMaximumSize( QSize( 26, 26 ) ); \
235 aButton->setMinimumSize( QSize( 26, 26 ) ); \
236 aButton->setIconSize( QSize( 20, 20 ) ); }
238 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
239 QFrame( NULL ), p_intf( _p_i )
241 QHBoxLayout *advLayout = new QHBoxLayout( this );
242 advLayout->setMargin( 0 );
243 advLayout->setSpacing( 0 );
245 /* FIXME A to B function */
246 ABButton = new QPushButton( "AB" );
247 ABButton->setMaximumSize( QSize( 26, 26 ) );
248 ABButton->setIconSize( QSize( 20, 20 ) );
249 advLayout->addWidget( ABButton );
250 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
253 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
254 this, AtoBLoop( float, int, int ) );
256 //FIXME Frame by frame function
257 frameButton = new QPushButton( "Fr" );
258 frameButton->setMaximumSize( QSize( 26, 26 ) );
259 frameButton->setIconSize( QSize( 20, 20 ) );
260 advLayout->addWidget( frameButton );
261 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
263 /* FIXME Record function */
264 recordButton = new QPushButton( "R" );
265 recordButton->setMaximumSize( QSize( 26, 26 ) );
266 recordButton->setIconSize( QSize( 20, 20 ) );
267 advLayout->addWidget( recordButton );
268 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
269 qtr( "Record" ), record() );
271 snapshotButton = new QPushButton( "S" );
272 snapshotButton->setMaximumSize( QSize( 26, 26 ) );
273 snapshotButton->setIconSize( QSize( 20, 20 ) );
274 advLayout->addWidget( snapshotButton );
275 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
279 AdvControlsWidget::~AdvControlsWidget()
283 void AdvControlsWidget::enableInput( bool enable )
285 ABButton->setEnabled( enable );
286 recordButton->setEnabled( enable );
288 void AdvControlsWidget::enableVideo( bool enable )
290 snapshotButton->setEnabled( enable );
291 frameButton->setEnabled( enable );
294 void AdvControlsWidget::snapshot()
296 vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
297 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
300 void AdvControlsWidget::frame()
304 void AdvControlsWidget::fromAtoB()
308 timeA = var_GetTime( THEMIM->getInput(), "time" );
309 ABButton->setText( "A->..." );
314 timeB = var_GetTime( THEMIM->getInput(), "time" );
315 var_SetTime( THEMIM->getInput(), "time" , timeA );
316 ABButton->setText( "A<=>B" );
321 ABButton->setText( "AB" );
324 void AdvControlsWidget::record(){}
326 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
330 if( i_time >= (int)(timeB/1000000) )
331 var_SetTime( THEMIM->getInput(), "time" , timeA );
335 /*****************************
336 * DA Control Widget !
337 *****************************/
338 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
341 QFrame( NULL ), p_intf( _p_i )
343 controlLayout = new QGridLayout( this );
344 controlLayout->setSpacing( 0 );
345 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Fixed );
347 /** The main Slider **/
348 slider = new InputSlider( Qt::Horizontal, NULL );
349 controlLayout->addWidget( slider, 0, 1, 1, 16 );
350 /* Update the position when the IM has changed */
351 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
352 slider, setPosition( float,int, int ) );
353 /* And update the IM, when the position has changed */
354 CONNECT( slider, sliderDragged( float ),
355 THEMIM->getIM(), sliderUpdate( float ) );
357 /** Slower and faster Buttons **/
358 slowerButton = new QPushButton;
359 slowerButton->setFlat( true );
360 slowerButton->setMaximumSize( QSize( 26, 20 ) );
362 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
363 controlLayout->addWidget( slowerButton, 0, 0 );
365 fasterButton = new QPushButton;
366 fasterButton->setFlat( true );
367 fasterButton->setMaximumSize( QSize( 26, 20 ) );
369 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
370 controlLayout->addWidget( fasterButton, 0, 17 );
372 /* advanced Controls handling */
373 b_advancedVisible = b_advControls;
375 advControls = new AdvControlsWidget( p_intf );
376 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
377 if( !b_advancedVisible ) advControls->hide();
379 /** Disc and Menus handling */
380 discFrame = new QFrame( this );
382 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
383 discLayout->setSpacing( 0 );
384 discLayout->setMargin( 0 );
386 prevSectionButton = new QPushButton( discFrame );
387 setupSmallButton( prevSectionButton );
388 discLayout->addWidget( prevSectionButton );
390 menuButton = new QPushButton( discFrame );
391 setupSmallButton( menuButton );
392 discLayout->addWidget( menuButton );
394 nextSectionButton = new QPushButton( discFrame );
395 setupSmallButton( nextSectionButton );
396 discLayout->addWidget( nextSectionButton );
398 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
400 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
401 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
402 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
406 /* Change the navigation button display when the IM navigation changes */
407 CONNECT( THEMIM->getIM(), navigationChanged( int ),
408 this, setNavigation( int ) );
409 /* Changes the IM navigation when triggered on the nav buttons */
410 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
412 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
414 CONNECT( menuButton, clicked(), THEMIM->getIM(),
419 * Merge with upper menu in a StackLayout
423 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
424 sizePolicy.setHorizontalStretch( 0 );
425 sizePolicy.setVerticalStretch( 0 );
428 playButton = new QPushButton;
429 playButton->setSizePolicy( sizePolicy );
430 playButton->setMaximumSize( QSize( 38, 38 ) );
431 playButton->setMinimumSize( QSize( 45, 45 ) );
432 playButton->setIconSize( QSize( 30, 30 ) );
434 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
436 controlLayout->setColumnMinimumWidth( 2, 20 );
437 controlLayout->setColumnStretch( 2, 0 );
439 /** Prev + Stop + Next Block **/
440 QHBoxLayout *controlButLayout = new QHBoxLayout;
441 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
444 QPushButton *prevButton = new QPushButton;
445 prevButton->setSizePolicy( sizePolicy );
446 setupSmallButton( prevButton );
448 controlButLayout->addWidget( prevButton );
451 QPushButton *stopButton = new QPushButton;
452 stopButton->setSizePolicy( sizePolicy );
453 setupSmallButton( stopButton );
455 controlButLayout->addWidget( stopButton );
458 QPushButton *nextButton = new QPushButton;
459 nextButton->setSizePolicy( sizePolicy );
460 setupSmallButton( nextButton );
462 controlButLayout->addWidget( nextButton );
464 /* Add this block to the main layout */
465 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
467 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
468 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
469 qtr( "Previous" ), prev() );
470 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
471 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
473 controlLayout->setColumnStretch( 7 , 2 );
476 * Other first Line buttons
477 * Might need to be inside a frame to avoid a few resizing pb
480 /** Fullscreen/Visualisation **/
481 fullscreenButton = new QPushButton( "F" );
482 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
483 setupSmallButton( fullscreenButton );
484 controlLayout->addWidget( fullscreenButton, 3, 10 );
486 /** Playlist Button **/
487 playlistButton = new QPushButton;
488 setupSmallButton( playlistButton );
489 controlLayout->addWidget( playlistButton, 3, 11 );
490 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
492 /** extended Settings **/
493 QPushButton *extSettingsButton = new QPushButton( "F" );
494 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
496 setupSmallButton( extSettingsButton );
497 controlLayout->addWidget( extSettingsButton, 3, 12 );
499 controlLayout->setColumnStretch( 14, 5 );
502 VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
504 volMuteLabel = new QLabel;
505 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
506 volMuteLabel->setToolTip( qtr( "Mute" ) );
507 volMuteLabel->installEventFilter( hVolLabel );
508 controlLayout->addWidget( volMuteLabel, 3, 15 );
512 volumeSlider = new SoundSlider( this,
513 config_GetInt( p_intf, "volume-step" ),
514 config_GetInt( p_intf, "qt-volume-complete" ) );
518 volumeSlider = new QSlider( this );
519 volumeSlider->setOrientation( Qt::Horizontal );
521 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
522 volumeSlider->setMinimumSize( QSize( 80, 20 ) );
523 volumeSlider->setFocusPolicy( Qt::NoFocus );
524 controlLayout->addWidget( volumeSlider, 3, 16, 1, 2 );
526 /* Set the volume from the config */
527 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
528 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
530 /* Volume control connection */
531 resize( QSize( 400, 60 ) );
532 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
533 msg_Dbg( p_intf, "controls size: %i - %i", size().width(), size().height() );
535 ControlsWidget::~ControlsWidget()
539 QSize ControlsWidget::sizeHint() const
541 return QSize( 300, 50 );
545 void ControlsWidget::stop()
550 void ControlsWidget::play()
552 if( THEPL->current.i_size == 0 )
554 /* The playlist is empty, open a file requester */
555 THEDP->openFileDialog();
559 THEMIM->togglePlayPause();
562 void ControlsWidget::prev()
567 void ControlsWidget::next()
572 void ControlsWidget::setNavigation( int navigation )
574 #define HELP_MENU N_( "Menu" )
575 #define HELP_PCH N_( "Previous chapter" )
576 #define HELP_NCH N_( "Next chapter" )
577 #define HELP_PTR N_( "Previous track" )
578 #define HELP_NTR N_( "Next track" )
580 // 1 = chapter, 2 = title, 0 = no
581 if( navigation == 0 )
584 } else if( navigation == 1 ) {
585 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
586 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
590 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
591 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
597 static bool b_my_volume;
598 void ControlsWidget::updateVolume( int i_sliderVolume )
602 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
603 aout_VolumeSet( p_intf, i_res );
605 if( i_sliderVolume == 0 )
606 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
607 else if( i_sliderVolume < VOLUME_MAX / 2 )
608 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
609 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
612 void ControlsWidget::updateOnTimer()
615 audio_volume_t i_volume;
616 aout_VolumeGet( p_intf, &i_volume );
617 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
618 int i_gauge = volumeSlider->value();
620 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
623 volumeSlider->setValue( i_volume );
627 /* Activate the interface buttons according to the presence of the input */
628 enableInput( THEMIM->getIM()->hasInput() );
629 //enableVideo( THEMIM->getIM()->hasVideo() );
633 void ControlsWidget::setStatus( int status )
635 if( status == PLAYING_S ) // Playing
636 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
638 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
643 * This functions toggle the fullscreen mode
644 * If there is no video, it should first activate Visualisations...
645 * This has also to be fixed in enableVideo()
647 void ControlsWidget::fullscreen()
649 vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
652 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
653 vlc_object_release( p_vout );
657 void ControlsWidget::extSettings()
659 THEDP->extendedDialog();
662 void ControlsWidget::slower()
664 THEMIM->getIM()->slower();
667 void ControlsWidget::faster()
669 THEMIM->getIM()->faster();
672 void ControlsWidget::enableInput( bool enable )
674 slowerButton->setEnabled( enable );
675 slider->setEnabled( enable );
676 fasterButton->setEnabled( enable );
678 /* Advanced Buttons too */
679 advControls->enableInput( enable );
682 void ControlsWidget::enableVideo( bool enable )
684 // TODO Later make the fullscreenButton toggle Visualisation and so on.
685 fullscreenButton->setEnabled( enable );
687 /* Advanced Buttons too */
688 advControls->enableVideo( enable );
691 void ControlsWidget::toggleAdvanced()
693 if( !VISIBLE( advControls ) )
696 b_advancedVisible = true;
701 b_advancedVisible = false;
703 //FIXME connect this one :D
704 emit advancedControlsToggled( b_advancedVisible ); // doComponentsUpdate();
707 /**********************************************************************
708 * Playlist Widget. The embedded playlist
709 **********************************************************************/
710 #include "components/playlist/panels.hpp"
711 #include "components/playlist/selector.hpp"
713 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i ) :
716 /* Left Part and design */
717 QWidget *leftW = new QWidget( this );
718 QVBoxLayout *left = new QVBoxLayout( leftW );
720 /* Source Selector */
721 selector = new PLSelector( this, p_intf, THEPL );
722 left->addWidget( selector );
725 art = new QLabel( "" );
726 art->setMinimumHeight( 128 );
727 art->setMinimumWidth( 128 );
728 art->setMaximumHeight( 128 );
729 art->setMaximumWidth( 128 );
730 art->setScaledContents( true );
731 art->setPixmap( QPixmap( ":/noart.png" ) );
732 left->addWidget( art );
734 /* Initialisation of the playlist */
735 playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
736 THEPL->p_local_category );
738 rightPanel = qobject_cast<PLPanel *>( new StandardPLPanel( this,
739 p_intf, THEPL, p_root ) );
742 CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
744 CONNECT( qobject_cast<StandardPLPanel *>( rightPanel )->model,
745 artSet( QString ) , this, setArt( QString ) );
746 /* Forward removal requests from the selector to the main panel */
747 CONNECT( qobject_cast<PLSelector *>( selector )->model,
749 qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );
751 connect( selector, SIGNAL( activated( int ) ),
752 this, SIGNAL( rootChanged( int ) ) );
753 emit rootChanged( p_root->i_id );
755 /* Add the two sides of the QSplitter */
757 addWidget( rightPanel );
759 leftW->setMaximumWidth( 250 );
760 setCollapsible( 1, false );
763 sizeList << 180 << 520 ;
764 setSizes( sizeList );
765 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
770 void PlaylistWidget::setArt( QString url )
774 art->setPixmap( QPixmap( ":/noart.png" ) );
777 else if( prevArt != url )
779 art->setPixmap( QPixmap( url ) );
785 QSize PlaylistWidget::sizeHint() const
787 return QSize( 700, 200 );
790 PlaylistWidget::~PlaylistWidget()
794 /**********************************************************************
795 * Speed control widget
796 **********************************************************************/
797 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
798 QFrame( NULL ), p_intf( _p_i )
800 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
801 sizePolicy.setHorizontalStretch( 0 );
802 sizePolicy.setVerticalStretch( 0 );
804 speedSlider = new QSlider;
805 speedSlider->setSizePolicy( sizePolicy );
806 speedSlider->setMaximumSize( QSize( 80, 200 ) );
807 speedSlider->setOrientation( Qt::Vertical );
808 speedSlider->setTickPosition( QSlider::TicksRight );
810 speedSlider->setRange( -100, 100 );
811 speedSlider->setSingleStep( 10 );
812 speedSlider->setPageStep( 20 );
813 speedSlider->setTickInterval( 20 );
815 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
817 normalSpeedButton = new QPushButton( "N" );
818 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
819 normalSpeedButton->setFlat( true );
820 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
822 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
824 QVBoxLayout *speedControlLayout = new QVBoxLayout;
825 speedControlLayout->addWidget(speedSlider);
826 speedControlLayout->addWidget(normalSpeedButton);
827 setLayout(speedControlLayout);
830 SpeedControlWidget::~SpeedControlWidget()
834 #define RATE_SLIDER_MAXIMUM 3.0
835 #define RATE_SLIDER_MINIMUM 0.3
836 #define RATE_SLIDER_LENGTH 100.0
838 void SpeedControlWidget::updateControls( int rate )
840 if( speedSlider->isSliderDown() )
842 //We don't want to change anything if the user is using the slider
847 double speed = INPUT_RATE_DEFAULT / (double)rate;
849 if( rate >= INPUT_RATE_DEFAULT )
851 if( speed < RATE_SLIDER_MINIMUM )
853 sliderValue = speedSlider->minimum();
857 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
858 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
863 if( speed > RATE_SLIDER_MAXIMUM )
865 sliderValue = speedSlider->maximum();
869 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
870 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
874 //Block signals to avoid feedback loop
875 speedSlider->blockSignals( true );
876 speedSlider->setValue( sliderValue );
877 speedSlider->blockSignals( false );
880 void SpeedControlWidget::updateRate( int sliderValue )
884 if( sliderValue < 0.0 )
886 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
887 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ) ;
891 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
892 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
895 THEMIM->getIM()->setRate(rate);
898 void SpeedControlWidget::resetRate()
900 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);