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( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
118 vout_Control( p_vout, VOUT_REPARENT );
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;
138 msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );
140 return ( void* )winId();
143 /* Set the Widget to the correct Size */
144 /* Function has to be called by the parent
145 Parent has to care about resizing himself*/
146 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
148 msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
149 videoSize.rwidth() = w;
150 videoSize.rheight() = h;
151 if( isHidden() ) show();
152 updateGeometry(); // Needed for deinterlace
155 void VideoWidget::release( void *p_win )
157 msg_Dbg( p_intf, "Video is not needed anymore" );
159 videoSize.rwidth() = 0;
160 videoSize.rheight() = 0;
165 QSize VideoWidget::sizeHint() const
170 /**********************************************************************
171 * Background Widget. Show a simple image background. Currently,
172 * it's album art if present or cone.
173 **********************************************************************/
174 #define ICON_SIZE 128
175 #define MAX_BG_SIZE 400
176 #define MIN_BG_SIZE 128
178 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
179 :QWidget( NULL ), p_intf( _p_i )
181 /* We should use that one to take the more size it can */
182 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding);
184 /* A dark background */
185 setAutoFillBackground( true );
187 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
188 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
191 /* A cone in the middle */
193 label->setMargin( 5 );
194 label->setMaximumHeight( MAX_BG_SIZE );
195 label->setMaximumWidth( MAX_BG_SIZE );
196 label->setMinimumHeight( MIN_BG_SIZE );
197 label->setMinimumWidth( MIN_BG_SIZE );
198 if( QDate::currentDate().dayOfYear() >= 354 )
199 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
201 label->setPixmap( QPixmap( ":/vlc128.png" ) );
203 QGridLayout *backgroundLayout = new QGridLayout( this );
204 backgroundLayout->addWidget( label, 0, 1 );
205 backgroundLayout->setColumnStretch( 0, 1 );
206 backgroundLayout->setColumnStretch( 2, 1 );
208 CONNECT( THEMIM->getIM(), artChanged( QString ), this, updateArt( QString ) );
211 BackgroundWidget::~BackgroundWidget()
214 void BackgroundWidget::resizeEvent( QResizeEvent * event )
216 if( event->size().height() <= MIN_BG_SIZE )
222 void BackgroundWidget::updateArt( QString url )
226 if( QDate::currentDate().dayOfYear() >= 354 )
227 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
229 label->setPixmap( QPixmap( ":/vlc128.png" ) );
234 label->setPixmap( QPixmap( url ) );
238 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
240 QVLCMenu::PopupMenu( p_intf, true );
244 /**********************************************************************
245 * Visualization selector panel
246 **********************************************************************/
247 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
248 QFrame( NULL ), p_intf( _p_i )
250 QHBoxLayout *layout = new QHBoxLayout( this );
251 layout->setMargin( 0 );
252 QPushButton *prevButton = new QPushButton( "Prev" );
253 QPushButton *nextButton = new QPushButton( "Next" );
254 layout->addWidget( prevButton );
255 layout->addWidget( nextButton );
257 layout->addStretch( 10 );
258 layout->addWidget( new QLabel( qtr( "Current visualization" ) ) );
260 current = new QLabel( qtr( "None" ) );
261 layout->addWidget( current );
263 BUTTONACT( prevButton, prev() );
264 BUTTONACT( nextButton, next() );
267 setMaximumHeight( 35 );
270 VisualSelector::~VisualSelector()
273 void VisualSelector::prev()
275 char *psz_new = aout_VisualPrev( p_intf );
278 current->setText( qfu( psz_new ) );
283 void VisualSelector::next()
285 char *psz_new = aout_VisualNext( p_intf );
288 current->setText( qfu( psz_new ) );
294 /**********************************************************************
296 **********************************************************************/
298 #define setupSmallButton( aButton ){ \
299 aButton->setMaximumSize( QSize( 26, 26 ) ); \
300 aButton->setMinimumSize( QSize( 26, 26 ) ); \
301 aButton->setIconSize( QSize( 20, 20 ) ); }
303 /* init static variables in advanced controls */
304 mtime_t AdvControlsWidget::timeA = 0;
305 mtime_t AdvControlsWidget::timeB = 0;
307 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, bool b_fsCreation = false ) :
308 QFrame( NULL ), p_intf( _p_i )
310 QHBoxLayout *advLayout = new QHBoxLayout( this );
311 advLayout->setMargin( 0 );
312 advLayout->setSpacing( 0 );
313 advLayout->setAlignment( Qt::AlignBottom );
316 ABButton = new QPushButton;
317 setupSmallButton( ABButton );
318 advLayout->addWidget( ABButton );
319 BUTTON_SET_ACT_I( ABButton, "", atob_nob,
320 qtr( "Loop from point A to point B continuously.\nClick to set point A" ),
324 /* in FS controller we skip this, because we dont want to have it double
327 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
328 this, AtoBLoop( float, int, int ) );
329 /* set up synchronization between main controller and fs controller */
330 CONNECT( THEMIM->getIM(), advControlsSetIcon(), this, setIcon() );
331 connect( this, SIGNAL( timeChanged() ),
332 THEMIM->getIM(), SIGNAL( advControlsSetIcon()));
334 frameButton = new QPushButton( "Fr" );
335 frameButton->setMaximumSize( QSize( 26, 26 ) );
336 frameButton->setIconSize( QSize( 20, 20 ) );
337 advLayout->addWidget( frameButton );
338 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by frame" ), frame() );
342 recordButton = new QPushButton;
343 setupSmallButton( recordButton );
344 advLayout->addWidget( recordButton );
345 BUTTON_SET_ACT_I( recordButton, "", record,
346 qtr( "Record" ), record() );
348 /* Snapshot Button */
349 snapshotButton = new QPushButton;
350 setupSmallButton( snapshotButton );
351 advLayout->addWidget( snapshotButton );
352 BUTTON_SET_ACT_I( snapshotButton, "", snapshot,
353 qtr( "Take a snapshot" ), snapshot() );
356 AdvControlsWidget::~AdvControlsWidget()
359 void AdvControlsWidget::enableInput( bool enable )
362 if( THEMIM->getInput() != NULL )
364 input_item_t *p_item = input_GetItem( THEMIM->getInput() );
365 i_input_id = p_item->i_id;
367 recordButton->setVisible( var_GetBool( THEMIM->getInput(), "can-record" ) );
371 recordButton->setVisible( false );
374 ABButton->setEnabled( enable );
375 recordButton->setEnabled( enable );
377 if( enable && ( i_last_input_id != i_input_id ) )
380 i_last_input_id = i_input_id;
385 void AdvControlsWidget::enableVideo( bool enable )
387 snapshotButton->setEnabled( enable );
389 frameButton->setEnabled( enable );
393 void AdvControlsWidget::snapshot()
395 vout_thread_t *p_vout =
396 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
397 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
400 /* Function called when the button is clicked() */
401 void AdvControlsWidget::fromAtoB()
405 timeA = var_GetTime( THEMIM->getInput(), "time" );
411 timeB = var_GetTime( THEMIM->getInput(), "time" );
412 var_SetTime( THEMIM->getInput(), "time" , timeA );
421 /* setting/synchro icons after click on main or fs controller */
422 void AdvControlsWidget::setIcon()
424 if( !timeA && !timeB)
426 ABButton->setIcon( QIcon( ":/atob_nob" ) );
427 ABButton->setToolTip( qtr( "Loop from point A to point B continuously\nClick to set point A" ) );
429 else if( timeA && !timeB )
431 ABButton->setIcon( QIcon( ":/atob_noa" ) );
432 ABButton->setToolTip( qtr( "Click to set point B" ) );
434 else if( timeA && timeB )
436 ABButton->setIcon( QIcon( ":/atob" ) );
437 ABButton->setToolTip( qtr( "Stop the A to B loop" ) );
441 /* Function called regularly when in an AtoB loop */
442 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
446 if( ( i_time >= (int)( timeB/1000000 ) )
447 || ( i_time < (int)( timeA/1000000 ) ) )
448 var_SetTime( THEMIM->getInput(), "time" , timeA );
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 const bool b_recording = var_GetBool( p_input, "record" );
459 var_SetBool( p_input, "record", !b_recording );
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( qtr( HELP_PCH ) );
845 nextSectionButton->setToolTip( qtr( HELP_NCH ) );
849 prevSectionButton->setToolTip( qtr( HELP_PCH ) );
850 nextSectionButton->setToolTip( qtr( 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, 2, 5, 2, 5 );
1004 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
1005 slider->setMinimumWidth( 220 );
1006 fsLayout->addWidget( slowerButton, 0, 0 );
1007 fsLayout->addWidget( slider, 0, 1, 1, 9 );
1008 fsLayout->addWidget( fasterButton, 0, 10 );
1010 fsLayout->addWidget( playButton, 1, 0, 1, 2 );
1011 fsLayout->addLayout( controlButLayout, 1, 2 );
1013 fsLayout->addWidget( discFrame, 1, 3 );
1014 fsLayout->addWidget( telexFrame, 1, 4 );
1015 fsLayout->addWidget( fullscreenButton, 1, 5 );
1016 fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
1018 fsLayout->setColumnStretch( 7, 10 );
1019 fsLayout->addWidget( volMuteLabel, 1, 8 );
1020 fsLayout->addWidget( volumeSlider, 1, 9, 1, 2 );
1023 p_hideTimer = new QTimer( this );
1024 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
1025 p_hideTimer->setSingleShot( true );
1027 /* slow hiding timer */
1028 #if HAVE_TRANSPARENCY
1029 p_slowHideTimer = new QTimer( this );
1030 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
1033 adjustSize (); /* need to get real width and height for moving */
1036 QDesktopWidget * p_desktop = QApplication::desktop();
1038 move( p_desktop->width() / 2 - width() / 2,
1039 p_desktop->height() - height() );
1042 setWindowOpacity( 0.0 );
1048 fullscreenButton->setIcon( QIcon( ":/defullscreen" ) );
1050 vlc_mutex_init_recursive( &lock );
1053 FullscreenControllerWidget::~FullscreenControllerWidget()
1056 vlc_mutex_destroy( &lock );
1060 * Show fullscreen controller
1062 void FullscreenControllerWidget::showFSC()
1066 // after quiting and going to fs, we need to call show()
1072 b_fscHidden = false;
1073 setWindowOpacity( 1.0 );
1079 #if HAVE_TRANSPARENCY
1080 setWindowOpacity( DEFAULT_OPACITY );
1085 * Hide fullscreen controller
1086 * FIXME: under windows it have to be done by moving out of screen
1087 * because hide() doesnt work
1089 void FullscreenControllerWidget::hideFSC()
1093 setWindowOpacity( 0.0 ); // simulate hidding
1100 * Plane to hide fullscreen controller
1102 void FullscreenControllerWidget::planHideFSC()
1104 vlc_mutex_lock( &lock );
1105 int i_timeout = i_hide_timeout;
1106 vlc_mutex_unlock( &lock );
1108 p_hideTimer->start( i_timeout );
1110 #if HAVE_TRANSPARENCY
1111 b_slow_hide_begin = true;
1112 i_slow_hide_timeout = i_timeout;
1113 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
1118 * Hidding fullscreen controller slowly
1119 * Linux: need composite manager
1120 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
1122 void FullscreenControllerWidget::slowHideFSC()
1124 #if HAVE_TRANSPARENCY
1125 if( b_slow_hide_begin )
1127 b_slow_hide_begin = false;
1129 p_slowHideTimer->stop();
1130 /* the last part of time divided to 100 pieces */
1131 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
1137 if ( windowOpacity() > 0.0 && !b_fscHidden )
1139 if ( windowOpacity() > 0.0 )
1142 /* we should use 0.01 because of 100 pieces ^^^
1143 but than it cannt be done in time */
1144 setWindowOpacity( windowOpacity() - 0.02 );
1147 if ( windowOpacity() <= 0.0 )
1148 p_slowHideTimer->stop();
1155 * events: show, hide, start timer for hidding
1157 void FullscreenControllerWidget::customEvent( QEvent *event )
1161 switch( event->type() )
1163 case FullscreenControlToggle_Type:
1164 vlc_mutex_lock( &lock );
1165 b_fs = b_fullscreen;
1166 vlc_mutex_unlock( &lock );
1174 p_hideTimer->stop();
1180 case FullscreenControlShow_Type:
1181 vlc_mutex_lock( &lock );
1182 b_fs = b_fullscreen;
1183 vlc_mutex_unlock( &lock );
1185 if( b_fs ) // FIXME I am not sure about that one
1188 case FullscreenControlHide_Type:
1191 case FullscreenControlPlanHide_Type:
1192 if( !b_mouse_over ) // Only if the mouse is not over FSC
1202 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1204 if ( event->buttons() == Qt::LeftButton )
1206 int i_moveX = event->globalX() - i_mouse_last_x;
1207 int i_moveY = event->globalY() - i_mouse_last_y;
1209 move( x() + i_moveX, y() + i_moveY );
1211 i_mouse_last_x = event->globalX();
1212 i_mouse_last_y = event->globalY();
1218 * store position of cursor
1220 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1222 i_mouse_last_x = event->globalX();
1223 i_mouse_last_y = event->globalY();
1227 * On mouse go above FSC
1229 void FullscreenControllerWidget::enterEvent( QEvent *event )
1231 b_mouse_over = true;
1233 p_hideTimer->stop();
1234 #if HAVE_TRANSPARENCY
1235 p_slowHideTimer->stop();
1240 * On mouse go out from FSC
1242 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1246 b_mouse_over = false;
1250 * When you get pressed key, send it to video output
1251 * FIXME: clearing focus by clearFocus() to not getting
1252 * key press events didnt work
1254 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1256 int i_vlck = qtEventToVLCKey( event );
1259 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1267 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object, const char *variable,
1268 vlc_value_t old_val, vlc_value_t new_val,
1271 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1272 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1274 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1279 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1280 vlc_value_t old_val, vlc_value_t new_val,
1283 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1286 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1287 QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1289 /* Plan hide event */
1290 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1291 QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1298 * It is called when video start
1300 void FullscreenControllerWidget::attachVout( vout_thread_t *p_nvout )
1302 assert( p_nvout && !p_vout );
1306 vlc_mutex_lock( &lock );
1307 var_AddCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this ); /* I miss a add and fire */
1308 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ), var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1309 vlc_mutex_unlock( &lock );
1312 * It is called after turn off video.
1314 void FullscreenControllerWidget::detachVout()
1318 var_DelCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this );
1319 vlc_mutex_lock( &lock );
1320 fullscreenChanged( p_vout, false, 0 );
1321 vlc_mutex_unlock( &lock );
1327 * Register and unregister callback for mouse moving
1329 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout, bool b_fs, int i_timeout )
1331 vlc_mutex_lock( &lock );
1332 if( b_fs && !b_fullscreen )
1334 b_fullscreen = true;
1335 i_hide_timeout = i_timeout;
1336 var_AddCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1338 else if( !b_fs && b_fullscreen )
1340 b_fullscreen = false;
1341 i_hide_timeout = i_timeout;
1342 var_DelCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1344 /* Force fs hidding */
1345 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1346 QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1348 vlc_mutex_unlock( &lock );
1351 /**********************************************************************
1352 * Speed control widget
1353 **********************************************************************/
1354 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1355 QFrame( NULL ), p_intf( _p_i )
1357 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1358 sizePolicy.setHorizontalStretch( 0 );
1359 sizePolicy.setVerticalStretch( 0 );
1361 speedSlider = new QSlider;
1362 speedSlider->setSizePolicy( sizePolicy );
1363 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1364 speedSlider->setOrientation( Qt::Vertical );
1365 speedSlider->setTickPosition( QSlider::TicksRight );
1367 speedSlider->setRange( -24, 24 );
1368 speedSlider->setSingleStep( 1 );
1369 speedSlider->setPageStep( 1 );
1370 speedSlider->setTickInterval( 12 );
1372 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1374 QToolButton *normalSpeedButton = new QToolButton( this );
1375 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1376 normalSpeedButton->setAutoRaise( true );
1377 normalSpeedButton->setText( "1x" );
1378 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1380 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1382 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1383 speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
1384 speedControlLayout->setSpacing( 4 );
1385 speedControlLayout->addWidget( speedSlider );
1386 speedControlLayout->addWidget( normalSpeedButton );
1387 setLayout( speedControlLayout );
1390 SpeedControlWidget::~SpeedControlWidget()
1393 void SpeedControlWidget::setEnable( bool b_enable )
1395 speedSlider->setEnabled( b_enable );
1398 void SpeedControlWidget::updateControls( int rate )
1400 if( speedSlider->isSliderDown() )
1402 //We don't want to change anything if the user is using the slider
1406 double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
1407 int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
1409 if( sliderValue < speedSlider->minimum() )
1411 sliderValue = speedSlider->minimum();
1413 else if( sliderValue > speedSlider->maximum() )
1415 sliderValue = speedSlider->maximum();
1418 //Block signals to avoid feedback loop
1419 speedSlider->blockSignals( true );
1420 speedSlider->setValue( sliderValue );
1421 speedSlider->blockSignals( false );
1424 void SpeedControlWidget::updateRate( int sliderValue )
1426 double speed = pow( 2, (double)sliderValue / 12 );
1427 int rate = INPUT_RATE_DEFAULT / speed;
1429 THEMIM->getIM()->setRate(rate);
1432 void SpeedControlWidget::resetRate()
1434 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);