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 * TODO: Merge with upper menu in a StackLayout
465 telexFrame = new QWidget( this );
466 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
467 telexLayout->setSpacing( 0 );
468 telexLayout->setMargin( 0 );
470 QToolButton *telexOn = new QToolButton;
471 telexOn->setText( qtr( "On" ) );
472 setupSmallButton( telexOn );
473 telexLayout->addWidget( telexOn );
475 QToolButton *telexTransparent = new QToolButton;
476 telexTransparent->setText( qtr( "Transparent" ) );
477 setupSmallButton( telexTransparent );
478 telexLayout->addWidget( telexTransparent );
480 QSpinBox *telexPage = new QSpinBox;
481 telexPage->setRange( 0, 999 );
482 telexPage->setValue( 100 );
483 telexPage->setAlignment( Qt::AlignRight );
484 telexLayout->addWidget( telexPage );
486 controlLayout->addWidget( telexFrame, 1, 10, 2, 3, Qt::AlignBottom );
489 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
490 telexGotoPage( int ) );
491 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
492 telexToggle( bool ) );
493 CONNECT( telexTransparent, clicked( bool ),
494 THEMIM->getIM(), telexSetTransparency( bool ) );
495 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
496 telexFrame, setVisible( bool ) );
500 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
501 sizePolicy.setHorizontalStretch( 0 );
502 sizePolicy.setVerticalStretch( 0 );
505 playButton = new QPushButton;
506 playButton->setSizePolicy( sizePolicy );
507 playButton->setMaximumSize( QSize( 36, 36 ) );
508 playButton->setMinimumSize( QSize( 36, 36 ) );
509 playButton->setIconSize( QSize( 30, 30 ) );
511 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
513 controlLayout->setColumnMinimumWidth( 2, 20 );
514 controlLayout->setColumnStretch( 2, 0 );
516 /** Prev + Stop + Next Block **/
517 QHBoxLayout *controlButLayout = new QHBoxLayout;
518 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
521 QPushButton *prevButton = new QPushButton;
522 prevButton->setSizePolicy( sizePolicy );
523 setupSmallButton( prevButton );
525 controlButLayout->addWidget( prevButton );
528 QPushButton *stopButton = new QPushButton;
529 stopButton->setSizePolicy( sizePolicy );
530 setupSmallButton( stopButton );
532 controlButLayout->addWidget( stopButton );
535 QPushButton *nextButton = new QPushButton;
536 nextButton->setSizePolicy( sizePolicy );
537 setupSmallButton( nextButton );
539 controlButLayout->addWidget( nextButton );
541 /* Add this block to the main layout */
542 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
544 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
545 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
546 qtr( "Previous" ), prev() );
547 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
548 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
550 controlLayout->setColumnMinimumWidth( 7, 20 );
551 controlLayout->setColumnStretch( 7, 0 );
552 controlLayout->setColumnStretch( 8, 0 );
553 controlLayout->setColumnStretch( 9, 0 );
556 * Other first Line buttons
558 /** Fullscreen/Visualisation **/
559 fullscreenButton = new QPushButton( "F" );
560 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
561 setupSmallButton( fullscreenButton );
562 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
564 /** Playlist Button **/
565 playlistButton = new QPushButton;
566 setupSmallButton( playlistButton );
567 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
568 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
569 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
571 /** extended Settings **/
572 QPushButton *extSettingsButton = new QPushButton( "F" );
573 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
575 setupSmallButton( extSettingsButton );
576 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
578 controlLayout->setColumnStretch( 13, 0 );
579 controlLayout->setColumnMinimumWidth( 13, 24 );
580 controlLayout->setColumnStretch( 14, 5 );
583 VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
585 volMuteLabel = new QLabel;
586 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
587 volMuteLabel->setToolTip( qtr( "Mute" ) );
588 volMuteLabel->installEventFilter( hVolLabel );
589 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
593 volumeSlider = new SoundSlider( this,
594 config_GetInt( p_intf, "volume-step" ),
595 config_GetInt( p_intf, "qt-volume-complete" ) );
599 volumeSlider = new QSlider( this );
600 volumeSlider->setOrientation( Qt::Horizontal );
602 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
603 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
604 volumeSlider->setFocusPolicy( Qt::NoFocus );
605 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
607 /* Set the volume from the config */
608 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
609 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
611 /* Volume control connection */
612 //resize( QSize( 300, 60 ) );
613 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
614 msg_Dbg( p_intf, "controls size: %i - %i", size().width(), size().height() );
617 ControlsWidget::~ControlsWidget()
621 QSize ControlsWidget::sizeHint() const
623 return QSize( 300, 50 );
627 void ControlsWidget::stop()
632 void ControlsWidget::play()
634 if( THEPL->current.i_size == 0 )
636 /* The playlist is empty, open a file requester */
637 THEDP->openFileDialog();
641 THEMIM->togglePlayPause();
644 void ControlsWidget::prev()
649 void ControlsWidget::next()
654 void ControlsWidget::setNavigation( int navigation )
656 #define HELP_MENU N_( "Menu" )
657 #define HELP_PCH N_( "Previous chapter" )
658 #define HELP_NCH N_( "Next chapter" )
659 #define HELP_PTR N_( "Previous track" )
660 #define HELP_NTR N_( "Next track" )
662 // 1 = chapter, 2 = title, 0 = no
663 if( navigation == 0 )
666 } else if( navigation == 1 ) {
667 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
668 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
672 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
673 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
679 static bool b_my_volume;
680 void ControlsWidget::updateVolume( int i_sliderVolume )
684 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
685 aout_VolumeSet( p_intf, i_res );
687 if( i_sliderVolume == 0 )
688 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
689 else if( i_sliderVolume < VOLUME_MAX / 2 )
690 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
691 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
694 void ControlsWidget::updateOnTimer()
697 audio_volume_t i_volume;
698 aout_VolumeGet( p_intf, &i_volume );
699 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
700 int i_gauge = volumeSlider->value();
702 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
705 volumeSlider->setValue( i_volume );
709 /* Activate the interface buttons according to the presence of the input */
710 enableInput( THEMIM->getIM()->hasInput() );
711 //enableVideo( THEMIM->getIM()->hasVideo() );
715 void ControlsWidget::setStatus( int status )
717 if( status == PLAYING_S ) // Playing
718 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
720 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
725 * This functions toggle the fullscreen mode
726 * If there is no video, it should first activate Visualisations...
727 * This has also to be fixed in enableVideo()
729 void ControlsWidget::fullscreen()
731 vout_thread_t *p_vout =
732 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
735 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
736 vlc_object_release( p_vout );
740 void ControlsWidget::extSettings()
742 THEDP->extendedDialog();
745 void ControlsWidget::slower()
747 THEMIM->getIM()->slower();
750 void ControlsWidget::faster()
752 THEMIM->getIM()->faster();
755 void ControlsWidget::enableInput( bool enable )
757 slowerButton->setEnabled( enable );
758 slider->setEnabled( enable );
759 fasterButton->setEnabled( enable );
761 /* Advanced Buttons too */
762 advControls->enableInput( enable );
765 void ControlsWidget::enableVideo( bool enable )
767 // TODO Later make the fullscreenButton toggle Visualisation and so on.
768 fullscreenButton->setEnabled( enable );
770 /* Advanced Buttons too */
771 advControls->enableVideo( enable );
774 void ControlsWidget::toggleAdvanced()
776 if( !VISIBLE( advControls ) )
779 b_advancedVisible = true;
784 b_advancedVisible = false;
786 emit advancedControlsToggled( b_advancedVisible );
790 /**********************************************************************
791 * Speed control widget
792 **********************************************************************/
793 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
794 QFrame( NULL ), p_intf( _p_i )
796 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
797 sizePolicy.setHorizontalStretch( 0 );
798 sizePolicy.setVerticalStretch( 0 );
800 speedSlider = new QSlider;
801 speedSlider->setSizePolicy( sizePolicy );
802 speedSlider->setMaximumSize( QSize( 80, 200 ) );
803 speedSlider->setOrientation( Qt::Vertical );
804 speedSlider->setTickPosition( QSlider::TicksRight );
806 speedSlider->setRange( -100, 100 );
807 speedSlider->setSingleStep( 10 );
808 speedSlider->setPageStep( 20 );
809 speedSlider->setTickInterval( 20 );
811 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
813 normalSpeedButton = new QPushButton( "N" );
814 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
815 normalSpeedButton->setFlat( true );
816 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
818 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
820 QVBoxLayout *speedControlLayout = new QVBoxLayout;
821 speedControlLayout->addWidget(speedSlider);
822 speedControlLayout->addWidget(normalSpeedButton);
823 setLayout(speedControlLayout);
826 SpeedControlWidget::~SpeedControlWidget()
829 #define RATE_SLIDER_MAXIMUM 3.0
830 #define RATE_SLIDER_MINIMUM 0.3
831 #define RATE_SLIDER_LENGTH 100.0
833 void SpeedControlWidget::updateControls( int rate )
835 if( speedSlider->isSliderDown() )
837 //We don't want to change anything if the user is using the slider
842 double speed = INPUT_RATE_DEFAULT / (double)rate;
844 if( rate >= INPUT_RATE_DEFAULT )
846 if( speed < RATE_SLIDER_MINIMUM )
848 sliderValue = speedSlider->minimum();
852 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
853 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
858 if( speed > RATE_SLIDER_MAXIMUM )
860 sliderValue = speedSlider->maximum();
864 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
865 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
869 //Block signals to avoid feedback loop
870 speedSlider->blockSignals( true );
871 speedSlider->setValue( sliderValue );
872 speedSlider->blockSignals( false );
875 void SpeedControlWidget::updateRate( int sliderValue )
879 if( sliderValue < 0.0 )
881 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
882 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH );
886 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
887 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
890 THEMIM->getIM()->setRate(rate);
893 void SpeedControlWidget::resetRate()
895 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);