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 hide(); setMinimumSize( 16, 16 );
71 videoSize.rwidth() = -1;
72 videoSize.rheight() = -1;
73 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
75 /* Black background is more coherent for a Video Widget IMVHO */
76 QPalette plt = palette();
77 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
78 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
80 setAttribute( Qt::WA_PaintOnScreen, true );
82 /* The core can ask through a callback to show the video. */
84 connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
85 this, SLOT(SetSizing(unsigned int, unsigned int )),
86 Qt::BlockingQueuedConnection );
88 #error This is broken. Fix it with a QEventLoop with a processEvents ()
89 connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
90 this, SLOT(SetSizing(unsigned int, unsigned int )) );
94 void VideoWidget::paintEvent(QPaintEvent *ev)
96 QFrame::paintEvent(ev);
98 XFlush( QX11Info::display() );
102 VideoWidget::~VideoWidget()
104 vout_thread_t *p_vout = i_vout
105 ? (vout_thread_t *)vlc_object_get( i_vout ) : NULL;
109 if( !p_intf->psz_switch_intf )
111 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
112 vout_Control( p_vout, VOUT_REPARENT );
116 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
117 vout_Control( p_vout, VOUT_CLOSE );
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;
137 msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );
138 return ( void* )winId();
141 /* Set the Widget to the correct Size */
142 /* Function has to be called by the parent
143 Parent has to care about resizing himself*/
144 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
146 msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
147 videoSize.rwidth() = w;
148 videoSize.rheight() = h;
149 if( isHidden() ) show();
150 updateGeometry(); // Needed for deinterlace
153 void VideoWidget::release( void *p_win )
155 msg_Dbg( p_intf, "Video is not needed anymore" );
157 videoSize.rwidth() = 0;
158 videoSize.rheight() = 0;
160 updateGeometry(); // Needed for deinterlace
163 QSize VideoWidget::sizeHint() const
168 /**********************************************************************
169 * Background Widget. Show a simple image background. Currently,
170 * it's album art if present or cone.
171 **********************************************************************/
172 #define ICON_SIZE 128
173 #define MAX_BG_SIZE 400
174 #define MIN_BG_SIZE 64
176 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
177 :QWidget( NULL ), p_intf( _p_i )
179 /* We should use that one to take the more size it can */
180 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding);
182 /* A dark background */
183 setAutoFillBackground( true );
185 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
186 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
189 /* A cone in the middle */
191 label->setMargin( 5 );
192 label->setMaximumHeight( MAX_BG_SIZE );
193 label->setMaximumWidth( MAX_BG_SIZE );
194 label->setMinimumHeight( MIN_BG_SIZE );
195 label->setMinimumWidth( MIN_BG_SIZE );
196 if( QDate::currentDate().dayOfYear() >= 354 )
197 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
199 label->setPixmap( QPixmap( ":/vlc128.png" ) );
201 QGridLayout *backgroundLayout = new QGridLayout( this );
202 backgroundLayout->addWidget( label, 0, 1 );
203 backgroundLayout->setColumnStretch( 0, 1 );
204 backgroundLayout->setColumnStretch( 2, 1 );
206 CONNECT( THEMIM->getIM(), artChanged( QString ), this, updateArt( QString ) );
209 BackgroundWidget::~BackgroundWidget()
212 void BackgroundWidget::resizeEvent( QResizeEvent * event )
214 if( event->size().height() <= MIN_BG_SIZE )
220 void BackgroundWidget::updateArt( QString url )
224 if( QDate::currentDate().dayOfYear() >= 354 )
225 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
227 label->setPixmap( QPixmap( ":/vlc128.png" ) );
232 label->setPixmap( QPixmap( url ) );
236 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
238 QVLCMenu::PopupMenu( p_intf, true );
242 /**********************************************************************
243 * Visualization selector panel
244 **********************************************************************/
245 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
246 QFrame( NULL ), p_intf( _p_i )
248 QHBoxLayout *layout = new QHBoxLayout( this );
249 layout->setMargin( 0 );
250 QPushButton *prevButton = new QPushButton( "Prev" );
251 QPushButton *nextButton = new QPushButton( "Next" );
252 layout->addWidget( prevButton );
253 layout->addWidget( nextButton );
255 layout->addStretch( 10 );
256 layout->addWidget( new QLabel( qtr( "Current visualization" ) ) );
258 current = new QLabel( qtr( "None" ) );
259 layout->addWidget( current );
261 BUTTONACT( prevButton, prev() );
262 BUTTONACT( nextButton, next() );
265 setMaximumHeight( 35 );
268 VisualSelector::~VisualSelector()
271 void VisualSelector::prev()
273 char *psz_new = aout_VisualPrev( p_intf );
276 current->setText( qfu( psz_new ) );
281 void VisualSelector::next()
283 char *psz_new = aout_VisualNext( p_intf );
286 current->setText( qfu( psz_new ) );
292 /**********************************************************************
294 **********************************************************************/
296 #define setupSmallButton( aButton ){ \
297 aButton->setMaximumSize( QSize( 26, 26 ) ); \
298 aButton->setMinimumSize( QSize( 26, 26 ) ); \
299 aButton->setIconSize( QSize( 20, 20 ) ); }
301 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
302 QFrame( NULL ), p_intf( _p_i )
304 QHBoxLayout *advLayout = new QHBoxLayout( this );
305 advLayout->setMargin( 0 );
306 advLayout->setSpacing( 0 );
307 advLayout->setAlignment( Qt::AlignBottom );
310 ABButton = new QPushButton;
311 setupSmallButton( ABButton );
312 advLayout->addWidget( ABButton );
313 BUTTON_SET_ACT_I( ABButton, "", atob_nob,
314 qtr( "Loop from point A to point B continuously.\nClick to set point A" ),
317 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
318 this, AtoBLoop( float, int, int ) );
320 frameButton = new QPushButton( "Fr" );
321 frameButton->setMaximumSize( QSize( 26, 26 ) );
322 frameButton->setIconSize( QSize( 20, 20 ) );
323 advLayout->addWidget( frameButton );
324 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by frame" ), frame() );
327 recordButton = new QPushButton;
328 setupSmallButton( recordButton );
329 advLayout->addWidget( recordButton );
330 BUTTON_SET_ACT_I( recordButton, "", record,
331 qtr( "Record" ), record() );
333 /* Snapshot Button */
334 snapshotButton = new QPushButton;
335 setupSmallButton( snapshotButton );
336 advLayout->addWidget( snapshotButton );
337 BUTTON_SET_ACT_I( snapshotButton, "", snapshot,
338 qtr( "Take a snapshot" ), snapshot() );
341 AdvControlsWidget::~AdvControlsWidget()
344 void AdvControlsWidget::enableInput( bool enable )
346 ABButton->setEnabled( enable );
347 recordButton->setEnabled( enable );
350 void AdvControlsWidget::enableVideo( bool enable )
352 snapshotButton->setEnabled( enable );
354 frameButton->setEnabled( enable );
358 void AdvControlsWidget::snapshot()
360 vout_thread_t *p_vout =
361 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
362 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
365 /* Function called when the button is clicked() */
366 void AdvControlsWidget::fromAtoB()
370 timeA = var_GetTime( THEMIM->getInput(), "time" );
371 ABButton->setToolTip( qtr( "Click to set point B" ) );
372 ABButton->setIcon( QIcon( ":/atob_noa" ) );
377 timeB = var_GetTime( THEMIM->getInput(), "time" );
378 var_SetTime( THEMIM->getInput(), "time" , timeA );
379 ABButton->setIcon( QIcon( ":/atob" ) );
380 ABButton->setToolTip( qtr( "Stop the A to B loop" ) );
385 ABButton->setToolTip( qtr( "Loop from point A to point B continuously\nClick to set point A" ) );
386 ABButton->setIcon( QIcon( ":/atob_nob" ) );
389 /* Function called regularly when in an AtoB loop */
390 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
394 if( i_time >= (int)(timeB/1000000) )
395 var_SetTime( THEMIM->getInput(), "time" , timeA );
399 /* FIXME Record function */
400 void AdvControlsWidget::record(){}
403 //FIXME Frame by frame function
404 void AdvControlsWidget::frame(){}
407 /*****************************
408 * DA Control Widget !
409 *****************************/
410 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
411 MainInterface *_p_mi,
415 QFrame( _p_mi ), p_intf( _p_i )
417 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
419 /** The main Slider **/
420 slider = new InputSlider( Qt::Horizontal, NULL );
421 /* Update the position when the IM has changed */
422 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
423 slider, setPosition( float, int, int ) );
424 /* And update the IM, when the position has changed */
425 CONNECT( slider, sliderDragged( float ),
426 THEMIM->getIM(), sliderUpdate( float ) );
428 /** Slower and faster Buttons **/
429 slowerButton = new QToolButton;
430 slowerButton->setAutoRaise( true );
431 slowerButton->setMaximumSize( QSize( 26, 20 ) );
433 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
435 fasterButton = new QToolButton;
436 fasterButton->setAutoRaise( true );
437 fasterButton->setMaximumSize( QSize( 26, 20 ) );
439 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
441 /* advanced Controls handling */
442 b_advancedVisible = b_advControls;
444 advControls = new AdvControlsWidget( p_intf );
445 if( !b_advancedVisible ) advControls->hide();
447 /** Disc and Menus handling */
448 discFrame = new QWidget( this );
450 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
451 discLayout->setSpacing( 0 );
452 discLayout->setMargin( 0 );
454 prevSectionButton = new QPushButton( discFrame );
455 setupSmallButton( prevSectionButton );
456 discLayout->addWidget( prevSectionButton );
458 menuButton = new QPushButton( discFrame );
459 setupSmallButton( menuButton );
460 discLayout->addWidget( menuButton );
462 nextSectionButton = new QPushButton( discFrame );
463 setupSmallButton( nextSectionButton );
464 discLayout->addWidget( nextSectionButton );
466 BUTTON_SET_IMG( prevSectionButton, "", dvd_prev, "" );
467 BUTTON_SET_IMG( nextSectionButton, "", dvd_next, "" );
468 BUTTON_SET_IMG( menuButton, "", dvd_menu, qtr( "Menu" ) );
472 /* Change the navigation button display when the IM navigation changes */
473 CONNECT( THEMIM->getIM(), navigationChanged( int ),
474 this, setNavigation( int ) );
475 /* Changes the IM navigation when triggered on the nav buttons */
476 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
478 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
480 CONNECT( menuButton, clicked(), THEMIM->getIM(),
485 * TODO: Merge with upper menu in a StackLayout
487 telexFrame = new QWidget( this );
488 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
489 telexLayout->setSpacing( 0 );
490 telexLayout->setMargin( 0 );
492 telexOn = new QPushButton;
493 setupSmallButton( telexOn );
494 telexLayout->addWidget( telexOn );
496 telexTransparent = new QPushButton;
497 setupSmallButton( telexTransparent );
498 telexLayout->addWidget( telexTransparent );
499 b_telexTransparent = false;
501 telexPage = new QSpinBox;
502 telexPage->setRange( 0, 999 );
503 telexPage->setValue( 100 );
504 telexPage->setAccelerated( true );
505 telexPage->setWrapping( true );
506 telexPage->setAlignment( Qt::AlignRight );
507 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
508 telexLayout->addWidget( telexPage );
510 telexFrame->hide(); /* default hidden */
512 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
513 telexGotoPage( int ) );
514 CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
515 telexPage, setValue( int ) );
517 BUTTON_SET_IMG( telexOn, "", tv, qtr( "Teletext on" ) );
519 CONNECT( telexOn, clicked(), THEMIM->getIM(),
520 telexToggleButtons() );
521 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
522 telexToggle( bool ) );
523 CONNECT( THEMIM->getIM(), toggleTelexButtons(),
524 this, toggleTeletext() );
525 b_telexEnabled = false;
526 telexTransparent->setEnabled( false );
527 telexPage->setEnabled( false );
529 BUTTON_SET_IMG( telexTransparent, "", tvtelx, qtr( "Teletext" ) );
530 CONNECT( telexTransparent, clicked( bool ),
531 THEMIM->getIM(), telexSetTransparency() );
532 CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
533 this, toggleTeletextTransparency() );
534 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
535 this, enableTeletext( bool ) );
538 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
539 sizePolicy.setHorizontalStretch( 0 );
540 sizePolicy.setVerticalStretch( 0 );
543 playButton = new QPushButton;
544 playButton->setSizePolicy( sizePolicy );
545 playButton->setMaximumSize( QSize( 36, 36 ) );
546 playButton->setMinimumSize( QSize( 36, 36 ) );
547 playButton->setIconSize( QSize( 30, 30 ) );
550 /** Prev + Stop + Next Block **/
551 controlButLayout = new QHBoxLayout;
552 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
555 QPushButton *prevButton = new QPushButton;
556 prevButton->setSizePolicy( sizePolicy );
557 setupSmallButton( prevButton );
559 controlButLayout->addWidget( prevButton );
562 QPushButton *stopButton = new QPushButton;
563 stopButton->setSizePolicy( sizePolicy );
564 setupSmallButton( stopButton );
566 controlButLayout->addWidget( stopButton );
569 QPushButton *nextButton = new QPushButton;
570 nextButton->setSizePolicy( sizePolicy );
571 setupSmallButton( nextButton );
573 controlButLayout->addWidget( nextButton );
575 /* Add this block to the main layout */
577 BUTTON_SET_ACT_I( playButton, "", play_b, qtr( I_PLAY_TOOLTIP ), play() );
578 BUTTON_SET_ACT_I( prevButton, "" , previous_b,
579 qtr( "Previous media in the playlist" ), prev() );
580 BUTTON_SET_ACT_I( nextButton, "", next_b,
581 qtr( "Next media in the playlist" ), next() );
582 BUTTON_SET_ACT_I( stopButton, "", stop_b, qtr( "Stop playback" ), stop() );
585 * Other first Line buttons
587 /** Fullscreen/Visualisation **/
588 fullscreenButton = new QPushButton;
589 BUTTON_SET_ACT_I( fullscreenButton, "", fullscreen,
590 qtr( "Toggle the video in fullscreen" ), fullscreen() );
591 setupSmallButton( fullscreenButton );
595 /** Playlist Button **/
596 playlistButton = new QPushButton;
597 setupSmallButton( playlistButton );
598 BUTTON_SET_IMG( playlistButton, "" , playlist, qtr( "Show playlist" ) );
599 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
601 /** extended Settings **/
602 extSettingsButton = new QPushButton;
603 BUTTON_SET_ACT_I( extSettingsButton, "", extended,
604 qtr( "Show extended settings" ), extSettings() );
605 setupSmallButton( extSettingsButton );
609 hVolLabel = new VolumeClickHandler( p_intf, this );
611 volMuteLabel = new QLabel;
612 volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
613 volMuteLabel->installEventFilter( hVolLabel );
617 volumeSlider = new SoundSlider( this,
618 config_GetInt( p_intf, "volume-step" ),
619 config_GetInt( p_intf, "qt-volume-complete" ),
620 config_GetPsz( p_intf, "qt-slider-colours" ) );
624 volumeSlider = new QSlider( this );
625 volumeSlider->setOrientation( Qt::Horizontal );
627 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
628 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
629 volumeSlider->setFocusPolicy( Qt::NoFocus );
631 /* Set the volume from the config */
632 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
633 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
635 /* Force the update at build time in order to have a muted icon if needed */
636 updateVolume( volumeSlider->value() );
638 /* Volume control connection */
639 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
640 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
644 controlLayout = new QGridLayout( this );
646 controlLayout->setSpacing( 0 );
647 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
649 controlLayout->addWidget( slider, 0, 1, 1, 16 );
650 controlLayout->addWidget( slowerButton, 0, 0 );
651 controlLayout->addWidget( fasterButton, 0, 17 );
653 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
654 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
655 controlLayout->addWidget( telexFrame, 1, 10, 2, 4, Qt::AlignBottom );
657 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
658 controlLayout->setColumnMinimumWidth( 2, 20 );
659 controlLayout->setColumnStretch( 2, 0 );
661 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
662 controlLayout->setColumnMinimumWidth( 7, 20 );
663 controlLayout->setColumnStretch( 7, 0 );
664 controlLayout->setColumnStretch( 8, 0 );
665 controlLayout->setColumnStretch( 9, 0 );
667 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
668 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
669 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
671 controlLayout->setColumnStretch( 13, 0 );
672 controlLayout->setColumnMinimumWidth( 13, 24 );
673 controlLayout->setColumnStretch( 14, 5 );
675 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
676 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
682 ControlsWidget::~ControlsWidget()
685 void ControlsWidget::toggleTeletext()
687 bool b_enabled = THEMIM->teletextState();
690 telexTransparent->setEnabled( false );
691 telexPage->setEnabled( false );
692 b_telexEnabled = false;
696 telexTransparent->setEnabled( true );
697 telexPage->setEnabled( true );
698 b_telexEnabled = true;
702 void ControlsWidget::enableTeletext( bool b_enable )
704 telexFrame->setVisible( b_enable );
705 bool b_on = THEMIM->teletextState();
707 telexOn->setChecked( b_on );
708 telexTransparent->setEnabled( b_on );
709 telexPage->setEnabled( b_on );
710 b_telexEnabled = b_on;
713 void ControlsWidget::toggleTeletextTransparency()
715 if( b_telexTransparent )
717 telexTransparent->setIcon( QIcon( ":/tvtelx" ) );
718 telexTransparent->setToolTip( qtr( "Teletext" ) );
719 b_telexTransparent = false;
723 telexTransparent->setIcon( QIcon( ":/tvtelx-transparent" ) );
724 telexTransparent->setToolTip( qtr( "Transparent" ) );
725 b_telexTransparent = true;
729 void ControlsWidget::stop()
734 void ControlsWidget::play()
736 if( THEPL->current.i_size == 0 )
738 /* The playlist is empty, open a file requester */
739 THEDP->openFileDialog();
743 THEMIM->togglePlayPause();
746 void ControlsWidget::prev()
751 void ControlsWidget::next()
756 void ControlsWidget::setNavigation( int navigation )
758 #define HELP_PCH N_( "Previous chapter" )
759 #define HELP_NCH N_( "Next chapter" )
761 // 1 = chapter, 2 = title, 0 = no
762 if( navigation == 0 )
765 } else if( navigation == 1 ) {
766 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
767 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
771 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
772 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
778 static bool b_my_volume;
779 void ControlsWidget::updateVolume( int i_sliderVolume )
783 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
784 aout_VolumeSet( p_intf, i_res );
786 if( i_sliderVolume == 0 )
788 volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
789 volMuteLabel->setToolTip( qtr( "Unmute" ) );
793 if( i_sliderVolume < VOLUME_MAX / 3 )
794 volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
795 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
796 volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
797 else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
798 volMuteLabel->setToolTip( qtr( "Mute" ) );
801 void ControlsWidget::updateVolume()
804 audio_volume_t i_volume;
805 aout_VolumeGet( p_intf, &i_volume );
806 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
807 int i_gauge = volumeSlider->value();
809 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
812 volumeSlider->setValue( i_volume );
817 void ControlsWidget::updateInput()
819 /* Activate the interface buttons according to the presence of the input */
820 enableInput( THEMIM->getIM()->hasInput() );
821 enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
824 void ControlsWidget::setStatus( int status )
826 if( status == PLAYING_S ) /* Playing */
828 playButton->setIcon( QIcon( ":/pause_b" ) );
829 playButton->setToolTip( qtr( "Pause the playback" ) );
833 playButton->setIcon( QIcon( ":/play_b" ) );
834 playButton->setToolTip( qtr( I_PLAY_TOOLTIP ) );
840 * This functions toggle the fullscreen mode
841 * If there is no video, it should first activate Visualisations...
842 * This has also to be fixed in enableVideo()
844 void ControlsWidget::fullscreen()
846 vout_thread_t *p_vout =
847 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
850 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
851 vlc_object_release( p_vout );
855 void ControlsWidget::extSettings()
857 THEDP->extendedDialog();
860 void ControlsWidget::slower()
862 THEMIM->getIM()->slower();
865 void ControlsWidget::faster()
867 THEMIM->getIM()->faster();
870 void ControlsWidget::enableInput( bool enable )
872 slowerButton->setEnabled( enable );
873 slider->setEnabled( enable );
874 slider->setSliderPosition ( 0 );
875 fasterButton->setEnabled( enable );
877 /* Advanced Buttons too */
878 advControls->enableInput( enable );
881 void ControlsWidget::enableVideo( bool enable )
883 // TODO Later make the fullscreenButton toggle Visualisation and so on.
884 fullscreenButton->setEnabled( enable );
886 /* Advanced Buttons too */
887 advControls->enableVideo( enable );
890 void ControlsWidget::toggleAdvanced()
892 if( !VISIBLE( advControls ) )
895 b_advancedVisible = true;
900 b_advancedVisible = false;
902 emit advancedControlsToggled( b_advancedVisible );
906 /**********************************************************************
907 * Fullscrenn control widget
908 **********************************************************************/
909 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
910 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
911 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
912 i_mouse_last_x( -1 ), i_mouse_last_y( -1 ), b_mouse_over(false),
913 b_slow_hide_begin(false), i_slow_hide_timeout(1),
914 b_fullscreen( false ), i_hide_timeout( 1 )
916 setWindowFlags( Qt::ToolTip );
918 setFrameShape( QFrame::StyledPanel );
919 setFrameStyle( QFrame::Sunken );
920 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
922 QGridLayout *fsLayout = new QGridLayout( this );
923 fsLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
926 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
927 fsLayout->addWidget( slowerButton, 0, 0 );
928 fsLayout->addWidget( slider, 0, 1, 1, 8 );
929 fsLayout->addWidget( fasterButton, 0, 9 );
931 fsLayout->addWidget( playButton, 1, 0, 1, 2 );
932 fsLayout->addLayout( controlButLayout, 1, 2 );
934 fsLayout->addWidget( discFrame, 1, 3 );
935 fsLayout->addWidget( telexFrame, 1, 4 );
936 fsLayout->addWidget( advControls, 1, 5, Qt::AlignVCenter );
937 fsLayout->addWidget( fullscreenButton, 1, 6 );
939 fsLayout->addWidget( volMuteLabel, 1, 7 );
940 fsLayout->addWidget( volumeSlider, 1, 8, 1, 2 );
943 p_hideTimer = new QTimer( this );
944 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
945 p_hideTimer->setSingleShot( true );
947 /* slow hiding timer */
948 #if HAVE_TRANSPARENCY
949 p_slowHideTimer = new QTimer( this );
950 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
953 adjustSize (); /* need to get real width and height for moving */
956 QDesktopWidget * p_desktop = QApplication::desktop();
958 move( p_desktop->width() / 2 - width() / 2,
959 p_desktop->height() - height() );
962 setWindowOpacity( 0.0 );
967 vlc_mutex_init_recursive( &lock );
970 FullscreenControllerWidget::~FullscreenControllerWidget()
972 vlc_mutex_destroy( &lock );
976 * Show fullscreen controller
978 void FullscreenControllerWidget::showFSC()
981 // after quiting and going to fs, we need to call show()
988 setWindowOpacity( 1.0 );
994 #if HAVE_TRANSPARENCY
995 setWindowOpacity( DEFAULT_OPACITY );
1000 * Hide fullscreen controller
1001 * FIXME: under windows it have to be done by moving out of screen
1002 * because hide() doesnt work
1004 void FullscreenControllerWidget::hideFSC()
1008 setWindowOpacity( 0.0 ); // simulate hidding
1015 * Plane to hide fullscreen controller
1017 void FullscreenControllerWidget::planHideFSC()
1019 vlc_mutex_lock( &lock );
1020 int i_timeout = i_hide_timeout;
1021 vlc_mutex_unlock( &lock );
1023 p_hideTimer->start( i_timeout );
1025 #if HAVE_TRANSPARENCY
1026 b_slow_hide_begin = true;
1027 i_slow_hide_timeout = i_timeout;
1028 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
1033 * Hidding fullscreen controller slowly
1034 * Linux: need composite manager
1035 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
1037 void FullscreenControllerWidget::slowHideFSC()
1039 #if HAVE_TRANSPARENCY
1040 if( b_slow_hide_begin )
1042 b_slow_hide_begin = false;
1044 p_slowHideTimer->stop();
1045 /* the last part of time divided to 100 pieces */
1046 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
1052 if ( windowOpacity() > 0.0 && !fscHidden )
1054 if ( windowOpacity() > 0.0 )
1057 /* we should use 0.01 because of 100 pieces ^^^
1058 but than it cannt be done in time */
1059 setWindowOpacity( windowOpacity() - 0.02 );
1062 if ( windowOpacity() <= 0.0 )
1063 p_slowHideTimer->stop();
1070 * events: show, hide, start timer for hidding
1072 void FullscreenControllerWidget::customEvent( QEvent *event )
1076 switch( event->type() )
1078 case FullscreenControlShow_Type:
1079 vlc_mutex_lock( &lock );
1080 b_fs = b_fullscreen;
1081 vlc_mutex_unlock( &lock );
1083 if( b_fs ) // FIXME I am not sure about that one
1086 case FullscreenControlHide_Type:
1089 case FullscreenControlPlanHide_Type:
1090 if( !b_mouse_over ) // Only if the mouse is not over FSC
1100 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1102 if ( event->buttons() == Qt::LeftButton )
1104 int i_moveX = event->globalX() - i_mouse_last_x;
1105 int i_moveY = event->globalY() - i_mouse_last_y;
1107 move( x() + i_moveX, y() + i_moveY );
1109 i_mouse_last_x = event->globalX();
1110 i_mouse_last_y = event->globalY();
1116 * store position of cursor
1118 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1120 i_mouse_last_x = event->globalX();
1121 i_mouse_last_y = event->globalY();
1125 * On mouse go above FSC
1127 void FullscreenControllerWidget::enterEvent( QEvent *event )
1129 b_mouse_over = true;
1131 p_hideTimer->stop();
1132 #if HAVE_TRANSPARENCY
1133 p_slowHideTimer->stop();
1138 * On mouse go out from FSC
1140 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1144 b_mouse_over = false;
1148 * When you get pressed key, send it to video output
1149 * FIXME: clearing focus by clearFocus() to not getting
1150 * key press events didnt work
1152 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1154 int i_vlck = qtEventToVLCKey( event );
1157 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1165 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object, const char *variable,
1166 vlc_value_t old_val, vlc_value_t new_val,
1169 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1170 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1172 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1177 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1178 vlc_value_t old_val, vlc_value_t new_val,
1181 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1184 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1185 QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1187 /* Plan hide event */
1188 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1189 QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1196 * It is called when video start
1198 void FullscreenControllerWidget::attachVout( vout_thread_t *p_vout )
1202 vlc_mutex_lock( &lock );
1203 var_AddCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this ); /* I miss a add and fire */
1204 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ), var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1205 vlc_mutex_unlock( &lock );
1208 * It is called after turn off video.
1210 void FullscreenControllerWidget::detachVout( vout_thread_t *p_vout )
1214 var_DelCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this );
1215 vlc_mutex_lock( &lock );
1216 fullscreenChanged( p_vout, false, 0 );
1217 vlc_mutex_unlock( &lock );
1221 * Register and unregister callback for mouse moving
1223 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout, bool b_fs, int i_timeout )
1225 vlc_mutex_lock( &lock );
1226 if( b_fs && !b_fullscreen )
1228 b_fullscreen = true;
1229 i_hide_timeout = i_timeout;
1230 var_AddCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1232 else if( !b_fs && b_fullscreen )
1234 b_fullscreen = false;
1235 i_hide_timeout = i_timeout;
1236 var_DelCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1238 /* Force fs hidding */
1239 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1240 QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1242 vlc_mutex_unlock( &lock );
1245 /**********************************************************************
1246 * Speed control widget
1247 **********************************************************************/
1248 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1249 QFrame( NULL ), p_intf( _p_i )
1251 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1252 sizePolicy.setHorizontalStretch( 0 );
1253 sizePolicy.setVerticalStretch( 0 );
1255 speedSlider = new QSlider;
1256 speedSlider->setSizePolicy( sizePolicy );
1257 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1258 speedSlider->setOrientation( Qt::Vertical );
1259 speedSlider->setTickPosition( QSlider::TicksRight );
1261 speedSlider->setRange( -24, 24 );
1262 speedSlider->setSingleStep( 1 );
1263 speedSlider->setPageStep( 1 );
1264 speedSlider->setTickInterval( 12 );
1266 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1268 QToolButton *normalSpeedButton = new QToolButton( this );
1269 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1270 normalSpeedButton->setAutoRaise( true );
1271 normalSpeedButton->setText( "1x" );
1272 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1274 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1276 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1277 speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
1278 speedControlLayout->setSpacing( 4 );
1279 speedControlLayout->addWidget( speedSlider );
1280 speedControlLayout->addWidget( normalSpeedButton );
1281 setLayout( speedControlLayout );
1284 SpeedControlWidget::~SpeedControlWidget()
1287 void SpeedControlWidget::setEnable( bool b_enable )
1289 speedSlider->setEnabled( b_enable );
1292 void SpeedControlWidget::updateControls( int rate )
1294 if( speedSlider->isSliderDown() )
1296 //We don't want to change anything if the user is using the slider
1300 double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
1301 int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
1303 if( sliderValue < speedSlider->minimum() )
1305 sliderValue = speedSlider->minimum();
1307 else if( sliderValue > speedSlider->maximum() )
1309 sliderValue = speedSlider->maximum();
1312 //Block signals to avoid feedback loop
1313 speedSlider->blockSignals( true );
1314 speedSlider->setValue( sliderValue );
1315 speedSlider->blockSignals( false );
1318 void SpeedControlWidget::updateRate( int sliderValue )
1320 double speed = pow( 2, (double)sliderValue / 12 );
1321 int rate = INPUT_RATE_DEFAULT / speed;
1323 THEMIM->getIM()->setRate(rate);
1326 void SpeedControlWidget::resetRate()
1328 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);