1 /*****************************************************************************
2 * Controller.cpp : Controller for the main interface
3 ****************************************************************************
4 * Copyright (C) 2006-2008 the VideoLAN team
7 * Authors: Jean-Baptiste Kempf <jb@videolan.org>
8 * Ilkka Ollakka <ileoo@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * ( at your option ) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
32 #include "components/controller.hpp"
33 #include "components/controller_widget.hpp"
34 #include "components/interface_widgets.hpp"
36 #include "dialogs_provider.hpp" /* Opening Dialogs */
37 #include "input_manager.hpp"
38 #include "actions_manager.hpp"
40 #include "util/input_slider.hpp" /* InputSlider */
41 #include "util/customwidgets.hpp" /* qEventToKey */
43 #include <QSpacerItem>
44 #include <QToolButton>
45 #include <QHBoxLayout>
46 #include <QSignalMapper>
49 /**********************************************************************
51 **********************************************************************/
54 * This is an abstract Toolbar/Controller
55 * This has helper to create any toolbar, any buttons and to manage the actions
58 AbstractController::AbstractController( intf_thread_t * _p_i, QWidget *_parent )
64 /* Main action provider */
65 toolbarActionsMapper = new QSignalMapper( this );
66 CONNECT( toolbarActionsMapper, mapped( int ),
67 ActionsManager::getInstance( p_intf ), doAction( int ) );
68 CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
71 /* Reemit some signals on status Change to activate some buttons */
72 void AbstractController::setStatus( int status )
74 bool b_hasInput = THEMIM->getIM()->hasInput();
75 /* Activate the interface buttons according to the presence of the input */
76 emit inputExists( b_hasInput );
78 emit inputPlaying( status == PLAYING_S );
80 emit inputIsRecordable( b_hasInput &&
81 var_GetBool( THEMIM->getInput(), "can-record" ) );
84 /* Generic button setup */
85 void AbstractController::setupButton( QAbstractButton *aButton )
87 static QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
88 sizePolicy.setHorizontalStretch( 0 );
89 sizePolicy.setVerticalStretch( 0 );
91 aButton->setSizePolicy( sizePolicy );
92 aButton->setFixedSize( QSize( 26, 26 ) );
93 aButton->setIconSize( QSize( 20, 20 ) );
94 aButton->setFocusPolicy( Qt::NoFocus );
97 /* Open the generic config line for the toolbar, parse it
98 * and create the widgets accordingly */
99 void AbstractController::parseAndCreate( QString config,
100 QBoxLayout *controlLayout )
102 QStringList list = config.split( ";", QString::SkipEmptyParts ) ;
103 for( int i = 0; i < list.size(); i++ )
105 QStringList list2 = list.at( i ).split( "-" );
106 if( list2.size() < 1 )
108 msg_Warn( p_intf, "Parsing error. Report this" );
113 int i_option = WIDGET_NORMAL;
114 buttonType_e i_type = (buttonType_e)list2.at( 0 ).toInt( &ok );
117 msg_Warn( p_intf, "Parsing error 0. Please report this" );
121 if( list2.size() > 1 )
123 i_option = list2.at( 1 ).toInt( &ok );
126 msg_Warn( p_intf, "Parsing error 1. Please report this" );
131 createAndAddWidget( controlLayout, -1, i_type, i_option );
135 void AbstractController::createAndAddWidget( QBoxLayout *controlLayout,
140 /* Special case for SPACERS, who aren't QWidgets */
141 if( i_type == WIDGET_SPACER )
143 controlLayout->insertSpacing( i_index, 16 );
147 if( i_type == WIDGET_SPACER_EXTEND )
149 controlLayout->insertStretch( i_index, 16 );
153 QWidget *widg = createWidget( i_type, i_option );
156 controlLayout->insertWidget( i_index, widg );
160 #define CONNECT_MAP( a ) CONNECT( a, clicked(), toolbarActionsMapper, map() )
161 #define SET_MAPPING( a, b ) toolbarActionsMapper->setMapping( a , b )
162 #define CONNECT_MAP_SET( a, b ) \
165 #define BUTTON_SET_BAR( a_button ) \
166 a_button->setToolTip( tooltipL[button] ); \
167 a_button->setIcon( QIcon( iconL[button] ) );
168 #define BUTTON_SET_BAR2( button, image, tooltip ) \
169 button->setToolTip( tooltip ); \
170 button->setIcon( QIcon( ":/"#image ) );
173 #define ENABLE_ON_VIDEO( a ) \
174 CONNECT( THEMIM->getIM(), voutChanged( bool ), a, setEnabled( bool ) ); \
175 a->setEnabled( THEMIM->getIM()->hasVideo() ); /* TODO: is this necessary? when input is started before the interface? */
177 #define ENABLE_ON_INPUT( a ) \
178 CONNECT( this, inputExists( bool ), a, setEnabled( bool ) ); \
179 a->setEnabled( THEMIM->getIM()->hasInput() ); /* TODO: is this necessary? when input is started before the interface? */
181 QWidget *AbstractController::createWidget( buttonType_e button, int options )
184 bool b_flat = options & WIDGET_FLAT;
185 bool b_big = options & WIDGET_BIG;
186 bool b_shiny = options & WIDGET_SHINY;
188 QWidget *widget = NULL;
192 PlayButton *playButton = new PlayButton;
193 setupButton( playButton );
194 BUTTON_SET_BAR( playButton );
195 CONNECT_MAP_SET( playButton, PLAY_ACTION );
196 CONNECT( this, inputPlaying( bool ),
197 playButton, updateButton( bool ));
202 QToolButton *stopButton = new QToolButton;
203 setupButton( stopButton );
204 CONNECT_MAP_SET( stopButton, STOP_ACTION );
205 BUTTON_SET_BAR( stopButton );
210 QToolButton *openButton = new QToolButton;
211 setupButton( openButton );
212 CONNECT_MAP_SET( openButton, OPEN_ACTION );
213 BUTTON_SET_BAR( openButton );
217 case PREVIOUS_BUTTON:{
218 QToolButton *prevButton = new QToolButton;
219 setupButton( prevButton );
220 CONNECT_MAP_SET( prevButton, PREVIOUS_ACTION );
221 BUTTON_SET_BAR( prevButton );
227 QToolButton *nextButton = new QToolButton;
228 setupButton( nextButton );
229 CONNECT_MAP_SET( nextButton, NEXT_ACTION );
230 BUTTON_SET_BAR( nextButton );
235 QToolButton *slowerButton = new QToolButton;
236 setupButton( slowerButton );
237 CONNECT_MAP_SET( slowerButton, SLOWER_ACTION );
238 BUTTON_SET_BAR( slowerButton );
239 ENABLE_ON_INPUT( slowerButton );
240 widget = slowerButton;
244 QToolButton *fasterButton = new QToolButton;
245 setupButton( fasterButton );
246 CONNECT_MAP_SET( fasterButton, FASTER_ACTION );
247 BUTTON_SET_BAR( fasterButton );
248 ENABLE_ON_INPUT( fasterButton );
249 widget = fasterButton;
253 QToolButton *frameButton = new QToolButton;
254 setupButton( frameButton );
255 CONNECT_MAP_SET( frameButton, FRAME_ACTION );
256 BUTTON_SET_BAR( frameButton );
257 ENABLE_ON_VIDEO( frameButton );
258 widget = frameButton;
261 case FULLSCREEN_BUTTON:{
262 QToolButton *fullscreenButton = new QToolButton;
263 setupButton( fullscreenButton );
264 CONNECT_MAP_SET( fullscreenButton, FULLSCREEN_ACTION );
265 BUTTON_SET_BAR( fullscreenButton );
266 ENABLE_ON_VIDEO( fullscreenButton );
267 widget = fullscreenButton;
270 case DEFULLSCREEN_BUTTON:{
271 QToolButton *fullscreenButton = new QToolButton;
272 setupButton( fullscreenButton );
273 CONNECT_MAP_SET( fullscreenButton, FULLSCREEN_ACTION );
274 BUTTON_SET_BAR( fullscreenButton )
275 ENABLE_ON_VIDEO( fullscreenButton );
276 widget = fullscreenButton;
279 case EXTENDED_BUTTON:{
280 QToolButton *extSettingsButton = new QToolButton;
281 setupButton( extSettingsButton );
282 CONNECT_MAP_SET( extSettingsButton, EXTENDED_ACTION );
283 BUTTON_SET_BAR( extSettingsButton )
284 widget = extSettingsButton;
287 case PLAYLIST_BUTTON:{
288 QToolButton *playlistButton = new QToolButton;
289 setupButton( playlistButton );
290 CONNECT_MAP_SET( playlistButton, PLAYLIST_ACTION );
291 BUTTON_SET_BAR( playlistButton );
292 widget = playlistButton;
295 case SNAPSHOT_BUTTON:{
296 QToolButton *snapshotButton = new QToolButton;
297 setupButton( snapshotButton );
298 CONNECT_MAP_SET( snapshotButton, SNAPSHOT_ACTION );
299 BUTTON_SET_BAR( snapshotButton );
300 ENABLE_ON_VIDEO( snapshotButton );
301 widget = snapshotButton;
305 QToolButton *recordButton = new QToolButton;
306 setupButton( recordButton );
307 CONNECT_MAP_SET( recordButton, RECORD_ACTION );
308 BUTTON_SET_BAR( recordButton );
309 ENABLE_ON_INPUT( recordButton );
310 recordButton->setCheckable( true );
311 CONNECT( THEMIM->getIM(), recordingStateChanged( bool ),
312 recordButton, setChecked( bool ) );
313 widget = recordButton;
317 AtoB_Button *ABButton = new AtoB_Button;
318 setupButton( ABButton );
319 BUTTON_SET_BAR( ABButton );
320 ENABLE_ON_INPUT( ABButton );
321 CONNECT_MAP_SET( ABButton, ATOB_ACTION );
322 CONNECT( THEMIM->getIM(), AtoBchanged( bool, bool),
323 ABButton, setIcons( bool, bool ) );
328 InputSlider *slider = new InputSlider( Qt::Horizontal, NULL );
330 /* Update the position when the IM has changed */
331 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
332 slider, setPosition( float, int, int ) );
333 /* And update the IM, when the position has changed */
334 CONNECT( slider, sliderDragged( float ),
335 THEMIM->getIM(), sliderUpdate( float ) );
340 widget = discFrame();
343 case TELETEXT_BUTTONS:
344 widget = telexFrame();
349 SoundWidget *snd = new SoundWidget( this, p_intf, b_shiny );
355 TimeLabel *timeLabel = new TimeLabel( p_intf );
361 QFrame *line = new QFrame;
362 line->setFrameShape( QFrame::VLine );
363 line->setFrameShadow( QFrame::Raised );
364 line->setLineWidth( 0 );
365 line->setMidLineWidth( 1 );
369 case ADVANCED_CONTROLLER:
371 advControls = new AdvControlsWidget( p_intf, this );
372 widget = advControls;
375 case REVERSE_BUTTON:{
376 QToolButton *reverseButton = new QToolButton;
377 setupButton( reverseButton );
378 CONNECT_MAP_SET( reverseButton, REVERSE_ACTION );
379 BUTTON_SET_BAR( reverseButton );
380 ENABLE_ON_INPUT( reverseButton );
381 widget = reverseButton;
384 case SKIP_BACK_BUTTON: {
385 QToolButton *skipBakButton = new QToolButton;
386 setupButton( skipBakButton );
387 CONNECT_MAP_SET( skipBakButton, SKIP_BACK_ACTION );
388 BUTTON_SET_BAR( skipBakButton );
389 ENABLE_ON_INPUT( skipBakButton );
390 widget = skipBakButton;
393 case SKIP_FW_BUTTON: {
394 QToolButton *skipFwButton = new QToolButton;
395 setupButton( skipFwButton );
396 CONNECT_MAP_SET( skipFwButton, SKIP_FW_ACTION );
397 BUTTON_SET_BAR( skipFwButton );
398 ENABLE_ON_INPUT( skipFwButton );
399 widget = skipFwButton;
403 QToolButton *quitButton = new QToolButton;
404 setupButton( quitButton );
405 CONNECT_MAP_SET( quitButton, QUIT_ACTION );
406 BUTTON_SET_BAR( quitButton );
411 msg_Warn( p_intf, "This should not happen %i", button );
415 /* Customize Buttons */
416 if( b_flat || b_big )
418 QToolButton *tmpButton = qobject_cast<QToolButton *>(widget);
422 tmpButton->setAutoRaise( b_flat );
425 tmpButton->setFixedSize( QSize( 32, 32 ) );
426 tmpButton->setIconSize( QSize( 26, 26 ) );
433 QFrame *AbstractController::discFrame()
435 /** Disc and Menus handling */
436 QFrame *discFrame = new QFrame( this );
438 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
439 discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );
441 QToolButton *prevSectionButton = new QToolButton( discFrame );
442 setupButton( prevSectionButton );
443 BUTTON_SET_BAR2( prevSectionButton, dvd_prev,
444 qtr("Previous Chapter/Title" ) );
445 discLayout->addWidget( prevSectionButton );
447 QToolButton *menuButton = new QToolButton( discFrame );
448 setupButton( menuButton );
449 discLayout->addWidget( menuButton );
450 BUTTON_SET_BAR2( menuButton, dvd_menu, qtr( "Menu" ) );
452 QToolButton *nextSectionButton = new QToolButton( discFrame );
453 setupButton( nextSectionButton );
454 discLayout->addWidget( nextSectionButton );
455 BUTTON_SET_BAR2( nextSectionButton, dvd_next,
456 qtr("Next Chapter/Title" ) );
458 /* Change the navigation button display when the IM
459 navigation changes */
460 CONNECT( THEMIM->getIM(), titleChanged( bool ),
461 discFrame, setVisible( bool ) );
462 CONNECT( THEMIM->getIM(), chapterChanged( bool ),
463 menuButton, setVisible( bool ) );
464 /* Changes the IM navigation when triggered on the nav buttons */
465 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
467 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
469 CONNECT( menuButton, clicked(), THEMIM->getIM(),
475 QFrame *AbstractController::telexFrame()
480 TeletextController *telexFrame = new TeletextController;
481 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
482 telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );
483 CONNECT( THEMIM->getIM(), teletextPossible( bool ),
484 telexFrame, setVisible( bool ) );
487 QToolButton *telexOn = new QToolButton;
488 telexFrame->telexOn = telexOn;
489 setupButton( telexOn );
490 BUTTON_SET_BAR2( telexOn, tv, qtr( "Teletext Activation" ) );
491 telexLayout->addWidget( telexOn );
493 /* Teletext Activation and set */
494 CONNECT( telexOn, clicked( bool ),
495 THEMIM->getIM(), activateTeletext( bool ) );
496 CONNECT( THEMIM->getIM(), teletextActivated( bool ),
497 telexFrame, enableTeletextButtons( bool ) );
500 /* Transparency button */
501 QToolButton *telexTransparent = new QToolButton;
502 telexFrame->telexTransparent = telexTransparent;
503 setupButton( telexTransparent );
504 BUTTON_SET_BAR2( telexTransparent, tvtelx,
505 qtr( "Toggle Transparency " ) );
506 telexTransparent->setEnabled( false );
507 telexTransparent->setCheckable( true );
508 telexLayout->addWidget( telexTransparent );
510 /* Transparency change and set */
511 CONNECT( telexTransparent, clicked( bool ),
512 THEMIM->getIM(), telexSetTransparency( bool ) );
513 CONNECT( THEMIM->getIM(), teletextTransparencyActivated( bool ),
514 telexTransparent, setChecked( bool ) );
518 QSpinBox *telexPage = new QSpinBox;
519 telexFrame->telexPage = telexPage;
520 telexPage->setRange( 0, 999 );
521 telexPage->setValue( 100 );
522 telexPage->setAccelerated( true );
523 telexPage->setWrapping( true );
524 telexPage->setAlignment( Qt::AlignRight );
525 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
526 telexPage->setEnabled( false );
527 telexLayout->addWidget( telexPage );
529 /* Page change and set */
530 CONNECT( telexPage, valueChanged( int ),
531 THEMIM->getIM(), telexSetPage( int ) );
532 CONNECT( THEMIM->getIM(), newTelexPageSet( int ),
533 telexPage, setValue( int ) );
539 #undef CONNECT_MAP_SET
540 #undef BUTTON_SET_BAR
541 #undef ENABLE_ON_VIDEO
542 #undef ENABLE_ON_INPUT
544 #include <QHBoxLayout>
545 /*****************************
546 * DA Control Widget !
547 *****************************/
548 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
551 AbstractController( _p_i, _parent )
553 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
555 /* advanced Controls handling */
556 b_advancedVisible = b_advControls;
558 QVBoxLayout *controlLayout = new QVBoxLayout( this );
559 controlLayout->setLayoutMargins( 6, 4, 6, 2, 5 );
560 controlLayout->setSpacing( 0 );
561 QHBoxLayout *controlLayout1 = new QHBoxLayout;
562 controlLayout1->setSpacing( 0 );
564 QString line1 = getSettings()->value( "MainToolbar1", MAIN_TB1_DEFAULT )
566 parseAndCreate( line1, controlLayout1 );
568 QHBoxLayout *controlLayout2 = new QHBoxLayout;
569 controlLayout2->setSpacing( 0 );
570 QString line2 = getSettings()->value( "MainToolbar2", MAIN_TB2_DEFAULT )
572 parseAndCreate( line2, controlLayout2 );
574 if( !b_advancedVisible && advControls ) advControls->hide();
576 controlLayout->addLayout( controlLayout1 );
577 controlLayout->addLayout( controlLayout2 );
580 ControlsWidget::~ControlsWidget()
583 void ControlsWidget::toggleAdvanced()
585 if( !advControls ) return;
587 if( !b_advancedVisible )
590 b_advancedVisible = true;
595 b_advancedVisible = false;
597 emit advancedControlsToggled( b_advancedVisible );
600 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
601 AbstractController( _p_i, _parent )
603 controlLayout = new QHBoxLayout( this );
604 controlLayout->setMargin( 0 );
605 controlLayout->setSpacing( 0 );
607 QString line = getSettings()->value( "AdvToolbar", ADV_TB_DEFAULT )
609 parseAndCreate( line, controlLayout );
612 InputControlsWidget::InputControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
613 AbstractController( _p_i, _parent )
615 controlLayout = new QHBoxLayout( this );
616 controlLayout->setMargin( 0 );
617 controlLayout->setSpacing( 0 );
619 QString line = getSettings()->value( "InputToolbar", INPT_TB_DEFAULT ).toString();
620 parseAndCreate( line, controlLayout );
622 /**********************************************************************
623 * Fullscrenn control widget
624 **********************************************************************/
625 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i )
626 : AbstractController( _p_i )
630 b_mouse_over = false;
631 i_mouse_last_move_x = -1;
632 i_mouse_last_move_y = -1;
633 #if HAVE_TRANSPARENCY
634 b_slow_hide_begin = false;
635 i_slow_hide_timeout = 1;
637 b_fullscreen = false;
643 setWindowFlags( Qt::ToolTip );
644 setMinimumWidth( 600 );
646 setFrameShape( QFrame::StyledPanel );
647 setFrameStyle( QFrame::Sunken );
648 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
650 QVBoxLayout *controlLayout2 = new QVBoxLayout( this );
651 controlLayout2->setLayoutMargins( 5, 2, 5, 2, 5 );
654 InputControlsWidget *inputC = new InputControlsWidget( p_intf, this );
655 controlLayout2->addWidget( inputC );
657 controlLayout = new QHBoxLayout;
658 QString line = getSettings()->value( "MainWindow/FSCtoolbar", FSC_TB_DEFAULT ).toString();
659 parseAndCreate( line, controlLayout );
660 controlLayout2->addLayout( controlLayout );
663 p_hideTimer = new QTimer( this );
664 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
665 p_hideTimer->setSingleShot( true );
667 /* slow hiding timer */
668 #if HAVE_TRANSPARENCY
669 p_slowHideTimer = new QTimer( this );
670 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
673 adjustSize (); /* need to get real width and height for moving */
676 setWindowOpacity( 0.0 );
682 vlc_mutex_init_recursive( &lock );
684 CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ), this, setVoutList( vout_thread_t **, int ) );
687 FullscreenControllerWidget::~FullscreenControllerWidget()
689 getSettings()->setValue( "FullScreen/pos", pos() );
690 setVoutList( NULL, 0 );
691 vlc_mutex_destroy( &lock );
695 * Show fullscreen controller
697 void FullscreenControllerWidget::showFSC()
701 int number = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
702 if( number != i_screennumber ||
703 screenRes != QApplication::desktop()->screenGeometry(number) )
705 screenRes = QApplication::desktop()->screenGeometry(number);
706 msg_Dbg( p_intf, "Calculation fullscreen controllers center");
707 /* screen has changed, calculate new position */
708 QPoint pos = QPoint( screenRes.x() + (screenRes.width() / 2) - (width() / 2),
709 screenRes.y() + screenRes.height() - height());
711 i_screennumber = number;
714 // after quiting and going to fs, we need to call show()
720 setWindowOpacity( 1.0 );
726 #if HAVE_TRANSPARENCY
727 setWindowOpacity( DEFAULT_OPACITY );
732 * Hide fullscreen controller
733 * FIXME: under windows it have to be done by moving out of screen
734 * because hide() doesnt work
736 void FullscreenControllerWidget::hideFSC()
740 setWindowOpacity( 0.0 ); // simulate hidding
747 * Plane to hide fullscreen controller
749 void FullscreenControllerWidget::planHideFSC()
751 vlc_mutex_lock( &lock );
752 int i_timeout = i_hide_timeout;
753 vlc_mutex_unlock( &lock );
755 p_hideTimer->start( i_timeout );
757 #if HAVE_TRANSPARENCY
758 b_slow_hide_begin = true;
759 i_slow_hide_timeout = i_timeout;
760 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
765 * Hidding fullscreen controller slowly
766 * Linux: need composite manager
767 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
769 void FullscreenControllerWidget::slowHideFSC()
771 #if HAVE_TRANSPARENCY
772 if( b_slow_hide_begin )
774 b_slow_hide_begin = false;
776 p_slowHideTimer->stop();
777 /* the last part of time divided to 100 pieces */
778 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
784 if ( windowOpacity() > 0.0 && !b_fscHidden )
786 if ( windowOpacity() > 0.0 )
789 /* we should use 0.01 because of 100 pieces ^^^
790 but than it cannt be done in time */
791 setWindowOpacity( windowOpacity() - 0.02 );
794 if ( windowOpacity() <= 0.0 )
795 p_slowHideTimer->stop();
802 * events: show, hide, start timer for hidding
804 void FullscreenControllerWidget::customEvent( QEvent *event )
808 switch( event->type() )
810 case FullscreenControlToggle_Type:
811 vlc_mutex_lock( &lock );
813 vlc_mutex_unlock( &lock );
829 case FullscreenControlShow_Type:
830 vlc_mutex_lock( &lock );
832 vlc_mutex_unlock( &lock );
835 if( b_fs && b_fscHidden )
837 if( b_fs && !isVisible() )
841 case FullscreenControlHide_Type:
844 case FullscreenControlPlanHide_Type:
845 if( !b_mouse_over ) // Only if the mouse is not over FSC
857 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
859 if ( event->buttons() == Qt::LeftButton )
861 int i_moveX = event->globalX() - i_mouse_last_x;
862 int i_moveY = event->globalY() - i_mouse_last_y;
864 move( x() + i_moveX, y() + i_moveY );
866 i_mouse_last_x = event->globalX();
867 i_mouse_last_y = event->globalY();
873 * store position of cursor
875 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
877 i_mouse_last_x = event->globalX();
878 i_mouse_last_y = event->globalY();
882 * On mouse go above FSC
884 void FullscreenControllerWidget::enterEvent( QEvent *event )
889 #if HAVE_TRANSPARENCY
890 p_slowHideTimer->stop();
896 * On mouse go out from FSC
898 void FullscreenControllerWidget::leaveEvent( QEvent *event )
902 b_mouse_over = false;
907 * When you get pressed key, send it to video output
908 * FIXME: clearing focus by clearFocus() to not getting
909 * key press events didnt work
911 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
913 int i_vlck = qtEventToVLCKey( event );
916 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
924 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object,
925 const char *variable, vlc_value_t old_val,
926 vlc_value_t new_val, void *data )
928 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
930 msg_Dbg( p_vout, "Qt4: Fullscreen state changed" );
931 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
933 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
938 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
939 vlc_value_t old_val, vlc_value_t new_val,
942 vout_thread_t *p_vout = (vout_thread_t *)vlc_object;
943 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
945 /* Get the value from the Vout - Trust the vout more than Qt */
946 const int i_mousex = var_GetInteger( p_vout, "mouse-x" );
947 const int i_mousey = var_GetInteger( p_vout, "mouse-y" );
949 p_fs->mouseChanged( p_vout, i_mousex, i_mousey );
955 * It is call to update the list of vout handled by the fullscreen controller
957 void FullscreenControllerWidget::setVoutList( vout_thread_t **pp_vout, int i_vout )
959 QList<vout_thread_t*> del;
960 QList<vout_thread_t*> add;
962 QList<vout_thread_t*> set;
965 for( int i = 0; i < i_vout; i++ )
969 vlc_mutex_lock( &lock );
970 foreach( vout_thread_t *p_vout, vout )
972 if( !set.contains( p_vout ) )
975 vlc_mutex_unlock( &lock );
977 foreach( vout_thread_t *p_vout, del )
979 var_DelCallback( p_vout, "fullscreen",
980 FullscreenControllerWidgetFullscreenChanged, this );
981 vlc_mutex_lock( &lock );
982 fullscreenChanged( p_vout, false, 0 );
983 vout.removeAll( p_vout );
984 vlc_mutex_unlock( &lock );
988 vlc_mutex_lock( &lock );
989 foreach( vout_thread_t *p_vout, set )
991 if( !vout.contains( p_vout ) )
994 vlc_mutex_unlock( &lock );
996 foreach( vout_thread_t *p_vout, add )
998 vlc_object_hold( (vlc_object_t*)p_vout );
1000 vlc_mutex_lock( &lock );
1001 vout.append( p_vout );
1002 var_AddCallback( p_vout, "fullscreen",
1003 FullscreenControllerWidgetFullscreenChanged, this );
1004 /* I miss a add and fire */
1005 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ),
1006 var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1007 vlc_mutex_unlock( &lock );
1011 * Register and unregister callback for mouse moving
1013 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout,
1014 bool b_fs, int i_timeout )
1016 /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
1017 msg_Dbg( p_vout, "Qt: Entering Fullscreen" );
1019 vlc_mutex_lock( &lock );
1020 /* Entering fullscreen, register callback */
1021 if( b_fs && !b_fullscreen )
1023 b_fullscreen = true;
1024 i_hide_timeout = i_timeout;
1025 var_AddCallback( p_vout, "mouse-moved",
1026 FullscreenControllerWidgetMouseMoved, this );
1028 /* Quitting fullscreen, unregistering callback */
1029 else if( !b_fs && b_fullscreen )
1031 b_fullscreen = false;
1032 i_hide_timeout = i_timeout;
1033 var_DelCallback( p_vout, "mouse-moved",
1034 FullscreenControllerWidgetMouseMoved, this );
1036 /* Force fs hidding */
1037 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1038 QApplication::postEvent( this, eHide );
1040 vlc_mutex_unlock( &lock );
1043 * Mouse change callback (show/hide the controller on mouse movement)
1045 void FullscreenControllerWidget::mouseChanged( vout_thread_t *p_vout, int i_mousex, int i_mousey )
1049 /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
1052 if( ( i_mouse_last_move_x == -1 || i_mouse_last_move_y == -1 ) ||
1053 ( abs( i_mouse_last_move_x - i_mousex ) > 2 ||
1054 abs( i_mouse_last_move_y - i_mousey ) > 2 ) )
1056 i_mouse_last_move_x = i_mousex;
1057 i_mouse_last_move_y = i_mousey;
1064 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1065 QApplication::postEvent( this, eShow );
1067 /* Plan hide event */
1068 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1069 QApplication::postEvent( this, eHide );