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 *****************************************************************************/
33 #include "dialogs_provider.hpp"
34 #include "components/interface_widgets.hpp"
35 #include "main_interface.hpp"
36 #include "input_manager.hpp"
38 #include "util/input_slider.hpp"
39 #include "util/customwidgets.hpp"
42 #include <QSpacerItem>
44 #include <QToolButton>
45 #include <QToolButton>
46 #include <QHBoxLayout>
49 #include <QResizeEvent>
51 #include <QSignalMapper>
53 #define I_PLAY_TOOLTIP N_("Play\nIf the playlist is empty, open a media")
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 ) : QFrame( NULL )
68 /* We need one layout. An controller without layout is stupid with
69 current architecture */
70 controlLayout = new QGridLayout( this );
72 /* Main action provider */
73 toolbarActionsMapper = new QSignalMapper();
74 CONNECT( toolbarActionsMapper, mapped( int ),
75 this, doAction( int ) );
76 CONNECT( THEMIM->getIM(), statusChanged( int ), this, setStatus( int ) );
79 void AbstractController::setStatus( int status )
81 bool b_hasInput = THEMIM->getIM()->hasInput();
82 /* Activate the interface buttons according to the presence of the input */
83 emit inputExists( b_hasInput );
85 emit inputPlaying( status == PLAYING_S );
87 emit inputIsRecordable( b_hasInput &&
88 var_GetBool( THEMIM->getInput(), "can-record" ) );
91 void AbstractController::setupButton( QAbstractButton *aButton )
93 static QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
94 sizePolicy.setHorizontalStretch( 0 );
95 sizePolicy.setVerticalStretch( 0 );
97 aButton->setSizePolicy( sizePolicy );
98 aButton->setFixedSize( QSize( 26, 26 ) );
99 aButton->setIconSize( QSize( 20, 20 ) );
100 aButton->setFocusPolicy( Qt::NoFocus );
103 #define CONNECT_MAP( a ) CONNECT( a, clicked(), toolbarActionsMapper, map() )
104 #define SET_MAPPING( a, b ) toolbarActionsMapper->setMapping( a , b )
105 #define CONNECT_MAP_SET( a, b ) \
108 #define BUTTON_SET_BAR( button, image, tooltip ) \
109 button->setToolTip( tooltip ); \
110 button->setIcon( QIcon( ":/"#image ) );
112 #define ENABLE_ON_VIDEO( a ) \
113 CONNECT( THEMIM->getIM(), voutChanged( bool ), a, setEnabled( bool ) ); \
114 a->setEnabled( THEMIM->getIM()->hasVideo() ); /* TODO: is this necessary? when input is started before the interface? */
116 #define ENABLE_ON_INPUT( a ) \
117 CONNECT( this, inputExists( bool ), a, setEnabled( bool ) ); \
118 a->setEnabled( THEMIM->getIM()->hasInput() ); /* TODO: is this necessary? when input is started before the interface? */
120 QWidget *AbstractController::createWidget( buttonType_e button, bool b_flat,
121 bool b_big, bool b_shiny )
123 QWidget *widget = NULL;
127 PlayButton *playButton = new PlayButton;
128 setupButton( playButton );
129 BUTTON_SET_BAR( playButton, play_b, qtr( I_PLAY_TOOLTIP ) );
130 CONNECT_MAP_SET( playButton, PLAY_ACTION );
131 CONNECT( this, inputPlaying( bool ),
132 playButton, updateButton( bool ));
137 QToolButton *stopButton = new QToolButton;
138 setupButton( stopButton );
139 CONNECT_MAP_SET( stopButton, STOP_ACTION );
140 BUTTON_SET_BAR( stopButton, stop_b, qtr( "Stop playback" ) );
144 case PREVIOUS_BUTTON:{
145 QToolButton *prevButton = new QToolButton;
146 setupButton( prevButton );
147 CONNECT_MAP_SET( prevButton, PREVIOUS_ACTION );
148 BUTTON_SET_BAR( prevButton, previous_b,
149 qtr( "Previous media in the playlist" ) );
155 QToolButton *nextButton = new QToolButton;
156 setupButton( nextButton );
157 CONNECT_MAP_SET( nextButton, NEXT_ACTION );
158 BUTTON_SET_BAR( nextButton, next_b,
159 qtr( "Next media in the playlist" ) );
164 QToolButton *slowerButton = new QToolButton;
165 setupButton( slowerButton );
166 CONNECT_MAP_SET( slowerButton, SLOWER_ACTION );
167 BUTTON_SET_BAR( slowerButton, slower, qtr( "Slower" ) );
168 ENABLE_ON_INPUT( slowerButton );
169 widget = slowerButton;
173 QToolButton *fasterButton = new QToolButton;
174 setupButton( fasterButton );
175 CONNECT_MAP_SET( fasterButton, SLOWER_ACTION );
176 BUTTON_SET_BAR( fasterButton, faster, qtr( "Faster" ) );
177 ENABLE_ON_INPUT( fasterButton );
178 widget = fasterButton;
183 QToolButton *frameButton = new QToolButton( "Fr" );
184 setupButton( frameButton );
185 BUTTON_SET_BAR( frameButton, "", qtr( "Frame by frame" ) );
186 ENABLE_ON_INPUT( frameButton );
187 widget = frameButton;
191 case FULLSCREEN_BUTTON:{
192 QToolButton *fullscreenButton = new QToolButton;
193 setupButton( fullscreenButton );
194 CONNECT_MAP_SET( fullscreenButton, FULLSCREEN_ACTION );
195 BUTTON_SET_BAR( fullscreenButton, fullscreen,
196 qtr( "Toggle the video in fullscreen" ) );
197 ENABLE_ON_VIDEO( fullscreenButton );
198 widget = fullscreenButton;
201 case EXTENDED_BUTTON:{
202 QToolButton *extSettingsButton = new QToolButton;
203 setupButton( extSettingsButton );
204 CONNECT_MAP_SET( extSettingsButton, EXTENDED_ACTION );
205 BUTTON_SET_BAR( extSettingsButton, extended,
206 qtr( "Show extended settings" ) );
207 widget = extSettingsButton;
210 case PLAYLIST_BUTTON:{
211 QToolButton *playlistButton = new QToolButton;
212 setupButton( playlistButton );
213 CONNECT_MAP_SET( playlistButton, PLAYLIST_ACTION );
214 BUTTON_SET_BAR( playlistButton, playlist,
215 qtr( "Show playlist" ) );
216 widget = playlistButton;
219 case SNAPSHOT_BUTTON:{
220 QToolButton *snapshotButton = new QToolButton;
221 setupButton( snapshotButton );
222 CONNECT_MAP_SET( snapshotButton, SNAPSHOT_ACTION );
223 BUTTON_SET_BAR( snapshotButton, snapshot, qtr( "Take a snapshot" ) );
224 ENABLE_ON_VIDEO( snapshotButton );
225 widget = snapshotButton;
229 QToolButton *recordButton = new QToolButton;
230 setupButton( recordButton );
231 CONNECT_MAP_SET( recordButton, RECORD_ACTION );
232 BUTTON_SET_BAR( recordButton, record, qtr( "Record" ) );
233 ENABLE_ON_INPUT( recordButton );
234 widget = recordButton;
238 AtoB_Button *ABButton = new AtoB_Button;
239 setupButton( ABButton );
240 BUTTON_SET_BAR( ABButton, atob_nob, qtr( "Loop from point A to point "
241 "B continuously.\nClick to set point A" ) );
242 ENABLE_ON_INPUT( ABButton );
243 CONNECT_MAP_SET( ABButton, ATOB_ACTION );
244 CONNECT( THEMIM->getIM(), AtoBchanged( bool, bool),
245 ABButton, setIcons( bool, bool ) );
250 InputSlider *slider = new InputSlider( Qt::Horizontal, NULL );
251 /* Update the position when the IM has changed */
252 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
253 slider, setPosition( float, int, int ) );
254 /* And update the IM, when the position has changed */
255 CONNECT( slider, sliderDragged( float ),
256 THEMIM->getIM(), sliderUpdate( float ) );
261 widget = discFrame();
264 case TELETEXT_BUTTONS:
265 widget = telexFrame();
270 SoundWidget *snd = new SoundWidget( p_intf, b_shiny );
275 msg_Warn( p_intf, "This should not happen" );
279 /* Customize Buttons */
280 if( b_flat || b_big )
282 QToolButton *tmpButton = qobject_cast<QToolButton *>(widget);
286 tmpButton->setAutoRaise( b_flat );
289 tmpButton->setFixedSize( QSize( 32, 32 ) );
290 tmpButton->setIconSize( QSize( 26, 26 ) );
297 QWidget *AbstractController::discFrame()
299 /** Disc and Menus handling */
300 QWidget *discFrame = new QWidget( this );
302 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
303 discLayout->setSpacing( 0 ); discLayout->setMargin( 0 );
305 QToolButton *prevSectionButton = new QToolButton( discFrame );
306 setupButton( prevSectionButton );
307 BUTTON_SET_BAR( prevSectionButton, dvd_prev,
308 qtr("Previous Chapter/Title" ) );
309 discLayout->addWidget( prevSectionButton );
311 QToolButton *menuButton = new QToolButton( discFrame );
312 setupButton( menuButton );
313 discLayout->addWidget( menuButton );
314 BUTTON_SET_BAR( menuButton, dvd_menu, qtr( "Menu" ) );
316 QToolButton *nextSectionButton = new QToolButton( discFrame );
317 setupButton( nextSectionButton );
318 discLayout->addWidget( nextSectionButton );
319 BUTTON_SET_BAR( nextSectionButton, dvd_next,
320 qtr("Next Chapter/Title" ) );
323 /* Change the navigation button display when the IM
324 navigation changes */
325 CONNECT( THEMIM->getIM(), titleChanged( bool ),
326 discFrame, setVisible( bool ) );
327 CONNECT( THEMIM->getIM(), chapterChanged( bool ),
328 menuButton, setVisible( bool ) );
329 /* Changes the IM navigation when triggered on the nav buttons */
330 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
332 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
334 CONNECT( menuButton, clicked(), THEMIM->getIM(),
340 QWidget *AbstractController::telexFrame()
345 TeletextController *telexFrame = new TeletextController;
346 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
347 telexLayout->setSpacing( 0 ); telexLayout->setMargin( 0 );
348 CONNECT( THEMIM->getIM(), teletextPossible( bool ),
349 telexFrame, setVisible( bool ) );
352 QToolButton *telexOn = new QToolButton;
353 telexFrame->telexOn = telexOn;
354 setupButton( telexOn );
355 BUTTON_SET_BAR( telexOn, tv, qtr( "Teletext Activation" ) );
356 telexLayout->addWidget( telexOn );
358 /* Teletext Activation and set */
359 CONNECT( telexOn, clicked( bool ),
360 THEMIM->getIM(), activateTeletext( bool ) );
361 CONNECT( THEMIM->getIM(), teletextActivated( bool ),
362 telexFrame, enableTeletextButtons( bool ) );
365 /* Transparency button */
366 QToolButton *telexTransparent = new QToolButton;
367 telexFrame->telexTransparent = telexTransparent;
368 setupButton( telexTransparent );
369 BUTTON_SET_BAR( telexTransparent, tvtelx,
370 qtr( "Toggle Transparency " ) );
371 telexTransparent->setEnabled( false );
372 telexLayout->addWidget( telexTransparent );
374 /* Transparency change and set */
375 CONNECT( telexTransparent, clicked( bool ),
376 THEMIM->getIM(), telexSetTransparency( bool ) );
377 CONNECT( THEMIM->getIM(), teletextTransparencyActivated( bool ),
378 telexFrame, toggleTeletextTransparency( bool ) );
382 QSpinBox *telexPage = new QSpinBox;
383 telexFrame->telexPage = telexPage;
384 telexPage->setRange( 0, 999 );
385 telexPage->setValue( 100 );
386 telexPage->setAccelerated( true );
387 telexPage->setWrapping( true );
388 telexPage->setAlignment( Qt::AlignRight );
389 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
390 telexPage->setEnabled( false );
391 telexLayout->addWidget( telexPage );
393 /* Page change and set */
394 CONNECT( telexPage, valueChanged( int ),
395 THEMIM->getIM(), telexSetPage( int ) );
396 CONNECT( THEMIM->getIM(), newTelexPageSet( int ),
397 telexPage, setValue( int ) );
403 #undef BUTTON_SET_BAR
405 SoundWidget::SoundWidget( intf_thread_t * _p_intf, bool b_shiny )
406 : b_my_volume( false )
409 QHBoxLayout *layout = new QHBoxLayout( this );
410 layout->setSpacing( 0 ); layout->setMargin( 0 );
411 hVolLabel = new VolumeClickHandler( p_intf, this );
413 volMuteLabel = new QLabel;
414 volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
415 volMuteLabel->installEventFilter( hVolLabel );
416 layout->addWidget( volMuteLabel );
420 volumeSlider = new SoundSlider( this,
421 config_GetInt( p_intf, "volume-step" ),
422 config_GetInt( p_intf, "qt-volume-complete" ),
423 config_GetPsz( p_intf, "qt-slider-colours" ) );
427 volumeSlider = new QSlider( this );
428 volumeSlider->setOrientation( Qt::Horizontal );
430 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
431 volumeSlider->setMinimumSize( QSize( 85, 30 ) );
432 volumeSlider->setFocusPolicy( Qt::NoFocus );
433 layout->addWidget( volumeSlider );
435 /* Set the volume from the config */
436 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
437 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
439 /* Force the update at build time in order to have a muted icon if needed */
440 updateVolume( volumeSlider->value() );
442 /* Volume control connection */
443 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
444 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
447 void SoundWidget::updateVolume( int i_sliderVolume )
451 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
452 aout_VolumeSet( p_intf, i_res );
454 if( i_sliderVolume == 0 )
456 volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
457 volMuteLabel->setToolTip( qtr( "Unmute" ) );
461 if( i_sliderVolume < VOLUME_MAX / 3 )
462 volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
463 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
464 volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
465 else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
466 volMuteLabel->setToolTip( qtr( "Mute" ) );
469 void SoundWidget::updateVolume()
472 audio_volume_t i_volume;
473 aout_VolumeGet( p_intf, &i_volume );
474 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
475 int i_gauge = volumeSlider->value();
477 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
480 volumeSlider->setValue( i_volume );
485 void TeletextController::toggleTeletextTransparency( bool b_transparent )
487 telexTransparent->setIcon( b_transparent ? QIcon( ":/tvtelx" )
488 : QIcon( ":/tvtelx-trans" ) );
491 void TeletextController::enableTeletextButtons( bool b_enabled )
493 telexOn->setChecked( b_enabled );
494 telexTransparent->setEnabled( b_enabled );
495 telexPage->setEnabled( b_enabled );
498 void PlayButton::updateButton( bool b_playing )
500 setIcon( b_playing ? QIcon( ":/pause_b" ) : QIcon( ":/play_b" ) );
501 setToolTip( b_playing ? qtr( "Pause the playback" )
502 : qtr( I_PLAY_TOOLTIP ) );
505 void AtoB_Button::setIcons( bool timeA, bool timeB )
507 if( !timeA && !timeB)
509 setIcon( QIcon( ":/atob_nob" ) );
510 setToolTip( qtr( "Loop from point A to point B continuously\n"
511 "Click to set point A" ) );
513 else if( timeA && !timeB )
515 setIcon( QIcon( ":/atob_noa" ) );
516 setToolTip( qtr( "Click to set point B" ) );
518 else if( timeA && timeB )
520 setIcon( QIcon( ":/atob" ) );
521 setToolTip( qtr( "Stop the A to B loop" ) );
527 void AbstractController::doAction( int id_action )
533 case PREVIOUS_ACTION:
543 case FULLSCREEN_ACTION:
545 case EXTENDED_ACTION:
546 extSettings(); break;
547 case PLAYLIST_ACTION:
549 case SNAPSHOT_ACTION:
554 THEMIM->getIM()->setAtoB(); break;
556 msg_Dbg( p_intf, "Action: %i", id_action );
561 void AbstractController::stop()
566 void AbstractController::play()
568 if( THEPL->current.i_size == 0 )
570 /* The playlist is empty, open a file requester */
571 THEDP->openFileDialog();
574 THEMIM->togglePlayPause();
577 void AbstractController::prev()
582 void AbstractController::next()
589 * This functions toggle the fullscreen mode
590 * If there is no video, it should first activate Visualisations...
591 * This has also to be fixed in enableVideo()
593 void AbstractController::fullscreen()
595 vout_thread_t *p_vout =
596 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
599 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
600 vlc_object_release( p_vout );
604 void AbstractController::snapshot()
606 vout_thread_t *p_vout =
607 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
610 vout_Control( p_vout, VOUT_SNAPSHOT );
611 vlc_object_release( p_vout );
616 void AbstractController::extSettings()
618 THEDP->extendedDialog();
621 void AbstractController::slower()
623 THEMIM->getIM()->slower();
626 void AbstractController::faster()
628 THEMIM->getIM()->faster();
631 void AbstractController::playlist()
633 if( p_intf->p_sys->p_mi ) p_intf->p_sys->p_mi->togglePlaylist();
636 void AbstractController::record()
638 input_thread_t *p_input = THEMIM->getInput();
641 /* This method won't work fine if the stream can't be cut anywhere */
642 const bool b_recording = var_GetBool( p_input, "record" );
643 var_SetBool( p_input, "record", !b_recording );
647 /* 'record' access-filter is not loaded, we open Save dialog */
648 input_item_t *p_item = input_GetItem( p_input );
652 char *psz = input_item_GetURI( p_item );
654 THEDP->streamingDialog( NULL, psz, true );
661 //TODO Frame by frame function
662 void AbstractController::frame(){}
666 /*****************************
667 * DA Control Widget !
668 *****************************/
669 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
670 bool b_advControls ) :
671 AbstractController( _p_i )
673 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
675 /* advanced Controls handling */
676 b_advancedVisible = b_advControls;
678 advControls = new AdvControlsWidget( p_intf );
679 if( !b_advancedVisible ) advControls->hide();
681 controlLayout->setSpacing( 0 );
682 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
684 controlLayout->addWidget( createWidget( INPUT_SLIDER ), 0, 1, 1, 18 );
685 controlLayout->addWidget( createWidget( SLOWER_BUTTON, true ), 0, 0 );
686 controlLayout->addWidget( createWidget( FASTER_BUTTON, true ), 0, 19 );
688 controlLayout->addWidget( createWidget( MENU_BUTTONS ), 1, 8, 2, 3 );
689 controlLayout->addWidget( createWidget( TELETEXT_BUTTONS ), 1, 8, 2, 5, Qt::AlignBottom );
691 controlLayout->addWidget( createWidget( PLAY_BUTTON, false, true ), 2, 0, 2, 2, Qt::AlignBottom );
692 controlLayout->setColumnMinimumWidth( 2, 10 );
693 controlLayout->setColumnStretch( 2, 0 );
695 controlLayout->addWidget( createWidget( PREVIOUS_BUTTON ), 3, 3, Qt::AlignBottom );
696 controlLayout->addWidget( createWidget( STOP_BUTTON ), 3, 4, Qt::AlignBottom );
697 controlLayout->addWidget( createWidget( NEXT_BUTTON ), 3, 5, Qt::AlignBottom );
699 /* Column 6 is unused */
700 controlLayout->setColumnStretch( 6, 0 );
701 controlLayout->setColumnStretch( 7, 0 );
702 controlLayout->setColumnMinimumWidth( 7, 10 );
704 controlLayout->addWidget( createWidget( FULLSCREEN_BUTTON ), 3, 8, Qt::AlignBottom );
705 controlLayout->addWidget( createWidget( PLAYLIST_BUTTON ), 3, 9, Qt::AlignBottom );
706 controlLayout->addWidget( createWidget( EXTENDED_BUTTON ), 3, 10, Qt::AlignBottom );
707 controlLayout->setColumnStretch( 11, 0 ); /* telex alignment */
709 controlLayout->setColumnStretch( 12, 0 );
710 controlLayout->setColumnMinimumWidth( 12, 10 );
712 controlLayout->addWidget( advControls, 3, 13, 1, 3, Qt::AlignBottom );
714 controlLayout->setColumnStretch( 16, 10 );
715 controlLayout->setColumnMinimumWidth( 16, 10 );
717 controlLayout->addWidget( createWidget( VOLUME, false, false, true ),
718 3, 17, 1, 3, Qt::AlignBottom );
721 ControlsWidget::~ControlsWidget()
724 void ControlsWidget::toggleAdvanced()
726 if( advControls && !b_advancedVisible )
729 b_advancedVisible = true;
734 b_advancedVisible = false;
736 emit advancedControlsToggled( b_advancedVisible );
739 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
740 AbstractController( _p_i )
742 controlLayout->setMargin( 0 );
743 controlLayout->setSpacing( 0 );
745 controlLayout->addWidget( createWidget( RECORD_BUTTON ), 0, 0 );
746 controlLayout->addWidget( createWidget( SNAPSHOT_BUTTON ), 0, 1 );
747 controlLayout->addWidget( createWidget( ATOB_BUTTON ), 0, 2 );
750 AdvControlsWidget::~AdvControlsWidget()
754 /**********************************************************************
755 * Fullscrenn control widget
756 **********************************************************************/
757 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i )
758 : AbstractController( _p_i )
762 b_mouse_over = false;
763 i_mouse_last_move_x = -1;
764 i_mouse_last_move_y = -1;
765 #if HAVE_TRANSPARENCY
766 b_slow_hide_begin = false;
767 i_slow_hide_timeout = 1;
769 b_fullscreen = false;
773 setWindowFlags( Qt::ToolTip );
774 setMinimumWidth( 600 );
776 setFrameShape( QFrame::StyledPanel );
777 setFrameStyle( QFrame::Sunken );
778 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
780 controlLayout->setLayoutMargins( 5, 2, 5, 2, 5 );
783 controlLayout->addWidget( createWidget( SLOWER_BUTTON ), 0, 0 );
784 controlLayout->addWidget( createWidget( INPUT_SLIDER ), 0, 1, 1, 13 );
785 controlLayout->addWidget( createWidget( FASTER_BUTTON ), 0, 14 );
788 controlLayout->addWidget( createWidget( PLAY_BUTTON, false, true ), 1, 0, 1, 2 );
789 controlLayout->addWidget( createWidget( PREVIOUS_BUTTON ), 1, 2 );
790 controlLayout->addWidget( createWidget( STOP_BUTTON ), 1, 3 );
791 controlLayout->addWidget( createWidget( NEXT_BUTTON ), 1, 4 );
793 controlLayout->addWidget( createWidget( MENU_BUTTONS ), 1, 5 );
794 controlLayout->addWidget( createWidget( TELETEXT_BUTTONS ), 1, 6 );
795 QToolButton *fullscreenButton =
796 qobject_cast<QToolButton *>(createWidget( FULLSCREEN_BUTTON ) );
797 fullscreenButton->setIcon( QIcon( ":/defullscreen" ) );
798 controlLayout->addWidget( fullscreenButton, 1, 7 );
800 controlLayout->setColumnStretch( 9, 10 );
802 TimeLabel *timeLabel = new TimeLabel( p_intf );
804 controlLayout->addWidget( timeLabel, 1, 10 );
805 controlLayout->addWidget( createWidget( VOLUME, false, false, true ),
809 p_hideTimer = new QTimer( this );
810 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
811 p_hideTimer->setSingleShot( true );
813 /* slow hiding timer */
814 #if HAVE_TRANSPARENCY
815 p_slowHideTimer = new QTimer( this );
816 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
819 adjustSize (); /* need to get real width and height for moving */
822 QWidget * p_desktop = QApplication::desktop()->screen(
823 QApplication::desktop()->screenNumber( p_intf->p_sys->p_mi ) );
825 QPoint pos = QPoint( p_desktop->width() / 2 - width() / 2,
826 p_desktop->height() - height() );
828 getSettings()->beginGroup( "FullScreen" );
829 move( getSettings()->value( "pos", pos ).toPoint() );
830 getSettings()->endGroup();
833 setWindowOpacity( 0.0 );
839 vlc_mutex_init_recursive( &lock );
842 FullscreenControllerWidget::~FullscreenControllerWidget()
844 getSettings()->beginGroup( "FullScreen" );
845 getSettings()->setValue( "pos", pos() );
846 getSettings()->endGroup();
848 vlc_mutex_destroy( &lock );
852 * Show fullscreen controller
854 void FullscreenControllerWidget::showFSC()
858 // after quiting and going to fs, we need to call show()
865 setWindowOpacity( 1.0 );
871 #if HAVE_TRANSPARENCY
872 setWindowOpacity( DEFAULT_OPACITY );
877 * Hide fullscreen controller
878 * FIXME: under windows it have to be done by moving out of screen
879 * because hide() doesnt work
881 void FullscreenControllerWidget::hideFSC()
885 setWindowOpacity( 0.0 ); // simulate hidding
892 * Plane to hide fullscreen controller
894 void FullscreenControllerWidget::planHideFSC()
896 vlc_mutex_lock( &lock );
897 int i_timeout = i_hide_timeout;
898 vlc_mutex_unlock( &lock );
900 p_hideTimer->start( i_timeout );
902 #if HAVE_TRANSPARENCY
903 b_slow_hide_begin = true;
904 i_slow_hide_timeout = i_timeout;
905 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
910 * Hidding fullscreen controller slowly
911 * Linux: need composite manager
912 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
914 void FullscreenControllerWidget::slowHideFSC()
916 #if HAVE_TRANSPARENCY
917 if( b_slow_hide_begin )
919 b_slow_hide_begin = false;
921 p_slowHideTimer->stop();
922 /* the last part of time divided to 100 pieces */
923 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
929 if ( windowOpacity() > 0.0 && !b_fscHidden )
931 if ( windowOpacity() > 0.0 )
934 /* we should use 0.01 because of 100 pieces ^^^
935 but than it cannt be done in time */
936 setWindowOpacity( windowOpacity() - 0.02 );
939 if ( windowOpacity() <= 0.0 )
940 p_slowHideTimer->stop();
947 * events: show, hide, start timer for hidding
949 void FullscreenControllerWidget::customEvent( QEvent *event )
953 switch( event->type() )
955 case FullscreenControlToggle_Type:
956 vlc_mutex_lock( &lock );
958 vlc_mutex_unlock( &lock );
972 case FullscreenControlShow_Type:
973 vlc_mutex_lock( &lock );
975 vlc_mutex_unlock( &lock );
978 if( b_fs && b_fscHidden )
980 if( b_fs && !isVisible() )
984 case FullscreenControlHide_Type:
987 case FullscreenControlPlanHide_Type:
988 if( !b_mouse_over ) // Only if the mouse is not over FSC
998 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1000 if ( event->buttons() == Qt::LeftButton )
1002 int i_moveX = event->globalX() - i_mouse_last_x;
1003 int i_moveY = event->globalY() - i_mouse_last_y;
1005 move( x() + i_moveX, y() + i_moveY );
1007 i_mouse_last_x = event->globalX();
1008 i_mouse_last_y = event->globalY();
1014 * store position of cursor
1016 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1018 i_mouse_last_x = event->globalX();
1019 i_mouse_last_y = event->globalY();
1023 * On mouse go above FSC
1025 void FullscreenControllerWidget::enterEvent( QEvent *event )
1027 b_mouse_over = true;
1029 p_hideTimer->stop();
1030 #if HAVE_TRANSPARENCY
1031 p_slowHideTimer->stop();
1036 * On mouse go out from FSC
1038 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1042 b_mouse_over = false;
1046 * When you get pressed key, send it to video output
1047 * FIXME: clearing focus by clearFocus() to not getting
1048 * key press events didnt work
1050 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1052 int i_vlck = qtEventToVLCKey( event );
1055 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1063 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object,
1064 const char *variable, vlc_value_t old_val,
1065 vlc_value_t new_val, void *data )
1067 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1068 msg_Dbg( p_vout, "Qt4: Fullscreen state changed" );
1069 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1071 p_fs->fullscreenChanged( p_vout, new_val.b_bool,
1072 var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1077 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1078 vlc_value_t old_val, vlc_value_t new_val,
1081 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1083 int i_mousex, i_mousey;
1084 bool b_toShow = false;
1086 /* Get the value from the Vout - Trust the vout more than Qt */
1087 i_mousex = var_GetInteger( p_fs->p_vout, "mouse-x" );
1088 i_mousey = var_GetInteger( p_fs->p_vout, "mouse-y" );
1091 if( p_fs->i_mouse_last_move_x == -1 || p_fs->i_mouse_last_move_y == -1 )
1093 p_fs->i_mouse_last_move_x = i_mousex;
1094 p_fs->i_mouse_last_move_y = i_mousey;
1097 /* All other times */
1100 /* Trigger only if move > 3 px dans une direction */
1101 if( abs( p_fs->i_mouse_last_move_x - i_mousex ) > 2 ||
1102 abs( p_fs->i_mouse_last_move_y - i_mousey ) > 2 )
1105 p_fs->i_mouse_last_move_x = i_mousex;
1106 p_fs->i_mouse_last_move_y = i_mousey;
1113 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1114 QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1116 /* Plan hide event */
1117 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1118 QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1126 * It is called when video start
1128 void FullscreenControllerWidget::attachVout( vout_thread_t *p_nvout )
1130 assert( p_nvout && !p_vout );
1134 msg_Dbg( p_vout, "Qt FS: Attaching Vout" );
1135 vlc_mutex_lock( &lock );
1137 var_AddCallback( p_vout, "fullscreen",
1138 FullscreenControllerWidgetFullscreenChanged, this );
1139 /* I miss a add and fire */
1140 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ),
1141 var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1142 vlc_mutex_unlock( &lock );
1145 * It is called after turn off video.
1147 void FullscreenControllerWidget::detachVout()
1151 msg_Dbg( p_vout, "Qt FS: Detaching Vout" );
1152 var_DelCallback( p_vout, "fullscreen",
1153 FullscreenControllerWidgetFullscreenChanged, this );
1154 vlc_mutex_lock( &lock );
1155 fullscreenChanged( p_vout, false, 0 );
1156 vlc_mutex_unlock( &lock );
1162 * Register and unregister callback for mouse moving
1164 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout,
1165 bool b_fs, int i_timeout )
1167 msg_Dbg( p_vout, "Qt: Entering Fullscreen" );
1169 vlc_mutex_lock( &lock );
1170 /* Entering fullscreen, register callback */
1171 if( b_fs && !b_fullscreen )
1173 b_fullscreen = true;
1174 i_hide_timeout = i_timeout;
1175 var_AddCallback( p_vout, "mouse-moved",
1176 FullscreenControllerWidgetMouseMoved, this );
1178 /* Quitting fullscreen, unregistering callback */
1179 else if( !b_fs && b_fullscreen )
1181 b_fullscreen = false;
1182 i_hide_timeout = i_timeout;
1183 var_DelCallback( p_vout, "mouse-moved",
1184 FullscreenControllerWidgetMouseMoved, this );
1186 /* Force fs hidding */
1187 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1188 QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1190 vlc_mutex_unlock( &lock );