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 telexLayout->addWidget( telexTransparent );
509 /* Transparency change and set */
510 CONNECT( telexTransparent, clicked( bool ),
511 THEMIM->getIM(), telexSetTransparency( bool ) );
512 CONNECT( THEMIM->getIM(), teletextTransparencyActivated( bool ),
513 telexFrame, toggleTeletextTransparency( bool ) );
517 QSpinBox *telexPage = new QSpinBox;
518 telexFrame->telexPage = telexPage;
519 telexPage->setRange( 0, 999 );
520 telexPage->setValue( 100 );
521 telexPage->setAccelerated( true );
522 telexPage->setWrapping( true );
523 telexPage->setAlignment( Qt::AlignRight );
524 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
525 telexPage->setEnabled( false );
526 telexLayout->addWidget( telexPage );
528 /* Page change and set */
529 CONNECT( telexPage, valueChanged( int ),
530 THEMIM->getIM(), telexSetPage( int ) );
531 CONNECT( THEMIM->getIM(), newTelexPageSet( int ),
532 telexPage, setValue( int ) );
538 #undef CONNECT_MAP_SET
539 #undef BUTTON_SET_BAR
540 #undef ENABLE_ON_VIDEO
541 #undef ENABLE_ON_INPUT
543 #include <QHBoxLayout>
544 /*****************************
545 * DA Control Widget !
546 *****************************/
547 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
550 AbstractController( _p_i, _parent )
552 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
554 /* advanced Controls handling */
555 b_advancedVisible = b_advControls;
557 QVBoxLayout *controlLayout = new QVBoxLayout( this );
558 controlLayout->setLayoutMargins( 6, 4, 6, 2, 5 );
559 controlLayout->setSpacing( 0 );
560 QHBoxLayout *controlLayout1 = new QHBoxLayout;
561 controlLayout1->setSpacing( 0 );
563 QString line1 = getSettings()->value( "MainToolbar1", MAIN_TB1_DEFAULT )
565 parseAndCreate( line1, controlLayout1 );
567 QHBoxLayout *controlLayout2 = new QHBoxLayout;
568 controlLayout2->setSpacing( 0 );
569 QString line2 = getSettings()->value( "MainToolbar2", MAIN_TB2_DEFAULT )
571 parseAndCreate( line2, controlLayout2 );
573 if( !b_advancedVisible && advControls ) advControls->hide();
575 controlLayout->addLayout( controlLayout1 );
576 controlLayout->addLayout( controlLayout2 );
579 ControlsWidget::~ControlsWidget()
582 void ControlsWidget::toggleAdvanced()
584 if( !advControls ) return;
586 if( !b_advancedVisible )
589 b_advancedVisible = true;
594 b_advancedVisible = false;
596 emit advancedControlsToggled( b_advancedVisible );
599 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
600 AbstractController( _p_i, _parent )
602 controlLayout = new QHBoxLayout( this );
603 controlLayout->setMargin( 0 );
604 controlLayout->setSpacing( 0 );
606 QString line = getSettings()->value( "AdvToolbar", ADV_TB_DEFAULT )
608 parseAndCreate( line, controlLayout );
611 InputControlsWidget::InputControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
612 AbstractController( _p_i, _parent )
614 controlLayout = new QHBoxLayout( this );
615 controlLayout->setMargin( 0 );
616 controlLayout->setSpacing( 0 );
618 QString line = getSettings()->value( "InputToolbar", INPT_TB_DEFAULT ).toString();
619 parseAndCreate( line, controlLayout );
621 /**********************************************************************
622 * Fullscrenn control widget
623 **********************************************************************/
624 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i )
625 : AbstractController( _p_i )
629 b_mouse_over = false;
630 i_mouse_last_move_x = -1;
631 i_mouse_last_move_y = -1;
632 #if HAVE_TRANSPARENCY
633 b_slow_hide_begin = false;
634 i_slow_hide_timeout = 1;
636 b_fullscreen = false;
642 setWindowFlags( Qt::ToolTip );
643 setMinimumWidth( 600 );
645 setFrameShape( QFrame::StyledPanel );
646 setFrameStyle( QFrame::Sunken );
647 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
649 QVBoxLayout *controlLayout2 = new QVBoxLayout( this );
650 controlLayout2->setLayoutMargins( 5, 2, 5, 2, 5 );
653 InputControlsWidget *inputC = new InputControlsWidget( p_intf, this );
654 controlLayout2->addWidget( inputC );
656 controlLayout = new QHBoxLayout;
657 QString line = getSettings()->value( "MainWindow/FSCtoolbar", FSC_TB_DEFAULT ).toString();
658 parseAndCreate( line, controlLayout );
659 controlLayout2->addLayout( controlLayout );
662 p_hideTimer = new QTimer( this );
663 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
664 p_hideTimer->setSingleShot( true );
666 /* slow hiding timer */
667 #if HAVE_TRANSPARENCY
668 p_slowHideTimer = new QTimer( this );
669 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
672 adjustSize (); /* need to get real width and height for moving */
675 setWindowOpacity( 0.0 );
681 vlc_mutex_init_recursive( &lock );
683 CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ), this, setVoutList( vout_thread_t **, int ) );
686 FullscreenControllerWidget::~FullscreenControllerWidget()
688 getSettings()->setValue( "FullScreen/pos", pos() );
689 setVoutList( NULL, 0 );
690 vlc_mutex_destroy( &lock );
694 * Show fullscreen controller
696 void FullscreenControllerWidget::showFSC()
700 int number = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
701 if( number != i_screennumber )
703 msg_Dbg( p_intf, "Calculation fullscreen controllers center");
704 /* screen has changed, calculate new position */
705 QRect screenRes = QApplication::desktop()->screenGeometry(number);
706 QPoint pos = QPoint( screenRes.x() + (screenRes.width() / 2) - (width() / 2),
707 screenRes.y() + screenRes.height() - height());
709 i_screennumber = number;
712 // after quiting and going to fs, we need to call show()
718 setWindowOpacity( 1.0 );
724 #if HAVE_TRANSPARENCY
725 setWindowOpacity( DEFAULT_OPACITY );
730 * Hide fullscreen controller
731 * FIXME: under windows it have to be done by moving out of screen
732 * because hide() doesnt work
734 void FullscreenControllerWidget::hideFSC()
738 setWindowOpacity( 0.0 ); // simulate hidding
745 * Plane to hide fullscreen controller
747 void FullscreenControllerWidget::planHideFSC()
749 vlc_mutex_lock( &lock );
750 int i_timeout = i_hide_timeout;
751 vlc_mutex_unlock( &lock );
753 p_hideTimer->start( i_timeout );
755 #if HAVE_TRANSPARENCY
756 b_slow_hide_begin = true;
757 i_slow_hide_timeout = i_timeout;
758 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
763 * Hidding fullscreen controller slowly
764 * Linux: need composite manager
765 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
767 void FullscreenControllerWidget::slowHideFSC()
769 #if HAVE_TRANSPARENCY
770 if( b_slow_hide_begin )
772 b_slow_hide_begin = false;
774 p_slowHideTimer->stop();
775 /* the last part of time divided to 100 pieces */
776 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
782 if ( windowOpacity() > 0.0 && !b_fscHidden )
784 if ( windowOpacity() > 0.0 )
787 /* we should use 0.01 because of 100 pieces ^^^
788 but than it cannt be done in time */
789 setWindowOpacity( windowOpacity() - 0.02 );
792 if ( windowOpacity() <= 0.0 )
793 p_slowHideTimer->stop();
800 * events: show, hide, start timer for hidding
802 void FullscreenControllerWidget::customEvent( QEvent *event )
806 switch( event->type() )
808 case FullscreenControlToggle_Type:
809 vlc_mutex_lock( &lock );
811 vlc_mutex_unlock( &lock );
827 case FullscreenControlShow_Type:
828 vlc_mutex_lock( &lock );
830 vlc_mutex_unlock( &lock );
833 if( b_fs && b_fscHidden )
835 if( b_fs && !isVisible() )
839 case FullscreenControlHide_Type:
842 case FullscreenControlPlanHide_Type:
843 if( !b_mouse_over ) // Only if the mouse is not over FSC
855 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
857 if ( event->buttons() == Qt::LeftButton )
859 int i_moveX = event->globalX() - i_mouse_last_x;
860 int i_moveY = event->globalY() - i_mouse_last_y;
862 move( x() + i_moveX, y() + i_moveY );
864 i_mouse_last_x = event->globalX();
865 i_mouse_last_y = event->globalY();
871 * store position of cursor
873 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
875 i_mouse_last_x = event->globalX();
876 i_mouse_last_y = event->globalY();
880 * On mouse go above FSC
882 void FullscreenControllerWidget::enterEvent( QEvent *event )
887 #if HAVE_TRANSPARENCY
888 p_slowHideTimer->stop();
894 * On mouse go out from FSC
896 void FullscreenControllerWidget::leaveEvent( QEvent *event )
900 b_mouse_over = false;
905 * When you get pressed key, send it to video output
906 * FIXME: clearing focus by clearFocus() to not getting
907 * key press events didnt work
909 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
911 int i_vlck = qtEventToVLCKey( event );
914 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
922 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object,
923 const char *variable, vlc_value_t old_val,
924 vlc_value_t new_val, void *data )
926 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
928 msg_Dbg( p_vout, "Qt4: Fullscreen state changed" );
929 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
931 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
936 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
937 vlc_value_t old_val, vlc_value_t new_val,
940 vout_thread_t *p_vout = (vout_thread_t *)vlc_object;
941 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
943 /* Get the value from the Vout - Trust the vout more than Qt */
944 const int i_mousex = var_GetInteger( p_vout, "mouse-x" );
945 const int i_mousey = var_GetInteger( p_vout, "mouse-y" );
947 p_fs->mouseChanged( p_vout, i_mousex, i_mousey );
953 * It is call to update the list of vout handled by the fullscreen controller
955 void FullscreenControllerWidget::setVoutList( vout_thread_t **pp_vout, int i_vout )
957 QList<vout_thread_t*> del;
958 QList<vout_thread_t*> add;
960 QList<vout_thread_t*> set;
963 for( int i = 0; i < i_vout; i++ )
967 vlc_mutex_lock( &lock );
968 foreach( vout_thread_t *p_vout, vout )
970 if( !set.contains( p_vout ) )
973 vlc_mutex_unlock( &lock );
975 foreach( vout_thread_t *p_vout, del )
977 var_DelCallback( p_vout, "fullscreen",
978 FullscreenControllerWidgetFullscreenChanged, this );
979 vlc_mutex_lock( &lock );
980 fullscreenChanged( p_vout, false, 0 );
981 vout.removeAll( p_vout );
982 vlc_mutex_unlock( &lock );
986 vlc_mutex_lock( &lock );
987 foreach( vout_thread_t *p_vout, set )
989 if( !vout.contains( p_vout ) )
992 vlc_mutex_unlock( &lock );
994 foreach( vout_thread_t *p_vout, add )
996 vlc_object_hold( (vlc_object_t*)p_vout );
998 vlc_mutex_lock( &lock );
999 vout.append( p_vout );
1000 var_AddCallback( p_vout, "fullscreen",
1001 FullscreenControllerWidgetFullscreenChanged, this );
1002 /* I miss a add and fire */
1003 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ),
1004 var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1005 vlc_mutex_unlock( &lock );
1009 * Register and unregister callback for mouse moving
1011 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout,
1012 bool b_fs, int i_timeout )
1014 /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
1015 msg_Dbg( p_vout, "Qt: Entering Fullscreen" );
1017 vlc_mutex_lock( &lock );
1018 /* Entering fullscreen, register callback */
1019 if( b_fs && !b_fullscreen )
1021 b_fullscreen = true;
1022 i_hide_timeout = i_timeout;
1023 var_AddCallback( p_vout, "mouse-moved",
1024 FullscreenControllerWidgetMouseMoved, this );
1026 /* Quitting fullscreen, unregistering callback */
1027 else if( !b_fs && b_fullscreen )
1029 b_fullscreen = false;
1030 i_hide_timeout = i_timeout;
1031 var_DelCallback( p_vout, "mouse-moved",
1032 FullscreenControllerWidgetMouseMoved, this );
1034 /* Force fs hidding */
1035 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1036 QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1038 vlc_mutex_unlock( &lock );
1041 * Mouse change callback (show/hide the controller on mouse movement)
1043 void FullscreenControllerWidget::mouseChanged( vout_thread_t *p_vout, int i_mousex, int i_mousey )
1047 /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
1050 if( ( i_mouse_last_move_x == -1 || i_mouse_last_move_y == -1 ) ||
1051 ( abs( i_mouse_last_move_x - i_mousex ) > 2 ||
1052 abs( i_mouse_last_move_y - i_mousey ) > 2 ) )
1054 i_mouse_last_move_x = i_mousex;
1055 i_mouse_last_move_y = i_mousey;
1062 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1063 QApplication::postEvent( this, static_cast<QEvent *>(eShow) );
1065 /* Plan hide event */
1066 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1067 QApplication::postEvent( this, static_cast<QEvent *>(eHide) );