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;
187 bool b_special = false;
189 QWidget *widget = NULL;
193 PlayButton *playButton = new PlayButton;
194 setupButton( playButton );
195 BUTTON_SET_BAR( playButton );
196 CONNECT_MAP_SET( playButton, PLAY_ACTION );
197 CONNECT( this, inputPlaying( bool ),
198 playButton, updateButton( bool ));
203 QToolButton *stopButton = new QToolButton;
204 setupButton( stopButton );
205 CONNECT_MAP_SET( stopButton, STOP_ACTION );
206 BUTTON_SET_BAR( stopButton );
211 QToolButton *openButton = new QToolButton;
212 setupButton( openButton );
213 CONNECT_MAP_SET( openButton, OPEN_ACTION );
214 BUTTON_SET_BAR( openButton );
218 case PREVIOUS_BUTTON:{
219 QToolButton *prevButton = new QToolButton;
220 setupButton( prevButton );
221 CONNECT_MAP_SET( prevButton, PREVIOUS_ACTION );
222 BUTTON_SET_BAR( prevButton );
228 QToolButton *nextButton = new QToolButton;
229 setupButton( nextButton );
230 CONNECT_MAP_SET( nextButton, NEXT_ACTION );
231 BUTTON_SET_BAR( nextButton );
236 QToolButton *slowerButton = new QToolButton;
237 setupButton( slowerButton );
238 CONNECT_MAP_SET( slowerButton, SLOWER_ACTION );
239 BUTTON_SET_BAR( slowerButton );
240 ENABLE_ON_INPUT( slowerButton );
241 widget = slowerButton;
245 QToolButton *fasterButton = new QToolButton;
246 setupButton( fasterButton );
247 CONNECT_MAP_SET( fasterButton, FASTER_ACTION );
248 BUTTON_SET_BAR( fasterButton );
249 ENABLE_ON_INPUT( fasterButton );
250 widget = fasterButton;
254 QToolButton *frameButton = new QToolButton;
255 setupButton( frameButton );
256 CONNECT_MAP_SET( frameButton, FRAME_ACTION );
257 BUTTON_SET_BAR( frameButton );
258 ENABLE_ON_VIDEO( frameButton );
259 widget = frameButton;
262 case FULLSCREEN_BUTTON:{
263 QToolButton *fullscreenButton = new QToolButton;
264 setupButton( fullscreenButton );
265 CONNECT_MAP_SET( fullscreenButton, FULLSCREEN_ACTION );
266 BUTTON_SET_BAR( fullscreenButton );
267 ENABLE_ON_VIDEO( fullscreenButton );
268 widget = fullscreenButton;
271 case DEFULLSCREEN_BUTTON:{
272 QToolButton *fullscreenButton = new QToolButton;
273 setupButton( fullscreenButton );
274 CONNECT_MAP_SET( fullscreenButton, FULLSCREEN_ACTION );
275 BUTTON_SET_BAR( fullscreenButton )
276 ENABLE_ON_VIDEO( fullscreenButton );
277 widget = fullscreenButton;
280 case EXTENDED_BUTTON:{
281 QToolButton *extSettingsButton = new QToolButton;
282 setupButton( extSettingsButton );
283 CONNECT_MAP_SET( extSettingsButton, EXTENDED_ACTION );
284 BUTTON_SET_BAR( extSettingsButton )
285 widget = extSettingsButton;
288 case PLAYLIST_BUTTON:{
289 QToolButton *playlistButton = new QToolButton;
290 setupButton( playlistButton );
291 CONNECT_MAP_SET( playlistButton, PLAYLIST_ACTION );
292 BUTTON_SET_BAR( playlistButton );
293 widget = playlistButton;
296 case SNAPSHOT_BUTTON:{
297 QToolButton *snapshotButton = new QToolButton;
298 setupButton( snapshotButton );
299 CONNECT_MAP_SET( snapshotButton, SNAPSHOT_ACTION );
300 BUTTON_SET_BAR( snapshotButton );
301 ENABLE_ON_VIDEO( snapshotButton );
302 widget = snapshotButton;
306 QToolButton *recordButton = new QToolButton;
307 setupButton( recordButton );
308 CONNECT_MAP_SET( recordButton, RECORD_ACTION );
309 BUTTON_SET_BAR( recordButton );
310 ENABLE_ON_INPUT( recordButton );
311 recordButton->setCheckable( true );
312 CONNECT( THEMIM->getIM(), recordingStateChanged( bool ),
313 recordButton, setChecked( bool ) );
314 widget = recordButton;
318 AtoB_Button *ABButton = new AtoB_Button;
319 setupButton( ABButton );
320 BUTTON_SET_BAR( ABButton );
321 ENABLE_ON_INPUT( ABButton );
322 CONNECT_MAP_SET( ABButton, ATOB_ACTION );
323 CONNECT( THEMIM->getIM(), AtoBchanged( bool, bool),
324 ABButton, setIcons( bool, bool ) );
329 InputSlider *slider = new InputSlider( Qt::Horizontal, NULL );
331 /* Update the position when the IM has changed */
332 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
333 slider, setPosition( float, int, int ) );
334 /* And update the IM, when the position has changed */
335 CONNECT( slider, sliderDragged( float ),
336 THEMIM->getIM(), sliderUpdate( float ) );
341 widget = discFrame();
344 case TELETEXT_BUTTONS:
345 widget = telexFrame();
352 SoundWidget *snd = new SoundWidget( this, p_intf, b_shiny, b_special );
358 TimeLabel *timeLabel = new TimeLabel( p_intf );
364 QFrame *line = new QFrame;
365 line->setFrameShape( QFrame::VLine );
366 line->setFrameShadow( QFrame::Raised );
367 line->setLineWidth( 0 );
368 line->setMidLineWidth( 1 );
372 case ADVANCED_CONTROLLER:
374 advControls = new AdvControlsWidget( p_intf, this );
375 widget = advControls;
378 case REVERSE_BUTTON:{
379 QToolButton *reverseButton = new QToolButton;
380 setupButton( reverseButton );
381 CONNECT_MAP_SET( reverseButton, REVERSE_ACTION );
382 BUTTON_SET_BAR( reverseButton );
383 ENABLE_ON_INPUT( reverseButton );
384 widget = reverseButton;
387 case SKIP_BACK_BUTTON: {
388 QToolButton *skipBakButton = new QToolButton;
389 setupButton( skipBakButton );
390 CONNECT_MAP_SET( skipBakButton, SKIP_BACK_ACTION );
391 BUTTON_SET_BAR( skipBakButton );
392 ENABLE_ON_INPUT( skipBakButton );
393 widget = skipBakButton;
396 case SKIP_FW_BUTTON: {
397 QToolButton *skipFwButton = new QToolButton;
398 setupButton( skipFwButton );
399 CONNECT_MAP_SET( skipFwButton, SKIP_FW_ACTION );
400 BUTTON_SET_BAR( skipFwButton );
401 ENABLE_ON_INPUT( skipFwButton );
402 widget = skipFwButton;
406 QToolButton *quitButton = new QToolButton;
407 setupButton( quitButton );
408 CONNECT_MAP_SET( quitButton, QUIT_ACTION );
409 BUTTON_SET_BAR( quitButton );
414 msg_Warn( p_intf, "This should not happen %i", button );
418 /* Customize Buttons */
419 if( b_flat || b_big )
421 QToolButton *tmpButton = qobject_cast<QToolButton *>(widget);
425 tmpButton->setAutoRaise( b_flat );
428 tmpButton->setFixedSize( QSize( 32, 32 ) );
429 tmpButton->setIconSize( QSize( 26, 26 ) );
436 QFrame *AbstractController::discFrame()
438 /** Disc and Menus handling */
439 QFrame *discFrame = new QFrame( this );
441 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
442 discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );
444 QToolButton *prevSectionButton = new QToolButton( discFrame );
445 setupButton( prevSectionButton );
446 BUTTON_SET_BAR2( prevSectionButton, dvd_prev,
447 qtr("Previous Chapter/Title" ) );
448 discLayout->addWidget( prevSectionButton );
450 QToolButton *menuButton = new QToolButton( discFrame );
451 setupButton( menuButton );
452 discLayout->addWidget( menuButton );
453 BUTTON_SET_BAR2( menuButton, dvd_menu, qtr( "Menu" ) );
455 QToolButton *nextSectionButton = new QToolButton( discFrame );
456 setupButton( nextSectionButton );
457 discLayout->addWidget( nextSectionButton );
458 BUTTON_SET_BAR2( nextSectionButton, dvd_next,
459 qtr("Next Chapter/Title" ) );
461 /* Change the navigation button display when the IM
462 navigation changes */
463 CONNECT( THEMIM->getIM(), titleChanged( bool ),
464 discFrame, setVisible( bool ) );
465 CONNECT( THEMIM->getIM(), chapterChanged( bool ),
466 menuButton, setVisible( bool ) );
467 /* Changes the IM navigation when triggered on the nav buttons */
468 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
470 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
472 CONNECT( menuButton, clicked(), THEMIM->getIM(),
478 QFrame *AbstractController::telexFrame()
483 TeletextController *telexFrame = new TeletextController;
484 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
485 telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );
486 CONNECT( THEMIM->getIM(), teletextPossible( bool ),
487 telexFrame, setVisible( bool ) );
490 QToolButton *telexOn = new QToolButton;
491 telexFrame->telexOn = telexOn;
492 setupButton( telexOn );
493 BUTTON_SET_BAR2( telexOn, tv, qtr( "Teletext Activation" ) );
494 telexLayout->addWidget( telexOn );
496 /* Teletext Activation and set */
497 CONNECT( telexOn, clicked( bool ),
498 THEMIM->getIM(), activateTeletext( bool ) );
499 CONNECT( THEMIM->getIM(), teletextActivated( bool ),
500 telexFrame, enableTeletextButtons( bool ) );
503 /* Transparency button */
504 QToolButton *telexTransparent = new QToolButton;
505 telexFrame->telexTransparent = telexTransparent;
506 setupButton( telexTransparent );
507 BUTTON_SET_BAR2( telexTransparent, tvtelx,
508 qtr( "Toggle Transparency " ) );
509 telexTransparent->setEnabled( false );
510 telexTransparent->setCheckable( true );
511 telexLayout->addWidget( telexTransparent );
513 /* Transparency change and set */
514 CONNECT( telexTransparent, clicked( bool ),
515 THEMIM->getIM(), telexSetTransparency( bool ) );
516 CONNECT( THEMIM->getIM(), teletextTransparencyActivated( bool ),
517 telexTransparent, setChecked( bool ) );
521 QSpinBox *telexPage = new QSpinBox;
522 telexFrame->telexPage = telexPage;
523 telexPage->setRange( 0, 999 );
524 telexPage->setValue( 100 );
525 telexPage->setAccelerated( true );
526 telexPage->setWrapping( true );
527 telexPage->setAlignment( Qt::AlignRight );
528 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
529 telexPage->setEnabled( false );
530 telexLayout->addWidget( telexPage );
532 /* Page change and set */
533 CONNECT( telexPage, valueChanged( int ),
534 THEMIM->getIM(), telexSetPage( int ) );
535 CONNECT( THEMIM->getIM(), newTelexPageSet( int ),
536 telexPage, setValue( int ) );
542 #undef CONNECT_MAP_SET
543 #undef BUTTON_SET_BAR
544 #undef ENABLE_ON_VIDEO
545 #undef ENABLE_ON_INPUT
547 #include <QHBoxLayout>
548 /*****************************
549 * DA Control Widget !
550 *****************************/
551 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
554 AbstractController( _p_i, _parent )
556 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
558 /* advanced Controls handling */
559 b_advancedVisible = b_advControls;
561 QVBoxLayout *controlLayout = new QVBoxLayout( this );
562 controlLayout->setLayoutMargins( 6, 4, 6, 2, 5 );
563 controlLayout->setSpacing( 0 );
564 QHBoxLayout *controlLayout1 = new QHBoxLayout;
565 controlLayout1->setSpacing( 0 );
567 QString line1 = getSettings()->value( "MainToolbar1", MAIN_TB1_DEFAULT )
569 parseAndCreate( line1, controlLayout1 );
571 QHBoxLayout *controlLayout2 = new QHBoxLayout;
572 controlLayout2->setSpacing( 0 );
573 QString line2 = getSettings()->value( "MainToolbar2", MAIN_TB2_DEFAULT )
575 parseAndCreate( line2, controlLayout2 );
577 if( !b_advancedVisible && advControls ) advControls->hide();
579 controlLayout->addLayout( controlLayout1 );
580 controlLayout->addLayout( controlLayout2 );
583 ControlsWidget::~ControlsWidget()
586 void ControlsWidget::toggleAdvanced()
588 if( !advControls ) return;
590 if( !b_advancedVisible )
593 b_advancedVisible = true;
598 b_advancedVisible = false;
600 emit advancedControlsToggled( b_advancedVisible );
603 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
604 AbstractController( _p_i, _parent )
606 controlLayout = new QHBoxLayout( this );
607 controlLayout->setMargin( 0 );
608 controlLayout->setSpacing( 0 );
610 QString line = getSettings()->value( "AdvToolbar", ADV_TB_DEFAULT )
612 parseAndCreate( line, controlLayout );
615 InputControlsWidget::InputControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
616 AbstractController( _p_i, _parent )
618 controlLayout = new QHBoxLayout( this );
619 controlLayout->setMargin( 0 );
620 controlLayout->setSpacing( 0 );
622 QString line = getSettings()->value( "InputToolbar", INPT_TB_DEFAULT ).toString();
623 parseAndCreate( line, controlLayout );
625 /**********************************************************************
626 * Fullscrenn control widget
627 **********************************************************************/
628 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i )
629 : AbstractController( _p_i )
633 b_mouse_over = false;
634 i_mouse_last_move_x = -1;
635 i_mouse_last_move_y = -1;
636 #if HAVE_TRANSPARENCY
637 b_slow_hide_begin = false;
638 i_slow_hide_timeout = 1;
640 b_fullscreen = false;
646 setWindowFlags( Qt::ToolTip );
647 setMinimumWidth( 600 );
649 setFrameShape( QFrame::StyledPanel );
650 setFrameStyle( QFrame::Sunken );
651 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
653 QVBoxLayout *controlLayout2 = new QVBoxLayout( this );
654 controlLayout2->setLayoutMargins( 5, 2, 5, 2, 5 );
657 InputControlsWidget *inputC = new InputControlsWidget( p_intf, this );
658 controlLayout2->addWidget( inputC );
660 controlLayout = new QHBoxLayout;
661 QString line = getSettings()->value( "MainWindow/FSCtoolbar", FSC_TB_DEFAULT ).toString();
662 parseAndCreate( line, controlLayout );
663 controlLayout2->addLayout( controlLayout );
666 p_hideTimer = new QTimer( this );
667 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
668 p_hideTimer->setSingleShot( true );
670 /* slow hiding timer */
671 #if HAVE_TRANSPARENCY
672 p_slowHideTimer = new QTimer( this );
673 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
676 adjustSize (); /* need to get real width and height for moving */
679 setWindowOpacity( 0.0 );
685 vlc_mutex_init_recursive( &lock );
687 CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ), this, setVoutList( vout_thread_t **, int ) );
690 FullscreenControllerWidget::~FullscreenControllerWidget()
692 getSettings()->setValue( "FullScreen/pos", pos() );
693 setVoutList( NULL, 0 );
694 vlc_mutex_destroy( &lock );
698 * Show fullscreen controller
700 void FullscreenControllerWidget::showFSC()
704 int number = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
705 if( number != i_screennumber ||
706 screenRes != QApplication::desktop()->screenGeometry(number) )
708 screenRes = QApplication::desktop()->screenGeometry(number);
709 msg_Dbg( p_intf, "Calculation fullscreen controllers center");
710 /* screen has changed, calculate new position */
711 QPoint pos = QPoint( screenRes.x() + (screenRes.width() / 2) - (width() / 2),
712 screenRes.y() + screenRes.height() - height());
714 i_screennumber = number;
717 // after quiting and going to fs, we need to call show()
723 setWindowOpacity( 1.0 );
729 #if HAVE_TRANSPARENCY
730 setWindowOpacity( DEFAULT_OPACITY );
735 * Hide fullscreen controller
736 * FIXME: under windows it have to be done by moving out of screen
737 * because hide() doesnt work
739 void FullscreenControllerWidget::hideFSC()
743 setWindowOpacity( 0.0 ); // simulate hidding
750 * Plane to hide fullscreen controller
752 void FullscreenControllerWidget::planHideFSC()
754 vlc_mutex_lock( &lock );
755 int i_timeout = i_hide_timeout;
756 vlc_mutex_unlock( &lock );
758 p_hideTimer->start( i_timeout );
760 #if HAVE_TRANSPARENCY
761 b_slow_hide_begin = true;
762 i_slow_hide_timeout = i_timeout;
763 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
768 * Hidding fullscreen controller slowly
769 * Linux: need composite manager
770 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
772 void FullscreenControllerWidget::slowHideFSC()
774 #if HAVE_TRANSPARENCY
775 if( b_slow_hide_begin )
777 b_slow_hide_begin = false;
779 p_slowHideTimer->stop();
780 /* the last part of time divided to 100 pieces */
781 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
787 if ( windowOpacity() > 0.0 && !b_fscHidden )
789 if ( windowOpacity() > 0.0 )
792 /* we should use 0.01 because of 100 pieces ^^^
793 but than it cannt be done in time */
794 setWindowOpacity( windowOpacity() - 0.02 );
797 if ( windowOpacity() <= 0.0 )
798 p_slowHideTimer->stop();
805 * events: show, hide, start timer for hidding
807 void FullscreenControllerWidget::customEvent( QEvent *event )
811 switch( event->type() )
813 case FullscreenControlToggle_Type:
814 vlc_mutex_lock( &lock );
816 vlc_mutex_unlock( &lock );
832 case FullscreenControlShow_Type:
833 vlc_mutex_lock( &lock );
835 vlc_mutex_unlock( &lock );
838 if( b_fs && b_fscHidden )
840 if( b_fs && !isVisible() )
844 case FullscreenControlHide_Type:
847 case FullscreenControlPlanHide_Type:
848 if( !b_mouse_over ) // Only if the mouse is not over FSC
860 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
862 if ( event->buttons() == Qt::LeftButton )
864 int i_moveX = event->globalX() - i_mouse_last_x;
865 int i_moveY = event->globalY() - i_mouse_last_y;
867 move( x() + i_moveX, y() + i_moveY );
869 i_mouse_last_x = event->globalX();
870 i_mouse_last_y = event->globalY();
876 * store position of cursor
878 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
880 i_mouse_last_x = event->globalX();
881 i_mouse_last_y = event->globalY();
885 * On mouse go above FSC
887 void FullscreenControllerWidget::enterEvent( QEvent *event )
892 #if HAVE_TRANSPARENCY
893 p_slowHideTimer->stop();
899 * On mouse go out from FSC
901 void FullscreenControllerWidget::leaveEvent( QEvent *event )
905 b_mouse_over = false;
910 * When you get pressed key, send it to video output
911 * FIXME: clearing focus by clearFocus() to not getting
912 * key press events didnt work
914 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
916 int i_vlck = qtEventToVLCKey( event );
919 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
927 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object,
928 const char *variable, vlc_value_t old_val,
929 vlc_value_t new_val, void *data )
931 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
933 msg_Dbg( p_vout, "Qt4: Fullscreen state changed" );
934 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
936 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
941 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
942 vlc_value_t old_val, vlc_value_t new_val,
945 vout_thread_t *p_vout = (vout_thread_t *)vlc_object;
946 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
948 /* Get the value from the Vout - Trust the vout more than Qt */
949 const int i_mousex = var_GetInteger( p_vout, "mouse-x" );
950 const int i_mousey = var_GetInteger( p_vout, "mouse-y" );
952 p_fs->mouseChanged( p_vout, i_mousex, i_mousey );
958 * It is call to update the list of vout handled by the fullscreen controller
960 void FullscreenControllerWidget::setVoutList( vout_thread_t **pp_vout, int i_vout )
962 QList<vout_thread_t*> del;
963 QList<vout_thread_t*> add;
965 QList<vout_thread_t*> set;
968 for( int i = 0; i < i_vout; i++ )
972 vlc_mutex_lock( &lock );
973 foreach( vout_thread_t *p_vout, vout )
975 if( !set.contains( p_vout ) )
978 vlc_mutex_unlock( &lock );
980 foreach( vout_thread_t *p_vout, del )
982 var_DelCallback( p_vout, "fullscreen",
983 FullscreenControllerWidgetFullscreenChanged, this );
984 vlc_mutex_lock( &lock );
985 fullscreenChanged( p_vout, false, 0 );
986 vout.removeAll( p_vout );
987 vlc_mutex_unlock( &lock );
991 vlc_mutex_lock( &lock );
992 foreach( vout_thread_t *p_vout, set )
994 if( !vout.contains( p_vout ) )
997 vlc_mutex_unlock( &lock );
999 foreach( vout_thread_t *p_vout, add )
1001 vlc_object_hold( (vlc_object_t*)p_vout );
1003 vlc_mutex_lock( &lock );
1004 vout.append( p_vout );
1005 var_AddCallback( p_vout, "fullscreen",
1006 FullscreenControllerWidgetFullscreenChanged, this );
1007 /* I miss a add and fire */
1008 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ),
1009 var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1010 vlc_mutex_unlock( &lock );
1014 * Register and unregister callback for mouse moving
1016 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout,
1017 bool b_fs, int i_timeout )
1019 /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
1020 msg_Dbg( p_vout, "Qt: Entering Fullscreen" );
1022 vlc_mutex_lock( &lock );
1023 /* Entering fullscreen, register callback */
1024 if( b_fs && !b_fullscreen )
1026 b_fullscreen = true;
1027 i_hide_timeout = i_timeout;
1028 var_AddCallback( p_vout, "mouse-moved",
1029 FullscreenControllerWidgetMouseMoved, this );
1031 /* Quitting fullscreen, unregistering callback */
1032 else if( !b_fs && b_fullscreen )
1034 b_fullscreen = false;
1035 i_hide_timeout = i_timeout;
1036 var_DelCallback( p_vout, "mouse-moved",
1037 FullscreenControllerWidgetMouseMoved, this );
1039 /* Force fs hidding */
1040 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1041 QApplication::postEvent( this, eHide );
1043 vlc_mutex_unlock( &lock );
1046 * Mouse change callback (show/hide the controller on mouse movement)
1048 void FullscreenControllerWidget::mouseChanged( vout_thread_t *p_vout, int i_mousex, int i_mousey )
1052 /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
1055 if( ( i_mouse_last_move_x == -1 || i_mouse_last_move_y == -1 ) ||
1056 ( abs( i_mouse_last_move_x - i_mousex ) > 2 ||
1057 abs( i_mouse_last_move_y - i_mousey ) > 2 ) )
1059 i_mouse_last_move_x = i_mousex;
1060 i_mouse_last_move_y = i_mousey;
1067 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1068 QApplication::postEvent( this, eShow );
1070 /* Plan hide event */
1071 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1072 QApplication::postEvent( this, eHide );