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()
114 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
115 vout_Control( p_vout, VOUT_REPARENT );
119 * Request the video to avoid the conflicts
121 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
122 unsigned int *pi_width, unsigned int *pi_height )
124 msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
125 emit askVideoWidgetToShow( *pi_width, *pi_height );
128 msg_Dbg( p_intf, "embedded video already in use" );
133 msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );
135 return ( void* )winId();
138 /* Set the Widget to the correct Size */
139 /* Function has to be called by the parent
140 Parent has to care about resizing himself*/
141 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
143 msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
144 videoSize.rwidth() = w;
145 videoSize.rheight() = h;
146 if( isHidden() ) show();
147 updateGeometry(); // Needed for deinterlace
150 void VideoWidget::release( void *p_win )
152 msg_Dbg( p_intf, "Video is not needed anymore" );
154 videoSize.rwidth() = 0;
155 videoSize.rheight() = 0;
160 QSize VideoWidget::sizeHint() const
165 /**********************************************************************
166 * Background Widget. Show a simple image background. Currently,
167 * it's album art if present or cone.
168 **********************************************************************/
169 #define ICON_SIZE 128
170 #define MAX_BG_SIZE 400
171 #define MIN_BG_SIZE 128
173 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
174 :QWidget( NULL ), p_intf( _p_i )
176 /* We should use that one to take the more size it can */
177 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding);
179 /* A dark background */
180 setAutoFillBackground( true );
182 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
183 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
186 /* A cone in the middle */
188 label->setMargin( 5 );
189 label->setMaximumHeight( MAX_BG_SIZE );
190 label->setMaximumWidth( MAX_BG_SIZE );
191 label->setMinimumHeight( MIN_BG_SIZE );
192 label->setMinimumWidth( MIN_BG_SIZE );
193 if( QDate::currentDate().dayOfYear() >= 354 )
194 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
196 label->setPixmap( QPixmap( ":/vlc128.png" ) );
198 QGridLayout *backgroundLayout = new QGridLayout( this );
199 backgroundLayout->addWidget( label, 0, 1 );
200 backgroundLayout->setColumnStretch( 0, 1 );
201 backgroundLayout->setColumnStretch( 2, 1 );
203 CONNECT( THEMIM->getIM(), artChanged( input_item_t* ),
204 this, updateArt( input_item_t* ) );
207 BackgroundWidget::~BackgroundWidget()
210 void BackgroundWidget::resizeEvent( QResizeEvent * event )
212 if( event->size().height() <= MIN_BG_SIZE )
218 void BackgroundWidget::updateArt( input_item_t *p_item )
223 char *psz_art = input_item_GetArtURL( p_item );
230 if( QDate::currentDate().dayOfYear() >= 354 )
231 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
233 label->setPixmap( QPixmap( ":/vlc128.png" ) );
237 url = url.replace( "file://", QString("" ) );
238 /* Taglib seems to define a attachment://, It won't work yet */
239 url = url.replace( "attachment://", QString("" ) );
240 label->setPixmap( QPixmap( url ) );
244 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
246 QVLCMenu::PopupMenu( p_intf, true );
250 /**********************************************************************
251 * Visualization selector panel
252 **********************************************************************/
253 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
254 QFrame( NULL ), p_intf( _p_i )
256 QHBoxLayout *layout = new QHBoxLayout( this );
257 layout->setMargin( 0 );
258 QPushButton *prevButton = new QPushButton( "Prev" );
259 QPushButton *nextButton = new QPushButton( "Next" );
260 layout->addWidget( prevButton );
261 layout->addWidget( nextButton );
263 layout->addStretch( 10 );
264 layout->addWidget( new QLabel( qtr( "Current visualization" ) ) );
266 current = new QLabel( qtr( "None" ) );
267 layout->addWidget( current );
269 BUTTONACT( prevButton, prev() );
270 BUTTONACT( nextButton, next() );
273 setMaximumHeight( 35 );
276 VisualSelector::~VisualSelector()
279 void VisualSelector::prev()
281 char *psz_new = aout_VisualPrev( p_intf );
284 current->setText( qfu( psz_new ) );
289 void VisualSelector::next()
291 char *psz_new = aout_VisualNext( p_intf );
294 current->setText( qfu( psz_new ) );
300 /**********************************************************************
302 **********************************************************************/
304 static void setupSmallButton( QPushButton *aButton )
306 aButton->setMaximumSize( QSize( 26, 26 ) );
307 aButton->setMinimumSize( QSize( 26, 26 ) );
308 aButton->setIconSize( QSize( 20, 20 ) );
309 aButton->setFocusPolicy( Qt::NoFocus );
312 /* init static variables in advanced controls */
313 mtime_t AdvControlsWidget::timeA = 0;
314 mtime_t AdvControlsWidget::timeB = 0;
316 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i, bool b_fsCreation = false ) :
317 QFrame( NULL ), p_intf( _p_i )
319 QHBoxLayout *advLayout = new QHBoxLayout( this );
320 advLayout->setMargin( 0 );
321 advLayout->setSpacing( 0 );
322 advLayout->setAlignment( Qt::AlignBottom );
325 ABButton = new QPushButton;
326 setupSmallButton( ABButton );
327 advLayout->addWidget( ABButton );
328 BUTTON_SET_ACT_I( ABButton, "", atob_nob,
329 qtr( "Loop from point A to point B continuously.\nClick to set point A" ),
333 /* in FS controller we skip this, because we dont want to have it double
336 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
337 this, AtoBLoop( float, int, int ) );
338 /* set up synchronization between main controller and fs controller */
339 CONNECT( THEMIM->getIM(), advControlsSetIcon(), this, setIcon() );
340 connect( this, SIGNAL( timeChanged() ),
341 THEMIM->getIM(), SIGNAL( advControlsSetIcon()));
343 frameButton = new QPushButton( "Fr" );
344 frameButton->setMaximumSize( QSize( 26, 26 ) );
345 frameButton->setIconSize( QSize( 20, 20 ) );
346 advLayout->addWidget( frameButton );
347 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by frame" ), frame() );
351 recordButton = new QPushButton;
352 setupSmallButton( recordButton );
353 advLayout->addWidget( recordButton );
354 BUTTON_SET_ACT_I( recordButton, "", record,
355 qtr( "Record" ), record() );
357 /* Snapshot Button */
358 snapshotButton = new QPushButton;
359 setupSmallButton( snapshotButton );
360 advLayout->addWidget( snapshotButton );
361 BUTTON_SET_ACT_I( snapshotButton, "", snapshot,
362 qtr( "Take a snapshot" ), snapshot() );
365 AdvControlsWidget::~AdvControlsWidget()
368 void AdvControlsWidget::enableInput( bool enable )
371 if( THEMIM->getInput() != NULL )
373 input_item_t *p_item = input_GetItem( THEMIM->getInput() );
374 i_input_id = p_item->i_id;
376 recordButton->setVisible( var_GetBool( THEMIM->getInput(), "can-record" ) );
380 recordButton->setVisible( false );
383 ABButton->setEnabled( enable );
384 recordButton->setEnabled( enable );
386 if( enable && ( i_last_input_id != i_input_id ) )
389 i_last_input_id = i_input_id;
394 void AdvControlsWidget::enableVideo( bool enable )
396 snapshotButton->setEnabled( enable );
398 frameButton->setEnabled( enable );
402 void AdvControlsWidget::snapshot()
404 vout_thread_t *p_vout =
405 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
408 vout_Control( p_vout, VOUT_SNAPSHOT );
409 vlc_object_release( p_vout );
413 /* Function called when the button is clicked() */
414 void AdvControlsWidget::fromAtoB()
418 timeA = var_GetTime( THEMIM->getInput(), "time" );
424 timeB = var_GetTime( THEMIM->getInput(), "time" );
425 var_SetTime( THEMIM->getInput(), "time" , timeA );
434 /* setting/synchro icons after click on main or fs controller */
435 void AdvControlsWidget::setIcon()
437 if( !timeA && !timeB)
439 ABButton->setIcon( QIcon( ":/atob_nob" ) );
440 ABButton->setToolTip( qtr( "Loop from point A to point B continuously\nClick to set point A" ) );
442 else if( timeA && !timeB )
444 ABButton->setIcon( QIcon( ":/atob_noa" ) );
445 ABButton->setToolTip( qtr( "Click to set point B" ) );
447 else if( timeA && timeB )
449 ABButton->setIcon( QIcon( ":/atob" ) );
450 ABButton->setToolTip( qtr( "Stop the A to B loop" ) );
454 /* Function called regularly when in an AtoB loop */
455 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
459 if( ( i_time >= (int)( timeB/1000000 ) )
460 || ( i_time < (int)( timeA/1000000 ) ) )
461 var_SetTime( THEMIM->getInput(), "time" , timeA );
465 void AdvControlsWidget::record()
467 input_thread_t *p_input = THEMIM->getInput();
470 /* This method won't work fine if the stream can't be cut anywhere */
471 const bool b_recording = var_GetBool( p_input, "record" );
472 var_SetBool( p_input, "record", !b_recording );
476 /* 'record' access-filter is not loaded, we open Save dialog */
477 input_item_t *p_item = input_GetItem( p_input );
481 char *psz = input_item_GetURI( p_item );
483 THEDP->streamingDialog( NULL, psz, true );
490 //FIXME Frame by frame function
491 void AdvControlsWidget::frame(){}
494 /*****************************
495 * DA Control Widget !
496 *****************************/
497 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
498 MainInterface *_p_mi,
502 QFrame( _p_mi ), p_intf( _p_i )
504 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
506 /** The main Slider **/
507 slider = new InputSlider( Qt::Horizontal, NULL );
508 /* Update the position when the IM has changed */
509 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
510 slider, setPosition( float, int, int ) );
511 /* And update the IM, when the position has changed */
512 CONNECT( slider, sliderDragged( float ),
513 THEMIM->getIM(), sliderUpdate( float ) );
515 /** Slower and faster Buttons **/
516 slowerButton = new QToolButton;
517 slowerButton->setAutoRaise( true );
518 slowerButton->setMaximumSize( QSize( 26, 20 ) );
519 slowerButton->setFocusPolicy( Qt::NoFocus );
521 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
523 fasterButton = new QToolButton;
524 fasterButton->setAutoRaise( true );
525 fasterButton->setMaximumSize( QSize( 26, 20 ) );
526 fasterButton->setFocusPolicy( Qt::NoFocus );
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( 32, 32 ) );
635 playButton->setMinimumSize( QSize( 32, 32 ) );
636 playButton->setIconSize( QSize( 26, 26 ) );
637 playButton->setFocusPolicy( Qt::NoFocus );
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( 300 );
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 msg_Dbg( p_intf, "showFSC() was called" );
1084 // after quiting and going to fs, we need to call show()
1090 b_fscHidden = false;
1091 setWindowOpacity( 1.0 );
1097 #if HAVE_TRANSPARENCY
1098 setWindowOpacity( DEFAULT_OPACITY );
1103 * Hide fullscreen controller
1104 * FIXME: under windows it have to be done by moving out of screen
1105 * because hide() doesnt work
1107 void FullscreenControllerWidget::hideFSC()
1110 msg_Dbg( p_intf, "hideFSC() was called" );
1112 setWindowOpacity( 0.0 ); // simulate hidding
1119 * Plane to hide fullscreen controller
1121 void FullscreenControllerWidget::planHideFSC()
1123 vlc_mutex_lock( &lock );
1124 int i_timeout = i_hide_timeout;
1125 vlc_mutex_unlock( &lock );
1127 p_hideTimer->start( i_timeout );
1129 #if HAVE_TRANSPARENCY
1130 b_slow_hide_begin = true;
1131 i_slow_hide_timeout = i_timeout;
1132 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
1137 * Hidding fullscreen controller slowly
1138 * Linux: need composite manager
1139 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
1141 void FullscreenControllerWidget::slowHideFSC()
1143 #if HAVE_TRANSPARENCY
1144 if( b_slow_hide_begin )
1146 b_slow_hide_begin = false;
1148 p_slowHideTimer->stop();
1149 /* the last part of time divided to 100 pieces */
1150 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
1156 msg_Dbg( p_intf, "slowHideFSC() was called" );
1157 if ( windowOpacity() > 0.0 && !b_fscHidden )
1159 if ( windowOpacity() > 0.0 )
1162 /* we should use 0.01 because of 100 pieces ^^^
1163 but than it cannt be done in time */
1164 setWindowOpacity( windowOpacity() - 0.02 );
1167 if ( windowOpacity() <= 0.0 )
1168 p_slowHideTimer->stop();
1175 * events: show, hide, start timer for hidding
1177 void FullscreenControllerWidget::customEvent( QEvent *event )
1182 msg_Dbg( p_intf, "New FSC event: %i", event->type() );
1185 switch( event->type() )
1187 case FullscreenControlToggle_Type:
1188 vlc_mutex_lock( &lock );
1189 b_fs = b_fullscreen;
1190 vlc_mutex_unlock( &lock );
1198 p_hideTimer->stop();
1204 case FullscreenControlShow_Type:
1205 vlc_mutex_lock( &lock );
1206 b_fs = b_fullscreen;
1207 vlc_mutex_unlock( &lock );
1209 if( b_fs ) // FIXME I am not sure about that one
1212 case FullscreenControlHide_Type:
1215 case FullscreenControlPlanHide_Type:
1216 if( !b_mouse_over ) // Only if the mouse is not over FSC
1226 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1228 if ( event->buttons() == Qt::LeftButton )
1230 int i_moveX = event->globalX() - i_mouse_last_x;
1231 int i_moveY = event->globalY() - i_mouse_last_y;
1233 move( x() + i_moveX, y() + i_moveY );
1235 i_mouse_last_x = event->globalX();
1236 i_mouse_last_y = event->globalY();
1242 * store position of cursor
1244 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1246 i_mouse_last_x = event->globalX();
1247 i_mouse_last_y = event->globalY();
1251 * On mouse go above FSC
1253 void FullscreenControllerWidget::enterEvent( QEvent *event )
1255 b_mouse_over = true;
1257 p_hideTimer->stop();
1258 #if HAVE_TRANSPARENCY
1259 p_slowHideTimer->stop();
1264 * On mouse go out from FSC
1266 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1270 b_mouse_over = false;
1274 * When you get pressed key, send it to video output
1275 * FIXME: clearing focus by clearFocus() to not getting
1276 * key press events didnt work
1278 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1280 int i_vlck = qtEventToVLCKey( event );
1283 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1291 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object, const char *variable,
1292 vlc_value_t old_val, vlc_value_t new_val,
1295 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1296 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1298 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1303 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1304 vlc_value_t old_val, vlc_value_t new_val,
1307 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1310 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1311 QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1313 /* Plan hide event */
1314 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1315 QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1322 * It is called when video start
1324 void FullscreenControllerWidget::attachVout( vout_thread_t *p_nvout )
1326 assert( p_nvout && !p_vout );
1330 vlc_mutex_lock( &lock );
1331 var_AddCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this ); /* I miss a add and fire */
1332 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ), var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1333 vlc_mutex_unlock( &lock );
1336 * It is called after turn off video.
1338 void FullscreenControllerWidget::detachVout()
1342 var_DelCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this );
1343 vlc_mutex_lock( &lock );
1344 fullscreenChanged( p_vout, false, 0 );
1345 vlc_mutex_unlock( &lock );
1351 * Register and unregister callback for mouse moving
1353 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout, bool b_fs, int i_timeout )
1355 vlc_mutex_lock( &lock );
1356 if( b_fs && !b_fullscreen )
1358 b_fullscreen = true;
1359 i_hide_timeout = i_timeout;
1360 var_AddCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1362 else if( !b_fs && b_fullscreen )
1364 b_fullscreen = false;
1365 i_hide_timeout = i_timeout;
1366 var_DelCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1368 /* Force fs hidding */
1369 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1370 QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1372 vlc_mutex_unlock( &lock );
1375 /**********************************************************************
1376 * Speed control widget
1377 **********************************************************************/
1378 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1379 QFrame( NULL ), p_intf( _p_i )
1381 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1382 sizePolicy.setHorizontalStretch( 0 );
1383 sizePolicy.setVerticalStretch( 0 );
1385 speedSlider = new QSlider;
1386 speedSlider->setSizePolicy( sizePolicy );
1387 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1388 speedSlider->setOrientation( Qt::Vertical );
1389 speedSlider->setTickPosition( QSlider::TicksRight );
1391 speedSlider->setRange( -24, 24 );
1392 speedSlider->setSingleStep( 1 );
1393 speedSlider->setPageStep( 1 );
1394 speedSlider->setTickInterval( 12 );
1396 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1398 QToolButton *normalSpeedButton = new QToolButton( this );
1399 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1400 normalSpeedButton->setAutoRaise( true );
1401 normalSpeedButton->setText( "1x" );
1402 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1404 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1406 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1407 speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
1408 speedControlLayout->setSpacing( 4 );
1409 speedControlLayout->addWidget( speedSlider );
1410 speedControlLayout->addWidget( normalSpeedButton );
1411 setLayout( speedControlLayout );
1414 SpeedControlWidget::~SpeedControlWidget()
1417 void SpeedControlWidget::setEnable( bool b_enable )
1419 speedSlider->setEnabled( b_enable );
1422 void SpeedControlWidget::updateControls( int rate )
1424 if( speedSlider->isSliderDown() )
1426 //We don't want to change anything if the user is using the slider
1430 double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
1431 int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
1433 if( sliderValue < speedSlider->minimum() )
1435 sliderValue = speedSlider->minimum();
1437 else if( sliderValue > speedSlider->maximum() )
1439 sliderValue = speedSlider->maximum();
1442 //Block signals to avoid feedback loop
1443 speedSlider->blockSignals( true );
1444 speedSlider->setValue( sliderValue );
1445 speedSlider->blockSignals( false );
1448 void SpeedControlWidget::updateRate( int sliderValue )
1450 double speed = pow( 2, (double)sliderValue / 12 );
1451 int rate = INPUT_RATE_DEFAULT / speed;
1453 THEMIM->getIM()->setRate(rate);
1456 void SpeedControlWidget::resetRate()
1458 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
1463 static int downloadCoverCallback( vlc_object_t *p_this,
1464 char const *psz_var,
1465 vlc_value_t oldvar, vlc_value_t newvar,
1468 if( !strcmp( psz_var, "item-change" ) )
1470 CoverArtLabel *art = static_cast< CoverArtLabel* >( data );
1472 art->requestUpdate();
1477 CoverArtLabel::CoverArtLabel( QWidget *parent,
1478 vlc_object_t *_p_this,
1479 input_item_t *_p_input )
1480 : QLabel( parent ), p_this( _p_this), p_input( _p_input ), prevArt()
1482 setContextMenuPolicy( Qt::ActionsContextMenu );
1483 CONNECT( this, updateRequested(), this, doUpdate() );
1485 playlist_t *p_playlist = pl_Yield( p_this );
1486 var_AddCallback( p_playlist, "item-change",
1487 downloadCoverCallback, this );
1488 pl_Release( p_this );
1490 setMinimumHeight( 128 );
1491 setMinimumWidth( 128 );
1492 setMaximumHeight( 128 );
1493 setMaximumWidth( 128 );
1494 setScaledContents( true );
1499 void CoverArtLabel::downloadCover()
1503 playlist_t *p_playlist = pl_Yield( p_this );
1504 playlist_AskForArtEnqueue( p_playlist, p_input );
1505 pl_Release( p_this );
1509 void CoverArtLabel::doUpdate()
1513 setPixmap( QPixmap( ":/noart.png" ) );
1514 QList< QAction* > artActions = actions();
1515 if( !artActions.isEmpty() )
1516 foreach( QAction *act, artActions )
1517 removeAction( act );
1522 char *psz_meta = input_item_GetArtURL( p_input );
1523 if( psz_meta && !strncmp( psz_meta, "file://", 7 ) )
1525 QString artUrl = qfu( psz_meta ).replace( "file://", "" );
1526 if( artUrl != prevArt )
1529 if( pix.load( artUrl ) )
1533 msg_Dbg( p_this, "Qt could not load image '%s'",
1535 setPixmap( QPixmap( ":/noart.png" ) );
1538 QList< QAction* > artActions = actions();
1539 if( !artActions.isEmpty() )
1541 foreach( QAction *act, artActions )
1542 removeAction( act );
1549 setPixmap( QPixmap( ":/noart.png" ) );
1551 QList< QAction* > artActions = actions();
1552 if( artActions.isEmpty() )
1554 QAction *action = new QAction( qtr( "Download cover art" ),
1556 addAction( action );
1557 CONNECT( action, triggered(),
1558 this, downloadCover() );