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 *****************************************************************************/
30 #include "dialogs_provider.hpp"
31 #include "components/interface_widgets.hpp"
32 #include "main_interface.hpp"
33 #include "input_manager.hpp"
35 #include "util/input_slider.hpp"
36 #include "util/customwidgets.hpp"
40 #include <QSpacerItem>
42 #include <QPushButton>
43 #include <QToolButton>
44 #include <QHBoxLayout>
47 #include <QResizeEvent>
50 /**********************************************************************
51 * Video Widget. A simple frame on which video is drawn
52 * This class handles resize issues
53 **********************************************************************/
54 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
55 unsigned int *, unsigned int * );
56 static void DoRelease( intf_thread_t *, void * );
57 static int DoControl( intf_thread_t *, void *, int, va_list );
59 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
61 vlc_mutex_init( p_intf, &lock );
63 hide(); setMinimumSize( 16, 16 );
65 // CONNECT( this, askResize( int, int ), this, SetSizing( int, int ) );
66 CONNECT( this, askVideoWidgetToShow(), this, show() );
67 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
70 VideoWidget::~VideoWidget()
72 vlc_mutex_lock( &lock );
75 if( !p_intf->psz_switch_intf )
77 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
78 vout_Control( p_vout, VOUT_REPARENT );
82 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
83 vout_Control( p_vout, VOUT_CLOSE );
86 vlc_mutex_unlock( &lock );
87 vlc_mutex_destroy( &lock );
91 * Request the video to avoid the conflicts
93 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
94 unsigned int *pi_width, unsigned int *pi_height )
96 emit askVideoWidgetToShow();
99 msg_Dbg( p_intf, "embedded video already in use" );
103 return ( void* )winId();
106 /* Set the Widget to the correct Size */
107 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
110 //updateGeometry(); // Needed for deinterlace
111 msg_Dbg( p_intf, "%i %i", sizeHint().height(), sizeHint().width() );
115 void VideoWidget::release( void *p_win )
121 /**********************************************************************
122 * Background Widget. Show a simple image background. Currently,
123 * it's album art if present or cone.
124 **********************************************************************/
125 #define ICON_SIZE 128
126 #define MAX_BG_SIZE 400
127 #define MIN_BG_SIZE 64
129 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
130 QWidget( NULL ), p_intf( _p_i )
132 /* We should use that one to take the more size it can */
133 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
135 /* A dark background */
136 setAutoFillBackground( true );
138 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
139 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
142 /* A cone in the middle */
144 label->setMargin( 5 );
145 label->setMaximumHeight( MAX_BG_SIZE );
146 label->setMaximumWidth( MAX_BG_SIZE );
147 label->setMinimumHeight( MIN_BG_SIZE );
148 label->setMinimumWidth( MIN_BG_SIZE );
149 if( QDate::currentDate().dayOfYear() >= 354 )
150 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
152 label->setPixmap( QPixmap( ":/vlc128.png" ) );
154 QGridLayout *backgroundLayout = new QGridLayout( this );
155 backgroundLayout->addWidget( label, 0, 1 );
156 backgroundLayout->setColumnStretch( 0, 1 );
157 backgroundLayout->setColumnStretch( 2, 1 );
159 CONNECT( THEMIM->getIM(), artChanged( QString ), this, update( QString ) );
163 BackgroundWidget::~BackgroundWidget()
167 void BackgroundWidget::update( QString url )
171 if( QDate::currentDate().dayOfYear() >= 354 )
172 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
174 label->setPixmap( QPixmap( ":/vlc128.png" ) );
179 label->setPixmap( QPixmap( url ) );
180 msg_Dbg( p_intf, "changing input b_need_update done ");
184 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
186 QVLCMenu::PopupMenu( p_intf, true );
189 /**********************************************************************
190 * Visualization selector panel
191 **********************************************************************/
192 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
193 QFrame( NULL ), p_intf( _p_i )
195 QHBoxLayout *layout = new QHBoxLayout( this );
196 layout->setMargin( 0 );
197 QPushButton *prevButton = new QPushButton( "Prev" );
198 QPushButton *nextButton = new QPushButton( "Next" );
199 layout->addWidget( prevButton );
200 layout->addWidget( nextButton );
202 layout->addItem( new QSpacerItem( 40,20,
203 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
204 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
206 current = new QLabel( qtr( "None" ) );
207 layout->addWidget( current );
209 BUTTONACT( prevButton, prev() );
210 BUTTONACT( nextButton, next() );
213 setMaximumHeight( 35 );
216 VisualSelector::~VisualSelector()
220 void VisualSelector::prev()
222 char *psz_new = aout_VisualPrev( p_intf );
225 current->setText( qfu( psz_new ) );
230 void VisualSelector::next()
232 char *psz_new = aout_VisualNext( p_intf );
235 current->setText( qfu( psz_new ) );
240 /**********************************************************************
242 **********************************************************************/
244 #define setupSmallButton( aButton ){ \
245 aButton->setMaximumSize( QSize( 26, 26 ) ); \
246 aButton->setMinimumSize( QSize( 26, 26 ) ); \
247 aButton->setIconSize( QSize( 20, 20 ) ); }
249 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
250 QFrame( NULL ), p_intf( _p_i )
252 QHBoxLayout *advLayout = new QHBoxLayout( this );
253 advLayout->setMargin( 0 );
254 advLayout->setSpacing( 0 );
257 ABButton = new QPushButton( "AB" );
258 ABButton->setMaximumSize( QSize( 26, 26 ) );
259 ABButton->setIconSize( QSize( 20, 20 ) );
260 advLayout->addWidget( ABButton );
261 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
263 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
264 this, AtoBLoop( float, int, int ) );
266 frameButton = new QPushButton( "Fr" );
267 frameButton->setMaximumSize( QSize( 26, 26 ) );
268 frameButton->setIconSize( QSize( 20, 20 ) );
269 advLayout->addWidget( frameButton );
270 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
273 recordButton = new QPushButton( "R" );
274 recordButton->setMaximumSize( QSize( 26, 26 ) );
275 recordButton->setIconSize( QSize( 20, 20 ) );
276 advLayout->addWidget( recordButton );
277 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
278 qtr( "Record" ), record() );
280 /* Snapshot Button */
281 snapshotButton = new QPushButton( "S" );
282 snapshotButton->setMaximumSize( QSize( 26, 26 ) );
283 snapshotButton->setIconSize( QSize( 20, 20 ) );
284 advLayout->addWidget( snapshotButton );
285 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
288 AdvControlsWidget::~AdvControlsWidget()
291 void AdvControlsWidget::enableInput( bool enable )
293 ABButton->setEnabled( enable );
294 recordButton->setEnabled( enable );
297 void AdvControlsWidget::enableVideo( bool enable )
299 snapshotButton->setEnabled( enable );
301 frameButton->setEnabled( enable );
305 void AdvControlsWidget::snapshot()
307 vout_thread_t *p_vout =
308 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
309 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
312 /* Function called when the button is clicked() */
313 void AdvControlsWidget::fromAtoB()
317 timeA = var_GetTime( THEMIM->getInput(), "time" );
318 ABButton->setText( "A->..." );
323 timeB = var_GetTime( THEMIM->getInput(), "time" );
324 var_SetTime( THEMIM->getInput(), "time" , timeA );
325 ABButton->setText( "A<=>B" );
330 ABButton->setText( "AB" );
333 /* Function called regularly when in an AtoB loop */
334 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
338 if( i_time >= (int)(timeB/1000000) )
339 var_SetTime( THEMIM->getInput(), "time" , timeA );
343 /* FIXME Record function */
344 void AdvControlsWidget::record(){}
347 //FIXME Frame by frame function
348 void AdvControlsWidget::frame(){}
351 /*****************************
352 * DA Control Widget !
353 *****************************/
354 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
355 MainInterface *_p_mi,
358 QFrame( NULL ), p_intf( _p_i )
360 controlLayout = new QGridLayout( this );
361 controlLayout->setSpacing( 0 );
363 controlLayout->setContentsMargins( 9, 6, 9, 6 );
365 controlLayout->setMargin( 6 );
368 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
370 /** The main Slider **/
371 slider = new InputSlider( Qt::Horizontal, NULL );
372 controlLayout->addWidget( slider, 0, 1, 1, 16 );
373 /* Update the position when the IM has changed */
374 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
375 slider, setPosition( float, int, int ) );
376 /* And update the IM, when the position has changed */
377 CONNECT( slider, sliderDragged( float ),
378 THEMIM->getIM(), sliderUpdate( float ) );
380 /** Slower and faster Buttons **/
381 slowerButton = new QToolButton;
382 slowerButton->setAutoRaise( true );
383 slowerButton->setMaximumSize( QSize( 26, 20 ) );
385 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
386 controlLayout->addWidget( slowerButton, 0, 0 );
388 fasterButton = new QToolButton;
389 fasterButton->setAutoRaise( true );
390 fasterButton->setMaximumSize( QSize( 26, 20 ) );
392 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
393 controlLayout->addWidget( fasterButton, 0, 17 );
395 /* advanced Controls handling */
396 b_advancedVisible = b_advControls;
398 advControls = new AdvControlsWidget( p_intf );
399 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
400 if( !b_advancedVisible ) advControls->hide();
402 /** Disc and Menus handling */
403 discFrame = new QWidget( this );
405 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
406 discLayout->setSpacing( 0 );
407 discLayout->setMargin( 0 );
409 prevSectionButton = new QPushButton( discFrame );
410 setupSmallButton( prevSectionButton );
411 discLayout->addWidget( prevSectionButton );
413 menuButton = new QPushButton( discFrame );
414 setupSmallButton( menuButton );
415 discLayout->addWidget( menuButton );
417 nextSectionButton = new QPushButton( discFrame );
418 setupSmallButton( nextSectionButton );
419 discLayout->addWidget( nextSectionButton );
421 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
423 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
424 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
425 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
429 /* Change the navigation button display when the IM navigation changes */
430 CONNECT( THEMIM->getIM(), navigationChanged( int ),
431 this, setNavigation( int ) );
432 /* Changes the IM navigation when triggered on the nav buttons */
433 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
435 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
437 CONNECT( menuButton, clicked(), THEMIM->getIM(),
441 * TODO: Merge with upper menu in a StackLayout
444 telexFrame = new QWidget( this );
445 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
446 telexLayout->setSpacing( 0 );
447 telexLayout->setMargin( 0 );
449 QToolButton *telexOn = new QToolButton;
450 telexOn->setText( qtr( "On" ) );
451 setupSmallButton( telexOn );
452 telexLayout->addWidget( telexOn );
454 QToolButton *telexTransparent = new QToolButton;
455 telexTransparent->setText( qtr( "Transparent" ) );
456 setupSmallButton( telexTransparent );
457 telexLayout->addWidget( telexTransparent );
459 QSpinBox *telexPage = new QSpinBox;
460 telexPage->setRange( 0, 999 );
461 telexPage->setValue( 100 );
462 telexPage->setAlignment( Qt::AlignRight );
463 telexLayout->addWidget( telexPage );
465 controlLayout->addWidget( telexFrame, 1, 10, 2, 3, Qt::AlignBottom );
468 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
469 telexGotoPage( int ) );
470 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
471 telexToggle( bool ) );
472 CONNECT( telexTransparent, clicked( bool ),
473 THEMIM->getIM(), telexSetTransparency( bool ) );
474 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
475 telexFrame, setVisible( bool ) );
479 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
480 sizePolicy.setHorizontalStretch( 0 );
481 sizePolicy.setVerticalStretch( 0 );
484 playButton = new QPushButton;
485 playButton->setSizePolicy( sizePolicy );
486 playButton->setMaximumSize( QSize( 36, 36 ) );
487 playButton->setMinimumSize( QSize( 36, 36 ) );
488 playButton->setIconSize( QSize( 30, 30 ) );
490 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
492 controlLayout->setColumnMinimumWidth( 2, 20 );
493 controlLayout->setColumnStretch( 2, 0 );
495 /** Prev + Stop + Next Block **/
496 QHBoxLayout *controlButLayout = new QHBoxLayout;
497 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
500 QPushButton *prevButton = new QPushButton;
501 prevButton->setSizePolicy( sizePolicy );
502 setupSmallButton( prevButton );
504 controlButLayout->addWidget( prevButton );
507 QPushButton *stopButton = new QPushButton;
508 stopButton->setSizePolicy( sizePolicy );
509 setupSmallButton( stopButton );
511 controlButLayout->addWidget( stopButton );
514 QPushButton *nextButton = new QPushButton;
515 nextButton->setSizePolicy( sizePolicy );
516 setupSmallButton( nextButton );
518 controlButLayout->addWidget( nextButton );
520 /* Add this block to the main layout */
521 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
523 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
524 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
525 qtr( "Previous" ), prev() );
526 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
527 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
529 controlLayout->setColumnMinimumWidth( 7, 20 );
530 controlLayout->setColumnStretch( 7, 0 );
531 controlLayout->setColumnStretch( 8, 0 );
532 controlLayout->setColumnStretch( 9, 0 );
535 * Other first Line buttons
537 /** Fullscreen/Visualisation **/
538 fullscreenButton = new QPushButton( "F" );
539 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
540 setupSmallButton( fullscreenButton );
541 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
543 /** Playlist Button **/
544 playlistButton = new QPushButton;
545 setupSmallButton( playlistButton );
546 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
547 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
548 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
550 /** extended Settings **/
551 QPushButton *extSettingsButton = new QPushButton( "F" );
552 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
554 setupSmallButton( extSettingsButton );
555 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
557 controlLayout->setColumnStretch( 13, 0 );
558 controlLayout->setColumnMinimumWidth( 13, 24 );
559 controlLayout->setColumnStretch( 14, 5 );
562 VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
564 volMuteLabel = new QLabel;
565 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
566 volMuteLabel->setToolTip( qtr( "Mute" ) );
567 volMuteLabel->installEventFilter( hVolLabel );
568 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
572 volumeSlider = new SoundSlider( this,
573 config_GetInt( p_intf, "volume-step" ),
574 config_GetInt( p_intf, "qt-volume-complete" ) );
578 volumeSlider = new QSlider( this );
579 volumeSlider->setOrientation( Qt::Horizontal );
581 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
582 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
583 volumeSlider->setFocusPolicy( Qt::NoFocus );
584 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
586 /* Set the volume from the config */
587 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
588 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
590 /* Volume control connection */
591 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
592 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
595 ControlsWidget::~ControlsWidget()
598 void ControlsWidget::stop()
603 void ControlsWidget::play()
605 if( THEPL->current.i_size == 0 )
607 /* The playlist is empty, open a file requester */
608 THEDP->openFileDialog();
612 THEMIM->togglePlayPause();
615 void ControlsWidget::prev()
620 void ControlsWidget::next()
625 void ControlsWidget::setNavigation( int navigation )
627 #define HELP_MENU N_( "Menu" )
628 #define HELP_PCH N_( "Previous chapter" )
629 #define HELP_NCH N_( "Next chapter" )
630 #define HELP_PTR N_( "Previous track" )
631 #define HELP_NTR N_( "Next track" )
633 // 1 = chapter, 2 = title, 0 = no
634 if( navigation == 0 )
637 } else if( navigation == 1 ) {
638 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
639 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
643 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
644 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
650 static bool b_my_volume;
651 void ControlsWidget::updateVolume( int i_sliderVolume )
655 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
656 aout_VolumeSet( p_intf, i_res );
658 if( i_sliderVolume == 0 )
659 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
660 else if( i_sliderVolume < VOLUME_MAX / 3 )
661 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
662 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
663 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
664 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
667 void ControlsWidget::updateVolume()
670 audio_volume_t i_volume;
671 aout_VolumeGet( p_intf, &i_volume );
672 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
673 int i_gauge = volumeSlider->value();
675 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
678 volumeSlider->setValue( i_volume );
682 /* Activate the interface buttons according to the presence of the input */
683 enableInput( THEMIM->getIM()->hasInput() );
684 //enableVideo( THEMIM->getIM()->hasVideo() );
688 void ControlsWidget::setStatus( int status )
690 if( status == PLAYING_S ) // Playing
691 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
693 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
698 * This functions toggle the fullscreen mode
699 * If there is no video, it should first activate Visualisations...
700 * This has also to be fixed in enableVideo()
702 void ControlsWidget::fullscreen()
704 vout_thread_t *p_vout =
705 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
708 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
709 vlc_object_release( p_vout );
713 void ControlsWidget::extSettings()
715 THEDP->extendedDialog();
718 void ControlsWidget::slower()
720 THEMIM->getIM()->slower();
723 void ControlsWidget::faster()
725 THEMIM->getIM()->faster();
728 void ControlsWidget::enableInput( bool enable )
730 slowerButton->setEnabled( enable );
731 slider->setEnabled( enable );
732 fasterButton->setEnabled( enable );
734 /* Advanced Buttons too */
735 advControls->enableInput( enable );
738 void ControlsWidget::enableVideo( bool enable )
740 // TODO Later make the fullscreenButton toggle Visualisation and so on.
741 fullscreenButton->setEnabled( enable );
743 /* Advanced Buttons too */
744 advControls->enableVideo( enable );
747 void ControlsWidget::toggleAdvanced()
749 if( !VISIBLE( advControls ) )
752 b_advancedVisible = true;
757 b_advancedVisible = false;
759 emit advancedControlsToggled( b_advancedVisible );
763 /**********************************************************************
764 * Speed control widget
765 **********************************************************************/
766 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
767 QFrame( NULL ), p_intf( _p_i )
769 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
770 sizePolicy.setHorizontalStretch( 0 );
771 sizePolicy.setVerticalStretch( 0 );
773 speedSlider = new QSlider;
774 speedSlider->setSizePolicy( sizePolicy );
775 speedSlider->setMaximumSize( QSize( 80, 200 ) );
776 speedSlider->setOrientation( Qt::Vertical );
777 speedSlider->setTickPosition( QSlider::TicksRight );
779 speedSlider->setRange( -100, 100 );
780 speedSlider->setSingleStep( 10 );
781 speedSlider->setPageStep( 20 );
782 speedSlider->setTickInterval( 20 );
784 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
786 QToolButton *normalSpeedButton = new QToolButton( this );
787 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
788 normalSpeedButton->setAutoRaise( true );
789 normalSpeedButton->setText( "N" );
790 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
792 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
794 QVBoxLayout *speedControlLayout = new QVBoxLayout;
795 speedControlLayout->addWidget( speedSlider );
796 speedControlLayout->addWidget( normalSpeedButton );
797 setLayout( speedControlLayout );
800 SpeedControlWidget::~SpeedControlWidget()
803 #define RATE_SLIDER_MAXIMUM 3.0
804 #define RATE_SLIDER_MINIMUM 0.3
805 #define RATE_SLIDER_LENGTH 100.0
807 void SpeedControlWidget::updateControls( int rate )
809 if( speedSlider->isSliderDown() )
811 //We don't want to change anything if the user is using the slider
816 double speed = INPUT_RATE_DEFAULT / (double)rate;
818 if( rate >= INPUT_RATE_DEFAULT )
820 if( speed < RATE_SLIDER_MINIMUM )
822 sliderValue = speedSlider->minimum();
826 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
827 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
832 if( speed > RATE_SLIDER_MAXIMUM )
834 sliderValue = speedSlider->maximum();
838 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
839 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
843 //Block signals to avoid feedback loop
844 speedSlider->blockSignals( true );
845 speedSlider->setValue( sliderValue );
846 speedSlider->blockSignals( false );
849 void SpeedControlWidget::updateRate( int sliderValue )
853 if( sliderValue < 0.0 )
855 rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
856 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ));
860 rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
861 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH ));
864 THEMIM->getIM()->setRate(rate);
867 void SpeedControlWidget::resetRate()
869 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);