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 "adapters/seekpoints.hpp"
47 #include <QToolButton>
48 #include <QHBoxLayout>
50 #include <QSignalMapper>
53 //#define DEBUG_LAYOUT 1
55 /**********************************************************************
57 **********************************************************************/
60 * This is an abstract Toolbar/Controller
61 * This has helper to create any toolbar, any buttons and to manage the actions
64 AbstractController::AbstractController( intf_thread_t * _p_i, QWidget *_parent )
69 buttonGroupLayout = NULL;
71 /* Main action provider */
72 toolbarActionsMapper = new QSignalMapper( this );
73 CONNECT( toolbarActionsMapper, mapped( int ),
74 ActionsManager::getInstance( p_intf ), doAction( int ) );
75 CONNECT( THEMIM->getIM(), playingStatusChanged( int ), this, setStatus( int ) );
77 setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
80 /* Reemit some signals on status Change to activate some buttons */
81 void AbstractController::setStatus( int status )
83 bool b_hasInput = THEMIM->getIM()->hasInput();
84 /* Activate the interface buttons according to the presence of the input */
85 emit inputExists( b_hasInput );
87 emit inputPlaying( status == PLAYING_S );
89 emit inputIsRecordable( b_hasInput &&
90 var_GetBool( THEMIM->getInput(), "can-record" ) );
92 emit inputIsTrickPlayable( b_hasInput &&
93 var_GetBool( THEMIM->getInput(), "can-rewind" ) );
96 /* Generic button setup */
97 void AbstractController::setupButton( QAbstractButton *aButton )
99 static QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
100 sizePolicy.setHorizontalStretch( 0 );
101 sizePolicy.setVerticalStretch( 0 );
103 aButton->setSizePolicy( sizePolicy );
104 aButton->setFixedSize( QSize( 26, 26 ) );
105 aButton->setIconSize( QSize( 20, 20 ) );
106 aButton->setFocusPolicy( Qt::NoFocus );
109 /* Open the generic config line for the toolbar, parse it
110 * and create the widgets accordingly */
111 void AbstractController::parseAndCreate( const QString& config,
112 QBoxLayout *controlLayout )
114 QStringList list = config.split( ";", QString::SkipEmptyParts ) ;
115 for( int i = 0; i < list.count(); i++ )
117 QStringList list2 = list.at( i ).split( "-" );
118 if( list2.count() < 1 )
120 msg_Warn( p_intf, "Parsing error 1. Please, report this." );
125 int i_option = WIDGET_NORMAL;
126 buttonType_e i_type = (buttonType_e)list2.at( 0 ).toInt( &ok );
129 msg_Warn( p_intf, "Parsing error 2. Please report this." );
133 if( list2.count() > 1 )
135 i_option = list2.at( 1 ).toInt( &ok );
138 msg_Warn( p_intf, "Parsing error 3. Please, report this." );
143 createAndAddWidget( controlLayout, -1, i_type, i_option );
146 if( buttonGroupLayout )
148 controlLayout->addLayout( buttonGroupLayout );
149 buttonGroupLayout = NULL;
153 void AbstractController::createAndAddWidget( QBoxLayout *controlLayout,
158 VLC_UNUSED( i_index ); // i_index should only be required for edition
160 /* Close the current buttonGroup if we have a special widget or a spacer */
161 if( buttonGroupLayout && i_type > BUTTON_MAX )
163 controlLayout->addLayout( buttonGroupLayout );
164 buttonGroupLayout = NULL;
167 /* Special case for SPACERS, who aren't QWidgets */
168 if( i_type == WIDGET_SPACER )
170 controlLayout->addSpacing( 12 );
172 else if( i_type == WIDGET_SPACER_EXTEND )
174 controlLayout->addStretch( 12 );
178 /* Create the widget */
179 QWidget *widg = createWidget( i_type, i_option );
183 if( i_type < BUTTON_MAX )
185 if( !buttonGroupLayout )
187 buttonGroupLayout = new QHBoxLayout;
190 buttonGroupLayout->addWidget( widg );
192 else /* Special widgets */
194 controlLayout->addWidget( widg );
200 #define CONNECT_MAP( a ) CONNECT( a, clicked(), toolbarActionsMapper, map() )
201 #define SET_MAPPING( a, b ) toolbarActionsMapper->setMapping( a , b )
202 #define CONNECT_MAP_SET( a, b ) \
205 #define BUTTON_SET_BAR( a_button ) \
206 a_button->setToolTip( qtr( tooltipL[button] ) ); \
207 a_button->setIcon( QIcon( iconL[button] ) );
208 #define BUTTON_SET_BAR2( button, image, tooltip ) \
209 button->setToolTip( tooltip ); \
210 button->setIcon( QIcon( ":/"#image ) );
212 #define ENABLE_ON_VIDEO( a ) \
213 CONNECT( THEMIM->getIM(), voutChanged( bool ), a, setEnabled( bool ) ); \
214 a->setEnabled( THEMIM->getIM()->hasVideo() ); /* TODO: is this necessary? when input is started before the interface? */
216 #define ENABLE_ON_INPUT( a ) \
217 CONNECT( this, inputExists( bool ), a, setEnabled( bool ) ); \
218 a->setEnabled( THEMIM->getIM()->hasInput() ); /* TODO: is this necessary? when input is started before the interface? */
220 #define NORMAL_BUTTON( name ) \
221 QToolButton * name ## Button = new QToolButton; \
222 setupButton( name ## Button ); \
223 CONNECT_MAP_SET( name ## Button, name ## _ACTION ); \
224 BUTTON_SET_BAR( name ## Button ); \
225 widget = name ## Button;
227 QWidget *AbstractController::createWidget( buttonType_e button, int options )
229 bool b_flat = options & WIDGET_FLAT;
230 bool b_big = options & WIDGET_BIG;
231 bool b_shiny = options & WIDGET_SHINY;
232 bool b_special = false;
234 QWidget *widget = NULL;
238 PlayButton *playButton = new PlayButton;
239 setupButton( playButton );
240 BUTTON_SET_BAR( playButton );
241 CONNECT_MAP_SET( playButton, PLAY_ACTION );
242 CONNECT( this, inputPlaying( bool ),
243 playButton, updateButtonIcons( bool ));
248 NORMAL_BUTTON( STOP );
252 NORMAL_BUTTON( OPEN );
255 case OPEN_SUB_BUTTON:{
256 NORMAL_BUTTON( OPEN_SUB );
259 case PREVIOUS_BUTTON:{
260 NORMAL_BUTTON( PREVIOUS );
264 NORMAL_BUTTON( NEXT );
268 NORMAL_BUTTON( SLOWER );
269 ENABLE_ON_INPUT( SLOWERButton );
273 NORMAL_BUTTON( FASTER );
274 ENABLE_ON_INPUT( FASTERButton );
277 case PREV_SLOW_BUTTON:{
278 QToolButtonExt *but = new QToolButtonExt;
280 BUTTON_SET_BAR( but );
281 CONNECT( but, shortClicked(), THEMIM, prev() );
282 CONNECT( but, longClicked(), THEAM, skipBackward() );
286 case NEXT_FAST_BUTTON:{
287 QToolButtonExt *but = new QToolButtonExt;
289 BUTTON_SET_BAR( but );
290 CONNECT( but, shortClicked(), THEMIM, next() );
291 CONNECT( but, longClicked(), THEAM, skipForward() );
296 NORMAL_BUTTON( FRAME );
297 ENABLE_ON_VIDEO( FRAMEButton );
300 case FULLSCREEN_BUTTON:
301 case DEFULLSCREEN_BUTTON:
303 NORMAL_BUTTON( FULLSCREEN );
304 ENABLE_ON_VIDEO( FULLSCREENButton );
307 case FULLWIDTH_BUTTON: {
308 NORMAL_BUTTON( FULLWIDTH );
311 case EXTENDED_BUTTON:{
312 NORMAL_BUTTON( EXTENDED );
315 case PLAYLIST_BUTTON:{
316 NORMAL_BUTTON( PLAYLIST );
319 case SNAPSHOT_BUTTON:{
320 NORMAL_BUTTON( SNAPSHOT );
321 ENABLE_ON_VIDEO( SNAPSHOTButton );
325 QToolButton *recordButton = new QToolButton;
326 setupButton( recordButton );
327 CONNECT_MAP_SET( recordButton, RECORD_ACTION );
328 BUTTON_SET_BAR( recordButton );
329 ENABLE_ON_INPUT( recordButton );
330 recordButton->setCheckable( true );
331 CONNECT( THEMIM->getIM(), recordingStateChanged( bool ),
332 recordButton, setChecked( bool ) );
333 widget = recordButton;
337 AtoB_Button *ABButton = new AtoB_Button;
338 setupButton( ABButton );
339 ABButton->setShortcut( qtr("Shift+L") );
340 BUTTON_SET_BAR( ABButton );
341 ENABLE_ON_INPUT( ABButton );
342 CONNECT_MAP_SET( ABButton, ATOB_ACTION );
343 CONNECT( THEMIM->getIM(), AtoBchanged( bool, bool),
344 ABButton, updateButtonIcons( bool, bool ) );
349 SeekSlider *slider = new SeekSlider( Qt::Horizontal, NULL );
350 SeekPoints *chapters = new SeekPoints( this, p_intf );
351 CONNECT( THEMIM->getIM(), titleChanged( bool ), chapters, update() );
352 slider->setChapters( chapters );
354 /* Update the position when the IM has changed */
355 CONNECT( THEMIM->getIM(), positionUpdated( float, int64_t, int ),
356 slider, setPosition( float, int64_t, int ) );
357 /* And update the IM, when the position has changed */
358 CONNECT( slider, sliderDragged( float ),
359 THEMIM->getIM(), sliderUpdate( float ) );
360 CONNECT( THEMIM->getIM(), cachingChanged( float ),
361 slider, updateBuffering( float ) );
366 widget = discFrame();
369 case TELETEXT_BUTTONS:
370 widget = telexFrame();
377 SoundWidget *snd = new SoundWidget( this, p_intf, b_shiny, b_special );
383 TimeLabel *timeLabel = new TimeLabel( p_intf );
389 QFrame *line = new QFrame;
390 line->setFrameShape( QFrame::VLine );
391 line->setFrameShadow( QFrame::Raised );
392 line->setLineWidth( 0 );
393 line->setMidLineWidth( 1 );
397 case ADVANCED_CONTROLLER:
399 advControls = new AdvControlsWidget( p_intf, this );
400 widget = advControls;
403 case REVERSE_BUTTON:{
404 QToolButton *reverseButton = new QToolButton;
405 setupButton( reverseButton );
406 CONNECT_MAP_SET( reverseButton, REVERSE_ACTION );
407 BUTTON_SET_BAR( reverseButton );
408 reverseButton->setCheckable( true );
409 /* You should, of COURSE change this to the correct event,
410 when/if we have one, that tells us if trickplay is possible . */
411 CONNECT( this, inputIsTrickPlayable( bool ), reverseButton, setVisible( bool ) );
412 reverseButton->setVisible( false );
413 widget = reverseButton;
416 case SKIP_BACK_BUTTON: {
417 NORMAL_BUTTON( SKIP_BACK );
418 ENABLE_ON_INPUT( SKIP_BACKButton );
421 case SKIP_FW_BUTTON: {
422 NORMAL_BUTTON( SKIP_FW );
423 ENABLE_ON_INPUT( SKIP_FWButton );
427 NORMAL_BUTTON( QUIT );
430 case RANDOM_BUTTON: {
431 NORMAL_BUTTON( RANDOM );
432 RANDOMButton->setCheckable( true );
433 RANDOMButton->setChecked( var_GetBool( THEPL, "random" ) );
434 CONNECT( THEMIM, randomChanged( bool ),
435 RANDOMButton, setChecked( bool ) );
439 LoopButton *loopButton = new LoopButton;
440 setupButton( loopButton );
441 loopButton->setToolTip( qtr( "Click to toggle between loop all, loop one and no loop") );
442 loopButton->setCheckable( true );
443 int i_state = 2 * var_GetBool( THEPL, "loop" ) + var_GetBool( THEPL, "repeat" );
444 loopButton->updateButtonIcons( i_state );
445 CONNECT( THEMIM, repeatLoopChanged( int ), loopButton, updateButtonIcons( int ) );
446 CONNECT( loopButton, clicked(), THEMIM, loopRepeatLoopStatus() );
451 NORMAL_BUTTON( INFO );
454 case PLAYBACK_BUTTONS:{
455 widget = new QWidget;
456 DeckButtonsLayout *layout = new DeckButtonsLayout( widget );
457 BrowseButton *prev = new BrowseButton( widget, BrowseButton::Backward );
458 BrowseButton *next = new BrowseButton( widget );
459 RoundButton *play = new RoundButton( widget );
460 layout->setBackwardButton( prev );
461 layout->setForwardButton( next );
462 layout->setRoundButton( play );
463 CONNECT_MAP_SET( prev, PREVIOUS_ACTION );
464 CONNECT_MAP_SET( next, NEXT_ACTION );
465 CONNECT_MAP_SET( play, PLAY_ACTION );
468 case ASPECT_RATIO_COMBOBOX:
469 widget = new AspectRatioComboBox( p_intf );
472 msg_Warn( p_intf, "This should not happen %i", button );
476 /* Customize Buttons */
477 if( b_flat || b_big )
479 QFrame *frame = qobject_cast<QFrame *>(widget);
482 QList<QToolButton *> allTButtons = frame->findChildren<QToolButton *>();
483 for( int i = 0; i < allTButtons.count(); i++ )
484 applyAttributes( allTButtons[i], b_flat, b_big );
488 QToolButton *tmpButton = qobject_cast<QToolButton *>(widget);
490 applyAttributes( tmpButton, b_flat, b_big );
497 void AbstractController::applyAttributes( QToolButton *tmpButton, bool b_flat, bool b_big )
502 tmpButton->setAutoRaise( b_flat );
505 tmpButton->setFixedSize( QSize( 32, 32 ) );
506 tmpButton->setIconSize( QSize( 26, 26 ) );
511 QFrame *AbstractController::discFrame()
513 /** Disc and Menus handling */
514 QFrame *discFrame = new QFrame( this );
516 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
517 discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );
519 QToolButton *prevSectionButton = new QToolButton( discFrame );
520 setupButton( prevSectionButton );
521 BUTTON_SET_BAR2( prevSectionButton, toolbar/dvd_prev,
522 qtr("Previous Chapter/Title" ) );
523 discLayout->addWidget( prevSectionButton );
525 QToolButton *menuButton = new QToolButton( discFrame );
526 setupButton( menuButton );
527 discLayout->addWidget( menuButton );
528 BUTTON_SET_BAR2( menuButton, toolbar/dvd_menu, qtr( "Menu" ) );
530 QToolButton *nextSectionButton = new QToolButton( discFrame );
531 setupButton( nextSectionButton );
532 discLayout->addWidget( nextSectionButton );
533 BUTTON_SET_BAR2( nextSectionButton, toolbar/dvd_next,
534 qtr("Next Chapter/Title" ) );
536 /* Change the navigation button display when the IM
537 navigation changes */
538 CONNECT( THEMIM->getIM(), titleChanged( bool ),
539 discFrame, setVisible( bool ) );
540 CONNECT( THEMIM->getIM(), chapterChanged( bool ),
541 menuButton, setVisible( bool ) );
542 /* Changes the IM navigation when triggered on the nav buttons */
543 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
545 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
547 CONNECT( menuButton, clicked(), THEMIM->getIM(),
553 QFrame *AbstractController::telexFrame()
558 QFrame *telexFrame = new QFrame( this );
559 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
560 telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );
561 CONNECT( THEMIM->getIM(), teletextPossible( bool ),
562 telexFrame, setVisible( bool ) );
565 QToolButton *telexOn = new QToolButton;
566 setupButton( telexOn );
567 BUTTON_SET_BAR2( telexOn, toolbar/tv, qtr( "Teletext Activation" ) );
568 telexOn->setEnabled( false );
569 telexOn->setCheckable( true );
571 telexLayout->addWidget( telexOn );
573 /* Teletext Activation and set */
574 CONNECT( telexOn, clicked( bool ),
575 THEMIM->getIM(), activateTeletext( bool ) );
576 CONNECT( THEMIM->getIM(), teletextPossible( bool ),
577 telexOn, setEnabled( bool ) );
579 /* Transparency button */
580 QToolButton *telexTransparent = new QToolButton;
581 setupButton( telexTransparent );
582 BUTTON_SET_BAR2( telexTransparent, toolbar/tvtelx,
583 qtr( "Toggle Transparency " ) );
584 telexTransparent->setEnabled( false );
585 telexTransparent->setCheckable( true );
586 telexLayout->addWidget( telexTransparent );
588 /* Transparency change and set */
589 CONNECT( telexTransparent, clicked( bool ),
590 THEMIM->getIM(), telexSetTransparency( bool ) );
591 CONNECT( THEMIM->getIM(), teletextTransparencyActivated( bool ),
592 telexTransparent, setChecked( bool ) );
596 QSpinBox *telexPage = new QSpinBox( telexFrame );
597 telexPage->setRange( 0, 999 );
598 telexPage->setValue( 100 );
599 telexPage->setAccelerated( true );
600 telexPage->setWrapping( true );
601 telexPage->setAlignment( Qt::AlignRight );
602 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
603 telexPage->setEnabled( false );
604 telexLayout->addWidget( telexPage );
606 /* Page change and set */
607 CONNECT( telexPage, valueChanged( int ),
608 THEMIM->getIM(), telexSetPage( int ) );
609 CONNECT( THEMIM->getIM(), newTelexPageSet( int ),
610 telexPage, setValue( int ) );
612 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexPage, setEnabled( bool ) );
613 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexTransparent, setEnabled( bool ) );
614 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexOn, setChecked( bool ) );
619 #undef CONNECT_MAP_SET
620 #undef BUTTON_SET_BAR
621 #undef BUTTON_SET_BAR2
622 #undef ENABLE_ON_VIDEO
623 #undef ENABLE_ON_INPUT
625 #include <QHBoxLayout>
626 /*****************************
627 * DA Control Widget !
628 *****************************/
629 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
632 AbstractController( _p_i, _parent )
634 RTL_UNAFFECTED_WIDGET
635 /* advanced Controls handling */
636 b_advancedVisible = b_advControls;
638 setStyleSheet( "background: red ");
640 setAttribute( Qt::WA_MacBrushedMetal);
641 QVBoxLayout *controlLayout = new QVBoxLayout( this );
642 controlLayout->setContentsMargins( 4, 1, 0, 0 );
643 controlLayout->setSpacing( 0 );
644 QHBoxLayout *controlLayout1 = new QHBoxLayout;
645 controlLayout1->setSpacing( 0 ); controlLayout1->setMargin( 0 );
647 QString line1 = getSettings()->value( "MainWindow/MainToolbar1", MAIN_TB1_DEFAULT )
649 parseAndCreate( line1, controlLayout1 );
651 QHBoxLayout *controlLayout2 = new QHBoxLayout;
652 controlLayout2->setSpacing( 0 ); controlLayout2->setMargin( 0 );
653 QString line2 = getSettings()->value( "MainWindow/MainToolbar2", MAIN_TB2_DEFAULT )
655 parseAndCreate( line2, controlLayout2 );
657 grip = new QSizeGrip( this );
658 controlLayout2->addWidget( grip, 0, Qt::AlignBottom|Qt::AlignRight );
660 if( !b_advancedVisible && advControls ) advControls->hide();
662 controlLayout->addLayout( controlLayout1 );
663 controlLayout->addLayout( controlLayout2 );
666 void ControlsWidget::toggleAdvanced()
668 if( !advControls ) return;
670 advControls->setVisible( !b_advancedVisible );
671 b_advancedVisible = !b_advancedVisible;
672 emit advancedControlsToggled( b_advancedVisible );
675 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
676 AbstractController( _p_i, _parent )
678 RTL_UNAFFECTED_WIDGET
679 controlLayout = new QHBoxLayout( this );
680 controlLayout->setMargin( 0 );
681 controlLayout->setSpacing( 0 );
683 setStyleSheet( "background: orange ");
687 QString line = getSettings()->value( "MainWindow/AdvToolbar", ADV_TB_DEFAULT )
689 parseAndCreate( line, controlLayout );
692 InputControlsWidget::InputControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
693 AbstractController( _p_i, _parent )
695 RTL_UNAFFECTED_WIDGET
696 controlLayout = new QHBoxLayout( this );
697 controlLayout->setMargin( 0 );
698 controlLayout->setSpacing( 0 );
700 setStyleSheet( "background: green ");
703 QString line = getSettings()->value( "MainWindow/InputToolbar", INPT_TB_DEFAULT ).toString();
704 parseAndCreate( line, controlLayout );
706 /**********************************************************************
707 * Fullscrenn control widget
708 **********************************************************************/
709 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i, QWidget *_parent )
710 : AbstractController( _p_i, _parent )
712 RTL_UNAFFECTED_WIDGET
715 b_mouse_over = false;
716 i_mouse_last_move_x = -1;
717 i_mouse_last_move_y = -1;
718 #if HAVE_TRANSPARENCY
719 b_slow_hide_begin = false;
720 i_slow_hide_timeout = 1;
722 b_fullscreen = false;
728 setWindowFlags( Qt::ToolTip );
729 setMinimumWidth( FSC_WIDTH );
730 setMinimumHeight( FSC_HEIGHT );
733 setFrameShape( QFrame::StyledPanel );
734 setFrameStyle( QFrame::Sunken );
735 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
737 QVBoxLayout *controlLayout2 = new QVBoxLayout( this );
738 controlLayout2->setContentsMargins( 4, 6, 4, 2 );
741 InputControlsWidget *inputC = new InputControlsWidget( p_intf, this );
742 controlLayout2->addWidget( inputC );
744 controlLayout = new QHBoxLayout;
745 QString line = getSettings()->value( "MainWindow/FSCtoolbar", FSC_TB_DEFAULT ).toString();
746 parseAndCreate( line, controlLayout );
747 controlLayout2->addLayout( controlLayout );
750 p_hideTimer = new QTimer( this );
751 p_hideTimer->setSingleShot( true );
752 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
754 /* slow hiding timer */
755 #if HAVE_TRANSPARENCY
756 p_slowHideTimer = new QTimer( this );
757 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
758 f_opacity = var_InheritFloat( p_intf, "qt-fs-opacity" );
761 vlc_mutex_init_recursive( &lock );
763 DCONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
764 this, setVoutList( vout_thread_t **, int ) );
767 previousPosition = getSettings()->value( "FullScreen/pos" ).toPoint();
768 screenRes = getSettings()->value( "FullScreen/screen" ).toRect();
769 isWideFSC = getSettings()->value( "FullScreen/wide" ).toBool();
770 i_screennumber = var_InheritInteger( p_intf, "qt-fullscreen-screennumber" );
773 FullscreenControllerWidget::~FullscreenControllerWidget()
775 getSettings()->setValue( "FullScreen/pos", previousPosition );
776 getSettings()->setValue( "FullScreen/screen", screenRes );
777 getSettings()->setValue( "FullScreen/wide", isWideFSC );
779 setVoutList( NULL, 0 );
780 vlc_mutex_destroy( &lock );
783 void FullscreenControllerWidget::restoreFSC()
787 /* Restore half-bar and re-centre if needed */
788 setMinimumWidth( FSC_WIDTH );
791 QRect currentRes = QApplication::desktop()->screenGeometry( targetScreen() );
793 if( currentRes == screenRes &&
794 QApplication::desktop()->screen()->geometry().contains( previousPosition, true ) )
796 /* Restore to the last known position */
797 move( previousPosition );
801 /* FSC is out of screen or screen resolution changed */
802 msg_Dbg( p_intf, "Recentering the Fullscreen Controller" );
803 centerFSC( targetScreen() );
804 screenRes = currentRes;
805 previousPosition = pos();
810 /* Dock at the bottom of the screen */
811 updateFullwidthGeometry( targetScreen() );
815 // Tell kwin that we do not want a shadow around the fscontroller
816 setMask( QRegion( 0, 0, width(), height() ) );
820 void FullscreenControllerWidget::centerFSC( int number )
822 QRect currentRes = QApplication::desktop()->screenGeometry( number );
824 /* screen has changed, calculate new position */
825 QPoint pos = QPoint( currentRes.x() + (currentRes.width() / 2) - (width() / 2),
826 currentRes.y() + currentRes.height() - height());
831 * Show fullscreen controller
833 void FullscreenControllerWidget::showFSC()
837 #if HAVE_TRANSPARENCY
838 setWindowOpacity( f_opacity );
845 * Plane to hide fullscreen controller
847 void FullscreenControllerWidget::planHideFSC()
849 vlc_mutex_lock( &lock );
850 int i_timeout = i_hide_timeout;
851 vlc_mutex_unlock( &lock );
853 p_hideTimer->start( i_timeout );
855 #if HAVE_TRANSPARENCY
856 b_slow_hide_begin = true;
857 i_slow_hide_timeout = i_timeout;
858 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
863 * Hidding fullscreen controller slowly
864 * Linux: need composite manager
865 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
867 void FullscreenControllerWidget::slowHideFSC()
869 #if HAVE_TRANSPARENCY
870 if( b_slow_hide_begin )
872 b_slow_hide_begin = false;
874 p_slowHideTimer->stop();
875 /* the last part of time divided to 100 pieces */
876 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
881 if ( windowOpacity() > 0.0 )
883 /* we should use 0.01 because of 100 pieces ^^^
884 but than it cannt be done in time */
885 setWindowOpacity( windowOpacity() - 0.02 );
888 if ( windowOpacity() <= 0.0 )
889 p_slowHideTimer->stop();
894 void FullscreenControllerWidget::updateFullwidthGeometry( int number )
896 QRect screenGeometry = QApplication::desktop()->screenGeometry( number );
897 setMinimumWidth( screenGeometry.width() );
898 setGeometry( screenGeometry.x(), screenGeometry.y() + screenGeometry.height() - FSC_HEIGHT, screenGeometry.width(), FSC_HEIGHT );
902 void FullscreenControllerWidget::toggleFullwidth()
904 /* Toggle isWideFSC switch */
905 isWideFSC = !isWideFSC;
910 int FullscreenControllerWidget::targetScreen()
912 if( i_screennumber == -1 || i_screennumber > QApplication::desktop()->numScreens() )
913 return QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
914 return i_screennumber;
919 * events: show, hide, start timer for hiding
921 void FullscreenControllerWidget::customEvent( QEvent *event )
925 switch( (int)event->type() )
927 /* This is used when the 'i' hotkey is used, to force quick toggle */
928 case FullscreenControlToggle_Type:
929 vlc_mutex_lock( &lock );
931 vlc_mutex_unlock( &lock );
944 /* Event called to Show the FSC on mouseChanged() */
945 case FullscreenControlShow_Type:
946 vlc_mutex_lock( &lock );
948 vlc_mutex_unlock( &lock );
954 /* Start the timer to hide later, called usually with above case */
955 case FullscreenControlPlanHide_Type:
956 if( !b_mouse_over ) // Only if the mouse is not over FSC
960 case FullscreenControlHide_Type:
972 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
974 if( event->buttons() == Qt::LeftButton )
976 if( i_mouse_last_x == -1 || i_mouse_last_y == -1 )
979 int i_moveX = event->globalX() - i_mouse_last_x;
980 int i_moveY = event->globalY() - i_mouse_last_y;
982 move( x() + i_moveX, y() + i_moveY );
984 i_mouse_last_x = event->globalX();
985 i_mouse_last_y = event->globalY();
991 * store position of cursor
993 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
995 if( isWideFSC ) return;
996 i_mouse_last_x = event->globalX();
997 i_mouse_last_y = event->globalY();
1001 void FullscreenControllerWidget::mouseReleaseEvent( QMouseEvent *event )
1003 if( isWideFSC ) return;
1004 i_mouse_last_x = -1;
1005 i_mouse_last_y = -1;
1008 // Save the new FSC position
1009 previousPosition = pos();
1013 * On mouse go above FSC
1015 void FullscreenControllerWidget::enterEvent( QEvent *event )
1017 b_mouse_over = true;
1019 p_hideTimer->stop();
1020 #if HAVE_TRANSPARENCY
1021 p_slowHideTimer->stop();
1022 setWindowOpacity( f_opacity );
1028 * On mouse go out from FSC
1030 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1034 b_mouse_over = false;
1039 * When you get pressed key, send it to video output
1041 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1043 emit keyPressed( event );
1047 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object,
1048 const char *variable, vlc_value_t old_val,
1049 vlc_value_t new_val, void *data )
1051 VLC_UNUSED( variable ); VLC_UNUSED( old_val );
1053 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1055 msg_Dbg( p_vout, "Qt4: Fullscreen state changed" );
1056 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1058 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1063 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1064 vlc_value_t old_val, vlc_value_t new_val,
1067 VLC_UNUSED( variable ); VLC_UNUSED( old_val );
1069 vout_thread_t *p_vout = (vout_thread_t *)vlc_object;
1070 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1072 /* Get the value from the Vout - Trust the vout more than Qt */
1073 p_fs->mouseChanged( p_vout, new_val.coords.x, new_val.coords.y );
1079 * It is call to update the list of vout handled by the fullscreen controller
1081 void FullscreenControllerWidget::setVoutList( vout_thread_t **pp_vout, int i_vout )
1083 QList<vout_thread_t*> del;
1084 QList<vout_thread_t*> add;
1086 QList<vout_thread_t*> set;
1089 for( int i = 0; i < i_vout; i++ )
1092 /* Vout to remove */
1093 vlc_mutex_lock( &lock );
1094 foreach( vout_thread_t *p_vout, vout )
1096 if( !set.contains( p_vout ) )
1099 vlc_mutex_unlock( &lock );
1101 foreach( vout_thread_t *p_vout, del )
1103 var_DelCallback( p_vout, "fullscreen",
1104 FullscreenControllerWidgetFullscreenChanged, this );
1105 vlc_mutex_lock( &lock );
1106 fullscreenChanged( p_vout, false, 0 );
1107 vout.removeAll( p_vout );
1108 vlc_mutex_unlock( &lock );
1110 vlc_object_release( VLC_OBJECT(p_vout) );
1114 vlc_mutex_lock( &lock );
1115 foreach( vout_thread_t *p_vout, set )
1117 if( !vout.contains( p_vout ) )
1120 vlc_mutex_unlock( &lock );
1122 foreach( vout_thread_t *p_vout, add )
1124 vlc_object_hold( VLC_OBJECT(p_vout) );
1126 vlc_mutex_lock( &lock );
1127 vout.append( p_vout );
1128 var_AddCallback( p_vout, "fullscreen",
1129 FullscreenControllerWidgetFullscreenChanged, this );
1130 /* I miss a add and fire */
1131 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ),
1132 var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1133 vlc_mutex_unlock( &lock );
1137 * Register and unregister callback for mouse moving
1139 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout,
1140 bool b_fs, int i_timeout )
1142 /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
1144 vlc_mutex_lock( &lock );
1145 /* Entering fullscreen, register callback */
1146 if( b_fs && !b_fullscreen )
1148 msg_Dbg( p_vout, "Qt: Entering Fullscreen" );
1149 b_fullscreen = true;
1150 i_hide_timeout = i_timeout;
1151 var_AddCallback( p_vout, "mouse-moved",
1152 FullscreenControllerWidgetMouseMoved, this );
1154 /* Quitting fullscreen, unregistering callback */
1155 else if( !b_fs && b_fullscreen )
1157 msg_Dbg( p_vout, "Qt: Quitting Fullscreen" );
1158 b_fullscreen = false;
1159 i_hide_timeout = i_timeout;
1160 var_DelCallback( p_vout, "mouse-moved",
1161 FullscreenControllerWidgetMouseMoved, this );
1163 /* Force fs hiding */
1164 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1165 QApplication::postEvent( this, eHide );
1167 vlc_mutex_unlock( &lock );
1171 * Mouse change callback (show/hide the controller on mouse movement)
1173 void FullscreenControllerWidget::mouseChanged( vout_thread_t *, int i_mousex, int i_mousey )
1177 /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
1180 if( ( i_mouse_last_move_x == -1 || i_mouse_last_move_y == -1 ) ||
1181 ( abs( i_mouse_last_move_x - i_mousex ) > 2 ||
1182 abs( i_mouse_last_move_y - i_mousey ) > 2 ) )
1184 i_mouse_last_move_x = i_mousex;
1185 i_mouse_last_move_y = i_mousey;
1192 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1193 QApplication::postEvent( this, eShow );
1195 /* Plan hide event */
1196 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1197 QApplication::postEvent( this, eHide );