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() );
353 recordButton = new QPushButton;
354 setupSmallButton( recordButton );
355 advLayout->addWidget( recordButton );
356 BUTTON_SET_ACT_I( recordButton, "", record,
357 qtr( "Record" ), record() );
359 /* Snapshot Button */
360 snapshotButton = new QPushButton;
361 setupSmallButton( snapshotButton );
362 advLayout->addWidget( snapshotButton );
363 BUTTON_SET_ACT_I( snapshotButton, "", snapshot,
364 qtr( "Take a snapshot" ), snapshot() );
367 AdvControlsWidget::~AdvControlsWidget()
370 void AdvControlsWidget::enableInput( bool enable )
373 if( THEMIM->getInput() != NULL )
375 input_item_t *p_item = input_GetItem( THEMIM->getInput() );
376 i_input_id = p_item->i_id;
378 recordButton->setVisible( var_GetBool( THEMIM->getInput(), "can-record" ) );
382 recordButton->setVisible( false );
385 ABButton->setEnabled( enable );
386 recordButton->setEnabled( enable );
388 if( enable && ( i_last_input_id != i_input_id ) )
391 i_last_input_id = i_input_id;
396 void AdvControlsWidget::enableVideo( bool enable )
398 snapshotButton->setEnabled( enable );
400 frameButton->setEnabled( enable );
404 void AdvControlsWidget::snapshot()
406 vout_thread_t *p_vout =
407 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
410 vout_Control( p_vout, VOUT_SNAPSHOT );
411 vlc_object_release( p_vout );
415 /* Function called when the button is clicked() */
416 void AdvControlsWidget::fromAtoB()
420 timeA = var_GetTime( THEMIM->getInput(), "time" );
426 timeB = var_GetTime( THEMIM->getInput(), "time" );
427 var_SetTime( THEMIM->getInput(), "time" , timeA );
436 /* setting/synchro icons after click on main or fs controller */
437 void AdvControlsWidget::setIcon()
439 if( !timeA && !timeB)
441 ABButton->setIcon( QIcon( ":/atob_nob" ) );
442 ABButton->setToolTip( qtr( "Loop from point A to point B continuously\nClick to set point A" ) );
444 else if( timeA && !timeB )
446 ABButton->setIcon( QIcon( ":/atob_noa" ) );
447 ABButton->setToolTip( qtr( "Click to set point B" ) );
449 else if( timeA && timeB )
451 ABButton->setIcon( QIcon( ":/atob" ) );
452 ABButton->setToolTip( qtr( "Stop the A to B loop" ) );
456 /* Function called regularly when in an AtoB loop */
457 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
461 if( ( i_time >= (int)( timeB/1000000 ) )
462 || ( i_time < (int)( timeA/1000000 ) ) )
463 var_SetTime( THEMIM->getInput(), "time" , timeA );
467 void AdvControlsWidget::record()
469 input_thread_t *p_input = THEMIM->getInput();
472 /* This method won't work fine if the stream can't be cut anywhere */
473 const bool b_recording = var_GetBool( p_input, "record" );
474 var_SetBool( p_input, "record", !b_recording );
478 /* 'record' access-filter is not loaded, we open Save dialog */
479 input_item_t *p_item = input_GetItem( p_input );
483 char *psz = input_item_GetURI( p_item );
485 THEDP->streamingDialog( NULL, psz, true );
492 //FIXME Frame by frame function
493 void AdvControlsWidget::frame(){}
496 /*****************************
497 * DA Control Widget !
498 *****************************/
499 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
500 MainInterface *_p_mi,
504 QFrame( _p_mi ), p_intf( _p_i )
506 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
508 /** The main Slider **/
509 slider = new InputSlider( Qt::Horizontal, NULL );
510 /* Update the position when the IM has changed */
511 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
512 slider, setPosition( float, int, int ) );
513 /* And update the IM, when the position has changed */
514 CONNECT( slider, sliderDragged( float ),
515 THEMIM->getIM(), sliderUpdate( float ) );
517 /** Slower and faster Buttons **/
518 slowerButton = new QToolButton;
519 slowerButton->setAutoRaise( true );
520 slowerButton->setMaximumSize( QSize( 26, 20 ) );
522 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
524 fasterButton = new QToolButton;
525 fasterButton->setAutoRaise( true );
526 fasterButton->setMaximumSize( QSize( 26, 20 ) );
528 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
530 /* advanced Controls handling */
531 b_advancedVisible = b_advControls;
533 advControls = new AdvControlsWidget( p_intf, b_fsCreation );
534 if( !b_advancedVisible ) advControls->hide();
536 /** Disc and Menus handling */
537 discFrame = new QWidget( this );
539 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
540 discLayout->setSpacing( 0 );
541 discLayout->setMargin( 0 );
543 prevSectionButton = new QPushButton( discFrame );
544 setupSmallButton( prevSectionButton );
545 discLayout->addWidget( prevSectionButton );
547 menuButton = new QPushButton( discFrame );
548 setupSmallButton( menuButton );
549 discLayout->addWidget( menuButton );
551 nextSectionButton = new QPushButton( discFrame );
552 setupSmallButton( nextSectionButton );
553 discLayout->addWidget( nextSectionButton );
555 BUTTON_SET_IMG( prevSectionButton, "", dvd_prev, "" );
556 BUTTON_SET_IMG( nextSectionButton, "", dvd_next, "" );
557 BUTTON_SET_IMG( menuButton, "", dvd_menu, qtr( "Menu" ) );
561 /* Change the navigation button display when the IM navigation changes */
562 CONNECT( THEMIM->getIM(), navigationChanged( int ),
563 this, setNavigation( int ) );
564 /* Changes the IM navigation when triggered on the nav buttons */
565 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
567 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
569 CONNECT( menuButton, clicked(), THEMIM->getIM(),
574 * TODO: Merge with upper menu in a StackLayout
576 telexFrame = new QWidget( this );
577 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
578 telexLayout->setSpacing( 0 );
579 telexLayout->setMargin( 0 );
581 telexOn = new QPushButton;
582 setupSmallButton( telexOn );
583 telexLayout->addWidget( telexOn );
585 telexTransparent = new QPushButton;
586 setupSmallButton( telexTransparent );
587 telexLayout->addWidget( telexTransparent );
588 b_telexTransparent = false;
590 telexPage = new QSpinBox;
591 telexPage->setRange( 0, 999 );
592 telexPage->setValue( 100 );
593 telexPage->setAccelerated( true );
594 telexPage->setWrapping( true );
595 telexPage->setAlignment( Qt::AlignRight );
596 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
597 telexLayout->addWidget( telexPage );
599 telexFrame->hide(); /* default hidden */
601 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
602 telexGotoPage( int ) );
603 CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
604 telexPage, setValue( int ) );
606 BUTTON_SET_IMG( telexOn, "", tv, qtr( "Teletext on" ) );
608 CONNECT( telexOn, clicked(), THEMIM->getIM(),
609 telexToggleButtons() );
610 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
611 telexToggle( bool ) );
612 CONNECT( THEMIM->getIM(), toggleTelexButtons(),
613 this, toggleTeletext() );
614 b_telexEnabled = false;
615 telexTransparent->setEnabled( false );
616 telexPage->setEnabled( false );
618 BUTTON_SET_IMG( telexTransparent, "", tvtelx, qtr( "Teletext" ) );
619 CONNECT( telexTransparent, clicked( bool ),
620 THEMIM->getIM(), telexSetTransparency() );
621 CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
622 this, toggleTeletextTransparency() );
623 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
624 this, enableTeletext( bool ) );
627 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
628 sizePolicy.setHorizontalStretch( 0 );
629 sizePolicy.setVerticalStretch( 0 );
632 playButton = new QPushButton;
633 playButton->setSizePolicy( sizePolicy );
634 playButton->setMaximumSize( QSize( 36, 36 ) );
635 playButton->setMinimumSize( QSize( 36, 36 ) );
636 playButton->setIconSize( QSize( 30, 30 ) );
639 /** Prev + Stop + Next Block **/
640 controlButLayout = new QHBoxLayout;
641 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
644 QPushButton *prevButton = new QPushButton;
645 prevButton->setSizePolicy( sizePolicy );
646 setupSmallButton( prevButton );
648 controlButLayout->addWidget( prevButton );
651 QPushButton *stopButton = new QPushButton;
652 stopButton->setSizePolicy( sizePolicy );
653 setupSmallButton( stopButton );
655 controlButLayout->addWidget( stopButton );
658 QPushButton *nextButton = new QPushButton;
659 nextButton->setSizePolicy( sizePolicy );
660 setupSmallButton( nextButton );
662 controlButLayout->addWidget( nextButton );
664 /* Add this block to the main layout */
666 BUTTON_SET_ACT_I( playButton, "", play_b, qtr( I_PLAY_TOOLTIP ), play() );
667 BUTTON_SET_ACT_I( prevButton, "" , previous_b,
668 qtr( "Previous media in the playlist" ), prev() );
669 BUTTON_SET_ACT_I( nextButton, "", next_b,
670 qtr( "Next media in the playlist" ), next() );
671 BUTTON_SET_ACT_I( stopButton, "", stop_b, qtr( "Stop playback" ), stop() );
674 * Other first Line buttons
677 CONNECT( THEMIM->getIM(), voutChanged(bool), this, enableVideo(bool) );
679 /** Fullscreen/Visualisation **/
680 fullscreenButton = new QPushButton;
681 BUTTON_SET_ACT_I( fullscreenButton, "", fullscreen,
682 qtr( "Toggle the video in fullscreen" ), fullscreen() );
683 setupSmallButton( fullscreenButton );
687 /** Playlist Button **/
688 playlistButton = new QPushButton;
689 setupSmallButton( playlistButton );
690 BUTTON_SET_IMG( playlistButton, "" , playlist, qtr( "Show playlist" ) );
691 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
693 /** extended Settings **/
694 extSettingsButton = new QPushButton;
695 BUTTON_SET_ACT_I( extSettingsButton, "", extended,
696 qtr( "Show extended settings" ), extSettings() );
697 setupSmallButton( extSettingsButton );
701 hVolLabel = new VolumeClickHandler( p_intf, this );
703 volMuteLabel = new QLabel;
704 volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
705 volMuteLabel->installEventFilter( hVolLabel );
709 volumeSlider = new SoundSlider( this,
710 config_GetInt( p_intf, "volume-step" ),
711 config_GetInt( p_intf, "qt-volume-complete" ),
712 config_GetPsz( p_intf, "qt-slider-colours" ) );
716 volumeSlider = new QSlider( this );
717 volumeSlider->setOrientation( Qt::Horizontal );
719 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
720 volumeSlider->setMinimumSize( QSize( 85, 30 ) );
721 volumeSlider->setFocusPolicy( Qt::NoFocus );
723 /* Set the volume from the config */
724 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
725 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
727 /* Force the update at build time in order to have a muted icon if needed */
728 updateVolume( volumeSlider->value() );
730 /* Volume control connection */
731 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
732 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
736 controlLayout = new QGridLayout( this );
738 controlLayout->setSpacing( 0 );
739 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
741 controlLayout->addWidget( slider, 0, 1, 1, 18 );
742 controlLayout->addWidget( slowerButton, 0, 0 );
743 controlLayout->addWidget( fasterButton, 0, 19 );
745 controlLayout->addWidget( discFrame, 1, 8, 2, 3, Qt::AlignBottom );
746 controlLayout->addWidget( telexFrame, 1, 8, 2, 5, Qt::AlignBottom );
748 controlLayout->addWidget( playButton, 2, 0, 2, 2, Qt::AlignBottom );
749 controlLayout->setColumnMinimumWidth( 2, 10 );
750 controlLayout->setColumnStretch( 2, 0 );
752 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
753 /* Column 6 is unused */
754 controlLayout->setColumnStretch( 6, 0 );
755 controlLayout->setColumnStretch( 7, 0 );
756 controlLayout->setColumnMinimumWidth( 7, 10 );
758 controlLayout->addWidget( fullscreenButton, 3, 8, Qt::AlignBottom );
759 controlLayout->addWidget( playlistButton, 3, 9, Qt::AlignBottom );
760 controlLayout->addWidget( extSettingsButton, 3, 10, Qt::AlignBottom );
761 controlLayout->setColumnStretch( 11, 0 ); /* telex alignment */
763 controlLayout->setColumnStretch( 12, 0 );
764 controlLayout->setColumnMinimumWidth( 12, 10 );
766 controlLayout->addWidget( advControls, 3, 13, 1, 3, Qt::AlignBottom );
768 controlLayout->setColumnStretch( 16, 10 );
769 controlLayout->setColumnMinimumWidth( 16, 10 );
771 controlLayout->addWidget( volMuteLabel, 3, 17, Qt::AlignBottom );
772 controlLayout->addWidget( volumeSlider, 3, 18, 1 , 2, Qt::AlignBottom );
778 ControlsWidget::~ControlsWidget()
781 void ControlsWidget::toggleTeletext()
783 bool b_enabled = THEMIM->teletextState();
786 telexTransparent->setEnabled( false );
787 telexPage->setEnabled( false );
788 b_telexEnabled = false;
792 telexTransparent->setEnabled( true );
793 telexPage->setEnabled( true );
794 b_telexEnabled = true;
798 void ControlsWidget::enableTeletext( bool b_enable )
800 telexFrame->setVisible( b_enable );
801 bool b_on = THEMIM->teletextState();
803 telexOn->setChecked( b_on );
804 telexTransparent->setEnabled( b_on );
805 telexPage->setEnabled( b_on );
806 b_telexEnabled = b_on;
809 void ControlsWidget::toggleTeletextTransparency()
811 if( b_telexTransparent )
813 telexTransparent->setIcon( QIcon( ":/tvtelx" ) );
814 telexTransparent->setToolTip( qtr( "Teletext" ) );
815 b_telexTransparent = false;
819 telexTransparent->setIcon( QIcon( ":/tvtelx-trans" ) );
820 telexTransparent->setToolTip( qtr( "Transparent" ) );
821 b_telexTransparent = true;
825 void ControlsWidget::stop()
830 void ControlsWidget::play()
832 if( THEPL->current.i_size == 0 )
834 /* The playlist is empty, open a file requester */
835 THEDP->openFileDialog();
839 THEMIM->togglePlayPause();
842 void ControlsWidget::prev()
847 void ControlsWidget::next()
852 void ControlsWidget::setNavigation( int navigation )
854 #define HELP_PCH N_( "Previous chapter" )
855 #define HELP_NCH N_( "Next chapter" )
857 // 1 = chapter, 2 = title, 0 = no
858 if( navigation == 0 )
861 } else if( navigation == 1 ) {
862 prevSectionButton->setToolTip( qtr( HELP_PCH ) );
863 nextSectionButton->setToolTip( qtr( HELP_NCH ) );
867 prevSectionButton->setToolTip( qtr( HELP_PCH ) );
868 nextSectionButton->setToolTip( qtr( HELP_NCH ) );
874 static bool b_my_volume;
875 void ControlsWidget::updateVolume( int i_sliderVolume )
879 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
880 aout_VolumeSet( p_intf, i_res );
882 if( i_sliderVolume == 0 )
884 volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
885 volMuteLabel->setToolTip( qtr( "Unmute" ) );
889 if( i_sliderVolume < VOLUME_MAX / 3 )
890 volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
891 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
892 volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
893 else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
894 volMuteLabel->setToolTip( qtr( "Mute" ) );
897 void ControlsWidget::updateVolume()
900 audio_volume_t i_volume;
901 aout_VolumeGet( p_intf, &i_volume );
902 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
903 int i_gauge = volumeSlider->value();
905 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
908 volumeSlider->setValue( i_volume );
913 void ControlsWidget::updateInput()
915 /* Activate the interface buttons according to the presence of the input */
916 enableInput( THEMIM->getIM()->hasInput() );
917 enableVideo( THEMIM->getIM()->hasVideo() );
920 void ControlsWidget::setStatus( int status )
922 if( status == PLAYING_S ) /* Playing */
924 playButton->setIcon( QIcon( ":/pause_b" ) );
925 playButton->setToolTip( qtr( "Pause the playback" ) );
929 playButton->setIcon( QIcon( ":/play_b" ) );
930 playButton->setToolTip( qtr( I_PLAY_TOOLTIP ) );
936 * This functions toggle the fullscreen mode
937 * If there is no video, it should first activate Visualisations...
938 * This has also to be fixed in enableVideo()
940 void ControlsWidget::fullscreen()
942 vout_thread_t *p_vout =
943 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
946 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
947 vlc_object_release( p_vout );
951 void ControlsWidget::extSettings()
953 THEDP->extendedDialog();
956 void ControlsWidget::slower()
958 THEMIM->getIM()->slower();
961 void ControlsWidget::faster()
963 THEMIM->getIM()->faster();
966 void ControlsWidget::enableInput( bool enable )
968 slowerButton->setEnabled( enable );
969 slider->setEnabled( enable );
970 slider->setSliderPosition ( 0 );
971 fasterButton->setEnabled( enable );
973 /* Advanced Buttons too */
974 advControls->enableInput( enable );
977 void ControlsWidget::enableVideo( bool enable )
979 // TODO Later make the fullscreenButton toggle Visualisation and so on.
980 fullscreenButton->setEnabled( enable );
982 /* Advanced Buttons too */
983 advControls->enableVideo( enable );
986 void ControlsWidget::toggleAdvanced()
988 if( advControls && !b_advancedVisible )
991 b_advancedVisible = true;
996 b_advancedVisible = false;
998 emit advancedControlsToggled( b_advancedVisible );
1001 /**********************************************************************
1002 * Fullscrenn control widget
1003 **********************************************************************/
1004 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
1005 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
1006 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
1007 i_mouse_last_x( -1 ), i_mouse_last_y( -1 ), b_mouse_over(false),
1008 b_slow_hide_begin(false), i_slow_hide_timeout(1),
1009 b_fullscreen( false ), i_hide_timeout( 1 ), p_vout(NULL)
1011 setWindowFlags( Qt::ToolTip );
1013 setFrameShape( QFrame::StyledPanel );
1014 setFrameStyle( QFrame::Sunken );
1015 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
1017 QGridLayout *fsLayout = new QGridLayout( this );
1018 fsLayout->setLayoutMargins( 5, 2, 5, 2, 5 );
1021 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
1022 slider->setMinimumWidth( 220 );
1023 fsLayout->addWidget( slowerButton, 0, 0 );
1024 fsLayout->addWidget( slider, 0, 1, 1, 9 );
1025 fsLayout->addWidget( fasterButton, 0, 10 );
1027 fsLayout->addWidget( playButton, 1, 0, 1, 2 );
1028 fsLayout->addLayout( controlButLayout, 1, 2 );
1030 fsLayout->addWidget( discFrame, 1, 3 );
1031 fsLayout->addWidget( telexFrame, 1, 4 );
1032 fsLayout->addWidget( fullscreenButton, 1, 5 );
1033 fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
1035 fsLayout->setColumnStretch( 7, 10 );
1036 fsLayout->addWidget( volMuteLabel, 1, 8 );
1037 fsLayout->addWidget( volumeSlider, 1, 9, 1, 2 );
1040 p_hideTimer = new QTimer( this );
1041 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
1042 p_hideTimer->setSingleShot( true );
1044 /* slow hiding timer */
1045 #if HAVE_TRANSPARENCY
1046 p_slowHideTimer = new QTimer( this );
1047 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
1050 adjustSize (); /* need to get real width and height for moving */
1053 QDesktopWidget * p_desktop = QApplication::desktop();
1055 move( p_desktop->width() / 2 - width() / 2,
1056 p_desktop->height() - height() );
1059 setWindowOpacity( 0.0 );
1065 fullscreenButton->setIcon( QIcon( ":/defullscreen" ) );
1067 vlc_mutex_init_recursive( &lock );
1070 FullscreenControllerWidget::~FullscreenControllerWidget()
1073 vlc_mutex_destroy( &lock );
1077 * Show fullscreen controller
1079 void FullscreenControllerWidget::showFSC()
1083 // after quiting and going to fs, we need to call show()
1089 b_fscHidden = false;
1090 setWindowOpacity( 1.0 );
1096 #if HAVE_TRANSPARENCY
1097 setWindowOpacity( DEFAULT_OPACITY );
1102 * Hide fullscreen controller
1103 * FIXME: under windows it have to be done by moving out of screen
1104 * because hide() doesnt work
1106 void FullscreenControllerWidget::hideFSC()
1110 setWindowOpacity( 0.0 ); // simulate hidding
1117 * Plane to hide fullscreen controller
1119 void FullscreenControllerWidget::planHideFSC()
1121 vlc_mutex_lock( &lock );
1122 int i_timeout = i_hide_timeout;
1123 vlc_mutex_unlock( &lock );
1125 p_hideTimer->start( i_timeout );
1127 #if HAVE_TRANSPARENCY
1128 b_slow_hide_begin = true;
1129 i_slow_hide_timeout = i_timeout;
1130 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
1135 * Hidding fullscreen controller slowly
1136 * Linux: need composite manager
1137 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
1139 void FullscreenControllerWidget::slowHideFSC()
1141 #if HAVE_TRANSPARENCY
1142 if( b_slow_hide_begin )
1144 b_slow_hide_begin = false;
1146 p_slowHideTimer->stop();
1147 /* the last part of time divided to 100 pieces */
1148 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
1154 if ( windowOpacity() > 0.0 && !b_fscHidden )
1156 if ( windowOpacity() > 0.0 )
1159 /* we should use 0.01 because of 100 pieces ^^^
1160 but than it cannt be done in time */
1161 setWindowOpacity( windowOpacity() - 0.02 );
1164 if ( windowOpacity() <= 0.0 )
1165 p_slowHideTimer->stop();
1172 * events: show, hide, start timer for hidding
1174 void FullscreenControllerWidget::customEvent( QEvent *event )
1178 switch( event->type() )
1180 case FullscreenControlToggle_Type:
1181 vlc_mutex_lock( &lock );
1182 b_fs = b_fullscreen;
1183 vlc_mutex_unlock( &lock );
1191 p_hideTimer->stop();
1197 case FullscreenControlShow_Type:
1198 vlc_mutex_lock( &lock );
1199 b_fs = b_fullscreen;
1200 vlc_mutex_unlock( &lock );
1202 if( b_fs ) // FIXME I am not sure about that one
1205 case FullscreenControlHide_Type:
1208 case FullscreenControlPlanHide_Type:
1209 if( !b_mouse_over ) // Only if the mouse is not over FSC
1219 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1221 if ( event->buttons() == Qt::LeftButton )
1223 int i_moveX = event->globalX() - i_mouse_last_x;
1224 int i_moveY = event->globalY() - i_mouse_last_y;
1226 move( x() + i_moveX, y() + i_moveY );
1228 i_mouse_last_x = event->globalX();
1229 i_mouse_last_y = event->globalY();
1235 * store position of cursor
1237 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1239 i_mouse_last_x = event->globalX();
1240 i_mouse_last_y = event->globalY();
1244 * On mouse go above FSC
1246 void FullscreenControllerWidget::enterEvent( QEvent *event )
1248 b_mouse_over = true;
1250 p_hideTimer->stop();
1251 #if HAVE_TRANSPARENCY
1252 p_slowHideTimer->stop();
1257 * On mouse go out from FSC
1259 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1263 b_mouse_over = false;
1267 * When you get pressed key, send it to video output
1268 * FIXME: clearing focus by clearFocus() to not getting
1269 * key press events didnt work
1271 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1273 int i_vlck = qtEventToVLCKey( event );
1276 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1284 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object, const char *variable,
1285 vlc_value_t old_val, vlc_value_t new_val,
1288 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1289 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1291 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1296 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1297 vlc_value_t old_val, vlc_value_t new_val,
1300 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1303 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1304 QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1306 /* Plan hide event */
1307 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1308 QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1315 * It is called when video start
1317 void FullscreenControllerWidget::attachVout( vout_thread_t *p_nvout )
1319 assert( p_nvout && !p_vout );
1323 vlc_mutex_lock( &lock );
1324 var_AddCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this ); /* I miss a add and fire */
1325 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ), var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1326 vlc_mutex_unlock( &lock );
1329 * It is called after turn off video.
1331 void FullscreenControllerWidget::detachVout()
1335 var_DelCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this );
1336 vlc_mutex_lock( &lock );
1337 fullscreenChanged( p_vout, false, 0 );
1338 vlc_mutex_unlock( &lock );
1344 * Register and unregister callback for mouse moving
1346 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout, bool b_fs, int i_timeout )
1348 vlc_mutex_lock( &lock );
1349 if( b_fs && !b_fullscreen )
1351 b_fullscreen = true;
1352 i_hide_timeout = i_timeout;
1353 var_AddCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1355 else if( !b_fs && b_fullscreen )
1357 b_fullscreen = false;
1358 i_hide_timeout = i_timeout;
1359 var_DelCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1361 /* Force fs hidding */
1362 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1363 QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1365 vlc_mutex_unlock( &lock );
1368 /**********************************************************************
1369 * Speed control widget
1370 **********************************************************************/
1371 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1372 QFrame( NULL ), p_intf( _p_i )
1374 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1375 sizePolicy.setHorizontalStretch( 0 );
1376 sizePolicy.setVerticalStretch( 0 );
1378 speedSlider = new QSlider;
1379 speedSlider->setSizePolicy( sizePolicy );
1380 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1381 speedSlider->setOrientation( Qt::Vertical );
1382 speedSlider->setTickPosition( QSlider::TicksRight );
1384 speedSlider->setRange( -24, 24 );
1385 speedSlider->setSingleStep( 1 );
1386 speedSlider->setPageStep( 1 );
1387 speedSlider->setTickInterval( 12 );
1389 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1391 QToolButton *normalSpeedButton = new QToolButton( this );
1392 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1393 normalSpeedButton->setAutoRaise( true );
1394 normalSpeedButton->setText( "1x" );
1395 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1397 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1399 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1400 speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
1401 speedControlLayout->setSpacing( 4 );
1402 speedControlLayout->addWidget( speedSlider );
1403 speedControlLayout->addWidget( normalSpeedButton );
1404 setLayout( speedControlLayout );
1407 SpeedControlWidget::~SpeedControlWidget()
1410 void SpeedControlWidget::setEnable( bool b_enable )
1412 speedSlider->setEnabled( b_enable );
1415 void SpeedControlWidget::updateControls( int rate )
1417 if( speedSlider->isSliderDown() )
1419 //We don't want to change anything if the user is using the slider
1423 double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
1424 int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
1426 if( sliderValue < speedSlider->minimum() )
1428 sliderValue = speedSlider->minimum();
1430 else if( sliderValue > speedSlider->maximum() )
1432 sliderValue = speedSlider->maximum();
1435 //Block signals to avoid feedback loop
1436 speedSlider->blockSignals( true );
1437 speedSlider->setValue( sliderValue );
1438 speedSlider->blockSignals( false );
1441 void SpeedControlWidget::updateRate( int sliderValue )
1443 double speed = pow( 2, (double)sliderValue / 12 );
1444 int rate = INPUT_RATE_DEFAULT / speed;
1446 THEMIM->getIM()->setRate(rate);
1449 void SpeedControlWidget::resetRate()
1451 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
1456 static int downloadCoverCallback( vlc_object_t *p_this,
1457 char const *psz_var,
1458 vlc_value_t oldvar, vlc_value_t newvar,
1461 if( !strcmp( psz_var, "item-change" ) )
1463 CoverArtLabel *art = static_cast< CoverArtLabel* >( data );
1465 art->requestUpdate();
1470 CoverArtLabel::CoverArtLabel( vlc_object_t *_p_this, input_item_t *_p_input )
1471 : p_this( _p_this), p_input( _p_input ), prevArt()
1473 setContextMenuPolicy( Qt::ActionsContextMenu );
1474 CONNECT( this, updateRequested(), this, doUpdate() );
1476 playlist_t *p_playlist = pl_Yield( p_this );
1477 var_AddCallback( p_playlist, "item-change",
1478 downloadCoverCallback, this );
1479 pl_Release( p_this );
1481 setMinimumHeight( 128 );
1482 setMinimumWidth( 128 );
1483 setMaximumHeight( 128 );
1484 setMaximumWidth( 128 );
1485 setScaledContents( true );
1490 void CoverArtLabel::downloadCover()
1494 playlist_t *p_playlist = pl_Yield( p_this );
1495 playlist_AskForArtEnqueue( p_playlist, p_input );
1496 pl_Release( p_this );
1500 void CoverArtLabel::doUpdate()
1504 setPixmap( QPixmap( ":/noart.png" ) );
1505 QList< QAction* > artActions = actions();
1506 if( !artActions.isEmpty() )
1507 foreach( QAction *act, artActions )
1508 removeAction( act );
1513 char *psz_meta = input_item_GetArtURL( p_input );
1514 if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
1516 QString artUrl = qfu( psz_meta ).replace( "file://", "" );
1517 if( artUrl != prevArt )
1518 setPixmap( QPixmap( artUrl ) );
1519 QList< QAction* > artActions = actions();
1520 if( !artActions.isEmpty() )
1522 foreach( QAction *act, artActions )
1523 removeAction( act );
1530 setPixmap( QPixmap( ":/noart.png" ) );
1532 QList< QAction* > artActions = actions();
1533 if( artActions.isEmpty() )
1535 QAction *action = new QAction( qtr( "Download cover art" ),
1537 addAction( action );
1538 CONNECT( action, triggered(),
1539 this, downloadCover() );