1 /*****************************************************************************
2 * interface_widgets.cpp : Custom widgets for the main interface
3 ****************************************************************************
4 * Copyright ( C ) 2006 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
9 * Rafaël Carré <funman@videolanorg>
10 * Ilkka Ollakka <ileoo@videolan.org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * ( at your option ) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
33 #include "dialogs_provider.hpp"
34 #include "components/interface_widgets.hpp"
35 #include "main_interface.hpp"
36 #include "input_manager.hpp"
38 #include "util/input_slider.hpp"
39 #include "util/customwidgets.hpp"
42 #include <QSpacerItem>
44 #include <QPushButton>
45 #include <QToolButton>
46 #include <QHBoxLayout>
49 #include <QResizeEvent>
53 # include <X11/Xlib.h>
54 # include <qx11info_x11.h>
59 #define I_PLAY_TOOLTIP "Play\nIf the playlist is empty, open a media"
61 /**********************************************************************
62 * Video Widget. A simple frame on which video is drawn
63 * This class handles resize issues
64 **********************************************************************/
66 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
70 hide(); setMinimumSize( 16, 16 );
71 videoSize.rwidth() = -1;
72 videoSize.rheight() = -1;
73 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
75 /* Black background is more coherent for a Video Widget IMVHO */
76 QPalette plt = palette();
77 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
78 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
80 setAttribute( Qt::WA_PaintOnScreen, true );
82 /* The core can ask through a callback to show the video. */
84 connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
85 this, SLOT(SetSizing(unsigned int, unsigned int )),
86 Qt::BlockingQueuedConnection );
88 #error This is broken. Fix it with a QEventLoop with a processEvents ()
89 connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
90 this, SLOT(SetSizing(unsigned int, unsigned int )) );
94 void VideoWidget::paintEvent(QPaintEvent *ev)
96 QFrame::paintEvent(ev);
98 XFlush( QX11Info::display() );
102 VideoWidget::~VideoWidget()
104 vout_thread_t *p_vout = i_vout
105 ? (vout_thread_t *)vlc_object_get( i_vout ) : NULL;
109 if( !p_intf->psz_switch_intf )
111 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
112 vout_Control( p_vout, VOUT_REPARENT );
116 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
117 vout_Control( p_vout, VOUT_CLOSE );
119 vlc_object_release( p_vout );
124 * Request the video to avoid the conflicts
126 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
127 unsigned int *pi_width, unsigned int *pi_height )
129 msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
130 emit askVideoWidgetToShow( *pi_width, *pi_height );
133 msg_Dbg( p_intf, "embedded video already in use" );
136 i_vout = p_nvout->i_object_id;
137 msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );
138 return ( void* )winId();
141 /* Set the Widget to the correct Size */
142 /* Function has to be called by the parent
143 Parent has to care about resizing himself*/
144 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
146 msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
147 videoSize.rwidth() = w;
148 videoSize.rheight() = h;
149 if( isHidden() ) show();
150 updateGeometry(); // Needed for deinterlace
153 void VideoWidget::release( void *p_win )
155 msg_Dbg( p_intf, "Video is not needed anymore" );
157 videoSize.rwidth() = 0;
158 videoSize.rheight() = 0;
160 updateGeometry(); // Needed for deinterlace
163 QSize VideoWidget::sizeHint() const
168 /**********************************************************************
169 * Background Widget. Show a simple image background. Currently,
170 * it's album art if present or cone.
171 **********************************************************************/
172 #define ICON_SIZE 128
173 #define MAX_BG_SIZE 400
174 #define MIN_BG_SIZE 64
176 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
177 :QWidget( NULL ), p_intf( _p_i )
179 /* We should use that one to take the more size it can */
180 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding);
182 /* A dark background */
183 setAutoFillBackground( true );
185 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
186 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
189 /* A cone in the middle */
191 label->setMargin( 5 );
192 label->setMaximumHeight( MAX_BG_SIZE );
193 label->setMaximumWidth( MAX_BG_SIZE );
194 label->setMinimumHeight( MIN_BG_SIZE );
195 label->setMinimumWidth( MIN_BG_SIZE );
196 if( QDate::currentDate().dayOfYear() >= 354 )
197 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
199 label->setPixmap( QPixmap( ":/vlc128.png" ) );
201 QGridLayout *backgroundLayout = new QGridLayout( this );
202 backgroundLayout->addWidget( label, 0, 1 );
203 backgroundLayout->setColumnStretch( 0, 1 );
204 backgroundLayout->setColumnStretch( 2, 1 );
206 CONNECT( THEMIM->getIM(), artChanged( QString ), this, updateArt( QString ) );
209 BackgroundWidget::~BackgroundWidget()
212 void BackgroundWidget::resizeEvent( QResizeEvent * event )
214 if( event->size().height() <= MIN_BG_SIZE )
220 void BackgroundWidget::updateArt( QString url )
224 if( QDate::currentDate().dayOfYear() >= 354 )
225 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
227 label->setPixmap( QPixmap( ":/vlc128.png" ) );
232 label->setPixmap( QPixmap( url ) );
236 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
238 QVLCMenu::PopupMenu( p_intf, true );
241 /**********************************************************************
242 * Visualization selector panel
243 **********************************************************************/
244 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
245 QFrame( NULL ), p_intf( _p_i )
247 QHBoxLayout *layout = new QHBoxLayout( this );
248 layout->setMargin( 0 );
249 QPushButton *prevButton = new QPushButton( "Prev" );
250 QPushButton *nextButton = new QPushButton( "Next" );
251 layout->addWidget( prevButton );
252 layout->addWidget( nextButton );
254 layout->addStretch( 10 );
255 layout->addWidget( new QLabel( qtr( "Current visualization" ) ) );
257 current = new QLabel( qtr( "None" ) );
258 layout->addWidget( current );
260 BUTTONACT( prevButton, prev() );
261 BUTTONACT( nextButton, next() );
264 setMaximumHeight( 35 );
267 VisualSelector::~VisualSelector()
270 void VisualSelector::prev()
272 char *psz_new = aout_VisualPrev( p_intf );
275 current->setText( qfu( psz_new ) );
280 void VisualSelector::next()
282 char *psz_new = aout_VisualNext( p_intf );
285 current->setText( qfu( psz_new ) );
290 /**********************************************************************
292 **********************************************************************/
294 #define setupSmallButton( aButton ){ \
295 aButton->setMaximumSize( QSize( 26, 26 ) ); \
296 aButton->setMinimumSize( QSize( 26, 26 ) ); \
297 aButton->setIconSize( QSize( 20, 20 ) ); }
299 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
300 QFrame( NULL ), p_intf( _p_i )
302 QHBoxLayout *advLayout = new QHBoxLayout( this );
303 advLayout->setMargin( 0 );
304 advLayout->setSpacing( 0 );
305 advLayout->setAlignment( Qt::AlignBottom );
308 ABButton = new QPushButton;
309 setupSmallButton( ABButton );
310 advLayout->addWidget( ABButton );
311 BUTTON_SET_ACT_I( ABButton, "", atob_nob,
312 qtr( "Loop from point A to point B continuously.\nClick to set point A" ),
315 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
316 this, AtoBLoop( float, int, int ) );
318 frameButton = new QPushButton( "Fr" );
319 frameButton->setMaximumSize( QSize( 26, 26 ) );
320 frameButton->setIconSize( QSize( 20, 20 ) );
321 advLayout->addWidget( frameButton );
322 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by frame" ), frame() );
325 recordButton = new QPushButton;
326 setupSmallButton( recordButton );
327 advLayout->addWidget( recordButton );
328 BUTTON_SET_ACT_I( recordButton, "", record,
329 qtr( "Record" ), record() );
331 /* Snapshot Button */
332 snapshotButton = new QPushButton;
333 setupSmallButton( snapshotButton );
334 advLayout->addWidget( snapshotButton );
335 BUTTON_SET_ACT_I( snapshotButton, "", snapshot,
336 qtr( "Take a snapshot" ), snapshot() );
339 AdvControlsWidget::~AdvControlsWidget()
342 void AdvControlsWidget::enableInput( bool enable )
344 ABButton->setEnabled( enable );
345 recordButton->setEnabled( enable );
348 void AdvControlsWidget::enableVideo( bool enable )
350 snapshotButton->setEnabled( enable );
352 frameButton->setEnabled( enable );
356 void AdvControlsWidget::snapshot()
358 vout_thread_t *p_vout =
359 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
360 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
363 /* Function called when the button is clicked() */
364 void AdvControlsWidget::fromAtoB()
368 timeA = var_GetTime( THEMIM->getInput(), "time" );
369 ABButton->setToolTip( "Click to set point B" );
370 ABButton->setIcon( QIcon( ":/atob_noa" ) );
375 timeB = var_GetTime( THEMIM->getInput(), "time" );
376 var_SetTime( THEMIM->getInput(), "time" , timeA );
377 ABButton->setIcon( QIcon( ":/atob" ) );
378 ABButton->setToolTip( "Stop the A to B loop" );
383 ABButton->setToolTip( qtr( "Loop from point A to point B continuously\nClick to set point A" ) );
384 ABButton->setIcon( QIcon( ":/atob_nob" ) );
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 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
417 /** The main Slider **/
418 slider = new InputSlider( Qt::Horizontal, NULL );
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() );
433 fasterButton = new QToolButton;
434 fasterButton->setAutoRaise( true );
435 fasterButton->setMaximumSize( QSize( 26, 20 ) );
437 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
439 /* advanced Controls handling */
440 b_advancedVisible = b_advControls;
442 advControls = new AdvControlsWidget( p_intf );
443 if( !b_advancedVisible ) advControls->hide();
445 /** Disc and Menus handling */
446 discFrame = new QWidget( this );
448 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
449 discLayout->setSpacing( 0 );
450 discLayout->setMargin( 0 );
452 prevSectionButton = new QPushButton( discFrame );
453 setupSmallButton( prevSectionButton );
454 discLayout->addWidget( prevSectionButton );
456 menuButton = new QPushButton( discFrame );
457 setupSmallButton( menuButton );
458 discLayout->addWidget( menuButton );
460 nextSectionButton = new QPushButton( discFrame );
461 setupSmallButton( nextSectionButton );
462 discLayout->addWidget( nextSectionButton );
464 BUTTON_SET_IMG( prevSectionButton, "", dvd_prev, "" );
465 BUTTON_SET_IMG( nextSectionButton, "", dvd_next, "" );
466 BUTTON_SET_IMG( menuButton, "", dvd_menu, qtr( "Menu" ) );
470 /* Change the navigation button display when the IM navigation changes */
471 CONNECT( THEMIM->getIM(), navigationChanged( int ),
472 this, setNavigation( int ) );
473 /* Changes the IM navigation when triggered on the nav buttons */
474 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
476 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
478 CONNECT( menuButton, clicked(), THEMIM->getIM(),
483 * TODO: Merge with upper menu in a StackLayout
485 telexFrame = new QWidget( this );
486 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
487 telexLayout->setSpacing( 0 );
488 telexLayout->setMargin( 0 );
490 telexOn = new QPushButton;
491 setupSmallButton( telexOn );
492 telexLayout->addWidget( telexOn );
494 telexTransparent = new QPushButton;
495 setupSmallButton( telexTransparent );
496 telexLayout->addWidget( telexTransparent );
497 b_telexTransparent = false;
499 telexPage = new QSpinBox;
500 telexPage->setRange( 0, 999 );
501 telexPage->setValue( 100 );
502 telexPage->setAccelerated( true );
503 telexPage->setWrapping( true );
504 telexPage->setAlignment( Qt::AlignRight );
505 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
506 telexLayout->addWidget( telexPage );
508 telexFrame->hide(); /* default hidden */
510 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
511 telexGotoPage( int ) );
512 CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
513 telexPage, setValue( int ) );
515 BUTTON_SET_IMG( telexOn, "", tv, qtr( "Teletext on" ) );
517 CONNECT( telexOn, clicked(), THEMIM->getIM(),
518 telexToggleButtons() );
519 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
520 telexToggle( bool ) );
521 CONNECT( THEMIM->getIM(), toggleTelexButtons(),
522 this, toggleTeletext() );
523 b_telexEnabled = false;
524 telexTransparent->setEnabled( false );
525 telexPage->setEnabled( false );
527 BUTTON_SET_IMG( telexTransparent, "", tvtelx, qtr( "Teletext" ) );
528 CONNECT( telexTransparent, clicked( bool ),
529 THEMIM->getIM(), telexSetTransparency() );
530 CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
531 this, toggleTeletextTransparency() );
532 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
533 this, enableTeletext( bool ) );
536 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
537 sizePolicy.setHorizontalStretch( 0 );
538 sizePolicy.setVerticalStretch( 0 );
541 playButton = new QPushButton;
542 playButton->setSizePolicy( sizePolicy );
543 playButton->setMaximumSize( QSize( 36, 36 ) );
544 playButton->setMinimumSize( QSize( 36, 36 ) );
545 playButton->setIconSize( QSize( 30, 30 ) );
548 /** Prev + Stop + Next Block **/
549 controlButLayout = new QHBoxLayout;
550 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
553 QPushButton *prevButton = new QPushButton;
554 prevButton->setSizePolicy( sizePolicy );
555 setupSmallButton( prevButton );
557 controlButLayout->addWidget( prevButton );
560 QPushButton *stopButton = new QPushButton;
561 stopButton->setSizePolicy( sizePolicy );
562 setupSmallButton( stopButton );
564 controlButLayout->addWidget( stopButton );
567 QPushButton *nextButton = new QPushButton;
568 nextButton->setSizePolicy( sizePolicy );
569 setupSmallButton( nextButton );
571 controlButLayout->addWidget( nextButton );
573 /* Add this block to the main layout */
575 BUTTON_SET_ACT_I( playButton, "", play_b, qtr( I_PLAY_TOOLTIP ), play() );
576 BUTTON_SET_ACT_I( prevButton, "" , previous_b,
577 qtr( "Previous media in the playlist" ), prev() );
578 BUTTON_SET_ACT_I( nextButton, "", next_b,
579 qtr( "Next media in the playlist" ), next() );
580 BUTTON_SET_ACT_I( stopButton, "", stop_b, qtr( "Stop playback" ), stop() );
583 * Other first Line buttons
585 /** Fullscreen/Visualisation **/
586 fullscreenButton = new QPushButton;
587 BUTTON_SET_ACT_I( fullscreenButton, "", fullscreen,
588 qtr( "Toggle the video in fullscreen" ), fullscreen() );
589 setupSmallButton( fullscreenButton );
593 /** Playlist Button **/
594 playlistButton = new QPushButton;
595 setupSmallButton( playlistButton );
596 BUTTON_SET_IMG( playlistButton, "" , playlist, qtr( "Show playlist" ) );
597 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
599 /** extended Settings **/
600 extSettingsButton = new QPushButton;
601 BUTTON_SET_ACT_I( extSettingsButton, "", extended,
602 qtr( "Show extended settings" ), extSettings() );
603 setupSmallButton( extSettingsButton );
607 hVolLabel = new VolumeClickHandler( p_intf, this );
609 volMuteLabel = new QLabel;
610 volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
611 volMuteLabel->installEventFilter( hVolLabel );
615 volumeSlider = new SoundSlider( this,
616 config_GetInt( p_intf, "volume-step" ),
617 config_GetInt( p_intf, "qt-volume-complete" ),
618 config_GetPsz( p_intf, "qt-slider-colours" ) );
622 volumeSlider = new QSlider( this );
623 volumeSlider->setOrientation( Qt::Horizontal );
625 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
626 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
627 volumeSlider->setFocusPolicy( Qt::NoFocus );
629 /* Set the volume from the config */
630 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
631 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
633 /* Force the update at build time in order to have a muted icon if needed */
634 updateVolume( volumeSlider->value() );
636 /* Volume control connection */
637 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
638 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
642 controlLayout = new QGridLayout( this );
644 controlLayout->setSpacing( 0 );
645 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
647 controlLayout->addWidget( slider, 0, 1, 1, 16 );
648 controlLayout->addWidget( slowerButton, 0, 0 );
649 controlLayout->addWidget( fasterButton, 0, 17 );
651 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
652 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
653 controlLayout->addWidget( telexFrame, 1, 10, 2, 4, Qt::AlignBottom );
655 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
656 controlLayout->setColumnMinimumWidth( 2, 20 );
657 controlLayout->setColumnStretch( 2, 0 );
659 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
660 controlLayout->setColumnMinimumWidth( 7, 20 );
661 controlLayout->setColumnStretch( 7, 0 );
662 controlLayout->setColumnStretch( 8, 0 );
663 controlLayout->setColumnStretch( 9, 0 );
665 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
666 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
667 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
669 controlLayout->setColumnStretch( 13, 0 );
670 controlLayout->setColumnMinimumWidth( 13, 24 );
671 controlLayout->setColumnStretch( 14, 5 );
673 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
674 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
680 ControlsWidget::~ControlsWidget()
683 void ControlsWidget::toggleTeletext()
685 bool b_enabled = THEMIM->teletextState();
688 telexTransparent->setEnabled( false );
689 telexPage->setEnabled( false );
690 b_telexEnabled = false;
694 telexTransparent->setEnabled( true );
695 telexPage->setEnabled( true );
696 b_telexEnabled = true;
700 void ControlsWidget::enableTeletext( bool b_enable )
702 telexFrame->setVisible( b_enable );
703 bool b_on = THEMIM->teletextState();
705 telexOn->setChecked( b_on );
706 telexTransparent->setEnabled( b_on );
707 telexPage->setEnabled( b_on );
708 b_telexEnabled = b_on;
711 void ControlsWidget::toggleTeletextTransparency()
713 if( b_telexTransparent )
715 telexTransparent->setIcon( QIcon( ":/tvtelx" ) );
716 telexTransparent->setToolTip( qtr( "Teletext" ) );
717 b_telexTransparent = false;
721 telexTransparent->setIcon( QIcon( ":/tvtelx-transparent" ) );
722 telexTransparent->setToolTip( qtr( "Transparent" ) );
723 b_telexTransparent = true;
727 void ControlsWidget::stop()
732 void ControlsWidget::play()
734 if( THEPL->current.i_size == 0 )
736 /* The playlist is empty, open a file requester */
737 THEDP->openFileDialog();
741 THEMIM->togglePlayPause();
744 void ControlsWidget::prev()
749 void ControlsWidget::next()
754 void ControlsWidget::setNavigation( int navigation )
756 #define HELP_PCH N_( "Previous chapter" )
757 #define HELP_NCH N_( "Next chapter" )
759 // 1 = chapter, 2 = title, 0 = no
760 if( navigation == 0 )
763 } else if( navigation == 1 ) {
764 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
765 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
769 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
770 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
776 static bool b_my_volume;
777 void ControlsWidget::updateVolume( int i_sliderVolume )
781 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
782 aout_VolumeSet( p_intf, i_res );
784 if( i_sliderVolume == 0 )
786 volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
787 volMuteLabel->setToolTip( qtr( "Unmute" ) );
791 if( i_sliderVolume < VOLUME_MAX / 3 )
792 volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
793 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
794 volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
795 else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
796 volMuteLabel->setToolTip( qtr( "Mute" ) );
799 void ControlsWidget::updateVolume()
802 audio_volume_t i_volume;
803 aout_VolumeGet( p_intf, &i_volume );
804 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
805 int i_gauge = volumeSlider->value();
807 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
810 volumeSlider->setValue( i_volume );
815 void ControlsWidget::updateInput()
817 /* Activate the interface buttons according to the presence of the input */
818 enableInput( THEMIM->getIM()->hasInput() );
819 enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
822 void ControlsWidget::setStatus( int status )
824 if( status == PLAYING_S ) /* Playing */
826 playButton->setIcon( QIcon( ":/pause_b" ) );
827 playButton->setToolTip( qtr( "Pause the playback" ) );
831 playButton->setIcon( QIcon( ":/play_b" ) );
832 playButton->setToolTip( qtr( I_PLAY_TOOLTIP ) );
838 * This functions toggle the fullscreen mode
839 * If there is no video, it should first activate Visualisations...
840 * This has also to be fixed in enableVideo()
842 void ControlsWidget::fullscreen()
844 vout_thread_t *p_vout =
845 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
848 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
849 vlc_object_release( p_vout );
853 void ControlsWidget::extSettings()
855 THEDP->extendedDialog();
858 void ControlsWidget::slower()
860 THEMIM->getIM()->slower();
863 void ControlsWidget::faster()
865 THEMIM->getIM()->faster();
868 void ControlsWidget::enableInput( bool enable )
870 slowerButton->setEnabled( enable );
871 slider->setEnabled( enable );
872 fasterButton->setEnabled( enable );
874 /* Advanced Buttons too */
875 advControls->enableInput( enable );
878 void ControlsWidget::enableVideo( bool enable )
880 // TODO Later make the fullscreenButton toggle Visualisation and so on.
881 fullscreenButton->setEnabled( enable );
883 /* Advanced Buttons too */
884 advControls->enableVideo( enable );
887 void ControlsWidget::toggleAdvanced()
889 if( !VISIBLE( advControls ) )
892 b_advancedVisible = true;
897 b_advancedVisible = false;
899 emit advancedControlsToggled( b_advancedVisible );
903 /**********************************************************************
904 * Fullscrenn control widget
905 **********************************************************************/
906 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
907 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
908 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
909 i_mouse_last_x( -1 ), i_mouse_last_y( -1 ), b_mouse_over(false),
910 b_slow_hide_begin(false), i_slow_hide_timeout(1),
911 b_fullscreen( false ), i_hide_timeout( 1 )
913 setWindowFlags( Qt::ToolTip );
915 setFrameShape( QFrame::StyledPanel );
916 setFrameStyle( QFrame::Sunken );
917 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
919 QGridLayout *fsLayout = new QGridLayout( this );
920 fsLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
923 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
924 fsLayout->addWidget( slowerButton, 0, 0 );
925 fsLayout->addWidget( slider, 0, 1, 1, 6 );
926 fsLayout->addWidget( fasterButton, 0, 7 );
928 fsLayout->addWidget( playButton, 1, 0 );
929 fsLayout->addLayout( controlButLayout, 1, 1 );
931 fsLayout->addWidget( discFrame, 1, 2 );
932 fsLayout->addWidget( telexFrame, 1, 3 );
933 fsLayout->addWidget( advControls, 1, 4, Qt::AlignVCenter );
934 fsLayout->addWidget( fullscreenButton, 1, 5 );
936 fsLayout->addWidget( volMuteLabel, 1, 6);
937 fsLayout->addWidget( volumeSlider, 1, 7 );
940 p_hideTimer = new QTimer( this );
941 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
942 p_hideTimer->setSingleShot( true );
944 /* slow hiding timer */
945 #if HAVE_TRANSPARENCY
946 p_slowHideTimer = new QTimer( this );
947 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
950 adjustSize (); /* need to get real width and height for moving */
953 QDesktopWidget * p_desktop = QApplication::desktop();
955 move( p_desktop->width() / 2 - width() / 2,
956 p_desktop->height() - height() );
959 setWindowOpacity( 0.0 );
964 vlc_mutex_init_recursive( &lock );
967 FullscreenControllerWidget::~FullscreenControllerWidget()
969 vlc_mutex_destroy( &lock );
973 * Show fullscreen controller
975 void FullscreenControllerWidget::showFSC()
978 // after quiting and going to fs, we need to call show()
985 setWindowOpacity( 1.0 );
991 #if HAVE_TRANSPARENCY
992 setWindowOpacity( DEFAULT_OPACITY );
997 * Hide fullscreen controller
998 * FIXME: under windows it have to be done by moving out of screen
999 * because hide() doesnt work
1001 void FullscreenControllerWidget::hideFSC()
1005 setWindowOpacity( 0.0 ); // simulate hidding
1012 * Plane to hide fullscreen controller
1014 void FullscreenControllerWidget::planHideFSC()
1016 vlc_mutex_lock( &lock );
1017 int i_timeout = i_hide_timeout;
1018 vlc_mutex_unlock( &lock );
1020 p_hideTimer->start( i_timeout );
1022 #if HAVE_TRANSPARENCY
1023 b_slow_hide_begin = true;
1024 i_slow_hide_timeout = i_timeout;
1025 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
1030 * Hidding fullscreen controller slowly
1031 * Linux: need composite manager
1032 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
1034 void FullscreenControllerWidget::slowHideFSC()
1036 #if HAVE_TRANSPARENCY
1037 if( b_slow_hide_begin )
1039 b_slow_hide_begin = false;
1041 p_slowHideTimer->stop();
1042 /* the last part of time divided to 100 pieces */
1043 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
1049 if ( windowOpacity() > 0.0 && !fscHidden )
1051 if ( windowOpacity() > 0.0 )
1054 /* we should use 0.01 because of 100 pieces ^^^
1055 but than it cannt be done in time */
1056 setWindowOpacity( windowOpacity() - 0.02 );
1059 if ( windowOpacity() <= 0.0 )
1060 p_slowHideTimer->stop();
1067 * events: show, hide, start timer for hidding
1069 void FullscreenControllerWidget::customEvent( QEvent *event )
1073 switch( event->type() )
1075 case FullscreenControlShow_Type:
1076 vlc_mutex_lock( &lock );
1077 b_fs = b_fullscreen;
1078 vlc_mutex_unlock( &lock );
1080 if( b_fs ) // FIXME I am not sure about that one
1083 case FullscreenControlHide_Type:
1086 case FullscreenControlPlanHide_Type:
1087 if( !b_mouse_over ) // Only if the mouse is not over FSC
1097 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1099 if ( event->buttons() == Qt::LeftButton )
1101 int i_moveX = event->globalX() - i_mouse_last_x;
1102 int i_moveY = event->globalY() - i_mouse_last_y;
1104 move( x() + i_moveX, y() + i_moveY );
1106 i_mouse_last_x = event->globalX();
1107 i_mouse_last_y = event->globalY();
1113 * store position of cursor
1115 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1117 i_mouse_last_x = event->globalX();
1118 i_mouse_last_y = event->globalY();
1122 * On mouse go above FSC
1124 void FullscreenControllerWidget::enterEvent( QEvent *event )
1126 b_mouse_over = true;
1128 p_hideTimer->stop();
1129 #if HAVE_TRANSPARENCY
1130 p_slowHideTimer->stop();
1135 * On mouse go out from FSC
1137 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1141 b_mouse_over = false;
1145 * When you get pressed key, send it to video output
1146 * FIXME: clearing focus by clearFocus() to not getting
1147 * key press events didnt work
1149 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1151 int i_vlck = qtEventToVLCKey( event );
1154 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1162 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object, const char *variable,
1163 vlc_value_t old_val, vlc_value_t new_val,
1166 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1167 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1169 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1174 static int FullscreenControllerWidgetMouseMoved( 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;
1181 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1182 QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1184 /* Plan hide event */
1185 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1186 QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1193 * It is called when video start
1195 void FullscreenControllerWidget::attachVout( vout_thread_t *p_vout )
1199 vlc_mutex_lock( &lock );
1200 var_AddCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this ); /* I miss a add and fire */
1201 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ), var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1202 vlc_mutex_unlock( &lock );
1205 * It is called after turn off video.
1207 void FullscreenControllerWidget::detachVout( vout_thread_t *p_vout )
1211 var_DelCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this );
1212 vlc_mutex_lock( &lock );
1213 fullscreenChanged( p_vout, false, 0 );
1214 vlc_mutex_unlock( &lock );
1218 * Register and unregister callback for mouse moving
1220 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout, bool b_fs, int i_timeout )
1222 vlc_mutex_lock( &lock );
1223 if( b_fs && !b_fullscreen )
1225 b_fullscreen = true;
1226 i_hide_timeout = i_timeout;
1227 var_AddCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1229 else if( !b_fs && b_fullscreen )
1231 b_fullscreen = false;
1232 i_hide_timeout = i_timeout;
1233 var_DelCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1235 /* Force fs hidding */
1236 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1237 QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1239 vlc_mutex_unlock( &lock );
1242 /**********************************************************************
1243 * Speed control widget
1244 **********************************************************************/
1245 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1246 QFrame( NULL ), p_intf( _p_i )
1248 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1249 sizePolicy.setHorizontalStretch( 0 );
1250 sizePolicy.setVerticalStretch( 0 );
1252 speedSlider = new QSlider;
1253 speedSlider->setSizePolicy( sizePolicy );
1254 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1255 speedSlider->setOrientation( Qt::Vertical );
1256 speedSlider->setTickPosition( QSlider::TicksRight );
1258 speedSlider->setRange( -24, 24 );
1259 speedSlider->setSingleStep( 1 );
1260 speedSlider->setPageStep( 1 );
1261 speedSlider->setTickInterval( 12 );
1263 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1265 QToolButton *normalSpeedButton = new QToolButton( this );
1266 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1267 normalSpeedButton->setAutoRaise( true );
1268 normalSpeedButton->setText( "1x" );
1269 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1271 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1273 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1274 speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
1275 speedControlLayout->setSpacing( 4 );
1276 speedControlLayout->addWidget( speedSlider );
1277 speedControlLayout->addWidget( normalSpeedButton );
1278 setLayout( speedControlLayout );
1281 SpeedControlWidget::~SpeedControlWidget()
1284 void SpeedControlWidget::setEnable( bool b_enable )
1286 speedSlider->setEnabled( b_enable );
1289 void SpeedControlWidget::updateControls( int rate )
1291 if( speedSlider->isSliderDown() )
1293 //We don't want to change anything if the user is using the slider
1297 double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
1298 int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
1300 if( sliderValue < speedSlider->minimum() )
1302 sliderValue = speedSlider->minimum();
1304 else if( sliderValue > speedSlider->maximum() )
1306 sliderValue = speedSlider->maximum();
1309 //Block signals to avoid feedback loop
1310 speedSlider->blockSignals( true );
1311 speedSlider->setValue( sliderValue );
1312 speedSlider->blockSignals( false );
1315 void SpeedControlWidget::updateRate( int sliderValue )
1317 double speed = pow( 2, (double)sliderValue / 12 );
1318 int rate = INPUT_RATE_DEFAULT / speed;
1320 THEMIM->getIM()->setRate(rate);
1323 void SpeedControlWidget::resetRate()
1325 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);