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>
50 #include <QMutexLocker>
52 # include <X11/Xlib.h>
53 # include <qx11info_x11.h>
56 /**********************************************************************
57 * Video Widget. A simple frame on which video is drawn
58 * This class handles resize issues
59 **********************************************************************/
61 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
64 vlc_mutex_init( &lock );
67 hide(); setMinimumSize( 16, 16 );
68 videoSize.rwidth() = -1;
69 videoSize.rheight() = -1;
71 /* Black background is more coherent for a Video Widget IMVHO */
72 QPalette plt = palette();
73 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
74 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
77 /* The core can ask through a callback to show the video.
78 * NOTE: We need to block the video output core until the window handle
79 * is ready for use (otherwise an X11 invalid handle failure may occur).
80 * As a side effect, it is illegal to emit askVideoWidgetToShow from
81 * the same thread as the Qt4 thread that owns this. */
82 QObject::connect( this, SIGNAL(askVideoWidgetToShow()), this, SLOT(show()),
83 Qt::BlockingQueuedConnection );
85 /* The core can ask through a callback to resize the video */
86 // CONNECT( this, askResize( int, int ), this, SetSizing( int, int ) );
89 void VideoWidget::paintEvent(QPaintEvent *ev)
91 QFrame::paintEvent(ev);
93 XFlush( QX11Info::display() );
95 QMutexLocker locker( &handleLock );
100 VideoWidget::~VideoWidget()
102 vlc_mutex_lock( &lock );
105 if( !p_intf->psz_switch_intf )
107 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
108 vout_Control( p_vout, VOUT_REPARENT );
112 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
113 vout_Control( p_vout, VOUT_CLOSE );
116 vlc_mutex_unlock( &lock );
117 vlc_mutex_destroy( &lock );
121 * Request the video to avoid the conflicts
123 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
124 unsigned int *pi_width, unsigned int *pi_height )
126 QMutexLocker locker( &handleLock );
127 msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
128 emit askVideoWidgetToShow();
131 msg_Dbg( p_intf, "embedded video already in use" );
135 while( !handleReady )
137 msg_Dbg( p_intf, "embedded video pending (handle %p)", winId() );
138 handleWait.wait( &handleLock );
140 msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );
141 return ( void* )winId();
144 /* Set the Widget to the correct Size */
145 /* Function has to be called by the parent
146 Parent has to care about resizing himself*/
147 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
149 msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
150 videoSize.rwidth() = w;
151 videoSize.rheight() = h;
152 updateGeometry(); // Needed for deinterlace
155 void VideoWidget::release( void *p_win )
157 msg_Dbg( p_intf, "Video is non needed anymore" );
159 videoSize.rwidth() = 0;
160 videoSize.rheight() = 0;
162 updateGeometry(); // Needed for deinterlace
165 QSize VideoWidget::sizeHint() const
170 /**********************************************************************
171 * Background Widget. Show a simple image background. Currently,
172 * it's album art if present or cone.
173 **********************************************************************/
174 #define ICON_SIZE 128
175 #define MAX_BG_SIZE 400
176 #define MIN_BG_SIZE 64
178 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
179 :QWidget( NULL ), p_intf( _p_i )
181 /* We should use that one to take the more size it can */
182 // setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
184 /* A dark background */
185 setAutoFillBackground( true );
187 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
188 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
191 /* A cone in the middle */
193 label->setMargin( 5 );
194 label->setMaximumHeight( MAX_BG_SIZE );
195 label->setMaximumWidth( MAX_BG_SIZE );
196 label->setMinimumHeight( MIN_BG_SIZE );
197 label->setMinimumWidth( MIN_BG_SIZE );
198 if( QDate::currentDate().dayOfYear() >= 354 )
199 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
201 label->setPixmap( QPixmap( ":/vlc128.png" ) );
203 QGridLayout *backgroundLayout = new QGridLayout( this );
204 backgroundLayout->addWidget( label, 0, 1 );
205 backgroundLayout->setColumnStretch( 0, 1 );
206 backgroundLayout->setColumnStretch( 2, 1 );
208 CONNECT( THEMIM->getIM(), artChanged( QString ), this, updateArt( QString ) );
211 BackgroundWidget::~BackgroundWidget()
215 void BackgroundWidget::resizeEvent( QResizeEvent * event )
217 if( event->size().height() <= MIN_BG_SIZE )
223 void BackgroundWidget::updateArt( QString url )
227 if( QDate::currentDate().dayOfYear() >= 354 )
228 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
230 label->setPixmap( QPixmap( ":/vlc128.png" ) );
235 label->setPixmap( QPixmap( url ) );
239 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
241 QVLCMenu::PopupMenu( p_intf, true );
244 /**********************************************************************
245 * Visualization selector panel
246 **********************************************************************/
247 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
248 QFrame( NULL ), p_intf( _p_i )
250 QHBoxLayout *layout = new QHBoxLayout( this );
251 layout->setMargin( 0 );
252 QPushButton *prevButton = new QPushButton( "Prev" );
253 QPushButton *nextButton = new QPushButton( "Next" );
254 layout->addWidget( prevButton );
255 layout->addWidget( nextButton );
257 layout->addItem( new QSpacerItem( 40,20,
258 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
259 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
261 current = new QLabel( qtr( "None" ) );
262 layout->addWidget( current );
264 BUTTONACT( prevButton, prev() );
265 BUTTONACT( nextButton, next() );
268 setMaximumHeight( 35 );
271 VisualSelector::~VisualSelector()
275 void VisualSelector::prev()
277 char *psz_new = aout_VisualPrev( p_intf );
280 current->setText( qfu( psz_new ) );
285 void VisualSelector::next()
287 char *psz_new = aout_VisualNext( p_intf );
290 current->setText( qfu( psz_new ) );
295 /**********************************************************************
297 **********************************************************************/
299 #define setupSmallButton( aButton ){ \
300 aButton->setMaximumSize( QSize( 26, 26 ) ); \
301 aButton->setMinimumSize( QSize( 26, 26 ) ); \
302 aButton->setIconSize( QSize( 20, 20 ) ); }
304 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
305 QFrame( NULL ), p_intf( _p_i )
307 QHBoxLayout *advLayout = new QHBoxLayout( this );
308 advLayout->setMargin( 0 );
309 advLayout->setSpacing( 0 );
310 advLayout->setAlignment( Qt::AlignBottom );
313 ABButton = new QPushButton( "AB" );
314 setupSmallButton( ABButton );
315 advLayout->addWidget( ABButton );
316 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
318 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
319 this, AtoBLoop( float, int, int ) );
321 frameButton = new QPushButton( "Fr" );
322 frameButton->setMaximumSize( QSize( 26, 26 ) );
323 frameButton->setIconSize( QSize( 20, 20 ) );
324 advLayout->addWidget( frameButton );
325 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
328 recordButton = new QPushButton( "R" );
329 setupSmallButton( recordButton );
330 advLayout->addWidget( recordButton );
331 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
332 qtr( "Record" ), record() );
334 /* Snapshot Button */
335 snapshotButton = new QPushButton( "S" );
336 setupSmallButton( snapshotButton );
337 advLayout->addWidget( snapshotButton );
338 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
341 AdvControlsWidget::~AdvControlsWidget()
344 void AdvControlsWidget::enableInput( bool enable )
346 ABButton->setEnabled( enable );
347 recordButton->setEnabled( enable );
350 void AdvControlsWidget::enableVideo( bool enable )
352 snapshotButton->setEnabled( enable );
354 frameButton->setEnabled( enable );
358 void AdvControlsWidget::snapshot()
360 vout_thread_t *p_vout =
361 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
362 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
365 /* Function called when the button is clicked() */
366 void AdvControlsWidget::fromAtoB()
370 timeA = var_GetTime( THEMIM->getInput(), "time" );
371 ABButton->setText( "A->..." );
376 timeB = var_GetTime( THEMIM->getInput(), "time" );
377 var_SetTime( THEMIM->getInput(), "time" , timeA );
378 ABButton->setText( "A<=>B" );
383 ABButton->setText( "AB" );
386 /* Function called regularly when in an AtoB loop */
387 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
391 if( i_time >= (int)(timeB/1000000) )
392 var_SetTime( THEMIM->getInput(), "time" , timeA );
396 /* FIXME Record function */
397 void AdvControlsWidget::record(){}
400 //FIXME Frame by frame function
401 void AdvControlsWidget::frame(){}
404 /*****************************
405 * DA Control Widget !
406 *****************************/
407 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
408 MainInterface *_p_mi,
412 QFrame( _p_mi ), p_intf( _p_i )
414 controlLayout = new QGridLayout( );
416 controlLayout->setSpacing( 0 );
417 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
420 setLayout( controlLayout );
422 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
424 /** The main Slider **/
425 slider = new InputSlider( Qt::Horizontal, NULL );
426 controlLayout->addWidget( slider, 0, 1, 1, 16 );
427 /* Update the position when the IM has changed */
428 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
429 slider, setPosition( float, int, int ) );
430 /* And update the IM, when the position has changed */
431 CONNECT( slider, sliderDragged( float ),
432 THEMIM->getIM(), sliderUpdate( float ) );
434 /** Slower and faster Buttons **/
435 slowerButton = new QToolButton;
436 slowerButton->setAutoRaise( true );
437 slowerButton->setMaximumSize( QSize( 26, 20 ) );
439 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
440 controlLayout->addWidget( slowerButton, 0, 0 );
442 fasterButton = new QToolButton;
443 fasterButton->setAutoRaise( true );
444 fasterButton->setMaximumSize( QSize( 26, 20 ) );
446 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
447 controlLayout->addWidget( fasterButton, 0, 17 );
449 /* advanced Controls handling */
450 b_advancedVisible = b_advControls;
452 advControls = new AdvControlsWidget( p_intf );
453 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
454 if( !b_advancedVisible ) advControls->hide();
456 /** Disc and Menus handling */
457 discFrame = new QWidget( this );
459 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
460 discLayout->setSpacing( 0 );
461 discLayout->setMargin( 0 );
463 prevSectionButton = new QPushButton( discFrame );
464 setupSmallButton( prevSectionButton );
465 discLayout->addWidget( prevSectionButton );
467 menuButton = new QPushButton( discFrame );
468 setupSmallButton( menuButton );
469 discLayout->addWidget( menuButton );
471 nextSectionButton = new QPushButton( discFrame );
472 setupSmallButton( nextSectionButton );
473 discLayout->addWidget( nextSectionButton );
475 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
477 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
478 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
479 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
483 /* Change the navigation button display when the IM navigation changes */
484 CONNECT( THEMIM->getIM(), navigationChanged( int ),
485 this, setNavigation( int ) );
486 /* Changes the IM navigation when triggered on the nav buttons */
487 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
489 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
491 CONNECT( menuButton, clicked(), THEMIM->getIM(),
496 * TODO: Merge with upper menu in a StackLayout
498 telexFrame = new QWidget( this );
499 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
500 telexLayout->setSpacing( 0 );
501 telexLayout->setMargin( 0 );
503 QPushButton *telexOn = new QPushButton;
504 setupSmallButton( telexOn );
505 telexLayout->addWidget( telexOn );
507 telexTransparent = new QPushButton;
508 setupSmallButton( telexTransparent );
509 telexLayout->addWidget( telexTransparent );
510 b_telexTransparent = false;
512 telexPage = new QSpinBox;
513 telexPage->setRange( 0, 999 );
514 telexPage->setValue( 100 );
515 telexPage->setAccelerated( true );
516 telexPage->setWrapping( true );
517 telexPage->setAlignment( Qt::AlignRight );
518 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
519 telexLayout->addWidget( telexPage );
521 controlLayout->addWidget( telexFrame, 1, 10, 2, 4, Qt::AlignBottom );
522 telexFrame->hide(); /* default hidden */
524 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
525 telexGotoPage( int ) );
527 BUTTON_SET_ACT_I( telexOn, "", tv.png, qtr( "Teletext on" ),
529 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
530 telexToggle( bool ) );
531 telexTransparent->setEnabled( false );
532 telexPage->setEnabled( false );
534 BUTTON_SET_ACT_I( telexTransparent, "", tvtelx.png, qtr( "Teletext" ),
535 toggleTeletextTransparency() );
536 CONNECT( telexTransparent, clicked( bool ),
537 THEMIM->getIM(), telexSetTransparency() );
538 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
539 telexFrame, setVisible( bool ) );
542 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
543 sizePolicy.setHorizontalStretch( 0 );
544 sizePolicy.setVerticalStretch( 0 );
547 playButton = new QPushButton;
548 playButton->setSizePolicy( sizePolicy );
549 playButton->setMaximumSize( QSize( 36, 36 ) );
550 playButton->setMinimumSize( QSize( 36, 36 ) );
551 playButton->setIconSize( QSize( 30, 30 ) );
553 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
555 controlLayout->setColumnMinimumWidth( 2, 20 );
556 controlLayout->setColumnStretch( 2, 0 );
558 /** Prev + Stop + Next Block **/
559 controlButLayout = new QHBoxLayout;
560 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
563 QPushButton *prevButton = new QPushButton;
564 prevButton->setSizePolicy( sizePolicy );
565 setupSmallButton( prevButton );
567 controlButLayout->addWidget( prevButton );
570 QPushButton *stopButton = new QPushButton;
571 stopButton->setSizePolicy( sizePolicy );
572 setupSmallButton( stopButton );
574 controlButLayout->addWidget( stopButton );
577 QPushButton *nextButton = new QPushButton;
578 nextButton->setSizePolicy( sizePolicy );
579 setupSmallButton( nextButton );
581 controlButLayout->addWidget( nextButton );
583 /* Add this block to the main layout */
585 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
587 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
588 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
589 qtr( "Previous" ), prev() );
590 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
591 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
593 controlLayout->setColumnMinimumWidth( 7, 20 );
594 controlLayout->setColumnStretch( 7, 0 );
595 controlLayout->setColumnStretch( 8, 0 );
596 controlLayout->setColumnStretch( 9, 0 );
599 * Other first Line buttons
601 /** Fullscreen/Visualisation **/
602 fullscreenButton = new QPushButton( "F" );
603 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
604 setupSmallButton( fullscreenButton );
605 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
607 /** Playlist Button **/
608 playlistButton = new QPushButton;
609 setupSmallButton( playlistButton );
610 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
611 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
612 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
614 /** extended Settings **/
615 extSettingsButton = new QPushButton;
616 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
618 setupSmallButton( extSettingsButton );
619 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
621 controlLayout->setColumnStretch( 13, 0 );
622 controlLayout->setColumnMinimumWidth( 13, 24 );
623 controlLayout->setColumnStretch( 14, 5 );
626 hVolLabel = new VolumeClickHandler( p_intf, this );
628 volMuteLabel = new QLabel;
629 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
630 volMuteLabel->setToolTip( qtr( "Mute" ) );
631 volMuteLabel->installEventFilter( hVolLabel );
632 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
636 volumeSlider = new SoundSlider( this,
637 config_GetInt( p_intf, "volume-step" ),
638 config_GetInt( p_intf, "qt-volume-complete" ),
639 config_GetPsz( p_intf, "qt-slider-colours" ) );
643 volumeSlider = new QSlider( this );
644 volumeSlider->setOrientation( Qt::Horizontal );
646 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
647 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
648 volumeSlider->setFocusPolicy( Qt::NoFocus );
649 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
651 /* Set the volume from the config */
652 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
653 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
655 /* Force the update at build time in order to have a muted icon if needed */
656 updateVolume( volumeSlider->value() );
658 /* Volume control connection */
659 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
660 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
665 ControlsWidget::~ControlsWidget()
668 void ControlsWidget::toggleTeletext()
670 bool b_enabled = THEMIM->teletextState();
673 telexTransparent->setEnabled( false );
674 telexPage->setEnabled( false );
675 b_telexEnabled = false;
679 telexTransparent->setEnabled( true );
680 telexPage->setEnabled( true );
681 b_telexEnabled = true;
685 void ControlsWidget::toggleTeletextTransparency()
687 if( b_telexTransparent )
689 telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx.png" ) );
690 telexTransparent->setToolTip( qtr( "Teletext" ) );
691 b_telexTransparent = false;
695 telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx-transparent.png" ) );
696 telexTransparent->setToolTip( qtr( "Transparent" ) );
697 b_telexTransparent = true;
701 void ControlsWidget::stop()
706 void ControlsWidget::play()
708 if( THEPL->current.i_size == 0 )
710 /* The playlist is empty, open a file requester */
711 THEDP->openFileDialog();
715 THEMIM->togglePlayPause();
718 void ControlsWidget::prev()
723 void ControlsWidget::next()
728 void ControlsWidget::setNavigation( int navigation )
730 #define HELP_MENU N_( "Menu" )
731 #define HELP_PCH N_( "Previous chapter" )
732 #define HELP_NCH N_( "Next chapter" )
733 #define HELP_PTR N_( "Previous track" )
734 #define HELP_NTR N_( "Next track" )
736 // 1 = chapter, 2 = title, 0 = no
737 if( navigation == 0 )
740 } else if( navigation == 1 ) {
741 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
742 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
746 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
747 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
753 static bool b_my_volume;
754 void ControlsWidget::updateVolume( int i_sliderVolume )
758 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
759 aout_VolumeSet( p_intf, i_res );
761 if( i_sliderVolume == 0 )
762 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
763 else if( i_sliderVolume < VOLUME_MAX / 3 )
764 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
765 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
766 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
767 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
770 void ControlsWidget::updateVolume()
773 audio_volume_t i_volume;
774 aout_VolumeGet( p_intf, &i_volume );
775 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
776 int i_gauge = volumeSlider->value();
778 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
781 volumeSlider->setValue( i_volume );
786 void ControlsWidget::updateInput()
788 /* Activate the interface buttons according to the presence of the input */
789 enableInput( THEMIM->getIM()->hasInput() );
790 enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
793 void ControlsWidget::setStatus( int status )
795 if( status == PLAYING_S ) /* Playing */
797 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
798 playButton->setToolTip( qtr( "Pause" ) );
802 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
803 playButton->setToolTip( qtr( "Play" ) );
809 * This functions toggle the fullscreen mode
810 * If there is no video, it should first activate Visualisations...
811 * This has also to be fixed in enableVideo()
813 void ControlsWidget::fullscreen()
815 vout_thread_t *p_vout =
816 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
819 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
820 vlc_object_release( p_vout );
824 void ControlsWidget::extSettings()
826 THEDP->extendedDialog();
829 void ControlsWidget::slower()
831 THEMIM->getIM()->slower();
834 void ControlsWidget::faster()
836 THEMIM->getIM()->faster();
839 void ControlsWidget::enableInput( bool enable )
841 slowerButton->setEnabled( enable );
842 slider->setEnabled( enable );
843 fasterButton->setEnabled( enable );
845 /* Advanced Buttons too */
846 advControls->enableInput( enable );
849 void ControlsWidget::enableVideo( bool enable )
851 // TODO Later make the fullscreenButton toggle Visualisation and so on.
852 fullscreenButton->setEnabled( enable );
854 /* Advanced Buttons too */
855 advControls->enableVideo( enable );
858 void ControlsWidget::toggleAdvanced()
860 if( !VISIBLE( advControls ) )
863 b_advancedVisible = true;
868 b_advancedVisible = false;
870 emit advancedControlsToggled( b_advancedVisible );
874 /**********************************************************************
875 * Fullscrenn control widget
876 **********************************************************************/
877 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
878 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
879 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
880 i_lastPosX( -1 ), i_lastPosY( -1 ), i_hideTimeout( 1 ),
881 b_mouseIsOver( false )
883 setWindowFlags( Qt::ToolTip );
885 setFrameShape( QFrame::StyledPanel );
886 setFrameStyle( QFrame::Sunken );
887 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
889 QGridLayout *fsLayout = new QGridLayout( this );
890 controlLayout->setSpacing( 0 );
891 controlLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
893 fsLayout->addWidget( slowerButton, 0, 0 );
894 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
895 fsLayout->addWidget( slider, 0, 1, 1, 6 );
896 fsLayout->addWidget( fasterButton, 0, 7 );
898 fsLayout->addWidget( volMuteLabel, 1, 0);
899 fsLayout->addWidget( volumeSlider, 1, 1 );
901 fsLayout->addLayout( controlButLayout, 1, 2 );
903 fsLayout->addWidget( playButton, 1, 3 );
905 fsLayout->addWidget( discFrame, 1, 4 );
907 fsLayout->addWidget( telexFrame, 1, 5 );
909 fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
911 fsLayout->addWidget( fullscreenButton, 1, 7 );
914 p_hideTimer = new QTimer( this );
915 CONNECT( p_hideTimer, timeout(), this, hideFSControllerWidget() );
916 p_hideTimer->setSingleShot( true );
918 /* slow hiding timer */
919 #if HAVE_TRANSPARENCY
920 p_slowHideTimer = new QTimer( this );
921 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
924 adjustSize (); /* need to get real width and height for moving */
927 QDesktopWidget * p_desktop = QApplication::desktop();
929 move( p_desktop->width() / 2 - width() / 2,
930 p_desktop->height() - height() );
933 setWindowOpacity( 0.0 );
939 FullscreenControllerWidget::~FullscreenControllerWidget()
944 * Hide fullscreen controller
945 * FIXME: under windows it have to be done by moving out of screen
946 * because hide() doesnt work
948 void FullscreenControllerWidget::hideFSControllerWidget()
952 setWindowOpacity( 0.0 ); // simulate hidding
959 * Hidding fullscreen controller slowly
960 * Linux: need composite manager
961 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
963 void FullscreenControllerWidget::slowHideFSC()
965 #if HAVE_TRANSPARENCY
966 static bool first_call = true;
972 p_slowHideTimer->stop();
973 /* the last part of time divided to 100 pieces */
974 p_slowHideTimer->start(
975 (int) ( i_hideTimeout / 2 / ( windowOpacity() * 100 ) ) );
979 if ( windowOpacity() > 0.0 )
981 /* we should use 0.01 because of 100 pieces ^^^
982 but than it cannt be done in time */
983 setWindowOpacity( windowOpacity() - 0.02 );
986 if ( windowOpacity() == 0.0 )
989 p_slowHideTimer->stop();
996 * Get state of visibility of FS controller on screen
997 * On windows control if it is on hidden position
999 bool FullscreenControllerWidget::isFSCHidden()
1010 * events: show, hide, start timer for hidding
1012 void FullscreenControllerWidget::customEvent( QEvent *event )
1014 int type = event->type();
1016 if ( type == FullscreenControlShow_Type )
1019 // after quiting and going to fs, we need to call show()
1026 setWindowOpacity( 1.0 );
1032 #if HAVE_TRANSPARENCY
1033 setWindowOpacity( DEFAULT_OPACITY );
1036 else if ( type == FullscreenControlHide_Type )
1038 hideFSControllerWidget();
1040 else if ( type == FullscreenControlPlanHide_Type && !b_mouseIsOver )
1042 p_hideTimer->start( i_hideTimeout );
1043 #if HAVE_TRANSPARENCY
1044 p_slowHideTimer->start( i_hideTimeout / 2 );
1053 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1055 if ( event->buttons() == Qt::LeftButton )
1057 int i_moveX = event->globalX() - i_lastPosX;
1058 int i_moveY = event->globalY() - i_lastPosY;
1060 move( x() + i_moveX, y() + i_moveY );
1062 i_lastPosX = event->globalX();
1063 i_lastPosY = event->globalY();
1069 * store position of cursor
1071 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1073 i_lastPosX = event->globalX();
1074 i_lastPosY = event->globalY();
1078 * On mouse go above FSC
1080 void FullscreenControllerWidget::enterEvent( QEvent *event )
1082 p_hideTimer->stop();
1083 #if HAVE_TRANSPARENCY
1084 p_slowHideTimer->stop();
1086 b_mouseIsOver = true;
1090 * On mouse go out from FSC
1092 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1094 p_hideTimer->start( i_hideTimeout );
1095 #if HAVE_TRANSPARENCY
1096 p_slowHideTimer->start( i_hideTimeout / 2 );
1098 b_mouseIsOver = false;
1102 * When you get pressed key, send it to video output
1103 * FIXME: clearing focus by clearFocus() to not getting
1104 * key press events didnt work
1106 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1108 int i_vlck = qtEventToVLCKey( event );
1111 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1119 * It is called when video start
1121 void FullscreenControllerWidget::regFullscreenCallback( vout_thread_t *p_vout )
1125 var_AddCallback( p_vout, "fullscreen", regMouseMoveCallback, this );
1130 * It is called after turn off video, because p_vout is NULL now
1131 * we cannt delete callback, just hide if FScontroller is visible
1133 void FullscreenControllerWidget::unregFullscreenCallback()
1140 * Register and unregister callback for mouse moving
1142 static int regMouseMoveCallback( vlc_object_t *vlc_object, const char *variable,
1143 vlc_value_t old_val, vlc_value_t new_val,
1146 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1148 static bool b_registered = false;
1149 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1151 if ( var_GetBool( p_vout, "fullscreen" ) && !b_registered )
1153 p_fs->SetHideTimeout( var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1154 var_AddCallback( p_vout, "mouse-moved",
1155 showFullscreenControllCallback, (void *) p_fs );
1156 b_registered = true;
1159 if ( !var_GetBool( p_vout, "fullscreen" ) && b_registered )
1161 var_DelCallback( p_vout, "mouse-moved",
1162 showFullscreenControllCallback, (void *) p_fs );
1163 b_registered = false;
1171 * Show fullscreen controller after mouse move
1172 * after show immediately plan hide event
1174 static int showFullscreenControllCallback( vlc_object_t *vlc_object, const char *variable,
1175 vlc_value_t old_val, vlc_value_t new_val,
1178 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1180 if ( p_fs->isFSCHidden() || p_fs->windowOpacity() < DEFAULT_OPACITY )
1182 IMEvent *event = new IMEvent( FullscreenControlShow_Type, 0 );
1183 QApplication::postEvent( p_fs, static_cast<QEvent *>(event) );
1186 IMEvent *e = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1187 QApplication::postEvent( p_fs, static_cast<QEvent *>(e) );
1192 /**********************************************************************
1193 * Speed control widget
1194 **********************************************************************/
1195 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1196 QFrame( NULL ), p_intf( _p_i )
1198 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1199 sizePolicy.setHorizontalStretch( 0 );
1200 sizePolicy.setVerticalStretch( 0 );
1202 speedSlider = new QSlider;
1203 speedSlider->setSizePolicy( sizePolicy );
1204 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1205 speedSlider->setOrientation( Qt::Vertical );
1206 speedSlider->setTickPosition( QSlider::TicksRight );
1208 speedSlider->setRange( -100, 100 );
1209 speedSlider->setSingleStep( 10 );
1210 speedSlider->setPageStep( 20 );
1211 speedSlider->setTickInterval( 20 );
1213 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1215 QToolButton *normalSpeedButton = new QToolButton( this );
1216 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1217 normalSpeedButton->setAutoRaise( true );
1218 normalSpeedButton->setText( "N" );
1219 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1221 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1223 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1224 speedControlLayout->addWidget( speedSlider );
1225 speedControlLayout->addWidget( normalSpeedButton );
1226 setLayout( speedControlLayout );
1229 SpeedControlWidget::~SpeedControlWidget()
1232 void SpeedControlWidget::setEnable( bool b_enable )
1234 speedSlider->setEnabled( b_enable );
1237 #define RATE_SLIDER_MAXIMUM 3.0
1238 #define RATE_SLIDER_MINIMUM 0.3
1239 #define RATE_SLIDER_LENGTH 100.0
1241 void SpeedControlWidget::updateControls( int rate )
1243 if( speedSlider->isSliderDown() )
1245 //We don't want to change anything if the user is using the slider
1250 double speed = INPUT_RATE_DEFAULT / (double)rate;
1252 if( rate >= INPUT_RATE_DEFAULT )
1254 if( speed < RATE_SLIDER_MINIMUM )
1256 sliderValue = speedSlider->minimum();
1260 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
1261 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
1266 if( speed > RATE_SLIDER_MAXIMUM )
1268 sliderValue = speedSlider->maximum();
1272 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
1273 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
1277 //Block signals to avoid feedback loop
1278 speedSlider->blockSignals( true );
1279 speedSlider->setValue( sliderValue );
1280 speedSlider->blockSignals( false );
1283 void SpeedControlWidget::updateRate( int sliderValue )
1287 if( sliderValue < 0.0 )
1289 rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
1290 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ));
1294 rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
1295 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH ));
1298 THEMIM->getIM()->setRate(rate);
1301 void SpeedControlWidget::resetRate()
1303 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);