1 /*****************************************************************************
2 * interface_widgets.cpp : Custom widgets for the main interface
3 ****************************************************************************
4 * Copyright ( C ) 2006 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
9 * Rafaël Carré <funman@videolanorg>
10 * Ilkka Ollakka <ileoo@videolan.org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * ( at your option ) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
33 #include "dialogs_provider.hpp"
34 #include "components/interface_widgets.hpp"
35 #include "main_interface.hpp"
36 #include "input_manager.hpp"
38 #include "util/input_slider.hpp"
39 #include "util/customwidgets.hpp"
42 #include <QSpacerItem>
44 #include <QPushButton>
45 #include <QToolButton>
46 #include <QHBoxLayout>
49 #include <QResizeEvent>
53 # include <X11/Xlib.h>
54 # include <qx11info_x11.h>
59 #define I_PLAY_TOOLTIP N_("Play\nIf the playlist is empty, open a media")
61 /**********************************************************************
62 * Video Widget. A simple frame on which video is drawn
63 * This class handles resize issues
64 **********************************************************************/
66 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
70 videoSize.rwidth() = -1;
71 videoSize.rheight() = -1;
75 /* Set the policy to expand in both directions */
76 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
78 /* Black background is more coherent for a Video Widget */
79 QPalette plt = palette();
80 plt.setColor( QPalette::Window, Qt::black );
82 setAutoFillBackground(true);
84 /* Indicates that the widget wants to draw directly onto the screen.
85 Widgets with this attribute set do not participate in composition
87 setAttribute( Qt::WA_PaintOnScreen, true );
89 /* The core can ask through a callback to show the video. */
91 connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
92 this, SLOT(SetSizing(unsigned int, unsigned int )),
93 Qt::BlockingQueuedConnection );
95 #warning This is broken. Fix it with a QEventLoop with a processEvents ()
96 connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
97 this, SLOT(SetSizing(unsigned int, unsigned int )) );
101 void VideoWidget::paintEvent(QPaintEvent *ev)
103 QFrame::paintEvent(ev);
105 XFlush( QX11Info::display() );
109 /* Kill the vout at Destruction */
110 VideoWidget::~VideoWidget()
112 vout_thread_t *p_vout = i_vout ?
113 (vout_thread_t *)vlc_object_get( i_vout ) : NULL;
117 if( !p_intf->psz_switch_intf )
119 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
120 vout_Control( p_vout, VOUT_REPARENT );
124 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
125 vout_Control( p_vout, VOUT_CLOSE );
127 vlc_object_release( p_vout );
132 * Request the video to avoid the conflicts
134 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
135 unsigned int *pi_width, unsigned int *pi_height )
137 msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
138 emit askVideoWidgetToShow( *pi_width, *pi_height );
141 msg_Dbg( p_intf, "embedded video already in use" );
144 i_vout = p_nvout->i_object_id;
146 msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );
148 return ( void* )winId();
151 /* Set the Widget to the correct Size */
152 /* Function has to be called by the parent
153 Parent has to care about resizing himself*/
154 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
156 msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
157 videoSize.rwidth() = w;
158 videoSize.rheight() = h;
159 if( isHidden() ) show();
160 updateGeometry(); // Needed for deinterlace
163 void VideoWidget::release( void *p_win )
165 msg_Dbg( p_intf, "Video is not needed anymore" );
167 videoSize.rwidth() = 0;
168 videoSize.rheight() = 0;
173 QSize VideoWidget::sizeHint() const
178 /**********************************************************************
179 * Background Widget. Show a simple image background. Currently,
180 * it's album art if present or cone.
181 **********************************************************************/
182 #define ICON_SIZE 128
183 #define MAX_BG_SIZE 400
184 #define MIN_BG_SIZE 128
186 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
187 :QWidget( NULL ), p_intf( _p_i )
189 /* We should use that one to take the more size it can */
190 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding);
192 /* A dark background */
193 setAutoFillBackground( true );
195 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
196 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
199 /* A cone in the middle */
201 label->setMargin( 5 );
202 label->setMaximumHeight( MAX_BG_SIZE );
203 label->setMaximumWidth( MAX_BG_SIZE );
204 label->setMinimumHeight( MIN_BG_SIZE );
205 label->setMinimumWidth( MIN_BG_SIZE );
206 if( QDate::currentDate().dayOfYear() >= 354 )
207 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
209 label->setPixmap( QPixmap( ":/vlc128.png" ) );
211 QGridLayout *backgroundLayout = new QGridLayout( this );
212 backgroundLayout->addWidget( label, 0, 1 );
213 backgroundLayout->setColumnStretch( 0, 1 );
214 backgroundLayout->setColumnStretch( 2, 1 );
216 CONNECT( THEMIM->getIM(), artChanged( QString ), this, updateArt( QString ) );
219 BackgroundWidget::~BackgroundWidget()
222 void BackgroundWidget::resizeEvent( QResizeEvent * event )
224 if( event->size().height() <= MIN_BG_SIZE )
230 void BackgroundWidget::updateArt( QString url )
234 if( QDate::currentDate().dayOfYear() >= 354 )
235 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
237 label->setPixmap( QPixmap( ":/vlc128.png" ) );
242 label->setPixmap( QPixmap( url ) );
246 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
248 QVLCMenu::PopupMenu( p_intf, true );
252 /**********************************************************************
253 * Visualization selector panel
254 **********************************************************************/
255 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
256 QFrame( NULL ), p_intf( _p_i )
258 QHBoxLayout *layout = new QHBoxLayout( this );
259 layout->setMargin( 0 );
260 QPushButton *prevButton = new QPushButton( "Prev" );
261 QPushButton *nextButton = new QPushButton( "Next" );
262 layout->addWidget( prevButton );
263 layout->addWidget( nextButton );
265 layout->addStretch( 10 );
266 layout->addWidget( new QLabel( qtr( "Current visualization" ) ) );
268 current = new QLabel( qtr( "None" ) );
269 layout->addWidget( current );
271 BUTTONACT( prevButton, prev() );
272 BUTTONACT( nextButton, next() );
275 setMaximumHeight( 35 );
278 VisualSelector::~VisualSelector()
281 void VisualSelector::prev()
283 char *psz_new = aout_VisualPrev( p_intf );
286 current->setText( qfu( psz_new ) );
291 void VisualSelector::next()
293 char *psz_new = aout_VisualNext( p_intf );
296 current->setText( qfu( psz_new ) );
302 /**********************************************************************
304 **********************************************************************/
306 #define setupSmallButton( aButton ){ \
307 aButton->setMaximumSize( QSize( 26, 26 ) ); \
308 aButton->setMinimumSize( QSize( 26, 26 ) ); \
309 aButton->setIconSize( QSize( 20, 20 ) ); }
311 /* init static variables in advanced controls */
312 mtime_t AdvControlsWidget::timeA = 0;
313 mtime_t AdvControlsWidget::timeB = 0;
315 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, bool b_fsCreation = false ) :
316 QFrame( NULL ), p_intf( _p_i )
318 QHBoxLayout *advLayout = new QHBoxLayout( this );
319 advLayout->setMargin( 0 );
320 advLayout->setSpacing( 0 );
321 advLayout->setAlignment( Qt::AlignBottom );
324 ABButton = new QPushButton;
325 setupSmallButton( ABButton );
326 advLayout->addWidget( ABButton );
327 BUTTON_SET_ACT_I( ABButton, "", atob_nob,
328 qtr( "Loop from point A to point B continuously.\nClick to set point A" ),
332 /* in FS controller we skip this, because we dont want to have it double
335 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
336 this, AtoBLoop( float, int, int ) );
337 /* set up synchronization between main controller and fs controller */
338 CONNECT( THEMIM->getIM(), advControlsSetIcon(), this, setIcon() );
339 connect( this, SIGNAL( timeChanged() ),
340 THEMIM->getIM(), SIGNAL( advControlsSetIcon()));
342 frameButton = new QPushButton( "Fr" );
343 frameButton->setMaximumSize( QSize( 26, 26 ) );
344 frameButton->setIconSize( QSize( 20, 20 ) );
345 advLayout->addWidget( frameButton );
346 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by frame" ), frame() );
350 recordButton = new QPushButton;
351 setupSmallButton( recordButton );
352 advLayout->addWidget( recordButton );
353 BUTTON_SET_ACT_I( recordButton, "", record,
354 qtr( "Record" ), record() );
356 /* Snapshot Button */
357 snapshotButton = new QPushButton;
358 setupSmallButton( snapshotButton );
359 advLayout->addWidget( snapshotButton );
360 BUTTON_SET_ACT_I( snapshotButton, "", snapshot,
361 qtr( "Take a snapshot" ), snapshot() );
364 AdvControlsWidget::~AdvControlsWidget()
367 void AdvControlsWidget::enableInput( bool enable )
370 if( THEMIM->getInput() != NULL )
372 input_item_t *p_item = input_GetItem( THEMIM->getInput() );
373 i_input_id = p_item->i_id;
375 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 void AdvControlsWidget::record()
463 input_thread_t *p_input = THEMIM->getInput();
466 /* This method won't work fine if the stream can't be cut anywhere */
467 if( var_Type( p_input, "record-toggle" ) == VLC_VAR_VOID )
468 var_TriggerCallback( p_input, "record-toggle" );
472 /* 'record' access-filter is not loaded, we open Save dialog */
473 input_item_t *p_item = input_GetItem( p_input );
477 char *psz = input_item_GetURI( p_item );
479 THEDP->streamingDialog( NULL, psz, true );
486 //FIXME Frame by frame function
487 void AdvControlsWidget::frame(){}
490 /*****************************
491 * DA Control Widget !
492 *****************************/
493 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
494 MainInterface *_p_mi,
498 QFrame( _p_mi ), p_intf( _p_i )
500 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
502 /** The main Slider **/
503 slider = new InputSlider( Qt::Horizontal, NULL );
504 /* Update the position when the IM has changed */
505 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
506 slider, setPosition( float, int, int ) );
507 /* And update the IM, when the position has changed */
508 CONNECT( slider, sliderDragged( float ),
509 THEMIM->getIM(), sliderUpdate( float ) );
511 /** Slower and faster Buttons **/
512 slowerButton = new QToolButton;
513 slowerButton->setAutoRaise( true );
514 slowerButton->setMaximumSize( QSize( 26, 20 ) );
516 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
518 fasterButton = new QToolButton;
519 fasterButton->setAutoRaise( true );
520 fasterButton->setMaximumSize( QSize( 26, 20 ) );
522 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
524 /* advanced Controls handling */
525 b_advancedVisible = b_advControls;
527 advControls = new AdvControlsWidget( p_intf, b_fsCreation );
528 if( !b_advancedVisible ) advControls->hide();
530 /** Disc and Menus handling */
531 discFrame = new QWidget( this );
533 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
534 discLayout->setSpacing( 0 );
535 discLayout->setMargin( 0 );
537 prevSectionButton = new QPushButton( discFrame );
538 setupSmallButton( prevSectionButton );
539 discLayout->addWidget( prevSectionButton );
541 menuButton = new QPushButton( discFrame );
542 setupSmallButton( menuButton );
543 discLayout->addWidget( menuButton );
545 nextSectionButton = new QPushButton( discFrame );
546 setupSmallButton( nextSectionButton );
547 discLayout->addWidget( nextSectionButton );
549 BUTTON_SET_IMG( prevSectionButton, "", dvd_prev, "" );
550 BUTTON_SET_IMG( nextSectionButton, "", dvd_next, "" );
551 BUTTON_SET_IMG( menuButton, "", dvd_menu, qtr( "Menu" ) );
555 /* Change the navigation button display when the IM navigation changes */
556 CONNECT( THEMIM->getIM(), navigationChanged( int ),
557 this, setNavigation( int ) );
558 /* Changes the IM navigation when triggered on the nav buttons */
559 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
561 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
563 CONNECT( menuButton, clicked(), THEMIM->getIM(),
568 * TODO: Merge with upper menu in a StackLayout
570 telexFrame = new QWidget( this );
571 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
572 telexLayout->setSpacing( 0 );
573 telexLayout->setMargin( 0 );
575 telexOn = new QPushButton;
576 setupSmallButton( telexOn );
577 telexLayout->addWidget( telexOn );
579 telexTransparent = new QPushButton;
580 setupSmallButton( telexTransparent );
581 telexLayout->addWidget( telexTransparent );
582 b_telexTransparent = false;
584 telexPage = new QSpinBox;
585 telexPage->setRange( 0, 999 );
586 telexPage->setValue( 100 );
587 telexPage->setAccelerated( true );
588 telexPage->setWrapping( true );
589 telexPage->setAlignment( Qt::AlignRight );
590 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
591 telexLayout->addWidget( telexPage );
593 telexFrame->hide(); /* default hidden */
595 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
596 telexGotoPage( int ) );
597 CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
598 telexPage, setValue( int ) );
600 BUTTON_SET_IMG( telexOn, "", tv, qtr( "Teletext on" ) );
602 CONNECT( telexOn, clicked(), THEMIM->getIM(),
603 telexToggleButtons() );
604 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
605 telexToggle( bool ) );
606 CONNECT( THEMIM->getIM(), toggleTelexButtons(),
607 this, toggleTeletext() );
608 b_telexEnabled = false;
609 telexTransparent->setEnabled( false );
610 telexPage->setEnabled( false );
612 BUTTON_SET_IMG( telexTransparent, "", tvtelx, qtr( "Teletext" ) );
613 CONNECT( telexTransparent, clicked( bool ),
614 THEMIM->getIM(), telexSetTransparency() );
615 CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
616 this, toggleTeletextTransparency() );
617 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
618 this, enableTeletext( bool ) );
621 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
622 sizePolicy.setHorizontalStretch( 0 );
623 sizePolicy.setVerticalStretch( 0 );
626 playButton = new QPushButton;
627 playButton->setSizePolicy( sizePolicy );
628 playButton->setMaximumSize( QSize( 36, 36 ) );
629 playButton->setMinimumSize( QSize( 36, 36 ) );
630 playButton->setIconSize( QSize( 30, 30 ) );
633 /** Prev + Stop + Next Block **/
634 controlButLayout = new QHBoxLayout;
635 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
638 QPushButton *prevButton = new QPushButton;
639 prevButton->setSizePolicy( sizePolicy );
640 setupSmallButton( prevButton );
642 controlButLayout->addWidget( prevButton );
645 QPushButton *stopButton = new QPushButton;
646 stopButton->setSizePolicy( sizePolicy );
647 setupSmallButton( stopButton );
649 controlButLayout->addWidget( stopButton );
652 QPushButton *nextButton = new QPushButton;
653 nextButton->setSizePolicy( sizePolicy );
654 setupSmallButton( nextButton );
656 controlButLayout->addWidget( nextButton );
658 /* Add this block to the main layout */
660 BUTTON_SET_ACT_I( playButton, "", play_b, qtr( I_PLAY_TOOLTIP ), play() );
661 BUTTON_SET_ACT_I( prevButton, "" , previous_b,
662 qtr( "Previous media in the playlist" ), prev() );
663 BUTTON_SET_ACT_I( nextButton, "", next_b,
664 qtr( "Next media in the playlist" ), next() );
665 BUTTON_SET_ACT_I( stopButton, "", stop_b, qtr( "Stop playback" ), stop() );
668 * Other first Line buttons
670 /** Fullscreen/Visualisation **/
671 fullscreenButton = new QPushButton;
672 BUTTON_SET_ACT_I( fullscreenButton, "", fullscreen,
673 qtr( "Toggle the video in fullscreen" ), fullscreen() );
674 setupSmallButton( fullscreenButton );
678 /** Playlist Button **/
679 playlistButton = new QPushButton;
680 setupSmallButton( playlistButton );
681 BUTTON_SET_IMG( playlistButton, "" , playlist, qtr( "Show playlist" ) );
682 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
684 /** extended Settings **/
685 extSettingsButton = new QPushButton;
686 BUTTON_SET_ACT_I( extSettingsButton, "", extended,
687 qtr( "Show extended settings" ), extSettings() );
688 setupSmallButton( extSettingsButton );
692 hVolLabel = new VolumeClickHandler( p_intf, this );
694 volMuteLabel = new QLabel;
695 volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
696 volMuteLabel->installEventFilter( hVolLabel );
700 volumeSlider = new SoundSlider( this,
701 config_GetInt( p_intf, "volume-step" ),
702 config_GetInt( p_intf, "qt-volume-complete" ),
703 config_GetPsz( p_intf, "qt-slider-colours" ) );
707 volumeSlider = new QSlider( this );
708 volumeSlider->setOrientation( Qt::Horizontal );
710 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
711 volumeSlider->setMinimumSize( QSize( 85, 30 ) );
712 volumeSlider->setFocusPolicy( Qt::NoFocus );
714 /* Set the volume from the config */
715 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
716 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
718 /* Force the update at build time in order to have a muted icon if needed */
719 updateVolume( volumeSlider->value() );
721 /* Volume control connection */
722 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
723 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
727 controlLayout = new QGridLayout( this );
729 controlLayout->setSpacing( 0 );
730 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
732 controlLayout->addWidget( slider, 0, 1, 1, 18 );
733 controlLayout->addWidget( slowerButton, 0, 0 );
734 controlLayout->addWidget( fasterButton, 0, 19 );
736 controlLayout->addWidget( discFrame, 1, 8, 2, 3, Qt::AlignBottom );
737 controlLayout->addWidget( telexFrame, 1, 8, 2, 5, Qt::AlignBottom );
739 controlLayout->addWidget( playButton, 2, 0, 2, 2, Qt::AlignBottom );
740 controlLayout->setColumnMinimumWidth( 2, 10 );
741 controlLayout->setColumnStretch( 2, 0 );
743 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
744 /* Column 6 is unused */
745 controlLayout->setColumnStretch( 6, 0 );
746 controlLayout->setColumnStretch( 7, 0 );
747 controlLayout->setColumnMinimumWidth( 7, 10 );
749 controlLayout->addWidget( fullscreenButton, 3, 8, Qt::AlignBottom );
750 controlLayout->addWidget( playlistButton, 3, 9, Qt::AlignBottom );
751 controlLayout->addWidget( extSettingsButton, 3, 10, Qt::AlignBottom );
752 controlLayout->setColumnStretch( 11, 0 ); /* telex alignment */
754 controlLayout->setColumnStretch( 12, 0 );
755 controlLayout->setColumnMinimumWidth( 12, 10 );
757 controlLayout->addWidget( advControls, 3, 13, 1, 3, Qt::AlignBottom );
759 controlLayout->setColumnStretch( 16, 10 );
760 controlLayout->setColumnMinimumWidth( 16, 10 );
762 controlLayout->addWidget( volMuteLabel, 3, 17, Qt::AlignBottom );
763 controlLayout->addWidget( volumeSlider, 3, 18, 1 , 2, Qt::AlignBottom );
769 ControlsWidget::~ControlsWidget()
772 void ControlsWidget::toggleTeletext()
774 bool b_enabled = THEMIM->teletextState();
777 telexTransparent->setEnabled( false );
778 telexPage->setEnabled( false );
779 b_telexEnabled = false;
783 telexTransparent->setEnabled( true );
784 telexPage->setEnabled( true );
785 b_telexEnabled = true;
789 void ControlsWidget::enableTeletext( bool b_enable )
791 telexFrame->setVisible( b_enable );
792 bool b_on = THEMIM->teletextState();
794 telexOn->setChecked( b_on );
795 telexTransparent->setEnabled( b_on );
796 telexPage->setEnabled( b_on );
797 b_telexEnabled = b_on;
800 void ControlsWidget::toggleTeletextTransparency()
802 if( b_telexTransparent )
804 telexTransparent->setIcon( QIcon( ":/tvtelx" ) );
805 telexTransparent->setToolTip( qtr( "Teletext" ) );
806 b_telexTransparent = false;
810 telexTransparent->setIcon( QIcon( ":/tvtelx-transparent" ) );
811 telexTransparent->setToolTip( qtr( "Transparent" ) );
812 b_telexTransparent = true;
816 void ControlsWidget::stop()
821 void ControlsWidget::play()
823 if( THEPL->current.i_size == 0 )
825 /* The playlist is empty, open a file requester */
826 THEDP->openFileDialog();
830 THEMIM->togglePlayPause();
833 void ControlsWidget::prev()
838 void ControlsWidget::next()
843 void ControlsWidget::setNavigation( int navigation )
845 #define HELP_PCH N_( "Previous chapter" )
846 #define HELP_NCH N_( "Next chapter" )
848 // 1 = chapter, 2 = title, 0 = no
849 if( navigation == 0 )
852 } else if( navigation == 1 ) {
853 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
854 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
858 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
859 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
865 static bool b_my_volume;
866 void ControlsWidget::updateVolume( int i_sliderVolume )
870 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
871 aout_VolumeSet( p_intf, i_res );
873 if( i_sliderVolume == 0 )
875 volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
876 volMuteLabel->setToolTip( qtr( "Unmute" ) );
880 if( i_sliderVolume < VOLUME_MAX / 3 )
881 volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
882 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
883 volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
884 else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
885 volMuteLabel->setToolTip( qtr( "Mute" ) );
888 void ControlsWidget::updateVolume()
891 audio_volume_t i_volume;
892 aout_VolumeGet( p_intf, &i_volume );
893 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
894 int i_gauge = volumeSlider->value();
896 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
899 volumeSlider->setValue( i_volume );
904 void ControlsWidget::updateInput()
906 /* Activate the interface buttons according to the presence of the input */
907 enableInput( THEMIM->getIM()->hasInput() );
908 enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
911 void ControlsWidget::setStatus( int status )
913 if( status == PLAYING_S ) /* Playing */
915 playButton->setIcon( QIcon( ":/pause_b" ) );
916 playButton->setToolTip( qtr( "Pause the playback" ) );
920 playButton->setIcon( QIcon( ":/play_b" ) );
921 playButton->setToolTip( qtr( I_PLAY_TOOLTIP ) );
927 * This functions toggle the fullscreen mode
928 * If there is no video, it should first activate Visualisations...
929 * This has also to be fixed in enableVideo()
931 void ControlsWidget::fullscreen()
933 vout_thread_t *p_vout =
934 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
937 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
938 vlc_object_release( p_vout );
942 void ControlsWidget::extSettings()
944 THEDP->extendedDialog();
947 void ControlsWidget::slower()
949 THEMIM->getIM()->slower();
952 void ControlsWidget::faster()
954 THEMIM->getIM()->faster();
957 void ControlsWidget::enableInput( bool enable )
959 slowerButton->setEnabled( enable );
960 slider->setEnabled( enable );
961 slider->setSliderPosition ( 0 );
962 fasterButton->setEnabled( enable );
964 /* Advanced Buttons too */
965 advControls->enableInput( enable );
968 void ControlsWidget::enableVideo( bool enable )
970 // TODO Later make the fullscreenButton toggle Visualisation and so on.
971 fullscreenButton->setEnabled( enable );
973 /* Advanced Buttons too */
974 advControls->enableVideo( enable );
977 void ControlsWidget::toggleAdvanced()
979 if( advControls && !b_advancedVisible )
982 b_advancedVisible = true;
987 b_advancedVisible = false;
989 emit advancedControlsToggled( b_advancedVisible );
993 /**********************************************************************
994 * Fullscrenn control widget
995 **********************************************************************/
996 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
997 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
998 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
999 i_mouse_last_x( -1 ), i_mouse_last_y( -1 ), b_mouse_over(false),
1000 b_slow_hide_begin(false), i_slow_hide_timeout(1),
1001 b_fullscreen( false ), i_hide_timeout( 1 ), p_vout(NULL)
1003 setWindowFlags( Qt::ToolTip );
1005 setFrameShape( QFrame::StyledPanel );
1006 setFrameStyle( QFrame::Sunken );
1007 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
1009 QGridLayout *fsLayout = new QGridLayout( this );
1010 fsLayout->setLayoutMargins( 5, 2, 5, 2, 5 );
1013 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
1014 slider->setMinimumWidth( 220 );
1015 fsLayout->addWidget( slowerButton, 0, 0 );
1016 fsLayout->addWidget( slider, 0, 1, 1, 9 );
1017 fsLayout->addWidget( fasterButton, 0, 10 );
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->setColumnStretch( 7, 10 );
1028 fsLayout->addWidget( volMuteLabel, 1, 8 );
1029 fsLayout->addWidget( volumeSlider, 1, 9, 1, 2 );
1032 p_hideTimer = new QTimer( this );
1033 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
1034 p_hideTimer->setSingleShot( true );
1036 /* slow hiding timer */
1037 #if HAVE_TRANSPARENCY
1038 p_slowHideTimer = new QTimer( this );
1039 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
1042 adjustSize (); /* need to get real width and height for moving */
1045 QDesktopWidget * p_desktop = QApplication::desktop();
1047 move( p_desktop->width() / 2 - width() / 2,
1048 p_desktop->height() - height() );
1051 setWindowOpacity( 0.0 );
1057 fullscreenButton->setIcon( QIcon( ":/defullscreen" ) );
1059 vlc_mutex_init_recursive( &lock );
1062 FullscreenControllerWidget::~FullscreenControllerWidget()
1065 vlc_mutex_destroy( &lock );
1069 * Show fullscreen controller
1071 void FullscreenControllerWidget::showFSC()
1075 // after quiting and going to fs, we need to call show()
1081 b_fscHidden = false;
1082 setWindowOpacity( 1.0 );
1088 #if HAVE_TRANSPARENCY
1089 setWindowOpacity( DEFAULT_OPACITY );
1094 * Hide fullscreen controller
1095 * FIXME: under windows it have to be done by moving out of screen
1096 * because hide() doesnt work
1098 void FullscreenControllerWidget::hideFSC()
1102 setWindowOpacity( 0.0 ); // simulate hidding
1109 * Plane to hide fullscreen controller
1111 void FullscreenControllerWidget::planHideFSC()
1113 vlc_mutex_lock( &lock );
1114 int i_timeout = i_hide_timeout;
1115 vlc_mutex_unlock( &lock );
1117 p_hideTimer->start( i_timeout );
1119 #if HAVE_TRANSPARENCY
1120 b_slow_hide_begin = true;
1121 i_slow_hide_timeout = i_timeout;
1122 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
1127 * Hidding fullscreen controller slowly
1128 * Linux: need composite manager
1129 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
1131 void FullscreenControllerWidget::slowHideFSC()
1133 #if HAVE_TRANSPARENCY
1134 if( b_slow_hide_begin )
1136 b_slow_hide_begin = false;
1138 p_slowHideTimer->stop();
1139 /* the last part of time divided to 100 pieces */
1140 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
1146 if ( windowOpacity() > 0.0 && !b_fscHidden )
1148 if ( windowOpacity() > 0.0 )
1151 /* we should use 0.01 because of 100 pieces ^^^
1152 but than it cannt be done in time */
1153 setWindowOpacity( windowOpacity() - 0.02 );
1156 if ( windowOpacity() <= 0.0 )
1157 p_slowHideTimer->stop();
1164 * events: show, hide, start timer for hidding
1166 void FullscreenControllerWidget::customEvent( QEvent *event )
1170 switch( event->type() )
1172 case FullscreenControlToggle_Type:
1173 vlc_mutex_lock( &lock );
1174 b_fs = b_fullscreen;
1175 vlc_mutex_unlock( &lock );
1183 p_hideTimer->stop();
1189 case FullscreenControlShow_Type:
1190 vlc_mutex_lock( &lock );
1191 b_fs = b_fullscreen;
1192 vlc_mutex_unlock( &lock );
1194 if( b_fs ) // FIXME I am not sure about that one
1197 case FullscreenControlHide_Type:
1200 case FullscreenControlPlanHide_Type:
1201 if( !b_mouse_over ) // Only if the mouse is not over FSC
1211 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1213 if ( event->buttons() == Qt::LeftButton )
1215 int i_moveX = event->globalX() - i_mouse_last_x;
1216 int i_moveY = event->globalY() - i_mouse_last_y;
1218 move( x() + i_moveX, y() + i_moveY );
1220 i_mouse_last_x = event->globalX();
1221 i_mouse_last_y = event->globalY();
1227 * store position of cursor
1229 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1231 i_mouse_last_x = event->globalX();
1232 i_mouse_last_y = event->globalY();
1236 * On mouse go above FSC
1238 void FullscreenControllerWidget::enterEvent( QEvent *event )
1240 b_mouse_over = true;
1242 p_hideTimer->stop();
1243 #if HAVE_TRANSPARENCY
1244 p_slowHideTimer->stop();
1249 * On mouse go out from FSC
1251 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1255 b_mouse_over = false;
1259 * When you get pressed key, send it to video output
1260 * FIXME: clearing focus by clearFocus() to not getting
1261 * key press events didnt work
1263 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1265 int i_vlck = qtEventToVLCKey( event );
1268 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1276 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object, const char *variable,
1277 vlc_value_t old_val, vlc_value_t new_val,
1280 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1281 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1283 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1288 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1289 vlc_value_t old_val, vlc_value_t new_val,
1292 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1295 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1296 QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1298 /* Plan hide event */
1299 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1300 QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1307 * It is called when video start
1309 void FullscreenControllerWidget::attachVout( vout_thread_t *p_nvout )
1311 assert( p_nvout && !p_vout );
1315 vlc_mutex_lock( &lock );
1316 var_AddCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this ); /* I miss a add and fire */
1317 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ), var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1318 vlc_mutex_unlock( &lock );
1321 * It is called after turn off video.
1323 void FullscreenControllerWidget::detachVout()
1327 var_DelCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this );
1328 vlc_mutex_lock( &lock );
1329 fullscreenChanged( p_vout, false, 0 );
1330 vlc_mutex_unlock( &lock );
1336 * Register and unregister callback for mouse moving
1338 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout, bool b_fs, int i_timeout )
1340 vlc_mutex_lock( &lock );
1341 if( b_fs && !b_fullscreen )
1343 b_fullscreen = true;
1344 i_hide_timeout = i_timeout;
1345 var_AddCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1347 else if( !b_fs && b_fullscreen )
1349 b_fullscreen = false;
1350 i_hide_timeout = i_timeout;
1351 var_DelCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1353 /* Force fs hidding */
1354 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1355 QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1357 vlc_mutex_unlock( &lock );
1360 /**********************************************************************
1361 * Speed control widget
1362 **********************************************************************/
1363 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1364 QFrame( NULL ), p_intf( _p_i )
1366 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1367 sizePolicy.setHorizontalStretch( 0 );
1368 sizePolicy.setVerticalStretch( 0 );
1370 speedSlider = new QSlider;
1371 speedSlider->setSizePolicy( sizePolicy );
1372 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1373 speedSlider->setOrientation( Qt::Vertical );
1374 speedSlider->setTickPosition( QSlider::TicksRight );
1376 speedSlider->setRange( -24, 24 );
1377 speedSlider->setSingleStep( 1 );
1378 speedSlider->setPageStep( 1 );
1379 speedSlider->setTickInterval( 12 );
1381 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1383 QToolButton *normalSpeedButton = new QToolButton( this );
1384 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1385 normalSpeedButton->setAutoRaise( true );
1386 normalSpeedButton->setText( "1x" );
1387 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1389 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1391 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1392 speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
1393 speedControlLayout->setSpacing( 4 );
1394 speedControlLayout->addWidget( speedSlider );
1395 speedControlLayout->addWidget( normalSpeedButton );
1396 setLayout( speedControlLayout );
1399 SpeedControlWidget::~SpeedControlWidget()
1402 void SpeedControlWidget::setEnable( bool b_enable )
1404 speedSlider->setEnabled( b_enable );
1407 void SpeedControlWidget::updateControls( int rate )
1409 if( speedSlider->isSliderDown() )
1411 //We don't want to change anything if the user is using the slider
1415 double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
1416 int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
1418 if( sliderValue < speedSlider->minimum() )
1420 sliderValue = speedSlider->minimum();
1422 else if( sliderValue > speedSlider->maximum() )
1424 sliderValue = speedSlider->maximum();
1427 //Block signals to avoid feedback loop
1428 speedSlider->blockSignals( true );
1429 speedSlider->setValue( sliderValue );
1430 speedSlider->blockSignals( false );
1433 void SpeedControlWidget::updateRate( int sliderValue )
1435 double speed = pow( 2, (double)sliderValue / 12 );
1436 int rate = INPUT_RATE_DEFAULT / speed;
1438 THEMIM->getIM()->setRate(rate);
1441 void SpeedControlWidget::resetRate()
1443 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);