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 );
408 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
411 /* Function called when the button is clicked() */
412 void AdvControlsWidget::fromAtoB()
416 timeA = var_GetTime( THEMIM->getInput(), "time" );
422 timeB = var_GetTime( THEMIM->getInput(), "time" );
423 var_SetTime( THEMIM->getInput(), "time" , timeA );
432 /* setting/synchro icons after click on main or fs controller */
433 void AdvControlsWidget::setIcon()
435 if( !timeA && !timeB)
437 ABButton->setIcon( QIcon( ":/atob_nob" ) );
438 ABButton->setToolTip( qtr( "Loop from point A to point B continuously\nClick to set point A" ) );
440 else if( timeA && !timeB )
442 ABButton->setIcon( QIcon( ":/atob_noa" ) );
443 ABButton->setToolTip( qtr( "Click to set point B" ) );
445 else if( timeA && timeB )
447 ABButton->setIcon( QIcon( ":/atob" ) );
448 ABButton->setToolTip( qtr( "Stop the A to B loop" ) );
452 /* Function called regularly when in an AtoB loop */
453 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
457 if( ( i_time >= (int)( timeB/1000000 ) )
458 || ( i_time < (int)( timeA/1000000 ) ) )
459 var_SetTime( THEMIM->getInput(), "time" , timeA );
463 void AdvControlsWidget::record()
465 input_thread_t *p_input = THEMIM->getInput();
468 /* This method won't work fine if the stream can't be cut anywhere */
469 const bool b_recording = var_GetBool( p_input, "record" );
470 var_SetBool( p_input, "record", !b_recording );
474 /* 'record' access-filter is not loaded, we open Save dialog */
475 input_item_t *p_item = input_GetItem( p_input );
479 char *psz = input_item_GetURI( p_item );
481 THEDP->streamingDialog( NULL, psz, true );
488 //FIXME Frame by frame function
489 void AdvControlsWidget::frame(){}
492 /*****************************
493 * DA Control Widget !
494 *****************************/
495 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
496 MainInterface *_p_mi,
500 QFrame( _p_mi ), p_intf( _p_i )
502 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
504 /** The main Slider **/
505 slider = new InputSlider( Qt::Horizontal, NULL );
506 /* Update the position when the IM has changed */
507 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
508 slider, setPosition( float, int, int ) );
509 /* And update the IM, when the position has changed */
510 CONNECT( slider, sliderDragged( float ),
511 THEMIM->getIM(), sliderUpdate( float ) );
513 /** Slower and faster Buttons **/
514 slowerButton = new QToolButton;
515 slowerButton->setAutoRaise( true );
516 slowerButton->setMaximumSize( QSize( 26, 20 ) );
518 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
520 fasterButton = new QToolButton;
521 fasterButton->setAutoRaise( true );
522 fasterButton->setMaximumSize( QSize( 26, 20 ) );
524 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
526 /* advanced Controls handling */
527 b_advancedVisible = b_advControls;
529 advControls = new AdvControlsWidget( p_intf, b_fsCreation );
530 if( !b_advancedVisible ) advControls->hide();
532 /** Disc and Menus handling */
533 discFrame = new QWidget( this );
535 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
536 discLayout->setSpacing( 0 );
537 discLayout->setMargin( 0 );
539 prevSectionButton = new QPushButton( discFrame );
540 setupSmallButton( prevSectionButton );
541 discLayout->addWidget( prevSectionButton );
543 menuButton = new QPushButton( discFrame );
544 setupSmallButton( menuButton );
545 discLayout->addWidget( menuButton );
547 nextSectionButton = new QPushButton( discFrame );
548 setupSmallButton( nextSectionButton );
549 discLayout->addWidget( nextSectionButton );
551 BUTTON_SET_IMG( prevSectionButton, "", dvd_prev, "" );
552 BUTTON_SET_IMG( nextSectionButton, "", dvd_next, "" );
553 BUTTON_SET_IMG( menuButton, "", dvd_menu, qtr( "Menu" ) );
557 /* Change the navigation button display when the IM navigation changes */
558 CONNECT( THEMIM->getIM(), navigationChanged( int ),
559 this, setNavigation( int ) );
560 /* Changes the IM navigation when triggered on the nav buttons */
561 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
563 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
565 CONNECT( menuButton, clicked(), THEMIM->getIM(),
570 * TODO: Merge with upper menu in a StackLayout
572 telexFrame = new QWidget( this );
573 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
574 telexLayout->setSpacing( 0 );
575 telexLayout->setMargin( 0 );
577 telexOn = new QPushButton;
578 setupSmallButton( telexOn );
579 telexLayout->addWidget( telexOn );
581 telexTransparent = new QPushButton;
582 setupSmallButton( telexTransparent );
583 telexLayout->addWidget( telexTransparent );
584 b_telexTransparent = false;
586 telexPage = new QSpinBox;
587 telexPage->setRange( 0, 999 );
588 telexPage->setValue( 100 );
589 telexPage->setAccelerated( true );
590 telexPage->setWrapping( true );
591 telexPage->setAlignment( Qt::AlignRight );
592 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
593 telexLayout->addWidget( telexPage );
595 telexFrame->hide(); /* default hidden */
597 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
598 telexGotoPage( int ) );
599 CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
600 telexPage, setValue( int ) );
602 BUTTON_SET_IMG( telexOn, "", tv, qtr( "Teletext on" ) );
604 CONNECT( telexOn, clicked(), THEMIM->getIM(),
605 telexToggleButtons() );
606 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
607 telexToggle( bool ) );
608 CONNECT( THEMIM->getIM(), toggleTelexButtons(),
609 this, toggleTeletext() );
610 b_telexEnabled = false;
611 telexTransparent->setEnabled( false );
612 telexPage->setEnabled( false );
614 BUTTON_SET_IMG( telexTransparent, "", tvtelx, qtr( "Teletext" ) );
615 CONNECT( telexTransparent, clicked( bool ),
616 THEMIM->getIM(), telexSetTransparency() );
617 CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
618 this, toggleTeletextTransparency() );
619 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
620 this, enableTeletext( bool ) );
623 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
624 sizePolicy.setHorizontalStretch( 0 );
625 sizePolicy.setVerticalStretch( 0 );
628 playButton = new QPushButton;
629 playButton->setSizePolicy( sizePolicy );
630 playButton->setMaximumSize( QSize( 36, 36 ) );
631 playButton->setMinimumSize( QSize( 36, 36 ) );
632 playButton->setIconSize( QSize( 30, 30 ) );
635 /** Prev + Stop + Next Block **/
636 controlButLayout = new QHBoxLayout;
637 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
640 QPushButton *prevButton = new QPushButton;
641 prevButton->setSizePolicy( sizePolicy );
642 setupSmallButton( prevButton );
644 controlButLayout->addWidget( prevButton );
647 QPushButton *stopButton = new QPushButton;
648 stopButton->setSizePolicy( sizePolicy );
649 setupSmallButton( stopButton );
651 controlButLayout->addWidget( stopButton );
654 QPushButton *nextButton = new QPushButton;
655 nextButton->setSizePolicy( sizePolicy );
656 setupSmallButton( nextButton );
658 controlButLayout->addWidget( nextButton );
660 /* Add this block to the main layout */
662 BUTTON_SET_ACT_I( playButton, "", play_b, qtr( I_PLAY_TOOLTIP ), play() );
663 BUTTON_SET_ACT_I( prevButton, "" , previous_b,
664 qtr( "Previous media in the playlist" ), prev() );
665 BUTTON_SET_ACT_I( nextButton, "", next_b,
666 qtr( "Next media in the playlist" ), next() );
667 BUTTON_SET_ACT_I( stopButton, "", stop_b, qtr( "Stop playback" ), stop() );
670 * Other first Line buttons
672 /** Fullscreen/Visualisation **/
673 fullscreenButton = new QPushButton;
674 BUTTON_SET_ACT_I( fullscreenButton, "", fullscreen,
675 qtr( "Toggle the video in fullscreen" ), fullscreen() );
676 setupSmallButton( fullscreenButton );
680 /** Playlist Button **/
681 playlistButton = new QPushButton;
682 setupSmallButton( playlistButton );
683 BUTTON_SET_IMG( playlistButton, "" , playlist, qtr( "Show playlist" ) );
684 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
686 /** extended Settings **/
687 extSettingsButton = new QPushButton;
688 BUTTON_SET_ACT_I( extSettingsButton, "", extended,
689 qtr( "Show extended settings" ), extSettings() );
690 setupSmallButton( extSettingsButton );
694 hVolLabel = new VolumeClickHandler( p_intf, this );
696 volMuteLabel = new QLabel;
697 volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
698 volMuteLabel->installEventFilter( hVolLabel );
702 volumeSlider = new SoundSlider( this,
703 config_GetInt( p_intf, "volume-step" ),
704 config_GetInt( p_intf, "qt-volume-complete" ),
705 config_GetPsz( p_intf, "qt-slider-colours" ) );
709 volumeSlider = new QSlider( this );
710 volumeSlider->setOrientation( Qt::Horizontal );
712 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
713 volumeSlider->setMinimumSize( QSize( 85, 30 ) );
714 volumeSlider->setFocusPolicy( Qt::NoFocus );
716 /* Set the volume from the config */
717 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
718 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
720 /* Force the update at build time in order to have a muted icon if needed */
721 updateVolume( volumeSlider->value() );
723 /* Volume control connection */
724 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
725 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
729 controlLayout = new QGridLayout( this );
731 controlLayout->setSpacing( 0 );
732 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
734 controlLayout->addWidget( slider, 0, 1, 1, 18 );
735 controlLayout->addWidget( slowerButton, 0, 0 );
736 controlLayout->addWidget( fasterButton, 0, 19 );
738 controlLayout->addWidget( discFrame, 1, 8, 2, 3, Qt::AlignBottom );
739 controlLayout->addWidget( telexFrame, 1, 8, 2, 5, Qt::AlignBottom );
741 controlLayout->addWidget( playButton, 2, 0, 2, 2, Qt::AlignBottom );
742 controlLayout->setColumnMinimumWidth( 2, 10 );
743 controlLayout->setColumnStretch( 2, 0 );
745 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
746 /* Column 6 is unused */
747 controlLayout->setColumnStretch( 6, 0 );
748 controlLayout->setColumnStretch( 7, 0 );
749 controlLayout->setColumnMinimumWidth( 7, 10 );
751 controlLayout->addWidget( fullscreenButton, 3, 8, Qt::AlignBottom );
752 controlLayout->addWidget( playlistButton, 3, 9, Qt::AlignBottom );
753 controlLayout->addWidget( extSettingsButton, 3, 10, Qt::AlignBottom );
754 controlLayout->setColumnStretch( 11, 0 ); /* telex alignment */
756 controlLayout->setColumnStretch( 12, 0 );
757 controlLayout->setColumnMinimumWidth( 12, 10 );
759 controlLayout->addWidget( advControls, 3, 13, 1, 3, Qt::AlignBottom );
761 controlLayout->setColumnStretch( 16, 10 );
762 controlLayout->setColumnMinimumWidth( 16, 10 );
764 controlLayout->addWidget( volMuteLabel, 3, 17, Qt::AlignBottom );
765 controlLayout->addWidget( volumeSlider, 3, 18, 1 , 2, Qt::AlignBottom );
771 ControlsWidget::~ControlsWidget()
774 void ControlsWidget::toggleTeletext()
776 bool b_enabled = THEMIM->teletextState();
779 telexTransparent->setEnabled( false );
780 telexPage->setEnabled( false );
781 b_telexEnabled = false;
785 telexTransparent->setEnabled( true );
786 telexPage->setEnabled( true );
787 b_telexEnabled = true;
791 void ControlsWidget::enableTeletext( bool b_enable )
793 telexFrame->setVisible( b_enable );
794 bool b_on = THEMIM->teletextState();
796 telexOn->setChecked( b_on );
797 telexTransparent->setEnabled( b_on );
798 telexPage->setEnabled( b_on );
799 b_telexEnabled = b_on;
802 void ControlsWidget::toggleTeletextTransparency()
804 if( b_telexTransparent )
806 telexTransparent->setIcon( QIcon( ":/tvtelx" ) );
807 telexTransparent->setToolTip( qtr( "Teletext" ) );
808 b_telexTransparent = false;
812 telexTransparent->setIcon( QIcon( ":/tvtelx-transparent" ) );
813 telexTransparent->setToolTip( qtr( "Transparent" ) );
814 b_telexTransparent = true;
818 void ControlsWidget::stop()
823 void ControlsWidget::play()
825 if( THEPL->current.i_size == 0 )
827 /* The playlist is empty, open a file requester */
828 THEDP->openFileDialog();
832 THEMIM->togglePlayPause();
835 void ControlsWidget::prev()
840 void ControlsWidget::next()
845 void ControlsWidget::setNavigation( int navigation )
847 #define HELP_PCH N_( "Previous chapter" )
848 #define HELP_NCH N_( "Next chapter" )
850 // 1 = chapter, 2 = title, 0 = no
851 if( navigation == 0 )
854 } else if( navigation == 1 ) {
855 prevSectionButton->setToolTip( qtr( HELP_PCH ) );
856 nextSectionButton->setToolTip( qtr( HELP_NCH ) );
860 prevSectionButton->setToolTip( qtr( HELP_PCH ) );
861 nextSectionButton->setToolTip( qtr( HELP_NCH ) );
867 static bool b_my_volume;
868 void ControlsWidget::updateVolume( int i_sliderVolume )
872 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
873 aout_VolumeSet( p_intf, i_res );
875 if( i_sliderVolume == 0 )
877 volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
878 volMuteLabel->setToolTip( qtr( "Unmute" ) );
882 if( i_sliderVolume < VOLUME_MAX / 3 )
883 volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
884 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
885 volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
886 else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
887 volMuteLabel->setToolTip( qtr( "Mute" ) );
890 void ControlsWidget::updateVolume()
893 audio_volume_t i_volume;
894 aout_VolumeGet( p_intf, &i_volume );
895 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
896 int i_gauge = volumeSlider->value();
898 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
901 volumeSlider->setValue( i_volume );
906 void ControlsWidget::updateInput()
908 /* Activate the interface buttons according to the presence of the input */
909 enableInput( THEMIM->getIM()->hasInput() );
910 enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
913 void ControlsWidget::setStatus( int status )
915 if( status == PLAYING_S ) /* Playing */
917 playButton->setIcon( QIcon( ":/pause_b" ) );
918 playButton->setToolTip( qtr( "Pause the playback" ) );
922 playButton->setIcon( QIcon( ":/play_b" ) );
923 playButton->setToolTip( qtr( I_PLAY_TOOLTIP ) );
929 * This functions toggle the fullscreen mode
930 * If there is no video, it should first activate Visualisations...
931 * This has also to be fixed in enableVideo()
933 void ControlsWidget::fullscreen()
935 vout_thread_t *p_vout =
936 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
939 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
940 vlc_object_release( p_vout );
944 void ControlsWidget::extSettings()
946 THEDP->extendedDialog();
949 void ControlsWidget::slower()
951 THEMIM->getIM()->slower();
954 void ControlsWidget::faster()
956 THEMIM->getIM()->faster();
959 void ControlsWidget::enableInput( bool enable )
961 slowerButton->setEnabled( enable );
962 slider->setEnabled( enable );
963 slider->setSliderPosition ( 0 );
964 fasterButton->setEnabled( enable );
966 /* Advanced Buttons too */
967 advControls->enableInput( enable );
970 void ControlsWidget::enableVideo( bool enable )
972 // TODO Later make the fullscreenButton toggle Visualisation and so on.
973 fullscreenButton->setEnabled( enable );
975 /* Advanced Buttons too */
976 advControls->enableVideo( enable );
979 void ControlsWidget::toggleAdvanced()
981 if( advControls && !b_advancedVisible )
984 b_advancedVisible = true;
989 b_advancedVisible = false;
991 emit advancedControlsToggled( b_advancedVisible );
995 /**********************************************************************
996 * Fullscrenn control widget
997 **********************************************************************/
998 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
999 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
1000 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
1001 i_mouse_last_x( -1 ), i_mouse_last_y( -1 ), b_mouse_over(false),
1002 b_slow_hide_begin(false), i_slow_hide_timeout(1),
1003 b_fullscreen( false ), i_hide_timeout( 1 ), p_vout(NULL)
1005 setWindowFlags( Qt::ToolTip );
1007 setFrameShape( QFrame::StyledPanel );
1008 setFrameStyle( QFrame::Sunken );
1009 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
1011 QGridLayout *fsLayout = new QGridLayout( this );
1012 fsLayout->setLayoutMargins( 5, 2, 5, 2, 5 );
1015 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
1016 slider->setMinimumWidth( 220 );
1017 fsLayout->addWidget( slowerButton, 0, 0 );
1018 fsLayout->addWidget( slider, 0, 1, 1, 9 );
1019 fsLayout->addWidget( fasterButton, 0, 10 );
1021 fsLayout->addWidget( playButton, 1, 0, 1, 2 );
1022 fsLayout->addLayout( controlButLayout, 1, 2 );
1024 fsLayout->addWidget( discFrame, 1, 3 );
1025 fsLayout->addWidget( telexFrame, 1, 4 );
1026 fsLayout->addWidget( fullscreenButton, 1, 5 );
1027 fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
1029 fsLayout->setColumnStretch( 7, 10 );
1030 fsLayout->addWidget( volMuteLabel, 1, 8 );
1031 fsLayout->addWidget( volumeSlider, 1, 9, 1, 2 );
1034 p_hideTimer = new QTimer( this );
1035 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
1036 p_hideTimer->setSingleShot( true );
1038 /* slow hiding timer */
1039 #if HAVE_TRANSPARENCY
1040 p_slowHideTimer = new QTimer( this );
1041 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
1044 adjustSize (); /* need to get real width and height for moving */
1047 QDesktopWidget * p_desktop = QApplication::desktop();
1049 move( p_desktop->width() / 2 - width() / 2,
1050 p_desktop->height() - height() );
1053 setWindowOpacity( 0.0 );
1059 fullscreenButton->setIcon( QIcon( ":/defullscreen" ) );
1061 vlc_mutex_init_recursive( &lock );
1064 FullscreenControllerWidget::~FullscreenControllerWidget()
1067 vlc_mutex_destroy( &lock );
1071 * Show fullscreen controller
1073 void FullscreenControllerWidget::showFSC()
1077 // after quiting and going to fs, we need to call show()
1083 b_fscHidden = false;
1084 setWindowOpacity( 1.0 );
1090 #if HAVE_TRANSPARENCY
1091 setWindowOpacity( DEFAULT_OPACITY );
1096 * Hide fullscreen controller
1097 * FIXME: under windows it have to be done by moving out of screen
1098 * because hide() doesnt work
1100 void FullscreenControllerWidget::hideFSC()
1104 setWindowOpacity( 0.0 ); // simulate hidding
1111 * Plane to hide fullscreen controller
1113 void FullscreenControllerWidget::planHideFSC()
1115 vlc_mutex_lock( &lock );
1116 int i_timeout = i_hide_timeout;
1117 vlc_mutex_unlock( &lock );
1119 p_hideTimer->start( i_timeout );
1121 #if HAVE_TRANSPARENCY
1122 b_slow_hide_begin = true;
1123 i_slow_hide_timeout = i_timeout;
1124 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
1129 * Hidding fullscreen controller slowly
1130 * Linux: need composite manager
1131 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
1133 void FullscreenControllerWidget::slowHideFSC()
1135 #if HAVE_TRANSPARENCY
1136 if( b_slow_hide_begin )
1138 b_slow_hide_begin = false;
1140 p_slowHideTimer->stop();
1141 /* the last part of time divided to 100 pieces */
1142 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
1148 if ( windowOpacity() > 0.0 && !b_fscHidden )
1150 if ( windowOpacity() > 0.0 )
1153 /* we should use 0.01 because of 100 pieces ^^^
1154 but than it cannt be done in time */
1155 setWindowOpacity( windowOpacity() - 0.02 );
1158 if ( windowOpacity() <= 0.0 )
1159 p_slowHideTimer->stop();
1166 * events: show, hide, start timer for hidding
1168 void FullscreenControllerWidget::customEvent( QEvent *event )
1172 switch( event->type() )
1174 case FullscreenControlToggle_Type:
1175 vlc_mutex_lock( &lock );
1176 b_fs = b_fullscreen;
1177 vlc_mutex_unlock( &lock );
1185 p_hideTimer->stop();
1191 case FullscreenControlShow_Type:
1192 vlc_mutex_lock( &lock );
1193 b_fs = b_fullscreen;
1194 vlc_mutex_unlock( &lock );
1196 if( b_fs ) // FIXME I am not sure about that one
1199 case FullscreenControlHide_Type:
1202 case FullscreenControlPlanHide_Type:
1203 if( !b_mouse_over ) // Only if the mouse is not over FSC
1213 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1215 if ( event->buttons() == Qt::LeftButton )
1217 int i_moveX = event->globalX() - i_mouse_last_x;
1218 int i_moveY = event->globalY() - i_mouse_last_y;
1220 move( x() + i_moveX, y() + i_moveY );
1222 i_mouse_last_x = event->globalX();
1223 i_mouse_last_y = event->globalY();
1229 * store position of cursor
1231 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1233 i_mouse_last_x = event->globalX();
1234 i_mouse_last_y = event->globalY();
1238 * On mouse go above FSC
1240 void FullscreenControllerWidget::enterEvent( QEvent *event )
1242 b_mouse_over = true;
1244 p_hideTimer->stop();
1245 #if HAVE_TRANSPARENCY
1246 p_slowHideTimer->stop();
1251 * On mouse go out from FSC
1253 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1257 b_mouse_over = false;
1261 * When you get pressed key, send it to video output
1262 * FIXME: clearing focus by clearFocus() to not getting
1263 * key press events didnt work
1265 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1267 int i_vlck = qtEventToVLCKey( event );
1270 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1278 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object, const char *variable,
1279 vlc_value_t old_val, vlc_value_t new_val,
1282 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1283 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1285 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1290 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1291 vlc_value_t old_val, vlc_value_t new_val,
1294 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1297 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1298 QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1300 /* Plan hide event */
1301 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1302 QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1309 * It is called when video start
1311 void FullscreenControllerWidget::attachVout( vout_thread_t *p_nvout )
1313 assert( p_nvout && !p_vout );
1317 vlc_mutex_lock( &lock );
1318 var_AddCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this ); /* I miss a add and fire */
1319 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ), var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1320 vlc_mutex_unlock( &lock );
1323 * It is called after turn off video.
1325 void FullscreenControllerWidget::detachVout()
1329 var_DelCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this );
1330 vlc_mutex_lock( &lock );
1331 fullscreenChanged( p_vout, false, 0 );
1332 vlc_mutex_unlock( &lock );
1338 * Register and unregister callback for mouse moving
1340 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout, bool b_fs, int i_timeout )
1342 vlc_mutex_lock( &lock );
1343 if( b_fs && !b_fullscreen )
1345 b_fullscreen = true;
1346 i_hide_timeout = i_timeout;
1347 var_AddCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1349 else if( !b_fs && b_fullscreen )
1351 b_fullscreen = false;
1352 i_hide_timeout = i_timeout;
1353 var_DelCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1355 /* Force fs hidding */
1356 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1357 QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1359 vlc_mutex_unlock( &lock );
1362 /**********************************************************************
1363 * Speed control widget
1364 **********************************************************************/
1365 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1366 QFrame( NULL ), p_intf( _p_i )
1368 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1369 sizePolicy.setHorizontalStretch( 0 );
1370 sizePolicy.setVerticalStretch( 0 );
1372 speedSlider = new QSlider;
1373 speedSlider->setSizePolicy( sizePolicy );
1374 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1375 speedSlider->setOrientation( Qt::Vertical );
1376 speedSlider->setTickPosition( QSlider::TicksRight );
1378 speedSlider->setRange( -24, 24 );
1379 speedSlider->setSingleStep( 1 );
1380 speedSlider->setPageStep( 1 );
1381 speedSlider->setTickInterval( 12 );
1383 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1385 QToolButton *normalSpeedButton = new QToolButton( this );
1386 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1387 normalSpeedButton->setAutoRaise( true );
1388 normalSpeedButton->setText( "1x" );
1389 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1391 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1393 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1394 speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
1395 speedControlLayout->setSpacing( 4 );
1396 speedControlLayout->addWidget( speedSlider );
1397 speedControlLayout->addWidget( normalSpeedButton );
1398 setLayout( speedControlLayout );
1401 SpeedControlWidget::~SpeedControlWidget()
1404 void SpeedControlWidget::setEnable( bool b_enable )
1406 speedSlider->setEnabled( b_enable );
1409 void SpeedControlWidget::updateControls( int rate )
1411 if( speedSlider->isSliderDown() )
1413 //We don't want to change anything if the user is using the slider
1417 double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
1418 int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
1420 if( sliderValue < speedSlider->minimum() )
1422 sliderValue = speedSlider->minimum();
1424 else if( sliderValue > speedSlider->maximum() )
1426 sliderValue = speedSlider->maximum();
1429 //Block signals to avoid feedback loop
1430 speedSlider->blockSignals( true );
1431 speedSlider->setValue( sliderValue );
1432 speedSlider->blockSignals( false );
1435 void SpeedControlWidget::updateRate( int sliderValue )
1437 double speed = pow( 2, (double)sliderValue / 12 );
1438 int rate = INPUT_RATE_DEFAULT / speed;
1440 THEMIM->getIM()->setRate(rate);
1443 void SpeedControlWidget::resetRate()
1445 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
1450 static int downloadCoverCallback( vlc_object_t *p_this,
1451 char const *psz_var,
1452 vlc_value_t oldvar, vlc_value_t newvar,
1455 if( !strcmp( psz_var, "item-change" ) )
1457 CoverArtLabel *art = static_cast< CoverArtLabel* >( data );
1459 art->requestUpdate();
1464 CoverArtLabel::CoverArtLabel( vlc_object_t *_p_this, input_item_t *_p_input )
1465 : p_this( _p_this), p_input( _p_input ), prevArt()
1467 setContextMenuPolicy( Qt::ActionsContextMenu );
1468 CONNECT( this, updateRequested(), this, doUpdate() );
1470 playlist_t *p_playlist = pl_Yield( p_this );
1471 var_AddCallback( p_playlist, "item-change",
1472 downloadCoverCallback, this );
1473 pl_Release( p_this );
1475 setMinimumHeight( 128 );
1476 setMinimumWidth( 128 );
1477 setMaximumHeight( 128 );
1478 setMaximumWidth( 128 );
1479 setScaledContents( true );
1484 void CoverArtLabel::downloadCover()
1488 playlist_t *p_playlist = pl_Yield( p_this );
1489 playlist_AskForArtEnqueue( p_playlist, p_input );
1490 pl_Release( p_this );
1494 void CoverArtLabel::doUpdate()
1498 setPixmap( QPixmap( ":/noart.png" ) );
1499 QList< QAction* > artActions = actions();
1500 if( !artActions.isEmpty() )
1501 foreach( QAction *act, artActions )
1502 removeAction( act );
1507 char *psz_meta = input_item_GetArtURL( p_input );
1508 if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
1510 QString artUrl = qfu( psz_meta ).replace( "file://", "" );
1511 if( artUrl != prevArt )
1512 setPixmap( QPixmap( artUrl ) );
1513 QList< QAction* > artActions = actions();
1514 if( !artActions.isEmpty() )
1516 foreach( QAction *act, artActions )
1517 removeAction( act );
1524 setPixmap( QPixmap( ":/noart.png" ) );
1526 QList< QAction* > artActions = actions();
1527 if( artActions.isEmpty() )
1529 QAction *action = new QAction( qtr( "Download cover art" ),
1531 addAction( action );
1532 CONNECT( action, triggered(),
1533 this, downloadCover() );