1 /*****************************************************************************
2 * Controller.cpp : Controller for the main interface
3 ****************************************************************************
4 * Copyright (C) 2006-2009 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 //#define DEBUG_LAYOUT 1
51 /**********************************************************************
53 **********************************************************************/
56 * This is an abstract Toolbar/Controller
57 * This has helper to create any toolbar, any buttons and to manage the actions
60 AbstractController::AbstractController( intf_thread_t * _p_i, QWidget *_parent )
66 /* Main action provider */
67 toolbarActionsMapper = new QSignalMapper( this );
68 CONNECT( toolbarActionsMapper, mapped( int ),
69 ActionsManager::getInstance( p_intf ), doAction( int ) );
70 CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
73 /* Reemit some signals on status Change to activate some buttons */
74 void AbstractController::setStatus( int status )
76 bool b_hasInput = THEMIM->getIM()->hasInput();
77 /* Activate the interface buttons according to the presence of the input */
78 emit inputExists( b_hasInput );
80 emit inputPlaying( status == PLAYING_S );
82 emit inputIsRecordable( b_hasInput &&
83 var_GetBool( THEMIM->getInput(), "can-record" ) );
85 emit inputIsTrickPlayable( b_hasInput &&
86 var_GetBool( THEMIM->getInput(), "can-rewind" ) );
89 /* Generic button setup */
90 void AbstractController::setupButton( QAbstractButton *aButton )
92 static QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
93 sizePolicy.setHorizontalStretch( 0 );
94 sizePolicy.setVerticalStretch( 0 );
96 aButton->setSizePolicy( sizePolicy );
97 aButton->setFixedSize( QSize( 26, 26 ) );
98 aButton->setIconSize( QSize( 20, 20 ) );
99 aButton->setFocusPolicy( Qt::NoFocus );
102 /* Open the generic config line for the toolbar, parse it
103 * and create the widgets accordingly */
104 void AbstractController::parseAndCreate( const QString& config,
105 QBoxLayout *controlLayout )
107 QStringList list = config.split( ";", QString::SkipEmptyParts ) ;
108 for( int i = 0; i < list.size(); i++ )
110 QStringList list2 = list.at( i ).split( "-" );
111 if( list2.size() < 1 )
113 msg_Warn( p_intf, "Parsing error. Report this" );
118 int i_option = WIDGET_NORMAL;
119 buttonType_e i_type = (buttonType_e)list2.at( 0 ).toInt( &ok );
122 msg_Warn( p_intf, "Parsing error 0. Please report this" );
126 if( list2.size() > 1 )
128 i_option = list2.at( 1 ).toInt( &ok );
131 msg_Warn( p_intf, "Parsing error 1. Please report this" );
136 createAndAddWidget( controlLayout, -1, i_type, i_option );
140 void AbstractController::createAndAddWidget( QBoxLayout *controlLayout,
145 /* Special case for SPACERS, who aren't QWidgets */
146 if( i_type == WIDGET_SPACER )
148 controlLayout->insertSpacing( i_index, 12 );
152 if( i_type == WIDGET_SPACER_EXTEND )
154 controlLayout->insertStretch( i_index, 12 );
158 QWidget *widg = createWidget( i_type, i_option );
161 controlLayout->insertWidget( i_index, widg );
165 #define CONNECT_MAP( a ) CONNECT( a, clicked(), toolbarActionsMapper, map() )
166 #define SET_MAPPING( a, b ) toolbarActionsMapper->setMapping( a , b )
167 #define CONNECT_MAP_SET( a, b ) \
170 #define BUTTON_SET_BAR( a_button ) \
171 a_button->setToolTip( qtr( tooltipL[button] ) ); \
172 a_button->setIcon( QIcon( iconL[button] ) );
173 #define BUTTON_SET_BAR2( button, image, tooltip ) \
174 button->setToolTip( tooltip ); \
175 button->setIcon( QIcon( ":/"#image ) );
177 #define ENABLE_ON_VIDEO( a ) \
178 CONNECT( THEMIM->getIM(), voutChanged( bool ), a, setEnabled( bool ) ); \
179 a->setEnabled( THEMIM->getIM()->hasVideo() ); /* TODO: is this necessary? when input is started before the interface? */
181 #define ENABLE_ON_INPUT( a ) \
182 CONNECT( this, inputExists( bool ), a, setEnabled( bool ) ); \
183 a->setEnabled( THEMIM->getIM()->hasInput() ); /* TODO: is this necessary? when input is started before the interface? */
185 #define NORMAL_BUTTON( name ) \
186 QToolButton * name ## Button = new QToolButton; \
187 setupButton( name ## Button ); \
188 CONNECT_MAP_SET( name ## Button, name ## _ACTION ); \
189 BUTTON_SET_BAR( name ## Button ); \
190 widget = name ## Button;
192 QWidget *AbstractController::createWidget( buttonType_e button, int options )
195 bool b_flat = options & WIDGET_FLAT;
196 bool b_big = options & WIDGET_BIG;
197 bool b_shiny = options & WIDGET_SHINY;
198 bool b_special = false;
200 QWidget *widget = NULL;
204 PlayButton *playButton = new PlayButton;
205 setupButton( playButton );
206 BUTTON_SET_BAR( playButton );
207 CONNECT_MAP_SET( playButton, PLAY_ACTION );
208 CONNECT( this, inputPlaying( bool ),
209 playButton, updateButton( bool ));
214 NORMAL_BUTTON( STOP );
218 NORMAL_BUTTON( OPEN );
221 case PREVIOUS_BUTTON:{
222 NORMAL_BUTTON( PREVIOUS );
226 NORMAL_BUTTON( NEXT );
230 NORMAL_BUTTON( SLOWER );
231 ENABLE_ON_INPUT( SLOWERButton );
235 NORMAL_BUTTON( FASTER );
236 ENABLE_ON_INPUT( FASTERButton );
240 NORMAL_BUTTON( FRAME );
241 ENABLE_ON_VIDEO( FRAMEButton );
244 case FULLSCREEN_BUTTON:
245 case DEFULLSCREEN_BUTTON:
247 NORMAL_BUTTON( FULLSCREEN );
248 ENABLE_ON_VIDEO( FULLSCREENButton );
251 case EXTENDED_BUTTON:{
252 NORMAL_BUTTON( EXTENDED );
255 case PLAYLIST_BUTTON:{
256 NORMAL_BUTTON( PLAYLIST );
259 case SNAPSHOT_BUTTON:{
260 NORMAL_BUTTON( SNAPSHOT );
261 ENABLE_ON_VIDEO( SNAPSHOTButton );
265 QToolButton *recordButton = new QToolButton;
266 setupButton( recordButton );
267 CONNECT_MAP_SET( recordButton, RECORD_ACTION );
268 BUTTON_SET_BAR( recordButton );
269 ENABLE_ON_INPUT( recordButton );
270 recordButton->setCheckable( true );
271 CONNECT( THEMIM->getIM(), recordingStateChanged( bool ),
272 recordButton, setChecked( bool ) );
273 widget = recordButton;
277 AtoB_Button *ABButton = new AtoB_Button;
278 setupButton( ABButton );
279 ABButton->setShortcut( qtr("Shift+L") );
280 BUTTON_SET_BAR( ABButton );
281 ENABLE_ON_INPUT( ABButton );
282 CONNECT_MAP_SET( ABButton, ATOB_ACTION );
283 CONNECT( THEMIM->getIM(), AtoBchanged( bool, bool),
284 ABButton, setIcons( bool, bool ) );
289 InputSlider *slider = new InputSlider( Qt::Horizontal, NULL );
291 /* Update the position when the IM has changed */
292 CONNECT( THEMIM->getIM(), positionUpdated( float, int64_t, int ),
293 slider, setPosition( float, int64_t, int ) );
294 /* And update the IM, when the position has changed */
295 CONNECT( slider, sliderDragged( float ),
296 THEMIM->getIM(), sliderUpdate( float ) );
301 widget = discFrame();
304 case TELETEXT_BUTTONS:
305 widget = telexFrame();
312 SoundWidget *snd = new SoundWidget( this, p_intf, b_shiny, b_special );
318 TimeLabel *timeLabel = new TimeLabel( p_intf );
324 QFrame *line = new QFrame;
325 line->setFrameShape( QFrame::VLine );
326 line->setFrameShadow( QFrame::Raised );
327 line->setLineWidth( 0 );
328 line->setMidLineWidth( 1 );
332 case ADVANCED_CONTROLLER:
334 advControls = new AdvControlsWidget( p_intf, this );
335 widget = advControls;
338 case REVERSE_BUTTON:{
339 QToolButton *reverseButton = new QToolButton;
340 setupButton( reverseButton );
341 CONNECT_MAP_SET( reverseButton, REVERSE_ACTION );
342 BUTTON_SET_BAR( reverseButton );
343 reverseButton->setCheckable( true );
344 /* You should, of COURSE change this to the correct event,
345 when/if we have one, that tells us if trickplay is possible . */
346 CONNECT( this, inputIsTrickPlayable( bool ), reverseButton, setVisible( bool ) );
347 reverseButton->setVisible( false );
348 widget = reverseButton;
351 case SKIP_BACK_BUTTON: {
352 NORMAL_BUTTON( SKIP_BACK );
353 ENABLE_ON_INPUT( SKIP_BACKButton );
356 case SKIP_FW_BUTTON: {
357 NORMAL_BUTTON( SKIP_FW );
358 ENABLE_ON_INPUT( SKIP_FWButton );
362 NORMAL_BUTTON( QUIT );
365 case RANDOM_BUTTON: {
366 NORMAL_BUTTON( RANDOM );
367 RANDOMButton->setCheckable( true );
368 RANDOMButton->setChecked( var_GetBool( THEPL, "random" ) );
369 CONNECT( THEMIM, randomChanged( bool ),
370 RANDOMButton, setChecked( bool ) );
374 LoopButton *loopButton = new LoopButton;
375 setupButton( loopButton );
376 loopButton->setToolTip( qtr( "Click to toggle between loop one, loop all" ) );
377 loopButton->setCheckable( true );
378 loopButton->updateIcons( NORMAL );
379 CONNECT( THEMIM, repeatLoopChanged( int ), loopButton, updateIcons( int ) );
380 CONNECT( loopButton, clicked(), THEMIM, loopRepeatLoopStatus() );
385 NORMAL_BUTTON( INFO );
389 msg_Warn( p_intf, "This should not happen %i", button );
393 /* Customize Buttons */
394 if( b_flat || b_big )
396 QFrame *frame = qobject_cast<QFrame *>(widget);
399 QList<QToolButton *> allTButtons = frame->findChildren<QToolButton *>();
400 for( int i = 0; i < allTButtons.size(); i++ )
401 applyAttributes( allTButtons[i], b_flat, b_big );
405 QToolButton *tmpButton = qobject_cast<QToolButton *>(widget);
407 applyAttributes( tmpButton, b_flat, b_big );
414 void AbstractController::applyAttributes( QToolButton *tmpButton, bool b_flat, bool b_big )
419 tmpButton->setAutoRaise( b_flat );
422 tmpButton->setFixedSize( QSize( 32, 32 ) );
423 tmpButton->setIconSize( QSize( 26, 26 ) );
428 QFrame *AbstractController::discFrame()
430 /** Disc and Menus handling */
431 QFrame *discFrame = new QFrame( this );
433 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
434 discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );
436 QToolButton *prevSectionButton = new QToolButton( discFrame );
437 setupButton( prevSectionButton );
438 BUTTON_SET_BAR2( prevSectionButton, toolbar/dvd_prev,
439 qtr("Previous Chapter/Title" ) );
440 discLayout->addWidget( prevSectionButton );
442 QToolButton *menuButton = new QToolButton( discFrame );
443 setupButton( menuButton );
444 discLayout->addWidget( menuButton );
445 BUTTON_SET_BAR2( menuButton, toolbar/dvd_menu, qtr( "Menu" ) );
447 QToolButton *nextSectionButton = new QToolButton( discFrame );
448 setupButton( nextSectionButton );
449 discLayout->addWidget( nextSectionButton );
450 BUTTON_SET_BAR2( nextSectionButton, toolbar/dvd_next,
451 qtr("Next Chapter/Title" ) );
453 /* Change the navigation button display when the IM
454 navigation changes */
455 CONNECT( THEMIM->getIM(), titleChanged( bool ),
456 discFrame, setVisible( bool ) );
457 CONNECT( THEMIM->getIM(), chapterChanged( bool ),
458 menuButton, setVisible( bool ) );
459 /* Changes the IM navigation when triggered on the nav buttons */
460 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
462 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
464 CONNECT( menuButton, clicked(), THEMIM->getIM(),
466 connect( THEMIM->getIM(), SIGNAL( titleChanged( bool ) ),
467 this, SIGNAL( sizeChanged() ) );
472 QFrame *AbstractController::telexFrame()
477 QFrame *telexFrame = new QFrame( this );
478 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
479 telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );
480 CONNECT( THEMIM->getIM(), teletextPossible( bool ),
481 telexFrame, setVisible( bool ) );
482 connect( THEMIM->getIM(), SIGNAL( teletextPossible( bool ) ),
483 this, SIGNAL( sizeChanged() ) );
486 QToolButton *telexOn = new QToolButton;
487 setupButton( telexOn );
488 BUTTON_SET_BAR2( telexOn, toolbar/tv, qtr( "Teletext Activation" ) );
489 telexOn->setEnabled( false );
490 telexOn->setCheckable( true );
492 telexLayout->addWidget( telexOn );
494 /* Teletext Activation and set */
495 CONNECT( telexOn, clicked( bool ),
496 THEMIM->getIM(), activateTeletext( bool ) );
497 CONNECT( THEMIM->getIM(), teletextPossible( bool ),
498 telexOn, setEnabled( bool ) );
500 /* Transparency button */
501 QToolButton *telexTransparent = new QToolButton;
502 setupButton( telexTransparent );
503 BUTTON_SET_BAR2( telexTransparent, toolbar/tvtelx,
504 qtr( "Toggle Transparency " ) );
505 telexTransparent->setEnabled( false );
506 telexTransparent->setCheckable( true );
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 telexTransparent, setChecked( bool ) );
517 QSpinBox *telexPage = new QSpinBox( telexFrame );
518 telexPage->setRange( 0, 999 );
519 telexPage->setValue( 100 );
520 telexPage->setAccelerated( true );
521 telexPage->setWrapping( true );
522 telexPage->setAlignment( Qt::AlignRight );
523 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
524 telexPage->setEnabled( false );
525 telexLayout->addWidget( telexPage );
527 /* Page change and set */
528 CONNECT( telexPage, valueChanged( int ),
529 THEMIM->getIM(), telexSetPage( int ) );
530 CONNECT( THEMIM->getIM(), newTelexPageSet( int ),
531 telexPage, setValue( int ) );
533 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexPage, setEnabled( bool ) );
534 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexTransparent, setEnabled( bool ) );
535 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexOn, setChecked( bool ) );
540 #undef CONNECT_MAP_SET
541 #undef BUTTON_SET_BAR
542 #undef BUTTON_SET_BAR2
543 #undef ENABLE_ON_VIDEO
544 #undef ENABLE_ON_INPUT
546 #include <QHBoxLayout>
547 /*****************************
548 * DA Control Widget !
549 *****************************/
550 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
553 AbstractController( _p_i, _parent )
555 /* advanced Controls handling */
556 b_advancedVisible = b_advControls;
558 setStyleSheet( " background: red ");
561 QVBoxLayout *controlLayout = new QVBoxLayout( this );
562 controlLayout->setContentsMargins( 4, 1, 4, 0 );
563 controlLayout->setSpacing( 0 );
564 QHBoxLayout *controlLayout1 = new QHBoxLayout;
565 controlLayout1->setSpacing( 0 ); controlLayout1->setMargin( 0 );
567 QString line1 = getSettings()->value( "MainToolbar1", MAIN_TB1_DEFAULT )
569 parseAndCreate( line1, controlLayout1 );
571 QHBoxLayout *controlLayout2 = new QHBoxLayout;
572 controlLayout2->setSpacing( 0 ); controlLayout2->setMargin( 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 setStyleSheet( " background: orange ");
614 QString line = getSettings()->value( "AdvToolbar", ADV_TB_DEFAULT )
616 parseAndCreate( line, controlLayout );
619 InputControlsWidget::InputControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
620 AbstractController( _p_i, _parent )
622 controlLayout = new QHBoxLayout( this );
623 controlLayout->setMargin( 0 );
624 controlLayout->setSpacing( 0 );
626 setStyleSheet( " background: green ");
629 QString line = getSettings()->value( "InputToolbar", INPT_TB_DEFAULT ).toString();
630 parseAndCreate( line, controlLayout );
632 /**********************************************************************
633 * Fullscrenn control widget
634 **********************************************************************/
635 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i, QWidget *_parent )
636 : AbstractController( _p_i, _parent )
640 b_mouse_over = false;
641 i_mouse_last_move_x = -1;
642 i_mouse_last_move_y = -1;
643 #if HAVE_TRANSPARENCY
644 b_slow_hide_begin = false;
645 i_slow_hide_timeout = 1;
647 b_fullscreen = false;
653 setWindowFlags( Qt::ToolTip );
654 setMinimumWidth( 600 );
656 setFrameShape( QFrame::StyledPanel );
657 setFrameStyle( QFrame::Sunken );
658 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
660 QVBoxLayout *controlLayout2 = new QVBoxLayout( this );
661 controlLayout2->setContentsMargins( 4, 6, 4, 2 );
664 InputControlsWidget *inputC = new InputControlsWidget( p_intf, this );
665 controlLayout2->addWidget( inputC );
667 controlLayout = new QHBoxLayout;
668 QString line = getSettings()->value( "MainWindow/FSCtoolbar", FSC_TB_DEFAULT ).toString();
669 parseAndCreate( line, controlLayout );
670 controlLayout2->addLayout( controlLayout );
673 p_hideTimer = new QTimer( this );
674 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
675 p_hideTimer->setSingleShot( true );
677 /* slow hiding timer */
678 #if HAVE_TRANSPARENCY
679 p_slowHideTimer = new QTimer( this );
680 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
683 vlc_mutex_init_recursive( &lock );
685 CONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
686 this, setVoutList( vout_thread_t **, int ) );
689 QRect rect1 = getSettings()->value( "FullScreen/screen" ).toRect();
690 QPoint pos1 = getSettings()->value( "FullScreen/pos" ).toPoint();
691 int number = var_InheritInteger( p_intf, "qt-fullscreen-screennumber" );
692 if( number == -1 || number > QApplication::desktop()->numScreens() )
693 number = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
695 QRect rect = QApplication::desktop()->screenGeometry( number );
696 if( rect == rect1 && rect.contains( pos1, true ) )
699 i_screennumber = number;
700 screenRes = QApplication::desktop()->screenGeometry(number);
709 FullscreenControllerWidget::~FullscreenControllerWidget()
712 QRect rect1 = QApplication::desktop()->screenGeometry( pos1 );
713 getSettings()->setValue( "FullScreen/pos", pos1 );
714 getSettings()->setValue( "FullScreen/screen", rect1 );
716 setVoutList( NULL, 0 );
717 vlc_mutex_destroy( &lock );
720 void FullscreenControllerWidget::centerFSC( int number )
722 screenRes = QApplication::desktop()->screenGeometry(number);
724 /* screen has changed, calculate new position */
725 QPoint pos = QPoint( screenRes.x() + (screenRes.width() / 2) - (sizeHint().width() / 2),
726 screenRes.y() + screenRes.height() - sizeHint().height());
729 i_screennumber = number;
733 * Show fullscreen controller
735 void FullscreenControllerWidget::showFSC()
739 int number = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
741 if( number != i_screennumber ||
742 screenRes != QApplication::desktop()->screenGeometry(number) )
745 msg_Dbg( p_intf, "Recentering the Fullscreen Controller" );
748 #if HAVE_TRANSPARENCY
749 setWindowOpacity( var_InheritFloat( p_intf, "qt-fs-opacity" ) );
756 * Plane to hide fullscreen controller
758 void FullscreenControllerWidget::planHideFSC()
760 vlc_mutex_lock( &lock );
761 int i_timeout = i_hide_timeout;
762 vlc_mutex_unlock( &lock );
764 p_hideTimer->start( i_timeout );
766 #if HAVE_TRANSPARENCY
767 b_slow_hide_begin = true;
768 i_slow_hide_timeout = i_timeout;
769 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
774 * Hidding fullscreen controller slowly
775 * Linux: need composite manager
776 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
778 void FullscreenControllerWidget::slowHideFSC()
780 #if HAVE_TRANSPARENCY
781 if( b_slow_hide_begin )
783 b_slow_hide_begin = false;
785 p_slowHideTimer->stop();
786 /* the last part of time divided to 100 pieces */
787 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
792 if ( windowOpacity() > 0.0 )
794 /* we should use 0.01 because of 100 pieces ^^^
795 but than it cannt be done in time */
796 setWindowOpacity( windowOpacity() - 0.02 );
799 if ( windowOpacity() <= 0.0 )
800 p_slowHideTimer->stop();
807 * events: show, hide, start timer for hidding
809 void FullscreenControllerWidget::customEvent( QEvent *event )
813 switch( event->type() )
815 /* This is used when the 'i' hotkey is used, to force quick toggle */
816 case FullscreenControlToggle_Type:
817 vlc_mutex_lock( &lock );
819 vlc_mutex_unlock( &lock );
832 /* Event called to Show the FSC on mouseChanged() */
833 case FullscreenControlShow_Type:
834 vlc_mutex_lock( &lock );
836 vlc_mutex_unlock( &lock );
842 /* Start the timer to hide later, called usually with above case */
843 case FullscreenControlPlanHide_Type:
844 if( !b_mouse_over ) // Only if the mouse is not over FSC
848 case FullscreenControlHide_Type:
860 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
862 if( event->buttons() == Qt::LeftButton )
864 if( i_mouse_last_x == -1 || i_mouse_last_y == -1 )
867 int i_moveX = event->globalX() - i_mouse_last_x;
868 int i_moveY = event->globalY() - i_mouse_last_y;
870 move( x() + i_moveX, y() + i_moveY );
872 i_mouse_last_x = event->globalX();
873 i_mouse_last_y = event->globalY();
879 * store position of cursor
881 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
883 i_mouse_last_x = event->globalX();
884 i_mouse_last_y = event->globalY();
888 void FullscreenControllerWidget::mouseReleaseEvent( QMouseEvent *event )
896 * On mouse go above FSC
898 void FullscreenControllerWidget::enterEvent( QEvent *event )
903 #if HAVE_TRANSPARENCY
904 p_slowHideTimer->stop();
905 setWindowOpacity( DEFAULT_OPACITY );
911 * On mouse go out from FSC
913 void FullscreenControllerWidget::leaveEvent( QEvent *event )
917 b_mouse_over = false;
922 * When you get pressed key, send it to video output
924 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
926 emit keyPressed( event );
930 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object,
931 const char *variable, vlc_value_t old_val,
932 vlc_value_t new_val, void *data )
934 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
936 msg_Dbg( p_vout, "Qt4: Fullscreen state changed" );
937 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
939 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
944 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
945 vlc_value_t old_val, vlc_value_t new_val,
948 vout_thread_t *p_vout = (vout_thread_t *)vlc_object;
949 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
951 /* Get the value from the Vout - Trust the vout more than Qt */
952 p_fs->mouseChanged( p_vout, new_val.coords.x, new_val.coords.y );
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 );
989 vlc_object_release( VLC_OBJECT(p_vout) );
993 vlc_mutex_lock( &lock );
994 foreach( vout_thread_t *p_vout, set )
996 if( !vout.contains( p_vout ) )
999 vlc_mutex_unlock( &lock );
1001 foreach( vout_thread_t *p_vout, add )
1003 vlc_object_hold( VLC_OBJECT(p_vout) );
1005 vlc_mutex_lock( &lock );
1006 vout.append( p_vout );
1007 var_AddCallback( p_vout, "fullscreen",
1008 FullscreenControllerWidgetFullscreenChanged, this );
1009 /* I miss a add and fire */
1010 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ),
1011 var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1012 vlc_mutex_unlock( &lock );
1016 * Register and unregister callback for mouse moving
1018 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout,
1019 bool b_fs, int i_timeout )
1021 /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
1022 msg_Dbg( p_vout, "Qt: Entering Fullscreen" );
1024 vlc_mutex_lock( &lock );
1025 /* Entering fullscreen, register callback */
1026 if( b_fs && !b_fullscreen )
1028 b_fullscreen = true;
1029 i_hide_timeout = i_timeout;
1030 var_AddCallback( p_vout, "mouse-moved",
1031 FullscreenControllerWidgetMouseMoved, this );
1033 /* Quitting fullscreen, unregistering callback */
1034 else if( !b_fs && b_fullscreen )
1036 b_fullscreen = false;
1037 i_hide_timeout = i_timeout;
1038 var_DelCallback( p_vout, "mouse-moved",
1039 FullscreenControllerWidgetMouseMoved, this );
1041 /* Force fs hidding */
1042 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1043 QApplication::postEvent( this, eHide );
1045 vlc_mutex_unlock( &lock );
1049 * Mouse change callback (show/hide the controller on mouse movement)
1051 void FullscreenControllerWidget::mouseChanged( vout_thread_t *p_vout, int i_mousex, int i_mousey )
1055 /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
1058 if( ( i_mouse_last_move_x == -1 || i_mouse_last_move_y == -1 ) ||
1059 ( abs( i_mouse_last_move_x - i_mousex ) > 2 ||
1060 abs( i_mouse_last_move_y - i_mousey ) > 2 ) )
1062 i_mouse_last_move_x = i_mousex;
1063 i_mouse_last_move_y = i_mousey;
1070 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1071 QApplication::postEvent( this, eShow );
1073 /* Plan hide event */
1074 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1075 QApplication::postEvent( this, eHide );