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 *****************************************************************************/
31 #include "dialogs_provider.hpp"
32 #include "components/interface_widgets.hpp"
33 #include "main_interface.hpp"
34 #include "input_manager.hpp"
36 #include "util/input_slider.hpp"
37 #include "util/customwidgets.hpp"
41 #include <QSpacerItem>
43 #include <QPushButton>
44 #include <QToolButton>
45 #include <QHBoxLayout>
48 #include <QResizeEvent>
51 /**********************************************************************
52 * Video Widget. A simple frame on which video is drawn
53 * This class handles resize issues
54 **********************************************************************/
55 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
56 unsigned int *, unsigned int * );
57 static void DoRelease( intf_thread_t *, void * );
58 static int DoControl( intf_thread_t *, void *, int, va_list );
60 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
63 vlc_mutex_init( &lock );
65 hide(); setMinimumSize( 16, 16 );
66 videoSize.rwidth() = -1;
67 videoSize.rheight() = -1;
69 /* Black background is more coherent for a Video Widget IMVHO */
70 QPalette plt = palette();
71 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
72 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
75 /* The core can ask through a callback to show the video */
76 CONNECT( this, askVideoWidgetToShow(), this, show() );
77 /* The core can ask through a callback to resize the video */
78 // CONNECT( this, askResize( int, int ), this, SetSizing( int, int ) );
81 VideoWidget::~VideoWidget()
83 vlc_mutex_lock( &lock );
86 if( !p_intf->psz_switch_intf )
88 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
89 vout_Control( p_vout, VOUT_REPARENT );
93 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
94 vout_Control( p_vout, VOUT_CLOSE );
97 vlc_mutex_unlock( &lock );
98 vlc_mutex_destroy( &lock );
102 * Request the video to avoid the conflicts
104 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
105 unsigned int *pi_width, unsigned int *pi_height )
107 msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
108 emit askVideoWidgetToShow();
111 msg_Dbg( p_intf, "embedded video already in use" );
115 return ( void* )winId();
118 /* Set the Widget to the correct Size */
119 /* Function has to be called by the parent
120 Parent has to care about resizing himself*/
121 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
123 msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
124 videoSize.rwidth() = w;
125 videoSize.rheight() = h;
126 updateGeometry(); // Needed for deinterlace
129 void VideoWidget::release( void *p_win )
131 msg_Dbg( p_intf, "Video is non needed anymore" );
133 videoSize.rwidth() = 0;
134 videoSize.rheight() = 0;
136 updateGeometry(); // Needed for deinterlace
139 QSize VideoWidget::sizeHint() const
144 /**********************************************************************
145 * Background Widget. Show a simple image background. Currently,
146 * it's album art if present or cone.
147 **********************************************************************/
148 #define ICON_SIZE 128
149 #define MAX_BG_SIZE 400
150 #define MIN_BG_SIZE 64
152 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
153 :QWidget( NULL ), p_intf( _p_i )
155 /* We should use that one to take the more size it can */
156 // setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
158 /* A dark background */
159 setAutoFillBackground( true );
161 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
162 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
165 /* A cone in the middle */
167 label->setMargin( 5 );
168 label->setMaximumHeight( MAX_BG_SIZE );
169 label->setMaximumWidth( MAX_BG_SIZE );
170 label->setMinimumHeight( MIN_BG_SIZE );
171 label->setMinimumWidth( MIN_BG_SIZE );
172 if( QDate::currentDate().dayOfYear() >= 354 )
173 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
175 label->setPixmap( QPixmap( ":/vlc128.png" ) );
177 QGridLayout *backgroundLayout = new QGridLayout( this );
178 backgroundLayout->addWidget( label, 0, 1 );
179 backgroundLayout->setColumnStretch( 0, 1 );
180 backgroundLayout->setColumnStretch( 2, 1 );
182 CONNECT( THEMIM->getIM(), artChanged( QString ), this, updateArt( QString ) );
185 BackgroundWidget::~BackgroundWidget()
189 void BackgroundWidget::resizeEvent( QResizeEvent * event )
191 if( event->size().height() <= MIN_BG_SIZE )
197 void BackgroundWidget::updateArt( QString url )
201 if( QDate::currentDate().dayOfYear() >= 354 )
202 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
204 label->setPixmap( QPixmap( ":/vlc128.png" ) );
209 label->setPixmap( QPixmap( url ) );
213 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
215 QVLCMenu::PopupMenu( p_intf, true );
218 /**********************************************************************
219 * Visualization selector panel
220 **********************************************************************/
221 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
222 QFrame( NULL ), p_intf( _p_i )
224 QHBoxLayout *layout = new QHBoxLayout( this );
225 layout->setMargin( 0 );
226 QPushButton *prevButton = new QPushButton( "Prev" );
227 QPushButton *nextButton = new QPushButton( "Next" );
228 layout->addWidget( prevButton );
229 layout->addWidget( nextButton );
231 layout->addItem( new QSpacerItem( 40,20,
232 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
233 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
235 current = new QLabel( qtr( "None" ) );
236 layout->addWidget( current );
238 BUTTONACT( prevButton, prev() );
239 BUTTONACT( nextButton, next() );
242 setMaximumHeight( 35 );
245 VisualSelector::~VisualSelector()
249 void VisualSelector::prev()
251 char *psz_new = aout_VisualPrev( p_intf );
254 current->setText( qfu( psz_new ) );
259 void VisualSelector::next()
261 char *psz_new = aout_VisualNext( p_intf );
264 current->setText( qfu( psz_new ) );
269 /**********************************************************************
271 **********************************************************************/
273 #define setupSmallButton( aButton ){ \
274 aButton->setMaximumSize( QSize( 26, 26 ) ); \
275 aButton->setMinimumSize( QSize( 26, 26 ) ); \
276 aButton->setIconSize( QSize( 20, 20 ) ); }
278 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
279 QFrame( NULL ), p_intf( _p_i )
281 QHBoxLayout *advLayout = new QHBoxLayout( this );
282 advLayout->setMargin( 0 );
283 advLayout->setSpacing( 0 );
284 advLayout->setAlignment( Qt::AlignBottom );
287 ABButton = new QPushButton( "AB" );
288 setupSmallButton( ABButton );
289 advLayout->addWidget( ABButton );
290 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
292 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
293 this, AtoBLoop( float, int, int ) );
295 frameButton = new QPushButton( "Fr" );
296 frameButton->setMaximumSize( QSize( 26, 26 ) );
297 frameButton->setIconSize( QSize( 20, 20 ) );
298 advLayout->addWidget( frameButton );
299 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
302 recordButton = new QPushButton( "R" );
303 setupSmallButton( recordButton );
304 advLayout->addWidget( recordButton );
305 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
306 qtr( "Record" ), record() );
308 /* Snapshot Button */
309 snapshotButton = new QPushButton( "S" );
310 setupSmallButton( snapshotButton );
311 advLayout->addWidget( snapshotButton );
312 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
315 AdvControlsWidget::~AdvControlsWidget()
318 void AdvControlsWidget::enableInput( bool enable )
320 ABButton->setEnabled( enable );
321 recordButton->setEnabled( enable );
324 void AdvControlsWidget::enableVideo( bool enable )
326 snapshotButton->setEnabled( enable );
328 frameButton->setEnabled( enable );
332 void AdvControlsWidget::snapshot()
334 vout_thread_t *p_vout =
335 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
336 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
339 /* Function called when the button is clicked() */
340 void AdvControlsWidget::fromAtoB()
344 timeA = var_GetTime( THEMIM->getInput(), "time" );
345 ABButton->setText( "A->..." );
350 timeB = var_GetTime( THEMIM->getInput(), "time" );
351 var_SetTime( THEMIM->getInput(), "time" , timeA );
352 ABButton->setText( "A<=>B" );
357 ABButton->setText( "AB" );
360 /* Function called regularly when in an AtoB loop */
361 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
365 if( i_time >= (int)(timeB/1000000) )
366 var_SetTime( THEMIM->getInput(), "time" , timeA );
370 /* FIXME Record function */
371 void AdvControlsWidget::record(){}
374 //FIXME Frame by frame function
375 void AdvControlsWidget::frame(){}
378 /*****************************
379 * DA Control Widget !
380 *****************************/
381 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
382 MainInterface *_p_mi,
386 QFrame( _p_mi ), p_intf( _p_i )
388 controlLayout = new QGridLayout( );
390 controlLayout->setSpacing( 0 );
391 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
394 setLayout( controlLayout );
396 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
398 /** The main Slider **/
399 slider = new InputSlider( Qt::Horizontal, NULL );
400 controlLayout->addWidget( slider, 0, 1, 1, 16 );
401 /* Update the position when the IM has changed */
402 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
403 slider, setPosition( float, int, int ) );
404 /* And update the IM, when the position has changed */
405 CONNECT( slider, sliderDragged( float ),
406 THEMIM->getIM(), sliderUpdate( float ) );
408 /** Slower and faster Buttons **/
409 slowerButton = new QToolButton;
410 slowerButton->setAutoRaise( true );
411 slowerButton->setMaximumSize( QSize( 26, 20 ) );
413 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
414 controlLayout->addWidget( slowerButton, 0, 0 );
416 fasterButton = new QToolButton;
417 fasterButton->setAutoRaise( true );
418 fasterButton->setMaximumSize( QSize( 26, 20 ) );
420 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
421 controlLayout->addWidget( fasterButton, 0, 17 );
423 /* advanced Controls handling */
424 b_advancedVisible = b_advControls;
426 advControls = new AdvControlsWidget( p_intf );
427 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
428 if( !b_advancedVisible ) advControls->hide();
430 /** Disc and Menus handling */
431 discFrame = new QWidget( this );
433 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
434 discLayout->setSpacing( 0 );
435 discLayout->setMargin( 0 );
437 prevSectionButton = new QPushButton( discFrame );
438 setupSmallButton( prevSectionButton );
439 discLayout->addWidget( prevSectionButton );
441 menuButton = new QPushButton( discFrame );
442 setupSmallButton( menuButton );
443 discLayout->addWidget( menuButton );
445 nextSectionButton = new QPushButton( discFrame );
446 setupSmallButton( nextSectionButton );
447 discLayout->addWidget( nextSectionButton );
449 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
451 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
452 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
453 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
457 /* Change the navigation button display when the IM navigation changes */
458 CONNECT( THEMIM->getIM(), navigationChanged( int ),
459 this, setNavigation( int ) );
460 /* Changes the IM navigation when triggered on the nav buttons */
461 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
463 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
465 CONNECT( menuButton, clicked(), THEMIM->getIM(),
469 * TODO: Merge with upper menu in a StackLayout
471 telexFrame = new QWidget( this );
472 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
473 telexLayout->setSpacing( 0 );
474 telexLayout->setMargin( 0 );
476 QToolButton *telexOn = new QToolButton;
477 telexOn->setText( qtr( "On" ) );
478 setupSmallButton( telexOn );
479 telexLayout->addWidget( telexOn );
481 QToolButton *telexTransparent = new QToolButton;
482 telexTransparent->setText( qtr( "Transparent" ) );
483 setupSmallButton( telexTransparent );
484 telexLayout->addWidget( telexTransparent );
486 QSpinBox *telexPage = new QSpinBox;
487 telexPage->setRange( 0, 999 );
488 telexPage->setValue( 100 );
489 telexPage->setAccelerated( true );
490 telexPage->setWrapping( true );
491 telexPage->setAlignment( Qt::AlignRight );
492 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
493 telexLayout->addWidget( telexPage );
495 controlLayout->addWidget( telexFrame, 1, 10, 2, 3, Qt::AlignBottom );
498 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
499 telexGotoPage( int ) );
500 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
501 telexToggle( bool ) );
502 CONNECT( telexTransparent, clicked( bool ),
503 THEMIM->getIM(), telexSetTransparency( bool ) );
504 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
505 telexFrame, setVisible( bool ) );
508 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
509 sizePolicy.setHorizontalStretch( 0 );
510 sizePolicy.setVerticalStretch( 0 );
513 playButton = new QPushButton;
514 playButton->setSizePolicy( sizePolicy );
515 playButton->setMaximumSize( QSize( 36, 36 ) );
516 playButton->setMinimumSize( QSize( 36, 36 ) );
517 playButton->setIconSize( QSize( 30, 30 ) );
519 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
521 controlLayout->setColumnMinimumWidth( 2, 20 );
522 controlLayout->setColumnStretch( 2, 0 );
524 /** Prev + Stop + Next Block **/
525 controlButLayout = new QHBoxLayout;
526 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
529 QPushButton *prevButton = new QPushButton;
530 prevButton->setSizePolicy( sizePolicy );
531 setupSmallButton( prevButton );
533 controlButLayout->addWidget( prevButton );
536 QPushButton *stopButton = new QPushButton;
537 stopButton->setSizePolicy( sizePolicy );
538 setupSmallButton( stopButton );
540 controlButLayout->addWidget( stopButton );
543 QPushButton *nextButton = new QPushButton;
544 nextButton->setSizePolicy( sizePolicy );
545 setupSmallButton( nextButton );
547 controlButLayout->addWidget( nextButton );
549 /* Add this block to the main layout */
551 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
553 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
554 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
555 qtr( "Previous" ), prev() );
556 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
557 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
559 controlLayout->setColumnMinimumWidth( 7, 20 );
560 controlLayout->setColumnStretch( 7, 0 );
561 controlLayout->setColumnStretch( 8, 0 );
562 controlLayout->setColumnStretch( 9, 0 );
565 * Other first Line buttons
567 /** Fullscreen/Visualisation **/
568 fullscreenButton = new QPushButton( "F" );
569 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
570 setupSmallButton( fullscreenButton );
571 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
573 /** Playlist Button **/
574 playlistButton = new QPushButton;
575 setupSmallButton( playlistButton );
576 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
577 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
578 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
580 /** extended Settings **/
581 extSettingsButton = new QPushButton;
582 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
584 setupSmallButton( extSettingsButton );
585 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
587 controlLayout->setColumnStretch( 13, 0 );
588 controlLayout->setColumnMinimumWidth( 13, 24 );
589 controlLayout->setColumnStretch( 14, 5 );
592 hVolLabel = new VolumeClickHandler( p_intf, this );
594 volMuteLabel = new QLabel;
595 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
596 volMuteLabel->setToolTip( qtr( "Mute" ) );
597 volMuteLabel->installEventFilter( hVolLabel );
598 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
602 volumeSlider = new SoundSlider( this,
603 config_GetInt( p_intf, "volume-step" ),
604 config_GetInt( p_intf, "qt-volume-complete" ),
605 config_GetPsz( p_intf, "qt-slider-colours" ) );
609 volumeSlider = new QSlider( this );
610 volumeSlider->setOrientation( Qt::Horizontal );
612 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
613 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
614 volumeSlider->setFocusPolicy( Qt::NoFocus );
615 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
617 /* Set the volume from the config */
618 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
619 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
621 /* Force the update at build time in order to have a muted icon if needed */
622 updateVolume( volumeSlider->value() );
624 /* Volume control connection */
625 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
626 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
631 ControlsWidget::~ControlsWidget()
634 void ControlsWidget::stop()
639 void ControlsWidget::play()
641 if( THEPL->current.i_size == 0 )
643 /* The playlist is empty, open a file requester */
644 THEDP->openFileDialog();
648 THEMIM->togglePlayPause();
651 void ControlsWidget::prev()
656 void ControlsWidget::next()
661 void ControlsWidget::setNavigation( int navigation )
663 #define HELP_MENU N_( "Menu" )
664 #define HELP_PCH N_( "Previous chapter" )
665 #define HELP_NCH N_( "Next chapter" )
666 #define HELP_PTR N_( "Previous track" )
667 #define HELP_NTR N_( "Next track" )
669 // 1 = chapter, 2 = title, 0 = no
670 if( navigation == 0 )
673 } else if( navigation == 1 ) {
674 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
675 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
679 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
680 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
686 static bool b_my_volume;
687 void ControlsWidget::updateVolume( int i_sliderVolume )
691 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
692 aout_VolumeSet( p_intf, i_res );
694 if( i_sliderVolume == 0 )
695 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
696 else if( i_sliderVolume < VOLUME_MAX / 3 )
697 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
698 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
699 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
700 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
703 void ControlsWidget::updateVolume()
706 audio_volume_t i_volume;
707 aout_VolumeGet( p_intf, &i_volume );
708 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
709 int i_gauge = volumeSlider->value();
711 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
714 volumeSlider->setValue( i_volume );
719 void ControlsWidget::updateInput()
721 /* Activate the interface buttons according to the presence of the input */
722 enableInput( THEMIM->getIM()->hasInput() );
723 enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
726 void ControlsWidget::setStatus( int status )
728 if( status == PLAYING_S ) /* Playing */
730 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
731 playButton->setToolTip( qtr( "Pause" ) );
735 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
736 playButton->setToolTip( qtr( "Play" ) );
742 * This functions toggle the fullscreen mode
743 * If there is no video, it should first activate Visualisations...
744 * This has also to be fixed in enableVideo()
746 void ControlsWidget::fullscreen()
748 vout_thread_t *p_vout =
749 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
752 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
753 vlc_object_release( p_vout );
757 void ControlsWidget::extSettings()
759 THEDP->extendedDialog();
762 void ControlsWidget::slower()
764 THEMIM->getIM()->slower();
767 void ControlsWidget::faster()
769 THEMIM->getIM()->faster();
772 void ControlsWidget::enableInput( bool enable )
774 slowerButton->setEnabled( enable );
775 slider->setEnabled( enable );
776 fasterButton->setEnabled( enable );
778 /* Advanced Buttons too */
779 advControls->enableInput( enable );
782 void ControlsWidget::enableVideo( bool enable )
784 // TODO Later make the fullscreenButton toggle Visualisation and so on.
785 fullscreenButton->setEnabled( enable );
787 /* Advanced Buttons too */
788 advControls->enableVideo( enable );
791 void ControlsWidget::toggleAdvanced()
793 if( !VISIBLE( advControls ) )
796 b_advancedVisible = true;
801 b_advancedVisible = false;
803 emit advancedControlsToggled( b_advancedVisible );
807 /**********************************************************************
808 * Fullscrenn control widget
809 **********************************************************************/
810 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
811 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
812 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
813 i_lastPosX( -1 ), i_lastPosY( -1 ), i_hideTimeout( 1 ),
814 b_mouseIsOver( false )
816 setWindowFlags( Qt::ToolTip );
818 setFrameShape( QFrame::StyledPanel );
819 setFrameStyle( QFrame::Sunken );
820 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
822 QGridLayout *fsLayout = new QGridLayout( this );
823 controlLayout->setSpacing( 0 );
824 controlLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
826 fsLayout->addWidget( slowerButton, 0, 0 );
827 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
828 fsLayout->addWidget( slider, 0, 1, 1, 6 );
829 fsLayout->addWidget( fasterButton, 0, 7 );
831 fsLayout->addWidget( volMuteLabel, 1, 0);
832 fsLayout->addWidget( volumeSlider, 1, 1 );
834 fsLayout->addLayout( controlButLayout, 1, 2 );
836 fsLayout->addWidget( playButton, 1, 3 );
838 fsLayout->addWidget( discFrame, 1, 4 );
840 fsLayout->addWidget( telexFrame, 1, 5 );
842 fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
844 fsLayout->addWidget( fullscreenButton, 1, 7 );
847 p_hideTimer = new QTimer( this );
848 CONNECT( p_hideTimer, timeout(), this, hideFSControllerWidget() );
849 p_hideTimer->setSingleShot( true );
851 /* slow hiding timer */
852 #if HAVE_TRANSPARENCY
853 p_slowHideTimer = new QTimer( this );
854 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
857 adjustSize (); /* need to get real width and height for moving */
860 QDesktopWidget * p_desktop = QApplication::desktop();
862 move( p_desktop->width() / 2 - width() / 2,
863 p_desktop->height() - height() );
866 setWindowOpacity( 0.0 );
872 FullscreenControllerWidget::~FullscreenControllerWidget()
877 * Hide fullscreen controller
878 * FIXME: under windows it have to be done by moving out of screen
879 * because hide() doesnt work
881 void FullscreenControllerWidget::hideFSControllerWidget()
885 setWindowOpacity( 0.0 ); // simulate hidding
892 * Hidding fullscreen controller slowly
893 * Linux: need composite manager
894 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
896 void FullscreenControllerWidget::slowHideFSC()
898 #if HAVE_TRANSPARENCY
899 static bool first_call = true;
905 p_slowHideTimer->stop();
906 /* the last part of time divided to 100 pieces */
907 p_slowHideTimer->start(
908 (int) ( i_hideTimeout / 2 / ( windowOpacity() * 100 ) ) );
912 if ( windowOpacity() > 0.0 )
914 /* we should use 0.01 because of 100 pieces ^^^
915 but than it cannt be done in time */
916 setWindowOpacity( windowOpacity() - 0.02 );
919 if ( windowOpacity() == 0.0 )
922 p_slowHideTimer->stop();
929 * Get state of visibility of FS controller on screen
930 * On windows control if it is on hidden position
932 bool FullscreenControllerWidget::isFSCHidden()
943 * events: show, hide, start timer for hidding
945 void FullscreenControllerWidget::customEvent( QEvent *event )
947 int type = event->type();
949 if ( type == FullscreenControlShow_Type )
952 // after quiting and going to fs, we need to call show()
959 setWindowOpacity( 1.0 );
965 #if HAVE_TRANSPARENCY
966 setWindowOpacity( DEFAULT_OPACITY );
969 else if ( type == FullscreenControlHide_Type )
971 hideFSControllerWidget();
973 else if ( type == FullscreenControlPlanHide_Type && !b_mouseIsOver )
975 p_hideTimer->start( i_hideTimeout );
976 #if HAVE_TRANSPARENCY
977 p_slowHideTimer->start( i_hideTimeout / 2 );
986 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
988 if ( event->buttons() == Qt::LeftButton )
990 int i_moveX = event->globalX() - i_lastPosX;
991 int i_moveY = event->globalY() - i_lastPosY;
993 move( x() + i_moveX, y() + i_moveY );
995 i_lastPosX = event->globalX();
996 i_lastPosY = event->globalY();
1002 * store position of cursor
1004 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1006 i_lastPosX = event->globalX();
1007 i_lastPosY = event->globalY();
1011 * On mouse go above FSC
1013 void FullscreenControllerWidget::enterEvent( QEvent *event )
1015 p_hideTimer->stop();
1016 #if HAVE_TRANSPARENCY
1017 p_slowHideTimer->stop();
1019 b_mouseIsOver = true;
1023 * On mouse go out from FSC
1025 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1027 p_hideTimer->start( i_hideTimeout );
1028 #if HAVE_TRANSPARENCY
1029 p_slowHideTimer->start( i_hideTimeout / 2 );
1031 b_mouseIsOver = false;
1035 * When you get pressed key, send it to video output
1036 * FIXME: clearing focus by clearFocus() to not getting
1037 * key press events didnt work
1039 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1041 int i_vlck = qtEventToVLCKey( event );
1044 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1052 * It is called when video start
1054 void FullscreenControllerWidget::regFullscreenCallback( vout_thread_t *p_vout )
1058 var_AddCallback( p_vout, "fullscreen", regMouseMoveCallback, this );
1063 * It is called after turn off video, because p_vout is NULL now
1064 * we cannt delete callback, just hide if FScontroller is visible
1066 void FullscreenControllerWidget::unregFullscreenCallback()
1073 * Register and unregister callback for mouse moving
1075 static int regMouseMoveCallback( vlc_object_t *vlc_object, const char *variable,
1076 vlc_value_t old_val, vlc_value_t new_val,
1079 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1081 static bool b_registered = false;
1082 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1084 if ( var_GetBool( p_vout, "fullscreen" ) && !b_registered )
1086 p_fs->SetHideTimeout( var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1087 var_AddCallback( p_vout, "mouse-moved",
1088 showFullscreenControllCallback, (void *) p_fs );
1089 b_registered = true;
1092 if ( !var_GetBool( p_vout, "fullscreen" ) && b_registered )
1094 var_DelCallback( p_vout, "mouse-moved",
1095 showFullscreenControllCallback, (void *) p_fs );
1096 b_registered = false;
1104 * Show fullscreen controller after mouse move
1105 * after show immediately plan hide event
1107 static int showFullscreenControllCallback( vlc_object_t *vlc_object, const char *variable,
1108 vlc_value_t old_val, vlc_value_t new_val,
1111 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1113 if ( p_fs->isFSCHidden() || p_fs->windowOpacity() < DEFAULT_OPACITY )
1115 IMEvent *event = new IMEvent( FullscreenControlShow_Type, 0 );
1116 QApplication::postEvent( p_fs, static_cast<QEvent *>(event) );
1119 IMEvent *e = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1120 QApplication::postEvent( p_fs, static_cast<QEvent *>(e) );
1125 /**********************************************************************
1126 * Speed control widget
1127 **********************************************************************/
1128 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1129 QFrame( NULL ), p_intf( _p_i )
1131 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1132 sizePolicy.setHorizontalStretch( 0 );
1133 sizePolicy.setVerticalStretch( 0 );
1135 speedSlider = new QSlider;
1136 speedSlider->setSizePolicy( sizePolicy );
1137 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1138 speedSlider->setOrientation( Qt::Vertical );
1139 speedSlider->setTickPosition( QSlider::TicksRight );
1141 speedSlider->setRange( -100, 100 );
1142 speedSlider->setSingleStep( 10 );
1143 speedSlider->setPageStep( 20 );
1144 speedSlider->setTickInterval( 20 );
1146 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1148 QToolButton *normalSpeedButton = new QToolButton( this );
1149 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1150 normalSpeedButton->setAutoRaise( true );
1151 normalSpeedButton->setText( "N" );
1152 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1154 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1156 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1157 speedControlLayout->addWidget( speedSlider );
1158 speedControlLayout->addWidget( normalSpeedButton );
1159 setLayout( speedControlLayout );
1162 SpeedControlWidget::~SpeedControlWidget()
1165 void SpeedControlWidget::setEnable( bool b_enable )
1167 speedSlider->setEnabled( b_enable );
1170 #define RATE_SLIDER_MAXIMUM 3.0
1171 #define RATE_SLIDER_MINIMUM 0.3
1172 #define RATE_SLIDER_LENGTH 100.0
1174 void SpeedControlWidget::updateControls( int rate )
1176 if( speedSlider->isSliderDown() )
1178 //We don't want to change anything if the user is using the slider
1183 double speed = INPUT_RATE_DEFAULT / (double)rate;
1185 if( rate >= INPUT_RATE_DEFAULT )
1187 if( speed < RATE_SLIDER_MINIMUM )
1189 sliderValue = speedSlider->minimum();
1193 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
1194 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
1199 if( speed > RATE_SLIDER_MAXIMUM )
1201 sliderValue = speedSlider->maximum();
1205 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
1206 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
1210 //Block signals to avoid feedback loop
1211 speedSlider->blockSignals( true );
1212 speedSlider->setValue( sliderValue );
1213 speedSlider->blockSignals( false );
1216 void SpeedControlWidget::updateRate( int sliderValue )
1220 if( sliderValue < 0.0 )
1222 rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
1223 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ));
1227 rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
1228 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH ));
1231 THEMIM->getIM()->setRate(rate);
1234 void SpeedControlWidget::resetRate()
1236 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);