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 64
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 if( var_Type( THEMIM->getInput(), "record-toggle" ) == VLC_VAR_VOID )
376 recordButton->setVisible( true );
378 recordButton->setVisible( false );
381 recordButton->setVisible( false );
383 ABButton->setEnabled( enable );
384 recordButton->setEnabled( enable );
386 if( enable && ( i_last_input_id != i_input_id ) )
389 i_last_input_id = i_input_id;
394 void AdvControlsWidget::enableVideo( bool enable )
396 snapshotButton->setEnabled( enable );
398 frameButton->setEnabled( enable );
402 void AdvControlsWidget::snapshot()
404 vout_thread_t *p_vout =
405 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
406 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
409 /* Function called when the button is clicked() */
410 void AdvControlsWidget::fromAtoB()
414 timeA = var_GetTime( THEMIM->getInput(), "time" );
420 timeB = var_GetTime( THEMIM->getInput(), "time" );
421 var_SetTime( THEMIM->getInput(), "time" , timeA );
430 /* setting/synchro icons after click on main or fs controller */
431 void AdvControlsWidget::setIcon()
433 if( !timeA && !timeB)
435 ABButton->setIcon( QIcon( ":/atob_nob" ) );
436 ABButton->setToolTip( qtr( "Loop from point A to point B continuously\nClick to set point A" ) );
438 else if( timeA && !timeB )
440 ABButton->setIcon( QIcon( ":/atob_noa" ) );
441 ABButton->setToolTip( qtr( "Click to set point B" ) );
443 else if( timeA && timeB )
445 ABButton->setIcon( QIcon( ":/atob" ) );
446 ABButton->setToolTip( qtr( "Stop the A to B loop" ) );
450 /* Function called regularly when in an AtoB loop */
451 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
455 if( ( i_time >= (int)( timeB/1000000 ) )
456 || ( i_time < (int)( timeA/1000000 ) ) )
457 var_SetTime( THEMIM->getInput(), "time" , timeA );
461 /* FIXME Record function */
462 void AdvControlsWidget::record()
464 input_thread_t *p_input = THEMIM->getInput();
467 /* This method won't work fine if the stream can't be cut anywhere */
468 if( var_Type( p_input, "record-toggle" ) == VLC_VAR_VOID )
469 var_TriggerCallback( p_input, "record-toggle" );
473 /* 'record' access-filter is not loaded, we open Save dialog */
474 input_item_t *p_item = input_GetItem( p_input );
478 char *psz = input_item_GetURI( p_item );
480 THEDP->streamingDialog( NULL, psz, true );
487 //FIXME Frame by frame function
488 void AdvControlsWidget::frame(){}
491 /*****************************
492 * DA Control Widget !
493 *****************************/
494 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
495 MainInterface *_p_mi,
499 QFrame( _p_mi ), p_intf( _p_i )
501 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
503 /** The main Slider **/
504 slider = new InputSlider( Qt::Horizontal, NULL );
505 /* Update the position when the IM has changed */
506 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
507 slider, setPosition( float, int, int ) );
508 /* And update the IM, when the position has changed */
509 CONNECT( slider, sliderDragged( float ),
510 THEMIM->getIM(), sliderUpdate( float ) );
512 /** Slower and faster Buttons **/
513 slowerButton = new QToolButton;
514 slowerButton->setAutoRaise( true );
515 slowerButton->setMaximumSize( QSize( 26, 20 ) );
517 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
519 fasterButton = new QToolButton;
520 fasterButton->setAutoRaise( true );
521 fasterButton->setMaximumSize( QSize( 26, 20 ) );
523 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
525 /* advanced Controls handling */
526 b_advancedVisible = b_advControls;
528 advControls = new AdvControlsWidget( p_intf, b_fsCreation );
529 if( !b_advancedVisible ) advControls->hide();
531 /** Disc and Menus handling */
532 discFrame = new QWidget( this );
534 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
535 discLayout->setSpacing( 0 );
536 discLayout->setMargin( 0 );
538 prevSectionButton = new QPushButton( discFrame );
539 setupSmallButton( prevSectionButton );
540 discLayout->addWidget( prevSectionButton );
542 menuButton = new QPushButton( discFrame );
543 setupSmallButton( menuButton );
544 discLayout->addWidget( menuButton );
546 nextSectionButton = new QPushButton( discFrame );
547 setupSmallButton( nextSectionButton );
548 discLayout->addWidget( nextSectionButton );
550 BUTTON_SET_IMG( prevSectionButton, "", dvd_prev, "" );
551 BUTTON_SET_IMG( nextSectionButton, "", dvd_next, "" );
552 BUTTON_SET_IMG( menuButton, "", dvd_menu, qtr( "Menu" ) );
556 /* Change the navigation button display when the IM navigation changes */
557 CONNECT( THEMIM->getIM(), navigationChanged( int ),
558 this, setNavigation( int ) );
559 /* Changes the IM navigation when triggered on the nav buttons */
560 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
562 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
564 CONNECT( menuButton, clicked(), THEMIM->getIM(),
569 * TODO: Merge with upper menu in a StackLayout
571 telexFrame = new QWidget( this );
572 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
573 telexLayout->setSpacing( 0 );
574 telexLayout->setMargin( 0 );
576 telexOn = new QPushButton;
577 setupSmallButton( telexOn );
578 telexLayout->addWidget( telexOn );
580 telexTransparent = new QPushButton;
581 setupSmallButton( telexTransparent );
582 telexLayout->addWidget( telexTransparent );
583 b_telexTransparent = false;
585 telexPage = new QSpinBox;
586 telexPage->setRange( 0, 999 );
587 telexPage->setValue( 100 );
588 telexPage->setAccelerated( true );
589 telexPage->setWrapping( true );
590 telexPage->setAlignment( Qt::AlignRight );
591 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
592 telexLayout->addWidget( telexPage );
594 telexFrame->hide(); /* default hidden */
596 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
597 telexGotoPage( int ) );
598 CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
599 telexPage, setValue( int ) );
601 BUTTON_SET_IMG( telexOn, "", tv, qtr( "Teletext on" ) );
603 CONNECT( telexOn, clicked(), THEMIM->getIM(),
604 telexToggleButtons() );
605 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
606 telexToggle( bool ) );
607 CONNECT( THEMIM->getIM(), toggleTelexButtons(),
608 this, toggleTeletext() );
609 b_telexEnabled = false;
610 telexTransparent->setEnabled( false );
611 telexPage->setEnabled( false );
613 BUTTON_SET_IMG( telexTransparent, "", tvtelx, qtr( "Teletext" ) );
614 CONNECT( telexTransparent, clicked( bool ),
615 THEMIM->getIM(), telexSetTransparency() );
616 CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
617 this, toggleTeletextTransparency() );
618 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
619 this, enableTeletext( bool ) );
622 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
623 sizePolicy.setHorizontalStretch( 0 );
624 sizePolicy.setVerticalStretch( 0 );
627 playButton = new QPushButton;
628 playButton->setSizePolicy( sizePolicy );
629 playButton->setMaximumSize( QSize( 36, 36 ) );
630 playButton->setMinimumSize( QSize( 36, 36 ) );
631 playButton->setIconSize( QSize( 30, 30 ) );
634 /** Prev + Stop + Next Block **/
635 controlButLayout = new QHBoxLayout;
636 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
639 QPushButton *prevButton = new QPushButton;
640 prevButton->setSizePolicy( sizePolicy );
641 setupSmallButton( prevButton );
643 controlButLayout->addWidget( prevButton );
646 QPushButton *stopButton = new QPushButton;
647 stopButton->setSizePolicy( sizePolicy );
648 setupSmallButton( stopButton );
650 controlButLayout->addWidget( stopButton );
653 QPushButton *nextButton = new QPushButton;
654 nextButton->setSizePolicy( sizePolicy );
655 setupSmallButton( nextButton );
657 controlButLayout->addWidget( nextButton );
659 /* Add this block to the main layout */
661 BUTTON_SET_ACT_I( playButton, "", play_b, qtr( I_PLAY_TOOLTIP ), play() );
662 BUTTON_SET_ACT_I( prevButton, "" , previous_b,
663 qtr( "Previous media in the playlist" ), prev() );
664 BUTTON_SET_ACT_I( nextButton, "", next_b,
665 qtr( "Next media in the playlist" ), next() );
666 BUTTON_SET_ACT_I( stopButton, "", stop_b, qtr( "Stop playback" ), stop() );
669 * Other first Line buttons
671 /** Fullscreen/Visualisation **/
672 fullscreenButton = new QPushButton;
673 BUTTON_SET_ACT_I( fullscreenButton, "", fullscreen,
674 qtr( "Toggle the video in fullscreen" ), fullscreen() );
675 setupSmallButton( fullscreenButton );
679 /** Playlist Button **/
680 playlistButton = new QPushButton;
681 setupSmallButton( playlistButton );
682 BUTTON_SET_IMG( playlistButton, "" , playlist, qtr( "Show playlist" ) );
683 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
685 /** extended Settings **/
686 extSettingsButton = new QPushButton;
687 BUTTON_SET_ACT_I( extSettingsButton, "", extended,
688 qtr( "Show extended settings" ), extSettings() );
689 setupSmallButton( extSettingsButton );
693 hVolLabel = new VolumeClickHandler( p_intf, this );
695 volMuteLabel = new QLabel;
696 volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
697 volMuteLabel->installEventFilter( hVolLabel );
701 volumeSlider = new SoundSlider( this,
702 config_GetInt( p_intf, "volume-step" ),
703 config_GetInt( p_intf, "qt-volume-complete" ),
704 config_GetPsz( p_intf, "qt-slider-colours" ) );
708 volumeSlider = new QSlider( this );
709 volumeSlider->setOrientation( Qt::Horizontal );
711 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
712 volumeSlider->setMinimumSize( QSize( 85, 30 ) );
713 volumeSlider->setFocusPolicy( Qt::NoFocus );
715 /* Set the volume from the config */
716 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
717 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
719 /* Force the update at build time in order to have a muted icon if needed */
720 updateVolume( volumeSlider->value() );
722 /* Volume control connection */
723 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
724 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
728 controlLayout = new QGridLayout( this );
730 controlLayout->setSpacing( 0 );
731 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
733 controlLayout->addWidget( slider, 0, 1, 1, 18 );
734 controlLayout->addWidget( slowerButton, 0, 0 );
735 controlLayout->addWidget( fasterButton, 0, 19 );
737 controlLayout->addWidget( discFrame, 1, 8, 2, 3, Qt::AlignBottom );
738 controlLayout->addWidget( telexFrame, 1, 8, 2, 5, Qt::AlignBottom );
740 controlLayout->addWidget( playButton, 2, 0, 2, 2, Qt::AlignBottom );
741 controlLayout->setColumnMinimumWidth( 2, 10 );
742 controlLayout->setColumnStretch( 2, 0 );
744 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
745 /* Column 6 is unused */
746 controlLayout->setColumnStretch( 6, 0 );
747 controlLayout->setColumnStretch( 7, 0 );
748 controlLayout->setColumnMinimumWidth( 7, 10 );
750 controlLayout->addWidget( fullscreenButton, 3, 8, Qt::AlignBottom );
751 controlLayout->addWidget( playlistButton, 3, 9, Qt::AlignBottom );
752 controlLayout->addWidget( extSettingsButton, 3, 10, Qt::AlignBottom );
753 controlLayout->setColumnStretch( 11, 0 ); /* telex alignment */
755 controlLayout->setColumnStretch( 12, 0 );
756 controlLayout->setColumnMinimumWidth( 12, 10 );
758 controlLayout->addWidget( advControls, 3, 13, 1, 3, Qt::AlignBottom );
760 controlLayout->setColumnStretch( 16, 10 );
761 controlLayout->setColumnMinimumWidth( 16, 10 );
763 controlLayout->addWidget( volMuteLabel, 3, 17, Qt::AlignBottom );
764 controlLayout->addWidget( volumeSlider, 3, 18, 1 , 2, Qt::AlignBottom );
770 ControlsWidget::~ControlsWidget()
773 void ControlsWidget::toggleTeletext()
775 bool b_enabled = THEMIM->teletextState();
778 telexTransparent->setEnabled( false );
779 telexPage->setEnabled( false );
780 b_telexEnabled = false;
784 telexTransparent->setEnabled( true );
785 telexPage->setEnabled( true );
786 b_telexEnabled = true;
790 void ControlsWidget::enableTeletext( bool b_enable )
792 telexFrame->setVisible( b_enable );
793 bool b_on = THEMIM->teletextState();
795 telexOn->setChecked( b_on );
796 telexTransparent->setEnabled( b_on );
797 telexPage->setEnabled( b_on );
798 b_telexEnabled = b_on;
801 void ControlsWidget::toggleTeletextTransparency()
803 if( b_telexTransparent )
805 telexTransparent->setIcon( QIcon( ":/tvtelx" ) );
806 telexTransparent->setToolTip( qtr( "Teletext" ) );
807 b_telexTransparent = false;
811 telexTransparent->setIcon( QIcon( ":/tvtelx-transparent" ) );
812 telexTransparent->setToolTip( qtr( "Transparent" ) );
813 b_telexTransparent = true;
817 void ControlsWidget::stop()
822 void ControlsWidget::play()
824 if( THEPL->current.i_size == 0 )
826 /* The playlist is empty, open a file requester */
827 THEDP->openFileDialog();
831 THEMIM->togglePlayPause();
834 void ControlsWidget::prev()
839 void ControlsWidget::next()
844 void ControlsWidget::setNavigation( int navigation )
846 #define HELP_PCH N_( "Previous chapter" )
847 #define HELP_NCH N_( "Next chapter" )
849 // 1 = chapter, 2 = title, 0 = no
850 if( navigation == 0 )
853 } else if( navigation == 1 ) {
854 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
855 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
859 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
860 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
866 static bool b_my_volume;
867 void ControlsWidget::updateVolume( int i_sliderVolume )
871 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
872 aout_VolumeSet( p_intf, i_res );
874 if( i_sliderVolume == 0 )
876 volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
877 volMuteLabel->setToolTip( qtr( "Unmute" ) );
881 if( i_sliderVolume < VOLUME_MAX / 3 )
882 volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
883 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
884 volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
885 else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
886 volMuteLabel->setToolTip( qtr( "Mute" ) );
889 void ControlsWidget::updateVolume()
892 audio_volume_t i_volume;
893 aout_VolumeGet( p_intf, &i_volume );
894 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
895 int i_gauge = volumeSlider->value();
897 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
900 volumeSlider->setValue( i_volume );
905 void ControlsWidget::updateInput()
907 /* Activate the interface buttons according to the presence of the input */
908 enableInput( THEMIM->getIM()->hasInput() );
909 enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
912 void ControlsWidget::setStatus( int status )
914 if( status == PLAYING_S ) /* Playing */
916 playButton->setIcon( QIcon( ":/pause_b" ) );
917 playButton->setToolTip( qtr( "Pause the playback" ) );
921 playButton->setIcon( QIcon( ":/play_b" ) );
922 playButton->setToolTip( qtr( I_PLAY_TOOLTIP ) );
928 * This functions toggle the fullscreen mode
929 * If there is no video, it should first activate Visualisations...
930 * This has also to be fixed in enableVideo()
932 void ControlsWidget::fullscreen()
934 vout_thread_t *p_vout =
935 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
938 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
939 vlc_object_release( p_vout );
943 void ControlsWidget::extSettings()
945 THEDP->extendedDialog();
948 void ControlsWidget::slower()
950 THEMIM->getIM()->slower();
953 void ControlsWidget::faster()
955 THEMIM->getIM()->faster();
958 void ControlsWidget::enableInput( bool enable )
960 slowerButton->setEnabled( enable );
961 slider->setEnabled( enable );
962 slider->setSliderPosition ( 0 );
963 fasterButton->setEnabled( enable );
965 /* Advanced Buttons too */
966 advControls->enableInput( enable );
969 void ControlsWidget::enableVideo( bool enable )
971 // TODO Later make the fullscreenButton toggle Visualisation and so on.
972 fullscreenButton->setEnabled( enable );
974 /* Advanced Buttons too */
975 advControls->enableVideo( enable );
978 void ControlsWidget::toggleAdvanced()
980 if( advControls && !b_advancedVisible )
983 b_advancedVisible = true;
988 b_advancedVisible = false;
990 emit advancedControlsToggled( b_advancedVisible );
994 /**********************************************************************
995 * Fullscrenn control widget
996 **********************************************************************/
997 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
998 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
999 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
1000 i_mouse_last_x( -1 ), i_mouse_last_y( -1 ), b_mouse_over(false),
1001 b_slow_hide_begin(false), i_slow_hide_timeout(1),
1002 b_fullscreen( false ), i_hide_timeout( 1 ), p_vout(NULL)
1004 setWindowFlags( Qt::ToolTip );
1006 setFrameShape( QFrame::StyledPanel );
1007 setFrameStyle( QFrame::Sunken );
1008 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
1010 QGridLayout *fsLayout = new QGridLayout( this );
1011 fsLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
1014 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
1015 fsLayout->addWidget( slowerButton, 0, 0 );
1016 fsLayout->addWidget( slider, 0, 1, 1, 8 );
1017 fsLayout->addWidget( fasterButton, 0, 9 );
1019 fsLayout->addWidget( playButton, 1, 0, 1, 2 );
1020 fsLayout->addLayout( controlButLayout, 1, 2 );
1022 fsLayout->addWidget( discFrame, 1, 3 );
1023 fsLayout->addWidget( telexFrame, 1, 4 );
1024 fsLayout->addWidget( fullscreenButton, 1, 5 );
1025 fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
1027 fsLayout->addWidget( volMuteLabel, 1, 7 );
1028 fsLayout->addWidget( volumeSlider, 1, 8, 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);