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 );
469 msg_Warn( p_intf, "This should not happen %i", button );
473 /* Customize Buttons */
474 if( b_flat || b_big )
476 QFrame *frame = qobject_cast<QFrame *>(widget);
479 QList<QToolButton *> allTButtons = frame->findChildren<QToolButton *>();
480 for( int i = 0; i < allTButtons.count(); i++ )
481 applyAttributes( allTButtons[i], b_flat, b_big );
485 QToolButton *tmpButton = qobject_cast<QToolButton *>(widget);
487 applyAttributes( tmpButton, b_flat, b_big );
494 void AbstractController::applyAttributes( QToolButton *tmpButton, bool b_flat, bool b_big )
499 tmpButton->setAutoRaise( b_flat );
502 tmpButton->setFixedSize( QSize( 32, 32 ) );
503 tmpButton->setIconSize( QSize( 26, 26 ) );
508 QFrame *AbstractController::discFrame()
510 /** Disc and Menus handling */
511 QFrame *discFrame = new QFrame( this );
513 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
514 discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );
516 QToolButton *prevSectionButton = new QToolButton( discFrame );
517 setupButton( prevSectionButton );
518 BUTTON_SET_BAR2( prevSectionButton, toolbar/dvd_prev,
519 qtr("Previous Chapter/Title" ) );
520 discLayout->addWidget( prevSectionButton );
522 QToolButton *menuButton = new QToolButton( discFrame );
523 setupButton( menuButton );
524 discLayout->addWidget( menuButton );
525 BUTTON_SET_BAR2( menuButton, toolbar/dvd_menu, qtr( "Menu" ) );
527 QToolButton *nextSectionButton = new QToolButton( discFrame );
528 setupButton( nextSectionButton );
529 discLayout->addWidget( nextSectionButton );
530 BUTTON_SET_BAR2( nextSectionButton, toolbar/dvd_next,
531 qtr("Next Chapter/Title" ) );
533 /* Change the navigation button display when the IM
534 navigation changes */
535 CONNECT( THEMIM->getIM(), titleChanged( bool ),
536 discFrame, setVisible( bool ) );
537 CONNECT( THEMIM->getIM(), chapterChanged( bool ),
538 menuButton, setVisible( bool ) );
539 /* Changes the IM navigation when triggered on the nav buttons */
540 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
542 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
544 CONNECT( menuButton, clicked(), THEMIM->getIM(),
550 QFrame *AbstractController::telexFrame()
555 QFrame *telexFrame = new QFrame( this );
556 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
557 telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );
558 CONNECT( THEMIM->getIM(), teletextPossible( bool ),
559 telexFrame, setVisible( bool ) );
562 QToolButton *telexOn = new QToolButton;
563 setupButton( telexOn );
564 BUTTON_SET_BAR2( telexOn, toolbar/tv, qtr( "Teletext Activation" ) );
565 telexOn->setEnabled( false );
566 telexOn->setCheckable( true );
568 telexLayout->addWidget( telexOn );
570 /* Teletext Activation and set */
571 CONNECT( telexOn, clicked( bool ),
572 THEMIM->getIM(), activateTeletext( bool ) );
573 CONNECT( THEMIM->getIM(), teletextPossible( bool ),
574 telexOn, setEnabled( bool ) );
576 /* Transparency button */
577 QToolButton *telexTransparent = new QToolButton;
578 setupButton( telexTransparent );
579 BUTTON_SET_BAR2( telexTransparent, toolbar/tvtelx,
580 qtr( "Toggle Transparency " ) );
581 telexTransparent->setEnabled( false );
582 telexTransparent->setCheckable( true );
583 telexLayout->addWidget( telexTransparent );
585 /* Transparency change and set */
586 CONNECT( telexTransparent, clicked( bool ),
587 THEMIM->getIM(), telexSetTransparency( bool ) );
588 CONNECT( THEMIM->getIM(), teletextTransparencyActivated( bool ),
589 telexTransparent, setChecked( bool ) );
593 QSpinBox *telexPage = new QSpinBox( telexFrame );
594 telexPage->setRange( 0, 999 );
595 telexPage->setValue( 100 );
596 telexPage->setAccelerated( true );
597 telexPage->setWrapping( true );
598 telexPage->setAlignment( Qt::AlignRight );
599 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
600 telexPage->setEnabled( false );
601 telexLayout->addWidget( telexPage );
603 /* Page change and set */
604 CONNECT( telexPage, valueChanged( int ),
605 THEMIM->getIM(), telexSetPage( int ) );
606 CONNECT( THEMIM->getIM(), newTelexPageSet( int ),
607 telexPage, setValue( int ) );
609 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexPage, setEnabled( bool ) );
610 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexTransparent, setEnabled( bool ) );
611 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexOn, setChecked( bool ) );
616 #undef CONNECT_MAP_SET
617 #undef BUTTON_SET_BAR
618 #undef BUTTON_SET_BAR2
619 #undef ENABLE_ON_VIDEO
620 #undef ENABLE_ON_INPUT
622 #include <QHBoxLayout>
623 /*****************************
624 * DA Control Widget !
625 *****************************/
626 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
629 AbstractController( _p_i, _parent )
631 RTL_UNAFFECTED_WIDGET
632 /* advanced Controls handling */
633 b_advancedVisible = b_advControls;
635 setStyleSheet( "background: red ");
637 setAttribute( Qt::WA_MacBrushedMetal);
638 QVBoxLayout *controlLayout = new QVBoxLayout( this );
639 controlLayout->setContentsMargins( 4, 1, 0, 0 );
640 controlLayout->setSpacing( 0 );
641 QHBoxLayout *controlLayout1 = new QHBoxLayout;
642 controlLayout1->setSpacing( 0 ); controlLayout1->setMargin( 0 );
644 QString line1 = getSettings()->value( "MainWindow/MainToolbar1", MAIN_TB1_DEFAULT )
646 parseAndCreate( line1, controlLayout1 );
648 QHBoxLayout *controlLayout2 = new QHBoxLayout;
649 controlLayout2->setSpacing( 0 ); controlLayout2->setMargin( 0 );
650 QString line2 = getSettings()->value( "MainWindow/MainToolbar2", MAIN_TB2_DEFAULT )
652 parseAndCreate( line2, controlLayout2 );
654 grip = new QSizeGrip( this );
655 controlLayout2->addWidget( grip, 0, Qt::AlignBottom|Qt::AlignRight );
657 if( !b_advancedVisible && advControls ) advControls->hide();
659 controlLayout->addLayout( controlLayout1 );
660 controlLayout->addLayout( controlLayout2 );
663 void ControlsWidget::toggleAdvanced()
665 if( !advControls ) return;
667 advControls->setVisible( !b_advancedVisible );
668 b_advancedVisible = !b_advancedVisible;
669 emit advancedControlsToggled( b_advancedVisible );
672 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
673 AbstractController( _p_i, _parent )
675 RTL_UNAFFECTED_WIDGET
676 controlLayout = new QHBoxLayout( this );
677 controlLayout->setMargin( 0 );
678 controlLayout->setSpacing( 0 );
680 setStyleSheet( "background: orange ");
684 QString line = getSettings()->value( "MainWindow/AdvToolbar", ADV_TB_DEFAULT )
686 parseAndCreate( line, controlLayout );
689 InputControlsWidget::InputControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
690 AbstractController( _p_i, _parent )
692 RTL_UNAFFECTED_WIDGET
693 controlLayout = new QHBoxLayout( this );
694 controlLayout->setMargin( 0 );
695 controlLayout->setSpacing( 0 );
697 setStyleSheet( "background: green ");
700 QString line = getSettings()->value( "MainWindow/InputToolbar", INPT_TB_DEFAULT ).toString();
701 parseAndCreate( line, controlLayout );
703 /**********************************************************************
704 * Fullscrenn control widget
705 **********************************************************************/
706 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i, QWidget *_parent )
707 : AbstractController( _p_i, _parent )
709 RTL_UNAFFECTED_WIDGET
712 b_mouse_over = false;
713 i_mouse_last_move_x = -1;
714 i_mouse_last_move_y = -1;
715 #if HAVE_TRANSPARENCY
716 b_slow_hide_begin = false;
717 i_slow_hide_timeout = 1;
719 b_fullscreen = false;
725 setWindowFlags( Qt::ToolTip );
726 setMinimumWidth( FSC_WIDTH );
727 setMinimumHeight( FSC_HEIGHT );
730 setFrameShape( QFrame::StyledPanel );
731 setFrameStyle( QFrame::Sunken );
732 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
734 QVBoxLayout *controlLayout2 = new QVBoxLayout( this );
735 controlLayout2->setContentsMargins( 4, 6, 4, 2 );
738 InputControlsWidget *inputC = new InputControlsWidget( p_intf, this );
739 controlLayout2->addWidget( inputC );
741 controlLayout = new QHBoxLayout;
742 QString line = getSettings()->value( "MainWindow/FSCtoolbar", FSC_TB_DEFAULT ).toString();
743 parseAndCreate( line, controlLayout );
744 controlLayout2->addLayout( controlLayout );
747 p_hideTimer = new QTimer( this );
748 p_hideTimer->setSingleShot( true );
749 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
751 /* slow hiding timer */
752 #if HAVE_TRANSPARENCY
753 p_slowHideTimer = new QTimer( this );
754 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
755 f_opacity = var_InheritFloat( p_intf, "qt-fs-opacity" );
758 vlc_mutex_init_recursive( &lock );
760 DCONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
761 this, setVoutList( vout_thread_t **, int ) );
764 previousPosition = getSettings()->value( "FullScreen/pos" ).toPoint();
765 screenRes = getSettings()->value( "FullScreen/screen" ).toRect();
766 isWideFSC = getSettings()->value( "FullScreen/wide" ).toBool();
767 i_screennumber = var_InheritInteger( p_intf, "qt-fullscreen-screennumber" );
770 FullscreenControllerWidget::~FullscreenControllerWidget()
772 getSettings()->setValue( "FullScreen/pos", previousPosition );
773 getSettings()->setValue( "FullScreen/screen", screenRes );
774 getSettings()->setValue( "FullScreen/wide", isWideFSC );
776 setVoutList( NULL, 0 );
777 vlc_mutex_destroy( &lock );
780 void FullscreenControllerWidget::restoreFSC()
784 /* Restore half-bar and re-centre if needed */
785 setMinimumWidth( FSC_WIDTH );
788 QRect currentRes = QApplication::desktop()->screenGeometry( targetScreen() );
790 if( currentRes == screenRes &&
791 QApplication::desktop()->screen()->geometry().contains( previousPosition, true ) )
793 /* Restore to the last known position */
794 move( previousPosition );
798 /* FSC is out of screen or screen resolution changed */
799 msg_Dbg( p_intf, "Recentering the Fullscreen Controller" );
800 centerFSC( targetScreen() );
801 screenRes = currentRes;
802 previousPosition = pos();
807 /* Dock at the bottom of the screen */
808 updateFullwidthGeometry( targetScreen() );
812 // Tell kwin that we do not want a shadow around the fscontroller
813 setMask( QRegion( 0, 0, width(), height() ) );
817 void FullscreenControllerWidget::centerFSC( int number )
819 QRect currentRes = QApplication::desktop()->screenGeometry( number );
821 /* screen has changed, calculate new position */
822 QPoint pos = QPoint( currentRes.x() + (currentRes.width() / 2) - (width() / 2),
823 currentRes.y() + currentRes.height() - height());
828 * Show fullscreen controller
830 void FullscreenControllerWidget::showFSC()
834 #if HAVE_TRANSPARENCY
835 setWindowOpacity( f_opacity );
842 * Plane to hide fullscreen controller
844 void FullscreenControllerWidget::planHideFSC()
846 vlc_mutex_lock( &lock );
847 int i_timeout = i_hide_timeout;
848 vlc_mutex_unlock( &lock );
850 p_hideTimer->start( i_timeout );
852 #if HAVE_TRANSPARENCY
853 b_slow_hide_begin = true;
854 i_slow_hide_timeout = i_timeout;
855 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
860 * Hidding fullscreen controller slowly
861 * Linux: need composite manager
862 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
864 void FullscreenControllerWidget::slowHideFSC()
866 #if HAVE_TRANSPARENCY
867 if( b_slow_hide_begin )
869 b_slow_hide_begin = false;
871 p_slowHideTimer->stop();
872 /* the last part of time divided to 100 pieces */
873 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
878 if ( windowOpacity() > 0.0 )
880 /* we should use 0.01 because of 100 pieces ^^^
881 but than it cannt be done in time */
882 setWindowOpacity( windowOpacity() - 0.02 );
885 if ( windowOpacity() <= 0.0 )
886 p_slowHideTimer->stop();
891 void FullscreenControllerWidget::updateFullwidthGeometry( int number )
893 QRect screenGeometry = QApplication::desktop()->screenGeometry( number );
894 setMinimumWidth( screenGeometry.width() );
895 setGeometry( screenGeometry.x(), screenGeometry.y() + screenGeometry.height() - FSC_HEIGHT, screenGeometry.width(), FSC_HEIGHT );
899 void FullscreenControllerWidget::toggleFullwidth()
901 /* Toggle isWideFSC switch */
902 isWideFSC = !isWideFSC;
907 int FullscreenControllerWidget::targetScreen()
909 if( i_screennumber == -1 || i_screennumber > QApplication::desktop()->numScreens() )
910 return QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
911 return i_screennumber;
916 * events: show, hide, start timer for hiding
918 void FullscreenControllerWidget::customEvent( QEvent *event )
922 switch( (int)event->type() )
924 /* This is used when the 'i' hotkey is used, to force quick toggle */
925 case FullscreenControlToggle_Type:
926 vlc_mutex_lock( &lock );
928 vlc_mutex_unlock( &lock );
941 /* Event called to Show the FSC on mouseChanged() */
942 case FullscreenControlShow_Type:
943 vlc_mutex_lock( &lock );
945 vlc_mutex_unlock( &lock );
951 /* Start the timer to hide later, called usually with above case */
952 case FullscreenControlPlanHide_Type:
953 if( !b_mouse_over ) // Only if the mouse is not over FSC
957 case FullscreenControlHide_Type:
969 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
971 if( event->buttons() == Qt::LeftButton )
973 if( i_mouse_last_x == -1 || i_mouse_last_y == -1 )
976 int i_moveX = event->globalX() - i_mouse_last_x;
977 int i_moveY = event->globalY() - i_mouse_last_y;
979 move( x() + i_moveX, y() + i_moveY );
981 i_mouse_last_x = event->globalX();
982 i_mouse_last_y = event->globalY();
988 * store position of cursor
990 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
992 if( isWideFSC ) return;
993 i_mouse_last_x = event->globalX();
994 i_mouse_last_y = event->globalY();
998 void FullscreenControllerWidget::mouseReleaseEvent( QMouseEvent *event )
1000 if( isWideFSC ) return;
1001 i_mouse_last_x = -1;
1002 i_mouse_last_y = -1;
1005 // Save the new FSC position
1006 previousPosition = pos();
1010 * On mouse go above FSC
1012 void FullscreenControllerWidget::enterEvent( QEvent *event )
1014 b_mouse_over = true;
1016 p_hideTimer->stop();
1017 #if HAVE_TRANSPARENCY
1018 p_slowHideTimer->stop();
1019 setWindowOpacity( f_opacity );
1025 * On mouse go out from FSC
1027 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1031 b_mouse_over = false;
1036 * When you get pressed key, send it to video output
1038 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1040 emit keyPressed( event );
1044 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object,
1045 const char *variable, vlc_value_t old_val,
1046 vlc_value_t new_val, void *data )
1048 VLC_UNUSED( variable ); VLC_UNUSED( old_val );
1050 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1052 msg_Dbg( p_vout, "Qt4: Fullscreen state changed" );
1053 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1055 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1060 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1061 vlc_value_t old_val, vlc_value_t new_val,
1064 VLC_UNUSED( variable ); VLC_UNUSED( old_val );
1066 vout_thread_t *p_vout = (vout_thread_t *)vlc_object;
1067 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1069 /* Get the value from the Vout - Trust the vout more than Qt */
1070 p_fs->mouseChanged( p_vout, new_val.coords.x, new_val.coords.y );
1076 * It is call to update the list of vout handled by the fullscreen controller
1078 void FullscreenControllerWidget::setVoutList( vout_thread_t **pp_vout, int i_vout )
1080 QList<vout_thread_t*> del;
1081 QList<vout_thread_t*> add;
1083 QList<vout_thread_t*> set;
1086 for( int i = 0; i < i_vout; i++ )
1089 /* Vout to remove */
1090 vlc_mutex_lock( &lock );
1091 foreach( vout_thread_t *p_vout, vout )
1093 if( !set.contains( p_vout ) )
1096 vlc_mutex_unlock( &lock );
1098 foreach( vout_thread_t *p_vout, del )
1100 var_DelCallback( p_vout, "fullscreen",
1101 FullscreenControllerWidgetFullscreenChanged, this );
1102 vlc_mutex_lock( &lock );
1103 fullscreenChanged( p_vout, false, 0 );
1104 vout.removeAll( p_vout );
1105 vlc_mutex_unlock( &lock );
1107 vlc_object_release( VLC_OBJECT(p_vout) );
1111 vlc_mutex_lock( &lock );
1112 foreach( vout_thread_t *p_vout, set )
1114 if( !vout.contains( p_vout ) )
1117 vlc_mutex_unlock( &lock );
1119 foreach( vout_thread_t *p_vout, add )
1121 vlc_object_hold( VLC_OBJECT(p_vout) );
1123 vlc_mutex_lock( &lock );
1124 vout.append( p_vout );
1125 var_AddCallback( p_vout, "fullscreen",
1126 FullscreenControllerWidgetFullscreenChanged, this );
1127 /* I miss a add and fire */
1128 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ),
1129 var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1130 vlc_mutex_unlock( &lock );
1134 * Register and unregister callback for mouse moving
1136 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout,
1137 bool b_fs, int i_timeout )
1139 /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
1141 vlc_mutex_lock( &lock );
1142 /* Entering fullscreen, register callback */
1143 if( b_fs && !b_fullscreen )
1145 msg_Dbg( p_vout, "Qt: Entering Fullscreen" );
1146 b_fullscreen = true;
1147 i_hide_timeout = i_timeout;
1148 var_AddCallback( p_vout, "mouse-moved",
1149 FullscreenControllerWidgetMouseMoved, this );
1151 /* Quitting fullscreen, unregistering callback */
1152 else if( !b_fs && b_fullscreen )
1154 msg_Dbg( p_vout, "Qt: Quitting Fullscreen" );
1155 b_fullscreen = false;
1156 i_hide_timeout = i_timeout;
1157 var_DelCallback( p_vout, "mouse-moved",
1158 FullscreenControllerWidgetMouseMoved, this );
1160 /* Force fs hiding */
1161 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1162 QApplication::postEvent( this, eHide );
1164 vlc_mutex_unlock( &lock );
1168 * Mouse change callback (show/hide the controller on mouse movement)
1170 void FullscreenControllerWidget::mouseChanged( vout_thread_t *, int i_mousex, int i_mousey )
1174 /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
1177 if( ( i_mouse_last_move_x == -1 || i_mouse_last_move_y == -1 ) ||
1178 ( abs( i_mouse_last_move_x - i_mousex ) > 2 ||
1179 abs( i_mouse_last_move_y - i_mousey ) > 2 ) )
1181 i_mouse_last_move_x = i_mousex;
1182 i_mouse_last_move_y = i_mousey;
1189 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1190 QApplication::postEvent( this, eShow );
1192 /* Plan hide event */
1193 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1194 QApplication::postEvent( this, eHide );