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 *****************************************************************************/
29 #include <vlc_vout.h> /* vout_thread_t for FSC */
32 #include "components/controller.hpp"
33 #include "components/controller_widget.hpp"
34 #include "components/interface_widgets.hpp"
35 #include "util/buttons/DeckButtonsLayout.hpp"
36 #include "util/buttons/BrowseButton.hpp"
37 #include "util/buttons/RoundButton.hpp"
39 #include "dialogs_provider.hpp" /* Opening Dialogs */
40 #include "actions_manager.hpp" /* *_ACTION */
42 #include "util/input_slider.hpp" /* SeekSlider */
43 #include "util/customwidgets.hpp" /* qEventToKey */
45 #include <QToolButton>
46 #include <QHBoxLayout>
48 #include <QSignalMapper>
51 //#define DEBUG_LAYOUT 1
53 /**********************************************************************
55 **********************************************************************/
58 * This is an abstract Toolbar/Controller
59 * This has helper to create any toolbar, any buttons and to manage the actions
62 AbstractController::AbstractController( intf_thread_t * _p_i, QWidget *_parent )
67 buttonGroupLayout = NULL;
69 /* Main action provider */
70 toolbarActionsMapper = new QSignalMapper( this );
71 CONNECT( toolbarActionsMapper, mapped( int ),
72 ActionsManager::getInstance( p_intf ), doAction( int ) );
73 CONNECT( THEMIM->getIM(), playingStatusChanged( int ), this, setStatus( int ) );
75 setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
78 /* Reemit some signals on status Change to activate some buttons */
79 void AbstractController::setStatus( int status )
81 bool b_hasInput = THEMIM->getIM()->hasInput();
82 /* Activate the interface buttons according to the presence of the input */
83 emit inputExists( b_hasInput );
85 emit inputPlaying( status == PLAYING_S );
87 emit inputIsRecordable( b_hasInput &&
88 var_GetBool( THEMIM->getInput(), "can-record" ) );
90 emit inputIsTrickPlayable( b_hasInput &&
91 var_GetBool( THEMIM->getInput(), "can-rewind" ) );
94 /* Generic button setup */
95 void AbstractController::setupButton( QAbstractButton *aButton )
97 static QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
98 sizePolicy.setHorizontalStretch( 0 );
99 sizePolicy.setVerticalStretch( 0 );
101 aButton->setSizePolicy( sizePolicy );
102 aButton->setFixedSize( QSize( 26, 26 ) );
103 aButton->setIconSize( QSize( 20, 20 ) );
104 aButton->setFocusPolicy( Qt::NoFocus );
107 /* Open the generic config line for the toolbar, parse it
108 * and create the widgets accordingly */
109 void AbstractController::parseAndCreate( const QString& config,
110 QBoxLayout *controlLayout )
112 QStringList list = config.split( ";", QString::SkipEmptyParts ) ;
113 for( int i = 0; i < list.size(); i++ )
115 QStringList list2 = list.at( i ).split( "-" );
116 if( list2.size() < 1 )
118 msg_Warn( p_intf, "Parsing error 1. Please, report this." );
123 int i_option = WIDGET_NORMAL;
124 buttonType_e i_type = (buttonType_e)list2.at( 0 ).toInt( &ok );
127 msg_Warn( p_intf, "Parsing error 2. Please report this." );
131 if( list2.size() > 1 )
133 i_option = list2.at( 1 ).toInt( &ok );
136 msg_Warn( p_intf, "Parsing error 3. Please, report this." );
140 createAndAddWidget( controlLayout, -1, i_type, i_option );
143 if( buttonGroupLayout )
145 controlLayout->addLayout( buttonGroupLayout );
146 buttonGroupLayout = NULL;
150 void AbstractController::createAndAddWidget( QBoxLayout *controlLayout,
155 VLC_UNUSED( i_index ); // i_index should only be required for edition
157 /* Close the current buttonGroup if we have a special widget or a spacer */
158 if( buttonGroupLayout && i_type > BUTTON_MAX )
160 controlLayout->addLayout( buttonGroupLayout );
161 buttonGroupLayout = NULL;
164 /* Special case for SPACERS, who aren't QWidgets */
165 if( i_type == WIDGET_SPACER )
167 controlLayout->addSpacing( 12 );
169 else if( i_type == WIDGET_SPACER_EXTEND )
171 controlLayout->addStretch( 12 );
175 /* Create the widget */
176 QWidget *widg = createWidget( i_type, i_option );
180 if( i_type < BUTTON_MAX )
182 if( !buttonGroupLayout )
184 buttonGroupLayout = new QHBoxLayout;
187 buttonGroupLayout->addWidget( widg );
189 else /* Special widgets */
191 controlLayout->addWidget( widg );
197 #define CONNECT_MAP( a ) CONNECT( a, clicked(), toolbarActionsMapper, map() )
198 #define SET_MAPPING( a, b ) toolbarActionsMapper->setMapping( a , b )
199 #define CONNECT_MAP_SET( a, b ) \
202 #define BUTTON_SET_BAR( a_button ) \
203 a_button->setToolTip( qtr( tooltipL[button] ) ); \
204 a_button->setIcon( QIcon( iconL[button] ) );
205 #define BUTTON_SET_BAR2( button, image, tooltip ) \
206 button->setToolTip( tooltip ); \
207 button->setIcon( QIcon( ":/"#image ) );
209 #define ENABLE_ON_VIDEO( a ) \
210 CONNECT( THEMIM->getIM(), voutChanged( bool ), a, setEnabled( bool ) ); \
211 a->setEnabled( THEMIM->getIM()->hasVideo() ); /* TODO: is this necessary? when input is started before the interface? */
213 #define ENABLE_ON_INPUT( a ) \
214 CONNECT( this, inputExists( bool ), a, setEnabled( bool ) ); \
215 a->setEnabled( THEMIM->getIM()->hasInput() ); /* TODO: is this necessary? when input is started before the interface? */
217 #define NORMAL_BUTTON( name ) \
218 QToolButton * name ## Button = new QToolButton; \
219 setupButton( name ## Button ); \
220 CONNECT_MAP_SET( name ## Button, name ## _ACTION ); \
221 BUTTON_SET_BAR( name ## Button ); \
222 widget = name ## Button;
224 QWidget *AbstractController::createWidget( buttonType_e button, int options )
226 bool b_flat = options & WIDGET_FLAT;
227 bool b_big = options & WIDGET_BIG;
228 bool b_shiny = options & WIDGET_SHINY;
229 bool b_special = false;
231 QWidget *widget = NULL;
235 PlayButton *playButton = new PlayButton;
236 setupButton( playButton );
237 BUTTON_SET_BAR( playButton );
238 CONNECT_MAP_SET( playButton, PLAY_ACTION );
239 CONNECT( this, inputPlaying( bool ),
240 playButton, updateButtonIcons( bool ));
245 NORMAL_BUTTON( STOP );
249 NORMAL_BUTTON( OPEN );
252 case PREVIOUS_BUTTON:{
253 NORMAL_BUTTON( PREVIOUS );
257 NORMAL_BUTTON( NEXT );
261 NORMAL_BUTTON( SLOWER );
262 ENABLE_ON_INPUT( SLOWERButton );
266 NORMAL_BUTTON( FASTER );
267 ENABLE_ON_INPUT( FASTERButton );
270 case PREV_SLOW_BUTTON:{
271 QToolButtonExt *but = new QToolButtonExt;
273 BUTTON_SET_BAR( but );
274 CONNECT( but, shortClicked(), THEMIM, prev() );
275 CONNECT( but, longClicked(), THEAM, skipBackward() );
279 case NEXT_FAST_BUTTON:{
280 QToolButtonExt *but = new QToolButtonExt;
282 BUTTON_SET_BAR( but );
283 CONNECT( but, shortClicked(), THEMIM, next() );
284 CONNECT( but, longClicked(), THEAM, skipForward() );
289 NORMAL_BUTTON( FRAME );
290 ENABLE_ON_VIDEO( FRAMEButton );
293 case FULLSCREEN_BUTTON:
294 case DEFULLSCREEN_BUTTON:
296 NORMAL_BUTTON( FULLSCREEN );
297 ENABLE_ON_VIDEO( FULLSCREENButton );
300 case EXTENDED_BUTTON:{
301 NORMAL_BUTTON( EXTENDED );
304 case PLAYLIST_BUTTON:{
305 NORMAL_BUTTON( PLAYLIST );
308 case SNAPSHOT_BUTTON:{
309 NORMAL_BUTTON( SNAPSHOT );
310 ENABLE_ON_VIDEO( SNAPSHOTButton );
314 QToolButton *recordButton = new QToolButton;
315 setupButton( recordButton );
316 CONNECT_MAP_SET( recordButton, RECORD_ACTION );
317 BUTTON_SET_BAR( recordButton );
318 ENABLE_ON_INPUT( recordButton );
319 recordButton->setCheckable( true );
320 CONNECT( THEMIM->getIM(), recordingStateChanged( bool ),
321 recordButton, setChecked( bool ) );
322 widget = recordButton;
326 AtoB_Button *ABButton = new AtoB_Button;
327 setupButton( ABButton );
328 ABButton->setShortcut( qtr("Shift+L") );
329 BUTTON_SET_BAR( ABButton );
330 ENABLE_ON_INPUT( ABButton );
331 CONNECT_MAP_SET( ABButton, ATOB_ACTION );
332 CONNECT( THEMIM->getIM(), AtoBchanged( bool, bool),
333 ABButton, updateButtonIcons( bool, bool ) );
338 SeekSlider *slider = new SeekSlider( Qt::Horizontal, NULL );
340 /* Update the position when the IM has changed */
341 CONNECT( THEMIM->getIM(), positionUpdated( float, int64_t, int ),
342 slider, setPosition( float, int64_t, int ) );
343 /* And update the IM, when the position has changed */
344 CONNECT( slider, sliderDragged( float ),
345 THEMIM->getIM(), sliderUpdate( float ) );
350 widget = discFrame();
353 case TELETEXT_BUTTONS:
354 widget = telexFrame();
361 SoundWidget *snd = new SoundWidget( this, p_intf, b_shiny, b_special );
367 TimeLabel *timeLabel = new TimeLabel( p_intf );
373 QFrame *line = new QFrame;
374 line->setFrameShape( QFrame::VLine );
375 line->setFrameShadow( QFrame::Raised );
376 line->setLineWidth( 0 );
377 line->setMidLineWidth( 1 );
381 case ADVANCED_CONTROLLER:
383 advControls = new AdvControlsWidget( p_intf, this );
384 widget = advControls;
387 case REVERSE_BUTTON:{
388 QToolButton *reverseButton = new QToolButton;
389 setupButton( reverseButton );
390 CONNECT_MAP_SET( reverseButton, REVERSE_ACTION );
391 BUTTON_SET_BAR( reverseButton );
392 reverseButton->setCheckable( true );
393 /* You should, of COURSE change this to the correct event,
394 when/if we have one, that tells us if trickplay is possible . */
395 CONNECT( this, inputIsTrickPlayable( bool ), reverseButton, setVisible( bool ) );
396 reverseButton->setVisible( false );
397 widget = reverseButton;
400 case SKIP_BACK_BUTTON: {
401 NORMAL_BUTTON( SKIP_BACK );
402 ENABLE_ON_INPUT( SKIP_BACKButton );
405 case SKIP_FW_BUTTON: {
406 NORMAL_BUTTON( SKIP_FW );
407 ENABLE_ON_INPUT( SKIP_FWButton );
411 NORMAL_BUTTON( QUIT );
414 case RANDOM_BUTTON: {
415 NORMAL_BUTTON( RANDOM );
416 RANDOMButton->setCheckable( true );
417 RANDOMButton->setChecked( var_GetBool( THEPL, "random" ) );
418 CONNECT( THEMIM, randomChanged( bool ),
419 RANDOMButton, setChecked( bool ) );
423 LoopButton *loopButton = new LoopButton;
424 setupButton( loopButton );
425 loopButton->setToolTip( qtr( "Click to toggle between loop one, loop all" ) );
426 loopButton->setCheckable( true );
427 loopButton->updateButtonIcons( NORMAL );
428 CONNECT( THEMIM, repeatLoopChanged( int ), loopButton, updateButtonIcons( int ) );
429 CONNECT( loopButton, clicked(), THEMIM, loopRepeatLoopStatus() );
434 NORMAL_BUTTON( INFO );
437 case PLAYBACK_BUTTONS:{
438 widget = new QWidget;
439 DeckButtonsLayout *layout = new DeckButtonsLayout( widget );
440 BrowseButton *prev = new BrowseButton( widget, BrowseButton::Backward );
441 BrowseButton *next = new BrowseButton( widget );
442 RoundButton *play = new RoundButton( widget );
443 layout->setBackwardButton( prev );
444 layout->setForwardButton( next );
445 layout->setRoundButton( play );
446 CONNECT_MAP_SET( prev, PREVIOUS_ACTION );
447 CONNECT_MAP_SET( next, NEXT_ACTION );
448 CONNECT_MAP_SET( play, PLAY_ACTION );
452 msg_Warn( p_intf, "This should not happen %i", button );
456 /* Customize Buttons */
457 if( b_flat || b_big )
459 QFrame *frame = qobject_cast<QFrame *>(widget);
462 QList<QToolButton *> allTButtons = frame->findChildren<QToolButton *>();
463 for( int i = 0; i < allTButtons.size(); i++ )
464 applyAttributes( allTButtons[i], b_flat, b_big );
468 QToolButton *tmpButton = qobject_cast<QToolButton *>(widget);
470 applyAttributes( tmpButton, b_flat, b_big );
477 void AbstractController::applyAttributes( QToolButton *tmpButton, bool b_flat, bool b_big )
482 tmpButton->setAutoRaise( b_flat );
485 tmpButton->setFixedSize( QSize( 32, 32 ) );
486 tmpButton->setIconSize( QSize( 26, 26 ) );
491 QFrame *AbstractController::discFrame()
493 /** Disc and Menus handling */
494 QFrame *discFrame = new QFrame( this );
496 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
497 discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );
499 QToolButton *prevSectionButton = new QToolButton( discFrame );
500 setupButton( prevSectionButton );
501 BUTTON_SET_BAR2( prevSectionButton, toolbar/dvd_prev,
502 qtr("Previous Chapter/Title" ) );
503 discLayout->addWidget( prevSectionButton );
505 QToolButton *menuButton = new QToolButton( discFrame );
506 setupButton( menuButton );
507 discLayout->addWidget( menuButton );
508 BUTTON_SET_BAR2( menuButton, toolbar/dvd_menu, qtr( "Menu" ) );
510 QToolButton *nextSectionButton = new QToolButton( discFrame );
511 setupButton( nextSectionButton );
512 discLayout->addWidget( nextSectionButton );
513 BUTTON_SET_BAR2( nextSectionButton, toolbar/dvd_next,
514 qtr("Next Chapter/Title" ) );
516 /* Change the navigation button display when the IM
517 navigation changes */
518 CONNECT( THEMIM->getIM(), titleChanged( bool ),
519 discFrame, setVisible( bool ) );
520 CONNECT( THEMIM->getIM(), chapterChanged( bool ),
521 menuButton, setVisible( bool ) );
522 /* Changes the IM navigation when triggered on the nav buttons */
523 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
525 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
527 CONNECT( menuButton, clicked(), THEMIM->getIM(),
533 QFrame *AbstractController::telexFrame()
538 QFrame *telexFrame = new QFrame( this );
539 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
540 telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );
541 CONNECT( THEMIM->getIM(), teletextPossible( bool ),
542 telexFrame, setVisible( bool ) );
545 QToolButton *telexOn = new QToolButton;
546 setupButton( telexOn );
547 BUTTON_SET_BAR2( telexOn, toolbar/tv, qtr( "Teletext Activation" ) );
548 telexOn->setEnabled( false );
549 telexOn->setCheckable( true );
551 telexLayout->addWidget( telexOn );
553 /* Teletext Activation and set */
554 CONNECT( telexOn, clicked( bool ),
555 THEMIM->getIM(), activateTeletext( bool ) );
556 CONNECT( THEMIM->getIM(), teletextPossible( bool ),
557 telexOn, setEnabled( bool ) );
559 /* Transparency button */
560 QToolButton *telexTransparent = new QToolButton;
561 setupButton( telexTransparent );
562 BUTTON_SET_BAR2( telexTransparent, toolbar/tvtelx,
563 qtr( "Toggle Transparency " ) );
564 telexTransparent->setEnabled( false );
565 telexTransparent->setCheckable( true );
566 telexLayout->addWidget( telexTransparent );
568 /* Transparency change and set */
569 CONNECT( telexTransparent, clicked( bool ),
570 THEMIM->getIM(), telexSetTransparency( bool ) );
571 CONNECT( THEMIM->getIM(), teletextTransparencyActivated( bool ),
572 telexTransparent, setChecked( bool ) );
576 QSpinBox *telexPage = new QSpinBox( telexFrame );
577 telexPage->setRange( 0, 999 );
578 telexPage->setValue( 100 );
579 telexPage->setAccelerated( true );
580 telexPage->setWrapping( true );
581 telexPage->setAlignment( Qt::AlignRight );
582 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
583 telexPage->setEnabled( false );
584 telexLayout->addWidget( telexPage );
586 /* Page change and set */
587 CONNECT( telexPage, valueChanged( int ),
588 THEMIM->getIM(), telexSetPage( int ) );
589 CONNECT( THEMIM->getIM(), newTelexPageSet( int ),
590 telexPage, setValue( int ) );
592 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexPage, setEnabled( bool ) );
593 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexTransparent, setEnabled( bool ) );
594 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexOn, setChecked( bool ) );
599 #undef CONNECT_MAP_SET
600 #undef BUTTON_SET_BAR
601 #undef BUTTON_SET_BAR2
602 #undef ENABLE_ON_VIDEO
603 #undef ENABLE_ON_INPUT
605 #include <QHBoxLayout>
606 /*****************************
607 * DA Control Widget !
608 *****************************/
609 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
612 AbstractController( _p_i, _parent )
614 /* advanced Controls handling */
615 b_advancedVisible = b_advControls;
617 setStyleSheet( "background: red ");
620 setAttribute( Qt::WA_MacBrushedMetal);
621 QVBoxLayout *controlLayout = new QVBoxLayout( this );
622 controlLayout->setContentsMargins( 4, 1, 0, 0 );
623 controlLayout->setSpacing( 0 );
624 QHBoxLayout *controlLayout1 = new QHBoxLayout;
625 controlLayout1->setSpacing( 0 ); controlLayout1->setMargin( 0 );
627 QString line1 = getSettings()->value( "MainToolbar1", MAIN_TB1_DEFAULT )
629 parseAndCreate( line1, controlLayout1 );
631 QHBoxLayout *controlLayout2 = new QHBoxLayout;
632 controlLayout2->setSpacing( 0 ); controlLayout2->setMargin( 0 );
633 QString line2 = getSettings()->value( "MainToolbar2", MAIN_TB2_DEFAULT )
635 parseAndCreate( line2, controlLayout2 );
637 grip = new QSizeGrip( this );
638 controlLayout2->addWidget( grip, 0, Qt::AlignBottom|Qt::AlignRight );
640 if( !b_advancedVisible && advControls ) advControls->hide();
642 controlLayout->addLayout( controlLayout1 );
643 controlLayout->addLayout( controlLayout2 );
646 void ControlsWidget::toggleAdvanced()
648 if( !advControls ) return;
650 if( !b_advancedVisible )
653 b_advancedVisible = true;
658 b_advancedVisible = false;
660 emit advancedControlsToggled( b_advancedVisible );
663 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
664 AbstractController( _p_i, _parent )
666 controlLayout = new QHBoxLayout( this );
667 controlLayout->setMargin( 0 );
668 controlLayout->setSpacing( 0 );
670 setStyleSheet( "background: orange ");
674 QString line = getSettings()->value( "AdvToolbar", ADV_TB_DEFAULT )
676 parseAndCreate( line, controlLayout );
679 InputControlsWidget::InputControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
680 AbstractController( _p_i, _parent )
682 controlLayout = new QHBoxLayout( this );
683 controlLayout->setMargin( 0 );
684 controlLayout->setSpacing( 0 );
686 setStyleSheet( "background: green ");
689 QString line = getSettings()->value( "InputToolbar", INPT_TB_DEFAULT ).toString();
690 parseAndCreate( line, controlLayout );
692 /**********************************************************************
693 * Fullscrenn control widget
694 **********************************************************************/
695 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i, QWidget *_parent )
696 : AbstractController( _p_i, _parent )
700 b_mouse_over = false;
701 i_mouse_last_move_x = -1;
702 i_mouse_last_move_y = -1;
703 #if HAVE_TRANSPARENCY
704 b_slow_hide_begin = false;
705 i_slow_hide_timeout = 1;
707 b_fullscreen = false;
714 setWindowFlags( Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint );
715 setWindowModality( Qt::ApplicationModal );
717 setWindowFlags( Qt::ToolTip );
719 setMinimumWidth( 600 );
721 setFrameShape( QFrame::StyledPanel );
722 setFrameStyle( QFrame::Sunken );
723 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
725 QVBoxLayout *controlLayout2 = new QVBoxLayout( this );
726 controlLayout2->setContentsMargins( 4, 6, 4, 2 );
729 InputControlsWidget *inputC = new InputControlsWidget( p_intf, this );
730 controlLayout2->addWidget( inputC );
732 controlLayout = new QHBoxLayout;
733 QString line = getSettings()->value( "MainWindow/FSCtoolbar", FSC_TB_DEFAULT ).toString();
734 parseAndCreate( line, controlLayout );
735 controlLayout2->addLayout( controlLayout );
738 p_hideTimer = new QTimer( this );
739 p_hideTimer->setSingleShot( true );
740 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
742 /* slow hiding timer */
743 #if HAVE_TRANSPARENCY
744 p_slowHideTimer = new QTimer( this );
745 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
748 vlc_mutex_init_recursive( &lock );
750 DCONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
751 this, setVoutList( vout_thread_t **, int ) );
754 QRect rect1 = getSettings()->value( "FullScreen/screen" ).toRect();
755 QPoint pos1 = getSettings()->value( "FullScreen/pos" ).toPoint();
756 int number = var_InheritInteger( p_intf, "qt-fullscreen-screennumber" );
757 if( number == -1 || number > QApplication::desktop()->numScreens() )
758 number = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
760 QRect rect = QApplication::desktop()->screenGeometry( number );
761 if( rect == rect1 && rect.contains( pos1, true ) )
764 i_screennumber = number;
765 screenRes = QApplication::desktop()->screenGeometry(number);
774 FullscreenControllerWidget::~FullscreenControllerWidget()
777 QRect rect1 = QApplication::desktop()->screenGeometry( pos1 );
778 getSettings()->setValue( "FullScreen/pos", pos1 );
779 getSettings()->setValue( "FullScreen/screen", rect1 );
781 setVoutList( NULL, 0 );
782 vlc_mutex_destroy( &lock );
785 void FullscreenControllerWidget::centerFSC( int number )
787 screenRes = QApplication::desktop()->screenGeometry(number);
789 /* screen has changed, calculate new position */
790 QPoint pos = QPoint( screenRes.x() + (screenRes.width() / 2) - (sizeHint().width() / 2),
791 screenRes.y() + screenRes.height() - sizeHint().height());
794 i_screennumber = number;
798 * Show fullscreen controller
800 void FullscreenControllerWidget::showFSC()
804 int number = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
806 if( number != i_screennumber ||
807 screenRes != QApplication::desktop()->screenGeometry(number) )
810 msg_Dbg( p_intf, "Recentering the Fullscreen Controller" );
813 #if HAVE_TRANSPARENCY
814 setWindowOpacity( var_InheritFloat( p_intf, "qt-fs-opacity" ) );
818 // Tell kwin that we do not want a shadow around the fscontroller
819 setMask( QRegion( 0, 0, width(), height() ) );
826 * Plane to hide fullscreen controller
828 void FullscreenControllerWidget::planHideFSC()
830 vlc_mutex_lock( &lock );
831 int i_timeout = i_hide_timeout;
832 vlc_mutex_unlock( &lock );
834 p_hideTimer->start( i_timeout );
836 #if HAVE_TRANSPARENCY
837 b_slow_hide_begin = true;
838 i_slow_hide_timeout = i_timeout;
839 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
844 * Hidding fullscreen controller slowly
845 * Linux: need composite manager
846 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
848 void FullscreenControllerWidget::slowHideFSC()
850 #if HAVE_TRANSPARENCY
851 if( b_slow_hide_begin )
853 b_slow_hide_begin = false;
855 p_slowHideTimer->stop();
856 /* the last part of time divided to 100 pieces */
857 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
862 if ( windowOpacity() > 0.0 )
864 /* we should use 0.01 because of 100 pieces ^^^
865 but than it cannt be done in time */
866 setWindowOpacity( windowOpacity() - 0.02 );
869 if ( windowOpacity() <= 0.0 )
870 p_slowHideTimer->stop();
877 * events: show, hide, start timer for hiding
879 void FullscreenControllerWidget::customEvent( QEvent *event )
883 switch( event->type() )
885 /* This is used when the 'i' hotkey is used, to force quick toggle */
886 case FullscreenControlToggle_Type:
887 vlc_mutex_lock( &lock );
889 vlc_mutex_unlock( &lock );
902 /* Event called to Show the FSC on mouseChanged() */
903 case FullscreenControlShow_Type:
904 vlc_mutex_lock( &lock );
906 vlc_mutex_unlock( &lock );
912 /* Start the timer to hide later, called usually with above case */
913 case FullscreenControlPlanHide_Type:
914 if( !b_mouse_over ) // Only if the mouse is not over FSC
918 case FullscreenControlHide_Type:
930 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
932 if( event->buttons() == Qt::LeftButton )
934 if( i_mouse_last_x == -1 || i_mouse_last_y == -1 )
937 int i_moveX = event->globalX() - i_mouse_last_x;
938 int i_moveY = event->globalY() - i_mouse_last_y;
940 move( x() + i_moveX, y() + i_moveY );
942 i_mouse_last_x = event->globalX();
943 i_mouse_last_y = event->globalY();
949 * store position of cursor
951 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
953 i_mouse_last_x = event->globalX();
954 i_mouse_last_y = event->globalY();
958 void FullscreenControllerWidget::mouseReleaseEvent( QMouseEvent *event )
966 * On mouse go above FSC
968 void FullscreenControllerWidget::enterEvent( QEvent *event )
973 #if HAVE_TRANSPARENCY
974 p_slowHideTimer->stop();
975 setWindowOpacity( DEFAULT_OPACITY );
981 * On mouse go out from FSC
983 void FullscreenControllerWidget::leaveEvent( QEvent *event )
987 b_mouse_over = false;
992 * When you get pressed key, send it to video output
994 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
996 emit keyPressed( event );
1000 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object,
1001 const char *variable, vlc_value_t old_val,
1002 vlc_value_t new_val, void *data )
1004 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1006 msg_Dbg( p_vout, "Qt4: Fullscreen state changed" );
1007 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1009 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1014 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1015 vlc_value_t old_val, vlc_value_t new_val,
1018 vout_thread_t *p_vout = (vout_thread_t *)vlc_object;
1019 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1021 /* Get the value from the Vout - Trust the vout more than Qt */
1022 p_fs->mouseChanged( p_vout, new_val.coords.x, new_val.coords.y );
1028 * It is call to update the list of vout handled by the fullscreen controller
1030 void FullscreenControllerWidget::setVoutList( vout_thread_t **pp_vout, int i_vout )
1032 QList<vout_thread_t*> del;
1033 QList<vout_thread_t*> add;
1035 QList<vout_thread_t*> set;
1038 for( int i = 0; i < i_vout; i++ )
1041 /* Vout to remove */
1042 vlc_mutex_lock( &lock );
1043 foreach( vout_thread_t *p_vout, vout )
1045 if( !set.contains( p_vout ) )
1048 vlc_mutex_unlock( &lock );
1050 foreach( vout_thread_t *p_vout, del )
1052 var_DelCallback( p_vout, "fullscreen",
1053 FullscreenControllerWidgetFullscreenChanged, this );
1054 vlc_mutex_lock( &lock );
1055 fullscreenChanged( p_vout, false, 0 );
1056 vout.removeAll( p_vout );
1057 vlc_mutex_unlock( &lock );
1059 vlc_object_release( VLC_OBJECT(p_vout) );
1063 vlc_mutex_lock( &lock );
1064 foreach( vout_thread_t *p_vout, set )
1066 if( !vout.contains( p_vout ) )
1069 vlc_mutex_unlock( &lock );
1071 foreach( vout_thread_t *p_vout, add )
1073 vlc_object_hold( VLC_OBJECT(p_vout) );
1075 vlc_mutex_lock( &lock );
1076 vout.append( p_vout );
1077 var_AddCallback( p_vout, "fullscreen",
1078 FullscreenControllerWidgetFullscreenChanged, this );
1079 /* I miss a add and fire */
1080 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ),
1081 var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1082 vlc_mutex_unlock( &lock );
1086 * Register and unregister callback for mouse moving
1088 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout,
1089 bool b_fs, int i_timeout )
1091 /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
1093 vlc_mutex_lock( &lock );
1094 /* Entering fullscreen, register callback */
1095 if( b_fs && !b_fullscreen )
1097 msg_Dbg( p_vout, "Qt: Entering Fullscreen" );
1098 b_fullscreen = true;
1099 i_hide_timeout = i_timeout;
1100 var_AddCallback( p_vout, "mouse-moved",
1101 FullscreenControllerWidgetMouseMoved, this );
1103 /* Quitting fullscreen, unregistering callback */
1104 else if( !b_fs && b_fullscreen )
1106 msg_Dbg( p_vout, "Qt: Quitting Fullscreen" );
1107 b_fullscreen = false;
1108 i_hide_timeout = i_timeout;
1109 var_DelCallback( p_vout, "mouse-moved",
1110 FullscreenControllerWidgetMouseMoved, this );
1112 /* Force fs hiding */
1113 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1114 QApplication::postEvent( this, eHide );
1116 vlc_mutex_unlock( &lock );
1120 * Mouse change callback (show/hide the controller on mouse movement)
1122 void FullscreenControllerWidget::mouseChanged( vout_thread_t *p_vout, int i_mousex, int i_mousey )
1126 /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
1129 if( ( i_mouse_last_move_x == -1 || i_mouse_last_move_y == -1 ) ||
1130 ( abs( i_mouse_last_move_x - i_mousex ) > 2 ||
1131 abs( i_mouse_last_move_y - i_mousey ) > 2 ) )
1133 i_mouse_last_move_x = i_mousex;
1134 i_mouse_last_move_y = i_mousey;
1141 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1142 QApplication::postEvent( this, eShow );
1144 /* Plan hide event */
1145 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1146 QApplication::postEvent( this, eHide );