1 /*****************************************************************************
2 * Controller.cpp : Controller for the main interface
3 ****************************************************************************
4 * Copyright ( C ) 2006-2008 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
9 * Rafaël Carré <funman@videolanorg>
10 * Ilkka Ollakka <ileoo@videolan.org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * ( at your option ) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
34 #include "components/controller.hpp"
35 #include "components/controller_widget.hpp"
36 #include "components/interface_widgets.hpp"
38 #include "dialogs_provider.hpp"
39 #include "input_manager.hpp"
41 #include "util/input_slider.hpp" /* InputSlider */
42 #include "util/customwidgets.hpp" /* qEventToKey */
44 #include <QSpacerItem>
45 #include <QToolButton>
46 #include <QHBoxLayout>
47 #include <QSignalMapper>
50 /**********************************************************************
52 **********************************************************************/
55 * This is an abstract Toolbar/Controller
56 * This has helper to create any toolbar, any buttons and to manage the actions
59 AbstractController::AbstractController( intf_thread_t * _p_i, QWidget *_parent )
65 /* Main action provider */
66 toolbarActionsMapper = new QSignalMapper( this );
67 CONNECT( toolbarActionsMapper, mapped( int ), this, doAction( int ) );
68 CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
71 /* Reemit some signals on status Change to activate some buttons */
72 void AbstractController::setStatus( int status )
74 bool b_hasInput = THEMIM->getIM()->hasInput();
75 /* Activate the interface buttons according to the presence of the input */
76 emit inputExists( b_hasInput );
78 emit inputPlaying( status == PLAYING_S );
80 emit inputIsRecordable( b_hasInput &&
81 var_GetBool( THEMIM->getInput(), "can-record" ) );
84 /* Generic button setup */
85 void AbstractController::setupButton( QAbstractButton *aButton )
87 static QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
88 sizePolicy.setHorizontalStretch( 0 );
89 sizePolicy.setVerticalStretch( 0 );
91 aButton->setSizePolicy( sizePolicy );
92 aButton->setFixedSize( QSize( 26, 26 ) );
93 aButton->setIconSize( QSize( 20, 20 ) );
94 aButton->setFocusPolicy( Qt::NoFocus );
97 /* Open the generic config line for the toolbar, parse it
98 * and create the widgets accordingly */
99 void AbstractController::parseAndCreate( QString config,
100 QBoxLayout *controlLayout )
102 QStringList list = config.split( ";", QString::SkipEmptyParts ) ;
103 for( int i = 0; i < list.size(); i++ )
105 QStringList list2 = list.at( i ).split( "-" );
106 if( list2.size() < 1 )
108 msg_Warn( p_intf, "Parsing error. Report this" );
113 int i_option = WIDGET_NORMAL;
114 buttonType_e i_type = (buttonType_e)list2.at( 0 ).toInt( &ok );
117 msg_Warn( p_intf, "Parsing error 0. Please report this" );
121 if( list2.size() > 1 )
123 i_option = list2.at( 1 ).toInt( &ok );
126 msg_Warn( p_intf, "Parsing error 1. Please report this" );
131 createAndAddWidget( controlLayout, -1, i_type, i_option );
135 void AbstractController::createAndAddWidget( QBoxLayout *controlLayout,
140 /* Special case for SPACERS, who aren't QWidgets */
141 if( i_type == WIDGET_SPACER )
143 controlLayout->insertSpacing( i_index, 16 );
147 if( i_type == WIDGET_SPACER_EXTEND )
149 controlLayout->insertStretch( i_index, 16 );
153 QWidget *widg = createWidget( i_type, i_option );
156 controlLayout->insertWidget( i_index, widg );
160 #define CONNECT_MAP( a ) CONNECT( a, clicked(), toolbarActionsMapper, map() )
161 #define SET_MAPPING( a, b ) toolbarActionsMapper->setMapping( a , b )
162 #define CONNECT_MAP_SET( a, b ) \
165 #define BUTTON_SET_BAR( a_button ) \
166 a_button->setToolTip( tooltipL[button] ); \
167 a_button->setIcon( QIcon( iconL[button] ) );
168 #define BUTTON_SET_BAR2( button, image, tooltip ) \
169 button->setToolTip( tooltip ); \
170 button->setIcon( QIcon( ":/"#image ) );
173 #define ENABLE_ON_VIDEO( a ) \
174 CONNECT( THEMIM->getIM(), voutChanged( bool ), a, setEnabled( bool ) ); \
175 a->setEnabled( THEMIM->getIM()->hasVideo() ); /* TODO: is this necessary? when input is started before the interface? */
177 #define ENABLE_ON_INPUT( a ) \
178 CONNECT( this, inputExists( bool ), a, setEnabled( bool ) ); \
179 a->setEnabled( THEMIM->getIM()->hasInput() ); /* TODO: is this necessary? when input is started before the interface? */
181 QWidget *AbstractController::createWidget( buttonType_e button, int options )
184 bool b_flat = options & WIDGET_FLAT;
185 bool b_big = options & WIDGET_BIG;
186 bool b_shiny = options & WIDGET_SHINY;
188 QWidget *widget = NULL;
192 PlayButton *playButton = new PlayButton;
193 setupButton( playButton );
194 BUTTON_SET_BAR( playButton );
195 CONNECT_MAP_SET( playButton, PLAY_ACTION );
196 CONNECT( this, inputPlaying( bool ),
197 playButton, updateButton( bool ));
202 QToolButton *stopButton = new QToolButton;
203 setupButton( stopButton );
204 CONNECT_MAP_SET( stopButton, STOP_ACTION );
205 BUTTON_SET_BAR( stopButton );
210 QToolButton *openButton = new QToolButton;
211 setupButton( openButton );
212 CONNECT_MAP_SET( openButton, OPEN_ACTION );
213 BUTTON_SET_BAR( openButton );
217 case PREVIOUS_BUTTON:{
218 QToolButton *prevButton = new QToolButton;
219 setupButton( prevButton );
220 CONNECT_MAP_SET( prevButton, PREVIOUS_ACTION );
221 BUTTON_SET_BAR( prevButton );
227 QToolButton *nextButton = new QToolButton;
228 setupButton( nextButton );
229 CONNECT_MAP_SET( nextButton, NEXT_ACTION );
230 BUTTON_SET_BAR( nextButton );
235 QToolButton *slowerButton = new QToolButton;
236 setupButton( slowerButton );
237 CONNECT_MAP_SET( slowerButton, SLOWER_ACTION );
238 BUTTON_SET_BAR( slowerButton );
239 ENABLE_ON_INPUT( slowerButton );
240 widget = slowerButton;
244 QToolButton *fasterButton = new QToolButton;
245 setupButton( fasterButton );
246 CONNECT_MAP_SET( fasterButton, FASTER_ACTION );
247 BUTTON_SET_BAR( fasterButton );
248 ENABLE_ON_INPUT( fasterButton );
249 widget = fasterButton;
253 QToolButton *frameButton = new QToolButton;
254 setupButton( frameButton );
255 CONNECT_MAP_SET( frameButton, FRAME_ACTION );
256 BUTTON_SET_BAR( frameButton );
257 ENABLE_ON_VIDEO( frameButton );
258 widget = frameButton;
261 case FULLSCREEN_BUTTON:{
262 QToolButton *fullscreenButton = new QToolButton;
263 setupButton( fullscreenButton );
264 CONNECT_MAP_SET( fullscreenButton, FULLSCREEN_ACTION );
265 BUTTON_SET_BAR( fullscreenButton );
266 ENABLE_ON_VIDEO( fullscreenButton );
267 widget = fullscreenButton;
270 case DEFULLSCREEN_BUTTON:{
271 QToolButton *fullscreenButton = new QToolButton;
272 setupButton( fullscreenButton );
273 CONNECT_MAP_SET( fullscreenButton, FULLSCREEN_ACTION );
274 BUTTON_SET_BAR( fullscreenButton )
275 ENABLE_ON_VIDEO( fullscreenButton );
276 widget = fullscreenButton;
279 case EXTENDED_BUTTON:{
280 QToolButton *extSettingsButton = new QToolButton;
281 setupButton( extSettingsButton );
282 CONNECT_MAP_SET( extSettingsButton, EXTENDED_ACTION );
283 BUTTON_SET_BAR( extSettingsButton )
284 widget = extSettingsButton;
287 case PLAYLIST_BUTTON:{
288 QToolButton *playlistButton = new QToolButton;
289 setupButton( playlistButton );
290 CONNECT_MAP_SET( playlistButton, PLAYLIST_ACTION );
291 BUTTON_SET_BAR( playlistButton );
292 widget = playlistButton;
295 case SNAPSHOT_BUTTON:{
296 QToolButton *snapshotButton = new QToolButton;
297 setupButton( snapshotButton );
298 CONNECT_MAP_SET( snapshotButton, SNAPSHOT_ACTION );
299 BUTTON_SET_BAR( snapshotButton );
300 ENABLE_ON_VIDEO( snapshotButton );
301 widget = snapshotButton;
305 QToolButton *recordButton = new QToolButton;
306 setupButton( recordButton );
307 CONNECT_MAP_SET( recordButton, RECORD_ACTION );
308 BUTTON_SET_BAR( recordButton );
309 ENABLE_ON_INPUT( recordButton );
310 widget = recordButton;
314 AtoB_Button *ABButton = new AtoB_Button;
315 setupButton( ABButton );
316 BUTTON_SET_BAR( ABButton );
317 ENABLE_ON_INPUT( ABButton );
318 CONNECT_MAP_SET( ABButton, ATOB_ACTION );
319 CONNECT( THEMIM->getIM(), AtoBchanged( bool, bool),
320 ABButton, setIcons( bool, bool ) );
325 InputSlider *slider = new InputSlider( Qt::Horizontal, NULL );
327 /* Update the position when the IM has changed */
328 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
329 slider, setPosition( float, int, int ) );
330 /* And update the IM, when the position has changed */
331 CONNECT( slider, sliderDragged( float ),
332 THEMIM->getIM(), sliderUpdate( float ) );
337 widget = discFrame();
340 case TELETEXT_BUTTONS:
341 widget = telexFrame();
346 SoundWidget *snd = new SoundWidget( this, p_intf, b_shiny );
352 TimeLabel *timeLabel = new TimeLabel( p_intf );
358 QFrame *line = new QFrame;
359 line->setFrameShape( QFrame::VLine );
360 line->setFrameShadow( QFrame::Raised );
361 line->setLineWidth( 0 );
362 line->setMidLineWidth( 1 );
366 case ADVANCED_CONTROLLER:
368 advControls = new AdvControlsWidget( p_intf, this );
369 widget = advControls;
372 case REVERSE_BUTTON:{
373 QToolButton *reverseButton = new QToolButton;
374 setupButton( reverseButton );
375 CONNECT_MAP_SET( reverseButton, REVERSE_ACTION );
376 BUTTON_SET_BAR( reverseButton );
377 ENABLE_ON_INPUT( reverseButton );
378 widget = reverseButton;
381 case SKIP_BACK_BUTTON: {
382 QToolButton *skipBakButton = new QToolButton;
383 setupButton( skipBakButton );
384 CONNECT_MAP_SET( skipBakButton, SKIP_BACK_ACTION );
385 BUTTON_SET_BAR( skipBakButton );
386 ENABLE_ON_INPUT( skipBakButton );
387 widget = skipBakButton;
390 case SKIP_FW_BUTTON: {
391 QToolButton *skipFwButton = new QToolButton;
392 setupButton( skipFwButton );
393 CONNECT_MAP_SET( skipFwButton, SKIP_FW_ACTION );
394 BUTTON_SET_BAR( skipFwButton );
395 ENABLE_ON_INPUT( skipFwButton );
396 widget = skipFwButton;
400 msg_Warn( p_intf, "This should not happen %i", button );
404 /* Customize Buttons */
405 if( b_flat || b_big )
407 QToolButton *tmpButton = qobject_cast<QToolButton *>(widget);
411 tmpButton->setAutoRaise( b_flat );
414 tmpButton->setFixedSize( QSize( 32, 32 ) );
415 tmpButton->setIconSize( QSize( 26, 26 ) );
422 QWidget *AbstractController::discFrame()
424 /** Disc and Menus handling */
425 QWidget *discFrame = new QWidget( this );
427 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
428 discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );
430 QToolButton *prevSectionButton = new QToolButton( discFrame );
431 setupButton( prevSectionButton );
432 BUTTON_SET_BAR2( prevSectionButton, dvd_prev,
433 qtr("Previous Chapter/Title" ) );
434 discLayout->addWidget( prevSectionButton );
436 QToolButton *menuButton = new QToolButton( discFrame );
437 setupButton( menuButton );
438 discLayout->addWidget( menuButton );
439 BUTTON_SET_BAR2( menuButton, dvd_menu, qtr( "Menu" ) );
441 QToolButton *nextSectionButton = new QToolButton( discFrame );
442 setupButton( nextSectionButton );
443 discLayout->addWidget( nextSectionButton );
444 BUTTON_SET_BAR2( nextSectionButton, dvd_next,
445 qtr("Next Chapter/Title" ) );
447 /* Change the navigation button display when the IM
448 navigation changes */
449 CONNECT( THEMIM->getIM(), titleChanged( bool ),
450 discFrame, setVisible( bool ) );
451 CONNECT( THEMIM->getIM(), chapterChanged( bool ),
452 menuButton, setVisible( bool ) );
453 /* Changes the IM navigation when triggered on the nav buttons */
454 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
456 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
458 CONNECT( menuButton, clicked(), THEMIM->getIM(),
464 QWidget *AbstractController::telexFrame()
469 TeletextController *telexFrame = new TeletextController;
470 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
471 telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );
472 CONNECT( THEMIM->getIM(), teletextPossible( bool ),
473 telexFrame, setVisible( bool ) );
476 QToolButton *telexOn = new QToolButton;
477 telexFrame->telexOn = telexOn;
478 setupButton( telexOn );
479 BUTTON_SET_BAR2( telexOn, tv, qtr( "Teletext Activation" ) );
480 telexLayout->addWidget( telexOn );
482 /* Teletext Activation and set */
483 CONNECT( telexOn, clicked( bool ),
484 THEMIM->getIM(), activateTeletext( bool ) );
485 CONNECT( THEMIM->getIM(), teletextActivated( bool ),
486 telexFrame, enableTeletextButtons( bool ) );
489 /* Transparency button */
490 QToolButton *telexTransparent = new QToolButton;
491 telexFrame->telexTransparent = telexTransparent;
492 setupButton( telexTransparent );
493 BUTTON_SET_BAR2( telexTransparent, tvtelx,
494 qtr( "Toggle Transparency " ) );
495 telexTransparent->setEnabled( false );
496 telexLayout->addWidget( telexTransparent );
498 /* Transparency change and set */
499 CONNECT( telexTransparent, clicked( bool ),
500 THEMIM->getIM(), telexSetTransparency( bool ) );
501 CONNECT( THEMIM->getIM(), teletextTransparencyActivated( bool ),
502 telexFrame, toggleTeletextTransparency( bool ) );
506 QSpinBox *telexPage = new QSpinBox;
507 telexFrame->telexPage = telexPage;
508 telexPage->setRange( 0, 999 );
509 telexPage->setValue( 100 );
510 telexPage->setAccelerated( true );
511 telexPage->setWrapping( true );
512 telexPage->setAlignment( Qt::AlignRight );
513 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
514 telexPage->setEnabled( false );
515 telexLayout->addWidget( telexPage );
517 /* Page change and set */
518 CONNECT( telexPage, valueChanged( int ),
519 THEMIM->getIM(), telexSetPage( int ) );
520 CONNECT( THEMIM->getIM(), newTelexPageSet( int ),
521 telexPage, setValue( int ) );
527 #undef CONNECT_MAP_SET
528 #undef BUTTON_SET_BAR
529 #undef ENABLE_ON_VIDEO
530 #undef ENABLE_ON_INPUT
533 void AbstractController::doAction( int id_action )
539 case PREVIOUS_ACTION:
549 case FULLSCREEN_ACTION:
551 case EXTENDED_ACTION:
552 extSettings(); break;
553 case PLAYLIST_ACTION:
555 case SNAPSHOT_ACTION:
560 THEMIM->getIM()->setAtoB(); break;
565 case SKIP_BACK_ACTION:
566 var_SetInteger( p_intf->p_libvlc, "key-pressed",
567 ACTIONID_JUMP_BACKWARD_SHORT );
570 var_SetInteger( p_intf->p_libvlc, "key-pressed",
571 ACTIONID_JUMP_FORWARD_SHORT );
574 msg_Dbg( p_intf, "Action: %i", id_action );
579 void AbstractController::stop()
584 void AbstractController::play()
586 if( THEPL->current.i_size == 0 )
588 /* The playlist is empty, open a file requester */
589 THEDP->openFileDialog();
592 THEMIM->togglePlayPause();
595 void AbstractController::prev()
600 void AbstractController::next()
607 * This functions toggle the fullscreen mode
608 * If there is no video, it should first activate Visualisations...
609 * This has also to be fixed in enableVideo()
611 void AbstractController::fullscreen()
613 vout_thread_t *p_vout =
614 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
617 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
618 vlc_object_release( p_vout );
622 void AbstractController::snapshot()
624 vout_thread_t *p_vout =
625 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
628 vout_Control( p_vout, VOUT_SNAPSHOT );
629 vlc_object_release( p_vout );
633 void AbstractController::extSettings()
635 THEDP->extendedDialog();
638 void AbstractController::reverse()
640 THEMIM->getIM()->reverse();
643 void AbstractController::slower()
645 THEMIM->getIM()->slower();
648 void AbstractController::faster()
650 THEMIM->getIM()->faster();
653 void AbstractController::playlist()
655 if( p_intf->p_sys->p_mi ) p_intf->p_sys->p_mi->togglePlaylist();
658 void AbstractController::record()
660 input_thread_t *p_input = THEMIM->getInput();
663 /* This method won't work fine if the stream can't be cut anywhere */
664 const bool b_recording = var_GetBool( p_input, "record" );
665 var_SetBool( p_input, "record", !b_recording );
669 /* 'record' access-filter is not loaded, we open Save dialog */
670 input_item_t *p_item = input_GetItem( p_input );
674 char *psz = input_item_GetURI( p_item );
676 THEDP->streamingDialog( NULL, psz, true );
682 void AbstractController::frame()
684 input_thread_t *p_input = THEMIM->getInput();
686 var_SetVoid( p_input, "frame-next" );
689 #include <QHBoxLayout>
690 /*****************************
691 * DA Control Widget !
692 *****************************/
693 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
696 AbstractController( _p_i, _parent )
698 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
700 /* advanced Controls handling */
701 b_advancedVisible = b_advControls;
703 QVBoxLayout *controlLayout = new QVBoxLayout( this );
704 controlLayout->setLayoutMargins( 6, 4, 6, 2, 5 );
705 controlLayout->setSpacing( 0 );
706 QHBoxLayout *controlLayout1 = new QHBoxLayout;
707 controlLayout1->setSpacing( 0 );
709 QString line1 = getSettings()->value( "MainWindow/MainToolbar1",
710 "64;36;37;38;65").toString();
711 parseAndCreate( line1, controlLayout1 );
713 /* QString line2 = QString( "%1-2;%2;%3;%4;%5;%6;%6;%7;%8;%9;%6;%10;%11-4")
714 .arg( PLAY_BUTTON ) .arg( WIDGET_SPACER )
715 .arg( PREVIOUS_BUTTON ) .arg( STOP_BUTTON )
716 .arg( NEXT_BUTTON ) .arg( WIDGET_SPACER )
717 .arg( FULLSCREEN_BUTTON ) .arg( PLAYLIST_BUTTON )
718 .arg( EXTENDED_BUTTON ) .arg( WIDGET_SPACER_EXTEND )
720 msg_Dbg( p_intf, "%s", qtu( line2 )); */
722 QHBoxLayout *controlLayout2 = new QHBoxLayout;
723 controlLayout2->setSpacing( 0 );
724 QString line2 = getSettings()->value( "MainWindow/MainToolbar2",
725 "0-2;64;3;1;4;64;7;10;9;65;34-4" ).toString();
726 parseAndCreate( line2, controlLayout2 );
728 if( !b_advancedVisible && advControls ) advControls->hide();
730 controlLayout->addLayout( controlLayout1 );
731 controlLayout->addLayout( controlLayout2 );
734 ControlsWidget::~ControlsWidget()
737 void ControlsWidget::toggleAdvanced()
739 if( !advControls ) return;
741 if( !b_advancedVisible )
744 b_advancedVisible = true;
749 b_advancedVisible = false;
751 emit advancedControlsToggled( b_advancedVisible );
754 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
755 AbstractController( _p_i, _parent )
757 controlLayout = new QHBoxLayout( this );
758 controlLayout->setMargin( 0 );
759 controlLayout->setSpacing( 0 );
761 /* QString line = QString( "%1;%2;%3").arg( RECORD_BUTTON )
762 .arg( SNAPSHOT_BUTTON )
764 .arg( FRAME_BUTTON ); */
766 QString line = getSettings()->value( "MainWindow/AdvToolbar",
767 "12;11;13;14" ).toString();
768 parseAndCreate( line, controlLayout );
771 InputControlsWidget::InputControlsWidget( intf_thread_t *_p_i, QWidget *_parent ) :
772 AbstractController( _p_i, _parent )
774 controlLayout = new QHBoxLayout( this );
775 controlLayout->setMargin( 0 );
776 controlLayout->setSpacing( 0 );
778 /* QString line = QString( "%1-%2;%3;%4-%2")
779 .arg( SLOWER_BUTTON ).arg( WIDGET_FLAT )
781 .arg( FASTER_BUTTON ); */
782 QString line = getSettings()->value( "MainWindow/InputToolbar",
783 "5-1;33;6-1" ).toString();
784 parseAndCreate( line, controlLayout );
786 /**********************************************************************
787 * Fullscrenn control widget
788 **********************************************************************/
789 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i )
790 : AbstractController( _p_i )
794 b_mouse_over = false;
795 i_mouse_last_move_x = -1;
796 i_mouse_last_move_y = -1;
797 #if HAVE_TRANSPARENCY
798 b_slow_hide_begin = false;
799 i_slow_hide_timeout = 1;
801 b_fullscreen = false;
806 setWindowFlags( Qt::ToolTip );
807 setMinimumWidth( 600 );
809 setFrameShape( QFrame::StyledPanel );
810 setFrameStyle( QFrame::Sunken );
811 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
813 controlLayout = new QHBoxLayout( this );
814 controlLayout->setLayoutMargins( 5, 2, 5, 2, 5 );
817 InputControlsWidget *inputC = new InputControlsWidget( p_intf, this );
818 controlLayout->addWidget( inputC );
821 /* QString line = QString( "%1-2;%2;%3;%4;%5;%2;%6;%2;%7;%2;%8;%9;%10-4")
823 .arg( WIDGET_SPACER )
824 .arg( PREVIOUS_BUTTON )
828 .arg( TELETEXT_BUTTONS )
829 .arg( DEFULLSCREEN_BUTTON )
830 .arg( WIDGET_SPACER_EXTEND )
834 QString line = getSettings()->value( "MainWindow/FSCtoolbar",
835 "0-2;64;3;1;4;64;36;64;37;64;8;65;35-4;34" ).toString();
836 parseAndCreate( line, controlLayout );
839 p_hideTimer = new QTimer( this );
840 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
841 p_hideTimer->setSingleShot( true );
843 /* slow hiding timer */
844 #if HAVE_TRANSPARENCY
845 p_slowHideTimer = new QTimer( this );
846 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
849 adjustSize (); /* need to get real width and height for moving */
852 setWindowOpacity( 0.0 );
858 vlc_mutex_init_recursive( &lock );
861 FullscreenControllerWidget::~FullscreenControllerWidget()
863 getSettings()->setValue( "FullScreen/pos", pos() );
865 vlc_mutex_destroy( &lock );
869 * Show fullscreen controller
871 void FullscreenControllerWidget::showFSC()
875 int number = QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi );
876 if( number != i_screennumber )
878 msg_Dbg( p_intf, "Calculation fullscreen controllers center");
879 /* screen has changed, calculate new position */
880 QRect screenRes = QApplication::desktop()->screenGeometry(number);
881 QPoint pos = QPoint( screenRes.x() + (screenRes.width() / 2) - (width() / 2),
882 screenRes.y() + screenRes.height() - height());
884 i_screennumber = number;
887 // after quiting and going to fs, we need to call show()
893 setWindowOpacity( 1.0 );
899 #if HAVE_TRANSPARENCY
900 setWindowOpacity( DEFAULT_OPACITY );
905 * Hide fullscreen controller
906 * FIXME: under windows it have to be done by moving out of screen
907 * because hide() doesnt work
909 void FullscreenControllerWidget::hideFSC()
913 setWindowOpacity( 0.0 ); // simulate hidding
920 * Plane to hide fullscreen controller
922 void FullscreenControllerWidget::planHideFSC()
924 vlc_mutex_lock( &lock );
925 int i_timeout = i_hide_timeout;
926 vlc_mutex_unlock( &lock );
928 p_hideTimer->start( i_timeout );
930 #if HAVE_TRANSPARENCY
931 b_slow_hide_begin = true;
932 i_slow_hide_timeout = i_timeout;
933 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
938 * Hidding fullscreen controller slowly
939 * Linux: need composite manager
940 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
942 void FullscreenControllerWidget::slowHideFSC()
944 #if HAVE_TRANSPARENCY
945 if( b_slow_hide_begin )
947 b_slow_hide_begin = false;
949 p_slowHideTimer->stop();
950 /* the last part of time divided to 100 pieces */
951 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
957 if ( windowOpacity() > 0.0 && !b_fscHidden )
959 if ( windowOpacity() > 0.0 )
962 /* we should use 0.01 because of 100 pieces ^^^
963 but than it cannt be done in time */
964 setWindowOpacity( windowOpacity() - 0.02 );
967 if ( windowOpacity() <= 0.0 )
968 p_slowHideTimer->stop();
975 * events: show, hide, start timer for hidding
977 void FullscreenControllerWidget::customEvent( QEvent *event )
981 switch( event->type() )
983 case FullscreenControlToggle_Type:
984 vlc_mutex_lock( &lock );
986 vlc_mutex_unlock( &lock );
1000 case FullscreenControlShow_Type:
1001 vlc_mutex_lock( &lock );
1002 b_fs = b_fullscreen;
1003 vlc_mutex_unlock( &lock );
1006 if( b_fs && b_fscHidden )
1008 if( b_fs && !isVisible() )
1012 case FullscreenControlHide_Type:
1015 case FullscreenControlPlanHide_Type:
1016 if( !b_mouse_over ) // Only if the mouse is not over FSC
1026 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1028 if ( event->buttons() == Qt::LeftButton )
1030 int i_moveX = event->globalX() - i_mouse_last_x;
1031 int i_moveY = event->globalY() - i_mouse_last_y;
1033 move( x() + i_moveX, y() + i_moveY );
1035 i_mouse_last_x = event->globalX();
1036 i_mouse_last_y = event->globalY();
1042 * store position of cursor
1044 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1046 i_mouse_last_x = event->globalX();
1047 i_mouse_last_y = event->globalY();
1051 * On mouse go above FSC
1053 void FullscreenControllerWidget::enterEvent( QEvent *event )
1055 b_mouse_over = true;
1057 p_hideTimer->stop();
1058 #if HAVE_TRANSPARENCY
1059 p_slowHideTimer->stop();
1064 * On mouse go out from FSC
1066 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1070 b_mouse_over = false;
1074 * When you get pressed key, send it to video output
1075 * FIXME: clearing focus by clearFocus() to not getting
1076 * key press events didnt work
1078 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1080 int i_vlck = qtEventToVLCKey( event );
1083 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1091 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object,
1092 const char *variable, vlc_value_t old_val,
1093 vlc_value_t new_val, void *data )
1095 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1096 msg_Dbg( p_vout, "Qt4: Fullscreen state changed" );
1097 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1099 p_fs->fullscreenChanged( p_vout, new_val.b_bool,
1100 var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1105 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1106 vlc_value_t old_val, vlc_value_t new_val,
1109 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1111 int i_mousex, i_mousey;
1112 bool b_toShow = false;
1114 /* Get the value from the Vout - Trust the vout more than Qt */
1115 i_mousex = var_GetInteger( p_fs->p_vout, "mouse-x" );
1116 i_mousey = var_GetInteger( p_fs->p_vout, "mouse-y" );
1119 if( p_fs->i_mouse_last_move_x == -1 || p_fs->i_mouse_last_move_y == -1 )
1121 p_fs->i_mouse_last_move_x = i_mousex;
1122 p_fs->i_mouse_last_move_y = i_mousey;
1125 /* All other times */
1128 /* Trigger only if move > 3 px dans une direction */
1129 if( abs( p_fs->i_mouse_last_move_x - i_mousex ) > 2 ||
1130 abs( p_fs->i_mouse_last_move_y - i_mousey ) > 2 )
1133 p_fs->i_mouse_last_move_x = i_mousex;
1134 p_fs->i_mouse_last_move_y = i_mousey;
1141 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1142 QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1144 /* Plan hide event */
1145 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1146 QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1153 * It is called when video start
1155 void FullscreenControllerWidget::attachVout( vout_thread_t *p_nvout )
1157 assert( p_nvout && !p_vout );
1161 msg_Dbg( p_vout, "Qt FS: Attaching Vout" );
1162 vlc_mutex_lock( &lock );
1164 var_AddCallback( p_vout, "fullscreen",
1165 FullscreenControllerWidgetFullscreenChanged, this );
1166 /* I miss a add and fire */
1167 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ),
1168 var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1169 vlc_mutex_unlock( &lock );
1173 * It is called after turn off video.
1175 void FullscreenControllerWidget::detachVout()
1179 msg_Dbg( p_vout, "Qt FS: Detaching Vout" );
1180 var_DelCallback( p_vout, "fullscreen",
1181 FullscreenControllerWidgetFullscreenChanged, this );
1182 vlc_mutex_lock( &lock );
1183 fullscreenChanged( p_vout, false, 0 );
1184 vlc_mutex_unlock( &lock );
1190 * Register and unregister callback for mouse moving
1192 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout,
1193 bool b_fs, int i_timeout )
1195 msg_Dbg( p_vout, "Qt: Entering Fullscreen" );
1197 vlc_mutex_lock( &lock );
1198 /* Entering fullscreen, register callback */
1199 if( b_fs && !b_fullscreen )
1201 b_fullscreen = true;
1202 i_hide_timeout = i_timeout;
1203 var_AddCallback( p_vout, "mouse-moved",
1204 FullscreenControllerWidgetMouseMoved, this );
1206 /* Quitting fullscreen, unregistering callback */
1207 else if( !b_fs && b_fullscreen )
1209 b_fullscreen = false;
1210 i_hide_timeout = i_timeout;
1211 var_DelCallback( p_vout, "mouse-moved",
1212 FullscreenControllerWidgetMouseMoved, this );
1214 /* Force fs hidding */
1215 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1216 QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1218 vlc_mutex_unlock( &lock );