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 *****************************************************************************/
31 #include "dialogs_provider.hpp"
32 #include "components/interface_widgets.hpp"
33 #include "main_interface.hpp"
34 #include "input_manager.hpp"
36 #include "util/input_slider.hpp"
37 #include "util/customwidgets.hpp"
41 #include <QSpacerItem>
43 #include <QPushButton>
44 #include <QToolButton>
45 #include <QHBoxLayout>
48 #include <QResizeEvent>
51 # include <X11/Xlib.h>
52 # include <qx11info_x11.h>
55 /**********************************************************************
56 * Video Widget. A simple frame on which video is drawn
57 * This class handles resize issues
58 **********************************************************************/
60 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
63 vlc_mutex_init( &lock );
65 hide(); setMinimumSize( 16, 16 );
66 videoSize.rwidth() = -1;
67 videoSize.rheight() = -1;
69 /* Black background is more coherent for a Video Widget IMVHO */
70 QPalette plt = palette();
71 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
72 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
74 setAttribute( Qt::WA_PaintOnScreen, true );
76 /* The core can ask through a callback to show the video. */
77 CONNECT( this, askVideoWidgetToShow(), this, show() );
79 /* The core can ask through a callback to resize the video */
80 // CONNECT( this, askResize( int, int ), this, SetSizing( int, int ) );
83 void VideoWidget::paintEvent(QPaintEvent *ev)
85 QFrame::paintEvent(ev);
87 XFlush( QX11Info::display() );
91 VideoWidget::~VideoWidget()
93 vlc_mutex_lock( &lock );
96 if( !p_intf->psz_switch_intf )
98 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
99 vout_Control( p_vout, VOUT_REPARENT );
103 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
104 vout_Control( p_vout, VOUT_CLOSE );
107 vlc_mutex_unlock( &lock );
108 vlc_mutex_destroy( &lock );
112 * Request the video to avoid the conflicts
114 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
115 unsigned int *pi_width, unsigned int *pi_height )
117 msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
118 emit askVideoWidgetToShow();
121 msg_Dbg( p_intf, "embedded video already in use" );
125 msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );
126 return ( void* )winId();
129 /* Set the Widget to the correct Size */
130 /* Function has to be called by the parent
131 Parent has to care about resizing himself*/
132 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
134 msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
135 videoSize.rwidth() = w;
136 videoSize.rheight() = h;
137 updateGeometry(); // Needed for deinterlace
140 void VideoWidget::release( void *p_win )
142 msg_Dbg( p_intf, "Video is non needed anymore" );
144 videoSize.rwidth() = 0;
145 videoSize.rheight() = 0;
147 updateGeometry(); // Needed for deinterlace
150 QSize VideoWidget::sizeHint() const
155 /**********************************************************************
156 * Background Widget. Show a simple image background. Currently,
157 * it's album art if present or cone.
158 **********************************************************************/
159 #define ICON_SIZE 128
160 #define MAX_BG_SIZE 400
161 #define MIN_BG_SIZE 64
163 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
164 :QWidget( NULL ), p_intf( _p_i )
166 /* We should use that one to take the more size it can */
167 // setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
169 /* A dark background */
170 setAutoFillBackground( true );
172 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
173 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
176 /* A cone in the middle */
178 label->setMargin( 5 );
179 label->setMaximumHeight( MAX_BG_SIZE );
180 label->setMaximumWidth( MAX_BG_SIZE );
181 label->setMinimumHeight( MIN_BG_SIZE );
182 label->setMinimumWidth( MIN_BG_SIZE );
183 if( QDate::currentDate().dayOfYear() >= 354 )
184 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
186 label->setPixmap( QPixmap( ":/vlc128.png" ) );
188 QGridLayout *backgroundLayout = new QGridLayout( this );
189 backgroundLayout->addWidget( label, 0, 1 );
190 backgroundLayout->setColumnStretch( 0, 1 );
191 backgroundLayout->setColumnStretch( 2, 1 );
193 CONNECT( THEMIM->getIM(), artChanged( QString ), this, updateArt( QString ) );
196 BackgroundWidget::~BackgroundWidget()
200 void BackgroundWidget::resizeEvent( QResizeEvent * event )
202 if( event->size().height() <= MIN_BG_SIZE )
208 void BackgroundWidget::updateArt( QString url )
212 if( QDate::currentDate().dayOfYear() >= 354 )
213 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
215 label->setPixmap( QPixmap( ":/vlc128.png" ) );
220 label->setPixmap( QPixmap( url ) );
224 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
226 QVLCMenu::PopupMenu( p_intf, true );
229 /**********************************************************************
230 * Visualization selector panel
231 **********************************************************************/
232 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
233 QFrame( NULL ), p_intf( _p_i )
235 QHBoxLayout *layout = new QHBoxLayout( this );
236 layout->setMargin( 0 );
237 QPushButton *prevButton = new QPushButton( "Prev" );
238 QPushButton *nextButton = new QPushButton( "Next" );
239 layout->addWidget( prevButton );
240 layout->addWidget( nextButton );
242 layout->addItem( new QSpacerItem( 40,20,
243 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
244 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
246 current = new QLabel( qtr( "None" ) );
247 layout->addWidget( current );
249 BUTTONACT( prevButton, prev() );
250 BUTTONACT( nextButton, next() );
253 setMaximumHeight( 35 );
256 VisualSelector::~VisualSelector()
260 void VisualSelector::prev()
262 char *psz_new = aout_VisualPrev( p_intf );
265 current->setText( qfu( psz_new ) );
270 void VisualSelector::next()
272 char *psz_new = aout_VisualNext( p_intf );
275 current->setText( qfu( psz_new ) );
280 /**********************************************************************
282 **********************************************************************/
284 #define setupSmallButton( aButton ){ \
285 aButton->setMaximumSize( QSize( 26, 26 ) ); \
286 aButton->setMinimumSize( QSize( 26, 26 ) ); \
287 aButton->setIconSize( QSize( 20, 20 ) ); }
289 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
290 QFrame( NULL ), p_intf( _p_i )
292 QHBoxLayout *advLayout = new QHBoxLayout( this );
293 advLayout->setMargin( 0 );
294 advLayout->setSpacing( 0 );
295 advLayout->setAlignment( Qt::AlignBottom );
298 ABButton = new QPushButton( "AB" );
299 setupSmallButton( ABButton );
300 advLayout->addWidget( ABButton );
301 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
303 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
304 this, AtoBLoop( float, int, int ) );
306 frameButton = new QPushButton( "Fr" );
307 frameButton->setMaximumSize( QSize( 26, 26 ) );
308 frameButton->setIconSize( QSize( 20, 20 ) );
309 advLayout->addWidget( frameButton );
310 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
313 recordButton = new QPushButton( "R" );
314 setupSmallButton( recordButton );
315 advLayout->addWidget( recordButton );
316 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
317 qtr( "Record" ), record() );
319 /* Snapshot Button */
320 snapshotButton = new QPushButton( "S" );
321 setupSmallButton( snapshotButton );
322 advLayout->addWidget( snapshotButton );
323 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
326 AdvControlsWidget::~AdvControlsWidget()
329 void AdvControlsWidget::enableInput( bool enable )
331 ABButton->setEnabled( enable );
332 recordButton->setEnabled( enable );
335 void AdvControlsWidget::enableVideo( bool enable )
337 snapshotButton->setEnabled( enable );
339 frameButton->setEnabled( enable );
343 void AdvControlsWidget::snapshot()
345 vout_thread_t *p_vout =
346 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
347 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
350 /* Function called when the button is clicked() */
351 void AdvControlsWidget::fromAtoB()
355 timeA = var_GetTime( THEMIM->getInput(), "time" );
356 ABButton->setText( "A->..." );
361 timeB = var_GetTime( THEMIM->getInput(), "time" );
362 var_SetTime( THEMIM->getInput(), "time" , timeA );
363 ABButton->setText( "A<=>B" );
368 ABButton->setText( "AB" );
371 /* Function called regularly when in an AtoB loop */
372 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
376 if( i_time >= (int)(timeB/1000000) )
377 var_SetTime( THEMIM->getInput(), "time" , timeA );
381 /* FIXME Record function */
382 void AdvControlsWidget::record(){}
385 //FIXME Frame by frame function
386 void AdvControlsWidget::frame(){}
389 /*****************************
390 * DA Control Widget !
391 *****************************/
392 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
393 MainInterface *_p_mi,
397 QFrame( _p_mi ), p_intf( _p_i )
399 controlLayout = new QGridLayout( );
401 controlLayout->setSpacing( 0 );
402 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
405 setLayout( controlLayout );
407 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
409 /** The main Slider **/
410 slider = new InputSlider( Qt::Horizontal, NULL );
411 controlLayout->addWidget( slider, 0, 1, 1, 16 );
412 /* Update the position when the IM has changed */
413 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
414 slider, setPosition( float, int, int ) );
415 /* And update the IM, when the position has changed */
416 CONNECT( slider, sliderDragged( float ),
417 THEMIM->getIM(), sliderUpdate( float ) );
419 /** Slower and faster Buttons **/
420 slowerButton = new QToolButton;
421 slowerButton->setAutoRaise( true );
422 slowerButton->setMaximumSize( QSize( 26, 20 ) );
424 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
425 controlLayout->addWidget( slowerButton, 0, 0 );
427 fasterButton = new QToolButton;
428 fasterButton->setAutoRaise( true );
429 fasterButton->setMaximumSize( QSize( 26, 20 ) );
431 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
432 controlLayout->addWidget( fasterButton, 0, 17 );
434 /* advanced Controls handling */
435 b_advancedVisible = b_advControls;
437 advControls = new AdvControlsWidget( p_intf );
438 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
439 if( !b_advancedVisible ) advControls->hide();
441 /** Disc and Menus handling */
442 discFrame = new QWidget( this );
444 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
445 discLayout->setSpacing( 0 );
446 discLayout->setMargin( 0 );
448 prevSectionButton = new QPushButton( discFrame );
449 setupSmallButton( prevSectionButton );
450 discLayout->addWidget( prevSectionButton );
452 menuButton = new QPushButton( discFrame );
453 setupSmallButton( menuButton );
454 discLayout->addWidget( menuButton );
456 nextSectionButton = new QPushButton( discFrame );
457 setupSmallButton( nextSectionButton );
458 discLayout->addWidget( nextSectionButton );
460 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
462 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
463 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
464 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
468 /* Change the navigation button display when the IM navigation changes */
469 CONNECT( THEMIM->getIM(), navigationChanged( int ),
470 this, setNavigation( int ) );
471 /* Changes the IM navigation when triggered on the nav buttons */
472 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
474 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
476 CONNECT( menuButton, clicked(), THEMIM->getIM(),
481 * TODO: Merge with upper menu in a StackLayout
483 telexFrame = new QWidget( this );
484 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
485 telexLayout->setSpacing( 0 );
486 telexLayout->setMargin( 0 );
488 QPushButton *telexOn = new QPushButton;
489 setupSmallButton( telexOn );
490 telexLayout->addWidget( telexOn );
492 telexTransparent = new QPushButton;
493 setupSmallButton( telexTransparent );
494 telexLayout->addWidget( telexTransparent );
495 b_telexTransparent = false;
497 telexPage = new QSpinBox;
498 telexPage->setRange( 0, 999 );
499 telexPage->setValue( 100 );
500 telexPage->setAccelerated( true );
501 telexPage->setWrapping( true );
502 telexPage->setAlignment( Qt::AlignRight );
503 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
504 telexLayout->addWidget( telexPage );
506 controlLayout->addWidget( telexFrame, 1, 10, 2, 4, Qt::AlignBottom );
507 telexFrame->hide(); /* default hidden */
509 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
510 telexGotoPage( int ) );
512 BUTTON_SET_ACT_I( telexOn, "", tv.png, qtr( "Teletext on" ),
514 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
515 telexToggle( bool ) );
516 telexTransparent->setEnabled( false );
517 telexPage->setEnabled( false );
519 BUTTON_SET_ACT_I( telexTransparent, "", tvtelx.png, qtr( "Teletext" ),
520 toggleTeletextTransparency() );
521 CONNECT( telexTransparent, clicked( bool ),
522 THEMIM->getIM(), telexSetTransparency() );
523 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
524 telexFrame, setVisible( bool ) );
527 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
528 sizePolicy.setHorizontalStretch( 0 );
529 sizePolicy.setVerticalStretch( 0 );
532 playButton = new QPushButton;
533 playButton->setSizePolicy( sizePolicy );
534 playButton->setMaximumSize( QSize( 36, 36 ) );
535 playButton->setMinimumSize( QSize( 36, 36 ) );
536 playButton->setIconSize( QSize( 30, 30 ) );
538 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
540 controlLayout->setColumnMinimumWidth( 2, 20 );
541 controlLayout->setColumnStretch( 2, 0 );
543 /** Prev + Stop + Next Block **/
544 controlButLayout = new QHBoxLayout;
545 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
548 QPushButton *prevButton = new QPushButton;
549 prevButton->setSizePolicy( sizePolicy );
550 setupSmallButton( prevButton );
552 controlButLayout->addWidget( prevButton );
555 QPushButton *stopButton = new QPushButton;
556 stopButton->setSizePolicy( sizePolicy );
557 setupSmallButton( stopButton );
559 controlButLayout->addWidget( stopButton );
562 QPushButton *nextButton = new QPushButton;
563 nextButton->setSizePolicy( sizePolicy );
564 setupSmallButton( nextButton );
566 controlButLayout->addWidget( nextButton );
568 /* Add this block to the main layout */
570 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
572 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
573 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
574 qtr( "Previous" ), prev() );
575 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
576 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
578 controlLayout->setColumnMinimumWidth( 7, 20 );
579 controlLayout->setColumnStretch( 7, 0 );
580 controlLayout->setColumnStretch( 8, 0 );
581 controlLayout->setColumnStretch( 9, 0 );
584 * Other first Line buttons
586 /** Fullscreen/Visualisation **/
587 fullscreenButton = new QPushButton( "F" );
588 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
589 setupSmallButton( fullscreenButton );
590 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
592 /** Playlist Button **/
593 playlistButton = new QPushButton;
594 setupSmallButton( playlistButton );
595 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
596 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
597 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
599 /** extended Settings **/
600 extSettingsButton = new QPushButton;
601 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
603 setupSmallButton( extSettingsButton );
604 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
606 controlLayout->setColumnStretch( 13, 0 );
607 controlLayout->setColumnMinimumWidth( 13, 24 );
608 controlLayout->setColumnStretch( 14, 5 );
611 hVolLabel = new VolumeClickHandler( p_intf, this );
613 volMuteLabel = new QLabel;
614 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
615 volMuteLabel->setToolTip( qtr( "Mute" ) );
616 volMuteLabel->installEventFilter( hVolLabel );
617 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
621 volumeSlider = new SoundSlider( this,
622 config_GetInt( p_intf, "volume-step" ),
623 config_GetInt( p_intf, "qt-volume-complete" ),
624 config_GetPsz( p_intf, "qt-slider-colours" ) );
628 volumeSlider = new QSlider( this );
629 volumeSlider->setOrientation( Qt::Horizontal );
631 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
632 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
633 volumeSlider->setFocusPolicy( Qt::NoFocus );
634 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
636 /* Set the volume from the config */
637 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
638 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
640 /* Force the update at build time in order to have a muted icon if needed */
641 updateVolume( volumeSlider->value() );
643 /* Volume control connection */
644 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
645 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
650 ControlsWidget::~ControlsWidget()
653 void ControlsWidget::toggleTeletext()
655 bool b_enabled = THEMIM->teletextState();
658 telexTransparent->setEnabled( false );
659 telexPage->setEnabled( false );
660 b_telexEnabled = false;
664 telexTransparent->setEnabled( true );
665 telexPage->setEnabled( true );
666 b_telexEnabled = true;
670 void ControlsWidget::toggleTeletextTransparency()
672 if( b_telexTransparent )
674 telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx.png" ) );
675 telexTransparent->setToolTip( qtr( "Teletext" ) );
676 b_telexTransparent = false;
680 telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx-transparent.png" ) );
681 telexTransparent->setToolTip( qtr( "Transparent" ) );
682 b_telexTransparent = true;
686 void ControlsWidget::stop()
691 void ControlsWidget::play()
693 if( THEPL->current.i_size == 0 )
695 /* The playlist is empty, open a file requester */
696 THEDP->openFileDialog();
700 THEMIM->togglePlayPause();
703 void ControlsWidget::prev()
708 void ControlsWidget::next()
713 void ControlsWidget::setNavigation( int navigation )
715 #define HELP_MENU N_( "Menu" )
716 #define HELP_PCH N_( "Previous chapter" )
717 #define HELP_NCH N_( "Next chapter" )
718 #define HELP_PTR N_( "Previous track" )
719 #define HELP_NTR N_( "Next track" )
721 // 1 = chapter, 2 = title, 0 = no
722 if( navigation == 0 )
725 } else if( navigation == 1 ) {
726 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
727 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
731 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
732 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
738 static bool b_my_volume;
739 void ControlsWidget::updateVolume( int i_sliderVolume )
743 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
744 aout_VolumeSet( p_intf, i_res );
746 if( i_sliderVolume == 0 )
747 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
748 else if( i_sliderVolume < VOLUME_MAX / 3 )
749 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
750 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
751 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
752 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
755 void ControlsWidget::updateVolume()
758 audio_volume_t i_volume;
759 aout_VolumeGet( p_intf, &i_volume );
760 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
761 int i_gauge = volumeSlider->value();
763 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
766 volumeSlider->setValue( i_volume );
771 void ControlsWidget::updateInput()
773 /* Activate the interface buttons according to the presence of the input */
774 enableInput( THEMIM->getIM()->hasInput() );
775 enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
778 void ControlsWidget::setStatus( int status )
780 if( status == PLAYING_S ) /* Playing */
782 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
783 playButton->setToolTip( qtr( "Pause" ) );
787 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
788 playButton->setToolTip( qtr( "Play" ) );
794 * This functions toggle the fullscreen mode
795 * If there is no video, it should first activate Visualisations...
796 * This has also to be fixed in enableVideo()
798 void ControlsWidget::fullscreen()
800 vout_thread_t *p_vout =
801 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
804 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
805 vlc_object_release( p_vout );
809 void ControlsWidget::extSettings()
811 THEDP->extendedDialog();
814 void ControlsWidget::slower()
816 THEMIM->getIM()->slower();
819 void ControlsWidget::faster()
821 THEMIM->getIM()->faster();
824 void ControlsWidget::enableInput( bool enable )
826 slowerButton->setEnabled( enable );
827 slider->setEnabled( enable );
828 fasterButton->setEnabled( enable );
830 /* Advanced Buttons too */
831 advControls->enableInput( enable );
834 void ControlsWidget::enableVideo( bool enable )
836 // TODO Later make the fullscreenButton toggle Visualisation and so on.
837 fullscreenButton->setEnabled( enable );
839 /* Advanced Buttons too */
840 advControls->enableVideo( enable );
843 void ControlsWidget::toggleAdvanced()
845 if( !VISIBLE( advControls ) )
848 b_advancedVisible = true;
853 b_advancedVisible = false;
855 emit advancedControlsToggled( b_advancedVisible );
859 /**********************************************************************
860 * Fullscrenn control widget
861 **********************************************************************/
862 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
863 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
864 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
865 i_lastPosX( -1 ), i_lastPosY( -1 ), i_hideTimeout( 1 ),
866 b_mouseIsOver( false )
868 setWindowFlags( Qt::ToolTip );
870 setFrameShape( QFrame::StyledPanel );
871 setFrameStyle( QFrame::Sunken );
872 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
874 QGridLayout *fsLayout = new QGridLayout( this );
875 controlLayout->setSpacing( 0 );
876 controlLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
878 fsLayout->addWidget( slowerButton, 0, 0 );
879 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
880 fsLayout->addWidget( slider, 0, 1, 1, 6 );
881 fsLayout->addWidget( fasterButton, 0, 7 );
883 fsLayout->addWidget( volMuteLabel, 1, 0);
884 fsLayout->addWidget( volumeSlider, 1, 1 );
886 fsLayout->addLayout( controlButLayout, 1, 2 );
888 fsLayout->addWidget( playButton, 1, 3 );
890 fsLayout->addWidget( discFrame, 1, 4 );
892 fsLayout->addWidget( telexFrame, 1, 5 );
894 fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
896 fsLayout->addWidget( fullscreenButton, 1, 7 );
899 p_hideTimer = new QTimer( this );
900 CONNECT( p_hideTimer, timeout(), this, hideFSControllerWidget() );
901 p_hideTimer->setSingleShot( true );
903 /* slow hiding timer */
904 #if HAVE_TRANSPARENCY
905 p_slowHideTimer = new QTimer( this );
906 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
909 adjustSize (); /* need to get real width and height for moving */
912 QDesktopWidget * p_desktop = QApplication::desktop();
914 move( p_desktop->width() / 2 - width() / 2,
915 p_desktop->height() - height() );
918 setWindowOpacity( 0.0 );
924 FullscreenControllerWidget::~FullscreenControllerWidget()
929 * Hide fullscreen controller
930 * FIXME: under windows it have to be done by moving out of screen
931 * because hide() doesnt work
933 void FullscreenControllerWidget::hideFSControllerWidget()
937 setWindowOpacity( 0.0 ); // simulate hidding
944 * Hidding fullscreen controller slowly
945 * Linux: need composite manager
946 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
948 void FullscreenControllerWidget::slowHideFSC()
950 #if HAVE_TRANSPARENCY
951 static bool first_call = true;
957 p_slowHideTimer->stop();
958 /* the last part of time divided to 100 pieces */
959 p_slowHideTimer->start(
960 (int) ( i_hideTimeout / 2 / ( windowOpacity() * 100 ) ) );
964 if ( windowOpacity() > 0.0 )
966 /* we should use 0.01 because of 100 pieces ^^^
967 but than it cannt be done in time */
968 setWindowOpacity( windowOpacity() - 0.02 );
971 if ( windowOpacity() == 0.0 )
974 p_slowHideTimer->stop();
981 * Get state of visibility of FS controller on screen
982 * On windows control if it is on hidden position
984 bool FullscreenControllerWidget::isFSCHidden()
995 * events: show, hide, start timer for hidding
997 void FullscreenControllerWidget::customEvent( QEvent *event )
999 int type = event->type();
1001 if ( type == FullscreenControlShow_Type )
1004 // after quiting and going to fs, we need to call show()
1011 setWindowOpacity( 1.0 );
1017 #if HAVE_TRANSPARENCY
1018 setWindowOpacity( DEFAULT_OPACITY );
1021 else if ( type == FullscreenControlHide_Type )
1023 hideFSControllerWidget();
1025 else if ( type == FullscreenControlPlanHide_Type && !b_mouseIsOver )
1027 p_hideTimer->start( i_hideTimeout );
1028 #if HAVE_TRANSPARENCY
1029 p_slowHideTimer->start( i_hideTimeout / 2 );
1038 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1040 if ( event->buttons() == Qt::LeftButton )
1042 int i_moveX = event->globalX() - i_lastPosX;
1043 int i_moveY = event->globalY() - i_lastPosY;
1045 move( x() + i_moveX, y() + i_moveY );
1047 i_lastPosX = event->globalX();
1048 i_lastPosY = event->globalY();
1054 * store position of cursor
1056 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1058 i_lastPosX = event->globalX();
1059 i_lastPosY = event->globalY();
1063 * On mouse go above FSC
1065 void FullscreenControllerWidget::enterEvent( QEvent *event )
1067 p_hideTimer->stop();
1068 #if HAVE_TRANSPARENCY
1069 p_slowHideTimer->stop();
1071 b_mouseIsOver = true;
1075 * On mouse go out from FSC
1077 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1079 p_hideTimer->start( i_hideTimeout );
1080 #if HAVE_TRANSPARENCY
1081 p_slowHideTimer->start( i_hideTimeout / 2 );
1083 b_mouseIsOver = false;
1087 * When you get pressed key, send it to video output
1088 * FIXME: clearing focus by clearFocus() to not getting
1089 * key press events didnt work
1091 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1093 int i_vlck = qtEventToVLCKey( event );
1096 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1104 * It is called when video start
1106 void FullscreenControllerWidget::regFullscreenCallback( vout_thread_t *p_vout )
1110 var_AddCallback( p_vout, "fullscreen", regMouseMoveCallback, this );
1115 * It is called after turn off video, because p_vout is NULL now
1116 * we cannt delete callback, just hide if FScontroller is visible
1118 void FullscreenControllerWidget::unregFullscreenCallback()
1125 * Register and unregister callback for mouse moving
1127 static int regMouseMoveCallback( vlc_object_t *vlc_object, const char *variable,
1128 vlc_value_t old_val, vlc_value_t new_val,
1131 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1133 static bool b_registered = false;
1134 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1136 if ( var_GetBool( p_vout, "fullscreen" ) && !b_registered )
1138 p_fs->SetHideTimeout( var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1139 var_AddCallback( p_vout, "mouse-moved",
1140 showFullscreenControllCallback, (void *) p_fs );
1141 b_registered = true;
1144 if ( !var_GetBool( p_vout, "fullscreen" ) && b_registered )
1146 var_DelCallback( p_vout, "mouse-moved",
1147 showFullscreenControllCallback, (void *) p_fs );
1148 b_registered = false;
1156 * Show fullscreen controller after mouse move
1157 * after show immediately plan hide event
1159 static int showFullscreenControllCallback( vlc_object_t *vlc_object, const char *variable,
1160 vlc_value_t old_val, vlc_value_t new_val,
1163 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1165 if ( p_fs->isFSCHidden() || p_fs->windowOpacity() < DEFAULT_OPACITY )
1167 IMEvent *event = new IMEvent( FullscreenControlShow_Type, 0 );
1168 QApplication::postEvent( p_fs, static_cast<QEvent *>(event) );
1171 IMEvent *e = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1172 QApplication::postEvent( p_fs, static_cast<QEvent *>(e) );
1177 /**********************************************************************
1178 * Speed control widget
1179 **********************************************************************/
1180 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1181 QFrame( NULL ), p_intf( _p_i )
1183 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1184 sizePolicy.setHorizontalStretch( 0 );
1185 sizePolicy.setVerticalStretch( 0 );
1187 speedSlider = new QSlider;
1188 speedSlider->setSizePolicy( sizePolicy );
1189 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1190 speedSlider->setOrientation( Qt::Vertical );
1191 speedSlider->setTickPosition( QSlider::TicksRight );
1193 speedSlider->setRange( -100, 100 );
1194 speedSlider->setSingleStep( 10 );
1195 speedSlider->setPageStep( 20 );
1196 speedSlider->setTickInterval( 20 );
1198 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1200 QToolButton *normalSpeedButton = new QToolButton( this );
1201 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1202 normalSpeedButton->setAutoRaise( true );
1203 normalSpeedButton->setText( "N" );
1204 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1206 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1208 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1209 speedControlLayout->addWidget( speedSlider );
1210 speedControlLayout->addWidget( normalSpeedButton );
1211 setLayout( speedControlLayout );
1214 SpeedControlWidget::~SpeedControlWidget()
1217 void SpeedControlWidget::setEnable( bool b_enable )
1219 speedSlider->setEnabled( b_enable );
1222 #define RATE_SLIDER_MAXIMUM 3.0
1223 #define RATE_SLIDER_MINIMUM 0.3
1224 #define RATE_SLIDER_LENGTH 100.0
1226 void SpeedControlWidget::updateControls( int rate )
1228 if( speedSlider->isSliderDown() )
1230 //We don't want to change anything if the user is using the slider
1235 double speed = INPUT_RATE_DEFAULT / (double)rate;
1237 if( rate >= INPUT_RATE_DEFAULT )
1239 if( speed < RATE_SLIDER_MINIMUM )
1241 sliderValue = speedSlider->minimum();
1245 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
1246 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
1251 if( speed > RATE_SLIDER_MAXIMUM )
1253 sliderValue = speedSlider->maximum();
1257 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
1258 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
1262 //Block signals to avoid feedback loop
1263 speedSlider->blockSignals( true );
1264 speedSlider->setValue( sliderValue );
1265 speedSlider->blockSignals( false );
1268 void SpeedControlWidget::updateRate( int sliderValue )
1272 if( sliderValue < 0.0 )
1274 rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
1275 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ));
1279 rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
1280 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH ));
1283 THEMIM->getIM()->setRate(rate);
1286 void SpeedControlWidget::resetRate()
1288 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);