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 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 );
242 /**********************************************************************
243 * Visualization selector panel
244 **********************************************************************/
245 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
246 QFrame( NULL ), p_intf( _p_i )
248 QHBoxLayout *layout = new QHBoxLayout( this );
249 layout->setMargin( 0 );
250 QPushButton *prevButton = new QPushButton( "Prev" );
251 QPushButton *nextButton = new QPushButton( "Next" );
252 layout->addWidget( prevButton );
253 layout->addWidget( nextButton );
255 layout->addStretch( 10 );
256 layout->addWidget( new QLabel( qtr( "Current visualization" ) ) );
258 current = new QLabel( qtr( "None" ) );
259 layout->addWidget( current );
261 BUTTONACT( prevButton, prev() );
262 BUTTONACT( nextButton, next() );
265 setMaximumHeight( 35 );
268 VisualSelector::~VisualSelector()
271 void VisualSelector::prev()
273 char *psz_new = aout_VisualPrev( p_intf );
276 current->setText( qfu( psz_new ) );
281 void VisualSelector::next()
283 char *psz_new = aout_VisualNext( p_intf );
286 current->setText( qfu( psz_new ) );
292 /**********************************************************************
294 **********************************************************************/
296 #define setupSmallButton( aButton ){ \
297 aButton->setMaximumSize( QSize( 26, 26 ) ); \
298 aButton->setMinimumSize( QSize( 26, 26 ) ); \
299 aButton->setIconSize( QSize( 20, 20 ) ); }
301 /* init static variables in advanced controls */
302 mtime_t AdvControlsWidget::timeA = 0;
303 mtime_t AdvControlsWidget::timeB = 0;
305 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, bool b_fsCreation = false ) :
306 QFrame( NULL ), p_intf( _p_i )
308 QHBoxLayout *advLayout = new QHBoxLayout( this );
309 advLayout->setMargin( 0 );
310 advLayout->setSpacing( 0 );
311 advLayout->setAlignment( Qt::AlignBottom );
314 ABButton = new QPushButton;
315 setupSmallButton( ABButton );
316 advLayout->addWidget( ABButton );
317 BUTTON_SET_ACT_I( ABButton, "", atob_nob,
318 qtr( "Loop from point A to point B continuously.\nClick to set point A" ),
322 /* in FS controller we skip this, because we dont want to have it double
325 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
326 this, AtoBLoop( float, int, int ) );
327 /* set up synchronization between main controller and fs controller */
328 CONNECT( THEMIM->getIM(), advControlsSetIcon(), this, setIcon() );
329 connect( this, SIGNAL( timeChanged() ),
330 THEMIM->getIM(), SIGNAL( advControlsSetIcon()));
332 frameButton = new QPushButton( "Fr" );
333 frameButton->setMaximumSize( QSize( 26, 26 ) );
334 frameButton->setIconSize( QSize( 20, 20 ) );
335 advLayout->addWidget( frameButton );
336 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by frame" ), frame() );
340 recordButton = new QPushButton;
341 setupSmallButton( recordButton );
342 advLayout->addWidget( recordButton );
343 BUTTON_SET_ACT_I( recordButton, "", record,
344 qtr( "Record" ), record() );
346 /* Snapshot Button */
347 snapshotButton = new QPushButton;
348 setupSmallButton( snapshotButton );
349 advLayout->addWidget( snapshotButton );
350 BUTTON_SET_ACT_I( snapshotButton, "", snapshot,
351 qtr( "Take a snapshot" ), snapshot() );
354 AdvControlsWidget::~AdvControlsWidget()
357 void AdvControlsWidget::enableInput( bool enable )
360 if( THEMIM->getInput() != NULL )
362 input_item_t *p_item = input_GetItem( THEMIM->getInput() );
363 i_input_id = p_item->i_id;
365 if( var_Type( THEMIM->getInput(), "record-toggle" ) == VLC_VAR_VOID )
366 recordButton->setVisible( true );
368 recordButton->setVisible( false );
371 recordButton->setVisible( false );
373 ABButton->setEnabled( enable );
374 recordButton->setEnabled( enable );
376 if( enable && ( i_last_input_id != i_input_id ) )
379 i_last_input_id = i_input_id;
384 void AdvControlsWidget::enableVideo( bool enable )
386 snapshotButton->setEnabled( enable );
388 frameButton->setEnabled( enable );
392 void AdvControlsWidget::snapshot()
394 vout_thread_t *p_vout =
395 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
396 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
399 /* Function called when the button is clicked() */
400 void AdvControlsWidget::fromAtoB()
404 timeA = var_GetTime( THEMIM->getInput(), "time" );
410 timeB = var_GetTime( THEMIM->getInput(), "time" );
411 var_SetTime( THEMIM->getInput(), "time" , timeA );
420 /* setting/synchro icons after click on main or fs controller */
421 void AdvControlsWidget::setIcon()
423 if( !timeA && !timeB)
425 ABButton->setIcon( QIcon( ":/atob_nob" ) );
426 ABButton->setToolTip( qtr( "Loop from point A to point B continuously\nClick to set point A" ) );
428 else if( timeA && !timeB )
430 ABButton->setIcon( QIcon( ":/atob_noa" ) );
431 ABButton->setToolTip( qtr( "Click to set point B" ) );
433 else if( timeA && timeB )
435 ABButton->setIcon( QIcon( ":/atob" ) );
436 ABButton->setToolTip( qtr( "Stop the A to B loop" ) );
440 /* Function called regularly when in an AtoB loop */
441 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
445 if( ( i_time >= (int)( timeB/1000000 ) )
446 || ( i_time < (int)( timeA/1000000 ) ) )
447 var_SetTime( THEMIM->getInput(), "time" , timeA );
451 /* FIXME Record function */
452 void AdvControlsWidget::record()
454 input_thread_t *p_input = THEMIM->getInput();
457 /* This method won't work fine if the stream can't be cut anywhere */
458 if( var_Type( p_input, "record-toggle" ) == VLC_VAR_VOID )
459 var_TriggerCallback( p_input, "record-toggle" );
463 /* 'record' access-filter is not loaded, we open Save dialog */
464 input_item_t *p_item = input_GetItem( p_input );
468 char *psz = input_item_GetURI( p_item );
470 THEDP->streamingDialog( NULL, psz, true );
477 //FIXME Frame by frame function
478 void AdvControlsWidget::frame(){}
481 /*****************************
482 * DA Control Widget !
483 *****************************/
484 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
485 MainInterface *_p_mi,
489 QFrame( _p_mi ), p_intf( _p_i )
491 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
493 /** The main Slider **/
494 slider = new InputSlider( Qt::Horizontal, NULL );
495 /* Update the position when the IM has changed */
496 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
497 slider, setPosition( float, int, int ) );
498 /* And update the IM, when the position has changed */
499 CONNECT( slider, sliderDragged( float ),
500 THEMIM->getIM(), sliderUpdate( float ) );
502 /** Slower and faster Buttons **/
503 slowerButton = new QToolButton;
504 slowerButton->setAutoRaise( true );
505 slowerButton->setMaximumSize( QSize( 26, 20 ) );
507 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
509 fasterButton = new QToolButton;
510 fasterButton->setAutoRaise( true );
511 fasterButton->setMaximumSize( QSize( 26, 20 ) );
513 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
515 /* advanced Controls handling */
516 b_advancedVisible = b_advControls;
518 advControls = new AdvControlsWidget( p_intf, b_fsCreation );
519 if( !b_advancedVisible ) advControls->hide();
521 /** Disc and Menus handling */
522 discFrame = new QWidget( this );
524 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
525 discLayout->setSpacing( 0 );
526 discLayout->setMargin( 0 );
528 prevSectionButton = new QPushButton( discFrame );
529 setupSmallButton( prevSectionButton );
530 discLayout->addWidget( prevSectionButton );
532 menuButton = new QPushButton( discFrame );
533 setupSmallButton( menuButton );
534 discLayout->addWidget( menuButton );
536 nextSectionButton = new QPushButton( discFrame );
537 setupSmallButton( nextSectionButton );
538 discLayout->addWidget( nextSectionButton );
540 BUTTON_SET_IMG( prevSectionButton, "", dvd_prev, "" );
541 BUTTON_SET_IMG( nextSectionButton, "", dvd_next, "" );
542 BUTTON_SET_IMG( menuButton, "", dvd_menu, qtr( "Menu" ) );
546 /* Change the navigation button display when the IM navigation changes */
547 CONNECT( THEMIM->getIM(), navigationChanged( int ),
548 this, setNavigation( int ) );
549 /* Changes the IM navigation when triggered on the nav buttons */
550 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
552 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
554 CONNECT( menuButton, clicked(), THEMIM->getIM(),
559 * TODO: Merge with upper menu in a StackLayout
561 telexFrame = new QWidget( this );
562 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
563 telexLayout->setSpacing( 0 );
564 telexLayout->setMargin( 0 );
566 telexOn = new QPushButton;
567 setupSmallButton( telexOn );
568 telexLayout->addWidget( telexOn );
570 telexTransparent = new QPushButton;
571 setupSmallButton( telexTransparent );
572 telexLayout->addWidget( telexTransparent );
573 b_telexTransparent = false;
575 telexPage = new QSpinBox;
576 telexPage->setRange( 0, 999 );
577 telexPage->setValue( 100 );
578 telexPage->setAccelerated( true );
579 telexPage->setWrapping( true );
580 telexPage->setAlignment( Qt::AlignRight );
581 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
582 telexLayout->addWidget( telexPage );
584 telexFrame->hide(); /* default hidden */
586 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
587 telexGotoPage( int ) );
588 CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
589 telexPage, setValue( int ) );
591 BUTTON_SET_IMG( telexOn, "", tv, qtr( "Teletext on" ) );
593 CONNECT( telexOn, clicked(), THEMIM->getIM(),
594 telexToggleButtons() );
595 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
596 telexToggle( bool ) );
597 CONNECT( THEMIM->getIM(), toggleTelexButtons(),
598 this, toggleTeletext() );
599 b_telexEnabled = false;
600 telexTransparent->setEnabled( false );
601 telexPage->setEnabled( false );
603 BUTTON_SET_IMG( telexTransparent, "", tvtelx, qtr( "Teletext" ) );
604 CONNECT( telexTransparent, clicked( bool ),
605 THEMIM->getIM(), telexSetTransparency() );
606 CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
607 this, toggleTeletextTransparency() );
608 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
609 this, enableTeletext( bool ) );
612 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
613 sizePolicy.setHorizontalStretch( 0 );
614 sizePolicy.setVerticalStretch( 0 );
617 playButton = new QPushButton;
618 playButton->setSizePolicy( sizePolicy );
619 playButton->setMaximumSize( QSize( 36, 36 ) );
620 playButton->setMinimumSize( QSize( 36, 36 ) );
621 playButton->setIconSize( QSize( 30, 30 ) );
624 /** Prev + Stop + Next Block **/
625 controlButLayout = new QHBoxLayout;
626 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
629 QPushButton *prevButton = new QPushButton;
630 prevButton->setSizePolicy( sizePolicy );
631 setupSmallButton( prevButton );
633 controlButLayout->addWidget( prevButton );
636 QPushButton *stopButton = new QPushButton;
637 stopButton->setSizePolicy( sizePolicy );
638 setupSmallButton( stopButton );
640 controlButLayout->addWidget( stopButton );
643 QPushButton *nextButton = new QPushButton;
644 nextButton->setSizePolicy( sizePolicy );
645 setupSmallButton( nextButton );
647 controlButLayout->addWidget( nextButton );
649 /* Add this block to the main layout */
651 BUTTON_SET_ACT_I( playButton, "", play_b, qtr( I_PLAY_TOOLTIP ), play() );
652 BUTTON_SET_ACT_I( prevButton, "" , previous_b,
653 qtr( "Previous media in the playlist" ), prev() );
654 BUTTON_SET_ACT_I( nextButton, "", next_b,
655 qtr( "Next media in the playlist" ), next() );
656 BUTTON_SET_ACT_I( stopButton, "", stop_b, qtr( "Stop playback" ), stop() );
659 * Other first Line buttons
661 /** Fullscreen/Visualisation **/
662 fullscreenButton = new QPushButton;
663 BUTTON_SET_ACT_I( fullscreenButton, "", fullscreen,
664 qtr( "Toggle the video in fullscreen" ), fullscreen() );
665 setupSmallButton( fullscreenButton );
669 /** Playlist Button **/
670 playlistButton = new QPushButton;
671 setupSmallButton( playlistButton );
672 BUTTON_SET_IMG( playlistButton, "" , playlist, qtr( "Show playlist" ) );
673 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
675 /** extended Settings **/
676 extSettingsButton = new QPushButton;
677 BUTTON_SET_ACT_I( extSettingsButton, "", extended,
678 qtr( "Show extended settings" ), extSettings() );
679 setupSmallButton( extSettingsButton );
683 hVolLabel = new VolumeClickHandler( p_intf, this );
685 volMuteLabel = new QLabel;
686 volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
687 volMuteLabel->installEventFilter( hVolLabel );
691 volumeSlider = new SoundSlider( this,
692 config_GetInt( p_intf, "volume-step" ),
693 config_GetInt( p_intf, "qt-volume-complete" ),
694 config_GetPsz( p_intf, "qt-slider-colours" ) );
698 volumeSlider = new QSlider( this );
699 volumeSlider->setOrientation( Qt::Horizontal );
701 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
702 volumeSlider->setMinimumSize( QSize( 85, 30 ) );
703 volumeSlider->setFocusPolicy( Qt::NoFocus );
705 /* Set the volume from the config */
706 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
707 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
709 /* Force the update at build time in order to have a muted icon if needed */
710 updateVolume( volumeSlider->value() );
712 /* Volume control connection */
713 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
714 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
718 controlLayout = new QGridLayout( this );
720 controlLayout->setSpacing( 0 );
721 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
723 controlLayout->addWidget( slider, 0, 1, 1, 18 );
724 controlLayout->addWidget( slowerButton, 0, 0 );
725 controlLayout->addWidget( fasterButton, 0, 19 );
727 controlLayout->addWidget( discFrame, 1, 8, 2, 3, Qt::AlignBottom );
728 controlLayout->addWidget( telexFrame, 1, 8, 2, 5, Qt::AlignBottom );
730 controlLayout->addWidget( playButton, 2, 0, 2, 2, Qt::AlignBottom );
731 controlLayout->setColumnMinimumWidth( 2, 10 );
732 controlLayout->setColumnStretch( 2, 0 );
734 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
735 /* Column 6 is unused */
736 controlLayout->setColumnStretch( 6, 0 );
737 controlLayout->setColumnStretch( 7, 0 );
738 controlLayout->setColumnMinimumWidth( 7, 10 );
740 controlLayout->addWidget( fullscreenButton, 3, 8, Qt::AlignBottom );
741 controlLayout->addWidget( playlistButton, 3, 9, Qt::AlignBottom );
742 controlLayout->addWidget( extSettingsButton, 3, 10, Qt::AlignBottom );
743 controlLayout->setColumnStretch( 11, 0 ); /* telex alignment */
745 controlLayout->setColumnStretch( 12, 0 );
746 controlLayout->setColumnMinimumWidth( 12, 10 );
748 controlLayout->addWidget( advControls, 3, 13, 1, 3, Qt::AlignBottom );
750 controlLayout->setColumnStretch( 16, 10 );
751 controlLayout->setColumnMinimumWidth( 16, 10 );
753 controlLayout->addWidget( volMuteLabel, 3, 17, Qt::AlignBottom );
754 controlLayout->addWidget( volumeSlider, 3, 18, 1 , 2, Qt::AlignBottom );
760 ControlsWidget::~ControlsWidget()
763 void ControlsWidget::toggleTeletext()
765 bool b_enabled = THEMIM->teletextState();
768 telexTransparent->setEnabled( false );
769 telexPage->setEnabled( false );
770 b_telexEnabled = false;
774 telexTransparent->setEnabled( true );
775 telexPage->setEnabled( true );
776 b_telexEnabled = true;
780 void ControlsWidget::enableTeletext( bool b_enable )
782 telexFrame->setVisible( b_enable );
783 bool b_on = THEMIM->teletextState();
785 telexOn->setChecked( b_on );
786 telexTransparent->setEnabled( b_on );
787 telexPage->setEnabled( b_on );
788 b_telexEnabled = b_on;
791 void ControlsWidget::toggleTeletextTransparency()
793 if( b_telexTransparent )
795 telexTransparent->setIcon( QIcon( ":/tvtelx" ) );
796 telexTransparent->setToolTip( qtr( "Teletext" ) );
797 b_telexTransparent = false;
801 telexTransparent->setIcon( QIcon( ":/tvtelx-transparent" ) );
802 telexTransparent->setToolTip( qtr( "Transparent" ) );
803 b_telexTransparent = true;
807 void ControlsWidget::stop()
812 void ControlsWidget::play()
814 if( THEPL->current.i_size == 0 )
816 /* The playlist is empty, open a file requester */
817 THEDP->openFileDialog();
821 THEMIM->togglePlayPause();
824 void ControlsWidget::prev()
829 void ControlsWidget::next()
834 void ControlsWidget::setNavigation( int navigation )
836 #define HELP_PCH N_( "Previous chapter" )
837 #define HELP_NCH N_( "Next chapter" )
839 // 1 = chapter, 2 = title, 0 = no
840 if( navigation == 0 )
843 } else if( navigation == 1 ) {
844 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
845 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
849 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
850 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
856 static bool b_my_volume;
857 void ControlsWidget::updateVolume( int i_sliderVolume )
861 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
862 aout_VolumeSet( p_intf, i_res );
864 if( i_sliderVolume == 0 )
866 volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
867 volMuteLabel->setToolTip( qtr( "Unmute" ) );
871 if( i_sliderVolume < VOLUME_MAX / 3 )
872 volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
873 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
874 volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
875 else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
876 volMuteLabel->setToolTip( qtr( "Mute" ) );
879 void ControlsWidget::updateVolume()
882 audio_volume_t i_volume;
883 aout_VolumeGet( p_intf, &i_volume );
884 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
885 int i_gauge = volumeSlider->value();
887 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
890 volumeSlider->setValue( i_volume );
895 void ControlsWidget::updateInput()
897 /* Activate the interface buttons according to the presence of the input */
898 enableInput( THEMIM->getIM()->hasInput() );
899 enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
902 void ControlsWidget::setStatus( int status )
904 if( status == PLAYING_S ) /* Playing */
906 playButton->setIcon( QIcon( ":/pause_b" ) );
907 playButton->setToolTip( qtr( "Pause the playback" ) );
911 playButton->setIcon( QIcon( ":/play_b" ) );
912 playButton->setToolTip( qtr( I_PLAY_TOOLTIP ) );
918 * This functions toggle the fullscreen mode
919 * If there is no video, it should first activate Visualisations...
920 * This has also to be fixed in enableVideo()
922 void ControlsWidget::fullscreen()
924 vout_thread_t *p_vout =
925 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
928 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
929 vlc_object_release( p_vout );
933 void ControlsWidget::extSettings()
935 THEDP->extendedDialog();
938 void ControlsWidget::slower()
940 THEMIM->getIM()->slower();
943 void ControlsWidget::faster()
945 THEMIM->getIM()->faster();
948 void ControlsWidget::enableInput( bool enable )
950 slowerButton->setEnabled( enable );
951 slider->setEnabled( enable );
952 slider->setSliderPosition ( 0 );
953 fasterButton->setEnabled( enable );
955 /* Advanced Buttons too */
956 advControls->enableInput( enable );
959 void ControlsWidget::enableVideo( bool enable )
961 // TODO Later make the fullscreenButton toggle Visualisation and so on.
962 fullscreenButton->setEnabled( enable );
964 /* Advanced Buttons too */
965 advControls->enableVideo( enable );
968 void ControlsWidget::toggleAdvanced()
970 if( advControls && !b_advancedVisible )
973 b_advancedVisible = true;
978 b_advancedVisible = false;
980 emit advancedControlsToggled( b_advancedVisible );
984 /**********************************************************************
985 * Fullscrenn control widget
986 **********************************************************************/
987 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
988 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
989 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
990 i_mouse_last_x( -1 ), i_mouse_last_y( -1 ), b_mouse_over(false),
991 b_slow_hide_begin(false), i_slow_hide_timeout(1),
992 b_fullscreen( false ), i_hide_timeout( 1 ), p_vout(NULL)
994 setWindowFlags( Qt::ToolTip );
996 setFrameShape( QFrame::StyledPanel );
997 setFrameStyle( QFrame::Sunken );
998 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
1000 QGridLayout *fsLayout = new QGridLayout( this );
1001 fsLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
1004 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
1005 fsLayout->addWidget( slowerButton, 0, 0 );
1006 fsLayout->addWidget( slider, 0, 1, 1, 8 );
1007 fsLayout->addWidget( fasterButton, 0, 9 );
1009 fsLayout->addWidget( playButton, 1, 0, 1, 2 );
1010 fsLayout->addLayout( controlButLayout, 1, 2 );
1012 fsLayout->addWidget( discFrame, 1, 3 );
1013 fsLayout->addWidget( telexFrame, 1, 4 );
1014 fsLayout->addWidget( fullscreenButton, 1, 5 );
1015 fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
1017 fsLayout->addWidget( volMuteLabel, 1, 7 );
1018 fsLayout->addWidget( volumeSlider, 1, 8, 1, 2 );
1021 p_hideTimer = new QTimer( this );
1022 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
1023 p_hideTimer->setSingleShot( true );
1025 /* slow hiding timer */
1026 #if HAVE_TRANSPARENCY
1027 p_slowHideTimer = new QTimer( this );
1028 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
1031 adjustSize (); /* need to get real width and height for moving */
1034 QDesktopWidget * p_desktop = QApplication::desktop();
1036 move( p_desktop->width() / 2 - width() / 2,
1037 p_desktop->height() - height() );
1040 setWindowOpacity( 0.0 );
1046 fullscreenButton->setIcon( QIcon( ":/defullscreen" ) );
1048 vlc_mutex_init_recursive( &lock );
1051 FullscreenControllerWidget::~FullscreenControllerWidget()
1054 vlc_mutex_destroy( &lock );
1058 * Show fullscreen controller
1060 void FullscreenControllerWidget::showFSC()
1064 // after quiting and going to fs, we need to call show()
1070 b_fscHidden = false;
1071 setWindowOpacity( 1.0 );
1077 #if HAVE_TRANSPARENCY
1078 setWindowOpacity( DEFAULT_OPACITY );
1083 * Hide fullscreen controller
1084 * FIXME: under windows it have to be done by moving out of screen
1085 * because hide() doesnt work
1087 void FullscreenControllerWidget::hideFSC()
1091 setWindowOpacity( 0.0 ); // simulate hidding
1098 * Plane to hide fullscreen controller
1100 void FullscreenControllerWidget::planHideFSC()
1102 vlc_mutex_lock( &lock );
1103 int i_timeout = i_hide_timeout;
1104 vlc_mutex_unlock( &lock );
1106 p_hideTimer->start( i_timeout );
1108 #if HAVE_TRANSPARENCY
1109 b_slow_hide_begin = true;
1110 i_slow_hide_timeout = i_timeout;
1111 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
1116 * Hidding fullscreen controller slowly
1117 * Linux: need composite manager
1118 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
1120 void FullscreenControllerWidget::slowHideFSC()
1122 #if HAVE_TRANSPARENCY
1123 if( b_slow_hide_begin )
1125 b_slow_hide_begin = false;
1127 p_slowHideTimer->stop();
1128 /* the last part of time divided to 100 pieces */
1129 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
1135 if ( windowOpacity() > 0.0 && !b_fscHidden )
1137 if ( windowOpacity() > 0.0 )
1140 /* we should use 0.01 because of 100 pieces ^^^
1141 but than it cannt be done in time */
1142 setWindowOpacity( windowOpacity() - 0.02 );
1145 if ( windowOpacity() <= 0.0 )
1146 p_slowHideTimer->stop();
1153 * events: show, hide, start timer for hidding
1155 void FullscreenControllerWidget::customEvent( QEvent *event )
1159 switch( event->type() )
1161 case FullscreenControlToggle_Type:
1162 vlc_mutex_lock( &lock );
1163 b_fs = b_fullscreen;
1164 vlc_mutex_unlock( &lock );
1172 p_hideTimer->stop();
1178 case FullscreenControlShow_Type:
1179 vlc_mutex_lock( &lock );
1180 b_fs = b_fullscreen;
1181 vlc_mutex_unlock( &lock );
1183 if( b_fs ) // FIXME I am not sure about that one
1186 case FullscreenControlHide_Type:
1189 case FullscreenControlPlanHide_Type:
1190 if( !b_mouse_over ) // Only if the mouse is not over FSC
1200 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1202 if ( event->buttons() == Qt::LeftButton )
1204 int i_moveX = event->globalX() - i_mouse_last_x;
1205 int i_moveY = event->globalY() - i_mouse_last_y;
1207 move( x() + i_moveX, y() + i_moveY );
1209 i_mouse_last_x = event->globalX();
1210 i_mouse_last_y = event->globalY();
1216 * store position of cursor
1218 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1220 i_mouse_last_x = event->globalX();
1221 i_mouse_last_y = event->globalY();
1225 * On mouse go above FSC
1227 void FullscreenControllerWidget::enterEvent( QEvent *event )
1229 b_mouse_over = true;
1231 p_hideTimer->stop();
1232 #if HAVE_TRANSPARENCY
1233 p_slowHideTimer->stop();
1238 * On mouse go out from FSC
1240 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1244 b_mouse_over = false;
1248 * When you get pressed key, send it to video output
1249 * FIXME: clearing focus by clearFocus() to not getting
1250 * key press events didnt work
1252 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1254 int i_vlck = qtEventToVLCKey( event );
1257 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1265 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object, const char *variable,
1266 vlc_value_t old_val, vlc_value_t new_val,
1269 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1270 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1272 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1277 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1278 vlc_value_t old_val, vlc_value_t new_val,
1281 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1284 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1285 QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1287 /* Plan hide event */
1288 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1289 QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1296 * It is called when video start
1298 void FullscreenControllerWidget::attachVout( vout_thread_t *p_nvout )
1300 assert( p_nvout && !p_vout );
1304 vlc_mutex_lock( &lock );
1305 var_AddCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this ); /* I miss a add and fire */
1306 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ), var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1307 vlc_mutex_unlock( &lock );
1310 * It is called after turn off video.
1312 void FullscreenControllerWidget::detachVout()
1316 var_DelCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this );
1317 vlc_mutex_lock( &lock );
1318 fullscreenChanged( p_vout, false, 0 );
1319 vlc_mutex_unlock( &lock );
1325 * Register and unregister callback for mouse moving
1327 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout, bool b_fs, int i_timeout )
1329 vlc_mutex_lock( &lock );
1330 if( b_fs && !b_fullscreen )
1332 b_fullscreen = true;
1333 i_hide_timeout = i_timeout;
1334 var_AddCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1336 else if( !b_fs && b_fullscreen )
1338 b_fullscreen = false;
1339 i_hide_timeout = i_timeout;
1340 var_DelCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1342 /* Force fs hidding */
1343 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1344 QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1346 vlc_mutex_unlock( &lock );
1349 /**********************************************************************
1350 * Speed control widget
1351 **********************************************************************/
1352 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1353 QFrame( NULL ), p_intf( _p_i )
1355 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1356 sizePolicy.setHorizontalStretch( 0 );
1357 sizePolicy.setVerticalStretch( 0 );
1359 speedSlider = new QSlider;
1360 speedSlider->setSizePolicy( sizePolicy );
1361 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1362 speedSlider->setOrientation( Qt::Vertical );
1363 speedSlider->setTickPosition( QSlider::TicksRight );
1365 speedSlider->setRange( -24, 24 );
1366 speedSlider->setSingleStep( 1 );
1367 speedSlider->setPageStep( 1 );
1368 speedSlider->setTickInterval( 12 );
1370 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1372 QToolButton *normalSpeedButton = new QToolButton( this );
1373 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1374 normalSpeedButton->setAutoRaise( true );
1375 normalSpeedButton->setText( "1x" );
1376 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1378 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1380 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1381 speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
1382 speedControlLayout->setSpacing( 4 );
1383 speedControlLayout->addWidget( speedSlider );
1384 speedControlLayout->addWidget( normalSpeedButton );
1385 setLayout( speedControlLayout );
1388 SpeedControlWidget::~SpeedControlWidget()
1391 void SpeedControlWidget::setEnable( bool b_enable )
1393 speedSlider->setEnabled( b_enable );
1396 void SpeedControlWidget::updateControls( int rate )
1398 if( speedSlider->isSliderDown() )
1400 //We don't want to change anything if the user is using the slider
1404 double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
1405 int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
1407 if( sliderValue < speedSlider->minimum() )
1409 sliderValue = speedSlider->minimum();
1411 else if( sliderValue > speedSlider->maximum() )
1413 sliderValue = speedSlider->maximum();
1416 //Block signals to avoid feedback loop
1417 speedSlider->blockSignals( true );
1418 speedSlider->setValue( sliderValue );
1419 speedSlider->blockSignals( false );
1422 void SpeedControlWidget::updateRate( int sliderValue )
1424 double speed = pow( 2, (double)sliderValue / 12 );
1425 int rate = INPUT_RATE_DEFAULT / speed;
1427 THEMIM->getIM()->setRate(rate);
1430 void SpeedControlWidget::resetRate()
1432 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);