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 *****************************************************************************/
31 #include "dialogs_provider.hpp"
32 #include "components/interface_widgets.hpp"
33 #include "main_interface.hpp"
34 #include "input_manager.hpp"
36 #include "util/input_slider.hpp"
37 #include "util/customwidgets.hpp"
41 #include <QSpacerItem>
43 #include <QPushButton>
44 #include <QToolButton>
45 #include <QHBoxLayout>
48 #include <QResizeEvent>
51 # include <X11/Xlib.h>
52 # include <qx11info_x11.h>
55 /**********************************************************************
56 * Video Widget. A simple frame on which video is drawn
57 * This class handles resize issues
58 **********************************************************************/
60 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
64 hide(); setMinimumSize( 16, 16 );
65 videoSize.rwidth() = -1;
66 videoSize.rheight() = -1;
67 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
69 /* Black background is more coherent for a Video Widget IMVHO */
70 QPalette plt = palette();
71 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
72 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
74 setAttribute( Qt::WA_PaintOnScreen, true );
76 /* The core can ask through a callback to show the video. */
78 connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
79 this, SLOT(SetSizing(unsigned int, unsigned int )),
80 Qt::BlockingQueuedConnection );
82 #error This is broken. Fix it with a QEventLoop with a processEvents ()
83 connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
84 this, SLOT(SetSizing(unsigned int, unsigned int )) );
90 void VideoWidget::paintEvent(QPaintEvent *ev)
92 QFrame::paintEvent(ev);
94 XFlush( QX11Info::display() );
98 VideoWidget::~VideoWidget()
102 if( !p_intf->psz_switch_intf )
104 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
105 vout_Control( p_vout, VOUT_REPARENT );
109 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
110 vout_Control( p_vout, VOUT_CLOSE );
116 * Request the video to avoid the conflicts
118 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
119 unsigned int *pi_width, unsigned int *pi_height )
121 msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
122 emit askVideoWidgetToShow( *pi_width, *pi_height );
125 msg_Dbg( p_intf, "embedded video already in use" );
129 msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );
130 return ( void* )winId();
133 /* Set the Widget to the correct Size */
134 /* Function has to be called by the parent
135 Parent has to care about resizing himself*/
136 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
138 msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
139 videoSize.rwidth() = w;
140 videoSize.rheight() = h;
141 if( isHidden() ) show();
142 updateGeometry(); // Needed for deinterlace
145 void VideoWidget::release( void *p_win )
147 msg_Dbg( p_intf, "Video is non needed anymore" );
149 videoSize.rwidth() = 0;
150 videoSize.rheight() = 0;
152 updateGeometry(); // Needed for deinterlace
155 QSize VideoWidget::sizeHint() const
160 /**********************************************************************
161 * Background Widget. Show a simple image background. Currently,
162 * it's album art if present or cone.
163 **********************************************************************/
164 #define ICON_SIZE 128
165 #define MAX_BG_SIZE 400
166 #define MIN_BG_SIZE 64
168 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
169 :QWidget( NULL ), p_intf( _p_i )
171 /* We should use that one to take the more size it can */
172 // setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
174 /* A dark background */
175 setAutoFillBackground( true );
177 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
178 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
181 /* A cone in the middle */
183 label->setMargin( 5 );
184 label->setMaximumHeight( MAX_BG_SIZE );
185 label->setMaximumWidth( MAX_BG_SIZE );
186 label->setMinimumHeight( MIN_BG_SIZE );
187 label->setMinimumWidth( MIN_BG_SIZE );
188 if( QDate::currentDate().dayOfYear() >= 354 )
189 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
191 label->setPixmap( QPixmap( ":/vlc128.png" ) );
193 QGridLayout *backgroundLayout = new QGridLayout( this );
194 backgroundLayout->addWidget( label, 0, 1 );
195 backgroundLayout->setColumnStretch( 0, 1 );
196 backgroundLayout->setColumnStretch( 2, 1 );
198 CONNECT( THEMIM->getIM(), artChanged( QString ), this, updateArt( QString ) );
201 BackgroundWidget::~BackgroundWidget()
205 void BackgroundWidget::resizeEvent( QResizeEvent * event )
207 if( event->size().height() <= MIN_BG_SIZE )
213 void BackgroundWidget::updateArt( QString url )
217 if( QDate::currentDate().dayOfYear() >= 354 )
218 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
220 label->setPixmap( QPixmap( ":/vlc128.png" ) );
225 label->setPixmap( QPixmap( url ) );
229 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
231 QVLCMenu::PopupMenu( p_intf, true );
234 /**********************************************************************
235 * Visualization selector panel
236 **********************************************************************/
237 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
238 QFrame( NULL ), p_intf( _p_i )
240 QHBoxLayout *layout = new QHBoxLayout( this );
241 layout->setMargin( 0 );
242 QPushButton *prevButton = new QPushButton( "Prev" );
243 QPushButton *nextButton = new QPushButton( "Next" );
244 layout->addWidget( prevButton );
245 layout->addWidget( nextButton );
247 layout->addItem( new QSpacerItem( 40,20,
248 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
249 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
251 current = new QLabel( qtr( "None" ) );
252 layout->addWidget( current );
254 BUTTONACT( prevButton, prev() );
255 BUTTONACT( nextButton, next() );
258 setMaximumHeight( 35 );
261 VisualSelector::~VisualSelector()
265 void VisualSelector::prev()
267 char *psz_new = aout_VisualPrev( p_intf );
270 current->setText( qfu( psz_new ) );
275 void VisualSelector::next()
277 char *psz_new = aout_VisualNext( p_intf );
280 current->setText( qfu( psz_new ) );
285 /**********************************************************************
287 **********************************************************************/
289 #define setupSmallButton( aButton ){ \
290 aButton->setMaximumSize( QSize( 26, 26 ) ); \
291 aButton->setMinimumSize( QSize( 26, 26 ) ); \
292 aButton->setIconSize( QSize( 20, 20 ) ); }
294 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
295 QFrame( NULL ), p_intf( _p_i )
297 QHBoxLayout *advLayout = new QHBoxLayout( this );
298 advLayout->setMargin( 0 );
299 advLayout->setSpacing( 0 );
300 advLayout->setAlignment( Qt::AlignBottom );
303 ABButton = new QPushButton( "AB" );
304 setupSmallButton( ABButton );
305 advLayout->addWidget( ABButton );
306 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
308 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
309 this, AtoBLoop( float, int, int ) );
311 frameButton = new QPushButton( "Fr" );
312 frameButton->setMaximumSize( QSize( 26, 26 ) );
313 frameButton->setIconSize( QSize( 20, 20 ) );
314 advLayout->addWidget( frameButton );
315 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
318 recordButton = new QPushButton( "R" );
319 setupSmallButton( recordButton );
320 advLayout->addWidget( recordButton );
321 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
322 qtr( "Record" ), record() );
324 /* Snapshot Button */
325 snapshotButton = new QPushButton( "S" );
326 setupSmallButton( snapshotButton );
327 advLayout->addWidget( snapshotButton );
328 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
331 AdvControlsWidget::~AdvControlsWidget()
334 void AdvControlsWidget::enableInput( bool enable )
336 ABButton->setEnabled( enable );
337 recordButton->setEnabled( enable );
340 void AdvControlsWidget::enableVideo( bool enable )
342 snapshotButton->setEnabled( enable );
344 frameButton->setEnabled( enable );
348 void AdvControlsWidget::snapshot()
350 vout_thread_t *p_vout =
351 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
352 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
355 /* Function called when the button is clicked() */
356 void AdvControlsWidget::fromAtoB()
360 timeA = var_GetTime( THEMIM->getInput(), "time" );
361 ABButton->setText( "A->..." );
366 timeB = var_GetTime( THEMIM->getInput(), "time" );
367 var_SetTime( THEMIM->getInput(), "time" , timeA );
368 ABButton->setText( "A<=>B" );
373 ABButton->setText( "AB" );
376 /* Function called regularly when in an AtoB loop */
377 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
381 if( i_time >= (int)(timeB/1000000) )
382 var_SetTime( THEMIM->getInput(), "time" , timeA );
386 /* FIXME Record function */
387 void AdvControlsWidget::record(){}
390 //FIXME Frame by frame function
391 void AdvControlsWidget::frame(){}
394 /*****************************
395 * DA Control Widget !
396 *****************************/
397 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
398 MainInterface *_p_mi,
402 QFrame( _p_mi ), p_intf( _p_i )
404 controlLayout = new QGridLayout( );
406 controlLayout->setSpacing( 0 );
407 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
410 setLayout( controlLayout );
412 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
414 /** The main Slider **/
415 slider = new InputSlider( Qt::Horizontal, NULL );
416 controlLayout->addWidget( slider, 0, 1, 1, 16 );
417 /* Update the position when the IM has changed */
418 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
419 slider, setPosition( float, int, int ) );
420 /* And update the IM, when the position has changed */
421 CONNECT( slider, sliderDragged( float ),
422 THEMIM->getIM(), sliderUpdate( float ) );
424 /** Slower and faster Buttons **/
425 slowerButton = new QToolButton;
426 slowerButton->setAutoRaise( true );
427 slowerButton->setMaximumSize( QSize( 26, 20 ) );
429 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
430 controlLayout->addWidget( slowerButton, 0, 0 );
432 fasterButton = new QToolButton;
433 fasterButton->setAutoRaise( true );
434 fasterButton->setMaximumSize( QSize( 26, 20 ) );
436 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
437 controlLayout->addWidget( fasterButton, 0, 17 );
439 /* advanced Controls handling */
440 b_advancedVisible = b_advControls;
442 advControls = new AdvControlsWidget( p_intf );
443 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
444 if( !b_advancedVisible ) advControls->hide();
446 /** Disc and Menus handling */
447 discFrame = new QWidget( this );
449 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
450 discLayout->setSpacing( 0 );
451 discLayout->setMargin( 0 );
453 prevSectionButton = new QPushButton( discFrame );
454 setupSmallButton( prevSectionButton );
455 discLayout->addWidget( prevSectionButton );
457 menuButton = new QPushButton( discFrame );
458 setupSmallButton( menuButton );
459 discLayout->addWidget( menuButton );
461 nextSectionButton = new QPushButton( discFrame );
462 setupSmallButton( nextSectionButton );
463 discLayout->addWidget( nextSectionButton );
465 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
467 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
468 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
469 BUTTON_SET_IMG( menuButton, "", previous.png, qtr( "Menu" ) );
473 /* Change the navigation button display when the IM navigation changes */
474 CONNECT( THEMIM->getIM(), navigationChanged( int ),
475 this, setNavigation( int ) );
476 /* Changes the IM navigation when triggered on the nav buttons */
477 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
479 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
481 CONNECT( menuButton, clicked(), THEMIM->getIM(),
486 * TODO: Merge with upper menu in a StackLayout
488 telexFrame = new QWidget( this );
489 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
490 telexLayout->setSpacing( 0 );
491 telexLayout->setMargin( 0 );
493 telexOn = new QPushButton;
494 setupSmallButton( telexOn );
495 telexLayout->addWidget( telexOn );
497 telexTransparent = new QPushButton;
498 setupSmallButton( telexTransparent );
499 telexLayout->addWidget( telexTransparent );
500 b_telexTransparent = false;
502 telexPage = new QSpinBox;
503 telexPage->setRange( 0, 999 );
504 telexPage->setValue( 100 );
505 telexPage->setAccelerated( true );
506 telexPage->setWrapping( true );
507 telexPage->setAlignment( Qt::AlignRight );
508 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
509 telexLayout->addWidget( telexPage );
512 controlLayout->addWidget( telexFrame, 1, 10, 2, 4, Qt::AlignBottom );
513 telexFrame->hide(); /* default hidden */
515 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
516 telexGotoPage( int ) );
517 CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
518 telexPage, setValue( int ) );
520 BUTTON_SET_IMG( telexOn, "", tv.png, qtr( "Teletext on" ) );
522 CONNECT( telexOn, clicked(), THEMIM->getIM(),
523 telexToggleButtons() );
524 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
525 telexToggle( bool ) );
526 CONNECT( THEMIM->getIM(), toggleTelexButtons(),
527 this, toggleTeletext() );
528 b_telexEnabled = false;
529 telexTransparent->setEnabled( false );
530 telexPage->setEnabled( false );
532 BUTTON_SET_IMG( telexTransparent, "", tvtelx.png, qtr( "Teletext" ) );
533 CONNECT( telexTransparent, clicked( bool ),
534 THEMIM->getIM(), telexSetTransparency() );
535 CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
536 this, toggleTeletextTransparency() );
537 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
538 telexFrame, setVisible( bool ) );
541 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
542 sizePolicy.setHorizontalStretch( 0 );
543 sizePolicy.setVerticalStretch( 0 );
546 playButton = new QPushButton;
547 playButton->setSizePolicy( sizePolicy );
548 playButton->setMaximumSize( QSize( 36, 36 ) );
549 playButton->setMinimumSize( QSize( 36, 36 ) );
550 playButton->setIconSize( QSize( 30, 30 ) );
552 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
554 controlLayout->setColumnMinimumWidth( 2, 20 );
555 controlLayout->setColumnStretch( 2, 0 );
557 /** Prev + Stop + Next Block **/
558 controlButLayout = new QHBoxLayout;
559 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
562 QPushButton *prevButton = new QPushButton;
563 prevButton->setSizePolicy( sizePolicy );
564 setupSmallButton( prevButton );
566 controlButLayout->addWidget( prevButton );
569 QPushButton *stopButton = new QPushButton;
570 stopButton->setSizePolicy( sizePolicy );
571 setupSmallButton( stopButton );
573 controlButLayout->addWidget( stopButton );
576 QPushButton *nextButton = new QPushButton;
577 nextButton->setSizePolicy( sizePolicy );
578 setupSmallButton( nextButton );
580 controlButLayout->addWidget( nextButton );
582 /* Add this block to the main layout */
584 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
586 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
587 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
588 qtr( "Previous" ), prev() );
589 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
590 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
592 controlLayout->setColumnMinimumWidth( 7, 20 );
593 controlLayout->setColumnStretch( 7, 0 );
594 controlLayout->setColumnStretch( 8, 0 );
595 controlLayout->setColumnStretch( 9, 0 );
598 * Other first Line buttons
600 /** Fullscreen/Visualisation **/
601 fullscreenButton = new QPushButton( "F" );
602 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
603 setupSmallButton( fullscreenButton );
604 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
606 /** Playlist Button **/
607 playlistButton = new QPushButton;
608 setupSmallButton( playlistButton );
609 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
610 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
611 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
613 /** extended Settings **/
614 extSettingsButton = new QPushButton;
615 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
617 setupSmallButton( extSettingsButton );
618 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
620 controlLayout->setColumnStretch( 13, 0 );
621 controlLayout->setColumnMinimumWidth( 13, 24 );
622 controlLayout->setColumnStretch( 14, 5 );
625 hVolLabel = new VolumeClickHandler( p_intf, this );
627 volMuteLabel = new QLabel;
628 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
629 volMuteLabel->setToolTip( qtr( "Mute" ) );
630 volMuteLabel->installEventFilter( hVolLabel );
631 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
635 volumeSlider = new SoundSlider( this,
636 config_GetInt( p_intf, "volume-step" ),
637 config_GetInt( p_intf, "qt-volume-complete" ),
638 config_GetPsz( p_intf, "qt-slider-colours" ) );
642 volumeSlider = new QSlider( this );
643 volumeSlider->setOrientation( Qt::Horizontal );
645 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
646 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
647 volumeSlider->setFocusPolicy( Qt::NoFocus );
648 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
650 /* Set the volume from the config */
651 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
652 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
654 /* Force the update at build time in order to have a muted icon if needed */
655 updateVolume( volumeSlider->value() );
657 /* Volume control connection */
658 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
659 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
664 ControlsWidget::~ControlsWidget()
667 void ControlsWidget::toggleTeletext()
669 bool b_enabled = THEMIM->teletextState();
672 telexTransparent->setEnabled( false );
673 telexPage->setEnabled( false );
674 b_telexEnabled = false;
678 telexTransparent->setEnabled( true );
679 telexPage->setEnabled( true );
680 b_telexEnabled = true;
684 void ControlsWidget::toggleTeletextTransparency()
686 if( b_telexTransparent )
688 telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx.png" ) );
689 telexTransparent->setToolTip( qtr( "Teletext" ) );
690 b_telexTransparent = false;
694 telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx-transparent.png" ) );
695 telexTransparent->setToolTip( qtr( "Transparent" ) );
696 b_telexTransparent = true;
700 void ControlsWidget::stop()
705 void ControlsWidget::play()
707 if( THEPL->current.i_size == 0 )
709 /* The playlist is empty, open a file requester */
710 THEDP->openFileDialog();
714 THEMIM->togglePlayPause();
717 void ControlsWidget::prev()
722 void ControlsWidget::next()
727 void ControlsWidget::setNavigation( int navigation )
729 #define HELP_PCH N_( "Previous chapter" )
730 #define HELP_NCH N_( "Next chapter" )
732 // 1 = chapter, 2 = title, 0 = no
733 if( navigation == 0 )
736 } else if( navigation == 1 ) {
737 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
738 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
742 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
743 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
749 static bool b_my_volume;
750 void ControlsWidget::updateVolume( int i_sliderVolume )
754 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
755 aout_VolumeSet( p_intf, i_res );
757 if( i_sliderVolume == 0 )
758 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
759 else if( i_sliderVolume < VOLUME_MAX / 3 )
760 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
761 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
762 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
763 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
766 void ControlsWidget::updateVolume()
769 audio_volume_t i_volume;
770 aout_VolumeGet( p_intf, &i_volume );
771 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
772 int i_gauge = volumeSlider->value();
774 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
777 volumeSlider->setValue( i_volume );
782 void ControlsWidget::updateInput()
784 /* Activate the interface buttons according to the presence of the input */
785 enableInput( THEMIM->getIM()->hasInput() );
786 enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
789 void ControlsWidget::setStatus( int status )
791 if( status == PLAYING_S ) /* Playing */
793 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
794 playButton->setToolTip( qtr( "Pause" ) );
798 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
799 playButton->setToolTip( qtr( "Play" ) );
805 * This functions toggle the fullscreen mode
806 * If there is no video, it should first activate Visualisations...
807 * This has also to be fixed in enableVideo()
809 void ControlsWidget::fullscreen()
811 vout_thread_t *p_vout =
812 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
815 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
816 vlc_object_release( p_vout );
820 void ControlsWidget::extSettings()
822 THEDP->extendedDialog();
825 void ControlsWidget::slower()
827 THEMIM->getIM()->slower();
830 void ControlsWidget::faster()
832 THEMIM->getIM()->faster();
835 void ControlsWidget::enableInput( bool enable )
837 slowerButton->setEnabled( enable );
838 slider->setEnabled( enable );
839 fasterButton->setEnabled( enable );
841 /* Advanced Buttons too */
842 advControls->enableInput( enable );
845 void ControlsWidget::enableVideo( bool enable )
847 // TODO Later make the fullscreenButton toggle Visualisation and so on.
848 fullscreenButton->setEnabled( enable );
850 /* Advanced Buttons too */
851 advControls->enableVideo( enable );
854 void ControlsWidget::toggleAdvanced()
856 if( !VISIBLE( advControls ) )
859 b_advancedVisible = true;
864 b_advancedVisible = false;
866 emit advancedControlsToggled( b_advancedVisible );
870 /**********************************************************************
871 * Fullscrenn control widget
872 **********************************************************************/
873 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
874 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
875 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
876 i_lastPosX( -1 ), i_lastPosY( -1 ), i_hideTimeout( 1 ),
877 b_mouseIsOver( false ), b_isFullscreen( false )
879 setWindowFlags( Qt::ToolTip );
881 setFrameShape( QFrame::StyledPanel );
882 setFrameStyle( QFrame::Sunken );
883 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
885 QGridLayout *fsLayout = new QGridLayout( this );
886 controlLayout->setSpacing( 0 );
887 controlLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
889 fsLayout->addWidget( slowerButton, 0, 0 );
890 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
891 fsLayout->addWidget( slider, 0, 1, 1, 6 );
892 fsLayout->addWidget( fasterButton, 0, 7 );
894 fsLayout->addWidget( volMuteLabel, 1, 0);
895 fsLayout->addWidget( volumeSlider, 1, 1 );
897 fsLayout->addLayout( controlButLayout, 1, 2 );
899 fsLayout->addWidget( playButton, 1, 3 );
901 fsLayout->addWidget( discFrame, 1, 4 );
903 fsLayout->addWidget( telexFrame, 1, 5 );
905 fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
907 fsLayout->addWidget( fullscreenButton, 1, 7 );
910 p_hideTimer = new QTimer( this );
911 CONNECT( p_hideTimer, timeout(), this, hideFSControllerWidget() );
912 p_hideTimer->setSingleShot( true );
914 /* slow hiding timer */
915 #if HAVE_TRANSPARENCY
916 p_slowHideTimer = new QTimer( this );
917 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
920 adjustSize (); /* need to get real width and height for moving */
923 QDesktopWidget * p_desktop = QApplication::desktop();
925 move( p_desktop->width() / 2 - width() / 2,
926 p_desktop->height() - height() );
929 setWindowOpacity( 0.0 );
935 FullscreenControllerWidget::~FullscreenControllerWidget()
940 * Hide fullscreen controller
941 * FIXME: under windows it have to be done by moving out of screen
942 * because hide() doesnt work
944 void FullscreenControllerWidget::hideFSControllerWidget()
948 setWindowOpacity( 0.0 ); // simulate hidding
955 * Hidding fullscreen controller slowly
956 * Linux: need composite manager
957 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
959 void FullscreenControllerWidget::slowHideFSC()
961 #if HAVE_TRANSPARENCY
962 static bool first_call = true;
968 p_slowHideTimer->stop();
969 /* the last part of time divided to 100 pieces */
970 p_slowHideTimer->start(
971 (int) ( i_hideTimeout / 2 / ( windowOpacity() * 100 ) ) );
976 if ( windowOpacity() > 0.0 && !fscHidden )
978 if ( windowOpacity() > 0.0 )
981 /* we should use 0.01 because of 100 pieces ^^^
982 but than it cannt be done in time */
983 setWindowOpacity( windowOpacity() - 0.02 );
986 if ( windowOpacity() == 0.0 )
989 p_slowHideTimer->stop();
996 * Get state of visibility of FS controller on screen
997 * On windows control if it is on hidden position
999 bool FullscreenControllerWidget::isFSCHidden()
1010 * events: show, hide, start timer for hidding
1012 void FullscreenControllerWidget::customEvent( QEvent *event )
1014 int type = event->type();
1016 if ( type == FullscreenControlShow_Type && b_isFullscreen )
1019 // after quiting and going to fs, we need to call show()
1026 setWindowOpacity( 1.0 );
1032 #if HAVE_TRANSPARENCY
1033 setWindowOpacity( DEFAULT_OPACITY );
1036 else if ( type == FullscreenControlHide_Type )
1038 hideFSControllerWidget();
1040 else if ( type == FullscreenControlPlanHide_Type && !b_mouseIsOver )
1042 p_hideTimer->start( i_hideTimeout );
1043 #if HAVE_TRANSPARENCY
1044 p_slowHideTimer->start( i_hideTimeout / 2 );
1053 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1055 if ( event->buttons() == Qt::LeftButton )
1057 int i_moveX = event->globalX() - i_lastPosX;
1058 int i_moveY = event->globalY() - i_lastPosY;
1060 move( x() + i_moveX, y() + i_moveY );
1062 i_lastPosX = event->globalX();
1063 i_lastPosY = event->globalY();
1069 * store position of cursor
1071 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1073 i_lastPosX = event->globalX();
1074 i_lastPosY = event->globalY();
1078 * On mouse go above FSC
1080 void FullscreenControllerWidget::enterEvent( QEvent *event )
1082 p_hideTimer->stop();
1083 #if HAVE_TRANSPARENCY
1084 p_slowHideTimer->stop();
1086 b_mouseIsOver = true;
1090 * On mouse go out from FSC
1092 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1094 p_hideTimer->start( i_hideTimeout );
1095 #if HAVE_TRANSPARENCY
1096 p_slowHideTimer->start( i_hideTimeout / 2 );
1098 b_mouseIsOver = false;
1102 * When you get pressed key, send it to video output
1103 * FIXME: clearing focus by clearFocus() to not getting
1104 * key press events didnt work
1106 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1108 int i_vlck = qtEventToVLCKey( event );
1111 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1119 * It is called when video start
1121 void FullscreenControllerWidget::regFullscreenCallback( vout_thread_t *p_vout )
1125 var_AddCallback( p_vout, "fullscreen", regMouseMoveCallback, this );
1130 * It is called after turn off video, because p_vout is NULL now
1131 * we cannt delete callback, just hide if FScontroller is visible
1133 void FullscreenControllerWidget::unregFullscreenCallback()
1140 * Register and unregister callback for mouse moving
1142 static int regMouseMoveCallback( vlc_object_t *vlc_object, const char *variable,
1143 vlc_value_t old_val, vlc_value_t new_val,
1146 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1148 static bool b_registered = false;
1149 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1151 if ( var_GetBool( p_vout, "fullscreen" ) && !b_registered )
1153 p_fs->setHideTimeout( var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1154 p_fs->setIsFullscreen( true );
1155 var_AddCallback( p_vout, "mouse-moved",
1156 showFullscreenControllCallback, (void *) p_fs );
1157 b_registered = true;
1160 if ( !var_GetBool( p_vout, "fullscreen" ) && b_registered )
1162 p_fs->setIsFullscreen( false );
1164 var_DelCallback( p_vout, "mouse-moved",
1165 showFullscreenControllCallback, (void *) p_fs );
1166 b_registered = false;
1173 * Show fullscreen controller after mouse move
1174 * after show immediately plan hide event
1176 static int showFullscreenControllCallback( vlc_object_t *vlc_object, const char *variable,
1177 vlc_value_t old_val, vlc_value_t new_val,
1180 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1182 if ( p_fs->isFSCHidden() || p_fs->windowOpacity() < DEFAULT_OPACITY )
1184 IMEvent *event = new IMEvent( FullscreenControlShow_Type, 0 );
1185 QApplication::postEvent( p_fs, static_cast<QEvent *>(event) );
1188 IMEvent *e = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1189 QApplication::postEvent( p_fs, static_cast<QEvent *>(e) );
1194 /**********************************************************************
1195 * Speed control widget
1196 **********************************************************************/
1197 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1198 QFrame( NULL ), p_intf( _p_i )
1200 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1201 sizePolicy.setHorizontalStretch( 0 );
1202 sizePolicy.setVerticalStretch( 0 );
1204 speedSlider = new QSlider;
1205 speedSlider->setSizePolicy( sizePolicy );
1206 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1207 speedSlider->setOrientation( Qt::Vertical );
1208 speedSlider->setTickPosition( QSlider::TicksRight );
1210 speedSlider->setRange( -100, 100 );
1211 speedSlider->setSingleStep( 10 );
1212 speedSlider->setPageStep( 20 );
1213 speedSlider->setTickInterval( 20 );
1215 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1217 QToolButton *normalSpeedButton = new QToolButton( this );
1218 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1219 normalSpeedButton->setAutoRaise( true );
1220 normalSpeedButton->setText( "N" );
1221 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1223 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1225 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1226 speedControlLayout->addWidget( speedSlider );
1227 speedControlLayout->addWidget( normalSpeedButton );
1228 setLayout( speedControlLayout );
1231 SpeedControlWidget::~SpeedControlWidget()
1234 void SpeedControlWidget::setEnable( bool b_enable )
1236 speedSlider->setEnabled( b_enable );
1239 #define RATE_SLIDER_MAXIMUM 3.0
1240 #define RATE_SLIDER_MINIMUM 0.3
1241 #define RATE_SLIDER_LENGTH 100.0
1243 void SpeedControlWidget::updateControls( int rate )
1245 if( speedSlider->isSliderDown() )
1247 //We don't want to change anything if the user is using the slider
1252 double speed = INPUT_RATE_DEFAULT / (double)rate;
1254 if( rate >= INPUT_RATE_DEFAULT )
1256 if( speed < RATE_SLIDER_MINIMUM )
1258 sliderValue = speedSlider->minimum();
1262 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
1263 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
1268 if( speed > RATE_SLIDER_MAXIMUM )
1270 sliderValue = speedSlider->maximum();
1274 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
1275 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
1279 //Block signals to avoid feedback loop
1280 speedSlider->blockSignals( true );
1281 speedSlider->setValue( sliderValue );
1282 speedSlider->blockSignals( false );
1285 void SpeedControlWidget::updateRate( int sliderValue )
1289 if( sliderValue < 0.0 )
1291 rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
1292 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ));
1296 rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
1297 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH ));
1300 THEMIM->getIM()->setRate(rate);
1303 void SpeedControlWidget::resetRate()
1305 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);