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 ) );
72 setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
75 /* Reemit some signals on status Change to activate some buttons */
76 void AbstractController::setStatus( int status )
78 bool b_hasInput = THEMIM->getIM()->hasInput();
79 /* Activate the interface buttons according to the presence of the input */
80 emit inputExists( b_hasInput );
82 emit inputPlaying( status == PLAYING_S );
84 emit inputIsRecordable( b_hasInput &&
85 var_GetBool( THEMIM->getInput(), "can-record" ) );
87 emit inputIsTrickPlayable( b_hasInput &&
88 var_GetBool( THEMIM->getInput(), "can-rewind" ) );
91 /* Generic button setup */
92 void AbstractController::setupButton( QAbstractButton *aButton )
94 static QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
95 sizePolicy.setHorizontalStretch( 0 );
96 sizePolicy.setVerticalStretch( 0 );
98 aButton->setSizePolicy( sizePolicy );
99 aButton->setFixedSize( QSize( 26, 26 ) );
100 aButton->setIconSize( QSize( 20, 20 ) );
101 aButton->setFocusPolicy( Qt::NoFocus );
104 /* Open the generic config line for the toolbar, parse it
105 * and create the widgets accordingly */
106 void AbstractController::parseAndCreate( const QString& config,
107 QBoxLayout *controlLayout )
109 QStringList list = config.split( ";", QString::SkipEmptyParts ) ;
110 for( int i = 0; i < list.size(); i++ )
112 QStringList list2 = list.at( i ).split( "-" );
113 if( list2.size() < 1 )
115 msg_Warn( p_intf, "Parsing error. Report this" );
120 int i_option = WIDGET_NORMAL;
121 buttonType_e i_type = (buttonType_e)list2.at( 0 ).toInt( &ok );
124 msg_Warn( p_intf, "Parsing error 0. Please report this" );
128 if( list2.size() > 1 )
130 i_option = list2.at( 1 ).toInt( &ok );
133 msg_Warn( p_intf, "Parsing error 1. Please report this" );
138 createAndAddWidget( controlLayout, -1, i_type, i_option );
142 void AbstractController::createAndAddWidget( QBoxLayout *controlLayout,
147 /* Special case for SPACERS, who aren't QWidgets */
148 if( i_type == WIDGET_SPACER )
150 controlLayout->insertSpacing( i_index, 12 );
154 if( i_type == WIDGET_SPACER_EXTEND )
156 controlLayout->insertStretch( i_index, 12 );
160 QWidget *widg = createWidget( i_type, i_option );
163 controlLayout->insertWidget( i_index, widg );
167 #define CONNECT_MAP( a ) CONNECT( a, clicked(), toolbarActionsMapper, map() )
168 #define SET_MAPPING( a, b ) toolbarActionsMapper->setMapping( a , b )
169 #define CONNECT_MAP_SET( a, b ) \
172 #define BUTTON_SET_BAR( a_button ) \
173 a_button->setToolTip( qtr( tooltipL[button] ) ); \
174 a_button->setIcon( QIcon( iconL[button] ) );
175 #define BUTTON_SET_BAR2( button, image, tooltip ) \
176 button->setToolTip( tooltip ); \
177 button->setIcon( QIcon( ":/"#image ) );
179 #define ENABLE_ON_VIDEO( a ) \
180 CONNECT( THEMIM->getIM(), voutChanged( bool ), a, setEnabled( bool ) ); \
181 a->setEnabled( THEMIM->getIM()->hasVideo() ); /* TODO: is this necessary? when input is started before the interface? */
183 #define ENABLE_ON_INPUT( a ) \
184 CONNECT( this, inputExists( bool ), a, setEnabled( bool ) ); \
185 a->setEnabled( THEMIM->getIM()->hasInput() ); /* TODO: is this necessary? when input is started before the interface? */
187 #define NORMAL_BUTTON( name ) \
188 QToolButton * name ## Button = new QToolButton; \
189 setupButton( name ## Button ); \
190 CONNECT_MAP_SET( name ## Button, name ## _ACTION ); \
191 BUTTON_SET_BAR( name ## Button ); \
192 widget = name ## Button;
194 QWidget *AbstractController::createWidget( buttonType_e button, int options )
197 bool b_flat = options & WIDGET_FLAT;
198 bool b_big = options & WIDGET_BIG;
199 bool b_shiny = options & WIDGET_SHINY;
200 bool b_special = false;
202 QWidget *widget = NULL;
206 PlayButton *playButton = new PlayButton;
207 setupButton( playButton );
208 BUTTON_SET_BAR( playButton );
209 CONNECT_MAP_SET( playButton, PLAY_ACTION );
210 CONNECT( this, inputPlaying( bool ),
211 playButton, updateButton( bool ));
216 NORMAL_BUTTON( STOP );
220 NORMAL_BUTTON( OPEN );
223 case PREVIOUS_BUTTON:{
224 NORMAL_BUTTON( PREVIOUS );
228 NORMAL_BUTTON( NEXT );
232 NORMAL_BUTTON( SLOWER );
233 ENABLE_ON_INPUT( SLOWERButton );
237 NORMAL_BUTTON( FASTER );
238 ENABLE_ON_INPUT( FASTERButton );
242 NORMAL_BUTTON( FRAME );
243 ENABLE_ON_VIDEO( FRAMEButton );
246 case FULLSCREEN_BUTTON:
247 case DEFULLSCREEN_BUTTON:
249 NORMAL_BUTTON( FULLSCREEN );
250 ENABLE_ON_VIDEO( FULLSCREENButton );
253 case EXTENDED_BUTTON:{
254 NORMAL_BUTTON( EXTENDED );
257 case PLAYLIST_BUTTON:{
258 NORMAL_BUTTON( PLAYLIST );
261 case SNAPSHOT_BUTTON:{
262 NORMAL_BUTTON( SNAPSHOT );
263 ENABLE_ON_VIDEO( SNAPSHOTButton );
267 QToolButton *recordButton = new QToolButton;
268 setupButton( recordButton );
269 CONNECT_MAP_SET( recordButton, RECORD_ACTION );
270 BUTTON_SET_BAR( recordButton );
271 ENABLE_ON_INPUT( recordButton );
272 recordButton->setCheckable( true );
273 CONNECT( THEMIM->getIM(), recordingStateChanged( bool ),
274 recordButton, setChecked( bool ) );
275 widget = recordButton;
279 AtoB_Button *ABButton = new AtoB_Button;
280 setupButton( ABButton );
281 ABButton->setShortcut( qtr("Shift+L") );
282 BUTTON_SET_BAR( ABButton );
283 ENABLE_ON_INPUT( ABButton );
284 CONNECT_MAP_SET( ABButton, ATOB_ACTION );
285 CONNECT( THEMIM->getIM(), AtoBchanged( bool, bool),
286 ABButton, setIcons( bool, bool ) );
291 InputSlider *slider = new InputSlider( Qt::Horizontal, NULL );
293 /* Update the position when the IM has changed */
294 CONNECT( THEMIM->getIM(), positionUpdated( float, int64_t, int ),
295 slider, setPosition( float, int64_t, int ) );
296 /* And update the IM, when the position has changed */
297 CONNECT( slider, sliderDragged( float ),
298 THEMIM->getIM(), sliderUpdate( float ) );
303 widget = discFrame();
306 case TELETEXT_BUTTONS:
307 widget = telexFrame();
314 SoundWidget *snd = new SoundWidget( this, p_intf, b_shiny, b_special );
320 TimeLabel *timeLabel = new TimeLabel( p_intf );
326 QFrame *line = new QFrame;
327 line->setFrameShape( QFrame::VLine );
328 line->setFrameShadow( QFrame::Raised );
329 line->setLineWidth( 0 );
330 line->setMidLineWidth( 1 );
334 case ADVANCED_CONTROLLER:
336 advControls = new AdvControlsWidget( p_intf, this );
337 widget = advControls;
340 case REVERSE_BUTTON:{
341 QToolButton *reverseButton = new QToolButton;
342 setupButton( reverseButton );
343 CONNECT_MAP_SET( reverseButton, REVERSE_ACTION );
344 BUTTON_SET_BAR( reverseButton );
345 reverseButton->setCheckable( true );
346 /* You should, of COURSE change this to the correct event,
347 when/if we have one, that tells us if trickplay is possible . */
348 CONNECT( this, inputIsTrickPlayable( bool ), reverseButton, setVisible( bool ) );
349 reverseButton->setVisible( false );
350 widget = reverseButton;
353 case SKIP_BACK_BUTTON: {
354 NORMAL_BUTTON( SKIP_BACK );
355 ENABLE_ON_INPUT( SKIP_BACKButton );
358 case SKIP_FW_BUTTON: {
359 NORMAL_BUTTON( SKIP_FW );
360 ENABLE_ON_INPUT( SKIP_FWButton );
364 NORMAL_BUTTON( QUIT );
367 case RANDOM_BUTTON: {
368 NORMAL_BUTTON( RANDOM );
369 RANDOMButton->setCheckable( true );
370 RANDOMButton->setChecked( var_GetBool( THEPL, "random" ) );
371 CONNECT( THEMIM, randomChanged( bool ),
372 RANDOMButton, setChecked( bool ) );
376 LoopButton *loopButton = new LoopButton;
377 setupButton( loopButton );
378 loopButton->setToolTip( qtr( "Click to toggle between loop one, loop all" ) );
379 loopButton->setCheckable( true );
380 loopButton->updateIcons( NORMAL );
381 CONNECT( THEMIM, repeatLoopChanged( int ), loopButton, updateIcons( int ) );
382 CONNECT( loopButton, clicked(), THEMIM, loopRepeatLoopStatus() );
387 NORMAL_BUTTON( INFO );
391 msg_Warn( p_intf, "This should not happen %i", button );
395 /* Customize Buttons */
396 if( b_flat || b_big )
398 QFrame *frame = qobject_cast<QFrame *>(widget);
401 QList<QToolButton *> allTButtons = frame->findChildren<QToolButton *>();
402 for( int i = 0; i < allTButtons.size(); i++ )
403 applyAttributes( allTButtons[i], b_flat, b_big );
407 QToolButton *tmpButton = qobject_cast<QToolButton *>(widget);
409 applyAttributes( tmpButton, b_flat, b_big );
416 void AbstractController::applyAttributes( QToolButton *tmpButton, bool b_flat, bool b_big )
421 tmpButton->setAutoRaise( b_flat );
424 tmpButton->setFixedSize( QSize( 32, 32 ) );
425 tmpButton->setIconSize( QSize( 26, 26 ) );
430 QFrame *AbstractController::discFrame()
432 /** Disc and Menus handling */
433 QFrame *discFrame = new QFrame( this );
435 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
436 discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );
438 QToolButton *prevSectionButton = new QToolButton( discFrame );
439 setupButton( prevSectionButton );
440 BUTTON_SET_BAR2( prevSectionButton, toolbar/dvd_prev,
441 qtr("Previous Chapter/Title" ) );
442 discLayout->addWidget( prevSectionButton );
444 QToolButton *menuButton = new QToolButton( discFrame );
445 setupButton( menuButton );
446 discLayout->addWidget( menuButton );
447 BUTTON_SET_BAR2( menuButton, toolbar/dvd_menu, qtr( "Menu" ) );
449 QToolButton *nextSectionButton = new QToolButton( discFrame );
450 setupButton( nextSectionButton );
451 discLayout->addWidget( nextSectionButton );
452 BUTTON_SET_BAR2( nextSectionButton, toolbar/dvd_next,
453 qtr("Next Chapter/Title" ) );
455 /* Change the navigation button display when the IM
456 navigation changes */
457 CONNECT( THEMIM->getIM(), titleChanged( bool ),
458 discFrame, setVisible( bool ) );
459 CONNECT( THEMIM->getIM(), chapterChanged( bool ),
460 menuButton, setVisible( bool ) );
461 /* Changes the IM navigation when triggered on the nav buttons */
462 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
464 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
466 CONNECT( menuButton, clicked(), THEMIM->getIM(),
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 ) );
484 QToolButton *telexOn = new QToolButton;
485 setupButton( telexOn );
486 BUTTON_SET_BAR2( telexOn, toolbar/tv, qtr( "Teletext Activation" ) );
487 telexOn->setEnabled( false );
488 telexOn->setCheckable( true );
490 telexLayout->addWidget( telexOn );
492 /* Teletext Activation and set */
493 CONNECT( telexOn, clicked( bool ),
494 THEMIM->getIM(), activateTeletext( bool ) );
495 CONNECT( THEMIM->getIM(), teletextPossible( bool ),
496 telexOn, setEnabled( bool ) );
498 /* Transparency button */
499 QToolButton *telexTransparent = new QToolButton;
500 setupButton( telexTransparent );
501 BUTTON_SET_BAR2( telexTransparent, toolbar/tvtelx,
502 qtr( "Toggle Transparency " ) );
503 telexTransparent->setEnabled( false );
504 telexTransparent->setCheckable( true );
505 telexLayout->addWidget( telexTransparent );
507 /* Transparency change and set */
508 CONNECT( telexTransparent, clicked( bool ),
509 THEMIM->getIM(), telexSetTransparency( bool ) );
510 CONNECT( THEMIM->getIM(), teletextTransparencyActivated( bool ),
511 telexTransparent, setChecked( bool ) );
515 QSpinBox *telexPage = new QSpinBox( telexFrame );
516 telexPage->setRange( 0, 999 );
517 telexPage->setValue( 100 );
518 telexPage->setAccelerated( true );
519 telexPage->setWrapping( true );
520 telexPage->setAlignment( Qt::AlignRight );
521 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
522 telexPage->setEnabled( false );
523 telexLayout->addWidget( telexPage );
525 /* Page change and set */
526 CONNECT( telexPage, valueChanged( int ),
527 THEMIM->getIM(), telexSetPage( int ) );
528 CONNECT( THEMIM->getIM(), newTelexPageSet( int ),
529 telexPage, setValue( int ) );
531 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexPage, setEnabled( bool ) );
532 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexTransparent, setEnabled( bool ) );
533 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexOn, setChecked( bool ) );
538 #undef CONNECT_MAP_SET
539 #undef BUTTON_SET_BAR
540 #undef BUTTON_SET_BAR2
541 #undef ENABLE_ON_VIDEO
542 #undef ENABLE_ON_INPUT
544 #include <QHBoxLayout>
545 /*****************************
546 * DA Control Widget !
547 *****************************/
548 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
551 AbstractController( _p_i, _parent )
553 /* advanced Controls handling */
554 b_advancedVisible = b_advControls;
556 setStyleSheet( " background: red ");
559 QVBoxLayout *controlLayout = new QVBoxLayout( this );
560 controlLayout->setContentsMargins( 4, 1, 4, 0 );
561 controlLayout->setSpacing( 0 );
562 QHBoxLayout *controlLayout1 = new QHBoxLayout;
563 controlLayout1->setSpacing( 0 ); controlLayout1->setMargin( 0 );
565 QString line1 = getSettings()->value( "MainToolbar1", MAIN_TB1_DEFAULT )
567 parseAndCreate( line1, controlLayout1 );
569 QHBoxLayout *controlLayout2 = new QHBoxLayout;
570 controlLayout2->setSpacing( 0 ); controlLayout2->setMargin( 0 );
571 QString line2 = getSettings()->value( "MainToolbar2", MAIN_TB2_DEFAULT )
573 parseAndCreate( line2, controlLayout2 );
575 if( !b_advancedVisible && advControls ) advControls->hide();
577 controlLayout->addLayout( controlLayout1 );
578 controlLayout->addLayout( controlLayout2 );
581 ControlsWidget::~ControlsWidget()
584 void ControlsWidget::toggleAdvanced()
586 if( !advControls ) return;
588 if( !b_advancedVisible )
591 b_advancedVisible = true;
596 b_advancedVisible = false;
598 emit advancedControlsToggled( b_advancedVisible );
601 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
602 AbstractController( _p_i, _parent )
604 controlLayout = new QHBoxLayout( this );
605 controlLayout->setMargin( 0 );
606 controlLayout->setSpacing( 0 );
608 setStyleSheet( " background: orange ");
612 QString line = getSettings()->value( "AdvToolbar", ADV_TB_DEFAULT )
614 parseAndCreate( line, controlLayout );
617 InputControlsWidget::InputControlsWidget( 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 setStyleSheet( " background: green ");
627 QString line = getSettings()->value( "InputToolbar", INPT_TB_DEFAULT ).toString();
628 parseAndCreate( line, controlLayout );
630 /**********************************************************************
631 * Fullscrenn control widget
632 **********************************************************************/
633 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i, QWidget *_parent )
634 : AbstractController( _p_i, _parent )
638 b_mouse_over = false;
639 i_mouse_last_move_x = -1;
640 i_mouse_last_move_y = -1;
641 #if HAVE_TRANSPARENCY
642 b_slow_hide_begin = false;
643 i_slow_hide_timeout = 1;
645 b_fullscreen = false;
651 setWindowFlags( Qt::ToolTip );
652 setMinimumWidth( 600 );
654 setFrameShape( QFrame::StyledPanel );
655 setFrameStyle( QFrame::Sunken );
656 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
658 QVBoxLayout *controlLayout2 = new QVBoxLayout( this );
659 controlLayout2->setContentsMargins( 4, 6, 4, 2 );
662 InputControlsWidget *inputC = new InputControlsWidget( p_intf, this );
663 controlLayout2->addWidget( inputC );
665 controlLayout = new QHBoxLayout;
666 QString line = getSettings()->value( "MainWindow/FSCtoolbar", FSC_TB_DEFAULT ).toString();
667 parseAndCreate( line, controlLayout );
668 controlLayout2->addLayout( controlLayout );
671 p_hideTimer = new QTimer( this );
672 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
673 p_hideTimer->setSingleShot( true );
675 /* slow hiding timer */
676 #if HAVE_TRANSPARENCY
677 p_slowHideTimer = new QTimer( this );
678 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
681 vlc_mutex_init_recursive( &lock );
683 DCONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
684 this, setVoutList( vout_thread_t **, int ) );
687 QRect rect1 = getSettings()->value( "FullScreen/screen" ).toRect();
688 QPoint pos1 = getSettings()->value( "FullScreen/pos" ).toPoint();
689 int number = var_InheritInteger( p_intf, "qt-fullscreen-screennumber" );
690 if( number == -1 || number > QApplication::desktop()->numScreens() )
691 number = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
693 QRect rect = QApplication::desktop()->screenGeometry( number );
694 if( rect == rect1 && rect.contains( pos1, true ) )
697 i_screennumber = number;
698 screenRes = QApplication::desktop()->screenGeometry(number);
707 FullscreenControllerWidget::~FullscreenControllerWidget()
710 QRect rect1 = QApplication::desktop()->screenGeometry( pos1 );
711 getSettings()->setValue( "FullScreen/pos", pos1 );
712 getSettings()->setValue( "FullScreen/screen", rect1 );
714 setVoutList( NULL, 0 );
715 vlc_mutex_destroy( &lock );
718 void FullscreenControllerWidget::centerFSC( int number )
720 screenRes = QApplication::desktop()->screenGeometry(number);
722 /* screen has changed, calculate new position */
723 QPoint pos = QPoint( screenRes.x() + (screenRes.width() / 2) - (sizeHint().width() / 2),
724 screenRes.y() + screenRes.height() - sizeHint().height());
727 i_screennumber = number;
731 * Show fullscreen controller
733 void FullscreenControllerWidget::showFSC()
737 int number = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
739 if( number != i_screennumber ||
740 screenRes != QApplication::desktop()->screenGeometry(number) )
743 msg_Dbg( p_intf, "Recentering the Fullscreen Controller" );
746 #if HAVE_TRANSPARENCY
747 setWindowOpacity( var_InheritFloat( p_intf, "qt-fs-opacity" ) );
754 * Plane to hide fullscreen controller
756 void FullscreenControllerWidget::planHideFSC()
758 vlc_mutex_lock( &lock );
759 int i_timeout = i_hide_timeout;
760 vlc_mutex_unlock( &lock );
762 p_hideTimer->start( i_timeout );
764 #if HAVE_TRANSPARENCY
765 b_slow_hide_begin = true;
766 i_slow_hide_timeout = i_timeout;
767 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
772 * Hidding fullscreen controller slowly
773 * Linux: need composite manager
774 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
776 void FullscreenControllerWidget::slowHideFSC()
778 #if HAVE_TRANSPARENCY
779 if( b_slow_hide_begin )
781 b_slow_hide_begin = false;
783 p_slowHideTimer->stop();
784 /* the last part of time divided to 100 pieces */
785 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
790 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 hiding
807 void FullscreenControllerWidget::customEvent( QEvent *event )
811 switch( event->type() )
813 /* This is used when the 'i' hotkey is used, to force quick toggle */
814 case FullscreenControlToggle_Type:
815 vlc_mutex_lock( &lock );
817 vlc_mutex_unlock( &lock );
830 /* Event called to Show the FSC on mouseChanged() */
831 case FullscreenControlShow_Type:
832 vlc_mutex_lock( &lock );
834 vlc_mutex_unlock( &lock );
840 /* Start the timer to hide later, called usually with above case */
841 case FullscreenControlPlanHide_Type:
842 if( !b_mouse_over ) // Only if the mouse is not over FSC
846 case FullscreenControlHide_Type:
858 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
860 if( event->buttons() == Qt::LeftButton )
862 if( i_mouse_last_x == -1 || i_mouse_last_y == -1 )
865 int i_moveX = event->globalX() - i_mouse_last_x;
866 int i_moveY = event->globalY() - i_mouse_last_y;
868 move( x() + i_moveX, y() + i_moveY );
870 i_mouse_last_x = event->globalX();
871 i_mouse_last_y = event->globalY();
877 * store position of cursor
879 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
881 i_mouse_last_x = event->globalX();
882 i_mouse_last_y = event->globalY();
886 void FullscreenControllerWidget::mouseReleaseEvent( QMouseEvent *event )
894 * On mouse go above FSC
896 void FullscreenControllerWidget::enterEvent( QEvent *event )
901 #if HAVE_TRANSPARENCY
902 p_slowHideTimer->stop();
903 setWindowOpacity( DEFAULT_OPACITY );
909 * On mouse go out from FSC
911 void FullscreenControllerWidget::leaveEvent( QEvent *event )
915 b_mouse_over = false;
920 * When you get pressed key, send it to video output
922 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
924 emit keyPressed( event );
928 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object,
929 const char *variable, vlc_value_t old_val,
930 vlc_value_t new_val, void *data )
932 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
934 msg_Dbg( p_vout, "Qt4: Fullscreen state changed" );
935 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
937 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
942 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
943 vlc_value_t old_val, vlc_value_t new_val,
946 vout_thread_t *p_vout = (vout_thread_t *)vlc_object;
947 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
949 /* Get the value from the Vout - Trust the vout more than Qt */
950 p_fs->mouseChanged( p_vout, new_val.coords.x, new_val.coords.y );
956 * It is call to update the list of vout handled by the fullscreen controller
958 void FullscreenControllerWidget::setVoutList( vout_thread_t **pp_vout, int i_vout )
960 QList<vout_thread_t*> del;
961 QList<vout_thread_t*> add;
963 QList<vout_thread_t*> set;
966 for( int i = 0; i < i_vout; i++ )
970 vlc_mutex_lock( &lock );
971 foreach( vout_thread_t *p_vout, vout )
973 if( !set.contains( p_vout ) )
976 vlc_mutex_unlock( &lock );
978 foreach( vout_thread_t *p_vout, del )
980 var_DelCallback( p_vout, "fullscreen",
981 FullscreenControllerWidgetFullscreenChanged, this );
982 vlc_mutex_lock( &lock );
983 fullscreenChanged( p_vout, false, 0 );
984 vout.removeAll( p_vout );
985 vlc_mutex_unlock( &lock );
987 vlc_object_release( VLC_OBJECT(p_vout) );
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(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 ? */
1021 vlc_mutex_lock( &lock );
1022 /* Entering fullscreen, register callback */
1023 if( b_fs && !b_fullscreen )
1025 msg_Dbg( p_vout, "Qt: Entering 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 msg_Dbg( p_vout, "Qt: Quitting Fullscreen" );
1035 b_fullscreen = false;
1036 i_hide_timeout = i_timeout;
1037 var_DelCallback( p_vout, "mouse-moved",
1038 FullscreenControllerWidgetMouseMoved, this );
1040 /* Force fs hiding */
1041 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1042 QApplication::postEvent( this, eHide );
1044 vlc_mutex_unlock( &lock );
1048 * Mouse change callback (show/hide the controller on mouse movement)
1050 void FullscreenControllerWidget::mouseChanged( vout_thread_t *p_vout, int i_mousex, int i_mousey )
1054 /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
1057 if( ( i_mouse_last_move_x == -1 || i_mouse_last_move_y == -1 ) ||
1058 ( abs( i_mouse_last_move_x - i_mousex ) > 2 ||
1059 abs( i_mouse_last_move_y - i_mousey ) > 2 ) )
1061 i_mouse_last_move_x = i_mousex;
1062 i_mouse_last_move_y = i_mousey;
1069 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1070 QApplication::postEvent( this, eShow );
1072 /* Plan hide event */
1073 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1074 QApplication::postEvent( this, eHide );