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() );
269 recordButton = new QPushButton( "R" );
270 recordButton->setMaximumSize( QSize( 26, 26 ) );
271 recordButton->setIconSize( QSize( 20, 20 ) );
272 advLayout->addWidget( recordButton );
273 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
274 qtr( "Record" ), record() );
276 /* Snapshot Button */
277 snapshotButton = new QPushButton( "S" );
278 snapshotButton->setMaximumSize( QSize( 26, 26 ) );
279 snapshotButton->setIconSize( QSize( 20, 20 ) );
280 advLayout->addWidget( snapshotButton );
281 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
284 AdvControlsWidget::~AdvControlsWidget()
287 void AdvControlsWidget::enableInput( bool enable )
289 ABButton->setEnabled( enable );
290 recordButton->setEnabled( enable );
293 void AdvControlsWidget::enableVideo( bool enable )
295 snapshotButton->setEnabled( enable );
296 frameButton->setEnabled( enable );
299 void AdvControlsWidget::snapshot()
301 vout_thread_t *p_vout =
302 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
303 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
306 /* Function called when the button is clicked() */
307 void AdvControlsWidget::fromAtoB()
311 timeA = var_GetTime( THEMIM->getInput(), "time" );
312 ABButton->setText( "A->..." );
317 timeB = var_GetTime( THEMIM->getInput(), "time" );
318 var_SetTime( THEMIM->getInput(), "time" , timeA );
319 ABButton->setText( "A<=>B" );
324 ABButton->setText( "AB" );
327 /* Function called regularly when in an AtoB loop */
328 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
332 if( i_time >= (int)(timeB/1000000) )
333 var_SetTime( THEMIM->getInput(), "time" , timeA );
337 /* FIXME Record function */
338 void AdvControlsWidget::record(){}
340 //FIXME Frame by frame function
341 void AdvControlsWidget::frame(){}
343 /*****************************
344 * DA Control Widget !
345 *****************************/
346 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
347 MainInterface *_p_mi,
350 QFrame( NULL ), p_intf( _p_i )
352 controlLayout = new QGridLayout( this );
353 controlLayout->setSpacing( 0 );
355 controlLayout->setContentsMargins( 9, 6, 9, 6 );
357 controlLayout->setMargin( 6 );
360 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
362 /** The main Slider **/
363 slider = new InputSlider( Qt::Horizontal, NULL );
364 controlLayout->addWidget( slider, 0, 1, 1, 16 );
365 /* Update the position when the IM has changed */
366 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
367 slider, setPosition( float, int, int ) );
368 /* And update the IM, when the position has changed */
369 CONNECT( slider, sliderDragged( float ),
370 THEMIM->getIM(), sliderUpdate( float ) );
372 /** Slower and faster Buttons **/
373 slowerButton = new QToolButton;
374 slowerButton->setAutoRaise( true );
375 slowerButton->setMaximumSize( QSize( 26, 20 ) );
377 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
378 controlLayout->addWidget( slowerButton, 0, 0 );
380 fasterButton = new QToolButton;
381 fasterButton->setAutoRaise( true );
382 fasterButton->setMaximumSize( QSize( 26, 20 ) );
384 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
385 controlLayout->addWidget( fasterButton, 0, 17 );
387 /* advanced Controls handling */
388 b_advancedVisible = b_advControls;
390 advControls = new AdvControlsWidget( p_intf );
391 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
392 if( !b_advancedVisible ) advControls->hide();
394 /** Disc and Menus handling */
395 discFrame = new QWidget( this );
397 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
398 discLayout->setSpacing( 0 );
399 discLayout->setMargin( 0 );
401 prevSectionButton = new QPushButton( discFrame );
402 setupSmallButton( prevSectionButton );
403 discLayout->addWidget( prevSectionButton );
405 menuButton = new QPushButton( discFrame );
406 setupSmallButton( menuButton );
407 discLayout->addWidget( menuButton );
409 nextSectionButton = new QPushButton( discFrame );
410 setupSmallButton( nextSectionButton );
411 discLayout->addWidget( nextSectionButton );
413 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
415 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
416 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
417 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
421 /* Change the navigation button display when the IM navigation changes */
422 CONNECT( THEMIM->getIM(), navigationChanged( int ),
423 this, setNavigation( int ) );
424 /* Changes the IM navigation when triggered on the nav buttons */
425 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
427 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
429 CONNECT( menuButton, clicked(), THEMIM->getIM(),
433 * TODO: Merge with upper menu in a StackLayout
436 telexFrame = new QWidget( this );
437 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
438 telexLayout->setSpacing( 0 );
439 telexLayout->setMargin( 0 );
441 QToolButton *telexOn = new QToolButton;
442 telexOn->setText( qtr( "On" ) );
443 setupSmallButton( telexOn );
444 telexLayout->addWidget( telexOn );
446 QToolButton *telexTransparent = new QToolButton;
447 telexTransparent->setText( qtr( "Transparent" ) );
448 setupSmallButton( telexTransparent );
449 telexLayout->addWidget( telexTransparent );
451 QSpinBox *telexPage = new QSpinBox;
452 telexPage->setRange( 0, 999 );
453 telexPage->setValue( 100 );
454 telexPage->setAlignment( Qt::AlignRight );
455 telexLayout->addWidget( telexPage );
457 controlLayout->addWidget( telexFrame, 1, 10, 2, 3, Qt::AlignBottom );
460 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
461 telexGotoPage( int ) );
462 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
463 telexToggle( bool ) );
464 CONNECT( telexTransparent, clicked( bool ),
465 THEMIM->getIM(), telexSetTransparency( bool ) );
466 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
467 telexFrame, setVisible( bool ) );
471 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
472 sizePolicy.setHorizontalStretch( 0 );
473 sizePolicy.setVerticalStretch( 0 );
476 playButton = new QPushButton;
477 playButton->setSizePolicy( sizePolicy );
478 playButton->setMaximumSize( QSize( 36, 36 ) );
479 playButton->setMinimumSize( QSize( 36, 36 ) );
480 playButton->setIconSize( QSize( 30, 30 ) );
482 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
484 controlLayout->setColumnMinimumWidth( 2, 20 );
485 controlLayout->setColumnStretch( 2, 0 );
487 /** Prev + Stop + Next Block **/
488 QHBoxLayout *controlButLayout = new QHBoxLayout;
489 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
492 QPushButton *prevButton = new QPushButton;
493 prevButton->setSizePolicy( sizePolicy );
494 setupSmallButton( prevButton );
496 controlButLayout->addWidget( prevButton );
499 QPushButton *stopButton = new QPushButton;
500 stopButton->setSizePolicy( sizePolicy );
501 setupSmallButton( stopButton );
503 controlButLayout->addWidget( stopButton );
506 QPushButton *nextButton = new QPushButton;
507 nextButton->setSizePolicy( sizePolicy );
508 setupSmallButton( nextButton );
510 controlButLayout->addWidget( nextButton );
512 /* Add this block to the main layout */
513 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
515 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
516 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
517 qtr( "Previous" ), prev() );
518 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
519 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
521 controlLayout->setColumnMinimumWidth( 7, 20 );
522 controlLayout->setColumnStretch( 7, 0 );
523 controlLayout->setColumnStretch( 8, 0 );
524 controlLayout->setColumnStretch( 9, 0 );
527 * Other first Line buttons
529 /** Fullscreen/Visualisation **/
530 fullscreenButton = new QPushButton( "F" );
531 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
532 setupSmallButton( fullscreenButton );
533 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
535 /** Playlist Button **/
536 playlistButton = new QPushButton;
537 setupSmallButton( playlistButton );
538 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
539 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
540 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
542 /** extended Settings **/
543 QPushButton *extSettingsButton = new QPushButton( "F" );
544 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
546 setupSmallButton( extSettingsButton );
547 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
549 controlLayout->setColumnStretch( 13, 0 );
550 controlLayout->setColumnMinimumWidth( 13, 24 );
551 controlLayout->setColumnStretch( 14, 5 );
554 VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
556 volMuteLabel = new QLabel;
557 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
558 volMuteLabel->setToolTip( qtr( "Mute" ) );
559 volMuteLabel->installEventFilter( hVolLabel );
560 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
564 volumeSlider = new SoundSlider( this,
565 config_GetInt( p_intf, "volume-step" ),
566 config_GetInt( p_intf, "qt-volume-complete" ) );
570 volumeSlider = new QSlider( this );
571 volumeSlider->setOrientation( Qt::Horizontal );
573 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
574 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
575 volumeSlider->setFocusPolicy( Qt::NoFocus );
576 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
578 /* Set the volume from the config */
579 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
580 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
582 /* Volume control connection */
583 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
584 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
587 ControlsWidget::~ControlsWidget()
590 void ControlsWidget::stop()
595 void ControlsWidget::play()
597 if( THEPL->current.i_size == 0 )
599 /* The playlist is empty, open a file requester */
600 THEDP->openFileDialog();
604 THEMIM->togglePlayPause();
607 void ControlsWidget::prev()
612 void ControlsWidget::next()
617 void ControlsWidget::setNavigation( int navigation )
619 #define HELP_MENU N_( "Menu" )
620 #define HELP_PCH N_( "Previous chapter" )
621 #define HELP_NCH N_( "Next chapter" )
622 #define HELP_PTR N_( "Previous track" )
623 #define HELP_NTR N_( "Next track" )
625 // 1 = chapter, 2 = title, 0 = no
626 if( navigation == 0 )
629 } else if( navigation == 1 ) {
630 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
631 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
635 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
636 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
642 static bool b_my_volume;
643 void ControlsWidget::updateVolume( int i_sliderVolume )
647 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
648 aout_VolumeSet( p_intf, i_res );
650 if( i_sliderVolume == 0 )
651 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
652 else if( i_sliderVolume < VOLUME_MAX / 3 )
653 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
654 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
655 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
656 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
659 void ControlsWidget::updateVolume()
662 audio_volume_t i_volume;
663 aout_VolumeGet( p_intf, &i_volume );
664 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
665 int i_gauge = volumeSlider->value();
667 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
670 volumeSlider->setValue( i_volume );
674 /* Activate the interface buttons according to the presence of the input */
675 enableInput( THEMIM->getIM()->hasInput() );
676 //enableVideo( THEMIM->getIM()->hasVideo() );
680 void ControlsWidget::setStatus( int status )
682 if( status == PLAYING_S ) // Playing
683 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
685 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
690 * This functions toggle the fullscreen mode
691 * If there is no video, it should first activate Visualisations...
692 * This has also to be fixed in enableVideo()
694 void ControlsWidget::fullscreen()
696 vout_thread_t *p_vout =
697 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
700 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
701 vlc_object_release( p_vout );
705 void ControlsWidget::extSettings()
707 THEDP->extendedDialog();
710 void ControlsWidget::slower()
712 THEMIM->getIM()->slower();
715 void ControlsWidget::faster()
717 THEMIM->getIM()->faster();
720 void ControlsWidget::enableInput( bool enable )
722 slowerButton->setEnabled( enable );
723 slider->setEnabled( enable );
724 fasterButton->setEnabled( enable );
726 /* Advanced Buttons too */
727 advControls->enableInput( enable );
730 void ControlsWidget::enableVideo( bool enable )
732 // TODO Later make the fullscreenButton toggle Visualisation and so on.
733 fullscreenButton->setEnabled( enable );
735 /* Advanced Buttons too */
736 advControls->enableVideo( enable );
739 void ControlsWidget::toggleAdvanced()
741 if( !VISIBLE( advControls ) )
744 b_advancedVisible = true;
749 b_advancedVisible = false;
751 emit advancedControlsToggled( b_advancedVisible );
755 /**********************************************************************
756 * Speed control widget
757 **********************************************************************/
758 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
759 QFrame( NULL ), p_intf( _p_i )
761 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
762 sizePolicy.setHorizontalStretch( 0 );
763 sizePolicy.setVerticalStretch( 0 );
765 speedSlider = new QSlider;
766 speedSlider->setSizePolicy( sizePolicy );
767 speedSlider->setMaximumSize( QSize( 80, 200 ) );
768 speedSlider->setOrientation( Qt::Vertical );
769 speedSlider->setTickPosition( QSlider::TicksRight );
771 speedSlider->setRange( -100, 100 );
772 speedSlider->setSingleStep( 10 );
773 speedSlider->setPageStep( 20 );
774 speedSlider->setTickInterval( 20 );
776 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
778 QToolButton *normalSpeedButton = new QToolButton( this );
779 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
780 normalSpeedButton->setAutoRaise( true );
781 normalSpeedButton->setText( "N" );
782 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
784 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
786 QVBoxLayout *speedControlLayout = new QVBoxLayout;
787 speedControlLayout->addWidget( speedSlider );
788 speedControlLayout->addWidget( normalSpeedButton );
789 setLayout( speedControlLayout );
792 SpeedControlWidget::~SpeedControlWidget()
795 #define RATE_SLIDER_MAXIMUM 3.0
796 #define RATE_SLIDER_MINIMUM 0.3
797 #define RATE_SLIDER_LENGTH 100.0
799 void SpeedControlWidget::updateControls( int rate )
801 if( speedSlider->isSliderDown() )
803 //We don't want to change anything if the user is using the slider
808 double speed = INPUT_RATE_DEFAULT / (double)rate;
810 if( rate >= INPUT_RATE_DEFAULT )
812 if( speed < RATE_SLIDER_MINIMUM )
814 sliderValue = speedSlider->minimum();
818 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
819 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
824 if( speed > RATE_SLIDER_MAXIMUM )
826 sliderValue = speedSlider->maximum();
830 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
831 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
835 //Block signals to avoid feedback loop
836 speedSlider->blockSignals( true );
837 speedSlider->setValue( sliderValue );
838 speedSlider->blockSignals( false );
841 void SpeedControlWidget::updateRate( int sliderValue )
845 if( sliderValue < 0.0 )
847 rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
848 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ));
852 rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
853 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH ));
856 THEMIM->getIM()->setRate(rate);
859 void SpeedControlWidget::resetRate()
861 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);