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 )
110 widgetSize = QSize( w, h );
112 //updateGeometry(); // Needed for deinterlace
113 msg_Dbg( p_intf, "%i %i", sizeHint().height(), sizeHint().width() );
117 void VideoWidget::release( void *p_win )
123 /**********************************************************************
124 * Background Widget. Show a simple image background. Currently,
125 * it's a static cone.
126 **********************************************************************/
127 #define ICON_SIZE 128
128 #define MAX_BG_SIZE 400
129 #define MIN_BG_SIZE 64
131 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
132 QFrame( NULL ), p_intf( _p_i )
134 /* We should use that one to take the more size it can */
135 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding );
137 /* A dark background */
138 setAutoFillBackground( true );
140 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
141 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
144 /* A cone in the middle */
146 label->setScaledContents( true );
147 label->setMargin( 5 );
148 label->setMaximumHeight( MAX_BG_SIZE );
149 label->setMaximumWidth( MAX_BG_SIZE );
150 label->setMinimumHeight( MIN_BG_SIZE );
151 label->setMinimumWidth( MIN_BG_SIZE );
152 label->setPixmap( QPixmap( ":/vlc128.png" ) );
154 QHBoxLayout *backgroundLayout = new QHBoxLayout( this );
155 backgroundLayout->addWidget( label );
159 CONNECT( THEMIM, inputChanged( input_thread_t *), this, update( input_thread_t * ) );
162 BackgroundWidget::~BackgroundWidget()
167 void BackgroundWidget::update( input_thread_t *p_input )
169 if( !p_input || p_input->b_dead )
171 label->setPixmap( QPixmap( ":/vlc128.png" ) );
176 vlc_object_yield( p_input );
177 char *psz_arturl = input_item_GetArtURL( input_GetItem(p_input) );
178 vlc_object_release( p_input );
179 QString url = qfu( psz_arturl );
180 QString arturl = url.replace( "file://",QString("" ) );
181 if( arturl.isNull() )
182 label->setPixmap( QPixmap( ":/vlc128.png" ) );
185 label->setPixmap( QPixmap( arturl ) );
186 msg_Dbg( p_intf, "changing input b_need_update done %s", psz_arturl );
191 QSize BackgroundWidget::sizeHint() const
193 return label->size();
196 void BackgroundWidget::resizeEvent( QResizeEvent *e )
198 if( e->size().height() < MAX_BG_SIZE -1 )
200 label->setMaximumWidth( e->size().height() );
201 label->setMaximumHeight( e->size().width() );
205 label->setMaximumHeight( MAX_BG_SIZE );
206 label->setMaximumWidth( MAX_BG_SIZE );
210 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
212 QVLCMenu::PopupMenu( p_intf, true );
215 /**********************************************************************
216 * Visualization selector panel
217 **********************************************************************/
218 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
219 QFrame( NULL ), p_intf( _p_i )
221 QHBoxLayout *layout = new QHBoxLayout( this );
222 layout->setMargin( 0 );
223 QPushButton *prevButton = new QPushButton( "Prev" );
224 QPushButton *nextButton = new QPushButton( "Next" );
225 layout->addWidget( prevButton );
226 layout->addWidget( nextButton );
228 layout->addItem( new QSpacerItem( 40,20,
229 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
230 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
232 current = new QLabel( qtr( "None" ) );
233 layout->addWidget( current );
235 BUTTONACT( prevButton, prev() );
236 BUTTONACT( nextButton, next() );
239 setMaximumHeight( 35 );
242 VisualSelector::~VisualSelector()
246 void VisualSelector::prev()
248 char *psz_new = aout_VisualPrev( p_intf );
251 current->setText( qfu( psz_new ) );
256 void VisualSelector::next()
258 char *psz_new = aout_VisualNext( p_intf );
261 current->setText( qfu( psz_new ) );
266 /**********************************************************************
268 **********************************************************************/
270 #define setupSmallButton( aButton ){ \
271 aButton->setMaximumSize( QSize( 26, 26 ) ); \
272 aButton->setMinimumSize( QSize( 26, 26 ) ); \
273 aButton->setIconSize( QSize( 20, 20 ) ); }
275 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
276 QFrame( NULL ), p_intf( _p_i )
278 QHBoxLayout *advLayout = new QHBoxLayout( this );
279 advLayout->setMargin( 0 );
280 advLayout->setSpacing( 0 );
283 ABButton = new QPushButton( "AB" );
284 ABButton->setMaximumSize( QSize( 26, 26 ) );
285 ABButton->setIconSize( QSize( 20, 20 ) );
286 advLayout->addWidget( ABButton );
287 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
289 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
290 this, AtoBLoop( float, int, int ) );
292 frameButton = new QPushButton( "Fr" );
293 frameButton->setMaximumSize( QSize( 26, 26 ) );
294 frameButton->setIconSize( QSize( 20, 20 ) );
295 advLayout->addWidget( frameButton );
296 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
298 recordButton = new QPushButton( "R" );
299 recordButton->setMaximumSize( QSize( 26, 26 ) );
300 recordButton->setIconSize( QSize( 20, 20 ) );
301 advLayout->addWidget( recordButton );
302 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
303 qtr( "Record" ), record() );
305 /* Snapshot Button */
306 snapshotButton = new QPushButton( "S" );
307 snapshotButton->setMaximumSize( QSize( 26, 26 ) );
308 snapshotButton->setIconSize( QSize( 20, 20 ) );
309 advLayout->addWidget( snapshotButton );
310 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
313 AdvControlsWidget::~AdvControlsWidget()
316 void AdvControlsWidget::enableInput( bool enable )
318 ABButton->setEnabled( enable );
319 recordButton->setEnabled( enable );
322 void AdvControlsWidget::enableVideo( bool enable )
324 snapshotButton->setEnabled( enable );
325 frameButton->setEnabled( enable );
328 void AdvControlsWidget::snapshot()
330 vout_thread_t *p_vout =
331 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
332 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
335 /* Function called when the button is clicked() */
336 void AdvControlsWidget::fromAtoB()
340 timeA = var_GetTime( THEMIM->getInput(), "time" );
341 ABButton->setText( "A->..." );
346 timeB = var_GetTime( THEMIM->getInput(), "time" );
347 var_SetTime( THEMIM->getInput(), "time" , timeA );
348 ABButton->setText( "A<=>B" );
353 ABButton->setText( "AB" );
356 /* Function called regularly when in an AtoB loop */
357 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
361 if( i_time >= (int)(timeB/1000000) )
362 var_SetTime( THEMIM->getInput(), "time" , timeA );
366 /* FIXME Record function */
367 void AdvControlsWidget::record(){}
369 //FIXME Frame by frame function
370 void AdvControlsWidget::frame(){}
372 /*****************************
373 * DA Control Widget !
374 *****************************/
375 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
376 MainInterface *_p_mi,
379 QFrame( NULL ), p_intf( _p_i )
381 controlLayout = new QGridLayout( this );
382 controlLayout->setSpacing( 0 );
384 controlLayout->setContentsMargins( 9, 6, 9, 6 );
386 controlLayout->setMargin( 6 );
389 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
391 /** The main Slider **/
392 slider = new InputSlider( Qt::Horizontal, NULL );
393 controlLayout->addWidget( slider, 0, 1, 1, 16 );
394 /* Update the position when the IM has changed */
395 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
396 slider, setPosition( float, int, int ) );
397 /* And update the IM, when the position has changed */
398 CONNECT( slider, sliderDragged( float ),
399 THEMIM->getIM(), sliderUpdate( float ) );
401 /** Slower and faster Buttons **/
402 slowerButton = new QPushButton;
403 slowerButton->setFlat( true );
404 slowerButton->setMaximumSize( QSize( 26, 20 ) );
406 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
407 controlLayout->addWidget( slowerButton, 0, 0 );
409 fasterButton = new QPushButton;
410 fasterButton->setFlat( true );
411 fasterButton->setMaximumSize( QSize( 26, 20 ) );
413 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
414 controlLayout->addWidget( fasterButton, 0, 17 );
416 /* advanced Controls handling */
417 b_advancedVisible = b_advControls;
419 advControls = new AdvControlsWidget( p_intf );
420 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
421 if( !b_advancedVisible ) advControls->hide();
423 /** Disc and Menus handling */
424 discFrame = new QWidget( this );
426 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
427 discLayout->setSpacing( 0 );
428 discLayout->setMargin( 0 );
430 prevSectionButton = new QPushButton( discFrame );
431 setupSmallButton( prevSectionButton );
432 discLayout->addWidget( prevSectionButton );
434 menuButton = new QPushButton( discFrame );
435 setupSmallButton( menuButton );
436 discLayout->addWidget( menuButton );
438 nextSectionButton = new QPushButton( discFrame );
439 setupSmallButton( nextSectionButton );
440 discLayout->addWidget( nextSectionButton );
442 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
444 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
445 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
446 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
450 /* Change the navigation button display when the IM navigation changes */
451 CONNECT( THEMIM->getIM(), navigationChanged( int ),
452 this, setNavigation( int ) );
453 /* Changes the IM navigation when triggered on the nav buttons */
454 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
456 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
458 CONNECT( menuButton, clicked(), THEMIM->getIM(),
462 * Merge with upper menu in a StackLayout
464 telexFrame = new QWidget( this );
465 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
466 telexLayout->setSpacing( 0 );
467 telexLayout->setMargin( 0 );
469 QToolButton *telexOn = new QToolButton;
470 telexOn->setText( qtr( "On" ) );
471 setupSmallButton( telexOn );
472 telexLayout->addWidget( telexOn );
474 QToolButton *telexTransparent = new QToolButton;
475 telexTransparent->setText( qtr( "Transparent" ) );
476 setupSmallButton( telexTransparent );
477 telexLayout->addWidget( telexTransparent );
479 QSpinBox *telexPage = new QSpinBox;
480 telexPage->setRange( 0, 999 );
481 telexPage->setValue( 100 );
482 telexPage->setAlignment( Qt::AlignRight );
483 telexLayout->addWidget( telexPage );
485 controlLayout->addWidget( telexFrame, 1, 10, 2, 3, Qt::AlignBottom );
488 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
489 telexGotoPage( int ) );
490 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
491 telexToggle( bool ) );
492 CONNECT( telexTransparent, clicked( bool ),
493 THEMIM->getIM(), telexSetTransparency( bool ) );
494 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
495 telexFrame, setVisible( bool ) );
498 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
499 sizePolicy.setHorizontalStretch( 0 );
500 sizePolicy.setVerticalStretch( 0 );
503 playButton = new QPushButton;
504 playButton->setSizePolicy( sizePolicy );
505 playButton->setMaximumSize( QSize( 36, 36 ) );
506 playButton->setMinimumSize( QSize( 36, 36 ) );
507 playButton->setIconSize( QSize( 30, 30 ) );
509 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
511 controlLayout->setColumnMinimumWidth( 2, 20 );
512 controlLayout->setColumnStretch( 2, 0 );
514 /** Prev + Stop + Next Block **/
515 QHBoxLayout *controlButLayout = new QHBoxLayout;
516 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
519 QPushButton *prevButton = new QPushButton;
520 prevButton->setSizePolicy( sizePolicy );
521 setupSmallButton( prevButton );
523 controlButLayout->addWidget( prevButton );
526 QPushButton *stopButton = new QPushButton;
527 stopButton->setSizePolicy( sizePolicy );
528 setupSmallButton( stopButton );
530 controlButLayout->addWidget( stopButton );
533 QPushButton *nextButton = new QPushButton;
534 nextButton->setSizePolicy( sizePolicy );
535 setupSmallButton( nextButton );
537 controlButLayout->addWidget( nextButton );
539 /* Add this block to the main layout */
540 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
542 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
543 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
544 qtr( "Previous" ), prev() );
545 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
546 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
548 controlLayout->setColumnMinimumWidth( 7, 20 );
549 controlLayout->setColumnStretch( 7, 0 );
550 controlLayout->setColumnStretch( 8, 0 );
551 controlLayout->setColumnStretch( 9, 0 );
554 * Other first Line buttons
556 /** Fullscreen/Visualisation **/
557 fullscreenButton = new QPushButton( "F" );
558 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
559 setupSmallButton( fullscreenButton );
560 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
562 /** Playlist Button **/
563 playlistButton = new QPushButton;
564 setupSmallButton( playlistButton );
565 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
566 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
567 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
569 /** extended Settings **/
570 QPushButton *extSettingsButton = new QPushButton( "F" );
571 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
573 setupSmallButton( extSettingsButton );
574 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
576 controlLayout->setColumnStretch( 13, 0 );
577 controlLayout->setColumnMinimumWidth( 13, 24 );
578 controlLayout->setColumnStretch( 14, 5 );
581 VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
583 volMuteLabel = new QLabel;
584 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
585 volMuteLabel->setToolTip( qtr( "Mute" ) );
586 volMuteLabel->installEventFilter( hVolLabel );
587 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
591 volumeSlider = new SoundSlider( this,
592 config_GetInt( p_intf, "volume-step" ),
593 config_GetInt( p_intf, "qt-volume-complete" ) );
597 volumeSlider = new QSlider( this );
598 volumeSlider->setOrientation( Qt::Horizontal );
600 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
601 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
602 volumeSlider->setFocusPolicy( Qt::NoFocus );
603 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
605 /* Set the volume from the config */
606 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
607 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
609 /* Volume control connection */
610 //resize( QSize( 300, 60 ) );
611 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
612 msg_Dbg( p_intf, "controls size: %i - %i", size().width(), size().height() );
615 ControlsWidget::~ControlsWidget()
619 QSize ControlsWidget::sizeHint() const
621 return QSize( 300, 50 );
625 void ControlsWidget::stop()
630 void ControlsWidget::play()
632 if( THEPL->current.i_size == 0 )
634 /* The playlist is empty, open a file requester */
635 THEDP->openFileDialog();
639 THEMIM->togglePlayPause();
642 void ControlsWidget::prev()
647 void ControlsWidget::next()
652 void ControlsWidget::setNavigation( int navigation )
654 #define HELP_MENU N_( "Menu" )
655 #define HELP_PCH N_( "Previous chapter" )
656 #define HELP_NCH N_( "Next chapter" )
657 #define HELP_PTR N_( "Previous track" )
658 #define HELP_NTR N_( "Next track" )
660 // 1 = chapter, 2 = title, 0 = no
661 if( navigation == 0 )
664 } else if( navigation == 1 ) {
665 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
666 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
670 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
671 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
677 static bool b_my_volume;
678 void ControlsWidget::updateVolume( int i_sliderVolume )
682 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
683 aout_VolumeSet( p_intf, i_res );
685 if( i_sliderVolume == 0 )
686 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
687 else if( i_sliderVolume < VOLUME_MAX / 2 )
688 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
689 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
692 void ControlsWidget::updateOnTimer()
695 audio_volume_t i_volume;
696 aout_VolumeGet( p_intf, &i_volume );
697 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
698 int i_gauge = volumeSlider->value();
700 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
703 volumeSlider->setValue( i_volume );
707 /* Activate the interface buttons according to the presence of the input */
708 enableInput( THEMIM->getIM()->hasInput() );
709 //enableVideo( THEMIM->getIM()->hasVideo() );
713 void ControlsWidget::setStatus( int status )
715 if( status == PLAYING_S ) // Playing
716 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
718 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
723 * This functions toggle the fullscreen mode
724 * If there is no video, it should first activate Visualisations...
725 * This has also to be fixed in enableVideo()
727 void ControlsWidget::fullscreen()
729 vout_thread_t *p_vout =
730 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
733 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
734 vlc_object_release( p_vout );
738 void ControlsWidget::extSettings()
740 THEDP->extendedDialog();
743 void ControlsWidget::slower()
745 THEMIM->getIM()->slower();
748 void ControlsWidget::faster()
750 THEMIM->getIM()->faster();
753 void ControlsWidget::enableInput( bool enable )
755 slowerButton->setEnabled( enable );
756 slider->setEnabled( enable );
757 fasterButton->setEnabled( enable );
759 /* Advanced Buttons too */
760 advControls->enableInput( enable );
763 void ControlsWidget::enableVideo( bool enable )
765 // TODO Later make the fullscreenButton toggle Visualisation and so on.
766 fullscreenButton->setEnabled( enable );
768 /* Advanced Buttons too */
769 advControls->enableVideo( enable );
772 void ControlsWidget::toggleAdvanced()
774 if( !VISIBLE( advControls ) )
777 b_advancedVisible = true;
782 b_advancedVisible = false;
784 emit advancedControlsToggled( b_advancedVisible );
788 /**********************************************************************
789 * Speed control widget
790 **********************************************************************/
791 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
792 QFrame( NULL ), p_intf( _p_i )
794 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
795 sizePolicy.setHorizontalStretch( 0 );
796 sizePolicy.setVerticalStretch( 0 );
798 speedSlider = new QSlider;
799 speedSlider->setSizePolicy( sizePolicy );
800 speedSlider->setMaximumSize( QSize( 80, 200 ) );
801 speedSlider->setOrientation( Qt::Vertical );
802 speedSlider->setTickPosition( QSlider::TicksRight );
804 speedSlider->setRange( -100, 100 );
805 speedSlider->setSingleStep( 10 );
806 speedSlider->setPageStep( 20 );
807 speedSlider->setTickInterval( 20 );
809 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
811 normalSpeedButton = new QPushButton( "N" );
812 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
813 normalSpeedButton->setFlat( true );
814 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
816 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
818 QVBoxLayout *speedControlLayout = new QVBoxLayout;
819 speedControlLayout->addWidget(speedSlider);
820 speedControlLayout->addWidget(normalSpeedButton);
821 setLayout(speedControlLayout);
824 SpeedControlWidget::~SpeedControlWidget()
827 #define RATE_SLIDER_MAXIMUM 3.0
828 #define RATE_SLIDER_MINIMUM 0.3
829 #define RATE_SLIDER_LENGTH 100.0
831 void SpeedControlWidget::updateControls( int rate )
833 if( speedSlider->isSliderDown() )
835 //We don't want to change anything if the user is using the slider
840 double speed = INPUT_RATE_DEFAULT / (double)rate;
842 if( rate >= INPUT_RATE_DEFAULT )
844 if( speed < RATE_SLIDER_MINIMUM )
846 sliderValue = speedSlider->minimum();
850 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
851 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
856 if( speed > RATE_SLIDER_MAXIMUM )
858 sliderValue = speedSlider->maximum();
862 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
863 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
867 //Block signals to avoid feedback loop
868 speedSlider->blockSignals( true );
869 speedSlider->setValue( sliderValue );
870 speedSlider->blockSignals( false );
873 void SpeedControlWidget::updateRate( int sliderValue )
877 if( sliderValue < 0.0 )
879 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
880 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH );
884 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
885 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
888 THEMIM->getIM()->setRate(rate);
891 void SpeedControlWidget::resetRate()
893 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);