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 N_("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 videoSize.rwidth() = -1;
71 videoSize.rheight() = -1;
75 /* Set the policy to expand in both directions */
76 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
78 /* Black background is more coherent for a Video Widget */
79 QPalette plt = palette();
80 plt.setColor( QPalette::Window, Qt::black );
82 setAutoFillBackground(true);
84 /* Indicates that the widget wants to draw directly onto the screen.
85 Widgets with this attribute set do not participate in composition
87 setAttribute( Qt::WA_PaintOnScreen, true );
89 /* The core can ask through a callback to show the video. */
91 connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
92 this, SLOT(SetSizing(unsigned int, unsigned int )),
93 Qt::BlockingQueuedConnection );
95 #warning This is broken. Fix it with a QEventLoop with a processEvents ()
96 connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
97 this, SLOT(SetSizing(unsigned int, unsigned int )) );
101 void VideoWidget::paintEvent(QPaintEvent *ev)
103 QFrame::paintEvent(ev);
105 XFlush( QX11Info::display() );
109 /* Kill the vout at Destruction */
110 VideoWidget::~VideoWidget()
112 vout_thread_t *p_vout = i_vout ?
113 (vout_thread_t *)vlc_object_get( i_vout ) : NULL;
117 if( !p_intf->psz_switch_intf )
119 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
120 vout_Control( p_vout, VOUT_REPARENT );
124 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
125 vout_Control( p_vout, VOUT_CLOSE );
127 vlc_object_release( p_vout );
132 * Request the video to avoid the conflicts
134 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
135 unsigned int *pi_width, unsigned int *pi_height )
137 msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
138 emit askVideoWidgetToShow( *pi_width, *pi_height );
141 msg_Dbg( p_intf, "embedded video already in use" );
144 i_vout = p_nvout->i_object_id;
146 msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );
148 return ( void* )winId();
151 /* Set the Widget to the correct Size */
152 /* Function has to be called by the parent
153 Parent has to care about resizing himself*/
154 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
156 msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
157 videoSize.rwidth() = w;
158 videoSize.rheight() = h;
159 if( isHidden() ) show();
160 updateGeometry(); // Needed for deinterlace
163 void VideoWidget::release( void *p_win )
165 msg_Dbg( p_intf, "Video is not needed anymore" );
167 videoSize.rwidth() = 0;
168 videoSize.rheight() = 0;
173 QSize VideoWidget::sizeHint() const
178 /**********************************************************************
179 * Background Widget. Show a simple image background. Currently,
180 * it's album art if present or cone.
181 **********************************************************************/
182 #define ICON_SIZE 128
183 #define MAX_BG_SIZE 400
184 #define MIN_BG_SIZE 128
186 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
187 :QWidget( NULL ), p_intf( _p_i )
189 /* We should use that one to take the more size it can */
190 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding);
192 /* A dark background */
193 setAutoFillBackground( true );
195 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
196 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
199 /* A cone in the middle */
201 label->setMargin( 5 );
202 label->setMaximumHeight( MAX_BG_SIZE );
203 label->setMaximumWidth( MAX_BG_SIZE );
204 label->setMinimumHeight( MIN_BG_SIZE );
205 label->setMinimumWidth( MIN_BG_SIZE );
206 if( QDate::currentDate().dayOfYear() >= 354 )
207 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
209 label->setPixmap( QPixmap( ":/vlc128.png" ) );
211 QGridLayout *backgroundLayout = new QGridLayout( this );
212 backgroundLayout->addWidget( label, 0, 1 );
213 backgroundLayout->setColumnStretch( 0, 1 );
214 backgroundLayout->setColumnStretch( 2, 1 );
216 CONNECT( THEMIM->getIM(), artChanged( QString ), this, updateArt( QString ) );
219 BackgroundWidget::~BackgroundWidget()
222 void BackgroundWidget::resizeEvent( QResizeEvent * event )
224 if( event->size().height() <= MIN_BG_SIZE )
230 void BackgroundWidget::updateArt( QString url )
234 if( QDate::currentDate().dayOfYear() >= 354 )
235 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
237 label->setPixmap( QPixmap( ":/vlc128.png" ) );
242 label->setPixmap( QPixmap( url ) );
246 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
248 QVLCMenu::PopupMenu( p_intf, true );
252 /**********************************************************************
253 * Visualization selector panel
254 **********************************************************************/
255 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
256 QFrame( NULL ), p_intf( _p_i )
258 QHBoxLayout *layout = new QHBoxLayout( this );
259 layout->setMargin( 0 );
260 QPushButton *prevButton = new QPushButton( "Prev" );
261 QPushButton *nextButton = new QPushButton( "Next" );
262 layout->addWidget( prevButton );
263 layout->addWidget( nextButton );
265 layout->addStretch( 10 );
266 layout->addWidget( new QLabel( qtr( "Current visualization" ) ) );
268 current = new QLabel( qtr( "None" ) );
269 layout->addWidget( current );
271 BUTTONACT( prevButton, prev() );
272 BUTTONACT( nextButton, next() );
275 setMaximumHeight( 35 );
278 VisualSelector::~VisualSelector()
281 void VisualSelector::prev()
283 char *psz_new = aout_VisualPrev( p_intf );
286 current->setText( qfu( psz_new ) );
291 void VisualSelector::next()
293 char *psz_new = aout_VisualNext( p_intf );
296 current->setText( qfu( psz_new ) );
302 /**********************************************************************
304 **********************************************************************/
306 #define setupSmallButton( aButton ){ \
307 aButton->setMaximumSize( QSize( 26, 26 ) ); \
308 aButton->setMinimumSize( QSize( 26, 26 ) ); \
309 aButton->setIconSize( QSize( 20, 20 ) ); }
311 /* init static variables in advanced controls */
312 mtime_t AdvControlsWidget::timeA = 0;
313 mtime_t AdvControlsWidget::timeB = 0;
315 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, bool b_fsCreation = false ) :
316 QFrame( NULL ), p_intf( _p_i )
318 QHBoxLayout *advLayout = new QHBoxLayout( this );
319 advLayout->setMargin( 0 );
320 advLayout->setSpacing( 0 );
321 advLayout->setAlignment( Qt::AlignBottom );
324 ABButton = new QPushButton;
325 setupSmallButton( ABButton );
326 advLayout->addWidget( ABButton );
327 BUTTON_SET_ACT_I( ABButton, "", atob_nob,
328 qtr( "Loop from point A to point B continuously.\nClick to set point A" ),
332 /* in FS controller we skip this, because we dont want to have it double
335 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
336 this, AtoBLoop( float, int, int ) );
337 /* set up synchronization between main controller and fs controller */
338 CONNECT( THEMIM->getIM(), advControlsSetIcon(), this, setIcon() );
339 connect( this, SIGNAL( timeChanged() ),
340 THEMIM->getIM(), SIGNAL( advControlsSetIcon()));
342 frameButton = new QPushButton( "Fr" );
343 frameButton->setMaximumSize( QSize( 26, 26 ) );
344 frameButton->setIconSize( QSize( 20, 20 ) );
345 advLayout->addWidget( frameButton );
346 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by frame" ), frame() );
350 recordButton = new QPushButton;
351 setupSmallButton( recordButton );
352 advLayout->addWidget( recordButton );
353 BUTTON_SET_ACT_I( recordButton, "", record,
354 qtr( "Record" ), record() );
356 /* Snapshot Button */
357 snapshotButton = new QPushButton;
358 setupSmallButton( snapshotButton );
359 advLayout->addWidget( snapshotButton );
360 BUTTON_SET_ACT_I( snapshotButton, "", snapshot,
361 qtr( "Take a snapshot" ), snapshot() );
364 AdvControlsWidget::~AdvControlsWidget()
367 void AdvControlsWidget::enableInput( bool enable )
370 if( THEMIM->getInput() != NULL )
372 input_item_t *p_item = input_GetItem( THEMIM->getInput() );
373 i_input_id = p_item->i_id;
375 recordButton->setVisible( var_GetBool( THEMIM->getInput(), "can-record" ) );
379 recordButton->setVisible( false );
382 ABButton->setEnabled( enable );
383 recordButton->setEnabled( enable );
385 if( enable && ( i_last_input_id != i_input_id ) )
388 i_last_input_id = i_input_id;
393 void AdvControlsWidget::enableVideo( bool enable )
395 snapshotButton->setEnabled( enable );
397 frameButton->setEnabled( enable );
401 void AdvControlsWidget::snapshot()
403 vout_thread_t *p_vout =
404 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
405 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
408 /* Function called when the button is clicked() */
409 void AdvControlsWidget::fromAtoB()
413 timeA = var_GetTime( THEMIM->getInput(), "time" );
419 timeB = var_GetTime( THEMIM->getInput(), "time" );
420 var_SetTime( THEMIM->getInput(), "time" , timeA );
429 /* setting/synchro icons after click on main or fs controller */
430 void AdvControlsWidget::setIcon()
432 if( !timeA && !timeB)
434 ABButton->setIcon( QIcon( ":/atob_nob" ) );
435 ABButton->setToolTip( qtr( "Loop from point A to point B continuously\nClick to set point A" ) );
437 else if( timeA && !timeB )
439 ABButton->setIcon( QIcon( ":/atob_noa" ) );
440 ABButton->setToolTip( qtr( "Click to set point B" ) );
442 else if( timeA && timeB )
444 ABButton->setIcon( QIcon( ":/atob" ) );
445 ABButton->setToolTip( qtr( "Stop the A to B loop" ) );
449 /* Function called regularly when in an AtoB loop */
450 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
454 if( ( i_time >= (int)( timeB/1000000 ) )
455 || ( i_time < (int)( timeA/1000000 ) ) )
456 var_SetTime( THEMIM->getInput(), "time" , timeA );
460 void AdvControlsWidget::record()
462 input_thread_t *p_input = THEMIM->getInput();
465 /* This method won't work fine if the stream can't be cut anywhere */
466 const bool b_recording = var_GetBool( p_input, "record" );
467 var_SetBool( p_input, "record", !b_recording );
471 /* 'record' access-filter is not loaded, we open Save dialog */
472 input_item_t *p_item = input_GetItem( p_input );
476 char *psz = input_item_GetURI( p_item );
478 THEDP->streamingDialog( NULL, psz, true );
485 //FIXME Frame by frame function
486 void AdvControlsWidget::frame(){}
489 /*****************************
490 * DA Control Widget !
491 *****************************/
492 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
493 MainInterface *_p_mi,
497 QFrame( _p_mi ), p_intf( _p_i )
499 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
501 /** The main Slider **/
502 slider = new InputSlider( Qt::Horizontal, NULL );
503 /* Update the position when the IM has changed */
504 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
505 slider, setPosition( float, int, int ) );
506 /* And update the IM, when the position has changed */
507 CONNECT( slider, sliderDragged( float ),
508 THEMIM->getIM(), sliderUpdate( float ) );
510 /** Slower and faster Buttons **/
511 slowerButton = new QToolButton;
512 slowerButton->setAutoRaise( true );
513 slowerButton->setMaximumSize( QSize( 26, 20 ) );
515 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
517 fasterButton = new QToolButton;
518 fasterButton->setAutoRaise( true );
519 fasterButton->setMaximumSize( QSize( 26, 20 ) );
521 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
523 /* advanced Controls handling */
524 b_advancedVisible = b_advControls;
526 advControls = new AdvControlsWidget( p_intf, b_fsCreation );
527 if( !b_advancedVisible ) advControls->hide();
529 /** Disc and Menus handling */
530 discFrame = new QWidget( this );
532 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
533 discLayout->setSpacing( 0 );
534 discLayout->setMargin( 0 );
536 prevSectionButton = new QPushButton( discFrame );
537 setupSmallButton( prevSectionButton );
538 discLayout->addWidget( prevSectionButton );
540 menuButton = new QPushButton( discFrame );
541 setupSmallButton( menuButton );
542 discLayout->addWidget( menuButton );
544 nextSectionButton = new QPushButton( discFrame );
545 setupSmallButton( nextSectionButton );
546 discLayout->addWidget( nextSectionButton );
548 BUTTON_SET_IMG( prevSectionButton, "", dvd_prev, "" );
549 BUTTON_SET_IMG( nextSectionButton, "", dvd_next, "" );
550 BUTTON_SET_IMG( menuButton, "", dvd_menu, qtr( "Menu" ) );
554 /* Change the navigation button display when the IM navigation changes */
555 CONNECT( THEMIM->getIM(), navigationChanged( int ),
556 this, setNavigation( int ) );
557 /* Changes the IM navigation when triggered on the nav buttons */
558 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
560 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
562 CONNECT( menuButton, clicked(), THEMIM->getIM(),
567 * TODO: Merge with upper menu in a StackLayout
569 telexFrame = new QWidget( this );
570 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
571 telexLayout->setSpacing( 0 );
572 telexLayout->setMargin( 0 );
574 telexOn = new QPushButton;
575 setupSmallButton( telexOn );
576 telexLayout->addWidget( telexOn );
578 telexTransparent = new QPushButton;
579 setupSmallButton( telexTransparent );
580 telexLayout->addWidget( telexTransparent );
581 b_telexTransparent = false;
583 telexPage = new QSpinBox;
584 telexPage->setRange( 0, 999 );
585 telexPage->setValue( 100 );
586 telexPage->setAccelerated( true );
587 telexPage->setWrapping( true );
588 telexPage->setAlignment( Qt::AlignRight );
589 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
590 telexLayout->addWidget( telexPage );
592 telexFrame->hide(); /* default hidden */
594 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
595 telexGotoPage( int ) );
596 CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
597 telexPage, setValue( int ) );
599 BUTTON_SET_IMG( telexOn, "", tv, qtr( "Teletext on" ) );
601 CONNECT( telexOn, clicked(), THEMIM->getIM(),
602 telexToggleButtons() );
603 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
604 telexToggle( bool ) );
605 CONNECT( THEMIM->getIM(), toggleTelexButtons(),
606 this, toggleTeletext() );
607 b_telexEnabled = false;
608 telexTransparent->setEnabled( false );
609 telexPage->setEnabled( false );
611 BUTTON_SET_IMG( telexTransparent, "", tvtelx, qtr( "Teletext" ) );
612 CONNECT( telexTransparent, clicked( bool ),
613 THEMIM->getIM(), telexSetTransparency() );
614 CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
615 this, toggleTeletextTransparency() );
616 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
617 this, enableTeletext( bool ) );
620 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
621 sizePolicy.setHorizontalStretch( 0 );
622 sizePolicy.setVerticalStretch( 0 );
625 playButton = new QPushButton;
626 playButton->setSizePolicy( sizePolicy );
627 playButton->setMaximumSize( QSize( 36, 36 ) );
628 playButton->setMinimumSize( QSize( 36, 36 ) );
629 playButton->setIconSize( QSize( 30, 30 ) );
632 /** Prev + Stop + Next Block **/
633 controlButLayout = new QHBoxLayout;
634 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
637 QPushButton *prevButton = new QPushButton;
638 prevButton->setSizePolicy( sizePolicy );
639 setupSmallButton( prevButton );
641 controlButLayout->addWidget( prevButton );
644 QPushButton *stopButton = new QPushButton;
645 stopButton->setSizePolicy( sizePolicy );
646 setupSmallButton( stopButton );
648 controlButLayout->addWidget( stopButton );
651 QPushButton *nextButton = new QPushButton;
652 nextButton->setSizePolicy( sizePolicy );
653 setupSmallButton( nextButton );
655 controlButLayout->addWidget( nextButton );
657 /* Add this block to the main layout */
659 BUTTON_SET_ACT_I( playButton, "", play_b, qtr( I_PLAY_TOOLTIP ), play() );
660 BUTTON_SET_ACT_I( prevButton, "" , previous_b,
661 qtr( "Previous media in the playlist" ), prev() );
662 BUTTON_SET_ACT_I( nextButton, "", next_b,
663 qtr( "Next media in the playlist" ), next() );
664 BUTTON_SET_ACT_I( stopButton, "", stop_b, qtr( "Stop playback" ), stop() );
667 * Other first Line buttons
669 /** Fullscreen/Visualisation **/
670 fullscreenButton = new QPushButton;
671 BUTTON_SET_ACT_I( fullscreenButton, "", fullscreen,
672 qtr( "Toggle the video in fullscreen" ), fullscreen() );
673 setupSmallButton( fullscreenButton );
677 /** Playlist Button **/
678 playlistButton = new QPushButton;
679 setupSmallButton( playlistButton );
680 BUTTON_SET_IMG( playlistButton, "" , playlist, qtr( "Show playlist" ) );
681 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
683 /** extended Settings **/
684 extSettingsButton = new QPushButton;
685 BUTTON_SET_ACT_I( extSettingsButton, "", extended,
686 qtr( "Show extended settings" ), extSettings() );
687 setupSmallButton( extSettingsButton );
691 hVolLabel = new VolumeClickHandler( p_intf, this );
693 volMuteLabel = new QLabel;
694 volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
695 volMuteLabel->installEventFilter( hVolLabel );
699 volumeSlider = new SoundSlider( this,
700 config_GetInt( p_intf, "volume-step" ),
701 config_GetInt( p_intf, "qt-volume-complete" ),
702 config_GetPsz( p_intf, "qt-slider-colours" ) );
706 volumeSlider = new QSlider( this );
707 volumeSlider->setOrientation( Qt::Horizontal );
709 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
710 volumeSlider->setMinimumSize( QSize( 85, 30 ) );
711 volumeSlider->setFocusPolicy( Qt::NoFocus );
713 /* Set the volume from the config */
714 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
715 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
717 /* Force the update at build time in order to have a muted icon if needed */
718 updateVolume( volumeSlider->value() );
720 /* Volume control connection */
721 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
722 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
726 controlLayout = new QGridLayout( this );
728 controlLayout->setSpacing( 0 );
729 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
731 controlLayout->addWidget( slider, 0, 1, 1, 18 );
732 controlLayout->addWidget( slowerButton, 0, 0 );
733 controlLayout->addWidget( fasterButton, 0, 19 );
735 controlLayout->addWidget( discFrame, 1, 8, 2, 3, Qt::AlignBottom );
736 controlLayout->addWidget( telexFrame, 1, 8, 2, 5, Qt::AlignBottom );
738 controlLayout->addWidget( playButton, 2, 0, 2, 2, Qt::AlignBottom );
739 controlLayout->setColumnMinimumWidth( 2, 10 );
740 controlLayout->setColumnStretch( 2, 0 );
742 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
743 /* Column 6 is unused */
744 controlLayout->setColumnStretch( 6, 0 );
745 controlLayout->setColumnStretch( 7, 0 );
746 controlLayout->setColumnMinimumWidth( 7, 10 );
748 controlLayout->addWidget( fullscreenButton, 3, 8, Qt::AlignBottom );
749 controlLayout->addWidget( playlistButton, 3, 9, Qt::AlignBottom );
750 controlLayout->addWidget( extSettingsButton, 3, 10, Qt::AlignBottom );
751 controlLayout->setColumnStretch( 11, 0 ); /* telex alignment */
753 controlLayout->setColumnStretch( 12, 0 );
754 controlLayout->setColumnMinimumWidth( 12, 10 );
756 controlLayout->addWidget( advControls, 3, 13, 1, 3, Qt::AlignBottom );
758 controlLayout->setColumnStretch( 16, 10 );
759 controlLayout->setColumnMinimumWidth( 16, 10 );
761 controlLayout->addWidget( volMuteLabel, 3, 17, Qt::AlignBottom );
762 controlLayout->addWidget( volumeSlider, 3, 18, 1 , 2, Qt::AlignBottom );
768 ControlsWidget::~ControlsWidget()
771 void ControlsWidget::toggleTeletext()
773 bool b_enabled = THEMIM->teletextState();
776 telexTransparent->setEnabled( false );
777 telexPage->setEnabled( false );
778 b_telexEnabled = false;
782 telexTransparent->setEnabled( true );
783 telexPage->setEnabled( true );
784 b_telexEnabled = true;
788 void ControlsWidget::enableTeletext( bool b_enable )
790 telexFrame->setVisible( b_enable );
791 bool b_on = THEMIM->teletextState();
793 telexOn->setChecked( b_on );
794 telexTransparent->setEnabled( b_on );
795 telexPage->setEnabled( b_on );
796 b_telexEnabled = b_on;
799 void ControlsWidget::toggleTeletextTransparency()
801 if( b_telexTransparent )
803 telexTransparent->setIcon( QIcon( ":/tvtelx" ) );
804 telexTransparent->setToolTip( qtr( "Teletext" ) );
805 b_telexTransparent = false;
809 telexTransparent->setIcon( QIcon( ":/tvtelx-transparent" ) );
810 telexTransparent->setToolTip( qtr( "Transparent" ) );
811 b_telexTransparent = true;
815 void ControlsWidget::stop()
820 void ControlsWidget::play()
822 if( THEPL->current.i_size == 0 )
824 /* The playlist is empty, open a file requester */
825 THEDP->openFileDialog();
829 THEMIM->togglePlayPause();
832 void ControlsWidget::prev()
837 void ControlsWidget::next()
842 void ControlsWidget::setNavigation( int navigation )
844 #define HELP_PCH N_( "Previous chapter" )
845 #define HELP_NCH N_( "Next chapter" )
847 // 1 = chapter, 2 = title, 0 = no
848 if( navigation == 0 )
851 } else if( navigation == 1 ) {
852 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
853 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
857 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
858 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
864 static bool b_my_volume;
865 void ControlsWidget::updateVolume( int i_sliderVolume )
869 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
870 aout_VolumeSet( p_intf, i_res );
872 if( i_sliderVolume == 0 )
874 volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
875 volMuteLabel->setToolTip( qtr( "Unmute" ) );
879 if( i_sliderVolume < VOLUME_MAX / 3 )
880 volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
881 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
882 volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
883 else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
884 volMuteLabel->setToolTip( qtr( "Mute" ) );
887 void ControlsWidget::updateVolume()
890 audio_volume_t i_volume;
891 aout_VolumeGet( p_intf, &i_volume );
892 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
893 int i_gauge = volumeSlider->value();
895 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
898 volumeSlider->setValue( i_volume );
903 void ControlsWidget::updateInput()
905 /* Activate the interface buttons according to the presence of the input */
906 enableInput( THEMIM->getIM()->hasInput() );
907 enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
910 void ControlsWidget::setStatus( int status )
912 if( status == PLAYING_S ) /* Playing */
914 playButton->setIcon( QIcon( ":/pause_b" ) );
915 playButton->setToolTip( qtr( "Pause the playback" ) );
919 playButton->setIcon( QIcon( ":/play_b" ) );
920 playButton->setToolTip( qtr( I_PLAY_TOOLTIP ) );
926 * This functions toggle the fullscreen mode
927 * If there is no video, it should first activate Visualisations...
928 * This has also to be fixed in enableVideo()
930 void ControlsWidget::fullscreen()
932 vout_thread_t *p_vout =
933 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
936 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
937 vlc_object_release( p_vout );
941 void ControlsWidget::extSettings()
943 THEDP->extendedDialog();
946 void ControlsWidget::slower()
948 THEMIM->getIM()->slower();
951 void ControlsWidget::faster()
953 THEMIM->getIM()->faster();
956 void ControlsWidget::enableInput( bool enable )
958 slowerButton->setEnabled( enable );
959 slider->setEnabled( enable );
960 slider->setSliderPosition ( 0 );
961 fasterButton->setEnabled( enable );
963 /* Advanced Buttons too */
964 advControls->enableInput( enable );
967 void ControlsWidget::enableVideo( bool enable )
969 // TODO Later make the fullscreenButton toggle Visualisation and so on.
970 fullscreenButton->setEnabled( enable );
972 /* Advanced Buttons too */
973 advControls->enableVideo( enable );
976 void ControlsWidget::toggleAdvanced()
978 if( advControls && !b_advancedVisible )
981 b_advancedVisible = true;
986 b_advancedVisible = false;
988 emit advancedControlsToggled( b_advancedVisible );
992 /**********************************************************************
993 * Fullscrenn control widget
994 **********************************************************************/
995 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
996 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
997 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
998 i_mouse_last_x( -1 ), i_mouse_last_y( -1 ), b_mouse_over(false),
999 b_slow_hide_begin(false), i_slow_hide_timeout(1),
1000 b_fullscreen( false ), i_hide_timeout( 1 ), p_vout(NULL)
1002 setWindowFlags( Qt::ToolTip );
1004 setFrameShape( QFrame::StyledPanel );
1005 setFrameStyle( QFrame::Sunken );
1006 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
1008 QGridLayout *fsLayout = new QGridLayout( this );
1009 fsLayout->setLayoutMargins( 5, 2, 5, 2, 5 );
1012 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
1013 slider->setMinimumWidth( 220 );
1014 fsLayout->addWidget( slowerButton, 0, 0 );
1015 fsLayout->addWidget( slider, 0, 1, 1, 9 );
1016 fsLayout->addWidget( fasterButton, 0, 10 );
1018 fsLayout->addWidget( playButton, 1, 0, 1, 2 );
1019 fsLayout->addLayout( controlButLayout, 1, 2 );
1021 fsLayout->addWidget( discFrame, 1, 3 );
1022 fsLayout->addWidget( telexFrame, 1, 4 );
1023 fsLayout->addWidget( fullscreenButton, 1, 5 );
1024 fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
1026 fsLayout->setColumnStretch( 7, 10 );
1027 fsLayout->addWidget( volMuteLabel, 1, 8 );
1028 fsLayout->addWidget( volumeSlider, 1, 9, 1, 2 );
1031 p_hideTimer = new QTimer( this );
1032 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
1033 p_hideTimer->setSingleShot( true );
1035 /* slow hiding timer */
1036 #if HAVE_TRANSPARENCY
1037 p_slowHideTimer = new QTimer( this );
1038 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
1041 adjustSize (); /* need to get real width and height for moving */
1044 QDesktopWidget * p_desktop = QApplication::desktop();
1046 move( p_desktop->width() / 2 - width() / 2,
1047 p_desktop->height() - height() );
1050 setWindowOpacity( 0.0 );
1056 fullscreenButton->setIcon( QIcon( ":/defullscreen" ) );
1058 vlc_mutex_init_recursive( &lock );
1061 FullscreenControllerWidget::~FullscreenControllerWidget()
1064 vlc_mutex_destroy( &lock );
1068 * Show fullscreen controller
1070 void FullscreenControllerWidget::showFSC()
1074 // after quiting and going to fs, we need to call show()
1080 b_fscHidden = false;
1081 setWindowOpacity( 1.0 );
1087 #if HAVE_TRANSPARENCY
1088 setWindowOpacity( DEFAULT_OPACITY );
1093 * Hide fullscreen controller
1094 * FIXME: under windows it have to be done by moving out of screen
1095 * because hide() doesnt work
1097 void FullscreenControllerWidget::hideFSC()
1101 setWindowOpacity( 0.0 ); // simulate hidding
1108 * Plane to hide fullscreen controller
1110 void FullscreenControllerWidget::planHideFSC()
1112 vlc_mutex_lock( &lock );
1113 int i_timeout = i_hide_timeout;
1114 vlc_mutex_unlock( &lock );
1116 p_hideTimer->start( i_timeout );
1118 #if HAVE_TRANSPARENCY
1119 b_slow_hide_begin = true;
1120 i_slow_hide_timeout = i_timeout;
1121 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
1126 * Hidding fullscreen controller slowly
1127 * Linux: need composite manager
1128 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
1130 void FullscreenControllerWidget::slowHideFSC()
1132 #if HAVE_TRANSPARENCY
1133 if( b_slow_hide_begin )
1135 b_slow_hide_begin = false;
1137 p_slowHideTimer->stop();
1138 /* the last part of time divided to 100 pieces */
1139 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
1145 if ( windowOpacity() > 0.0 && !b_fscHidden )
1147 if ( windowOpacity() > 0.0 )
1150 /* we should use 0.01 because of 100 pieces ^^^
1151 but than it cannt be done in time */
1152 setWindowOpacity( windowOpacity() - 0.02 );
1155 if ( windowOpacity() <= 0.0 )
1156 p_slowHideTimer->stop();
1163 * events: show, hide, start timer for hidding
1165 void FullscreenControllerWidget::customEvent( QEvent *event )
1169 switch( event->type() )
1171 case FullscreenControlToggle_Type:
1172 vlc_mutex_lock( &lock );
1173 b_fs = b_fullscreen;
1174 vlc_mutex_unlock( &lock );
1182 p_hideTimer->stop();
1188 case FullscreenControlShow_Type:
1189 vlc_mutex_lock( &lock );
1190 b_fs = b_fullscreen;
1191 vlc_mutex_unlock( &lock );
1193 if( b_fs ) // FIXME I am not sure about that one
1196 case FullscreenControlHide_Type:
1199 case FullscreenControlPlanHide_Type:
1200 if( !b_mouse_over ) // Only if the mouse is not over FSC
1210 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1212 if ( event->buttons() == Qt::LeftButton )
1214 int i_moveX = event->globalX() - i_mouse_last_x;
1215 int i_moveY = event->globalY() - i_mouse_last_y;
1217 move( x() + i_moveX, y() + i_moveY );
1219 i_mouse_last_x = event->globalX();
1220 i_mouse_last_y = event->globalY();
1226 * store position of cursor
1228 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1230 i_mouse_last_x = event->globalX();
1231 i_mouse_last_y = event->globalY();
1235 * On mouse go above FSC
1237 void FullscreenControllerWidget::enterEvent( QEvent *event )
1239 b_mouse_over = true;
1241 p_hideTimer->stop();
1242 #if HAVE_TRANSPARENCY
1243 p_slowHideTimer->stop();
1248 * On mouse go out from FSC
1250 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1254 b_mouse_over = false;
1258 * When you get pressed key, send it to video output
1259 * FIXME: clearing focus by clearFocus() to not getting
1260 * key press events didnt work
1262 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1264 int i_vlck = qtEventToVLCKey( event );
1267 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1275 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object, const char *variable,
1276 vlc_value_t old_val, vlc_value_t new_val,
1279 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1280 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1282 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1287 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1288 vlc_value_t old_val, vlc_value_t new_val,
1291 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1294 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1295 QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1297 /* Plan hide event */
1298 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1299 QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1306 * It is called when video start
1308 void FullscreenControllerWidget::attachVout( vout_thread_t *p_nvout )
1310 assert( p_nvout && !p_vout );
1314 vlc_mutex_lock( &lock );
1315 var_AddCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this ); /* I miss a add and fire */
1316 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ), var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1317 vlc_mutex_unlock( &lock );
1320 * It is called after turn off video.
1322 void FullscreenControllerWidget::detachVout()
1326 var_DelCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this );
1327 vlc_mutex_lock( &lock );
1328 fullscreenChanged( p_vout, false, 0 );
1329 vlc_mutex_unlock( &lock );
1335 * Register and unregister callback for mouse moving
1337 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout, bool b_fs, int i_timeout )
1339 vlc_mutex_lock( &lock );
1340 if( b_fs && !b_fullscreen )
1342 b_fullscreen = true;
1343 i_hide_timeout = i_timeout;
1344 var_AddCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1346 else if( !b_fs && b_fullscreen )
1348 b_fullscreen = false;
1349 i_hide_timeout = i_timeout;
1350 var_DelCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1352 /* Force fs hidding */
1353 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1354 QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1356 vlc_mutex_unlock( &lock );
1359 /**********************************************************************
1360 * Speed control widget
1361 **********************************************************************/
1362 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1363 QFrame( NULL ), p_intf( _p_i )
1365 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1366 sizePolicy.setHorizontalStretch( 0 );
1367 sizePolicy.setVerticalStretch( 0 );
1369 speedSlider = new QSlider;
1370 speedSlider->setSizePolicy( sizePolicy );
1371 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1372 speedSlider->setOrientation( Qt::Vertical );
1373 speedSlider->setTickPosition( QSlider::TicksRight );
1375 speedSlider->setRange( -24, 24 );
1376 speedSlider->setSingleStep( 1 );
1377 speedSlider->setPageStep( 1 );
1378 speedSlider->setTickInterval( 12 );
1380 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1382 QToolButton *normalSpeedButton = new QToolButton( this );
1383 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1384 normalSpeedButton->setAutoRaise( true );
1385 normalSpeedButton->setText( "1x" );
1386 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1388 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1390 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1391 speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
1392 speedControlLayout->setSpacing( 4 );
1393 speedControlLayout->addWidget( speedSlider );
1394 speedControlLayout->addWidget( normalSpeedButton );
1395 setLayout( speedControlLayout );
1398 SpeedControlWidget::~SpeedControlWidget()
1401 void SpeedControlWidget::setEnable( bool b_enable )
1403 speedSlider->setEnabled( b_enable );
1406 void SpeedControlWidget::updateControls( int rate )
1408 if( speedSlider->isSliderDown() )
1410 //We don't want to change anything if the user is using the slider
1414 double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
1415 int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
1417 if( sliderValue < speedSlider->minimum() )
1419 sliderValue = speedSlider->minimum();
1421 else if( sliderValue > speedSlider->maximum() )
1423 sliderValue = speedSlider->maximum();
1426 //Block signals to avoid feedback loop
1427 speedSlider->blockSignals( true );
1428 speedSlider->setValue( sliderValue );
1429 speedSlider->blockSignals( false );
1432 void SpeedControlWidget::updateRate( int sliderValue )
1434 double speed = pow( 2, (double)sliderValue / 12 );
1435 int rate = INPUT_RATE_DEFAULT / speed;
1437 THEMIM->getIM()->setRate(rate);
1440 void SpeedControlWidget::resetRate()
1442 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);