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 <QToolButton>
41 #include <QHBoxLayout>
44 #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 hide(); setMinimumSize( 16, 16 );
61 // CONNECT( this, askResize( int, int ), this, SetSizing( int, int ) );
62 CONNECT( this, askVideoWidgetToShow(), this, show() );
63 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
66 VideoWidget::~VideoWidget()
68 vlc_mutex_lock( &lock );
71 if( !p_intf->psz_switch_intf )
73 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
74 vout_Control( p_vout, VOUT_REPARENT );
78 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
79 vout_Control( p_vout, VOUT_CLOSE );
82 vlc_mutex_unlock( &lock );
83 vlc_mutex_destroy( &lock );
86 QSize VideoWidget::sizeHint() const
92 * Request the video to avoid the conflicts
94 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
95 unsigned int *pi_width, unsigned int *pi_height )
97 emit askVideoWidgetToShow();
100 msg_Dbg( p_intf, "embedded video already in use" );
104 return ( void* )winId();
107 /* Set the Widget to the correct Size */
108 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
111 //updateGeometry(); // Needed for deinterlace
112 msg_Dbg( p_intf, "%i %i", sizeHint().height(), sizeHint().width() );
116 void VideoWidget::release( void *p_win )
122 /**********************************************************************
123 * Background Widget. Show a simple image background. Currently,
124 * it's a static cone.
125 **********************************************************************/
126 #define ICON_SIZE 128
127 #define MAX_BG_SIZE 400
128 #define MIN_BG_SIZE 64
130 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
131 QFrame( NULL ), p_intf( _p_i )
133 /* We should use that one to take the more size it can */
134 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding );
136 /* A dark background */
137 setAutoFillBackground( true );
139 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
140 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
143 /* A cone in the middle */
145 label->setScaledContents( true );
146 label->setMargin( 5 );
147 label->setMaximumHeight( MAX_BG_SIZE );
148 label->setMaximumWidth( MAX_BG_SIZE );
149 label->setMinimumHeight( MIN_BG_SIZE );
150 label->setMinimumWidth( MIN_BG_SIZE );
151 label->setPixmap( QPixmap( ":/vlc128.png" ) );
153 QHBoxLayout *backgroundLayout = new QHBoxLayout( this );
154 backgroundLayout->addWidget( label );
158 CONNECT( THEMIM, inputChanged( input_thread_t *), this, update( input_thread_t * ) );
161 BackgroundWidget::~BackgroundWidget()
166 void BackgroundWidget::update( input_thread_t *p_input )
168 if( !p_input || p_input->b_dead )
170 label->setPixmap( QPixmap( ":/vlc128.png" ) );
175 vlc_object_yield( p_input );
176 char *psz_arturl = input_item_GetArtURL( input_GetItem(p_input) );
177 vlc_object_release( p_input );
178 QString url = qfu( psz_arturl );
179 QString arturl = url.replace( "file://",QString("" ) );
180 if( arturl.isNull() )
181 label->setPixmap( QPixmap( ":/vlc128.png" ) );
184 label->setPixmap( QPixmap( arturl ) );
185 msg_Dbg( p_intf, "changing input b_need_update done %s", psz_arturl );
190 QSize BackgroundWidget::sizeHint() const
192 return label->size();
195 void BackgroundWidget::resizeEvent( QResizeEvent *e )
197 if( e->size().height() < MAX_BG_SIZE -1 )
199 label->setMaximumWidth( e->size().height() );
200 label->setMaximumHeight( e->size().width() );
204 label->setMaximumHeight( MAX_BG_SIZE );
205 label->setMaximumWidth( MAX_BG_SIZE );
209 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
211 QVLCMenu::PopupMenu( p_intf, true );
214 /**********************************************************************
215 * Visualization selector panel
216 **********************************************************************/
217 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
218 QFrame( NULL ), p_intf( _p_i )
220 QHBoxLayout *layout = new QHBoxLayout( this );
221 layout->setMargin( 0 );
222 QPushButton *prevButton = new QPushButton( "Prev" );
223 QPushButton *nextButton = new QPushButton( "Next" );
224 layout->addWidget( prevButton );
225 layout->addWidget( nextButton );
227 layout->addItem( new QSpacerItem( 40,20,
228 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
229 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
231 current = new QLabel( qtr( "None" ) );
232 layout->addWidget( current );
234 BUTTONACT( prevButton, prev() );
235 BUTTONACT( nextButton, next() );
238 setMaximumHeight( 35 );
241 VisualSelector::~VisualSelector()
245 void VisualSelector::prev()
247 char *psz_new = aout_VisualPrev( p_intf );
250 current->setText( qfu( psz_new ) );
255 void VisualSelector::next()
257 char *psz_new = aout_VisualNext( p_intf );
260 current->setText( qfu( psz_new ) );
265 /**********************************************************************
267 **********************************************************************/
269 #define setupSmallButton( aButton ){ \
270 aButton->setMaximumSize( QSize( 26, 26 ) ); \
271 aButton->setMinimumSize( QSize( 26, 26 ) ); \
272 aButton->setIconSize( QSize( 20, 20 ) ); }
274 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
275 QFrame( NULL ), p_intf( _p_i )
277 QHBoxLayout *advLayout = new QHBoxLayout( this );
278 advLayout->setMargin( 0 );
279 advLayout->setSpacing( 0 );
282 ABButton = new QPushButton( "AB" );
283 ABButton->setMaximumSize( QSize( 26, 26 ) );
284 ABButton->setIconSize( QSize( 20, 20 ) );
285 advLayout->addWidget( ABButton );
286 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
288 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
289 this, AtoBLoop( float, int, int ) );
291 frameButton = new QPushButton( "Fr" );
292 frameButton->setMaximumSize( QSize( 26, 26 ) );
293 frameButton->setIconSize( QSize( 20, 20 ) );
294 advLayout->addWidget( frameButton );
295 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
297 recordButton = new QPushButton( "R" );
298 recordButton->setMaximumSize( QSize( 26, 26 ) );
299 recordButton->setIconSize( QSize( 20, 20 ) );
300 advLayout->addWidget( recordButton );
301 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
302 qtr( "Record" ), record() );
304 /* Snapshot Button */
305 snapshotButton = new QPushButton( "S" );
306 snapshotButton->setMaximumSize( QSize( 26, 26 ) );
307 snapshotButton->setIconSize( QSize( 20, 20 ) );
308 advLayout->addWidget( snapshotButton );
309 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
312 AdvControlsWidget::~AdvControlsWidget()
315 void AdvControlsWidget::enableInput( bool enable )
317 ABButton->setEnabled( enable );
318 recordButton->setEnabled( enable );
321 void AdvControlsWidget::enableVideo( bool enable )
323 snapshotButton->setEnabled( enable );
324 frameButton->setEnabled( enable );
327 void AdvControlsWidget::snapshot()
329 vout_thread_t *p_vout =
330 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
331 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
334 /* Function called when the button is clicked() */
335 void AdvControlsWidget::fromAtoB()
339 timeA = var_GetTime( THEMIM->getInput(), "time" );
340 ABButton->setText( "A->..." );
345 timeB = var_GetTime( THEMIM->getInput(), "time" );
346 var_SetTime( THEMIM->getInput(), "time" , timeA );
347 ABButton->setText( "A<=>B" );
352 ABButton->setText( "AB" );
355 /* Function called regularly when in an AtoB loop */
356 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
360 if( i_time >= (int)(timeB/1000000) )
361 var_SetTime( THEMIM->getInput(), "time" , timeA );
365 /* FIXME Record function */
366 void AdvControlsWidget::record(){}
368 //FIXME Frame by frame function
369 void AdvControlsWidget::frame(){}
371 /*****************************
372 * DA Control Widget !
373 *****************************/
374 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
375 MainInterface *_p_mi,
378 QFrame( NULL ), p_intf( _p_i )
380 controlLayout = new QGridLayout( this );
381 controlLayout->setSpacing( 0 );
383 controlLayout->setContentsMargins( 9, 6, 9, 6 );
385 controlLayout->setMargin( 6 );
388 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
390 /** The main Slider **/
391 slider = new InputSlider( Qt::Horizontal, NULL );
392 controlLayout->addWidget( slider, 0, 1, 1, 16 );
393 /* Update the position when the IM has changed */
394 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
395 slider, setPosition( float, int, int ) );
396 /* And update the IM, when the position has changed */
397 CONNECT( slider, sliderDragged( float ),
398 THEMIM->getIM(), sliderUpdate( float ) );
400 /** Slower and faster Buttons **/
401 slowerButton = new QPushButton;
402 slowerButton->setFlat( true );
403 slowerButton->setMaximumSize( QSize( 26, 20 ) );
405 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
406 controlLayout->addWidget( slowerButton, 0, 0 );
408 fasterButton = new QPushButton;
409 fasterButton->setFlat( true );
410 fasterButton->setMaximumSize( QSize( 26, 20 ) );
412 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
413 controlLayout->addWidget( fasterButton, 0, 17 );
415 /* advanced Controls handling */
416 b_advancedVisible = b_advControls;
418 advControls = new AdvControlsWidget( p_intf );
419 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
420 if( !b_advancedVisible ) advControls->hide();
422 /** Disc and Menus handling */
423 discFrame = new QWidget( this );
425 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
426 discLayout->setSpacing( 0 );
427 discLayout->setMargin( 0 );
429 prevSectionButton = new QPushButton( discFrame );
430 setupSmallButton( prevSectionButton );
431 discLayout->addWidget( prevSectionButton );
433 menuButton = new QPushButton( discFrame );
434 setupSmallButton( menuButton );
435 discLayout->addWidget( menuButton );
437 nextSectionButton = new QPushButton( discFrame );
438 setupSmallButton( nextSectionButton );
439 discLayout->addWidget( nextSectionButton );
441 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
443 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
444 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
445 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
449 /* Change the navigation button display when the IM navigation changes */
450 CONNECT( THEMIM->getIM(), navigationChanged( int ),
451 this, setNavigation( int ) );
452 /* Changes the IM navigation when triggered on the nav buttons */
453 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
455 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
457 CONNECT( menuButton, clicked(), THEMIM->getIM(),
461 * Merge with upper menu in a StackLayout
463 telexFrame = new QWidget( this );
464 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
465 telexLayout->setSpacing( 0 );
466 telexLayout->setMargin( 0 );
468 QToolButton *telexOn = new QToolButton;
469 telexOn->setText( qtr( "On" ) );
470 setupSmallButton( telexOn );
471 telexLayout->addWidget( telexOn );
473 QToolButton *telexTransparent = new QToolButton;
474 telexTransparent->setText( qtr( "Transparent" ) );
475 setupSmallButton( telexTransparent );
476 telexLayout->addWidget( telexTransparent );
478 QSpinBox *telexPage = new QSpinBox;
479 telexPage->setRange( 0, 999 );
480 telexPage->setValue( 100 );
481 telexPage->setAlignment( Qt::AlignRight );
482 telexLayout->addWidget( telexPage );
484 controlLayout->addWidget( telexFrame, 1, 10, 2, 3, Qt::AlignBottom );
485 // telexFrame->hide();
487 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
488 telexGotoPage( int ) );
489 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
490 telexToggle( bool ) );
491 CONNECT( telexTransparent, clicked( bool ),
492 THEMIM->getIM(), telexSetTransparency( bool ) );
493 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
494 telexFrame, setVisible( bool ) );
497 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
498 sizePolicy.setHorizontalStretch( 0 );
499 sizePolicy.setVerticalStretch( 0 );
502 playButton = new QPushButton;
503 playButton->setSizePolicy( sizePolicy );
504 playButton->setMaximumSize( QSize( 36, 36 ) );
505 playButton->setMinimumSize( QSize( 36, 36 ) );
506 playButton->setIconSize( QSize( 30, 30 ) );
508 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
510 controlLayout->setColumnMinimumWidth( 2, 20 );
511 controlLayout->setColumnStretch( 2, 0 );
513 /** Prev + Stop + Next Block **/
514 QHBoxLayout *controlButLayout = new QHBoxLayout;
515 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
518 QPushButton *prevButton = new QPushButton;
519 prevButton->setSizePolicy( sizePolicy );
520 setupSmallButton( prevButton );
522 controlButLayout->addWidget( prevButton );
525 QPushButton *stopButton = new QPushButton;
526 stopButton->setSizePolicy( sizePolicy );
527 setupSmallButton( stopButton );
529 controlButLayout->addWidget( stopButton );
532 QPushButton *nextButton = new QPushButton;
533 nextButton->setSizePolicy( sizePolicy );
534 setupSmallButton( nextButton );
536 controlButLayout->addWidget( nextButton );
538 /* Add this block to the main layout */
539 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
541 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
542 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
543 qtr( "Previous" ), prev() );
544 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
545 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
547 controlLayout->setColumnMinimumWidth( 7, 20 );
548 controlLayout->setColumnStretch( 7, 0 );
549 controlLayout->setColumnStretch( 8, 0 );
550 controlLayout->setColumnStretch( 9, 0 );
553 * Other first Line buttons
555 /** Fullscreen/Visualisation **/
556 fullscreenButton = new QPushButton( "F" );
557 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
558 setupSmallButton( fullscreenButton );
559 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
561 /** Playlist Button **/
562 playlistButton = new QPushButton;
563 setupSmallButton( playlistButton );
564 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
565 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
566 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
568 /** extended Settings **/
569 QPushButton *extSettingsButton = new QPushButton( "F" );
570 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
572 setupSmallButton( extSettingsButton );
573 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
575 controlLayout->setColumnStretch( 13, 0 );
576 controlLayout->setColumnMinimumWidth( 13, 24 );
577 controlLayout->setColumnStretch( 14, 5 );
580 VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
582 volMuteLabel = new QLabel;
583 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
584 volMuteLabel->setToolTip( qtr( "Mute" ) );
585 volMuteLabel->installEventFilter( hVolLabel );
586 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
590 volumeSlider = new SoundSlider( this,
591 config_GetInt( p_intf, "volume-step" ),
592 config_GetInt( p_intf, "qt-volume-complete" ) );
596 volumeSlider = new QSlider( this );
597 volumeSlider->setOrientation( Qt::Horizontal );
599 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
600 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
601 volumeSlider->setFocusPolicy( Qt::NoFocus );
602 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
604 /* Set the volume from the config */
605 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
606 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
608 /* Volume control connection */
609 //resize( QSize( 300, 60 ) );
610 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
611 msg_Dbg( p_intf, "controls size: %i - %i", size().width(), size().height() );
614 ControlsWidget::~ControlsWidget()
618 QSize ControlsWidget::sizeHint() const
620 return QSize( 300, 50 );
624 void ControlsWidget::stop()
629 void ControlsWidget::play()
631 if( THEPL->current.i_size == 0 )
633 /* The playlist is empty, open a file requester */
634 THEDP->openFileDialog();
638 THEMIM->togglePlayPause();
641 void ControlsWidget::prev()
646 void ControlsWidget::next()
651 void ControlsWidget::setNavigation( int navigation )
653 #define HELP_MENU N_( "Menu" )
654 #define HELP_PCH N_( "Previous chapter" )
655 #define HELP_NCH N_( "Next chapter" )
656 #define HELP_PTR N_( "Previous track" )
657 #define HELP_NTR N_( "Next track" )
659 // 1 = chapter, 2 = title, 0 = no
660 if( navigation == 0 )
663 } else if( navigation == 1 ) {
664 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
665 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
669 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
670 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
676 static bool b_my_volume;
677 void ControlsWidget::updateVolume( int i_sliderVolume )
681 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
682 aout_VolumeSet( p_intf, i_res );
684 if( i_sliderVolume == 0 )
685 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
686 else if( i_sliderVolume < VOLUME_MAX / 2 )
687 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
688 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
691 void ControlsWidget::updateOnTimer()
694 audio_volume_t i_volume;
695 aout_VolumeGet( p_intf, &i_volume );
696 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
697 int i_gauge = volumeSlider->value();
699 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
702 volumeSlider->setValue( i_volume );
706 /* Activate the interface buttons according to the presence of the input */
707 enableInput( THEMIM->getIM()->hasInput() );
708 //enableVideo( THEMIM->getIM()->hasVideo() );
712 void ControlsWidget::setStatus( int status )
714 if( status == PLAYING_S ) // Playing
715 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
717 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
722 * This functions toggle the fullscreen mode
723 * If there is no video, it should first activate Visualisations...
724 * This has also to be fixed in enableVideo()
726 void ControlsWidget::fullscreen()
728 vout_thread_t *p_vout =
729 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
732 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
733 vlc_object_release( p_vout );
737 void ControlsWidget::extSettings()
739 THEDP->extendedDialog();
742 void ControlsWidget::slower()
744 THEMIM->getIM()->slower();
747 void ControlsWidget::faster()
749 THEMIM->getIM()->faster();
752 void ControlsWidget::enableInput( bool enable )
754 slowerButton->setEnabled( enable );
755 slider->setEnabled( enable );
756 fasterButton->setEnabled( enable );
758 /* Advanced Buttons too */
759 advControls->enableInput( enable );
762 void ControlsWidget::enableVideo( bool enable )
764 // TODO Later make the fullscreenButton toggle Visualisation and so on.
765 fullscreenButton->setEnabled( enable );
767 /* Advanced Buttons too */
768 advControls->enableVideo( enable );
771 void ControlsWidget::toggleAdvanced()
773 if( !VISIBLE( advControls ) )
776 b_advancedVisible = true;
781 b_advancedVisible = false;
783 emit advancedControlsToggled( b_advancedVisible );
787 /**********************************************************************
788 * Speed control widget
789 **********************************************************************/
790 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
791 QFrame( NULL ), p_intf( _p_i )
793 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
794 sizePolicy.setHorizontalStretch( 0 );
795 sizePolicy.setVerticalStretch( 0 );
797 speedSlider = new QSlider;
798 speedSlider->setSizePolicy( sizePolicy );
799 speedSlider->setMaximumSize( QSize( 80, 200 ) );
800 speedSlider->setOrientation( Qt::Vertical );
801 speedSlider->setTickPosition( QSlider::TicksRight );
803 speedSlider->setRange( -100, 100 );
804 speedSlider->setSingleStep( 10 );
805 speedSlider->setPageStep( 20 );
806 speedSlider->setTickInterval( 20 );
808 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
810 normalSpeedButton = new QPushButton( "N" );
811 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
812 normalSpeedButton->setFlat( true );
813 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
815 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
817 QVBoxLayout *speedControlLayout = new QVBoxLayout;
818 speedControlLayout->addWidget(speedSlider);
819 speedControlLayout->addWidget(normalSpeedButton);
820 setLayout(speedControlLayout);
823 SpeedControlWidget::~SpeedControlWidget()
826 #define RATE_SLIDER_MAXIMUM 3.0
827 #define RATE_SLIDER_MINIMUM 0.3
828 #define RATE_SLIDER_LENGTH 100.0
830 void SpeedControlWidget::updateControls( int rate )
832 if( speedSlider->isSliderDown() )
834 //We don't want to change anything if the user is using the slider
839 double speed = INPUT_RATE_DEFAULT / (double)rate;
841 if( rate >= INPUT_RATE_DEFAULT )
843 if( speed < RATE_SLIDER_MINIMUM )
845 sliderValue = speedSlider->minimum();
849 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
850 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
855 if( speed > RATE_SLIDER_MAXIMUM )
857 sliderValue = speedSlider->maximum();
861 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
862 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
866 //Block signals to avoid feedback loop
867 speedSlider->blockSignals( true );
868 speedSlider->setValue( sliderValue );
869 speedSlider->blockSignals( false );
872 void SpeedControlWidget::updateRate( int sliderValue )
876 if( sliderValue < 0.0 )
878 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
879 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH );
883 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
884 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
887 THEMIM->getIM()->setRate(rate);
890 void SpeedControlWidget::resetRate()
892 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);