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( p_intf->p_libvlc, 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( input_item_t* ),
209 this, updateArt( input_item_t* ) );
212 BackgroundWidget::~BackgroundWidget()
215 void BackgroundWidget::resizeEvent( QResizeEvent * event )
217 if( event->size().height() <= MIN_BG_SIZE )
223 void BackgroundWidget::updateArt( input_item_t *p_item )
228 char *psz_art = input_item_GetArtURL( p_item );
235 if( QDate::currentDate().dayOfYear() >= 354 )
236 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
238 label->setPixmap( QPixmap( ":/vlc128.png" ) );
242 url = url.replace( "file://", QString("" ) );
243 /* Taglib seems to define a attachment://, It won't work yet */
244 url = url.replace( "attachment://", QString("" ) );
245 label->setPixmap( QPixmap( url ) );
249 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
251 QVLCMenu::PopupMenu( p_intf, true );
255 /**********************************************************************
256 * Visualization selector panel
257 **********************************************************************/
258 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
259 QFrame( NULL ), p_intf( _p_i )
261 QHBoxLayout *layout = new QHBoxLayout( this );
262 layout->setMargin( 0 );
263 QPushButton *prevButton = new QPushButton( "Prev" );
264 QPushButton *nextButton = new QPushButton( "Next" );
265 layout->addWidget( prevButton );
266 layout->addWidget( nextButton );
268 layout->addStretch( 10 );
269 layout->addWidget( new QLabel( qtr( "Current visualization" ) ) );
271 current = new QLabel( qtr( "None" ) );
272 layout->addWidget( current );
274 BUTTONACT( prevButton, prev() );
275 BUTTONACT( nextButton, next() );
278 setMaximumHeight( 35 );
281 VisualSelector::~VisualSelector()
284 void VisualSelector::prev()
286 char *psz_new = aout_VisualPrev( p_intf );
289 current->setText( qfu( psz_new ) );
294 void VisualSelector::next()
296 char *psz_new = aout_VisualNext( p_intf );
299 current->setText( qfu( psz_new ) );
305 /**********************************************************************
307 **********************************************************************/
309 #define setupSmallButton( aButton ){ \
310 aButton->setMaximumSize( QSize( 26, 26 ) ); \
311 aButton->setMinimumSize( QSize( 26, 26 ) ); \
312 aButton->setIconSize( QSize( 20, 20 ) ); }
314 /* init static variables in advanced controls */
315 mtime_t AdvControlsWidget::timeA = 0;
316 mtime_t AdvControlsWidget::timeB = 0;
318 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, bool b_fsCreation = false ) :
319 QFrame( NULL ), p_intf( _p_i )
321 QHBoxLayout *advLayout = new QHBoxLayout( this );
322 advLayout->setMargin( 0 );
323 advLayout->setSpacing( 0 );
324 advLayout->setAlignment( Qt::AlignBottom );
327 ABButton = new QPushButton;
328 setupSmallButton( ABButton );
329 advLayout->addWidget( ABButton );
330 BUTTON_SET_ACT_I( ABButton, "", atob_nob,
331 qtr( "Loop from point A to point B continuously.\nClick to set point A" ),
335 /* in FS controller we skip this, because we dont want to have it double
338 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
339 this, AtoBLoop( float, int, int ) );
340 /* set up synchronization between main controller and fs controller */
341 CONNECT( THEMIM->getIM(), advControlsSetIcon(), this, setIcon() );
342 connect( this, SIGNAL( timeChanged() ),
343 THEMIM->getIM(), SIGNAL( advControlsSetIcon()));
345 frameButton = new QPushButton( "Fr" );
346 frameButton->setMaximumSize( QSize( 26, 26 ) );
347 frameButton->setIconSize( QSize( 20, 20 ) );
348 advLayout->addWidget( frameButton );
349 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by frame" ), frame() );
354 recordButton = new QPushButton;
355 setupSmallButton( recordButton );
356 advLayout->addWidget( recordButton );
357 BUTTON_SET_ACT_I( recordButton, "", record,
358 qtr( "Record" ), record() );
361 /* Snapshot Button */
362 snapshotButton = new QPushButton;
363 setupSmallButton( snapshotButton );
364 advLayout->addWidget( snapshotButton );
365 BUTTON_SET_ACT_I( snapshotButton, "", snapshot,
366 qtr( "Take a snapshot" ), snapshot() );
369 AdvControlsWidget::~AdvControlsWidget()
372 void AdvControlsWidget::enableInput( bool enable )
375 if( THEMIM->getInput() != NULL )
377 input_item_t *p_item = input_GetItem( THEMIM->getInput() );
378 i_input_id = p_item->i_id;
380 recordButton->setVisible( var_GetBool( THEMIM->getInput(), "can-record" ) );
384 recordButton->setVisible( false );
388 ABButton->setEnabled( enable );
390 recordButton->setEnabled( enable );
393 if( enable && ( i_last_input_id != i_input_id ) )
396 i_last_input_id = i_input_id;
401 void AdvControlsWidget::enableVideo( bool enable )
403 snapshotButton->setEnabled( enable );
405 frameButton->setEnabled( enable );
409 void AdvControlsWidget::snapshot()
411 vout_thread_t *p_vout =
412 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
415 vout_Control( p_vout, VOUT_SNAPSHOT );
416 vlc_object_release( p_vout );
420 /* Function called when the button is clicked() */
421 void AdvControlsWidget::fromAtoB()
425 timeA = var_GetTime( THEMIM->getInput(), "time" );
431 timeB = var_GetTime( THEMIM->getInput(), "time" );
432 var_SetTime( THEMIM->getInput(), "time" , timeA );
441 /* setting/synchro icons after click on main or fs controller */
442 void AdvControlsWidget::setIcon()
444 if( !timeA && !timeB)
446 ABButton->setIcon( QIcon( ":/atob_nob" ) );
447 ABButton->setToolTip( qtr( "Loop from point A to point B continuously\nClick to set point A" ) );
449 else if( timeA && !timeB )
451 ABButton->setIcon( QIcon( ":/atob_noa" ) );
452 ABButton->setToolTip( qtr( "Click to set point B" ) );
454 else if( timeA && timeB )
456 ABButton->setIcon( QIcon( ":/atob" ) );
457 ABButton->setToolTip( qtr( "Stop the A to B loop" ) );
461 /* Function called regularly when in an AtoB loop */
462 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
466 if( ( i_time >= (int)( timeB/1000000 ) )
467 || ( i_time < (int)( timeA/1000000 ) ) )
468 var_SetTime( THEMIM->getInput(), "time" , timeA );
472 // TODO: On-the-fly record needs to be reimplemented
473 void AdvControlsWidget::record()
475 input_thread_t *p_input = THEMIM->getInput();
478 /* This method won't work fine if the stream can't be cut anywhere */
479 const bool b_recording = var_GetBool( p_input, "record" );
480 var_SetBool( p_input, "record", !b_recording );
484 /* 'record' access-filter is not loaded, we open Save dialog */
485 input_item_t *p_item = input_GetItem( p_input );
489 char *psz = input_item_GetURI( p_item );
491 THEDP->streamingDialog( NULL, psz, true );
498 //FIXME Frame by frame function
499 void AdvControlsWidget::frame(){}
502 /*****************************
503 * DA Control Widget !
504 *****************************/
505 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
506 MainInterface *_p_mi,
510 QFrame( _p_mi ), p_intf( _p_i )
512 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
514 /** The main Slider **/
515 slider = new InputSlider( Qt::Horizontal, NULL );
516 /* Update the position when the IM has changed */
517 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
518 slider, setPosition( float, int, int ) );
519 /* And update the IM, when the position has changed */
520 CONNECT( slider, sliderDragged( float ),
521 THEMIM->getIM(), sliderUpdate( float ) );
523 /** Slower and faster Buttons **/
524 slowerButton = new QToolButton;
525 slowerButton->setAutoRaise( true );
526 slowerButton->setMaximumSize( QSize( 26, 20 ) );
528 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
530 fasterButton = new QToolButton;
531 fasterButton->setAutoRaise( true );
532 fasterButton->setMaximumSize( QSize( 26, 20 ) );
534 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
536 /* advanced Controls handling */
537 b_advancedVisible = b_advControls;
539 advControls = new AdvControlsWidget( p_intf, b_fsCreation );
540 if( !b_advancedVisible ) advControls->hide();
542 /** Disc and Menus handling */
543 discFrame = new QWidget( this );
545 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
546 discLayout->setSpacing( 0 );
547 discLayout->setMargin( 0 );
549 prevSectionButton = new QPushButton( discFrame );
550 setupSmallButton( prevSectionButton );
551 discLayout->addWidget( prevSectionButton );
553 menuButton = new QPushButton( discFrame );
554 setupSmallButton( menuButton );
555 discLayout->addWidget( menuButton );
557 nextSectionButton = new QPushButton( discFrame );
558 setupSmallButton( nextSectionButton );
559 discLayout->addWidget( nextSectionButton );
561 BUTTON_SET_IMG( prevSectionButton, "", dvd_prev, "" );
562 BUTTON_SET_IMG( nextSectionButton, "", dvd_next, "" );
563 BUTTON_SET_IMG( menuButton, "", dvd_menu, qtr( "Menu" ) );
567 /* Change the navigation button display when the IM navigation changes */
568 CONNECT( THEMIM->getIM(), navigationChanged( int ),
569 this, setNavigation( int ) );
570 /* Changes the IM navigation when triggered on the nav buttons */
571 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
573 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
575 CONNECT( menuButton, clicked(), THEMIM->getIM(),
580 * TODO: Merge with upper menu in a StackLayout
582 telexFrame = new QWidget( this );
583 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
584 telexLayout->setSpacing( 0 );
585 telexLayout->setMargin( 0 );
587 telexOn = new QPushButton;
588 setupSmallButton( telexOn );
589 telexLayout->addWidget( telexOn );
591 telexTransparent = new QPushButton;
592 setupSmallButton( telexTransparent );
593 telexLayout->addWidget( telexTransparent );
594 b_telexTransparent = false;
596 telexPage = new QSpinBox;
597 telexPage->setRange( 0, 999 );
598 telexPage->setValue( 100 );
599 telexPage->setAccelerated( true );
600 telexPage->setWrapping( true );
601 telexPage->setAlignment( Qt::AlignRight );
602 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
603 telexLayout->addWidget( telexPage );
605 telexFrame->hide(); /* default hidden */
607 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
608 telexGotoPage( int ) );
609 CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
610 telexPage, setValue( int ) );
612 BUTTON_SET_IMG( telexOn, "", tv, qtr( "Teletext on" ) );
614 CONNECT( telexOn, clicked(), THEMIM->getIM(),
615 telexToggleButtons() );
616 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
617 telexToggle( bool ) );
618 CONNECT( THEMIM->getIM(), toggleTelexButtons(),
619 this, toggleTeletext() );
620 b_telexEnabled = false;
621 telexTransparent->setEnabled( false );
622 telexPage->setEnabled( false );
624 BUTTON_SET_IMG( telexTransparent, "", tvtelx, qtr( "Teletext" ) );
625 CONNECT( telexTransparent, clicked( bool ),
626 THEMIM->getIM(), telexSetTransparency() );
627 CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
628 this, toggleTeletextTransparency() );
629 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
630 this, enableTeletext( bool ) );
633 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
634 sizePolicy.setHorizontalStretch( 0 );
635 sizePolicy.setVerticalStretch( 0 );
638 playButton = new QPushButton;
639 playButton->setSizePolicy( sizePolicy );
640 playButton->setMaximumSize( QSize( 36, 36 ) );
641 playButton->setMinimumSize( QSize( 36, 36 ) );
642 playButton->setIconSize( QSize( 30, 30 ) );
645 /** Prev + Stop + Next Block **/
646 controlButLayout = new QHBoxLayout;
647 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
650 QPushButton *prevButton = new QPushButton;
651 prevButton->setSizePolicy( sizePolicy );
652 setupSmallButton( prevButton );
654 controlButLayout->addWidget( prevButton );
657 QPushButton *stopButton = new QPushButton;
658 stopButton->setSizePolicy( sizePolicy );
659 setupSmallButton( stopButton );
661 controlButLayout->addWidget( stopButton );
664 QPushButton *nextButton = new QPushButton;
665 nextButton->setSizePolicy( sizePolicy );
666 setupSmallButton( nextButton );
668 controlButLayout->addWidget( nextButton );
670 /* Add this block to the main layout */
672 BUTTON_SET_ACT_I( playButton, "", play_b, qtr( I_PLAY_TOOLTIP ), play() );
673 BUTTON_SET_ACT_I( prevButton, "" , previous_b,
674 qtr( "Previous media in the playlist" ), prev() );
675 BUTTON_SET_ACT_I( nextButton, "", next_b,
676 qtr( "Next media in the playlist" ), next() );
677 BUTTON_SET_ACT_I( stopButton, "", stop_b, qtr( "Stop playback" ), stop() );
680 * Other first Line buttons
683 CONNECT( THEMIM->getIM(), voutChanged(bool), this, enableVideo(bool) );
685 /** Fullscreen/Visualisation **/
686 fullscreenButton = new QPushButton;
687 BUTTON_SET_ACT_I( fullscreenButton, "", fullscreen,
688 qtr( "Toggle the video in fullscreen" ), fullscreen() );
689 setupSmallButton( fullscreenButton );
693 /** Playlist Button **/
694 playlistButton = new QPushButton;
695 setupSmallButton( playlistButton );
696 BUTTON_SET_IMG( playlistButton, "" , playlist, qtr( "Show playlist" ) );
697 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
699 /** extended Settings **/
700 extSettingsButton = new QPushButton;
701 BUTTON_SET_ACT_I( extSettingsButton, "", extended,
702 qtr( "Show extended settings" ), extSettings() );
703 setupSmallButton( extSettingsButton );
707 hVolLabel = new VolumeClickHandler( p_intf, this );
709 volMuteLabel = new QLabel;
710 volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
711 volMuteLabel->installEventFilter( hVolLabel );
715 volumeSlider = new SoundSlider( this,
716 config_GetInt( p_intf, "volume-step" ),
717 config_GetInt( p_intf, "qt-volume-complete" ),
718 config_GetPsz( p_intf, "qt-slider-colours" ) );
722 volumeSlider = new QSlider( this );
723 volumeSlider->setOrientation( Qt::Horizontal );
725 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
726 volumeSlider->setMinimumSize( QSize( 85, 30 ) );
727 volumeSlider->setFocusPolicy( Qt::NoFocus );
729 /* Set the volume from the config */
730 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
731 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
733 /* Force the update at build time in order to have a muted icon if needed */
734 updateVolume( volumeSlider->value() );
736 /* Volume control connection */
737 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
738 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
742 controlLayout = new QGridLayout( this );
744 controlLayout->setSpacing( 0 );
745 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
747 controlLayout->addWidget( slider, 0, 1, 1, 18 );
748 controlLayout->addWidget( slowerButton, 0, 0 );
749 controlLayout->addWidget( fasterButton, 0, 19 );
751 controlLayout->addWidget( discFrame, 1, 8, 2, 3, Qt::AlignBottom );
752 controlLayout->addWidget( telexFrame, 1, 8, 2, 5, Qt::AlignBottom );
754 controlLayout->addWidget( playButton, 2, 0, 2, 2, Qt::AlignBottom );
755 controlLayout->setColumnMinimumWidth( 2, 10 );
756 controlLayout->setColumnStretch( 2, 0 );
758 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
759 /* Column 6 is unused */
760 controlLayout->setColumnStretch( 6, 0 );
761 controlLayout->setColumnStretch( 7, 0 );
762 controlLayout->setColumnMinimumWidth( 7, 10 );
764 controlLayout->addWidget( fullscreenButton, 3, 8, Qt::AlignBottom );
765 controlLayout->addWidget( playlistButton, 3, 9, Qt::AlignBottom );
766 controlLayout->addWidget( extSettingsButton, 3, 10, Qt::AlignBottom );
767 controlLayout->setColumnStretch( 11, 0 ); /* telex alignment */
769 controlLayout->setColumnStretch( 12, 0 );
770 controlLayout->setColumnMinimumWidth( 12, 10 );
772 controlLayout->addWidget( advControls, 3, 13, 1, 3, Qt::AlignBottom );
774 controlLayout->setColumnStretch( 16, 10 );
775 controlLayout->setColumnMinimumWidth( 16, 10 );
777 controlLayout->addWidget( volMuteLabel, 3, 17, Qt::AlignBottom );
778 controlLayout->addWidget( volumeSlider, 3, 18, 1 , 2, Qt::AlignBottom );
784 ControlsWidget::~ControlsWidget()
787 void ControlsWidget::toggleTeletext()
789 bool b_enabled = THEMIM->teletextState();
792 telexTransparent->setEnabled( false );
793 telexPage->setEnabled( false );
794 b_telexEnabled = false;
798 telexTransparent->setEnabled( true );
799 telexPage->setEnabled( true );
800 b_telexEnabled = true;
804 void ControlsWidget::enableTeletext( bool b_enable )
806 telexFrame->setVisible( b_enable );
807 bool b_on = THEMIM->teletextState();
809 telexOn->setChecked( b_on );
810 telexTransparent->setEnabled( b_on );
811 telexPage->setEnabled( b_on );
812 b_telexEnabled = b_on;
815 void ControlsWidget::toggleTeletextTransparency()
817 if( b_telexTransparent )
819 telexTransparent->setIcon( QIcon( ":/tvtelx" ) );
820 telexTransparent->setToolTip( qtr( "Teletext" ) );
821 b_telexTransparent = false;
825 telexTransparent->setIcon( QIcon( ":/tvtelx-trans" ) );
826 telexTransparent->setToolTip( qtr( "Transparent" ) );
827 b_telexTransparent = true;
831 void ControlsWidget::stop()
836 void ControlsWidget::play()
838 if( THEPL->current.i_size == 0 )
840 /* The playlist is empty, open a file requester */
841 THEDP->openFileDialog();
845 THEMIM->togglePlayPause();
848 void ControlsWidget::prev()
853 void ControlsWidget::next()
858 void ControlsWidget::setNavigation( int navigation )
860 #define HELP_PCH N_( "Previous chapter" )
861 #define HELP_NCH N_( "Next chapter" )
863 // 1 = chapter, 2 = title, 0 = no
864 if( navigation == 0 )
867 } else if( navigation == 1 ) {
868 prevSectionButton->setToolTip( qtr( HELP_PCH ) );
869 nextSectionButton->setToolTip( qtr( HELP_NCH ) );
873 prevSectionButton->setToolTip( qtr( HELP_PCH ) );
874 nextSectionButton->setToolTip( qtr( HELP_NCH ) );
880 static bool b_my_volume;
881 void ControlsWidget::updateVolume( int i_sliderVolume )
885 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
886 aout_VolumeSet( p_intf, i_res );
888 if( i_sliderVolume == 0 )
890 volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
891 volMuteLabel->setToolTip( qtr( "Unmute" ) );
895 if( i_sliderVolume < VOLUME_MAX / 3 )
896 volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
897 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
898 volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
899 else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
900 volMuteLabel->setToolTip( qtr( "Mute" ) );
903 void ControlsWidget::updateVolume()
906 audio_volume_t i_volume;
907 aout_VolumeGet( p_intf, &i_volume );
908 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
909 int i_gauge = volumeSlider->value();
911 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
914 volumeSlider->setValue( i_volume );
919 void ControlsWidget::updateInput()
921 /* Activate the interface buttons according to the presence of the input */
922 enableInput( THEMIM->getIM()->hasInput() );
923 enableVideo( THEMIM->getIM()->hasVideo() );
926 void ControlsWidget::setStatus( int status )
928 if( status == PLAYING_S ) /* Playing */
930 playButton->setIcon( QIcon( ":/pause_b" ) );
931 playButton->setToolTip( qtr( "Pause the playback" ) );
935 playButton->setIcon( QIcon( ":/play_b" ) );
936 playButton->setToolTip( qtr( I_PLAY_TOOLTIP ) );
942 * This functions toggle the fullscreen mode
943 * If there is no video, it should first activate Visualisations...
944 * This has also to be fixed in enableVideo()
946 void ControlsWidget::fullscreen()
948 vout_thread_t *p_vout =
949 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
952 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
953 vlc_object_release( p_vout );
957 void ControlsWidget::extSettings()
959 THEDP->extendedDialog();
962 void ControlsWidget::slower()
964 THEMIM->getIM()->slower();
967 void ControlsWidget::faster()
969 THEMIM->getIM()->faster();
972 void ControlsWidget::enableInput( bool enable )
974 slowerButton->setEnabled( enable );
975 slider->setEnabled( enable );
976 slider->setSliderPosition ( 0 );
977 fasterButton->setEnabled( enable );
979 /* Advanced Buttons too */
980 advControls->enableInput( enable );
983 void ControlsWidget::enableVideo( bool enable )
985 // TODO Later make the fullscreenButton toggle Visualisation and so on.
986 fullscreenButton->setEnabled( enable );
988 /* Advanced Buttons too */
989 advControls->enableVideo( enable );
992 void ControlsWidget::toggleAdvanced()
994 if( advControls && !b_advancedVisible )
997 b_advancedVisible = true;
1001 advControls->hide();
1002 b_advancedVisible = false;
1004 emit advancedControlsToggled( b_advancedVisible );
1007 /**********************************************************************
1008 * Fullscrenn control widget
1009 **********************************************************************/
1010 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
1011 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
1012 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
1013 i_mouse_last_x( -1 ), i_mouse_last_y( -1 ), b_mouse_over(false),
1014 b_slow_hide_begin(false), i_slow_hide_timeout(1),
1015 b_fullscreen( false ), i_hide_timeout( 1 ), p_vout(NULL)
1017 setWindowFlags( Qt::ToolTip );
1019 setFrameShape( QFrame::StyledPanel );
1020 setFrameStyle( QFrame::Sunken );
1021 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
1023 QGridLayout *fsLayout = new QGridLayout( this );
1024 fsLayout->setLayoutMargins( 5, 2, 5, 2, 5 );
1027 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
1028 slider->setMinimumWidth( 220 );
1029 fsLayout->addWidget( slowerButton, 0, 0 );
1030 fsLayout->addWidget( slider, 0, 1, 1, 9 );
1031 fsLayout->addWidget( fasterButton, 0, 10 );
1033 fsLayout->addWidget( playButton, 1, 0, 1, 2 );
1034 fsLayout->addLayout( controlButLayout, 1, 2 );
1036 fsLayout->addWidget( discFrame, 1, 3 );
1037 fsLayout->addWidget( telexFrame, 1, 4 );
1038 fsLayout->addWidget( fullscreenButton, 1, 5 );
1039 fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
1041 fsLayout->setColumnStretch( 7, 10 );
1042 fsLayout->addWidget( volMuteLabel, 1, 8 );
1043 fsLayout->addWidget( volumeSlider, 1, 9, 1, 2 );
1046 p_hideTimer = new QTimer( this );
1047 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
1048 p_hideTimer->setSingleShot( true );
1050 /* slow hiding timer */
1051 #if HAVE_TRANSPARENCY
1052 p_slowHideTimer = new QTimer( this );
1053 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
1056 adjustSize (); /* need to get real width and height for moving */
1059 QDesktopWidget * p_desktop = QApplication::desktop();
1061 move( p_desktop->width() / 2 - width() / 2,
1062 p_desktop->height() - height() );
1065 setWindowOpacity( 0.0 );
1071 fullscreenButton->setIcon( QIcon( ":/defullscreen" ) );
1073 vlc_mutex_init_recursive( &lock );
1076 FullscreenControllerWidget::~FullscreenControllerWidget()
1079 vlc_mutex_destroy( &lock );
1083 * Show fullscreen controller
1085 void FullscreenControllerWidget::showFSC()
1089 // after quiting and going to fs, we need to call show()
1095 b_fscHidden = false;
1096 setWindowOpacity( 1.0 );
1102 #if HAVE_TRANSPARENCY
1103 setWindowOpacity( DEFAULT_OPACITY );
1108 * Hide fullscreen controller
1109 * FIXME: under windows it have to be done by moving out of screen
1110 * because hide() doesnt work
1112 void FullscreenControllerWidget::hideFSC()
1116 setWindowOpacity( 0.0 ); // simulate hidding
1123 * Plane to hide fullscreen controller
1125 void FullscreenControllerWidget::planHideFSC()
1127 vlc_mutex_lock( &lock );
1128 int i_timeout = i_hide_timeout;
1129 vlc_mutex_unlock( &lock );
1131 p_hideTimer->start( i_timeout );
1133 #if HAVE_TRANSPARENCY
1134 b_slow_hide_begin = true;
1135 i_slow_hide_timeout = i_timeout;
1136 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
1141 * Hidding fullscreen controller slowly
1142 * Linux: need composite manager
1143 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
1145 void FullscreenControllerWidget::slowHideFSC()
1147 #if HAVE_TRANSPARENCY
1148 if( b_slow_hide_begin )
1150 b_slow_hide_begin = false;
1152 p_slowHideTimer->stop();
1153 /* the last part of time divided to 100 pieces */
1154 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
1160 if ( windowOpacity() > 0.0 && !b_fscHidden )
1162 if ( windowOpacity() > 0.0 )
1165 /* we should use 0.01 because of 100 pieces ^^^
1166 but than it cannt be done in time */
1167 setWindowOpacity( windowOpacity() - 0.02 );
1170 if ( windowOpacity() <= 0.0 )
1171 p_slowHideTimer->stop();
1178 * events: show, hide, start timer for hidding
1180 void FullscreenControllerWidget::customEvent( QEvent *event )
1184 switch( event->type() )
1186 case FullscreenControlToggle_Type:
1187 vlc_mutex_lock( &lock );
1188 b_fs = b_fullscreen;
1189 vlc_mutex_unlock( &lock );
1197 p_hideTimer->stop();
1203 case FullscreenControlShow_Type:
1204 vlc_mutex_lock( &lock );
1205 b_fs = b_fullscreen;
1206 vlc_mutex_unlock( &lock );
1208 if( b_fs ) // FIXME I am not sure about that one
1211 case FullscreenControlHide_Type:
1214 case FullscreenControlPlanHide_Type:
1215 if( !b_mouse_over ) // Only if the mouse is not over FSC
1225 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1227 if ( event->buttons() == Qt::LeftButton )
1229 int i_moveX = event->globalX() - i_mouse_last_x;
1230 int i_moveY = event->globalY() - i_mouse_last_y;
1232 move( x() + i_moveX, y() + i_moveY );
1234 i_mouse_last_x = event->globalX();
1235 i_mouse_last_y = event->globalY();
1241 * store position of cursor
1243 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1245 i_mouse_last_x = event->globalX();
1246 i_mouse_last_y = event->globalY();
1250 * On mouse go above FSC
1252 void FullscreenControllerWidget::enterEvent( QEvent *event )
1254 b_mouse_over = true;
1256 p_hideTimer->stop();
1257 #if HAVE_TRANSPARENCY
1258 p_slowHideTimer->stop();
1263 * On mouse go out from FSC
1265 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1269 b_mouse_over = false;
1273 * When you get pressed key, send it to video output
1274 * FIXME: clearing focus by clearFocus() to not getting
1275 * key press events didnt work
1277 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1279 int i_vlck = qtEventToVLCKey( event );
1282 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1290 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object, const char *variable,
1291 vlc_value_t old_val, vlc_value_t new_val,
1294 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1295 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1297 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1302 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1303 vlc_value_t old_val, vlc_value_t new_val,
1306 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1309 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1310 QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1312 /* Plan hide event */
1313 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1314 QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1321 * It is called when video start
1323 void FullscreenControllerWidget::attachVout( vout_thread_t *p_nvout )
1325 assert( p_nvout && !p_vout );
1329 vlc_mutex_lock( &lock );
1330 var_AddCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this ); /* I miss a add and fire */
1331 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ), var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1332 vlc_mutex_unlock( &lock );
1335 * It is called after turn off video.
1337 void FullscreenControllerWidget::detachVout()
1341 var_DelCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this );
1342 vlc_mutex_lock( &lock );
1343 fullscreenChanged( p_vout, false, 0 );
1344 vlc_mutex_unlock( &lock );
1350 * Register and unregister callback for mouse moving
1352 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout, bool b_fs, int i_timeout )
1354 vlc_mutex_lock( &lock );
1355 if( b_fs && !b_fullscreen )
1357 b_fullscreen = true;
1358 i_hide_timeout = i_timeout;
1359 var_AddCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1361 else if( !b_fs && b_fullscreen )
1363 b_fullscreen = false;
1364 i_hide_timeout = i_timeout;
1365 var_DelCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1367 /* Force fs hidding */
1368 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1369 QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1371 vlc_mutex_unlock( &lock );
1374 /**********************************************************************
1375 * Speed control widget
1376 **********************************************************************/
1377 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1378 QFrame( NULL ), p_intf( _p_i )
1380 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1381 sizePolicy.setHorizontalStretch( 0 );
1382 sizePolicy.setVerticalStretch( 0 );
1384 speedSlider = new QSlider;
1385 speedSlider->setSizePolicy( sizePolicy );
1386 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1387 speedSlider->setOrientation( Qt::Vertical );
1388 speedSlider->setTickPosition( QSlider::TicksRight );
1390 speedSlider->setRange( -24, 24 );
1391 speedSlider->setSingleStep( 1 );
1392 speedSlider->setPageStep( 1 );
1393 speedSlider->setTickInterval( 12 );
1395 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1397 QToolButton *normalSpeedButton = new QToolButton( this );
1398 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1399 normalSpeedButton->setAutoRaise( true );
1400 normalSpeedButton->setText( "1x" );
1401 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1403 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1405 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1406 speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
1407 speedControlLayout->setSpacing( 4 );
1408 speedControlLayout->addWidget( speedSlider );
1409 speedControlLayout->addWidget( normalSpeedButton );
1410 setLayout( speedControlLayout );
1413 SpeedControlWidget::~SpeedControlWidget()
1416 void SpeedControlWidget::setEnable( bool b_enable )
1418 speedSlider->setEnabled( b_enable );
1421 void SpeedControlWidget::updateControls( int rate )
1423 if( speedSlider->isSliderDown() )
1425 //We don't want to change anything if the user is using the slider
1429 double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
1430 int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
1432 if( sliderValue < speedSlider->minimum() )
1434 sliderValue = speedSlider->minimum();
1436 else if( sliderValue > speedSlider->maximum() )
1438 sliderValue = speedSlider->maximum();
1441 //Block signals to avoid feedback loop
1442 speedSlider->blockSignals( true );
1443 speedSlider->setValue( sliderValue );
1444 speedSlider->blockSignals( false );
1447 void SpeedControlWidget::updateRate( int sliderValue )
1449 double speed = pow( 2, (double)sliderValue / 12 );
1450 int rate = INPUT_RATE_DEFAULT / speed;
1452 THEMIM->getIM()->setRate(rate);
1455 void SpeedControlWidget::resetRate()
1457 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
1462 static int downloadCoverCallback( vlc_object_t *p_this,
1463 char const *psz_var,
1464 vlc_value_t oldvar, vlc_value_t newvar,
1467 if( !strcmp( psz_var, "item-change" ) )
1469 CoverArtLabel *art = static_cast< CoverArtLabel* >( data );
1471 art->requestUpdate();
1476 CoverArtLabel::CoverArtLabel( QWidget *parent,
1477 vlc_object_t *_p_this,
1478 input_item_t *_p_input )
1479 : QLabel( parent ), p_this( _p_this), p_input( _p_input ), prevArt()
1481 setContextMenuPolicy( Qt::ActionsContextMenu );
1482 CONNECT( this, updateRequested(), this, doUpdate() );
1484 playlist_t *p_playlist = pl_Yield( p_this );
1485 var_AddCallback( p_playlist, "item-change",
1486 downloadCoverCallback, this );
1487 pl_Release( p_this );
1489 setMinimumHeight( 128 );
1490 setMinimumWidth( 128 );
1491 setMaximumHeight( 128 );
1492 setMaximumWidth( 128 );
1493 setScaledContents( true );
1498 void CoverArtLabel::downloadCover()
1502 playlist_t *p_playlist = pl_Yield( p_this );
1503 playlist_AskForArtEnqueue( p_playlist, p_input );
1504 pl_Release( p_this );
1508 void CoverArtLabel::doUpdate()
1512 setPixmap( QPixmap( ":/noart.png" ) );
1513 QList< QAction* > artActions = actions();
1514 if( !artActions.isEmpty() )
1515 foreach( QAction *act, artActions )
1516 removeAction( act );
1521 char *psz_meta = input_item_GetArtURL( p_input );
1522 if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
1524 QString artUrl = qfu( psz_meta ).replace( "file://", "" );
1525 if( artUrl != prevArt )
1526 setPixmap( QPixmap( artUrl ) );
1527 QList< QAction* > artActions = actions();
1528 if( !artActions.isEmpty() )
1530 foreach( QAction *act, artActions )
1531 removeAction( act );
1538 setPixmap( QPixmap( ":/noart.png" ) );
1540 QList< QAction* > artActions = actions();
1541 if( artActions.isEmpty() )
1543 QAction *action = new QAction( qtr( "Download cover art" ),
1545 addAction( action );
1546 CONNECT( action, triggered(),
1547 this, downloadCover() );