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" ) );
175 QString arturl = url.replace( "file://",QString("" ) );
176 if( arturl.isNull() )
178 if( QDate::currentDate().dayOfYear() >= 354 )
179 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
181 label->setPixmap( QPixmap( ":/vlc128.png" ) );
185 label->setPixmap( QPixmap( arturl ) );
186 msg_Dbg( p_intf, "changing input b_need_update done ");
190 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
192 QVLCMenu::PopupMenu( p_intf, true );
195 /**********************************************************************
196 * Visualization selector panel
197 **********************************************************************/
198 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
199 QFrame( NULL ), p_intf( _p_i )
201 QHBoxLayout *layout = new QHBoxLayout( this );
202 layout->setMargin( 0 );
203 QPushButton *prevButton = new QPushButton( "Prev" );
204 QPushButton *nextButton = new QPushButton( "Next" );
205 layout->addWidget( prevButton );
206 layout->addWidget( nextButton );
208 layout->addItem( new QSpacerItem( 40,20,
209 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
210 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
212 current = new QLabel( qtr( "None" ) );
213 layout->addWidget( current );
215 BUTTONACT( prevButton, prev() );
216 BUTTONACT( nextButton, next() );
219 setMaximumHeight( 35 );
222 VisualSelector::~VisualSelector()
226 void VisualSelector::prev()
228 char *psz_new = aout_VisualPrev( p_intf );
231 current->setText( qfu( psz_new ) );
236 void VisualSelector::next()
238 char *psz_new = aout_VisualNext( p_intf );
241 current->setText( qfu( psz_new ) );
246 /**********************************************************************
248 **********************************************************************/
250 #define setupSmallButton( aButton ){ \
251 aButton->setMaximumSize( QSize( 26, 26 ) ); \
252 aButton->setMinimumSize( QSize( 26, 26 ) ); \
253 aButton->setIconSize( QSize( 20, 20 ) ); }
255 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
256 QFrame( NULL ), p_intf( _p_i )
258 QHBoxLayout *advLayout = new QHBoxLayout( this );
259 advLayout->setMargin( 0 );
260 advLayout->setSpacing( 0 );
263 ABButton = new QPushButton( "AB" );
264 ABButton->setMaximumSize( QSize( 26, 26 ) );
265 ABButton->setIconSize( QSize( 20, 20 ) );
266 advLayout->addWidget( ABButton );
267 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
269 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
270 this, AtoBLoop( float, int, int ) );
272 frameButton = new QPushButton( "Fr" );
273 frameButton->setMaximumSize( QSize( 26, 26 ) );
274 frameButton->setIconSize( QSize( 20, 20 ) );
275 advLayout->addWidget( frameButton );
276 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
278 recordButton = new QPushButton( "R" );
279 recordButton->setMaximumSize( QSize( 26, 26 ) );
280 recordButton->setIconSize( QSize( 20, 20 ) );
281 advLayout->addWidget( recordButton );
282 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
283 qtr( "Record" ), record() );
285 /* Snapshot Button */
286 snapshotButton = new QPushButton( "S" );
287 snapshotButton->setMaximumSize( QSize( 26, 26 ) );
288 snapshotButton->setIconSize( QSize( 20, 20 ) );
289 advLayout->addWidget( snapshotButton );
290 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
293 AdvControlsWidget::~AdvControlsWidget()
296 void AdvControlsWidget::enableInput( bool enable )
298 ABButton->setEnabled( enable );
299 recordButton->setEnabled( enable );
302 void AdvControlsWidget::enableVideo( bool enable )
304 snapshotButton->setEnabled( enable );
305 frameButton->setEnabled( enable );
308 void AdvControlsWidget::snapshot()
310 vout_thread_t *p_vout =
311 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
312 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
315 /* Function called when the button is clicked() */
316 void AdvControlsWidget::fromAtoB()
320 timeA = var_GetTime( THEMIM->getInput(), "time" );
321 ABButton->setText( "A->..." );
326 timeB = var_GetTime( THEMIM->getInput(), "time" );
327 var_SetTime( THEMIM->getInput(), "time" , timeA );
328 ABButton->setText( "A<=>B" );
333 ABButton->setText( "AB" );
336 /* Function called regularly when in an AtoB loop */
337 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
341 if( i_time >= (int)(timeB/1000000) )
342 var_SetTime( THEMIM->getInput(), "time" , timeA );
346 /* FIXME Record function */
347 void AdvControlsWidget::record(){}
349 //FIXME Frame by frame function
350 void AdvControlsWidget::frame(){}
352 /*****************************
353 * DA Control Widget !
354 *****************************/
355 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
356 MainInterface *_p_mi,
359 QFrame( NULL ), p_intf( _p_i )
361 controlLayout = new QGridLayout( this );
362 controlLayout->setSpacing( 0 );
364 controlLayout->setContentsMargins( 9, 6, 9, 6 );
366 controlLayout->setMargin( 6 );
369 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
371 /** The main Slider **/
372 slider = new InputSlider( Qt::Horizontal, NULL );
373 controlLayout->addWidget( slider, 0, 1, 1, 16 );
374 /* Update the position when the IM has changed */
375 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
376 slider, setPosition( float, int, int ) );
377 /* And update the IM, when the position has changed */
378 CONNECT( slider, sliderDragged( float ),
379 THEMIM->getIM(), sliderUpdate( float ) );
381 /** Slower and faster Buttons **/
382 slowerButton = new QToolButton;
383 slowerButton->setAutoRaise( true );
384 slowerButton->setMaximumSize( QSize( 26, 20 ) );
386 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
387 controlLayout->addWidget( slowerButton, 0, 0 );
389 fasterButton = new QToolButton;
390 fasterButton->setAutoRaise( true );
391 fasterButton->setMaximumSize( QSize( 26, 20 ) );
393 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
394 controlLayout->addWidget( fasterButton, 0, 17 );
396 /* advanced Controls handling */
397 b_advancedVisible = b_advControls;
399 advControls = new AdvControlsWidget( p_intf );
400 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
401 if( !b_advancedVisible ) advControls->hide();
403 /** Disc and Menus handling */
404 discFrame = new QWidget( this );
406 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
407 discLayout->setSpacing( 0 );
408 discLayout->setMargin( 0 );
410 prevSectionButton = new QPushButton( discFrame );
411 setupSmallButton( prevSectionButton );
412 discLayout->addWidget( prevSectionButton );
414 menuButton = new QPushButton( discFrame );
415 setupSmallButton( menuButton );
416 discLayout->addWidget( menuButton );
418 nextSectionButton = new QPushButton( discFrame );
419 setupSmallButton( nextSectionButton );
420 discLayout->addWidget( nextSectionButton );
422 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
424 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
425 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
426 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
430 /* Change the navigation button display when the IM navigation changes */
431 CONNECT( THEMIM->getIM(), navigationChanged( int ),
432 this, setNavigation( int ) );
433 /* Changes the IM navigation when triggered on the nav buttons */
434 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
436 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
438 CONNECT( menuButton, clicked(), THEMIM->getIM(),
442 * TODO: Merge with upper menu in a StackLayout
445 telexFrame = new QWidget( this );
446 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
447 telexLayout->setSpacing( 0 );
448 telexLayout->setMargin( 0 );
450 QToolButton *telexOn = new QToolButton;
451 telexOn->setText( qtr( "On" ) );
452 setupSmallButton( telexOn );
453 telexLayout->addWidget( telexOn );
455 QToolButton *telexTransparent = new QToolButton;
456 telexTransparent->setText( qtr( "Transparent" ) );
457 setupSmallButton( telexTransparent );
458 telexLayout->addWidget( telexTransparent );
460 QSpinBox *telexPage = new QSpinBox;
461 telexPage->setRange( 0, 999 );
462 telexPage->setValue( 100 );
463 telexPage->setAlignment( Qt::AlignRight );
464 telexLayout->addWidget( telexPage );
466 controlLayout->addWidget( telexFrame, 1, 10, 2, 3, Qt::AlignBottom );
469 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
470 telexGotoPage( int ) );
471 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
472 telexToggle( bool ) );
473 CONNECT( telexTransparent, clicked( bool ),
474 THEMIM->getIM(), telexSetTransparency( bool ) );
475 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
476 telexFrame, setVisible( bool ) );
480 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
481 sizePolicy.setHorizontalStretch( 0 );
482 sizePolicy.setVerticalStretch( 0 );
485 playButton = new QPushButton;
486 playButton->setSizePolicy( sizePolicy );
487 playButton->setMaximumSize( QSize( 36, 36 ) );
488 playButton->setMinimumSize( QSize( 36, 36 ) );
489 playButton->setIconSize( QSize( 30, 30 ) );
491 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
493 controlLayout->setColumnMinimumWidth( 2, 20 );
494 controlLayout->setColumnStretch( 2, 0 );
496 /** Prev + Stop + Next Block **/
497 QHBoxLayout *controlButLayout = new QHBoxLayout;
498 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
501 QPushButton *prevButton = new QPushButton;
502 prevButton->setSizePolicy( sizePolicy );
503 setupSmallButton( prevButton );
505 controlButLayout->addWidget( prevButton );
508 QPushButton *stopButton = new QPushButton;
509 stopButton->setSizePolicy( sizePolicy );
510 setupSmallButton( stopButton );
512 controlButLayout->addWidget( stopButton );
515 QPushButton *nextButton = new QPushButton;
516 nextButton->setSizePolicy( sizePolicy );
517 setupSmallButton( nextButton );
519 controlButLayout->addWidget( nextButton );
521 /* Add this block to the main layout */
522 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
524 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
525 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
526 qtr( "Previous" ), prev() );
527 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
528 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
530 controlLayout->setColumnMinimumWidth( 7, 20 );
531 controlLayout->setColumnStretch( 7, 0 );
532 controlLayout->setColumnStretch( 8, 0 );
533 controlLayout->setColumnStretch( 9, 0 );
536 * Other first Line buttons
538 /** Fullscreen/Visualisation **/
539 fullscreenButton = new QPushButton( "F" );
540 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
541 setupSmallButton( fullscreenButton );
542 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
544 /** Playlist Button **/
545 playlistButton = new QPushButton;
546 setupSmallButton( playlistButton );
547 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
548 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
549 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
551 /** extended Settings **/
552 QPushButton *extSettingsButton = new QPushButton( "F" );
553 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
555 setupSmallButton( extSettingsButton );
556 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
558 controlLayout->setColumnStretch( 13, 0 );
559 controlLayout->setColumnMinimumWidth( 13, 24 );
560 controlLayout->setColumnStretch( 14, 5 );
563 VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
565 volMuteLabel = new QLabel;
566 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
567 volMuteLabel->setToolTip( qtr( "Mute" ) );
568 volMuteLabel->installEventFilter( hVolLabel );
569 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
573 volumeSlider = new SoundSlider( this,
574 config_GetInt( p_intf, "volume-step" ),
575 config_GetInt( p_intf, "qt-volume-complete" ) );
579 volumeSlider = new QSlider( this );
580 volumeSlider->setOrientation( Qt::Horizontal );
582 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
583 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
584 volumeSlider->setFocusPolicy( Qt::NoFocus );
585 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
587 /* Set the volume from the config */
588 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
589 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
591 /* Volume control connection */
592 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
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::updateOnTimer()
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 = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
856 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH );
860 rate = 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);