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 album art if present or 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->getIM(), artChanged( QString ), this, update( QString ) );
160 BackgroundWidget::~BackgroundWidget()
164 void BackgroundWidget::update( QString url )
168 if( QDate::currentDate().dayOfYear() >= 354 )
169 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
171 label->setPixmap( QPixmap( ":/vlc128.png" ) );
176 label->setPixmap( QPixmap( url ) );
177 msg_Dbg( p_intf, "changing input b_need_update done ");
181 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
183 QVLCMenu::PopupMenu( p_intf, true );
186 /**********************************************************************
187 * Visualization selector panel
188 **********************************************************************/
189 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
190 QFrame( NULL ), p_intf( _p_i )
192 QHBoxLayout *layout = new QHBoxLayout( this );
193 layout->setMargin( 0 );
194 QPushButton *prevButton = new QPushButton( "Prev" );
195 QPushButton *nextButton = new QPushButton( "Next" );
196 layout->addWidget( prevButton );
197 layout->addWidget( nextButton );
199 layout->addItem( new QSpacerItem( 40,20,
200 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
201 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
203 current = new QLabel( qtr( "None" ) );
204 layout->addWidget( current );
206 BUTTONACT( prevButton, prev() );
207 BUTTONACT( nextButton, next() );
210 setMaximumHeight( 35 );
213 VisualSelector::~VisualSelector()
217 void VisualSelector::prev()
219 char *psz_new = aout_VisualPrev( p_intf );
222 current->setText( qfu( psz_new ) );
227 void VisualSelector::next()
229 char *psz_new = aout_VisualNext( p_intf );
232 current->setText( qfu( psz_new ) );
237 /**********************************************************************
239 **********************************************************************/
241 #define setupSmallButton( aButton ){ \
242 aButton->setMaximumSize( QSize( 26, 26 ) ); \
243 aButton->setMinimumSize( QSize( 26, 26 ) ); \
244 aButton->setIconSize( QSize( 20, 20 ) ); }
246 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
247 QFrame( NULL ), p_intf( _p_i )
249 QHBoxLayout *advLayout = new QHBoxLayout( this );
250 advLayout->setMargin( 0 );
251 advLayout->setSpacing( 0 );
254 ABButton = new QPushButton( "AB" );
255 ABButton->setMaximumSize( QSize( 26, 26 ) );
256 ABButton->setIconSize( QSize( 20, 20 ) );
257 advLayout->addWidget( ABButton );
258 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
260 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
261 this, AtoBLoop( float, int, int ) );
263 frameButton = new QPushButton( "Fr" );
264 frameButton->setMaximumSize( QSize( 26, 26 ) );
265 frameButton->setIconSize( QSize( 20, 20 ) );
266 advLayout->addWidget( frameButton );
267 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
270 recordButton = new QPushButton( "R" );
271 recordButton->setMaximumSize( QSize( 26, 26 ) );
272 recordButton->setIconSize( QSize( 20, 20 ) );
273 advLayout->addWidget( recordButton );
274 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
275 qtr( "Record" ), record() );
277 /* Snapshot Button */
278 snapshotButton = new QPushButton( "S" );
279 snapshotButton->setMaximumSize( QSize( 26, 26 ) );
280 snapshotButton->setIconSize( QSize( 20, 20 ) );
281 advLayout->addWidget( snapshotButton );
282 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
285 AdvControlsWidget::~AdvControlsWidget()
288 void AdvControlsWidget::enableInput( bool enable )
290 ABButton->setEnabled( enable );
291 recordButton->setEnabled( enable );
294 void AdvControlsWidget::enableVideo( bool enable )
296 snapshotButton->setEnabled( enable );
298 frameButton->setEnabled( enable );
302 void AdvControlsWidget::snapshot()
304 vout_thread_t *p_vout =
305 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
306 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
309 /* Function called when the button is clicked() */
310 void AdvControlsWidget::fromAtoB()
314 timeA = var_GetTime( THEMIM->getInput(), "time" );
315 ABButton->setText( "A->..." );
320 timeB = var_GetTime( THEMIM->getInput(), "time" );
321 var_SetTime( THEMIM->getInput(), "time" , timeA );
322 ABButton->setText( "A<=>B" );
327 ABButton->setText( "AB" );
330 /* Function called regularly when in an AtoB loop */
331 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
335 if( i_time >= (int)(timeB/1000000) )
336 var_SetTime( THEMIM->getInput(), "time" , timeA );
340 /* FIXME Record function */
341 void AdvControlsWidget::record(){}
344 //FIXME Frame by frame function
345 void AdvControlsWidget::frame(){}
348 /*****************************
349 * DA Control Widget !
350 *****************************/
351 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
352 MainInterface *_p_mi,
355 QFrame( NULL ), p_intf( _p_i )
357 controlLayout = new QGridLayout( this );
358 controlLayout->setSpacing( 0 );
360 controlLayout->setContentsMargins( 9, 6, 9, 6 );
362 controlLayout->setMargin( 6 );
365 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
367 /** The main Slider **/
368 slider = new InputSlider( Qt::Horizontal, NULL );
369 controlLayout->addWidget( slider, 0, 1, 1, 16 );
370 /* Update the position when the IM has changed */
371 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
372 slider, setPosition( float, int, int ) );
373 /* And update the IM, when the position has changed */
374 CONNECT( slider, sliderDragged( float ),
375 THEMIM->getIM(), sliderUpdate( float ) );
377 /** Slower and faster Buttons **/
378 slowerButton = new QToolButton;
379 slowerButton->setAutoRaise( true );
380 slowerButton->setMaximumSize( QSize( 26, 20 ) );
382 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
383 controlLayout->addWidget( slowerButton, 0, 0 );
385 fasterButton = new QToolButton;
386 fasterButton->setAutoRaise( true );
387 fasterButton->setMaximumSize( QSize( 26, 20 ) );
389 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
390 controlLayout->addWidget( fasterButton, 0, 17 );
392 /* advanced Controls handling */
393 b_advancedVisible = b_advControls;
395 advControls = new AdvControlsWidget( p_intf );
396 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
397 if( !b_advancedVisible ) advControls->hide();
399 /** Disc and Menus handling */
400 discFrame = new QWidget( this );
402 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
403 discLayout->setSpacing( 0 );
404 discLayout->setMargin( 0 );
406 prevSectionButton = new QPushButton( discFrame );
407 setupSmallButton( prevSectionButton );
408 discLayout->addWidget( prevSectionButton );
410 menuButton = new QPushButton( discFrame );
411 setupSmallButton( menuButton );
412 discLayout->addWidget( menuButton );
414 nextSectionButton = new QPushButton( discFrame );
415 setupSmallButton( nextSectionButton );
416 discLayout->addWidget( nextSectionButton );
418 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
420 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
421 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
422 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
426 /* Change the navigation button display when the IM navigation changes */
427 CONNECT( THEMIM->getIM(), navigationChanged( int ),
428 this, setNavigation( int ) );
429 /* Changes the IM navigation when triggered on the nav buttons */
430 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
432 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
434 CONNECT( menuButton, clicked(), THEMIM->getIM(),
438 * TODO: Merge with upper menu in a StackLayout
441 telexFrame = new QWidget( this );
442 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
443 telexLayout->setSpacing( 0 );
444 telexLayout->setMargin( 0 );
446 QToolButton *telexOn = new QToolButton;
447 telexOn->setText( qtr( "On" ) );
448 setupSmallButton( telexOn );
449 telexLayout->addWidget( telexOn );
451 QToolButton *telexTransparent = new QToolButton;
452 telexTransparent->setText( qtr( "Transparent" ) );
453 setupSmallButton( telexTransparent );
454 telexLayout->addWidget( telexTransparent );
456 QSpinBox *telexPage = new QSpinBox;
457 telexPage->setRange( 0, 999 );
458 telexPage->setValue( 100 );
459 telexPage->setAlignment( Qt::AlignRight );
460 telexLayout->addWidget( telexPage );
462 controlLayout->addWidget( telexFrame, 1, 10, 2, 3, Qt::AlignBottom );
465 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
466 telexGotoPage( int ) );
467 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
468 telexToggle( bool ) );
469 CONNECT( telexTransparent, clicked( bool ),
470 THEMIM->getIM(), telexSetTransparency( bool ) );
471 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
472 telexFrame, setVisible( bool ) );
476 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
477 sizePolicy.setHorizontalStretch( 0 );
478 sizePolicy.setVerticalStretch( 0 );
481 playButton = new QPushButton;
482 playButton->setSizePolicy( sizePolicy );
483 playButton->setMaximumSize( QSize( 36, 36 ) );
484 playButton->setMinimumSize( QSize( 36, 36 ) );
485 playButton->setIconSize( QSize( 30, 30 ) );
487 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
489 controlLayout->setColumnMinimumWidth( 2, 20 );
490 controlLayout->setColumnStretch( 2, 0 );
492 /** Prev + Stop + Next Block **/
493 QHBoxLayout *controlButLayout = new QHBoxLayout;
494 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
497 QPushButton *prevButton = new QPushButton;
498 prevButton->setSizePolicy( sizePolicy );
499 setupSmallButton( prevButton );
501 controlButLayout->addWidget( prevButton );
504 QPushButton *stopButton = new QPushButton;
505 stopButton->setSizePolicy( sizePolicy );
506 setupSmallButton( stopButton );
508 controlButLayout->addWidget( stopButton );
511 QPushButton *nextButton = new QPushButton;
512 nextButton->setSizePolicy( sizePolicy );
513 setupSmallButton( nextButton );
515 controlButLayout->addWidget( nextButton );
517 /* Add this block to the main layout */
518 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
520 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
521 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
522 qtr( "Previous" ), prev() );
523 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
524 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
526 controlLayout->setColumnMinimumWidth( 7, 20 );
527 controlLayout->setColumnStretch( 7, 0 );
528 controlLayout->setColumnStretch( 8, 0 );
529 controlLayout->setColumnStretch( 9, 0 );
532 * Other first Line buttons
534 /** Fullscreen/Visualisation **/
535 fullscreenButton = new QPushButton( "F" );
536 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
537 setupSmallButton( fullscreenButton );
538 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
540 /** Playlist Button **/
541 playlistButton = new QPushButton;
542 setupSmallButton( playlistButton );
543 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
544 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
545 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
547 /** extended Settings **/
548 QPushButton *extSettingsButton = new QPushButton( "F" );
549 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
551 setupSmallButton( extSettingsButton );
552 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
554 controlLayout->setColumnStretch( 13, 0 );
555 controlLayout->setColumnMinimumWidth( 13, 24 );
556 controlLayout->setColumnStretch( 14, 5 );
559 VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
561 volMuteLabel = new QLabel;
562 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
563 volMuteLabel->setToolTip( qtr( "Mute" ) );
564 volMuteLabel->installEventFilter( hVolLabel );
565 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
569 volumeSlider = new SoundSlider( this,
570 config_GetInt( p_intf, "volume-step" ),
571 config_GetInt( p_intf, "qt-volume-complete" ) );
575 volumeSlider = new QSlider( this );
576 volumeSlider->setOrientation( Qt::Horizontal );
578 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
579 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
580 volumeSlider->setFocusPolicy( Qt::NoFocus );
581 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
583 /* Set the volume from the config */
584 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
585 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
587 /* Volume control connection */
588 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
589 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
592 ControlsWidget::~ControlsWidget()
595 void ControlsWidget::stop()
600 void ControlsWidget::play()
602 if( THEPL->current.i_size == 0 )
604 /* The playlist is empty, open a file requester */
605 THEDP->openFileDialog();
609 THEMIM->togglePlayPause();
612 void ControlsWidget::prev()
617 void ControlsWidget::next()
622 void ControlsWidget::setNavigation( int navigation )
624 #define HELP_MENU N_( "Menu" )
625 #define HELP_PCH N_( "Previous chapter" )
626 #define HELP_NCH N_( "Next chapter" )
627 #define HELP_PTR N_( "Previous track" )
628 #define HELP_NTR N_( "Next track" )
630 // 1 = chapter, 2 = title, 0 = no
631 if( navigation == 0 )
634 } else if( navigation == 1 ) {
635 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
636 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
640 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
641 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
647 static bool b_my_volume;
648 void ControlsWidget::updateVolume( int i_sliderVolume )
652 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
653 aout_VolumeSet( p_intf, i_res );
655 if( i_sliderVolume == 0 )
656 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
657 else if( i_sliderVolume < VOLUME_MAX / 3 )
658 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
659 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
660 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
661 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
664 void ControlsWidget::updateVolume()
667 audio_volume_t i_volume;
668 aout_VolumeGet( p_intf, &i_volume );
669 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
670 int i_gauge = volumeSlider->value();
672 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
675 volumeSlider->setValue( i_volume );
679 /* Activate the interface buttons according to the presence of the input */
680 enableInput( THEMIM->getIM()->hasInput() );
681 //enableVideo( THEMIM->getIM()->hasVideo() );
685 void ControlsWidget::setStatus( int status )
687 if( status == PLAYING_S ) // Playing
688 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
690 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
695 * This functions toggle the fullscreen mode
696 * If there is no video, it should first activate Visualisations...
697 * This has also to be fixed in enableVideo()
699 void ControlsWidget::fullscreen()
701 vout_thread_t *p_vout =
702 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
705 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
706 vlc_object_release( p_vout );
710 void ControlsWidget::extSettings()
712 THEDP->extendedDialog();
715 void ControlsWidget::slower()
717 THEMIM->getIM()->slower();
720 void ControlsWidget::faster()
722 THEMIM->getIM()->faster();
725 void ControlsWidget::enableInput( bool enable )
727 slowerButton->setEnabled( enable );
728 slider->setEnabled( enable );
729 fasterButton->setEnabled( enable );
731 /* Advanced Buttons too */
732 advControls->enableInput( enable );
735 void ControlsWidget::enableVideo( bool enable )
737 // TODO Later make the fullscreenButton toggle Visualisation and so on.
738 fullscreenButton->setEnabled( enable );
740 /* Advanced Buttons too */
741 advControls->enableVideo( enable );
744 void ControlsWidget::toggleAdvanced()
746 if( !VISIBLE( advControls ) )
749 b_advancedVisible = true;
754 b_advancedVisible = false;
756 emit advancedControlsToggled( b_advancedVisible );
760 /**********************************************************************
761 * Speed control widget
762 **********************************************************************/
763 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
764 QFrame( NULL ), p_intf( _p_i )
766 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
767 sizePolicy.setHorizontalStretch( 0 );
768 sizePolicy.setVerticalStretch( 0 );
770 speedSlider = new QSlider;
771 speedSlider->setSizePolicy( sizePolicy );
772 speedSlider->setMaximumSize( QSize( 80, 200 ) );
773 speedSlider->setOrientation( Qt::Vertical );
774 speedSlider->setTickPosition( QSlider::TicksRight );
776 speedSlider->setRange( -100, 100 );
777 speedSlider->setSingleStep( 10 );
778 speedSlider->setPageStep( 20 );
779 speedSlider->setTickInterval( 20 );
781 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
783 QToolButton *normalSpeedButton = new QToolButton( this );
784 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
785 normalSpeedButton->setAutoRaise( true );
786 normalSpeedButton->setText( "N" );
787 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
789 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
791 QVBoxLayout *speedControlLayout = new QVBoxLayout;
792 speedControlLayout->addWidget( speedSlider );
793 speedControlLayout->addWidget( normalSpeedButton );
794 setLayout( speedControlLayout );
797 SpeedControlWidget::~SpeedControlWidget()
800 #define RATE_SLIDER_MAXIMUM 3.0
801 #define RATE_SLIDER_MINIMUM 0.3
802 #define RATE_SLIDER_LENGTH 100.0
804 void SpeedControlWidget::updateControls( int rate )
806 if( speedSlider->isSliderDown() )
808 //We don't want to change anything if the user is using the slider
813 double speed = INPUT_RATE_DEFAULT / (double)rate;
815 if( rate >= INPUT_RATE_DEFAULT )
817 if( speed < RATE_SLIDER_MINIMUM )
819 sliderValue = speedSlider->minimum();
823 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
824 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
829 if( speed > RATE_SLIDER_MAXIMUM )
831 sliderValue = speedSlider->maximum();
835 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
836 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
840 //Block signals to avoid feedback loop
841 speedSlider->blockSignals( true );
842 speedSlider->setValue( sliderValue );
843 speedSlider->blockSignals( false );
846 void SpeedControlWidget::updateRate( int sliderValue )
850 if( sliderValue < 0.0 )
852 rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
853 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ));
857 rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
858 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH ));
861 THEMIM->getIM()->setRate(rate);
864 void SpeedControlWidget::resetRate()
866 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);