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>
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 hide(); setMinimumSize( 16, 16 );
62 // CONNECT( this, askResize( int, int ), this, SetSizing( int, int ) );
63 CONNECT( this, askVideoWidgetToShow(), this, show() );
64 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
67 VideoWidget::~VideoWidget()
69 vlc_mutex_lock( &lock );
72 if( !p_intf->psz_switch_intf )
74 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
75 vout_Control( p_vout, VOUT_REPARENT );
79 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
80 vout_Control( p_vout, VOUT_CLOSE );
83 vlc_mutex_unlock( &lock );
84 vlc_mutex_destroy( &lock );
88 * Request the video to avoid the conflicts
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 askVideoWidgetToShow();
96 msg_Dbg( p_intf, "embedded video already in use" );
100 return ( void* )winId();
103 /* Set the Widget to the correct Size */
104 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
107 //updateGeometry(); // Needed for deinterlace
108 msg_Dbg( p_intf, "%i %i", sizeHint().height(), sizeHint().width() );
112 void VideoWidget::release( void *p_win )
118 /**********************************************************************
119 * Background Widget. Show a simple image background. Currently,
120 * it's a static cone.
121 **********************************************************************/
122 #define ICON_SIZE 128
123 #define MAX_BG_SIZE 400
124 #define MIN_BG_SIZE 64
126 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
127 QWidget( NULL ), p_intf( _p_i )
129 /* We should use that one to take the more size it can */
130 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
132 /* A dark background */
133 setAutoFillBackground( true );
135 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
136 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
139 /* A cone in the middle */
141 label->setMargin( 5 );
142 label->setMaximumHeight( MAX_BG_SIZE );
143 label->setMaximumWidth( MAX_BG_SIZE );
144 label->setMinimumHeight( MIN_BG_SIZE );
145 label->setMinimumWidth( MIN_BG_SIZE );
146 if( QDate::currentDate().dayOfYear() >= 354 )
147 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
149 label->setPixmap( QPixmap( ":/vlc128.png" ) );
151 QGridLayout *backgroundLayout = new QGridLayout( this );
152 backgroundLayout->addWidget( label, 0, 1 );
153 backgroundLayout->setColumnStretch( 0, 1 );
154 backgroundLayout->setColumnStretch( 2, 1 );
156 CONNECT( THEMIM, inputChanged( input_thread_t *),
157 this, update( input_thread_t * ) );
161 BackgroundWidget::~BackgroundWidget()
165 void BackgroundWidget::update( input_thread_t *p_input )
167 if( !p_input || p_input->b_dead )
169 if( QDate::currentDate().dayOfYear() >= 354 )
170 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
172 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 );
180 QString arturl = qfu( psz_arturl ).replace( "file://",QString("" ) );
181 if( arturl.isNull() )
183 if( QDate::currentDate().dayOfYear() >= 354 )
184 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
186 label->setPixmap( QPixmap( ":/vlc128.png" ) );
190 label->setPixmap( QPixmap( arturl ) );
191 msg_Dbg( p_intf, "changing input b_need_update done %s", psz_arturl );
196 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
198 QVLCMenu::PopupMenu( p_intf, true );
201 /**********************************************************************
202 * Visualization selector panel
203 **********************************************************************/
204 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
205 QFrame( NULL ), p_intf( _p_i )
207 QHBoxLayout *layout = new QHBoxLayout( this );
208 layout->setMargin( 0 );
209 QPushButton *prevButton = new QPushButton( "Prev" );
210 QPushButton *nextButton = new QPushButton( "Next" );
211 layout->addWidget( prevButton );
212 layout->addWidget( nextButton );
214 layout->addItem( new QSpacerItem( 40,20,
215 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
216 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
218 current = new QLabel( qtr( "None" ) );
219 layout->addWidget( current );
221 BUTTONACT( prevButton, prev() );
222 BUTTONACT( nextButton, next() );
225 setMaximumHeight( 35 );
228 VisualSelector::~VisualSelector()
232 void VisualSelector::prev()
234 char *psz_new = aout_VisualPrev( p_intf );
237 current->setText( qfu( psz_new ) );
242 void VisualSelector::next()
244 char *psz_new = aout_VisualNext( p_intf );
247 current->setText( qfu( psz_new ) );
252 /**********************************************************************
254 **********************************************************************/
256 #define setupSmallButton( aButton ){ \
257 aButton->setMaximumSize( QSize( 26, 26 ) ); \
258 aButton->setMinimumSize( QSize( 26, 26 ) ); \
259 aButton->setIconSize( QSize( 20, 20 ) ); }
261 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
262 QFrame( NULL ), p_intf( _p_i )
264 QHBoxLayout *advLayout = new QHBoxLayout( this );
265 advLayout->setMargin( 0 );
266 advLayout->setSpacing( 0 );
269 ABButton = new QPushButton( "AB" );
270 ABButton->setMaximumSize( QSize( 26, 26 ) );
271 ABButton->setIconSize( QSize( 20, 20 ) );
272 advLayout->addWidget( ABButton );
273 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
275 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
276 this, AtoBLoop( float, int, int ) );
278 frameButton = new QPushButton( "Fr" );
279 frameButton->setMaximumSize( QSize( 26, 26 ) );
280 frameButton->setIconSize( QSize( 20, 20 ) );
281 advLayout->addWidget( frameButton );
282 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
284 recordButton = new QPushButton( "R" );
285 recordButton->setMaximumSize( QSize( 26, 26 ) );
286 recordButton->setIconSize( QSize( 20, 20 ) );
287 advLayout->addWidget( recordButton );
288 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
289 qtr( "Record" ), record() );
291 /* Snapshot Button */
292 snapshotButton = new QPushButton( "S" );
293 snapshotButton->setMaximumSize( QSize( 26, 26 ) );
294 snapshotButton->setIconSize( QSize( 20, 20 ) );
295 advLayout->addWidget( snapshotButton );
296 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
299 AdvControlsWidget::~AdvControlsWidget()
302 void AdvControlsWidget::enableInput( bool enable )
304 ABButton->setEnabled( enable );
305 recordButton->setEnabled( enable );
308 void AdvControlsWidget::enableVideo( bool enable )
310 snapshotButton->setEnabled( enable );
311 frameButton->setEnabled( enable );
314 void AdvControlsWidget::snapshot()
316 vout_thread_t *p_vout =
317 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
318 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
321 /* Function called when the button is clicked() */
322 void AdvControlsWidget::fromAtoB()
326 timeA = var_GetTime( THEMIM->getInput(), "time" );
327 ABButton->setText( "A->..." );
332 timeB = var_GetTime( THEMIM->getInput(), "time" );
333 var_SetTime( THEMIM->getInput(), "time" , timeA );
334 ABButton->setText( "A<=>B" );
339 ABButton->setText( "AB" );
342 /* Function called regularly when in an AtoB loop */
343 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
347 if( i_time >= (int)(timeB/1000000) )
348 var_SetTime( THEMIM->getInput(), "time" , timeA );
352 /* FIXME Record function */
353 void AdvControlsWidget::record(){}
355 //FIXME Frame by frame function
356 void AdvControlsWidget::frame(){}
358 /*****************************
359 * DA Control Widget !
360 *****************************/
361 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
362 MainInterface *_p_mi,
365 QFrame( NULL ), p_intf( _p_i )
367 controlLayout = new QGridLayout( this );
368 controlLayout->setSpacing( 0 );
370 controlLayout->setContentsMargins( 9, 6, 9, 6 );
372 controlLayout->setMargin( 6 );
375 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
377 /** The main Slider **/
378 slider = new InputSlider( Qt::Horizontal, NULL );
379 controlLayout->addWidget( slider, 0, 1, 1, 16 );
380 /* Update the position when the IM has changed */
381 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
382 slider, setPosition( float, int, int ) );
383 /* And update the IM, when the position has changed */
384 CONNECT( slider, sliderDragged( float ),
385 THEMIM->getIM(), sliderUpdate( float ) );
387 /** Slower and faster Buttons **/
388 slowerButton = new QToolButton;
389 slowerButton->setAutoRaise( true );
390 slowerButton->setMaximumSize( QSize( 26, 20 ) );
392 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
393 controlLayout->addWidget( slowerButton, 0, 0 );
395 fasterButton = new QToolButton;
396 fasterButton->setAutoRaise( true );
397 fasterButton->setMaximumSize( QSize( 26, 20 ) );
399 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
400 controlLayout->addWidget( fasterButton, 0, 17 );
402 /* advanced Controls handling */
403 b_advancedVisible = b_advControls;
405 advControls = new AdvControlsWidget( p_intf );
406 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
407 if( !b_advancedVisible ) advControls->hide();
409 /** Disc and Menus handling */
410 discFrame = new QWidget( this );
412 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
413 discLayout->setSpacing( 0 );
414 discLayout->setMargin( 0 );
416 prevSectionButton = new QPushButton( discFrame );
417 setupSmallButton( prevSectionButton );
418 discLayout->addWidget( prevSectionButton );
420 menuButton = new QPushButton( discFrame );
421 setupSmallButton( menuButton );
422 discLayout->addWidget( menuButton );
424 nextSectionButton = new QPushButton( discFrame );
425 setupSmallButton( nextSectionButton );
426 discLayout->addWidget( nextSectionButton );
428 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
430 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
431 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
432 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
436 /* Change the navigation button display when the IM navigation changes */
437 CONNECT( THEMIM->getIM(), navigationChanged( int ),
438 this, setNavigation( int ) );
439 /* Changes the IM navigation when triggered on the nav buttons */
440 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
442 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
444 CONNECT( menuButton, clicked(), THEMIM->getIM(),
448 * TODO: Merge with upper menu in a StackLayout
451 telexFrame = new QWidget( this );
452 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
453 telexLayout->setSpacing( 0 );
454 telexLayout->setMargin( 0 );
456 QToolButton *telexOn = new QToolButton;
457 telexOn->setText( qtr( "On" ) );
458 setupSmallButton( telexOn );
459 telexLayout->addWidget( telexOn );
461 QToolButton *telexTransparent = new QToolButton;
462 telexTransparent->setText( qtr( "Transparent" ) );
463 setupSmallButton( telexTransparent );
464 telexLayout->addWidget( telexTransparent );
466 QSpinBox *telexPage = new QSpinBox;
467 telexPage->setRange( 0, 999 );
468 telexPage->setValue( 100 );
469 telexPage->setAlignment( Qt::AlignRight );
470 telexLayout->addWidget( telexPage );
472 controlLayout->addWidget( telexFrame, 1, 10, 2, 3, Qt::AlignBottom );
475 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
476 telexGotoPage( int ) );
477 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
478 telexToggle( bool ) );
479 CONNECT( telexTransparent, clicked( bool ),
480 THEMIM->getIM(), telexSetTransparency( bool ) );
481 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
482 telexFrame, setVisible( bool ) );
486 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
487 sizePolicy.setHorizontalStretch( 0 );
488 sizePolicy.setVerticalStretch( 0 );
491 playButton = new QPushButton;
492 playButton->setSizePolicy( sizePolicy );
493 playButton->setMaximumSize( QSize( 36, 36 ) );
494 playButton->setMinimumSize( QSize( 36, 36 ) );
495 playButton->setIconSize( QSize( 30, 30 ) );
497 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
499 controlLayout->setColumnMinimumWidth( 2, 20 );
500 controlLayout->setColumnStretch( 2, 0 );
502 /** Prev + Stop + Next Block **/
503 QHBoxLayout *controlButLayout = new QHBoxLayout;
504 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
507 QPushButton *prevButton = new QPushButton;
508 prevButton->setSizePolicy( sizePolicy );
509 setupSmallButton( prevButton );
511 controlButLayout->addWidget( prevButton );
514 QPushButton *stopButton = new QPushButton;
515 stopButton->setSizePolicy( sizePolicy );
516 setupSmallButton( stopButton );
518 controlButLayout->addWidget( stopButton );
521 QPushButton *nextButton = new QPushButton;
522 nextButton->setSizePolicy( sizePolicy );
523 setupSmallButton( nextButton );
525 controlButLayout->addWidget( nextButton );
527 /* Add this block to the main layout */
528 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
530 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
531 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
532 qtr( "Previous" ), prev() );
533 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
534 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
536 controlLayout->setColumnMinimumWidth( 7, 20 );
537 controlLayout->setColumnStretch( 7, 0 );
538 controlLayout->setColumnStretch( 8, 0 );
539 controlLayout->setColumnStretch( 9, 0 );
542 * Other first Line buttons
544 /** Fullscreen/Visualisation **/
545 fullscreenButton = new QPushButton( "F" );
546 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
547 setupSmallButton( fullscreenButton );
548 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
550 /** Playlist Button **/
551 playlistButton = new QPushButton;
552 setupSmallButton( playlistButton );
553 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
554 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
555 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
557 /** extended Settings **/
558 QPushButton *extSettingsButton = new QPushButton( "F" );
559 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
561 setupSmallButton( extSettingsButton );
562 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
564 controlLayout->setColumnStretch( 13, 0 );
565 controlLayout->setColumnMinimumWidth( 13, 24 );
566 controlLayout->setColumnStretch( 14, 5 );
569 VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
571 volMuteLabel = new QLabel;
572 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
573 volMuteLabel->setToolTip( qtr( "Mute" ) );
574 volMuteLabel->installEventFilter( hVolLabel );
575 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
579 volumeSlider = new SoundSlider( this,
580 config_GetInt( p_intf, "volume-step" ),
581 config_GetInt( p_intf, "qt-volume-complete" ) );
585 volumeSlider = new QSlider( this );
586 volumeSlider->setOrientation( Qt::Horizontal );
588 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
589 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
590 volumeSlider->setFocusPolicy( Qt::NoFocus );
591 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
593 /* Set the volume from the config */
594 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
595 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
597 /* Volume control connection */
598 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
601 ControlsWidget::~ControlsWidget()
604 void ControlsWidget::stop()
609 void ControlsWidget::play()
611 if( THEPL->current.i_size == 0 )
613 /* The playlist is empty, open a file requester */
614 THEDP->openFileDialog();
618 THEMIM->togglePlayPause();
621 void ControlsWidget::prev()
626 void ControlsWidget::next()
631 void ControlsWidget::setNavigation( int navigation )
633 #define HELP_MENU N_( "Menu" )
634 #define HELP_PCH N_( "Previous chapter" )
635 #define HELP_NCH N_( "Next chapter" )
636 #define HELP_PTR N_( "Previous track" )
637 #define HELP_NTR N_( "Next track" )
639 // 1 = chapter, 2 = title, 0 = no
640 if( navigation == 0 )
643 } else if( navigation == 1 ) {
644 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
645 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
649 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
650 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
656 static bool b_my_volume;
657 void ControlsWidget::updateVolume( int i_sliderVolume )
661 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
662 aout_VolumeSet( p_intf, i_res );
664 if( i_sliderVolume == 0 )
665 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
666 else if( i_sliderVolume < VOLUME_MAX / 3 )
667 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
668 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
669 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
670 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
673 void ControlsWidget::updateOnTimer()
676 audio_volume_t i_volume;
677 aout_VolumeGet( p_intf, &i_volume );
678 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
679 int i_gauge = volumeSlider->value();
681 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
684 volumeSlider->setValue( i_volume );
688 /* Activate the interface buttons according to the presence of the input */
689 enableInput( THEMIM->getIM()->hasInput() );
690 //enableVideo( THEMIM->getIM()->hasVideo() );
694 void ControlsWidget::setStatus( int status )
696 if( status == PLAYING_S ) // Playing
697 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
699 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
704 * This functions toggle the fullscreen mode
705 * If there is no video, it should first activate Visualisations...
706 * This has also to be fixed in enableVideo()
708 void ControlsWidget::fullscreen()
710 vout_thread_t *p_vout =
711 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
714 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
715 vlc_object_release( p_vout );
719 void ControlsWidget::extSettings()
721 THEDP->extendedDialog();
724 void ControlsWidget::slower()
726 THEMIM->getIM()->slower();
729 void ControlsWidget::faster()
731 THEMIM->getIM()->faster();
734 void ControlsWidget::enableInput( bool enable )
736 slowerButton->setEnabled( enable );
737 slider->setEnabled( enable );
738 fasterButton->setEnabled( enable );
740 /* Advanced Buttons too */
741 advControls->enableInput( enable );
744 void ControlsWidget::enableVideo( bool enable )
746 // TODO Later make the fullscreenButton toggle Visualisation and so on.
747 fullscreenButton->setEnabled( enable );
749 /* Advanced Buttons too */
750 advControls->enableVideo( enable );
753 void ControlsWidget::toggleAdvanced()
755 if( !VISIBLE( advControls ) )
758 b_advancedVisible = true;
763 b_advancedVisible = false;
765 emit advancedControlsToggled( b_advancedVisible );
769 /**********************************************************************
770 * Speed control widget
771 **********************************************************************/
772 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
773 QFrame( NULL ), p_intf( _p_i )
775 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
776 sizePolicy.setHorizontalStretch( 0 );
777 sizePolicy.setVerticalStretch( 0 );
779 speedSlider = new QSlider;
780 speedSlider->setSizePolicy( sizePolicy );
781 speedSlider->setMaximumSize( QSize( 80, 200 ) );
782 speedSlider->setOrientation( Qt::Vertical );
783 speedSlider->setTickPosition( QSlider::TicksRight );
785 speedSlider->setRange( -100, 100 );
786 speedSlider->setSingleStep( 10 );
787 speedSlider->setPageStep( 20 );
788 speedSlider->setTickInterval( 20 );
790 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
792 QToolButton *normalSpeedButton = new QToolButton( this );
793 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
794 normalSpeedButton->setAutoRaise( true );
795 normalSpeedButton->setText( "N" );
796 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
798 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
800 QVBoxLayout *speedControlLayout = new QVBoxLayout;
801 speedControlLayout->addWidget( speedSlider );
802 speedControlLayout->addWidget( normalSpeedButton );
803 setLayout( speedControlLayout );
806 SpeedControlWidget::~SpeedControlWidget()
809 #define RATE_SLIDER_MAXIMUM 3.0
810 #define RATE_SLIDER_MINIMUM 0.3
811 #define RATE_SLIDER_LENGTH 100.0
813 void SpeedControlWidget::updateControls( int rate )
815 if( speedSlider->isSliderDown() )
817 //We don't want to change anything if the user is using the slider
822 double speed = INPUT_RATE_DEFAULT / (double)rate;
824 if( rate >= INPUT_RATE_DEFAULT )
826 if( speed < RATE_SLIDER_MINIMUM )
828 sliderValue = speedSlider->minimum();
832 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
833 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
838 if( speed > RATE_SLIDER_MAXIMUM )
840 sliderValue = speedSlider->maximum();
844 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
845 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
849 //Block signals to avoid feedback loop
850 speedSlider->blockSignals( true );
851 speedSlider->setValue( sliderValue );
852 speedSlider->blockSignals( false );
855 void SpeedControlWidget::updateRate( int sliderValue )
859 if( sliderValue < 0.0 )
861 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
862 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH );
866 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
867 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
870 THEMIM->getIM()->setRate(rate);
873 void SpeedControlWidget::resetRate()
875 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);