1 /*****************************************************************************
2 * interface_widgets.cpp : Custom widgets for the main interface
3 ****************************************************************************
4 * Copyright ( C ) 2006 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 <QPushButton>
45 #include <QToolButton>
46 #include <QHBoxLayout>
49 #include <QResizeEvent>
52 #define I_PLAY_TOOLTIP N_("Play\nIf the playlist is empty, open a media")
54 /**********************************************************************
56 **********************************************************************/
58 static void setupSmallButton( QPushButton *aButton )
60 aButton->setMaximumSize( QSize( 26, 26 ) );
61 aButton->setMinimumSize( QSize( 26, 26 ) );
62 aButton->setIconSize( QSize( 20, 20 ) );
63 aButton->setFocusPolicy( Qt::NoFocus );
66 /* init static variables in advanced controls */
67 mtime_t AdvControlsWidget::timeA = 0;
68 mtime_t AdvControlsWidget::timeB = 0;
70 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, bool b_fsCreation = false ) :
71 QFrame( NULL ), p_intf( _p_i )
73 QHBoxLayout *advLayout = new QHBoxLayout( this );
74 advLayout->setMargin( 0 );
75 advLayout->setSpacing( 0 );
76 advLayout->setAlignment( Qt::AlignBottom );
79 ABButton = new QPushButton;
80 setupSmallButton( ABButton );
81 advLayout->addWidget( ABButton );
82 BUTTON_SET_ACT_I( ABButton, "", atob_nob,
83 qtr( "Loop from point A to point B continuously.\nClick to set point A" ),
87 /* in FS controller we skip this, because we dont want to have it double
90 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
91 this, AtoBLoop( float, int, int ) );
92 /* set up synchronization between main controller and fs controller */
93 CONNECT( THEMIM->getIM(), advControlsSetIcon(), this, setIcon() );
94 connect( this, SIGNAL( timeChanged() ),
95 THEMIM->getIM(), SIGNAL( advControlsSetIcon()));
97 frameButton = new QPushButton( "Fr" );
98 frameButton->setMaximumSize( QSize( 26, 26 ) );
99 frameButton->setIconSize( QSize( 20, 20 ) );
100 advLayout->addWidget( frameButton );
101 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by frame" ), frame() );
105 recordButton = new QPushButton;
106 setupSmallButton( recordButton );
107 advLayout->addWidget( recordButton );
108 BUTTON_SET_ACT_I( recordButton, "", record,
109 qtr( "Record" ), record() );
111 /* Snapshot Button */
112 snapshotButton = new QPushButton;
113 setupSmallButton( snapshotButton );
114 advLayout->addWidget( snapshotButton );
115 BUTTON_SET_ACT_I( snapshotButton, "", snapshot,
116 qtr( "Take a snapshot" ), snapshot() );
119 AdvControlsWidget::~AdvControlsWidget()
122 void AdvControlsWidget::enableInput( bool enable )
125 if( THEMIM->getInput() != NULL )
127 input_item_t *p_item = input_GetItem( THEMIM->getInput() );
128 i_input_id = p_item->i_id;
130 recordButton->setVisible( var_GetBool( THEMIM->getInput(), "can-record" ) );
134 recordButton->setVisible( false );
137 ABButton->setEnabled( enable );
138 recordButton->setEnabled( enable );
140 if( enable && ( i_last_input_id != i_input_id ) )
143 i_last_input_id = i_input_id;
148 void AdvControlsWidget::enableVideo( bool enable )
150 snapshotButton->setEnabled( enable );
152 frameButton->setEnabled( enable );
156 void AdvControlsWidget::snapshot()
158 vout_thread_t *p_vout =
159 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
162 vout_Control( p_vout, VOUT_SNAPSHOT );
163 vlc_object_release( p_vout );
167 /* Function called when the button is clicked() */
168 void AdvControlsWidget::fromAtoB()
172 timeA = var_GetTime( THEMIM->getInput(), "time" );
178 timeB = var_GetTime( THEMIM->getInput(), "time" );
179 var_SetTime( THEMIM->getInput(), "time" , timeA );
188 /* setting/synchro icons after click on main or fs controller */
189 void AdvControlsWidget::setIcon()
191 if( !timeA && !timeB)
193 ABButton->setIcon( QIcon( ":/atob_nob" ) );
194 ABButton->setToolTip( qtr( "Loop from point A to point B continuously\nClick to set point A" ) );
196 else if( timeA && !timeB )
198 ABButton->setIcon( QIcon( ":/atob_noa" ) );
199 ABButton->setToolTip( qtr( "Click to set point B" ) );
201 else if( timeA && timeB )
203 ABButton->setIcon( QIcon( ":/atob" ) );
204 ABButton->setToolTip( qtr( "Stop the A to B loop" ) );
208 /* Function called regularly when in an AtoB loop */
209 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
213 if( ( i_time >= (int)( timeB/1000000 ) )
214 || ( i_time < (int)( timeA/1000000 ) ) )
215 var_SetTime( THEMIM->getInput(), "time" , timeA );
219 void AdvControlsWidget::record()
221 input_thread_t *p_input = THEMIM->getInput();
224 /* This method won't work fine if the stream can't be cut anywhere */
225 const bool b_recording = var_GetBool( p_input, "record" );
226 var_SetBool( p_input, "record", !b_recording );
230 /* 'record' access-filter is not loaded, we open Save dialog */
231 input_item_t *p_item = input_GetItem( p_input );
235 char *psz = input_item_GetURI( p_item );
237 THEDP->streamingDialog( NULL, psz, true );
244 //FIXME Frame by frame function
245 void AdvControlsWidget::frame(){}
248 /*****************************
249 * DA Control Widget !
250 *****************************/
251 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
252 MainInterface *_p_mi,
256 QFrame( _p_mi ), p_intf( _p_i )
258 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
260 /** The main Slider **/
261 slider = new InputSlider( Qt::Horizontal, NULL );
262 /* Update the position when the IM has changed */
263 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
264 slider, setPosition( float, int, int ) );
265 /* And update the IM, when the position has changed */
266 CONNECT( slider, sliderDragged( float ),
267 THEMIM->getIM(), sliderUpdate( float ) );
269 /** Slower and faster Buttons **/
270 slowerButton = new QToolButton;
271 slowerButton->setAutoRaise( true );
272 slowerButton->setMaximumSize( QSize( 26, 20 ) );
273 slowerButton->setFocusPolicy( Qt::NoFocus );
275 BUTTON_SET_ACT_I( slowerButton, "", slower, qtr( "Slower" ), slower() );
277 fasterButton = new QToolButton;
278 fasterButton->setAutoRaise( true );
279 fasterButton->setMaximumSize( QSize( 26, 20 ) );
280 fasterButton->setFocusPolicy( Qt::NoFocus );
282 BUTTON_SET_ACT_I( fasterButton, "", faster, qtr( "Faster" ), faster() );
284 /* advanced Controls handling */
285 b_advancedVisible = b_advControls;
287 advControls = new AdvControlsWidget( p_intf, b_fsCreation );
288 if( !b_advancedVisible ) advControls->hide();
290 /** Disc and Menus handling */
291 discFrame = new QWidget( this );
293 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
294 discLayout->setSpacing( 0 );
295 discLayout->setMargin( 0 );
297 prevSectionButton = new QPushButton( discFrame );
298 setupSmallButton( prevSectionButton );
299 discLayout->addWidget( prevSectionButton );
301 menuButton = new QPushButton( discFrame );
302 setupSmallButton( menuButton );
303 discLayout->addWidget( menuButton );
305 nextSectionButton = new QPushButton( discFrame );
306 setupSmallButton( nextSectionButton );
307 discLayout->addWidget( nextSectionButton );
309 BUTTON_SET_IMG( prevSectionButton, "", dvd_prev, "" );
310 BUTTON_SET_IMG( nextSectionButton, "", dvd_next, "" );
311 BUTTON_SET_IMG( menuButton, "", dvd_menu, qtr( "Menu" ) );
315 /* Change the navigation button display when the IM navigation changes */
316 CONNECT( THEMIM->getIM(), navigationChanged( int ),
317 this, setNavigation( int ) );
318 /* Changes the IM navigation when triggered on the nav buttons */
319 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
321 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
323 CONNECT( menuButton, clicked(), THEMIM->getIM(),
328 * TODO: Merge with upper menu in a StackLayout
330 telexFrame = new QWidget( this );
331 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
332 telexLayout->setSpacing( 0 );
333 telexLayout->setMargin( 0 );
335 telexOn = new QPushButton;
336 setupSmallButton( telexOn );
337 telexLayout->addWidget( telexOn );
339 telexTransparent = new QPushButton;
340 setupSmallButton( telexTransparent );
341 telexLayout->addWidget( telexTransparent );
342 b_telexTransparent = false;
344 telexPage = new QSpinBox;
345 telexPage->setRange( 0, 999 );
346 telexPage->setValue( 100 );
347 telexPage->setAccelerated( true );
348 telexPage->setWrapping( true );
349 telexPage->setAlignment( Qt::AlignRight );
350 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
351 telexLayout->addWidget( telexPage );
353 telexFrame->hide(); /* default hidden */
355 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
356 telexGotoPage( int ) );
357 CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
358 telexPage, setValue( int ) );
360 BUTTON_SET_IMG( telexOn, "", tv, qtr( "Teletext on" ) );
362 CONNECT( telexOn, clicked(), THEMIM->getIM(),
363 telexToggleButtons() );
364 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
365 telexToggle( bool ) );
366 CONNECT( THEMIM->getIM(), toggleTelexButtons(),
367 this, toggleTeletext() );
368 b_telexEnabled = false;
369 telexTransparent->setEnabled( false );
370 telexPage->setEnabled( false );
372 BUTTON_SET_IMG( telexTransparent, "", tvtelx, qtr( "Teletext" ) );
373 CONNECT( telexTransparent, clicked( bool ),
374 THEMIM->getIM(), telexSetTransparency() );
375 CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
376 this, toggleTeletextTransparency() );
377 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
378 this, enableTeletext( bool ) );
381 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
382 sizePolicy.setHorizontalStretch( 0 );
383 sizePolicy.setVerticalStretch( 0 );
386 playButton = new QPushButton;
387 playButton->setSizePolicy( sizePolicy );
388 playButton->setMaximumSize( QSize( 32, 32 ) );
389 playButton->setMinimumSize( QSize( 32, 32 ) );
390 playButton->setIconSize( QSize( 26, 26 ) );
391 playButton->setFocusPolicy( Qt::NoFocus );
393 /** Prev + Stop + Next Block **/
394 controlButLayout = new QHBoxLayout;
395 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
398 QPushButton *prevButton = new QPushButton;
399 prevButton->setSizePolicy( sizePolicy );
400 setupSmallButton( prevButton );
402 controlButLayout->addWidget( prevButton );
405 QPushButton *stopButton = new QPushButton;
406 stopButton->setSizePolicy( sizePolicy );
407 setupSmallButton( stopButton );
409 controlButLayout->addWidget( stopButton );
412 QPushButton *nextButton = new QPushButton;
413 nextButton->setSizePolicy( sizePolicy );
414 setupSmallButton( nextButton );
416 controlButLayout->addWidget( nextButton );
418 /* Add this block to the main layout */
420 BUTTON_SET_ACT_I( playButton, "", play_b, qtr( I_PLAY_TOOLTIP ), play() );
421 BUTTON_SET_ACT_I( prevButton, "" , previous_b,
422 qtr( "Previous media in the playlist" ), prev() );
423 BUTTON_SET_ACT_I( nextButton, "", next_b,
424 qtr( "Next media in the playlist" ), next() );
425 BUTTON_SET_ACT_I( stopButton, "", stop_b, qtr( "Stop playback" ), stop() );
428 * Other first Line buttons
431 CONNECT( THEMIM->getIM(), voutChanged(bool), this, enableVideo(bool) );
433 /** Fullscreen/Visualisation **/
434 fullscreenButton = new QPushButton;
435 BUTTON_SET_ACT_I( fullscreenButton, "", fullscreen,
436 qtr( "Toggle the video in fullscreen" ), fullscreen() );
437 setupSmallButton( fullscreenButton );
441 /** Playlist Button **/
442 playlistButton = new QPushButton;
443 setupSmallButton( playlistButton );
444 BUTTON_SET_IMG( playlistButton, "" , playlist, qtr( "Show playlist" ) );
445 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
447 /** extended Settings **/
448 extSettingsButton = new QPushButton;
449 BUTTON_SET_ACT_I( extSettingsButton, "", extended,
450 qtr( "Show extended settings" ), extSettings() );
451 setupSmallButton( extSettingsButton );
455 hVolLabel = new VolumeClickHandler( p_intf, this );
457 volMuteLabel = new QLabel;
458 volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
459 volMuteLabel->installEventFilter( hVolLabel );
463 volumeSlider = new SoundSlider( this,
464 config_GetInt( p_intf, "volume-step" ),
465 config_GetInt( p_intf, "qt-volume-complete" ),
466 config_GetPsz( p_intf, "qt-slider-colours" ) );
470 volumeSlider = new QSlider( this );
471 volumeSlider->setOrientation( Qt::Horizontal );
473 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
474 volumeSlider->setMinimumSize( QSize( 85, 30 ) );
475 volumeSlider->setFocusPolicy( Qt::NoFocus );
477 /* Set the volume from the config */
478 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
479 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
481 /* Force the update at build time in order to have a muted icon if needed */
482 updateVolume( volumeSlider->value() );
484 /* Volume control connection */
485 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
486 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
490 controlLayout = new QGridLayout( this );
492 controlLayout->setSpacing( 0 );
493 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
495 controlLayout->addWidget( slider, 0, 1, 1, 18 );
496 controlLayout->addWidget( slowerButton, 0, 0 );
497 controlLayout->addWidget( fasterButton, 0, 19 );
499 controlLayout->addWidget( discFrame, 1, 8, 2, 3, Qt::AlignBottom );
500 controlLayout->addWidget( telexFrame, 1, 8, 2, 5, Qt::AlignBottom );
502 controlLayout->addWidget( playButton, 2, 0, 2, 2, Qt::AlignBottom );
503 controlLayout->setColumnMinimumWidth( 2, 10 );
504 controlLayout->setColumnStretch( 2, 0 );
506 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
507 /* Column 6 is unused */
508 controlLayout->setColumnStretch( 6, 0 );
509 controlLayout->setColumnStretch( 7, 0 );
510 controlLayout->setColumnMinimumWidth( 7, 10 );
512 controlLayout->addWidget( fullscreenButton, 3, 8, Qt::AlignBottom );
513 controlLayout->addWidget( playlistButton, 3, 9, Qt::AlignBottom );
514 controlLayout->addWidget( extSettingsButton, 3, 10, Qt::AlignBottom );
515 controlLayout->setColumnStretch( 11, 0 ); /* telex alignment */
517 controlLayout->setColumnStretch( 12, 0 );
518 controlLayout->setColumnMinimumWidth( 12, 10 );
520 controlLayout->addWidget( advControls, 3, 13, 1, 3, Qt::AlignBottom );
522 controlLayout->setColumnStretch( 16, 10 );
523 controlLayout->setColumnMinimumWidth( 16, 10 );
525 controlLayout->addWidget( volMuteLabel, 3, 17, Qt::AlignBottom );
526 controlLayout->addWidget( volumeSlider, 3, 18, 1 , 2, Qt::AlignBottom );
532 ControlsWidget::~ControlsWidget()
535 void ControlsWidget::toggleTeletext()
537 bool b_enabled = THEMIM->teletextState();
540 telexTransparent->setEnabled( false );
541 telexPage->setEnabled( false );
542 b_telexEnabled = false;
546 telexTransparent->setEnabled( true );
547 telexPage->setEnabled( true );
548 b_telexEnabled = true;
552 void ControlsWidget::enableTeletext( bool b_enable )
554 telexFrame->setVisible( b_enable );
555 bool b_on = THEMIM->teletextState();
557 telexOn->setChecked( b_on );
558 telexTransparent->setEnabled( b_on );
559 telexPage->setEnabled( b_on );
560 b_telexEnabled = b_on;
563 void ControlsWidget::toggleTeletextTransparency()
565 if( b_telexTransparent )
567 telexTransparent->setIcon( QIcon( ":/tvtelx" ) );
568 telexTransparent->setToolTip( qtr( "Teletext" ) );
569 b_telexTransparent = false;
573 telexTransparent->setIcon( QIcon( ":/tvtelx-trans" ) );
574 telexTransparent->setToolTip( qtr( "Transparent" ) );
575 b_telexTransparent = true;
579 void ControlsWidget::stop()
584 void ControlsWidget::play()
586 if( THEPL->current.i_size == 0 )
588 /* The playlist is empty, open a file requester */
589 THEDP->openFileDialog();
593 THEMIM->togglePlayPause();
596 void ControlsWidget::prev()
601 void ControlsWidget::next()
606 void ControlsWidget::setNavigation( int navigation )
608 #define HELP_PCH N_( "Previous chapter" )
609 #define HELP_NCH N_( "Next chapter" )
611 // 1 = chapter, 2 = title, 0 = no
612 if( navigation == 0 )
615 } else if( navigation == 1 ) {
616 prevSectionButton->setToolTip( qtr( HELP_PCH ) );
617 nextSectionButton->setToolTip( qtr( HELP_NCH ) );
621 prevSectionButton->setToolTip( qtr( HELP_PCH ) );
622 nextSectionButton->setToolTip( qtr( HELP_NCH ) );
628 static bool b_my_volume;
629 void ControlsWidget::updateVolume( int i_sliderVolume )
633 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
634 aout_VolumeSet( p_intf, i_res );
636 if( i_sliderVolume == 0 )
638 volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
639 volMuteLabel->setToolTip( qtr( "Unmute" ) );
643 if( i_sliderVolume < VOLUME_MAX / 3 )
644 volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
645 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
646 volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
647 else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
648 volMuteLabel->setToolTip( qtr( "Mute" ) );
651 void ControlsWidget::updateVolume()
654 audio_volume_t i_volume;
655 aout_VolumeGet( p_intf, &i_volume );
656 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
657 int i_gauge = volumeSlider->value();
659 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
662 volumeSlider->setValue( i_volume );
667 void ControlsWidget::updateInput()
669 /* Activate the interface buttons according to the presence of the input */
670 enableInput( THEMIM->getIM()->hasInput() );
671 enableVideo( THEMIM->getIM()->hasVideo() );
674 void ControlsWidget::setStatus( int status )
676 if( status == PLAYING_S ) /* Playing */
678 playButton->setIcon( QIcon( ":/pause_b" ) );
679 playButton->setToolTip( qtr( "Pause the playback" ) );
683 playButton->setIcon( QIcon( ":/play_b" ) );
684 playButton->setToolTip( qtr( I_PLAY_TOOLTIP ) );
690 * This functions toggle the fullscreen mode
691 * If there is no video, it should first activate Visualisations...
692 * This has also to be fixed in enableVideo()
694 void ControlsWidget::fullscreen()
696 vout_thread_t *p_vout =
697 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
700 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
701 vlc_object_release( p_vout );
705 void ControlsWidget::extSettings()
707 THEDP->extendedDialog();
710 void ControlsWidget::slower()
712 THEMIM->getIM()->slower();
715 void ControlsWidget::faster()
717 THEMIM->getIM()->faster();
720 void ControlsWidget::enableInput( bool enable )
722 slowerButton->setEnabled( enable );
723 slider->setEnabled( enable );
724 slider->setSliderPosition ( 0 );
725 fasterButton->setEnabled( enable );
727 /* Advanced Buttons too */
728 advControls->enableInput( enable );
731 void ControlsWidget::enableVideo( bool enable )
733 // TODO Later make the fullscreenButton toggle Visualisation and so on.
734 fullscreenButton->setEnabled( enable );
736 /* Advanced Buttons too */
737 advControls->enableVideo( enable );
740 void ControlsWidget::toggleAdvanced()
742 if( advControls && !b_advancedVisible )
745 b_advancedVisible = true;
750 b_advancedVisible = false;
752 emit advancedControlsToggled( b_advancedVisible );
755 /**********************************************************************
756 * Fullscrenn control widget
757 **********************************************************************/
758 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
759 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
760 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
761 i_mouse_last_x( -1 ), i_mouse_last_y( -1 ), b_mouse_over(false),
762 b_slow_hide_begin(false), i_slow_hide_timeout(1),
763 b_fullscreen( false ), i_hide_timeout( 1 ), p_vout(NULL)
765 i_mouse_last_move_x = -1;
766 i_mouse_last_move_y = -1;
768 setWindowFlags( Qt::ToolTip );
769 setMinimumWidth( 600 );
771 setFrameShape( QFrame::StyledPanel );
772 setFrameStyle( QFrame::Sunken );
773 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
775 QGridLayout *fsLayout = new QGridLayout( this );
776 fsLayout->setLayoutMargins( 5, 2, 5, 2, 5 );
779 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
780 fsLayout->addWidget( slowerButton, 0, 0 );
781 fsLayout->addWidget( slider, 0, 1, 1, 11 );
782 fsLayout->addWidget( fasterButton, 0, 12 );
785 fsLayout->addWidget( playButton, 1, 0, 1, 2 );
786 fsLayout->addLayout( controlButLayout, 1, 2 );
788 fsLayout->addWidget( discFrame, 1, 3 );
789 fsLayout->addWidget( telexFrame, 1, 4 );
790 fsLayout->addWidget( fullscreenButton, 1, 5 );
791 fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
793 fsLayout->setColumnStretch( 7, 10 );
795 TimeLabel *timeLabel = new TimeLabel( p_intf );
797 fsLayout->addWidget( timeLabel, 1, 8 );
798 fsLayout->addWidget( volMuteLabel, 1, 9 );
799 fsLayout->addWidget( volumeSlider, 1, 10, 1, 2 );
802 p_hideTimer = new QTimer( this );
803 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
804 p_hideTimer->setSingleShot( true );
806 /* slow hiding timer */
807 #if HAVE_TRANSPARENCY
808 p_slowHideTimer = new QTimer( this );
809 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
812 adjustSize (); /* need to get real width and height for moving */
815 QWidget * p_desktop = QApplication::desktop()->screen(
816 QApplication::desktop()->screenNumber( _p_mi ) );
818 QPoint pos = QPoint( p_desktop->width() / 2 - width() / 2,
819 p_desktop->height() - height() );
821 getSettings()->beginGroup( "FullScreen" );
822 move( getSettings()->value( "pos", pos ).toPoint() );
823 getSettings()->endGroup();
826 setWindowOpacity( 0.0 );
832 fullscreenButton->setIcon( QIcon( ":/defullscreen" ) );
834 vlc_mutex_init_recursive( &lock );
837 FullscreenControllerWidget::~FullscreenControllerWidget()
839 getSettings()->beginGroup( "FullScreen" );
840 getSettings()->setValue( "pos", pos() );
841 getSettings()->endGroup();
843 vlc_mutex_destroy( &lock );
847 * Show fullscreen controller
849 void FullscreenControllerWidget::showFSC()
853 // after quiting and going to fs, we need to call show()
860 setWindowOpacity( 1.0 );
866 #if HAVE_TRANSPARENCY
867 setWindowOpacity( DEFAULT_OPACITY );
872 * Hide fullscreen controller
873 * FIXME: under windows it have to be done by moving out of screen
874 * because hide() doesnt work
876 void FullscreenControllerWidget::hideFSC()
880 setWindowOpacity( 0.0 ); // simulate hidding
887 * Plane to hide fullscreen controller
889 void FullscreenControllerWidget::planHideFSC()
891 vlc_mutex_lock( &lock );
892 int i_timeout = i_hide_timeout;
893 vlc_mutex_unlock( &lock );
895 p_hideTimer->start( i_timeout );
897 #if HAVE_TRANSPARENCY
898 b_slow_hide_begin = true;
899 i_slow_hide_timeout = i_timeout;
900 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
905 * Hidding fullscreen controller slowly
906 * Linux: need composite manager
907 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
909 void FullscreenControllerWidget::slowHideFSC()
911 #if HAVE_TRANSPARENCY
912 if( b_slow_hide_begin )
914 b_slow_hide_begin = false;
916 p_slowHideTimer->stop();
917 /* the last part of time divided to 100 pieces */
918 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
924 if ( windowOpacity() > 0.0 && !b_fscHidden )
926 if ( windowOpacity() > 0.0 )
929 /* we should use 0.01 because of 100 pieces ^^^
930 but than it cannt be done in time */
931 setWindowOpacity( windowOpacity() - 0.02 );
934 if ( windowOpacity() <= 0.0 )
935 p_slowHideTimer->stop();
942 * events: show, hide, start timer for hidding
944 void FullscreenControllerWidget::customEvent( QEvent *event )
948 switch( event->type() )
950 case FullscreenControlToggle_Type:
951 vlc_mutex_lock( &lock );
953 vlc_mutex_unlock( &lock );
967 case FullscreenControlShow_Type:
968 vlc_mutex_lock( &lock );
970 vlc_mutex_unlock( &lock );
973 if( b_fs && b_fscHidden ) // FIXME I am not sure about that one
975 if( b_fs && !isVisible() ) // FIXME I am not sure about that one
979 case FullscreenControlHide_Type:
982 case FullscreenControlPlanHide_Type:
983 if( !b_mouse_over ) // Only if the mouse is not over FSC
993 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
995 if ( event->buttons() == Qt::LeftButton )
997 int i_moveX = event->globalX() - i_mouse_last_x;
998 int i_moveY = event->globalY() - i_mouse_last_y;
1000 move( x() + i_moveX, y() + i_moveY );
1002 i_mouse_last_x = event->globalX();
1003 i_mouse_last_y = event->globalY();
1009 * store position of cursor
1011 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1013 i_mouse_last_x = event->globalX();
1014 i_mouse_last_y = event->globalY();
1018 * On mouse go above FSC
1020 void FullscreenControllerWidget::enterEvent( QEvent *event )
1022 b_mouse_over = true;
1024 p_hideTimer->stop();
1025 #if HAVE_TRANSPARENCY
1026 p_slowHideTimer->stop();
1031 * On mouse go out from FSC
1033 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1037 b_mouse_over = false;
1041 * When you get pressed key, send it to video output
1042 * FIXME: clearing focus by clearFocus() to not getting
1043 * key press events didnt work
1045 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1047 int i_vlck = qtEventToVLCKey( event );
1050 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1058 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object,
1059 const char *variable, vlc_value_t old_val,
1060 vlc_value_t new_val, void *data )
1062 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1063 msg_Dbg( p_vout, "Qt4: Fullscreen state changed" );
1064 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1066 p_fs->fullscreenChanged( p_vout, new_val.b_bool,
1067 var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1072 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1073 vlc_value_t old_val, vlc_value_t new_val,
1076 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1078 int i_mousex, i_mousey;
1079 bool b_toShow = false;
1081 /* Get the value from the Vout - Trust the vout more than Qt */
1082 i_mousex = var_GetInteger( p_fs->p_vout, "mouse-x" );
1083 i_mousey = var_GetInteger( p_fs->p_vout, "mouse-y" );
1086 if( p_fs->i_mouse_last_move_x == -1 || p_fs->i_mouse_last_move_y == -1 )
1088 p_fs->i_mouse_last_move_x = i_mousex;
1089 p_fs->i_mouse_last_move_y = i_mousey;
1092 /* All other times */
1095 /* Trigger only if move > 3 px dans une direction */
1096 if( abs( p_fs->i_mouse_last_move_x - i_mousex ) > 2 ||
1097 abs( p_fs->i_mouse_last_move_y - i_mousey ) > 2 )
1100 p_fs->i_mouse_last_move_x = i_mousex;
1101 p_fs->i_mouse_last_move_y = i_mousey;
1108 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1109 QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1111 /* Plan hide event */
1112 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1113 QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1121 * It is called when video start
1123 void FullscreenControllerWidget::attachVout( vout_thread_t *p_nvout )
1125 assert( p_nvout && !p_vout );
1129 msg_Dbg( p_vout, "Qt FS: Attaching Vout" );
1130 vlc_mutex_lock( &lock );
1132 var_AddCallback( p_vout, "fullscreen",
1133 FullscreenControllerWidgetFullscreenChanged, this );
1134 /* I miss a add and fire */
1135 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ),
1136 var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1137 vlc_mutex_unlock( &lock );
1140 * It is called after turn off video.
1142 void FullscreenControllerWidget::detachVout()
1146 msg_Dbg( p_vout, "Qt FS: Detaching Vout" );
1147 var_DelCallback( p_vout, "fullscreen",
1148 FullscreenControllerWidgetFullscreenChanged, this );
1149 vlc_mutex_lock( &lock );
1150 fullscreenChanged( p_vout, false, 0 );
1151 vlc_mutex_unlock( &lock );
1157 * Register and unregister callback for mouse moving
1159 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout,
1160 bool b_fs, int i_timeout )
1162 msg_Dbg( p_vout, "Qt: Entering Fullscreen" );
1164 vlc_mutex_lock( &lock );
1165 /* Entering fullscreen, register callback */
1166 if( b_fs && !b_fullscreen )
1168 b_fullscreen = true;
1169 i_hide_timeout = i_timeout;
1170 var_AddCallback( p_vout, "mouse-moved",
1171 FullscreenControllerWidgetMouseMoved, this );
1173 /* Quitting fullscreen, unregistering callback */
1174 else if( !b_fs && b_fullscreen )
1176 b_fullscreen = false;
1177 i_hide_timeout = i_timeout;
1178 var_DelCallback( p_vout, "mouse-moved",
1179 FullscreenControllerWidgetMouseMoved, this );
1181 /* Force fs hidding */
1182 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1183 QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1185 vlc_mutex_unlock( &lock );