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 );
76 setAttribute( Qt::WA_PaintOnScreen, true );
78 /* The core can ask through a callback to show the video.
79 * NOTE: We need to block the video output core until the window handle
80 * is ready for use (otherwise an X11 invalid handle failure may occur).
81 * As a side effect, it is illegal to emit askVideoWidgetToShow from
82 * the same thread as the Qt4 thread that owns this. */
83 QObject::connect( this, SIGNAL(askVideoWidgetToShow()), this, SLOT(show()),
84 Qt::BlockingQueuedConnection );
86 /* The core can ask through a callback to resize the video */
87 // CONNECT( this, askResize( int, int ), this, SetSizing( int, int ) );
90 void VideoWidget::paintEvent(QPaintEvent *ev)
92 QFrame::paintEvent(ev);
94 XFlush( QX11Info::display() );
96 QMutexLocker locker( &handleLock );
101 VideoWidget::~VideoWidget()
103 vlc_mutex_lock( &lock );
106 if( !p_intf->psz_switch_intf )
108 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
109 vout_Control( p_vout, VOUT_REPARENT );
113 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
114 vout_Control( p_vout, VOUT_CLOSE );
117 vlc_mutex_unlock( &lock );
118 vlc_mutex_destroy( &lock );
122 * Request the video to avoid the conflicts
124 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
125 unsigned int *pi_width, unsigned int *pi_height )
127 QMutexLocker locker( &handleLock );
128 msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
129 emit askVideoWidgetToShow();
132 msg_Dbg( p_intf, "embedded video already in use" );
136 while( !handleReady )
138 msg_Dbg( p_intf, "embedded video pending (handle %p)", winId() );
139 handleWait.wait( &handleLock );
141 msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );
142 return ( void* )winId();
145 /* Set the Widget to the correct Size */
146 /* Function has to be called by the parent
147 Parent has to care about resizing himself*/
148 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
150 msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
151 videoSize.rwidth() = w;
152 videoSize.rheight() = h;
153 updateGeometry(); // Needed for deinterlace
156 void VideoWidget::release( void *p_win )
158 msg_Dbg( p_intf, "Video is non needed anymore" );
160 videoSize.rwidth() = 0;
161 videoSize.rheight() = 0;
163 updateGeometry(); // Needed for deinterlace
166 QSize VideoWidget::sizeHint() const
171 /**********************************************************************
172 * Background Widget. Show a simple image background. Currently,
173 * it's album art if present or cone.
174 **********************************************************************/
175 #define ICON_SIZE 128
176 #define MAX_BG_SIZE 400
177 #define MIN_BG_SIZE 64
179 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
180 :QWidget( NULL ), p_intf( _p_i )
182 /* We should use that one to take the more size it can */
183 // setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
185 /* A dark background */
186 setAutoFillBackground( true );
188 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
189 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
192 /* A cone in the middle */
194 label->setMargin( 5 );
195 label->setMaximumHeight( MAX_BG_SIZE );
196 label->setMaximumWidth( MAX_BG_SIZE );
197 label->setMinimumHeight( MIN_BG_SIZE );
198 label->setMinimumWidth( MIN_BG_SIZE );
199 if( QDate::currentDate().dayOfYear() >= 354 )
200 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
202 label->setPixmap( QPixmap( ":/vlc128.png" ) );
204 QGridLayout *backgroundLayout = new QGridLayout( this );
205 backgroundLayout->addWidget( label, 0, 1 );
206 backgroundLayout->setColumnStretch( 0, 1 );
207 backgroundLayout->setColumnStretch( 2, 1 );
209 CONNECT( THEMIM->getIM(), artChanged( QString ), this, updateArt( QString ) );
212 BackgroundWidget::~BackgroundWidget()
216 void BackgroundWidget::resizeEvent( QResizeEvent * event )
218 if( event->size().height() <= MIN_BG_SIZE )
224 void BackgroundWidget::updateArt( QString url )
228 if( QDate::currentDate().dayOfYear() >= 354 )
229 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
231 label->setPixmap( QPixmap( ":/vlc128.png" ) );
236 label->setPixmap( QPixmap( url ) );
240 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
242 QVLCMenu::PopupMenu( p_intf, true );
245 /**********************************************************************
246 * Visualization selector panel
247 **********************************************************************/
248 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
249 QFrame( NULL ), p_intf( _p_i )
251 QHBoxLayout *layout = new QHBoxLayout( this );
252 layout->setMargin( 0 );
253 QPushButton *prevButton = new QPushButton( "Prev" );
254 QPushButton *nextButton = new QPushButton( "Next" );
255 layout->addWidget( prevButton );
256 layout->addWidget( nextButton );
258 layout->addItem( new QSpacerItem( 40,20,
259 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
260 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
262 current = new QLabel( qtr( "None" ) );
263 layout->addWidget( current );
265 BUTTONACT( prevButton, prev() );
266 BUTTONACT( nextButton, next() );
269 setMaximumHeight( 35 );
272 VisualSelector::~VisualSelector()
276 void VisualSelector::prev()
278 char *psz_new = aout_VisualPrev( p_intf );
281 current->setText( qfu( psz_new ) );
286 void VisualSelector::next()
288 char *psz_new = aout_VisualNext( p_intf );
291 current->setText( qfu( psz_new ) );
296 /**********************************************************************
298 **********************************************************************/
300 #define setupSmallButton( aButton ){ \
301 aButton->setMaximumSize( QSize( 26, 26 ) ); \
302 aButton->setMinimumSize( QSize( 26, 26 ) ); \
303 aButton->setIconSize( QSize( 20, 20 ) ); }
305 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
306 QFrame( NULL ), p_intf( _p_i )
308 QHBoxLayout *advLayout = new QHBoxLayout( this );
309 advLayout->setMargin( 0 );
310 advLayout->setSpacing( 0 );
311 advLayout->setAlignment( Qt::AlignBottom );
314 ABButton = new QPushButton( "AB" );
315 setupSmallButton( ABButton );
316 advLayout->addWidget( ABButton );
317 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
319 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
320 this, AtoBLoop( float, int, int ) );
322 frameButton = new QPushButton( "Fr" );
323 frameButton->setMaximumSize( QSize( 26, 26 ) );
324 frameButton->setIconSize( QSize( 20, 20 ) );
325 advLayout->addWidget( frameButton );
326 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
329 recordButton = new QPushButton( "R" );
330 setupSmallButton( recordButton );
331 advLayout->addWidget( recordButton );
332 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
333 qtr( "Record" ), record() );
335 /* Snapshot Button */
336 snapshotButton = new QPushButton( "S" );
337 setupSmallButton( snapshotButton );
338 advLayout->addWidget( snapshotButton );
339 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
342 AdvControlsWidget::~AdvControlsWidget()
345 void AdvControlsWidget::enableInput( bool enable )
347 ABButton->setEnabled( enable );
348 recordButton->setEnabled( enable );
351 void AdvControlsWidget::enableVideo( bool enable )
353 snapshotButton->setEnabled( enable );
355 frameButton->setEnabled( enable );
359 void AdvControlsWidget::snapshot()
361 vout_thread_t *p_vout =
362 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
363 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
366 /* Function called when the button is clicked() */
367 void AdvControlsWidget::fromAtoB()
371 timeA = var_GetTime( THEMIM->getInput(), "time" );
372 ABButton->setText( "A->..." );
377 timeB = var_GetTime( THEMIM->getInput(), "time" );
378 var_SetTime( THEMIM->getInput(), "time" , timeA );
379 ABButton->setText( "A<=>B" );
384 ABButton->setText( "AB" );
387 /* Function called regularly when in an AtoB loop */
388 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
392 if( i_time >= (int)(timeB/1000000) )
393 var_SetTime( THEMIM->getInput(), "time" , timeA );
397 /* FIXME Record function */
398 void AdvControlsWidget::record(){}
401 //FIXME Frame by frame function
402 void AdvControlsWidget::frame(){}
405 /*****************************
406 * DA Control Widget !
407 *****************************/
408 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
409 MainInterface *_p_mi,
413 QFrame( _p_mi ), p_intf( _p_i )
415 controlLayout = new QGridLayout( );
417 controlLayout->setSpacing( 0 );
418 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
421 setLayout( controlLayout );
423 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
425 /** The main Slider **/
426 slider = new InputSlider( Qt::Horizontal, NULL );
427 controlLayout->addWidget( slider, 0, 1, 1, 16 );
428 /* Update the position when the IM has changed */
429 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
430 slider, setPosition( float, int, int ) );
431 /* And update the IM, when the position has changed */
432 CONNECT( slider, sliderDragged( float ),
433 THEMIM->getIM(), sliderUpdate( float ) );
435 /** Slower and faster Buttons **/
436 slowerButton = new QToolButton;
437 slowerButton->setAutoRaise( true );
438 slowerButton->setMaximumSize( QSize( 26, 20 ) );
440 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
441 controlLayout->addWidget( slowerButton, 0, 0 );
443 fasterButton = new QToolButton;
444 fasterButton->setAutoRaise( true );
445 fasterButton->setMaximumSize( QSize( 26, 20 ) );
447 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
448 controlLayout->addWidget( fasterButton, 0, 17 );
450 /* advanced Controls handling */
451 b_advancedVisible = b_advControls;
453 advControls = new AdvControlsWidget( p_intf );
454 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
455 if( !b_advancedVisible ) advControls->hide();
457 /** Disc and Menus handling */
458 discFrame = new QWidget( this );
460 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
461 discLayout->setSpacing( 0 );
462 discLayout->setMargin( 0 );
464 prevSectionButton = new QPushButton( discFrame );
465 setupSmallButton( prevSectionButton );
466 discLayout->addWidget( prevSectionButton );
468 menuButton = new QPushButton( discFrame );
469 setupSmallButton( menuButton );
470 discLayout->addWidget( menuButton );
472 nextSectionButton = new QPushButton( discFrame );
473 setupSmallButton( nextSectionButton );
474 discLayout->addWidget( nextSectionButton );
476 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
478 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
479 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
480 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
484 /* Change the navigation button display when the IM navigation changes */
485 CONNECT( THEMIM->getIM(), navigationChanged( int ),
486 this, setNavigation( int ) );
487 /* Changes the IM navigation when triggered on the nav buttons */
488 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
490 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
492 CONNECT( menuButton, clicked(), THEMIM->getIM(),
497 * TODO: Merge with upper menu in a StackLayout
499 telexFrame = new QWidget( this );
500 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
501 telexLayout->setSpacing( 0 );
502 telexLayout->setMargin( 0 );
504 QPushButton *telexOn = new QPushButton;
505 setupSmallButton( telexOn );
506 telexLayout->addWidget( telexOn );
508 telexTransparent = new QPushButton;
509 setupSmallButton( telexTransparent );
510 telexLayout->addWidget( telexTransparent );
511 b_telexTransparent = false;
513 telexPage = new QSpinBox;
514 telexPage->setRange( 0, 999 );
515 telexPage->setValue( 100 );
516 telexPage->setAccelerated( true );
517 telexPage->setWrapping( true );
518 telexPage->setAlignment( Qt::AlignRight );
519 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
520 telexLayout->addWidget( telexPage );
522 controlLayout->addWidget( telexFrame, 1, 10, 2, 4, Qt::AlignBottom );
523 telexFrame->hide(); /* default hidden */
525 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
526 telexGotoPage( int ) );
528 BUTTON_SET_ACT_I( telexOn, "", tv.png, qtr( "Teletext on" ),
530 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
531 telexToggle( bool ) );
532 telexTransparent->setEnabled( false );
533 telexPage->setEnabled( false );
535 BUTTON_SET_ACT_I( telexTransparent, "", tvtelx.png, qtr( "Teletext" ),
536 toggleTeletextTransparency() );
537 CONNECT( telexTransparent, clicked( bool ),
538 THEMIM->getIM(), telexSetTransparency() );
539 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
540 telexFrame, setVisible( bool ) );
543 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
544 sizePolicy.setHorizontalStretch( 0 );
545 sizePolicy.setVerticalStretch( 0 );
548 playButton = new QPushButton;
549 playButton->setSizePolicy( sizePolicy );
550 playButton->setMaximumSize( QSize( 36, 36 ) );
551 playButton->setMinimumSize( QSize( 36, 36 ) );
552 playButton->setIconSize( QSize( 30, 30 ) );
554 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
556 controlLayout->setColumnMinimumWidth( 2, 20 );
557 controlLayout->setColumnStretch( 2, 0 );
559 /** Prev + Stop + Next Block **/
560 controlButLayout = new QHBoxLayout;
561 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
564 QPushButton *prevButton = new QPushButton;
565 prevButton->setSizePolicy( sizePolicy );
566 setupSmallButton( prevButton );
568 controlButLayout->addWidget( prevButton );
571 QPushButton *stopButton = new QPushButton;
572 stopButton->setSizePolicy( sizePolicy );
573 setupSmallButton( stopButton );
575 controlButLayout->addWidget( stopButton );
578 QPushButton *nextButton = new QPushButton;
579 nextButton->setSizePolicy( sizePolicy );
580 setupSmallButton( nextButton );
582 controlButLayout->addWidget( nextButton );
584 /* Add this block to the main layout */
586 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
588 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
589 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
590 qtr( "Previous" ), prev() );
591 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
592 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
594 controlLayout->setColumnMinimumWidth( 7, 20 );
595 controlLayout->setColumnStretch( 7, 0 );
596 controlLayout->setColumnStretch( 8, 0 );
597 controlLayout->setColumnStretch( 9, 0 );
600 * Other first Line buttons
602 /** Fullscreen/Visualisation **/
603 fullscreenButton = new QPushButton( "F" );
604 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
605 setupSmallButton( fullscreenButton );
606 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
608 /** Playlist Button **/
609 playlistButton = new QPushButton;
610 setupSmallButton( playlistButton );
611 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
612 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
613 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
615 /** extended Settings **/
616 extSettingsButton = new QPushButton;
617 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
619 setupSmallButton( extSettingsButton );
620 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
622 controlLayout->setColumnStretch( 13, 0 );
623 controlLayout->setColumnMinimumWidth( 13, 24 );
624 controlLayout->setColumnStretch( 14, 5 );
627 hVolLabel = new VolumeClickHandler( p_intf, this );
629 volMuteLabel = new QLabel;
630 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
631 volMuteLabel->setToolTip( qtr( "Mute" ) );
632 volMuteLabel->installEventFilter( hVolLabel );
633 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
637 volumeSlider = new SoundSlider( this,
638 config_GetInt( p_intf, "volume-step" ),
639 config_GetInt( p_intf, "qt-volume-complete" ),
640 config_GetPsz( p_intf, "qt-slider-colours" ) );
644 volumeSlider = new QSlider( this );
645 volumeSlider->setOrientation( Qt::Horizontal );
647 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
648 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
649 volumeSlider->setFocusPolicy( Qt::NoFocus );
650 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
652 /* Set the volume from the config */
653 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
654 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
656 /* Force the update at build time in order to have a muted icon if needed */
657 updateVolume( volumeSlider->value() );
659 /* Volume control connection */
660 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
661 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
666 ControlsWidget::~ControlsWidget()
669 void ControlsWidget::toggleTeletext()
671 bool b_enabled = THEMIM->teletextState();
674 telexTransparent->setEnabled( false );
675 telexPage->setEnabled( false );
676 b_telexEnabled = false;
680 telexTransparent->setEnabled( true );
681 telexPage->setEnabled( true );
682 b_telexEnabled = true;
686 void ControlsWidget::toggleTeletextTransparency()
688 if( b_telexTransparent )
690 telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx.png" ) );
691 telexTransparent->setToolTip( qtr( "Teletext" ) );
692 b_telexTransparent = false;
696 telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx-transparent.png" ) );
697 telexTransparent->setToolTip( qtr( "Transparent" ) );
698 b_telexTransparent = true;
702 void ControlsWidget::stop()
707 void ControlsWidget::play()
709 if( THEPL->current.i_size == 0 )
711 /* The playlist is empty, open a file requester */
712 THEDP->openFileDialog();
716 THEMIM->togglePlayPause();
719 void ControlsWidget::prev()
724 void ControlsWidget::next()
729 void ControlsWidget::setNavigation( int navigation )
731 #define HELP_MENU N_( "Menu" )
732 #define HELP_PCH N_( "Previous chapter" )
733 #define HELP_NCH N_( "Next chapter" )
734 #define HELP_PTR N_( "Previous track" )
735 #define HELP_NTR N_( "Next track" )
737 // 1 = chapter, 2 = title, 0 = no
738 if( navigation == 0 )
741 } else if( navigation == 1 ) {
742 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
743 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
747 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
748 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
754 static bool b_my_volume;
755 void ControlsWidget::updateVolume( int i_sliderVolume )
759 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
760 aout_VolumeSet( p_intf, i_res );
762 if( i_sliderVolume == 0 )
763 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
764 else if( i_sliderVolume < VOLUME_MAX / 3 )
765 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
766 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
767 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
768 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
771 void ControlsWidget::updateVolume()
774 audio_volume_t i_volume;
775 aout_VolumeGet( p_intf, &i_volume );
776 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
777 int i_gauge = volumeSlider->value();
779 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
782 volumeSlider->setValue( i_volume );
787 void ControlsWidget::updateInput()
789 /* Activate the interface buttons according to the presence of the input */
790 enableInput( THEMIM->getIM()->hasInput() );
791 enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
794 void ControlsWidget::setStatus( int status )
796 if( status == PLAYING_S ) /* Playing */
798 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
799 playButton->setToolTip( qtr( "Pause" ) );
803 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
804 playButton->setToolTip( qtr( "Play" ) );
810 * This functions toggle the fullscreen mode
811 * If there is no video, it should first activate Visualisations...
812 * This has also to be fixed in enableVideo()
814 void ControlsWidget::fullscreen()
816 vout_thread_t *p_vout =
817 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
820 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
821 vlc_object_release( p_vout );
825 void ControlsWidget::extSettings()
827 THEDP->extendedDialog();
830 void ControlsWidget::slower()
832 THEMIM->getIM()->slower();
835 void ControlsWidget::faster()
837 THEMIM->getIM()->faster();
840 void ControlsWidget::enableInput( bool enable )
842 slowerButton->setEnabled( enable );
843 slider->setEnabled( enable );
844 fasterButton->setEnabled( enable );
846 /* Advanced Buttons too */
847 advControls->enableInput( enable );
850 void ControlsWidget::enableVideo( bool enable )
852 // TODO Later make the fullscreenButton toggle Visualisation and so on.
853 fullscreenButton->setEnabled( enable );
855 /* Advanced Buttons too */
856 advControls->enableVideo( enable );
859 void ControlsWidget::toggleAdvanced()
861 if( !VISIBLE( advControls ) )
864 b_advancedVisible = true;
869 b_advancedVisible = false;
871 emit advancedControlsToggled( b_advancedVisible );
875 /**********************************************************************
876 * Fullscrenn control widget
877 **********************************************************************/
878 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
879 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
880 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
881 i_lastPosX( -1 ), i_lastPosY( -1 ), i_hideTimeout( 1 ),
882 b_mouseIsOver( false )
884 setWindowFlags( Qt::ToolTip );
886 setFrameShape( QFrame::StyledPanel );
887 setFrameStyle( QFrame::Sunken );
888 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
890 QGridLayout *fsLayout = new QGridLayout( this );
891 controlLayout->setSpacing( 0 );
892 controlLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
894 fsLayout->addWidget( slowerButton, 0, 0 );
895 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
896 fsLayout->addWidget( slider, 0, 1, 1, 6 );
897 fsLayout->addWidget( fasterButton, 0, 7 );
899 fsLayout->addWidget( volMuteLabel, 1, 0);
900 fsLayout->addWidget( volumeSlider, 1, 1 );
902 fsLayout->addLayout( controlButLayout, 1, 2 );
904 fsLayout->addWidget( playButton, 1, 3 );
906 fsLayout->addWidget( discFrame, 1, 4 );
908 fsLayout->addWidget( telexFrame, 1, 5 );
910 fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
912 fsLayout->addWidget( fullscreenButton, 1, 7 );
915 p_hideTimer = new QTimer( this );
916 CONNECT( p_hideTimer, timeout(), this, hideFSControllerWidget() );
917 p_hideTimer->setSingleShot( true );
919 /* slow hiding timer */
920 #if HAVE_TRANSPARENCY
921 p_slowHideTimer = new QTimer( this );
922 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
925 adjustSize (); /* need to get real width and height for moving */
928 QDesktopWidget * p_desktop = QApplication::desktop();
930 move( p_desktop->width() / 2 - width() / 2,
931 p_desktop->height() - height() );
934 setWindowOpacity( 0.0 );
940 FullscreenControllerWidget::~FullscreenControllerWidget()
945 * Hide fullscreen controller
946 * FIXME: under windows it have to be done by moving out of screen
947 * because hide() doesnt work
949 void FullscreenControllerWidget::hideFSControllerWidget()
953 setWindowOpacity( 0.0 ); // simulate hidding
960 * Hidding fullscreen controller slowly
961 * Linux: need composite manager
962 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
964 void FullscreenControllerWidget::slowHideFSC()
966 #if HAVE_TRANSPARENCY
967 static bool first_call = true;
973 p_slowHideTimer->stop();
974 /* the last part of time divided to 100 pieces */
975 p_slowHideTimer->start(
976 (int) ( i_hideTimeout / 2 / ( windowOpacity() * 100 ) ) );
980 if ( windowOpacity() > 0.0 )
982 /* we should use 0.01 because of 100 pieces ^^^
983 but than it cannt be done in time */
984 setWindowOpacity( windowOpacity() - 0.02 );
987 if ( windowOpacity() == 0.0 )
990 p_slowHideTimer->stop();
997 * Get state of visibility of FS controller on screen
998 * On windows control if it is on hidden position
1000 bool FullscreenControllerWidget::isFSCHidden()
1011 * events: show, hide, start timer for hidding
1013 void FullscreenControllerWidget::customEvent( QEvent *event )
1015 int type = event->type();
1017 if ( type == FullscreenControlShow_Type )
1020 // after quiting and going to fs, we need to call show()
1027 setWindowOpacity( 1.0 );
1033 #if HAVE_TRANSPARENCY
1034 setWindowOpacity( DEFAULT_OPACITY );
1037 else if ( type == FullscreenControlHide_Type )
1039 hideFSControllerWidget();
1041 else if ( type == FullscreenControlPlanHide_Type && !b_mouseIsOver )
1043 p_hideTimer->start( i_hideTimeout );
1044 #if HAVE_TRANSPARENCY
1045 p_slowHideTimer->start( i_hideTimeout / 2 );
1054 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1056 if ( event->buttons() == Qt::LeftButton )
1058 int i_moveX = event->globalX() - i_lastPosX;
1059 int i_moveY = event->globalY() - i_lastPosY;
1061 move( x() + i_moveX, y() + i_moveY );
1063 i_lastPosX = event->globalX();
1064 i_lastPosY = event->globalY();
1070 * store position of cursor
1072 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1074 i_lastPosX = event->globalX();
1075 i_lastPosY = event->globalY();
1079 * On mouse go above FSC
1081 void FullscreenControllerWidget::enterEvent( QEvent *event )
1083 p_hideTimer->stop();
1084 #if HAVE_TRANSPARENCY
1085 p_slowHideTimer->stop();
1087 b_mouseIsOver = true;
1091 * On mouse go out from FSC
1093 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1095 p_hideTimer->start( i_hideTimeout );
1096 #if HAVE_TRANSPARENCY
1097 p_slowHideTimer->start( i_hideTimeout / 2 );
1099 b_mouseIsOver = false;
1103 * When you get pressed key, send it to video output
1104 * FIXME: clearing focus by clearFocus() to not getting
1105 * key press events didnt work
1107 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1109 int i_vlck = qtEventToVLCKey( event );
1112 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1120 * It is called when video start
1122 void FullscreenControllerWidget::regFullscreenCallback( vout_thread_t *p_vout )
1126 var_AddCallback( p_vout, "fullscreen", regMouseMoveCallback, this );
1131 * It is called after turn off video, because p_vout is NULL now
1132 * we cannt delete callback, just hide if FScontroller is visible
1134 void FullscreenControllerWidget::unregFullscreenCallback()
1141 * Register and unregister callback for mouse moving
1143 static int regMouseMoveCallback( vlc_object_t *vlc_object, const char *variable,
1144 vlc_value_t old_val, vlc_value_t new_val,
1147 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1149 static bool b_registered = false;
1150 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1152 if ( var_GetBool( p_vout, "fullscreen" ) && !b_registered )
1154 p_fs->SetHideTimeout( var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1155 var_AddCallback( p_vout, "mouse-moved",
1156 showFullscreenControllCallback, (void *) p_fs );
1157 b_registered = true;
1160 if ( !var_GetBool( p_vout, "fullscreen" ) && b_registered )
1162 var_DelCallback( p_vout, "mouse-moved",
1163 showFullscreenControllCallback, (void *) p_fs );
1164 b_registered = false;
1172 * Show fullscreen controller after mouse move
1173 * after show immediately plan hide event
1175 static int showFullscreenControllCallback( vlc_object_t *vlc_object, const char *variable,
1176 vlc_value_t old_val, vlc_value_t new_val,
1179 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1181 if ( p_fs->isFSCHidden() || p_fs->windowOpacity() < DEFAULT_OPACITY )
1183 IMEvent *event = new IMEvent( FullscreenControlShow_Type, 0 );
1184 QApplication::postEvent( p_fs, static_cast<QEvent *>(event) );
1187 IMEvent *e = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1188 QApplication::postEvent( p_fs, static_cast<QEvent *>(e) );
1193 /**********************************************************************
1194 * Speed control widget
1195 **********************************************************************/
1196 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1197 QFrame( NULL ), p_intf( _p_i )
1199 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1200 sizePolicy.setHorizontalStretch( 0 );
1201 sizePolicy.setVerticalStretch( 0 );
1203 speedSlider = new QSlider;
1204 speedSlider->setSizePolicy( sizePolicy );
1205 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1206 speedSlider->setOrientation( Qt::Vertical );
1207 speedSlider->setTickPosition( QSlider::TicksRight );
1209 speedSlider->setRange( -100, 100 );
1210 speedSlider->setSingleStep( 10 );
1211 speedSlider->setPageStep( 20 );
1212 speedSlider->setTickInterval( 20 );
1214 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1216 QToolButton *normalSpeedButton = new QToolButton( this );
1217 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1218 normalSpeedButton->setAutoRaise( true );
1219 normalSpeedButton->setText( "N" );
1220 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1222 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1224 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1225 speedControlLayout->addWidget( speedSlider );
1226 speedControlLayout->addWidget( normalSpeedButton );
1227 setLayout( speedControlLayout );
1230 SpeedControlWidget::~SpeedControlWidget()
1233 void SpeedControlWidget::setEnable( bool b_enable )
1235 speedSlider->setEnabled( b_enable );
1238 #define RATE_SLIDER_MAXIMUM 3.0
1239 #define RATE_SLIDER_MINIMUM 0.3
1240 #define RATE_SLIDER_LENGTH 100.0
1242 void SpeedControlWidget::updateControls( int rate )
1244 if( speedSlider->isSliderDown() )
1246 //We don't want to change anything if the user is using the slider
1251 double speed = INPUT_RATE_DEFAULT / (double)rate;
1253 if( rate >= INPUT_RATE_DEFAULT )
1255 if( speed < RATE_SLIDER_MINIMUM )
1257 sliderValue = speedSlider->minimum();
1261 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
1262 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
1267 if( speed > RATE_SLIDER_MAXIMUM )
1269 sliderValue = speedSlider->maximum();
1273 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
1274 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
1278 //Block signals to avoid feedback loop
1279 speedSlider->blockSignals( true );
1280 speedSlider->setValue( sliderValue );
1281 speedSlider->blockSignals( false );
1284 void SpeedControlWidget::updateRate( int sliderValue )
1288 if( sliderValue < 0.0 )
1290 rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
1291 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ));
1295 rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
1296 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH ));
1299 THEMIM->getIM()->setRate(rate);
1302 void SpeedControlWidget::resetRate()
1304 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);