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 static void setupSmallButton( QPushButton *aButton )
311 aButton->setMaximumSize( QSize( 26, 26 ) );
312 aButton->setMinimumSize( QSize( 26, 26 ) );
313 aButton->setIconSize( QSize( 20, 20 ) );
314 aButton->setFocusPolicy( Qt::NoFocus );
317 /* init static variables in advanced controls */
318 mtime_t AdvControlsWidget::timeA = 0;
319 mtime_t AdvControlsWidget::timeB = 0;
321 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, bool b_fsCreation = false ) :
322 QFrame( NULL ), p_intf( _p_i )
324 QHBoxLayout *advLayout = new QHBoxLayout( this );
325 advLayout->setMargin( 0 );
326 advLayout->setSpacing( 0 );
327 advLayout->setAlignment( Qt::AlignBottom );
330 ABButton = new QPushButton;
331 setupSmallButton( ABButton );
332 advLayout->addWidget( ABButton );
333 BUTTON_SET_ACT_I( ABButton, "", atob_nob,
334 qtr( "Loop from point A to point B continuously.\nClick to set point A" ),
338 /* in FS controller we skip this, because we dont want to have it double
341 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
342 this, AtoBLoop( float, int, int ) );
343 /* set up synchronization between main controller and fs controller */
344 CONNECT( THEMIM->getIM(), advControlsSetIcon(), this, setIcon() );
345 connect( this, SIGNAL( timeChanged() ),
346 THEMIM->getIM(), SIGNAL( advControlsSetIcon()));
348 frameButton = new QPushButton( "Fr" );
349 frameButton->setMaximumSize( QSize( 26, 26 ) );
350 frameButton->setIconSize( QSize( 20, 20 ) );
351 advLayout->addWidget( frameButton );
352 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by frame" ), frame() );
356 recordButton = new QPushButton;
357 setupSmallButton( recordButton );
358 advLayout->addWidget( recordButton );
359 BUTTON_SET_ACT_I( recordButton, "", record,
360 qtr( "Record" ), record() );
362 /* Snapshot Button */
363 snapshotButton = new QPushButton;
364 setupSmallButton( snapshotButton );
365 advLayout->addWidget( snapshotButton );
366 BUTTON_SET_ACT_I( snapshotButton, "", snapshot,
367 qtr( "Take a snapshot" ), snapshot() );
370 AdvControlsWidget::~AdvControlsWidget()
373 void AdvControlsWidget::enableInput( bool enable )
376 if( THEMIM->getInput() != NULL )
378 input_item_t *p_item = input_GetItem( THEMIM->getInput() );
379 i_input_id = p_item->i_id;
381 recordButton->setVisible( var_GetBool( THEMIM->getInput(), "can-record" ) );
385 recordButton->setVisible( false );
388 ABButton->setEnabled( enable );
389 recordButton->setEnabled( enable );
391 if( enable && ( i_last_input_id != i_input_id ) )
394 i_last_input_id = i_input_id;
399 void AdvControlsWidget::enableVideo( bool enable )
401 snapshotButton->setEnabled( enable );
403 frameButton->setEnabled( enable );
407 void AdvControlsWidget::snapshot()
409 vout_thread_t *p_vout =
410 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
413 vout_Control( p_vout, VOUT_SNAPSHOT );
414 vlc_object_release( p_vout );
418 /* Function called when the button is clicked() */
419 void AdvControlsWidget::fromAtoB()
423 timeA = var_GetTime( THEMIM->getInput(), "time" );
429 timeB = var_GetTime( THEMIM->getInput(), "time" );
430 var_SetTime( THEMIM->getInput(), "time" , timeA );
439 /* setting/synchro icons after click on main or fs controller */
440 void AdvControlsWidget::setIcon()
442 if( !timeA && !timeB)
444 ABButton->setIcon( QIcon( ":/atob_nob" ) );
445 ABButton->setToolTip( qtr( "Loop from point A to point B continuously\nClick to set point A" ) );
447 else if( timeA && !timeB )
449 ABButton->setIcon( QIcon( ":/atob_noa" ) );
450 ABButton->setToolTip( qtr( "Click to set point B" ) );
452 else if( timeA && timeB )
454 ABButton->setIcon( QIcon( ":/atob" ) );
455 ABButton->setToolTip( qtr( "Stop the A to B loop" ) );
459 /* Function called regularly when in an AtoB loop */
460 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
464 if( ( i_time >= (int)( timeB/1000000 ) )
465 || ( i_time < (int)( timeA/1000000 ) ) )
466 var_SetTime( THEMIM->getInput(), "time" , timeA );
470 void AdvControlsWidget::record()
472 input_thread_t *p_input = THEMIM->getInput();
475 /* This method won't work fine if the stream can't be cut anywhere */
476 const bool b_recording = var_GetBool( p_input, "record" );
477 var_SetBool( p_input, "record", !b_recording );
481 /* 'record' access-filter is not loaded, we open Save dialog */
482 input_item_t *p_item = input_GetItem( p_input );
486 char *psz = input_item_GetURI( p_item );
488 THEDP->streamingDialog( NULL, psz, true );
495 //FIXME Frame by frame function
496 void AdvControlsWidget::frame(){}
499 /*****************************
500 * DA Control Widget !
501 *****************************/
502 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
503 MainInterface *_p_mi,
507 QFrame( _p_mi ), p_intf( _p_i )
509 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
511 /** The main Slider **/
512 slider = new InputSlider( Qt::Horizontal, NULL );
513 /* Update the position when the IM has changed */
514 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
515 slider, setPosition( float, int, int ) );
516 /* And update the IM, when the position has changed */
517 CONNECT( slider, sliderDragged( float ),
518 THEMIM->getIM(), sliderUpdate( float ) );
520 /** Slower and faster Buttons **/
521 slowerButton = new QToolButton;
522 slowerButton->setAutoRaise( true );
523 slowerButton->setMaximumSize( QSize( 26, 20 ) );
524 slowerButton->setFocusPolicy( Qt::NoFocus );
526 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
528 fasterButton = new QToolButton;
529 fasterButton->setAutoRaise( true );
530 fasterButton->setMaximumSize( QSize( 26, 20 ) );
531 fasterButton->setFocusPolicy( Qt::NoFocus );
533 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
535 /* advanced Controls handling */
536 b_advancedVisible = b_advControls;
538 advControls = new AdvControlsWidget( p_intf, b_fsCreation );
539 if( !b_advancedVisible ) advControls->hide();
541 /** Disc and Menus handling */
542 discFrame = new QWidget( this );
544 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
545 discLayout->setSpacing( 0 );
546 discLayout->setMargin( 0 );
548 prevSectionButton = new QPushButton( discFrame );
549 setupSmallButton( prevSectionButton );
550 discLayout->addWidget( prevSectionButton );
552 menuButton = new QPushButton( discFrame );
553 setupSmallButton( menuButton );
554 discLayout->addWidget( menuButton );
556 nextSectionButton = new QPushButton( discFrame );
557 setupSmallButton( nextSectionButton );
558 discLayout->addWidget( nextSectionButton );
560 BUTTON_SET_IMG( prevSectionButton, "", dvd_prev, "" );
561 BUTTON_SET_IMG( nextSectionButton, "", dvd_next, "" );
562 BUTTON_SET_IMG( menuButton, "", dvd_menu, qtr( "Menu" ) );
566 /* Change the navigation button display when the IM navigation changes */
567 CONNECT( THEMIM->getIM(), navigationChanged( int ),
568 this, setNavigation( int ) );
569 /* Changes the IM navigation when triggered on the nav buttons */
570 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
572 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
574 CONNECT( menuButton, clicked(), THEMIM->getIM(),
579 * TODO: Merge with upper menu in a StackLayout
581 telexFrame = new QWidget( this );
582 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
583 telexLayout->setSpacing( 0 );
584 telexLayout->setMargin( 0 );
586 telexOn = new QPushButton;
587 setupSmallButton( telexOn );
588 telexLayout->addWidget( telexOn );
590 telexTransparent = new QPushButton;
591 setupSmallButton( telexTransparent );
592 telexLayout->addWidget( telexTransparent );
593 b_telexTransparent = false;
595 telexPage = new QSpinBox;
596 telexPage->setRange( 0, 999 );
597 telexPage->setValue( 100 );
598 telexPage->setAccelerated( true );
599 telexPage->setWrapping( true );
600 telexPage->setAlignment( Qt::AlignRight );
601 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
602 telexLayout->addWidget( telexPage );
604 telexFrame->hide(); /* default hidden */
606 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
607 telexGotoPage( int ) );
608 CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
609 telexPage, setValue( int ) );
611 BUTTON_SET_IMG( telexOn, "", tv, qtr( "Teletext on" ) );
613 CONNECT( telexOn, clicked(), THEMIM->getIM(),
614 telexToggleButtons() );
615 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
616 telexToggle( bool ) );
617 CONNECT( THEMIM->getIM(), toggleTelexButtons(),
618 this, toggleTeletext() );
619 b_telexEnabled = false;
620 telexTransparent->setEnabled( false );
621 telexPage->setEnabled( false );
623 BUTTON_SET_IMG( telexTransparent, "", tvtelx, qtr( "Teletext" ) );
624 CONNECT( telexTransparent, clicked( bool ),
625 THEMIM->getIM(), telexSetTransparency() );
626 CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
627 this, toggleTeletextTransparency() );
628 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
629 this, enableTeletext( bool ) );
632 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
633 sizePolicy.setHorizontalStretch( 0 );
634 sizePolicy.setVerticalStretch( 0 );
637 playButton = new QPushButton;
638 playButton->setSizePolicy( sizePolicy );
639 playButton->setMaximumSize( QSize( 36, 36 ) );
640 playButton->setMinimumSize( QSize( 36, 36 ) );
641 playButton->setIconSize( QSize( 30, 30 ) );
642 playButton->setFocusPolicy( Qt::NoFocus );
644 /** Prev + Stop + Next Block **/
645 controlButLayout = new QHBoxLayout;
646 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
649 QPushButton *prevButton = new QPushButton;
650 prevButton->setSizePolicy( sizePolicy );
651 setupSmallButton( prevButton );
653 controlButLayout->addWidget( prevButton );
656 QPushButton *stopButton = new QPushButton;
657 stopButton->setSizePolicy( sizePolicy );
658 setupSmallButton( stopButton );
660 controlButLayout->addWidget( stopButton );
663 QPushButton *nextButton = new QPushButton;
664 nextButton->setSizePolicy( sizePolicy );
665 setupSmallButton( nextButton );
667 controlButLayout->addWidget( nextButton );
669 /* Add this block to the main layout */
671 BUTTON_SET_ACT_I( playButton, "", play_b, qtr( I_PLAY_TOOLTIP ), play() );
672 BUTTON_SET_ACT_I( prevButton, "" , previous_b,
673 qtr( "Previous media in the playlist" ), prev() );
674 BUTTON_SET_ACT_I( nextButton, "", next_b,
675 qtr( "Next media in the playlist" ), next() );
676 BUTTON_SET_ACT_I( stopButton, "", stop_b, qtr( "Stop playback" ), stop() );
679 * Other first Line buttons
682 CONNECT( THEMIM->getIM(), voutChanged(bool), this, enableVideo(bool) );
684 /** Fullscreen/Visualisation **/
685 fullscreenButton = new QPushButton;
686 BUTTON_SET_ACT_I( fullscreenButton, "", fullscreen,
687 qtr( "Toggle the video in fullscreen" ), fullscreen() );
688 setupSmallButton( fullscreenButton );
692 /** Playlist Button **/
693 playlistButton = new QPushButton;
694 setupSmallButton( playlistButton );
695 BUTTON_SET_IMG( playlistButton, "" , playlist, qtr( "Show playlist" ) );
696 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
698 /** extended Settings **/
699 extSettingsButton = new QPushButton;
700 BUTTON_SET_ACT_I( extSettingsButton, "", extended,
701 qtr( "Show extended settings" ), extSettings() );
702 setupSmallButton( extSettingsButton );
706 hVolLabel = new VolumeClickHandler( p_intf, this );
708 volMuteLabel = new QLabel;
709 volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
710 volMuteLabel->installEventFilter( hVolLabel );
714 volumeSlider = new SoundSlider( this,
715 config_GetInt( p_intf, "volume-step" ),
716 config_GetInt( p_intf, "qt-volume-complete" ),
717 config_GetPsz( p_intf, "qt-slider-colours" ) );
721 volumeSlider = new QSlider( this );
722 volumeSlider->setOrientation( Qt::Horizontal );
724 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
725 volumeSlider->setMinimumSize( QSize( 85, 30 ) );
726 volumeSlider->setFocusPolicy( Qt::NoFocus );
728 /* Set the volume from the config */
729 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
730 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
732 /* Force the update at build time in order to have a muted icon if needed */
733 updateVolume( volumeSlider->value() );
735 /* Volume control connection */
736 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
737 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
741 controlLayout = new QGridLayout( this );
743 controlLayout->setSpacing( 0 );
744 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
746 controlLayout->addWidget( slider, 0, 1, 1, 18 );
747 controlLayout->addWidget( slowerButton, 0, 0 );
748 controlLayout->addWidget( fasterButton, 0, 19 );
750 controlLayout->addWidget( discFrame, 1, 8, 2, 3, Qt::AlignBottom );
751 controlLayout->addWidget( telexFrame, 1, 8, 2, 5, Qt::AlignBottom );
753 controlLayout->addWidget( playButton, 2, 0, 2, 2, Qt::AlignBottom );
754 controlLayout->setColumnMinimumWidth( 2, 10 );
755 controlLayout->setColumnStretch( 2, 0 );
757 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
758 /* Column 6 is unused */
759 controlLayout->setColumnStretch( 6, 0 );
760 controlLayout->setColumnStretch( 7, 0 );
761 controlLayout->setColumnMinimumWidth( 7, 10 );
763 controlLayout->addWidget( fullscreenButton, 3, 8, Qt::AlignBottom );
764 controlLayout->addWidget( playlistButton, 3, 9, Qt::AlignBottom );
765 controlLayout->addWidget( extSettingsButton, 3, 10, Qt::AlignBottom );
766 controlLayout->setColumnStretch( 11, 0 ); /* telex alignment */
768 controlLayout->setColumnStretch( 12, 0 );
769 controlLayout->setColumnMinimumWidth( 12, 10 );
771 controlLayout->addWidget( advControls, 3, 13, 1, 3, Qt::AlignBottom );
773 controlLayout->setColumnStretch( 16, 10 );
774 controlLayout->setColumnMinimumWidth( 16, 10 );
776 controlLayout->addWidget( volMuteLabel, 3, 17, Qt::AlignBottom );
777 controlLayout->addWidget( volumeSlider, 3, 18, 1 , 2, Qt::AlignBottom );
783 ControlsWidget::~ControlsWidget()
786 void ControlsWidget::toggleTeletext()
788 bool b_enabled = THEMIM->teletextState();
791 telexTransparent->setEnabled( false );
792 telexPage->setEnabled( false );
793 b_telexEnabled = false;
797 telexTransparent->setEnabled( true );
798 telexPage->setEnabled( true );
799 b_telexEnabled = true;
803 void ControlsWidget::enableTeletext( bool b_enable )
805 telexFrame->setVisible( b_enable );
806 bool b_on = THEMIM->teletextState();
808 telexOn->setChecked( b_on );
809 telexTransparent->setEnabled( b_on );
810 telexPage->setEnabled( b_on );
811 b_telexEnabled = b_on;
814 void ControlsWidget::toggleTeletextTransparency()
816 if( b_telexTransparent )
818 telexTransparent->setIcon( QIcon( ":/tvtelx" ) );
819 telexTransparent->setToolTip( qtr( "Teletext" ) );
820 b_telexTransparent = false;
824 telexTransparent->setIcon( QIcon( ":/tvtelx-trans" ) );
825 telexTransparent->setToolTip( qtr( "Transparent" ) );
826 b_telexTransparent = true;
830 void ControlsWidget::stop()
835 void ControlsWidget::play()
837 if( THEPL->current.i_size == 0 )
839 /* The playlist is empty, open a file requester */
840 THEDP->openFileDialog();
844 THEMIM->togglePlayPause();
847 void ControlsWidget::prev()
852 void ControlsWidget::next()
857 void ControlsWidget::setNavigation( int navigation )
859 #define HELP_PCH N_( "Previous chapter" )
860 #define HELP_NCH N_( "Next chapter" )
862 // 1 = chapter, 2 = title, 0 = no
863 if( navigation == 0 )
866 } else if( navigation == 1 ) {
867 prevSectionButton->setToolTip( qtr( HELP_PCH ) );
868 nextSectionButton->setToolTip( qtr( HELP_NCH ) );
872 prevSectionButton->setToolTip( qtr( HELP_PCH ) );
873 nextSectionButton->setToolTip( qtr( HELP_NCH ) );
879 static bool b_my_volume;
880 void ControlsWidget::updateVolume( int i_sliderVolume )
884 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
885 aout_VolumeSet( p_intf, i_res );
887 if( i_sliderVolume == 0 )
889 volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
890 volMuteLabel->setToolTip( qtr( "Unmute" ) );
894 if( i_sliderVolume < VOLUME_MAX / 3 )
895 volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
896 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
897 volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
898 else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
899 volMuteLabel->setToolTip( qtr( "Mute" ) );
902 void ControlsWidget::updateVolume()
905 audio_volume_t i_volume;
906 aout_VolumeGet( p_intf, &i_volume );
907 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
908 int i_gauge = volumeSlider->value();
910 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
913 volumeSlider->setValue( i_volume );
918 void ControlsWidget::updateInput()
920 /* Activate the interface buttons according to the presence of the input */
921 enableInput( THEMIM->getIM()->hasInput() );
922 enableVideo( THEMIM->getIM()->hasVideo() );
925 void ControlsWidget::setStatus( int status )
927 if( status == PLAYING_S ) /* Playing */
929 playButton->setIcon( QIcon( ":/pause_b" ) );
930 playButton->setToolTip( qtr( "Pause the playback" ) );
934 playButton->setIcon( QIcon( ":/play_b" ) );
935 playButton->setToolTip( qtr( I_PLAY_TOOLTIP ) );
941 * This functions toggle the fullscreen mode
942 * If there is no video, it should first activate Visualisations...
943 * This has also to be fixed in enableVideo()
945 void ControlsWidget::fullscreen()
947 vout_thread_t *p_vout =
948 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
951 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
952 vlc_object_release( p_vout );
956 void ControlsWidget::extSettings()
958 THEDP->extendedDialog();
961 void ControlsWidget::slower()
963 THEMIM->getIM()->slower();
966 void ControlsWidget::faster()
968 THEMIM->getIM()->faster();
971 void ControlsWidget::enableInput( bool enable )
973 slowerButton->setEnabled( enable );
974 slider->setEnabled( enable );
975 slider->setSliderPosition ( 0 );
976 fasterButton->setEnabled( enable );
978 /* Advanced Buttons too */
979 advControls->enableInput( enable );
982 void ControlsWidget::enableVideo( bool enable )
984 // TODO Later make the fullscreenButton toggle Visualisation and so on.
985 fullscreenButton->setEnabled( enable );
987 /* Advanced Buttons too */
988 advControls->enableVideo( enable );
991 void ControlsWidget::toggleAdvanced()
993 if( advControls && !b_advancedVisible )
996 b_advancedVisible = true;
1000 advControls->hide();
1001 b_advancedVisible = false;
1003 emit advancedControlsToggled( b_advancedVisible );
1006 /**********************************************************************
1007 * Fullscrenn control widget
1008 **********************************************************************/
1009 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
1010 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
1011 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
1012 i_mouse_last_x( -1 ), i_mouse_last_y( -1 ), b_mouse_over(false),
1013 b_slow_hide_begin(false), i_slow_hide_timeout(1),
1014 b_fullscreen( false ), i_hide_timeout( 1 ), p_vout(NULL)
1016 setWindowFlags( Qt::ToolTip );
1018 setFrameShape( QFrame::StyledPanel );
1019 setFrameStyle( QFrame::Sunken );
1020 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
1022 QGridLayout *fsLayout = new QGridLayout( this );
1023 fsLayout->setLayoutMargins( 5, 2, 5, 2, 5 );
1026 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
1027 slider->setMinimumWidth( 220 );
1028 fsLayout->addWidget( slowerButton, 0, 0 );
1029 fsLayout->addWidget( slider, 0, 1, 1, 9 );
1030 fsLayout->addWidget( fasterButton, 0, 10 );
1032 fsLayout->addWidget( playButton, 1, 0, 1, 2 );
1033 fsLayout->addLayout( controlButLayout, 1, 2 );
1035 fsLayout->addWidget( discFrame, 1, 3 );
1036 fsLayout->addWidget( telexFrame, 1, 4 );
1037 fsLayout->addWidget( fullscreenButton, 1, 5 );
1038 fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
1040 fsLayout->setColumnStretch( 7, 10 );
1041 fsLayout->addWidget( volMuteLabel, 1, 8 );
1042 fsLayout->addWidget( volumeSlider, 1, 9, 1, 2 );
1045 p_hideTimer = new QTimer( this );
1046 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
1047 p_hideTimer->setSingleShot( true );
1049 /* slow hiding timer */
1050 #if HAVE_TRANSPARENCY
1051 p_slowHideTimer = new QTimer( this );
1052 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
1055 adjustSize (); /* need to get real width and height for moving */
1058 QDesktopWidget * p_desktop = QApplication::desktop();
1060 move( p_desktop->width() / 2 - width() / 2,
1061 p_desktop->height() - height() );
1064 setWindowOpacity( 0.0 );
1070 fullscreenButton->setIcon( QIcon( ":/defullscreen" ) );
1072 vlc_mutex_init_recursive( &lock );
1075 FullscreenControllerWidget::~FullscreenControllerWidget()
1078 vlc_mutex_destroy( &lock );
1082 * Show fullscreen controller
1084 void FullscreenControllerWidget::showFSC()
1088 // after quiting and going to fs, we need to call show()
1094 b_fscHidden = false;
1095 setWindowOpacity( 1.0 );
1101 #if HAVE_TRANSPARENCY
1102 setWindowOpacity( DEFAULT_OPACITY );
1107 * Hide fullscreen controller
1108 * FIXME: under windows it have to be done by moving out of screen
1109 * because hide() doesnt work
1111 void FullscreenControllerWidget::hideFSC()
1115 setWindowOpacity( 0.0 ); // simulate hidding
1122 * Plane to hide fullscreen controller
1124 void FullscreenControllerWidget::planHideFSC()
1126 vlc_mutex_lock( &lock );
1127 int i_timeout = i_hide_timeout;
1128 vlc_mutex_unlock( &lock );
1130 p_hideTimer->start( i_timeout );
1132 #if HAVE_TRANSPARENCY
1133 b_slow_hide_begin = true;
1134 i_slow_hide_timeout = i_timeout;
1135 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
1140 * Hidding fullscreen controller slowly
1141 * Linux: need composite manager
1142 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
1144 void FullscreenControllerWidget::slowHideFSC()
1146 #if HAVE_TRANSPARENCY
1147 if( b_slow_hide_begin )
1149 b_slow_hide_begin = false;
1151 p_slowHideTimer->stop();
1152 /* the last part of time divided to 100 pieces */
1153 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
1159 if ( windowOpacity() > 0.0 && !b_fscHidden )
1161 if ( windowOpacity() > 0.0 )
1164 /* we should use 0.01 because of 100 pieces ^^^
1165 but than it cannt be done in time */
1166 setWindowOpacity( windowOpacity() - 0.02 );
1169 if ( windowOpacity() <= 0.0 )
1170 p_slowHideTimer->stop();
1177 * events: show, hide, start timer for hidding
1179 void FullscreenControllerWidget::customEvent( QEvent *event )
1183 switch( event->type() )
1185 case FullscreenControlToggle_Type:
1186 vlc_mutex_lock( &lock );
1187 b_fs = b_fullscreen;
1188 vlc_mutex_unlock( &lock );
1196 p_hideTimer->stop();
1202 case FullscreenControlShow_Type:
1203 vlc_mutex_lock( &lock );
1204 b_fs = b_fullscreen;
1205 vlc_mutex_unlock( &lock );
1207 if( b_fs ) // FIXME I am not sure about that one
1210 case FullscreenControlHide_Type:
1213 case FullscreenControlPlanHide_Type:
1214 if( !b_mouse_over ) // Only if the mouse is not over FSC
1224 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1226 if ( event->buttons() == Qt::LeftButton )
1228 int i_moveX = event->globalX() - i_mouse_last_x;
1229 int i_moveY = event->globalY() - i_mouse_last_y;
1231 move( x() + i_moveX, y() + i_moveY );
1233 i_mouse_last_x = event->globalX();
1234 i_mouse_last_y = event->globalY();
1240 * store position of cursor
1242 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1244 i_mouse_last_x = event->globalX();
1245 i_mouse_last_y = event->globalY();
1249 * On mouse go above FSC
1251 void FullscreenControllerWidget::enterEvent( QEvent *event )
1253 b_mouse_over = true;
1255 p_hideTimer->stop();
1256 #if HAVE_TRANSPARENCY
1257 p_slowHideTimer->stop();
1262 * On mouse go out from FSC
1264 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1268 b_mouse_over = false;
1272 * When you get pressed key, send it to video output
1273 * FIXME: clearing focus by clearFocus() to not getting
1274 * key press events didnt work
1276 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1278 int i_vlck = qtEventToVLCKey( event );
1281 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1289 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object, const char *variable,
1290 vlc_value_t old_val, vlc_value_t new_val,
1293 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1294 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1296 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1301 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1302 vlc_value_t old_val, vlc_value_t new_val,
1305 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1308 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1309 QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1311 /* Plan hide event */
1312 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1313 QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1320 * It is called when video start
1322 void FullscreenControllerWidget::attachVout( vout_thread_t *p_nvout )
1324 assert( p_nvout && !p_vout );
1328 vlc_mutex_lock( &lock );
1329 var_AddCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this ); /* I miss a add and fire */
1330 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ), var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1331 vlc_mutex_unlock( &lock );
1334 * It is called after turn off video.
1336 void FullscreenControllerWidget::detachVout()
1340 var_DelCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this );
1341 vlc_mutex_lock( &lock );
1342 fullscreenChanged( p_vout, false, 0 );
1343 vlc_mutex_unlock( &lock );
1349 * Register and unregister callback for mouse moving
1351 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout, bool b_fs, int i_timeout )
1353 vlc_mutex_lock( &lock );
1354 if( b_fs && !b_fullscreen )
1356 b_fullscreen = true;
1357 i_hide_timeout = i_timeout;
1358 var_AddCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1360 else if( !b_fs && b_fullscreen )
1362 b_fullscreen = false;
1363 i_hide_timeout = i_timeout;
1364 var_DelCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1366 /* Force fs hidding */
1367 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1368 QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1370 vlc_mutex_unlock( &lock );
1373 /**********************************************************************
1374 * Speed control widget
1375 **********************************************************************/
1376 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1377 QFrame( NULL ), p_intf( _p_i )
1379 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1380 sizePolicy.setHorizontalStretch( 0 );
1381 sizePolicy.setVerticalStretch( 0 );
1383 speedSlider = new QSlider;
1384 speedSlider->setSizePolicy( sizePolicy );
1385 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1386 speedSlider->setOrientation( Qt::Vertical );
1387 speedSlider->setTickPosition( QSlider::TicksRight );
1389 speedSlider->setRange( -24, 24 );
1390 speedSlider->setSingleStep( 1 );
1391 speedSlider->setPageStep( 1 );
1392 speedSlider->setTickInterval( 12 );
1394 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1396 QToolButton *normalSpeedButton = new QToolButton( this );
1397 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1398 normalSpeedButton->setAutoRaise( true );
1399 normalSpeedButton->setText( "1x" );
1400 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1402 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1404 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1405 speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
1406 speedControlLayout->setSpacing( 4 );
1407 speedControlLayout->addWidget( speedSlider );
1408 speedControlLayout->addWidget( normalSpeedButton );
1409 setLayout( speedControlLayout );
1412 SpeedControlWidget::~SpeedControlWidget()
1415 void SpeedControlWidget::setEnable( bool b_enable )
1417 speedSlider->setEnabled( b_enable );
1420 void SpeedControlWidget::updateControls( int rate )
1422 if( speedSlider->isSliderDown() )
1424 //We don't want to change anything if the user is using the slider
1428 double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
1429 int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
1431 if( sliderValue < speedSlider->minimum() )
1433 sliderValue = speedSlider->minimum();
1435 else if( sliderValue > speedSlider->maximum() )
1437 sliderValue = speedSlider->maximum();
1440 //Block signals to avoid feedback loop
1441 speedSlider->blockSignals( true );
1442 speedSlider->setValue( sliderValue );
1443 speedSlider->blockSignals( false );
1446 void SpeedControlWidget::updateRate( int sliderValue )
1448 double speed = pow( 2, (double)sliderValue / 12 );
1449 int rate = INPUT_RATE_DEFAULT / speed;
1451 THEMIM->getIM()->setRate(rate);
1454 void SpeedControlWidget::resetRate()
1456 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
1461 static int downloadCoverCallback( vlc_object_t *p_this,
1462 char const *psz_var,
1463 vlc_value_t oldvar, vlc_value_t newvar,
1466 if( !strcmp( psz_var, "item-change" ) )
1468 CoverArtLabel *art = static_cast< CoverArtLabel* >( data );
1470 art->requestUpdate();
1475 CoverArtLabel::CoverArtLabel( QWidget *parent,
1476 vlc_object_t *_p_this,
1477 input_item_t *_p_input )
1478 : QLabel( parent ), p_this( _p_this), p_input( _p_input ), prevArt()
1480 setContextMenuPolicy( Qt::ActionsContextMenu );
1481 CONNECT( this, updateRequested(), this, doUpdate() );
1483 playlist_t *p_playlist = pl_Yield( p_this );
1484 var_AddCallback( p_playlist, "item-change",
1485 downloadCoverCallback, this );
1486 pl_Release( p_this );
1488 setMinimumHeight( 128 );
1489 setMinimumWidth( 128 );
1490 setMaximumHeight( 128 );
1491 setMaximumWidth( 128 );
1492 setScaledContents( true );
1497 void CoverArtLabel::downloadCover()
1501 playlist_t *p_playlist = pl_Yield( p_this );
1502 playlist_AskForArtEnqueue( p_playlist, p_input );
1503 pl_Release( p_this );
1507 void CoverArtLabel::doUpdate()
1511 setPixmap( QPixmap( ":/noart.png" ) );
1512 QList< QAction* > artActions = actions();
1513 if( !artActions.isEmpty() )
1514 foreach( QAction *act, artActions )
1515 removeAction( act );
1520 char *psz_meta = input_item_GetArtURL( p_input );
1521 if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
1523 QString artUrl = qfu( psz_meta ).replace( "file://", "" );
1524 if( artUrl != prevArt )
1527 if( pix.load( artUrl ) )
1531 msg_Dbg( p_this, "Qt could not load image '%s'",
1533 setPixmap( QPixmap( ":/noart.png" ) );
1536 QList< QAction* > artActions = actions();
1537 if( !artActions.isEmpty() )
1539 foreach( QAction *act, artActions )
1540 removeAction( act );
1547 setPixmap( QPixmap( ":/noart.png" ) );
1549 QList< QAction* > artActions = actions();
1550 if( artActions.isEmpty() )
1552 QAction *action = new QAction( qtr( "Download cover art" ),
1554 addAction( action );
1555 CONNECT( action, triggered(),
1556 this, downloadCover() );