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 /**********************************************************************
53 * Video Widget. A simple frame on which video is drawn
54 * This class handles resize issues
55 **********************************************************************/
57 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
60 vlc_mutex_init( &lock );
63 hide(); setMinimumSize( 16, 16 );
64 videoSize.rwidth() = -1;
65 videoSize.rheight() = -1;
67 /* Black background is more coherent for a Video Widget IMVHO */
68 QPalette plt = palette();
69 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
70 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
73 /* The core can ask through a callback to show the video.
74 * NOTE: We need to block the video output core until the window handle
75 * is ready for use (otherwise an X11 invalid handle failure may occur).
76 * As a side effect, it is illegal to emit askVideoWidgetToShow from
77 * the same thread as the Qt4 thread that owns this. */
78 QObject::connect( this, SIGNAL(askVideoWidgetToShow()), this, SLOT(show()),
79 Qt::BlockingQueuedConnection );
81 /* The core can ask through a callback to resize the video */
82 // CONNECT( this, askResize( int, int ), this, SetSizing( int, int ) );
85 void VideoWidget::paintEvent(QPaintEvent *ev)
87 QFrame::paintEvent(ev);
92 VideoWidget::~VideoWidget()
94 vlc_mutex_lock( &lock );
97 if( !p_intf->psz_switch_intf )
99 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
100 vout_Control( p_vout, VOUT_REPARENT );
104 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
105 vout_Control( p_vout, VOUT_CLOSE );
108 vlc_mutex_unlock( &lock );
109 vlc_mutex_destroy( &lock );
113 * Request the video to avoid the conflicts
115 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
116 unsigned int *pi_width, unsigned int *pi_height )
118 QMutexLocker locker( &handleLock );
119 msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
120 emit askVideoWidgetToShow();
123 msg_Dbg( p_intf, "embedded video already in use" );
127 while( !handleReady )
129 msg_Dbg( p_intf, "embedded video pending (handle %p)", winId() );
130 handleWait.wait( &handleLock );
132 msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );
133 return ( void* )winId();
136 /* Set the Widget to the correct Size */
137 /* Function has to be called by the parent
138 Parent has to care about resizing himself*/
139 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
141 msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
142 videoSize.rwidth() = w;
143 videoSize.rheight() = h;
144 updateGeometry(); // Needed for deinterlace
147 void VideoWidget::release( void *p_win )
149 msg_Dbg( p_intf, "Video is non needed anymore" );
151 videoSize.rwidth() = 0;
152 videoSize.rheight() = 0;
154 updateGeometry(); // Needed for deinterlace
157 QSize VideoWidget::sizeHint() const
162 /**********************************************************************
163 * Background Widget. Show a simple image background. Currently,
164 * it's album art if present or cone.
165 **********************************************************************/
166 #define ICON_SIZE 128
167 #define MAX_BG_SIZE 400
168 #define MIN_BG_SIZE 64
170 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
171 :QWidget( NULL ), p_intf( _p_i )
173 /* We should use that one to take the more size it can */
174 // setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
176 /* A dark background */
177 setAutoFillBackground( true );
179 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
180 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
183 /* A cone in the middle */
185 label->setMargin( 5 );
186 label->setMaximumHeight( MAX_BG_SIZE );
187 label->setMaximumWidth( MAX_BG_SIZE );
188 label->setMinimumHeight( MIN_BG_SIZE );
189 label->setMinimumWidth( MIN_BG_SIZE );
190 if( QDate::currentDate().dayOfYear() >= 354 )
191 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
193 label->setPixmap( QPixmap( ":/vlc128.png" ) );
195 QGridLayout *backgroundLayout = new QGridLayout( this );
196 backgroundLayout->addWidget( label, 0, 1 );
197 backgroundLayout->setColumnStretch( 0, 1 );
198 backgroundLayout->setColumnStretch( 2, 1 );
200 CONNECT( THEMIM->getIM(), artChanged( QString ), this, updateArt( QString ) );
203 BackgroundWidget::~BackgroundWidget()
207 void BackgroundWidget::resizeEvent( QResizeEvent * event )
209 if( event->size().height() <= MIN_BG_SIZE )
215 void BackgroundWidget::updateArt( QString url )
219 if( QDate::currentDate().dayOfYear() >= 354 )
220 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
222 label->setPixmap( QPixmap( ":/vlc128.png" ) );
227 label->setPixmap( QPixmap( url ) );
231 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
233 QVLCMenu::PopupMenu( p_intf, true );
236 /**********************************************************************
237 * Visualization selector panel
238 **********************************************************************/
239 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
240 QFrame( NULL ), p_intf( _p_i )
242 QHBoxLayout *layout = new QHBoxLayout( this );
243 layout->setMargin( 0 );
244 QPushButton *prevButton = new QPushButton( "Prev" );
245 QPushButton *nextButton = new QPushButton( "Next" );
246 layout->addWidget( prevButton );
247 layout->addWidget( nextButton );
249 layout->addItem( new QSpacerItem( 40,20,
250 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
251 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
253 current = new QLabel( qtr( "None" ) );
254 layout->addWidget( current );
256 BUTTONACT( prevButton, prev() );
257 BUTTONACT( nextButton, next() );
260 setMaximumHeight( 35 );
263 VisualSelector::~VisualSelector()
267 void VisualSelector::prev()
269 char *psz_new = aout_VisualPrev( p_intf );
272 current->setText( qfu( psz_new ) );
277 void VisualSelector::next()
279 char *psz_new = aout_VisualNext( p_intf );
282 current->setText( qfu( psz_new ) );
287 /**********************************************************************
289 **********************************************************************/
291 #define setupSmallButton( aButton ){ \
292 aButton->setMaximumSize( QSize( 26, 26 ) ); \
293 aButton->setMinimumSize( QSize( 26, 26 ) ); \
294 aButton->setIconSize( QSize( 20, 20 ) ); }
296 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
297 QFrame( NULL ), p_intf( _p_i )
299 QHBoxLayout *advLayout = new QHBoxLayout( this );
300 advLayout->setMargin( 0 );
301 advLayout->setSpacing( 0 );
302 advLayout->setAlignment( Qt::AlignBottom );
305 ABButton = new QPushButton( "AB" );
306 setupSmallButton( ABButton );
307 advLayout->addWidget( ABButton );
308 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
310 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
311 this, AtoBLoop( float, int, int ) );
313 frameButton = new QPushButton( "Fr" );
314 frameButton->setMaximumSize( QSize( 26, 26 ) );
315 frameButton->setIconSize( QSize( 20, 20 ) );
316 advLayout->addWidget( frameButton );
317 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
320 recordButton = new QPushButton( "R" );
321 setupSmallButton( recordButton );
322 advLayout->addWidget( recordButton );
323 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
324 qtr( "Record" ), record() );
326 /* Snapshot Button */
327 snapshotButton = new QPushButton( "S" );
328 setupSmallButton( snapshotButton );
329 advLayout->addWidget( snapshotButton );
330 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
333 AdvControlsWidget::~AdvControlsWidget()
336 void AdvControlsWidget::enableInput( bool enable )
338 ABButton->setEnabled( enable );
339 recordButton->setEnabled( enable );
342 void AdvControlsWidget::enableVideo( bool enable )
344 snapshotButton->setEnabled( enable );
346 frameButton->setEnabled( enable );
350 void AdvControlsWidget::snapshot()
352 vout_thread_t *p_vout =
353 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
354 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
357 /* Function called when the button is clicked() */
358 void AdvControlsWidget::fromAtoB()
362 timeA = var_GetTime( THEMIM->getInput(), "time" );
363 ABButton->setText( "A->..." );
368 timeB = var_GetTime( THEMIM->getInput(), "time" );
369 var_SetTime( THEMIM->getInput(), "time" , timeA );
370 ABButton->setText( "A<=>B" );
375 ABButton->setText( "AB" );
378 /* Function called regularly when in an AtoB loop */
379 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
383 if( i_time >= (int)(timeB/1000000) )
384 var_SetTime( THEMIM->getInput(), "time" , timeA );
388 /* FIXME Record function */
389 void AdvControlsWidget::record(){}
392 //FIXME Frame by frame function
393 void AdvControlsWidget::frame(){}
396 /*****************************
397 * DA Control Widget !
398 *****************************/
399 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
400 MainInterface *_p_mi,
404 QFrame( _p_mi ), p_intf( _p_i )
406 controlLayout = new QGridLayout( );
408 controlLayout->setSpacing( 0 );
409 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
412 setLayout( controlLayout );
414 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
416 /** The main Slider **/
417 slider = new InputSlider( Qt::Horizontal, NULL );
418 controlLayout->addWidget( slider, 0, 1, 1, 16 );
419 /* Update the position when the IM has changed */
420 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
421 slider, setPosition( float, int, int ) );
422 /* And update the IM, when the position has changed */
423 CONNECT( slider, sliderDragged( float ),
424 THEMIM->getIM(), sliderUpdate( float ) );
426 /** Slower and faster Buttons **/
427 slowerButton = new QToolButton;
428 slowerButton->setAutoRaise( true );
429 slowerButton->setMaximumSize( QSize( 26, 20 ) );
431 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
432 controlLayout->addWidget( slowerButton, 0, 0 );
434 fasterButton = new QToolButton;
435 fasterButton->setAutoRaise( true );
436 fasterButton->setMaximumSize( QSize( 26, 20 ) );
438 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
439 controlLayout->addWidget( fasterButton, 0, 17 );
441 /* advanced Controls handling */
442 b_advancedVisible = b_advControls;
444 advControls = new AdvControlsWidget( p_intf );
445 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
446 if( !b_advancedVisible ) advControls->hide();
448 /** Disc and Menus handling */
449 discFrame = new QWidget( this );
451 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
452 discLayout->setSpacing( 0 );
453 discLayout->setMargin( 0 );
455 prevSectionButton = new QPushButton( discFrame );
456 setupSmallButton( prevSectionButton );
457 discLayout->addWidget( prevSectionButton );
459 menuButton = new QPushButton( discFrame );
460 setupSmallButton( menuButton );
461 discLayout->addWidget( menuButton );
463 nextSectionButton = new QPushButton( discFrame );
464 setupSmallButton( nextSectionButton );
465 discLayout->addWidget( nextSectionButton );
467 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
469 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
470 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
471 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
475 /* Change the navigation button display when the IM navigation changes */
476 CONNECT( THEMIM->getIM(), navigationChanged( int ),
477 this, setNavigation( int ) );
478 /* Changes the IM navigation when triggered on the nav buttons */
479 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
481 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
483 CONNECT( menuButton, clicked(), THEMIM->getIM(),
488 * TODO: Merge with upper menu in a StackLayout
490 telexFrame = new QWidget( this );
491 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
492 telexLayout->setSpacing( 0 );
493 telexLayout->setMargin( 0 );
495 QPushButton *telexOn = new QPushButton;
496 setupSmallButton( telexOn );
497 telexLayout->addWidget( telexOn );
499 telexTransparent = new QPushButton;
500 setupSmallButton( telexTransparent );
501 telexLayout->addWidget( telexTransparent );
502 b_telexTransparent = false;
504 telexPage = new QSpinBox;
505 telexPage->setRange( 0, 999 );
506 telexPage->setValue( 100 );
507 telexPage->setAccelerated( true );
508 telexPage->setWrapping( true );
509 telexPage->setAlignment( Qt::AlignRight );
510 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
511 telexLayout->addWidget( telexPage );
513 controlLayout->addWidget( telexFrame, 1, 10, 2, 4, Qt::AlignBottom );
514 telexFrame->hide(); /* default hidden */
516 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
517 telexGotoPage( int ) );
519 BUTTON_SET_ACT_I( telexOn, "", tv.png, qtr( "Teletext on" ),
521 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
522 telexToggle( bool ) );
523 telexTransparent->setEnabled( false );
524 telexPage->setEnabled( false );
526 BUTTON_SET_ACT_I( telexTransparent, "", tvtelx.png, qtr( "Teletext" ),
527 toggleTeletextTransparency() );
528 CONNECT( telexTransparent, clicked( bool ),
529 THEMIM->getIM(), telexSetTransparency() );
530 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
531 telexFrame, setVisible( bool ) );
534 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
535 sizePolicy.setHorizontalStretch( 0 );
536 sizePolicy.setVerticalStretch( 0 );
539 playButton = new QPushButton;
540 playButton->setSizePolicy( sizePolicy );
541 playButton->setMaximumSize( QSize( 36, 36 ) );
542 playButton->setMinimumSize( QSize( 36, 36 ) );
543 playButton->setIconSize( QSize( 30, 30 ) );
545 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
547 controlLayout->setColumnMinimumWidth( 2, 20 );
548 controlLayout->setColumnStretch( 2, 0 );
550 /** Prev + Stop + Next Block **/
551 controlButLayout = new QHBoxLayout;
552 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
555 QPushButton *prevButton = new QPushButton;
556 prevButton->setSizePolicy( sizePolicy );
557 setupSmallButton( prevButton );
559 controlButLayout->addWidget( prevButton );
562 QPushButton *stopButton = new QPushButton;
563 stopButton->setSizePolicy( sizePolicy );
564 setupSmallButton( stopButton );
566 controlButLayout->addWidget( stopButton );
569 QPushButton *nextButton = new QPushButton;
570 nextButton->setSizePolicy( sizePolicy );
571 setupSmallButton( nextButton );
573 controlButLayout->addWidget( nextButton );
575 /* Add this block to the main layout */
577 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
579 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
580 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
581 qtr( "Previous" ), prev() );
582 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
583 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
585 controlLayout->setColumnMinimumWidth( 7, 20 );
586 controlLayout->setColumnStretch( 7, 0 );
587 controlLayout->setColumnStretch( 8, 0 );
588 controlLayout->setColumnStretch( 9, 0 );
591 * Other first Line buttons
593 /** Fullscreen/Visualisation **/
594 fullscreenButton = new QPushButton( "F" );
595 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
596 setupSmallButton( fullscreenButton );
597 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
599 /** Playlist Button **/
600 playlistButton = new QPushButton;
601 setupSmallButton( playlistButton );
602 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
603 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
604 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
606 /** extended Settings **/
607 extSettingsButton = new QPushButton;
608 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
610 setupSmallButton( extSettingsButton );
611 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
613 controlLayout->setColumnStretch( 13, 0 );
614 controlLayout->setColumnMinimumWidth( 13, 24 );
615 controlLayout->setColumnStretch( 14, 5 );
618 hVolLabel = new VolumeClickHandler( p_intf, this );
620 volMuteLabel = new QLabel;
621 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
622 volMuteLabel->setToolTip( qtr( "Mute" ) );
623 volMuteLabel->installEventFilter( hVolLabel );
624 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
628 volumeSlider = new SoundSlider( this,
629 config_GetInt( p_intf, "volume-step" ),
630 config_GetInt( p_intf, "qt-volume-complete" ),
631 config_GetPsz( p_intf, "qt-slider-colours" ) );
635 volumeSlider = new QSlider( this );
636 volumeSlider->setOrientation( Qt::Horizontal );
638 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
639 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
640 volumeSlider->setFocusPolicy( Qt::NoFocus );
641 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
643 /* Set the volume from the config */
644 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
645 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
647 /* Force the update at build time in order to have a muted icon if needed */
648 updateVolume( volumeSlider->value() );
650 /* Volume control connection */
651 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
652 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
657 ControlsWidget::~ControlsWidget()
660 void ControlsWidget::toggleTeletext()
662 bool b_enabled = THEMIM->teletextState();
665 telexTransparent->setEnabled( false );
666 telexPage->setEnabled( false );
667 b_telexEnabled = false;
671 telexTransparent->setEnabled( true );
672 telexPage->setEnabled( true );
673 b_telexEnabled = true;
677 void ControlsWidget::toggleTeletextTransparency()
679 if( b_telexTransparent )
681 telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx.png" ) );
682 telexTransparent->setToolTip( qtr( "Teletext" ) );
683 b_telexTransparent = false;
687 telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx-transparent.png" ) );
688 telexTransparent->setToolTip( qtr( "Transparent" ) );
689 b_telexTransparent = true;
693 void ControlsWidget::stop()
698 void ControlsWidget::play()
700 if( THEPL->current.i_size == 0 )
702 /* The playlist is empty, open a file requester */
703 THEDP->openFileDialog();
707 THEMIM->togglePlayPause();
710 void ControlsWidget::prev()
715 void ControlsWidget::next()
720 void ControlsWidget::setNavigation( int navigation )
722 #define HELP_MENU N_( "Menu" )
723 #define HELP_PCH N_( "Previous chapter" )
724 #define HELP_NCH N_( "Next chapter" )
725 #define HELP_PTR N_( "Previous track" )
726 #define HELP_NTR N_( "Next track" )
728 // 1 = chapter, 2 = title, 0 = no
729 if( navigation == 0 )
732 } else if( navigation == 1 ) {
733 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
734 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
738 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
739 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
745 static bool b_my_volume;
746 void ControlsWidget::updateVolume( int i_sliderVolume )
750 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
751 aout_VolumeSet( p_intf, i_res );
753 if( i_sliderVolume == 0 )
754 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
755 else if( i_sliderVolume < VOLUME_MAX / 3 )
756 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
757 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
758 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
759 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
762 void ControlsWidget::updateVolume()
765 audio_volume_t i_volume;
766 aout_VolumeGet( p_intf, &i_volume );
767 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
768 int i_gauge = volumeSlider->value();
770 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
773 volumeSlider->setValue( i_volume );
778 void ControlsWidget::updateInput()
780 /* Activate the interface buttons according to the presence of the input */
781 enableInput( THEMIM->getIM()->hasInput() );
782 enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
785 void ControlsWidget::setStatus( int status )
787 if( status == PLAYING_S ) /* Playing */
789 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
790 playButton->setToolTip( qtr( "Pause" ) );
794 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
795 playButton->setToolTip( qtr( "Play" ) );
801 * This functions toggle the fullscreen mode
802 * If there is no video, it should first activate Visualisations...
803 * This has also to be fixed in enableVideo()
805 void ControlsWidget::fullscreen()
807 vout_thread_t *p_vout =
808 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
811 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
812 vlc_object_release( p_vout );
816 void ControlsWidget::extSettings()
818 THEDP->extendedDialog();
821 void ControlsWidget::slower()
823 THEMIM->getIM()->slower();
826 void ControlsWidget::faster()
828 THEMIM->getIM()->faster();
831 void ControlsWidget::enableInput( bool enable )
833 slowerButton->setEnabled( enable );
834 slider->setEnabled( enable );
835 fasterButton->setEnabled( enable );
837 /* Advanced Buttons too */
838 advControls->enableInput( enable );
841 void ControlsWidget::enableVideo( bool enable )
843 // TODO Later make the fullscreenButton toggle Visualisation and so on.
844 fullscreenButton->setEnabled( enable );
846 /* Advanced Buttons too */
847 advControls->enableVideo( enable );
850 void ControlsWidget::toggleAdvanced()
852 if( !VISIBLE( advControls ) )
855 b_advancedVisible = true;
860 b_advancedVisible = false;
862 emit advancedControlsToggled( b_advancedVisible );
866 /**********************************************************************
867 * Fullscrenn control widget
868 **********************************************************************/
869 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
870 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
871 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
872 i_lastPosX( -1 ), i_lastPosY( -1 ), i_hideTimeout( 1 ),
873 b_mouseIsOver( false )
875 setWindowFlags( Qt::ToolTip );
877 setFrameShape( QFrame::StyledPanel );
878 setFrameStyle( QFrame::Sunken );
879 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
881 QGridLayout *fsLayout = new QGridLayout( this );
882 controlLayout->setSpacing( 0 );
883 controlLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
885 fsLayout->addWidget( slowerButton, 0, 0 );
886 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
887 fsLayout->addWidget( slider, 0, 1, 1, 6 );
888 fsLayout->addWidget( fasterButton, 0, 7 );
890 fsLayout->addWidget( volMuteLabel, 1, 0);
891 fsLayout->addWidget( volumeSlider, 1, 1 );
893 fsLayout->addLayout( controlButLayout, 1, 2 );
895 fsLayout->addWidget( playButton, 1, 3 );
897 fsLayout->addWidget( discFrame, 1, 4 );
899 fsLayout->addWidget( telexFrame, 1, 5 );
901 fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
903 fsLayout->addWidget( fullscreenButton, 1, 7 );
906 p_hideTimer = new QTimer( this );
907 CONNECT( p_hideTimer, timeout(), this, hideFSControllerWidget() );
908 p_hideTimer->setSingleShot( true );
910 /* slow hiding timer */
911 #if HAVE_TRANSPARENCY
912 p_slowHideTimer = new QTimer( this );
913 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
916 adjustSize (); /* need to get real width and height for moving */
919 QDesktopWidget * p_desktop = QApplication::desktop();
921 move( p_desktop->width() / 2 - width() / 2,
922 p_desktop->height() - height() );
925 setWindowOpacity( 0.0 );
931 FullscreenControllerWidget::~FullscreenControllerWidget()
936 * Hide fullscreen controller
937 * FIXME: under windows it have to be done by moving out of screen
938 * because hide() doesnt work
940 void FullscreenControllerWidget::hideFSControllerWidget()
944 setWindowOpacity( 0.0 ); // simulate hidding
951 * Hidding fullscreen controller slowly
952 * Linux: need composite manager
953 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
955 void FullscreenControllerWidget::slowHideFSC()
957 #if HAVE_TRANSPARENCY
958 static bool first_call = true;
964 p_slowHideTimer->stop();
965 /* the last part of time divided to 100 pieces */
966 p_slowHideTimer->start(
967 (int) ( i_hideTimeout / 2 / ( windowOpacity() * 100 ) ) );
971 if ( windowOpacity() > 0.0 )
973 /* we should use 0.01 because of 100 pieces ^^^
974 but than it cannt be done in time */
975 setWindowOpacity( windowOpacity() - 0.02 );
978 if ( windowOpacity() == 0.0 )
981 p_slowHideTimer->stop();
988 * Get state of visibility of FS controller on screen
989 * On windows control if it is on hidden position
991 bool FullscreenControllerWidget::isFSCHidden()
1002 * events: show, hide, start timer for hidding
1004 void FullscreenControllerWidget::customEvent( QEvent *event )
1006 int type = event->type();
1008 if ( type == FullscreenControlShow_Type )
1011 // after quiting and going to fs, we need to call show()
1018 setWindowOpacity( 1.0 );
1024 #if HAVE_TRANSPARENCY
1025 setWindowOpacity( DEFAULT_OPACITY );
1028 else if ( type == FullscreenControlHide_Type )
1030 hideFSControllerWidget();
1032 else if ( type == FullscreenControlPlanHide_Type && !b_mouseIsOver )
1034 p_hideTimer->start( i_hideTimeout );
1035 #if HAVE_TRANSPARENCY
1036 p_slowHideTimer->start( i_hideTimeout / 2 );
1045 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1047 if ( event->buttons() == Qt::LeftButton )
1049 int i_moveX = event->globalX() - i_lastPosX;
1050 int i_moveY = event->globalY() - i_lastPosY;
1052 move( x() + i_moveX, y() + i_moveY );
1054 i_lastPosX = event->globalX();
1055 i_lastPosY = event->globalY();
1061 * store position of cursor
1063 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1065 i_lastPosX = event->globalX();
1066 i_lastPosY = event->globalY();
1070 * On mouse go above FSC
1072 void FullscreenControllerWidget::enterEvent( QEvent *event )
1074 p_hideTimer->stop();
1075 #if HAVE_TRANSPARENCY
1076 p_slowHideTimer->stop();
1078 b_mouseIsOver = true;
1082 * On mouse go out from FSC
1084 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1086 p_hideTimer->start( i_hideTimeout );
1087 #if HAVE_TRANSPARENCY
1088 p_slowHideTimer->start( i_hideTimeout / 2 );
1090 b_mouseIsOver = false;
1094 * When you get pressed key, send it to video output
1095 * FIXME: clearing focus by clearFocus() to not getting
1096 * key press events didnt work
1098 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1100 int i_vlck = qtEventToVLCKey( event );
1103 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1111 * It is called when video start
1113 void FullscreenControllerWidget::regFullscreenCallback( vout_thread_t *p_vout )
1117 var_AddCallback( p_vout, "fullscreen", regMouseMoveCallback, this );
1122 * It is called after turn off video, because p_vout is NULL now
1123 * we cannt delete callback, just hide if FScontroller is visible
1125 void FullscreenControllerWidget::unregFullscreenCallback()
1132 * Register and unregister callback for mouse moving
1134 static int regMouseMoveCallback( vlc_object_t *vlc_object, const char *variable,
1135 vlc_value_t old_val, vlc_value_t new_val,
1138 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1140 static bool b_registered = false;
1141 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1143 if ( var_GetBool( p_vout, "fullscreen" ) && !b_registered )
1145 p_fs->SetHideTimeout( var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1146 var_AddCallback( p_vout, "mouse-moved",
1147 showFullscreenControllCallback, (void *) p_fs );
1148 b_registered = true;
1151 if ( !var_GetBool( p_vout, "fullscreen" ) && b_registered )
1153 var_DelCallback( p_vout, "mouse-moved",
1154 showFullscreenControllCallback, (void *) p_fs );
1155 b_registered = false;
1163 * Show fullscreen controller after mouse move
1164 * after show immediately plan hide event
1166 static int showFullscreenControllCallback( vlc_object_t *vlc_object, const char *variable,
1167 vlc_value_t old_val, vlc_value_t new_val,
1170 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1172 if ( p_fs->isFSCHidden() || p_fs->windowOpacity() < DEFAULT_OPACITY )
1174 IMEvent *event = new IMEvent( FullscreenControlShow_Type, 0 );
1175 QApplication::postEvent( p_fs, static_cast<QEvent *>(event) );
1178 IMEvent *e = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1179 QApplication::postEvent( p_fs, static_cast<QEvent *>(e) );
1184 /**********************************************************************
1185 * Speed control widget
1186 **********************************************************************/
1187 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1188 QFrame( NULL ), p_intf( _p_i )
1190 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1191 sizePolicy.setHorizontalStretch( 0 );
1192 sizePolicy.setVerticalStretch( 0 );
1194 speedSlider = new QSlider;
1195 speedSlider->setSizePolicy( sizePolicy );
1196 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1197 speedSlider->setOrientation( Qt::Vertical );
1198 speedSlider->setTickPosition( QSlider::TicksRight );
1200 speedSlider->setRange( -100, 100 );
1201 speedSlider->setSingleStep( 10 );
1202 speedSlider->setPageStep( 20 );
1203 speedSlider->setTickInterval( 20 );
1205 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1207 QToolButton *normalSpeedButton = new QToolButton( this );
1208 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1209 normalSpeedButton->setAutoRaise( true );
1210 normalSpeedButton->setText( "N" );
1211 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1213 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1215 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1216 speedControlLayout->addWidget( speedSlider );
1217 speedControlLayout->addWidget( normalSpeedButton );
1218 setLayout( speedControlLayout );
1221 SpeedControlWidget::~SpeedControlWidget()
1224 void SpeedControlWidget::setEnable( bool b_enable )
1226 speedSlider->setEnabled( b_enable );
1229 #define RATE_SLIDER_MAXIMUM 3.0
1230 #define RATE_SLIDER_MINIMUM 0.3
1231 #define RATE_SLIDER_LENGTH 100.0
1233 void SpeedControlWidget::updateControls( int rate )
1235 if( speedSlider->isSliderDown() )
1237 //We don't want to change anything if the user is using the slider
1242 double speed = INPUT_RATE_DEFAULT / (double)rate;
1244 if( rate >= INPUT_RATE_DEFAULT )
1246 if( speed < RATE_SLIDER_MINIMUM )
1248 sliderValue = speedSlider->minimum();
1252 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
1253 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
1258 if( speed > RATE_SLIDER_MAXIMUM )
1260 sliderValue = speedSlider->maximum();
1264 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
1265 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
1269 //Block signals to avoid feedback loop
1270 speedSlider->blockSignals( true );
1271 speedSlider->setValue( sliderValue );
1272 speedSlider->blockSignals( false );
1275 void SpeedControlWidget::updateRate( int sliderValue )
1279 if( sliderValue < 0.0 )
1281 rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
1282 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ));
1286 rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
1287 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH ));
1290 THEMIM->getIM()->setRate(rate);
1293 void SpeedControlWidget::resetRate()
1295 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);