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" ) );
83 emit inputIsTrickPlayable( b_hasInput &&
84 var_GetBool( THEMIM->getInput(), "can-rewind" ) );
87 /* Generic button setup */
88 void AbstractController::setupButton( QAbstractButton *aButton )
90 static QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
91 sizePolicy.setHorizontalStretch( 0 );
92 sizePolicy.setVerticalStretch( 0 );
94 aButton->setSizePolicy( sizePolicy );
95 aButton->setFixedSize( QSize( 26, 26 ) );
96 aButton->setIconSize( QSize( 20, 20 ) );
97 aButton->setFocusPolicy( Qt::NoFocus );
100 /* Open the generic config line for the toolbar, parse it
101 * and create the widgets accordingly */
102 void AbstractController::parseAndCreate( QString config,
103 QBoxLayout *controlLayout )
105 QStringList list = config.split( ";", QString::SkipEmptyParts ) ;
106 for( int i = 0; i < list.size(); i++ )
108 QStringList list2 = list.at( i ).split( "-" );
109 if( list2.size() < 1 )
111 msg_Warn( p_intf, "Parsing error. Report this" );
116 int i_option = WIDGET_NORMAL;
117 buttonType_e i_type = (buttonType_e)list2.at( 0 ).toInt( &ok );
120 msg_Warn( p_intf, "Parsing error 0. Please report this" );
124 if( list2.size() > 1 )
126 i_option = list2.at( 1 ).toInt( &ok );
129 msg_Warn( p_intf, "Parsing error 1. Please report this" );
134 createAndAddWidget( controlLayout, -1, i_type, i_option );
138 void AbstractController::createAndAddWidget( QBoxLayout *controlLayout,
143 /* Special case for SPACERS, who aren't QWidgets */
144 if( i_type == WIDGET_SPACER )
146 controlLayout->insertSpacing( i_index, 16 );
150 if( i_type == WIDGET_SPACER_EXTEND )
152 controlLayout->insertStretch( i_index, 16 );
156 QWidget *widg = createWidget( i_type, i_option );
159 controlLayout->insertWidget( i_index, widg );
163 #define CONNECT_MAP( a ) CONNECT( a, clicked(), toolbarActionsMapper, map() )
164 #define SET_MAPPING( a, b ) toolbarActionsMapper->setMapping( a , b )
165 #define CONNECT_MAP_SET( a, b ) \
168 #define BUTTON_SET_BAR( a_button ) \
169 a_button->setToolTip( tooltipL[button] ); \
170 a_button->setIcon( QIcon( iconL[button] ) );
171 #define BUTTON_SET_BAR2( button, image, tooltip ) \
172 button->setToolTip( tooltip ); \
173 button->setIcon( QIcon( ":/"#image ) );
176 #define ENABLE_ON_VIDEO( a ) \
177 CONNECT( THEMIM->getIM(), voutChanged( bool ), a, setEnabled( bool ) ); \
178 a->setEnabled( THEMIM->getIM()->hasVideo() ); /* TODO: is this necessary? when input is started before the interface? */
180 #define ENABLE_ON_INPUT( a ) \
181 CONNECT( this, inputExists( bool ), a, setEnabled( bool ) ); \
182 a->setEnabled( THEMIM->getIM()->hasInput() ); /* TODO: is this necessary? when input is started before the interface? */
184 QWidget *AbstractController::createWidget( buttonType_e button, int options )
187 bool b_flat = options & WIDGET_FLAT;
188 bool b_big = options & WIDGET_BIG;
189 bool b_shiny = options & WIDGET_SHINY;
190 bool b_special = false;
192 QWidget *widget = NULL;
196 PlayButton *playButton = new PlayButton;
197 setupButton( playButton );
198 BUTTON_SET_BAR( playButton );
199 CONNECT_MAP_SET( playButton, PLAY_ACTION );
200 CONNECT( this, inputPlaying( bool ),
201 playButton, updateButton( bool ));
206 QToolButton *stopButton = new QToolButton;
207 setupButton( stopButton );
208 CONNECT_MAP_SET( stopButton, STOP_ACTION );
209 BUTTON_SET_BAR( stopButton );
214 QToolButton *openButton = new QToolButton;
215 setupButton( openButton );
216 CONNECT_MAP_SET( openButton, OPEN_ACTION );
217 BUTTON_SET_BAR( openButton );
221 case PREVIOUS_BUTTON:{
222 QToolButton *prevButton = new QToolButton;
223 setupButton( prevButton );
224 CONNECT_MAP_SET( prevButton, PREVIOUS_ACTION );
225 BUTTON_SET_BAR( prevButton );
231 QToolButton *nextButton = new QToolButton;
232 setupButton( nextButton );
233 CONNECT_MAP_SET( nextButton, NEXT_ACTION );
234 BUTTON_SET_BAR( nextButton );
239 QToolButton *slowerButton = new QToolButton;
240 setupButton( slowerButton );
241 CONNECT_MAP_SET( slowerButton, SLOWER_ACTION );
242 BUTTON_SET_BAR( slowerButton );
243 ENABLE_ON_INPUT( slowerButton );
244 widget = slowerButton;
248 QToolButton *fasterButton = new QToolButton;
249 setupButton( fasterButton );
250 CONNECT_MAP_SET( fasterButton, FASTER_ACTION );
251 BUTTON_SET_BAR( fasterButton );
252 ENABLE_ON_INPUT( fasterButton );
253 widget = fasterButton;
257 QToolButton *frameButton = new QToolButton;
258 setupButton( frameButton );
259 CONNECT_MAP_SET( frameButton, FRAME_ACTION );
260 BUTTON_SET_BAR( frameButton );
261 ENABLE_ON_VIDEO( frameButton );
262 widget = frameButton;
265 case FULLSCREEN_BUTTON:{
266 QToolButton *fullscreenButton = new QToolButton;
267 setupButton( fullscreenButton );
268 CONNECT_MAP_SET( fullscreenButton, FULLSCREEN_ACTION );
269 BUTTON_SET_BAR( fullscreenButton );
270 ENABLE_ON_VIDEO( fullscreenButton );
271 widget = fullscreenButton;
274 case DEFULLSCREEN_BUTTON:{
275 QToolButton *fullscreenButton = new QToolButton;
276 setupButton( fullscreenButton );
277 CONNECT_MAP_SET( fullscreenButton, FULLSCREEN_ACTION );
278 BUTTON_SET_BAR( fullscreenButton )
279 ENABLE_ON_VIDEO( fullscreenButton );
280 widget = fullscreenButton;
283 case EXTENDED_BUTTON:{
284 QToolButton *extSettingsButton = new QToolButton;
285 setupButton( extSettingsButton );
286 CONNECT_MAP_SET( extSettingsButton, EXTENDED_ACTION );
287 BUTTON_SET_BAR( extSettingsButton )
288 widget = extSettingsButton;
291 case PLAYLIST_BUTTON:{
292 QToolButton *playlistButton = new QToolButton;
293 setupButton( playlistButton );
294 CONNECT_MAP_SET( playlistButton, PLAYLIST_ACTION );
295 BUTTON_SET_BAR( playlistButton );
296 widget = playlistButton;
299 case SNAPSHOT_BUTTON:{
300 QToolButton *snapshotButton = new QToolButton;
301 setupButton( snapshotButton );
302 CONNECT_MAP_SET( snapshotButton, SNAPSHOT_ACTION );
303 BUTTON_SET_BAR( snapshotButton );
304 ENABLE_ON_VIDEO( snapshotButton );
305 widget = snapshotButton;
309 QToolButton *recordButton = new QToolButton;
310 setupButton( recordButton );
311 CONNECT_MAP_SET( recordButton, RECORD_ACTION );
312 BUTTON_SET_BAR( recordButton );
313 ENABLE_ON_INPUT( recordButton );
314 recordButton->setCheckable( true );
315 CONNECT( THEMIM->getIM(), recordingStateChanged( bool ),
316 recordButton, setChecked( bool ) );
317 widget = recordButton;
321 AtoB_Button *ABButton = new AtoB_Button;
322 setupButton( ABButton );
323 ABButton->setShortcut( qtr("Shift+L") );
324 BUTTON_SET_BAR( ABButton );
325 ENABLE_ON_INPUT( ABButton );
326 CONNECT_MAP_SET( ABButton, ATOB_ACTION );
327 CONNECT( THEMIM->getIM(), AtoBchanged( bool, bool),
328 ABButton, setIcons( bool, bool ) );
333 InputSlider *slider = new InputSlider( Qt::Horizontal, NULL );
335 /* Update the position when the IM has changed */
336 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
337 slider, setPosition( float, int, int ) );
338 /* And update the IM, when the position has changed */
339 CONNECT( slider, sliderDragged( float ),
340 THEMIM->getIM(), sliderUpdate( float ) );
345 widget = discFrame();
348 case TELETEXT_BUTTONS:
349 widget = telexFrame();
356 SoundWidget *snd = new SoundWidget( this, p_intf, b_shiny, b_special );
362 TimeLabel *timeLabel = new TimeLabel( p_intf );
368 QFrame *line = new QFrame;
369 line->setFrameShape( QFrame::VLine );
370 line->setFrameShadow( QFrame::Raised );
371 line->setLineWidth( 0 );
372 line->setMidLineWidth( 1 );
376 case ADVANCED_CONTROLLER:
378 advControls = new AdvControlsWidget( p_intf, this );
379 widget = advControls;
382 case REVERSE_BUTTON:{
383 QToolButton *reverseButton = new QToolButton;
384 setupButton( reverseButton );
385 CONNECT_MAP_SET( reverseButton, REVERSE_ACTION );
386 BUTTON_SET_BAR( reverseButton );
387 reverseButton->setCheckable( true );
388 /* You should, of COURSE change this to the correct event,
389 when/if we have one, that tells us if trickplay is possible . */
390 CONNECT( this, inputIsTrickPlayable( bool ), reverseButton, setVisible( bool ) );
391 reverseButton->setVisible( false );
392 widget = reverseButton;
395 case SKIP_BACK_BUTTON: {
396 QToolButton *skipBakButton = new QToolButton;
397 setupButton( skipBakButton );
398 CONNECT_MAP_SET( skipBakButton, SKIP_BACK_ACTION );
399 BUTTON_SET_BAR( skipBakButton );
400 ENABLE_ON_INPUT( skipBakButton );
401 widget = skipBakButton;
404 case SKIP_FW_BUTTON: {
405 QToolButton *skipFwButton = new QToolButton;
406 setupButton( skipFwButton );
407 CONNECT_MAP_SET( skipFwButton, SKIP_FW_ACTION );
408 BUTTON_SET_BAR( skipFwButton );
409 ENABLE_ON_INPUT( skipFwButton );
410 widget = skipFwButton;
414 QToolButton *quitButton = new QToolButton;
415 setupButton( quitButton );
416 CONNECT_MAP_SET( quitButton, QUIT_ACTION );
417 BUTTON_SET_BAR( quitButton );
422 msg_Warn( p_intf, "This should not happen %i", button );
426 /* Customize Buttons */
427 if( b_flat || b_big )
429 QToolButton *tmpButton = qobject_cast<QToolButton *>(widget);
433 tmpButton->setAutoRaise( b_flat );
436 tmpButton->setFixedSize( QSize( 32, 32 ) );
437 tmpButton->setIconSize( QSize( 26, 26 ) );
444 QFrame *AbstractController::discFrame()
446 /** Disc and Menus handling */
447 QFrame *discFrame = new QFrame( this );
449 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
450 discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );
452 QToolButton *prevSectionButton = new QToolButton( discFrame );
453 setupButton( prevSectionButton );
454 BUTTON_SET_BAR2( prevSectionButton, dvd_prev,
455 qtr("Previous Chapter/Title" ) );
456 discLayout->addWidget( prevSectionButton );
458 QToolButton *menuButton = new QToolButton( discFrame );
459 setupButton( menuButton );
460 discLayout->addWidget( menuButton );
461 BUTTON_SET_BAR2( menuButton, dvd_menu, qtr( "Menu" ) );
463 QToolButton *nextSectionButton = new QToolButton( discFrame );
464 setupButton( nextSectionButton );
465 discLayout->addWidget( nextSectionButton );
466 BUTTON_SET_BAR2( nextSectionButton, dvd_next,
467 qtr("Next Chapter/Title" ) );
469 /* Change the navigation button display when the IM
470 navigation changes */
471 CONNECT( THEMIM->getIM(), titleChanged( bool ),
472 discFrame, setVisible( bool ) );
473 CONNECT( THEMIM->getIM(), chapterChanged( bool ),
474 menuButton, setVisible( bool ) );
475 /* Changes the IM navigation when triggered on the nav buttons */
476 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
478 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
480 CONNECT( menuButton, clicked(), THEMIM->getIM(),
482 connect( THEMIM->getIM(), SIGNAL( titleChanged( bool ) ),
483 this, SIGNAL( sizeChanged() ) );
488 QFrame *AbstractController::telexFrame()
493 QFrame *telexFrame = new QFrame;
494 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
495 telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );
496 CONNECT( THEMIM->getIM(), teletextPossible( bool ),
497 telexFrame, setVisible( bool ) );
498 connect( THEMIM->getIM(), SIGNAL( teletextPossible( bool ) ),
499 this, SIGNAL( sizeChanged() ) );
502 QToolButton *telexOn = new QToolButton;
503 setupButton( telexOn );
504 BUTTON_SET_BAR2( telexOn, tv, qtr( "Teletext Activation" ) );
505 telexOn->setEnabled( false );
506 telexOn->setCheckable( true );
508 telexLayout->addWidget( telexOn );
510 /* Teletext Activation and set */
511 CONNECT( telexOn, clicked( bool ),
512 THEMIM->getIM(), activateTeletext( bool ) );
513 CONNECT( THEMIM->getIM(), teletextPossible( bool ),
514 telexOn, setEnabled( bool ) );
516 /* Transparency button */
517 QToolButton *telexTransparent = new QToolButton;
518 setupButton( telexTransparent );
519 BUTTON_SET_BAR2( telexTransparent, tvtelx,
520 qtr( "Toggle Transparency " ) );
521 telexTransparent->setEnabled( false );
522 telexTransparent->setCheckable( true );
523 telexLayout->addWidget( telexTransparent );
525 /* Transparency change and set */
526 CONNECT( telexTransparent, clicked( bool ),
527 THEMIM->getIM(), telexSetTransparency( bool ) );
528 CONNECT( THEMIM->getIM(), teletextTransparencyActivated( bool ),
529 telexTransparent, setChecked( bool ) );
533 QSpinBox *telexPage = new QSpinBox( telexFrame );
534 telexPage->setRange( 0, 999 );
535 telexPage->setValue( 100 );
536 telexPage->setAccelerated( true );
537 telexPage->setWrapping( true );
538 telexPage->setAlignment( Qt::AlignRight );
539 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
540 telexPage->setEnabled( false );
541 telexLayout->addWidget( telexPage );
543 /* Page change and set */
544 CONNECT( telexPage, valueChanged( int ),
545 THEMIM->getIM(), telexSetPage( int ) );
546 CONNECT( THEMIM->getIM(), newTelexPageSet( int ),
547 telexPage, setValue( int ) );
549 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexPage, setEnabled( bool ) );
550 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexTransparent, setEnabled( bool ) );
551 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexOn, setChecked( bool ) );
556 #undef CONNECT_MAP_SET
557 #undef BUTTON_SET_BAR
558 #undef ENABLE_ON_VIDEO
559 #undef ENABLE_ON_INPUT
561 #include <QHBoxLayout>
562 /*****************************
563 * DA Control Widget !
564 *****************************/
565 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
568 AbstractController( _p_i, _parent )
570 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
572 /* advanced Controls handling */
573 b_advancedVisible = b_advControls;
575 QVBoxLayout *controlLayout = new QVBoxLayout( this );
576 controlLayout->setLayoutMargins( 6, 4, 6, 2, 5 );
577 controlLayout->setSpacing( 0 );
578 QHBoxLayout *controlLayout1 = new QHBoxLayout;
579 controlLayout1->setSpacing( 0 );
581 QString line1 = getSettings()->value( "MainToolbar1", MAIN_TB1_DEFAULT )
583 parseAndCreate( line1, controlLayout1 );
585 QHBoxLayout *controlLayout2 = new QHBoxLayout;
586 controlLayout2->setSpacing( 0 );
587 QString line2 = getSettings()->value( "MainToolbar2", MAIN_TB2_DEFAULT )
589 parseAndCreate( line2, controlLayout2 );
591 if( !b_advancedVisible && advControls ) advControls->hide();
593 controlLayout->addLayout( controlLayout1 );
594 controlLayout->addLayout( controlLayout2 );
597 ControlsWidget::~ControlsWidget()
600 void ControlsWidget::toggleAdvanced()
602 if( !advControls ) return;
604 if( !b_advancedVisible )
607 b_advancedVisible = true;
612 b_advancedVisible = false;
614 emit advancedControlsToggled( b_advancedVisible );
617 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
618 AbstractController( _p_i, _parent )
620 controlLayout = new QHBoxLayout( this );
621 controlLayout->setMargin( 0 );
622 controlLayout->setSpacing( 0 );
624 QString line = getSettings()->value( "AdvToolbar", ADV_TB_DEFAULT )
626 parseAndCreate( line, controlLayout );
629 InputControlsWidget::InputControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
630 AbstractController( _p_i, _parent )
632 controlLayout = new QHBoxLayout( this );
633 controlLayout->setMargin( 0 );
634 controlLayout->setSpacing( 0 );
636 QString line = getSettings()->value( "InputToolbar", INPT_TB_DEFAULT ).toString();
637 parseAndCreate( line, controlLayout );
639 /**********************************************************************
640 * Fullscrenn control widget
641 **********************************************************************/
642 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i )
643 : AbstractController( _p_i )
647 b_mouse_over = false;
648 i_mouse_last_move_x = -1;
649 i_mouse_last_move_y = -1;
650 #if HAVE_TRANSPARENCY
651 b_slow_hide_begin = false;
652 i_slow_hide_timeout = 1;
654 b_fullscreen = false;
660 setWindowFlags( Qt::ToolTip );
661 setMinimumWidth( 600 );
663 setFrameShape( QFrame::StyledPanel );
664 setFrameStyle( QFrame::Sunken );
665 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
667 QVBoxLayout *controlLayout2 = new QVBoxLayout( this );
668 controlLayout2->setLayoutMargins( 5, 2, 5, 2, 5 );
671 InputControlsWidget *inputC = new InputControlsWidget( p_intf, this );
672 controlLayout2->addWidget( inputC );
674 controlLayout = new QHBoxLayout;
675 QString line = getSettings()->value( "MainWindow/FSCtoolbar", FSC_TB_DEFAULT ).toString();
676 parseAndCreate( line, controlLayout );
677 controlLayout2->addLayout( controlLayout );
680 p_hideTimer = new QTimer( this );
681 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
682 p_hideTimer->setSingleShot( true );
684 /* slow hiding timer */
685 #if HAVE_TRANSPARENCY
686 p_slowHideTimer = new QTimer( this );
687 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
690 adjustSize (); /* need to get real width and height for moving */
693 setWindowOpacity( 0.0 );
699 vlc_mutex_init_recursive( &lock );
701 CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ), this, setVoutList( vout_thread_t **, int ) );
704 FullscreenControllerWidget::~FullscreenControllerWidget()
706 getSettings()->setValue( "FullScreen/pos", pos() );
707 setVoutList( NULL, 0 );
708 vlc_mutex_destroy( &lock );
712 * Show fullscreen controller
714 void FullscreenControllerWidget::showFSC()
718 int number = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
719 if( number != i_screennumber ||
720 screenRes != QApplication::desktop()->screenGeometry(number) )
722 screenRes = QApplication::desktop()->screenGeometry(number);
723 msg_Dbg( p_intf, "Calculation fullscreen controllers center");
724 /* screen has changed, calculate new position */
725 QPoint pos = QPoint( screenRes.x() + (screenRes.width() / 2) - (width() / 2),
726 screenRes.y() + screenRes.height() - height());
728 i_screennumber = number;
731 // after quiting and going to fs, we need to call show()
737 setWindowOpacity( 1.0 );
743 #if HAVE_TRANSPARENCY
744 setWindowOpacity( DEFAULT_OPACITY );
749 * Hide fullscreen controller
750 * FIXME: under windows it have to be done by moving out of screen
751 * because hide() doesnt work
753 void FullscreenControllerWidget::hideFSC()
757 setWindowOpacity( 0.0 ); // simulate hidding
764 * Plane to hide fullscreen controller
766 void FullscreenControllerWidget::planHideFSC()
768 vlc_mutex_lock( &lock );
769 int i_timeout = i_hide_timeout;
770 vlc_mutex_unlock( &lock );
772 p_hideTimer->start( i_timeout );
774 #if HAVE_TRANSPARENCY
775 b_slow_hide_begin = true;
776 i_slow_hide_timeout = i_timeout;
777 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
782 * Hidding fullscreen controller slowly
783 * Linux: need composite manager
784 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
786 void FullscreenControllerWidget::slowHideFSC()
788 #if HAVE_TRANSPARENCY
789 if( b_slow_hide_begin )
791 b_slow_hide_begin = false;
793 p_slowHideTimer->stop();
794 /* the last part of time divided to 100 pieces */
795 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
801 if ( windowOpacity() > 0.0 && !b_fscHidden )
803 if ( windowOpacity() > 0.0 )
806 /* we should use 0.01 because of 100 pieces ^^^
807 but than it cannt be done in time */
808 setWindowOpacity( windowOpacity() - 0.02 );
811 if ( windowOpacity() <= 0.0 )
812 p_slowHideTimer->stop();
819 * events: show, hide, start timer for hidding
821 void FullscreenControllerWidget::customEvent( QEvent *event )
825 switch( event->type() )
827 case FullscreenControlToggle_Type:
828 vlc_mutex_lock( &lock );
830 vlc_mutex_unlock( &lock );
846 case FullscreenControlShow_Type:
847 vlc_mutex_lock( &lock );
849 vlc_mutex_unlock( &lock );
852 if( b_fs && b_fscHidden )
854 if( b_fs && !isVisible() )
858 case FullscreenControlHide_Type:
861 case FullscreenControlPlanHide_Type:
862 if( !b_mouse_over ) // Only if the mouse is not over FSC
874 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
876 if ( event->buttons() == Qt::LeftButton )
878 int i_moveX = event->globalX() - i_mouse_last_x;
879 int i_moveY = event->globalY() - i_mouse_last_y;
881 move( x() + i_moveX, y() + i_moveY );
883 i_mouse_last_x = event->globalX();
884 i_mouse_last_y = event->globalY();
890 * store position of cursor
892 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
894 i_mouse_last_x = event->globalX();
895 i_mouse_last_y = event->globalY();
899 * On mouse go above FSC
901 void FullscreenControllerWidget::enterEvent( QEvent *event )
906 #if HAVE_TRANSPARENCY
907 p_slowHideTimer->stop();
913 * On mouse go out from FSC
915 void FullscreenControllerWidget::leaveEvent( QEvent *event )
919 b_mouse_over = false;
924 * When you get pressed key, send it to video output
925 * FIXME: clearing focus by clearFocus() to not getting
926 * key press events didnt work
928 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
930 int i_vlck = qtEventToVLCKey( event );
933 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
941 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object,
942 const char *variable, vlc_value_t old_val,
943 vlc_value_t new_val, void *data )
945 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
947 msg_Dbg( p_vout, "Qt4: Fullscreen state changed" );
948 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
950 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
955 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
956 vlc_value_t old_val, vlc_value_t new_val,
959 vout_thread_t *p_vout = (vout_thread_t *)vlc_object;
960 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
962 /* Get the value from the Vout - Trust the vout more than Qt */
963 const int i_mousex = var_GetInteger( p_vout, "mouse-x" );
964 const int i_mousey = var_GetInteger( p_vout, "mouse-y" );
966 p_fs->mouseChanged( p_vout, i_mousex, i_mousey );
972 * It is call to update the list of vout handled by the fullscreen controller
974 void FullscreenControllerWidget::setVoutList( vout_thread_t **pp_vout, int i_vout )
976 QList<vout_thread_t*> del;
977 QList<vout_thread_t*> add;
979 QList<vout_thread_t*> set;
982 for( int i = 0; i < i_vout; i++ )
986 vlc_mutex_lock( &lock );
987 foreach( vout_thread_t *p_vout, vout )
989 if( !set.contains( p_vout ) )
992 vlc_mutex_unlock( &lock );
994 foreach( vout_thread_t *p_vout, del )
996 var_DelCallback( p_vout, "fullscreen",
997 FullscreenControllerWidgetFullscreenChanged, this );
998 vlc_mutex_lock( &lock );
999 fullscreenChanged( p_vout, false, 0 );
1000 vout.removeAll( p_vout );
1001 vlc_mutex_unlock( &lock );
1003 vlc_object_release( VLC_OBJECT(p_vout) );
1007 vlc_mutex_lock( &lock );
1008 foreach( vout_thread_t *p_vout, set )
1010 if( !vout.contains( p_vout ) )
1013 vlc_mutex_unlock( &lock );
1015 foreach( vout_thread_t *p_vout, add )
1017 vlc_object_hold( VLC_OBJECT(p_vout) );
1019 vlc_mutex_lock( &lock );
1020 vout.append( p_vout );
1021 var_AddCallback( p_vout, "fullscreen",
1022 FullscreenControllerWidgetFullscreenChanged, this );
1023 /* I miss a add and fire */
1024 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ),
1025 var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1026 vlc_mutex_unlock( &lock );
1030 * Register and unregister callback for mouse moving
1032 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout,
1033 bool b_fs, int i_timeout )
1035 /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
1036 msg_Dbg( p_vout, "Qt: Entering Fullscreen" );
1038 vlc_mutex_lock( &lock );
1039 /* Entering fullscreen, register callback */
1040 if( b_fs && !b_fullscreen )
1042 b_fullscreen = true;
1043 i_hide_timeout = i_timeout;
1044 var_AddCallback( p_vout, "mouse-moved",
1045 FullscreenControllerWidgetMouseMoved, this );
1047 /* Quitting fullscreen, unregistering callback */
1048 else if( !b_fs && b_fullscreen )
1050 b_fullscreen = false;
1051 i_hide_timeout = i_timeout;
1052 var_DelCallback( p_vout, "mouse-moved",
1053 FullscreenControllerWidgetMouseMoved, this );
1055 /* Force fs hidding */
1056 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1057 QApplication::postEvent( this, eHide );
1059 vlc_mutex_unlock( &lock );
1062 * Mouse change callback (show/hide the controller on mouse movement)
1064 void FullscreenControllerWidget::mouseChanged( vout_thread_t *p_vout, int i_mousex, int i_mousey )
1068 /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
1071 if( ( i_mouse_last_move_x == -1 || i_mouse_last_move_y == -1 ) ||
1072 ( abs( i_mouse_last_move_x - i_mousex ) > 2 ||
1073 abs( i_mouse_last_move_y - i_mousey ) > 2 ) )
1075 i_mouse_last_move_x = i_mousex;
1076 i_mouse_last_move_y = i_mousey;
1083 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1084 QApplication::postEvent( this, eShow );
1086 /* Plan hide event */
1087 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1088 QApplication::postEvent( this, eHide );