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 *newControlLayout )
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( newControlLayout, -1, i_type, i_option );
146 if( buttonGroupLayout )
148 newControlLayout->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, !b_shiny );
350 SeekPoints *chapters = new SeekPoints( this, p_intf );
351 CONNECT( THEMIM->getIM(), chapterChanged( 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 ) );
362 /* Give hint to disable slider's interactivity when useless */
363 CONNECT( THEMIM->getIM(), inputCanSeek( bool ),
364 slider, setSeekable( bool ) );
369 widget = discFrame();
372 case TELETEXT_BUTTONS:
373 widget = telexFrame();
380 SoundWidget *snd = new SoundWidget( this, p_intf, b_shiny, b_special );
386 TimeLabel *timeLabel = new TimeLabel( p_intf );
392 QFrame *line = new QFrame;
393 line->setFrameShape( QFrame::VLine );
394 line->setFrameShadow( QFrame::Raised );
395 line->setLineWidth( 0 );
396 line->setMidLineWidth( 1 );
400 case ADVANCED_CONTROLLER:
402 advControls = new AdvControlsWidget( p_intf, this );
403 widget = advControls;
406 case REVERSE_BUTTON:{
407 QToolButton *reverseButton = new QToolButton;
408 setupButton( reverseButton );
409 CONNECT_MAP_SET( reverseButton, REVERSE_ACTION );
410 BUTTON_SET_BAR( reverseButton );
411 reverseButton->setCheckable( true );
412 /* You should, of COURSE change this to the correct event,
413 when/if we have one, that tells us if trickplay is possible . */
414 CONNECT( this, inputIsTrickPlayable( bool ), reverseButton, setVisible( bool ) );
415 reverseButton->setVisible( false );
416 widget = reverseButton;
419 case SKIP_BACK_BUTTON: {
420 NORMAL_BUTTON( SKIP_BACK );
421 ENABLE_ON_INPUT( SKIP_BACKButton );
424 case SKIP_FW_BUTTON: {
425 NORMAL_BUTTON( SKIP_FW );
426 ENABLE_ON_INPUT( SKIP_FWButton );
430 NORMAL_BUTTON( QUIT );
433 case RANDOM_BUTTON: {
434 NORMAL_BUTTON( RANDOM );
435 RANDOMButton->setCheckable( true );
436 RANDOMButton->setChecked( var_GetBool( THEPL, "random" ) );
437 CONNECT( THEMIM, randomChanged( bool ),
438 RANDOMButton, setChecked( bool ) );
442 LoopButton *loopButton = new LoopButton;
443 setupButton( loopButton );
444 loopButton->setToolTip( qtr( "Click to toggle between loop all, loop one and no loop") );
445 loopButton->setCheckable( true );
446 int i_state = 2 * var_GetBool( THEPL, "loop" ) + var_GetBool( THEPL, "repeat" );
447 loopButton->updateButtonIcons( i_state );
448 CONNECT( THEMIM, repeatLoopChanged( int ), loopButton, updateButtonIcons( int ) );
449 CONNECT( loopButton, clicked(), THEMIM, loopRepeatLoopStatus() );
454 NORMAL_BUTTON( INFO );
457 case PLAYBACK_BUTTONS:{
458 widget = new QWidget;
459 DeckButtonsLayout *layout = new DeckButtonsLayout( widget );
460 BrowseButton *prev = new BrowseButton( widget, BrowseButton::Backward );
461 BrowseButton *next = new BrowseButton( widget );
462 RoundButton *play = new RoundButton( widget );
463 layout->setBackwardButton( prev );
464 layout->setForwardButton( next );
465 layout->setRoundButton( play );
466 CONNECT_MAP_SET( prev, PREVIOUS_ACTION );
467 CONNECT_MAP_SET( next, NEXT_ACTION );
468 CONNECT_MAP_SET( play, PLAY_ACTION );
471 case ASPECT_RATIO_COMBOBOX:
472 widget = new AspectRatioComboBox( p_intf );
473 widget->setMinimumHeight( 26 );
476 widget = new SpeedLabel( p_intf, this );
478 case TIME_LABEL_ELAPSED:
479 widget = new TimeLabel( p_intf, TimeLabel::Elapsed );
481 case TIME_LABEL_REMAINING:
482 widget = new TimeLabel( p_intf, TimeLabel::Remaining );
485 msg_Warn( p_intf, "This should not happen %i", button );
489 /* Customize Buttons */
490 if( b_flat || b_big )
492 QFrame *frame = qobject_cast<QFrame *>(widget);
495 QList<QToolButton *> allTButtons = frame->findChildren<QToolButton *>();
496 for( int i = 0; i < allTButtons.count(); i++ )
497 applyAttributes( allTButtons[i], b_flat, b_big );
501 QToolButton *tmpButton = qobject_cast<QToolButton *>(widget);
503 applyAttributes( tmpButton, b_flat, b_big );
510 void AbstractController::applyAttributes( QToolButton *tmpButton, bool b_flat, bool b_big )
515 tmpButton->setAutoRaise( b_flat );
518 tmpButton->setFixedSize( QSize( 32, 32 ) );
519 tmpButton->setIconSize( QSize( 26, 26 ) );
524 QFrame *AbstractController::discFrame()
526 /** Disc and Menus handling */
527 QFrame *discFrame = new QFrame( this );
529 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
530 discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );
532 QToolButton *prevSectionButton = new QToolButton( discFrame );
533 setupButton( prevSectionButton );
534 BUTTON_SET_BAR2( prevSectionButton, toolbar/dvd_prev,
535 qtr("Previous Chapter/Title" ) );
536 discLayout->addWidget( prevSectionButton );
538 QToolButton *menuButton = new QToolButton( discFrame );
539 setupButton( menuButton );
540 discLayout->addWidget( menuButton );
541 BUTTON_SET_BAR2( menuButton, toolbar/dvd_menu, qtr( "Menu" ) );
543 QToolButton *nextSectionButton = new QToolButton( discFrame );
544 setupButton( nextSectionButton );
545 discLayout->addWidget( nextSectionButton );
546 BUTTON_SET_BAR2( nextSectionButton, toolbar/dvd_next,
547 qtr("Next Chapter/Title" ) );
549 /* Change the navigation button display when the IM
550 navigation changes */
551 CONNECT( THEMIM->getIM(), chapterChanged( bool ),
552 discFrame, setVisible( bool ) );
553 CONNECT( THEMIM->getIM(), titleChanged( bool ),
554 menuButton, setVisible( bool ) );
555 /* Changes the IM navigation when triggered on the nav buttons */
556 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
558 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
560 CONNECT( menuButton, clicked(), THEMIM->getIM(),
566 QFrame *AbstractController::telexFrame()
571 QFrame *telexFrame = new QFrame( this );
572 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
573 telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );
574 CONNECT( THEMIM->getIM(), teletextPossible( bool ),
575 telexFrame, setVisible( bool ) );
578 QToolButton *telexOn = new QToolButton;
579 setupButton( telexOn );
580 BUTTON_SET_BAR2( telexOn, toolbar/tv, qtr( "Teletext Activation" ) );
581 telexOn->setEnabled( false );
582 telexOn->setCheckable( true );
584 telexLayout->addWidget( telexOn );
586 /* Teletext Activation and set */
587 CONNECT( telexOn, clicked( bool ),
588 THEMIM->getIM(), activateTeletext( bool ) );
589 CONNECT( THEMIM->getIM(), teletextPossible( bool ),
590 telexOn, setEnabled( bool ) );
592 /* Transparency button */
593 QToolButton *telexTransparent = new QToolButton;
594 setupButton( telexTransparent );
595 BUTTON_SET_BAR2( telexTransparent, toolbar/tvtelx,
596 qtr( "Toggle Transparency " ) );
597 telexTransparent->setEnabled( false );
598 telexTransparent->setCheckable( true );
599 telexLayout->addWidget( telexTransparent );
601 /* Transparency change and set */
602 CONNECT( telexTransparent, clicked( bool ),
603 THEMIM->getIM(), telexSetTransparency( bool ) );
604 CONNECT( THEMIM->getIM(), teletextTransparencyActivated( bool ),
605 telexTransparent, setChecked( bool ) );
609 QSpinBox *telexPage = new QSpinBox( telexFrame );
610 telexPage->setRange( 0, 999 );
611 telexPage->setValue( 100 );
612 telexPage->setAccelerated( true );
613 telexPage->setWrapping( true );
614 telexPage->setAlignment( Qt::AlignRight );
615 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
616 telexPage->setEnabled( false );
617 telexLayout->addWidget( telexPage );
619 /* Page change and set */
620 CONNECT( telexPage, valueChanged( int ),
621 THEMIM->getIM(), telexSetPage( int ) );
622 CONNECT( THEMIM->getIM(), newTelexPageSet( int ),
623 telexPage, setValue( int ) );
625 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexPage, setEnabled( bool ) );
626 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexTransparent, setEnabled( bool ) );
627 CONNECT( THEMIM->getIM(), teletextActivated( bool ), telexOn, setChecked( bool ) );
632 #undef CONNECT_MAP_SET
633 #undef BUTTON_SET_BAR
634 #undef BUTTON_SET_BAR2
635 #undef ENABLE_ON_VIDEO
636 #undef ENABLE_ON_INPUT
638 #include <QHBoxLayout>
639 /*****************************
640 * DA Control Widget !
641 *****************************/
642 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
645 AbstractController( _p_i, _parent )
647 RTL_UNAFFECTED_WIDGET
648 /* advanced Controls handling */
649 b_advancedVisible = b_advControls;
651 setStyleSheet( "background: red ");
653 setAttribute( Qt::WA_MacBrushedMetal);
654 controlLayout = new QVBoxLayout( this );
655 controlLayout->setContentsMargins( 3, 1, 0, 1 );
656 controlLayout->setSpacing( 0 );
657 QHBoxLayout *controlLayout1 = new QHBoxLayout;
658 controlLayout1->setSpacing( 0 ); controlLayout1->setMargin( 0 );
660 QString line1 = getSettings()->value( "MainWindow/MainToolbar1", MAIN_TB1_DEFAULT )
662 parseAndCreate( line1, controlLayout1 );
664 QHBoxLayout *controlLayout2 = new QHBoxLayout;
665 controlLayout2->setSpacing( 0 ); controlLayout2->setMargin( 0 );
666 QString line2 = getSettings()->value( "MainWindow/MainToolbar2", MAIN_TB2_DEFAULT )
668 parseAndCreate( line2, controlLayout2 );
670 grip = new QSizeGrip( this );
671 controlLayout2->addWidget( grip, 0, Qt::AlignBottom|Qt::AlignRight );
673 if( !b_advancedVisible && advControls ) advControls->hide();
675 controlLayout->addLayout( controlLayout1 );
676 controlLayout->addLayout( controlLayout2 );
679 void ControlsWidget::toggleAdvanced()
681 if( !advControls ) return;
683 advControls->setVisible( !b_advancedVisible );
684 b_advancedVisible = !b_advancedVisible;
685 emit advancedControlsToggled( b_advancedVisible );
688 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
689 AbstractController( _p_i, _parent )
691 RTL_UNAFFECTED_WIDGET
692 controlLayout = new QHBoxLayout( this );
693 controlLayout->setMargin( 0 );
694 controlLayout->setSpacing( 0 );
696 setStyleSheet( "background: orange ");
700 QString line = getSettings()->value( "MainWindow/AdvToolbar", ADV_TB_DEFAULT )
702 parseAndCreate( line, controlLayout );
705 InputControlsWidget::InputControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
706 AbstractController( _p_i, _parent )
708 RTL_UNAFFECTED_WIDGET
709 controlLayout = new QHBoxLayout( this );
710 controlLayout->setMargin( 0 );
711 controlLayout->setSpacing( 0 );
713 setStyleSheet( "background: green ");
716 QString line = getSettings()->value( "MainWindow/InputToolbar", INPT_TB_DEFAULT ).toString();
717 parseAndCreate( line, controlLayout );
719 /**********************************************************************
720 * Fullscrenn control widget
721 **********************************************************************/
722 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i, QWidget *_parent )
723 : AbstractController( _p_i, _parent )
725 RTL_UNAFFECTED_WIDGET
728 b_mouse_over = false;
729 i_mouse_last_move_x = -1;
730 i_mouse_last_move_y = -1;
731 #if HAVE_TRANSPARENCY
732 b_slow_hide_begin = false;
733 i_slow_hide_timeout = 1;
735 b_fullscreen = false;
741 setWindowFlags( Qt::ToolTip );
742 setMinimumWidth( FSC_WIDTH );
743 setMinimumHeight( FSC_HEIGHT );
746 setFrameShape( QFrame::StyledPanel );
747 setFrameStyle( QFrame::Sunken );
748 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
750 QVBoxLayout *controlLayout2 = new QVBoxLayout( this );
751 controlLayout2->setContentsMargins( 4, 6, 4, 2 );
754 InputControlsWidget *inputC = new InputControlsWidget( p_intf, this );
755 controlLayout2->addWidget( inputC );
757 controlLayout = new QHBoxLayout;
758 QString line = getSettings()->value( "MainWindow/FSCtoolbar", FSC_TB_DEFAULT ).toString();
759 parseAndCreate( line, controlLayout );
760 controlLayout2->addLayout( controlLayout );
763 p_hideTimer = new QTimer( this );
764 p_hideTimer->setSingleShot( true );
765 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
767 /* slow hiding timer */
768 #if HAVE_TRANSPARENCY
769 p_slowHideTimer = new QTimer( this );
770 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
771 f_opacity = var_InheritFloat( p_intf, "qt-fs-opacity" );
774 vlc_mutex_init_recursive( &lock );
776 DCONNECT( THEMIM->getIM(), voutListChanged( vout_thread_t **, int ),
777 this, setVoutList( vout_thread_t **, int ) );
780 previousPosition = getSettings()->value( "FullScreen/pos" ).toPoint();
781 screenRes = getSettings()->value( "FullScreen/screen" ).toRect();
782 isWideFSC = getSettings()->value( "FullScreen/wide" ).toBool();
783 i_screennumber = var_InheritInteger( p_intf, "qt-fullscreen-screennumber" );
786 FullscreenControllerWidget::~FullscreenControllerWidget()
788 getSettings()->setValue( "FullScreen/pos", previousPosition );
789 getSettings()->setValue( "FullScreen/screen", screenRes );
790 getSettings()->setValue( "FullScreen/wide", isWideFSC );
792 setVoutList( NULL, 0 );
793 vlc_mutex_destroy( &lock );
796 void FullscreenControllerWidget::restoreFSC()
800 /* Restore half-bar and re-centre if needed */
801 setMinimumWidth( FSC_WIDTH );
804 QRect currentRes = QApplication::desktop()->screenGeometry( targetScreen() );
806 if( currentRes == screenRes &&
807 QApplication::desktop()->screen()->geometry().contains( previousPosition, true ) )
809 /* Restore to the last known position */
810 move( previousPosition );
814 /* FSC is out of screen or screen resolution changed */
815 msg_Dbg( p_intf, "Recentering the Fullscreen Controller" );
816 centerFSC( targetScreen() );
817 screenRes = currentRes;
818 previousPosition = pos();
823 /* Dock at the bottom of the screen */
824 updateFullwidthGeometry( targetScreen() );
828 // Tell kwin that we do not want a shadow around the fscontroller
829 setMask( QRegion( 0, 0, width(), height() ) );
833 void FullscreenControllerWidget::centerFSC( int number )
835 QRect currentRes = QApplication::desktop()->screenGeometry( number );
837 /* screen has changed, calculate new position */
838 QPoint pos = QPoint( currentRes.x() + (currentRes.width() / 2) - (width() / 2),
839 currentRes.y() + currentRes.height() - height());
844 * Show fullscreen controller
846 void FullscreenControllerWidget::showFSC()
850 #if HAVE_TRANSPARENCY
851 setWindowOpacity( f_opacity );
858 * Plane to hide fullscreen controller
860 void FullscreenControllerWidget::planHideFSC()
862 vlc_mutex_lock( &lock );
863 int i_timeout = i_hide_timeout;
864 vlc_mutex_unlock( &lock );
866 p_hideTimer->start( i_timeout );
868 #if HAVE_TRANSPARENCY
869 b_slow_hide_begin = true;
870 i_slow_hide_timeout = i_timeout;
871 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
876 * Hidding fullscreen controller slowly
877 * Linux: need composite manager
878 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
880 void FullscreenControllerWidget::slowHideFSC()
882 #if HAVE_TRANSPARENCY
883 if( b_slow_hide_begin )
885 b_slow_hide_begin = false;
887 p_slowHideTimer->stop();
888 /* the last part of time divided to 100 pieces */
889 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
894 if ( windowOpacity() > 0.0 )
896 /* we should use 0.01 because of 100 pieces ^^^
897 but than it cannt be done in time */
898 setWindowOpacity( windowOpacity() - 0.02 );
901 if ( windowOpacity() <= 0.0 )
902 p_slowHideTimer->stop();
907 void FullscreenControllerWidget::updateFullwidthGeometry( int number )
909 QRect screenGeometry = QApplication::desktop()->screenGeometry( number );
910 setMinimumWidth( screenGeometry.width() );
911 setGeometry( screenGeometry.x(), screenGeometry.y() + screenGeometry.height() - FSC_HEIGHT, screenGeometry.width(), FSC_HEIGHT );
915 void FullscreenControllerWidget::toggleFullwidth()
917 /* Toggle isWideFSC switch */
918 isWideFSC = !isWideFSC;
923 int FullscreenControllerWidget::targetScreen()
925 if( i_screennumber == -1 || i_screennumber > QApplication::desktop()->numScreens() )
926 return QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
927 return i_screennumber;
932 * events: show, hide, start timer for hiding
934 void FullscreenControllerWidget::customEvent( QEvent *event )
938 switch( (int)event->type() )
940 /* This is used when the 'i' hotkey is used, to force quick toggle */
941 case IMEvent::FullscreenControlToggle:
942 vlc_mutex_lock( &lock );
944 vlc_mutex_unlock( &lock );
957 /* Event called to Show the FSC on mouseChanged() */
958 case IMEvent::FullscreenControlShow:
959 vlc_mutex_lock( &lock );
961 vlc_mutex_unlock( &lock );
967 /* Start the timer to hide later, called usually with above case */
968 case IMEvent::FullscreenControlPlanHide:
969 if( !b_mouse_over ) // Only if the mouse is not over FSC
973 case IMEvent::FullscreenControlHide:
985 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
987 if( event->buttons() == Qt::LeftButton )
989 if( i_mouse_last_x == -1 || i_mouse_last_y == -1 )
992 int i_moveX = event->globalX() - i_mouse_last_x;
993 int i_moveY = event->globalY() - i_mouse_last_y;
995 move( x() + i_moveX, y() + i_moveY );
997 i_mouse_last_x = event->globalX();
998 i_mouse_last_y = event->globalY();
1004 * store position of cursor
1006 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1008 if( isWideFSC ) return;
1009 i_mouse_last_x = event->globalX();
1010 i_mouse_last_y = event->globalY();
1014 void FullscreenControllerWidget::mouseReleaseEvent( QMouseEvent *event )
1016 if( isWideFSC ) return;
1017 i_mouse_last_x = -1;
1018 i_mouse_last_y = -1;
1021 // Save the new FSC position
1022 previousPosition = pos();
1026 * On mouse go above FSC
1028 void FullscreenControllerWidget::enterEvent( QEvent *event )
1030 b_mouse_over = true;
1032 p_hideTimer->stop();
1033 #if HAVE_TRANSPARENCY
1034 p_slowHideTimer->stop();
1035 setWindowOpacity( f_opacity );
1041 * On mouse go out from FSC
1043 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1047 b_mouse_over = false;
1052 * When you get pressed key, send it to video output
1054 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1056 emit keyPressed( event );
1060 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object,
1061 const char *variable, vlc_value_t old_val,
1062 vlc_value_t new_val, void *data )
1064 VLC_UNUSED( variable ); VLC_UNUSED( old_val );
1066 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1068 msg_Dbg( p_vout, "Qt: Fullscreen state changed" );
1069 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1071 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1076 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1077 vlc_value_t old_val, vlc_value_t new_val,
1080 VLC_UNUSED( variable ); VLC_UNUSED( old_val );
1082 vout_thread_t *p_vout = (vout_thread_t *)vlc_object;
1083 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1085 /* Get the value from the Vout - Trust the vout more than Qt */
1086 p_fs->mouseChanged( p_vout, new_val.coords.x, new_val.coords.y );
1092 * It is call to update the list of vout handled by the fullscreen controller
1094 void FullscreenControllerWidget::setVoutList( vout_thread_t **pp_vout, int i_vout )
1096 QList<vout_thread_t*> del;
1097 QList<vout_thread_t*> add;
1099 QList<vout_thread_t*> set;
1102 for( int i = 0; i < i_vout; i++ )
1105 /* Vout to remove */
1106 vlc_mutex_lock( &lock );
1107 foreach( vout_thread_t *p_vout, vout )
1109 if( !set.contains( p_vout ) )
1112 vlc_mutex_unlock( &lock );
1114 foreach( vout_thread_t *p_vout, del )
1116 var_DelCallback( p_vout, "fullscreen",
1117 FullscreenControllerWidgetFullscreenChanged, this );
1118 vlc_mutex_lock( &lock );
1119 fullscreenChanged( p_vout, false, 0 );
1120 vout.removeAll( p_vout );
1121 vlc_mutex_unlock( &lock );
1123 vlc_object_release( VLC_OBJECT(p_vout) );
1127 vlc_mutex_lock( &lock );
1128 foreach( vout_thread_t *p_vout, set )
1130 if( !vout.contains( p_vout ) )
1133 vlc_mutex_unlock( &lock );
1135 foreach( vout_thread_t *p_vout, add )
1137 vlc_object_hold( VLC_OBJECT(p_vout) );
1139 vlc_mutex_lock( &lock );
1140 vout.append( p_vout );
1141 var_AddCallback( p_vout, "fullscreen",
1142 FullscreenControllerWidgetFullscreenChanged, this );
1143 /* I miss a add and fire */
1144 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ),
1145 var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1146 vlc_mutex_unlock( &lock );
1150 * Register and unregister callback for mouse moving
1152 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout,
1153 bool b_fs, int i_timeout )
1155 /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
1157 vlc_mutex_lock( &lock );
1158 /* Entering fullscreen, register callback */
1159 if( b_fs && !b_fullscreen )
1161 msg_Dbg( p_vout, "Qt: Entering Fullscreen" );
1162 b_fullscreen = true;
1163 i_hide_timeout = i_timeout;
1164 var_AddCallback( p_vout, "mouse-moved",
1165 FullscreenControllerWidgetMouseMoved, this );
1167 /* Quitting fullscreen, unregistering callback */
1168 else if( !b_fs && b_fullscreen )
1170 msg_Dbg( p_vout, "Qt: Quitting Fullscreen" );
1171 b_fullscreen = false;
1172 i_hide_timeout = i_timeout;
1173 var_DelCallback( p_vout, "mouse-moved",
1174 FullscreenControllerWidgetMouseMoved, this );
1176 /* Force fs hiding */
1177 IMEvent *eHide = new IMEvent( IMEvent::FullscreenControlHide, 0 );
1178 QApplication::postEvent( this, eHide );
1180 vlc_mutex_unlock( &lock );
1184 * Mouse change callback (show/hide the controller on mouse movement)
1186 void FullscreenControllerWidget::mouseChanged( vout_thread_t *, int i_mousex, int i_mousey )
1190 /* FIXME - multiple vout (ie multiple mouse position ?) and thread safety if multiple vout ? */
1193 if( ( i_mouse_last_move_x == -1 || i_mouse_last_move_y == -1 ) ||
1194 ( abs( i_mouse_last_move_x - i_mousex ) > 2 ||
1195 abs( i_mouse_last_move_y - i_mousey ) > 2 ) )
1197 i_mouse_last_move_x = i_mousex;
1198 i_mouse_last_move_y = i_mousey;
1205 IMEvent *eShow = new IMEvent( IMEvent::FullscreenControlShow, 0 );
1206 QApplication::postEvent( this, eShow );
1208 /* Plan hide event */
1209 IMEvent *eHide = new IMEvent( IMEvent::FullscreenControlPlanHide, 0 );
1210 QApplication::postEvent( this, eHide );