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 /**********************************************************************
60 * Video Widget. A simple frame on which video is drawn
61 * This class handles resize issues
62 **********************************************************************/
64 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
68 hide(); setMinimumSize( 16, 16 );
69 videoSize.rwidth() = -1;
70 videoSize.rheight() = -1;
71 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
73 /* Black background is more coherent for a Video Widget IMVHO */
74 QPalette plt = palette();
75 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
76 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
78 setAttribute( Qt::WA_PaintOnScreen, true );
80 /* The core can ask through a callback to show the video. */
82 connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
83 this, SLOT(SetSizing(unsigned int, unsigned int )),
84 Qt::BlockingQueuedConnection );
86 #error This is broken. Fix it with a QEventLoop with a processEvents ()
87 connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
88 this, SLOT(SetSizing(unsigned int, unsigned int )) );
92 void VideoWidget::paintEvent(QPaintEvent *ev)
94 QFrame::paintEvent(ev);
96 XFlush( QX11Info::display() );
100 VideoWidget::~VideoWidget()
102 vout_thread_t *p_vout = i_vout
103 ? (vout_thread_t *)vlc_object_get( i_vout ) : NULL;
107 if( !p_intf->psz_switch_intf )
109 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
110 vout_Control( p_vout, VOUT_REPARENT );
114 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
115 vout_Control( p_vout, VOUT_CLOSE );
117 vlc_object_release( p_vout );
122 * Request the video to avoid the conflicts
124 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
125 unsigned int *pi_width, unsigned int *pi_height )
127 msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
128 emit askVideoWidgetToShow( *pi_width, *pi_height );
131 msg_Dbg( p_intf, "embedded video already in use" );
134 i_vout = p_nvout->i_object_id;
135 msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );
136 return ( void* )winId();
139 /* Set the Widget to the correct Size */
140 /* Function has to be called by the parent
141 Parent has to care about resizing himself*/
142 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
144 msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
145 videoSize.rwidth() = w;
146 videoSize.rheight() = h;
147 if( isHidden() ) show();
148 updateGeometry(); // Needed for deinterlace
151 void VideoWidget::release( void *p_win )
153 msg_Dbg( p_intf, "Video is not needed anymore" );
155 videoSize.rwidth() = 0;
156 videoSize.rheight() = 0;
158 updateGeometry(); // Needed for deinterlace
161 QSize VideoWidget::sizeHint() const
166 /**********************************************************************
167 * Background Widget. Show a simple image background. Currently,
168 * it's album art if present or cone.
169 **********************************************************************/
170 #define ICON_SIZE 128
171 #define MAX_BG_SIZE 400
172 #define MIN_BG_SIZE 64
174 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
175 :QWidget( NULL ), p_intf( _p_i )
177 /* We should use that one to take the more size it can */
178 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding);
180 /* A dark background */
181 setAutoFillBackground( true );
183 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
184 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
187 /* A cone in the middle */
189 label->setMargin( 5 );
190 label->setMaximumHeight( MAX_BG_SIZE );
191 label->setMaximumWidth( MAX_BG_SIZE );
192 label->setMinimumHeight( MIN_BG_SIZE );
193 label->setMinimumWidth( MIN_BG_SIZE );
194 if( QDate::currentDate().dayOfYear() >= 354 )
195 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
197 label->setPixmap( QPixmap( ":/vlc128.png" ) );
199 QGridLayout *backgroundLayout = new QGridLayout( this );
200 backgroundLayout->addWidget( label, 0, 1 );
201 backgroundLayout->setColumnStretch( 0, 1 );
202 backgroundLayout->setColumnStretch( 2, 1 );
204 CONNECT( THEMIM->getIM(), artChanged( QString ), this, updateArt( QString ) );
207 BackgroundWidget::~BackgroundWidget()
210 void BackgroundWidget::resizeEvent( QResizeEvent * event )
212 if( event->size().height() <= MIN_BG_SIZE )
218 void BackgroundWidget::updateArt( QString url )
222 if( QDate::currentDate().dayOfYear() >= 354 )
223 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
225 label->setPixmap( QPixmap( ":/vlc128.png" ) );
230 label->setPixmap( QPixmap( url ) );
234 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
236 QVLCMenu::PopupMenu( p_intf, true );
239 /**********************************************************************
240 * Visualization selector panel
241 **********************************************************************/
242 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
243 QFrame( NULL ), p_intf( _p_i )
245 QHBoxLayout *layout = new QHBoxLayout( this );
246 layout->setMargin( 0 );
247 QPushButton *prevButton = new QPushButton( "Prev" );
248 QPushButton *nextButton = new QPushButton( "Next" );
249 layout->addWidget( prevButton );
250 layout->addWidget( nextButton );
252 layout->addItem( new QSpacerItem( 40,20,
253 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
254 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
256 current = new QLabel( qtr( "None" ) );
257 layout->addWidget( current );
259 BUTTONACT( prevButton, prev() );
260 BUTTONACT( nextButton, next() );
263 setMaximumHeight( 35 );
266 VisualSelector::~VisualSelector()
269 void VisualSelector::prev()
271 char *psz_new = aout_VisualPrev( p_intf );
274 current->setText( qfu( psz_new ) );
279 void VisualSelector::next()
281 char *psz_new = aout_VisualNext( p_intf );
284 current->setText( qfu( psz_new ) );
289 /**********************************************************************
291 **********************************************************************/
293 #define setupSmallButton( aButton ){ \
294 aButton->setMaximumSize( QSize( 26, 26 ) ); \
295 aButton->setMinimumSize( QSize( 26, 26 ) ); \
296 aButton->setIconSize( QSize( 20, 20 ) ); }
298 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
299 QFrame( NULL ), p_intf( _p_i )
301 QHBoxLayout *advLayout = new QHBoxLayout( this );
302 advLayout->setMargin( 0 );
303 advLayout->setSpacing( 0 );
304 advLayout->setAlignment( Qt::AlignBottom );
307 ABButton = new QPushButton( "AB" );
308 setupSmallButton( ABButton );
309 advLayout->addWidget( ABButton );
310 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
312 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
313 this, AtoBLoop( float, int, int ) );
315 frameButton = new QPushButton( "Fr" );
316 frameButton->setMaximumSize( QSize( 26, 26 ) );
317 frameButton->setIconSize( QSize( 20, 20 ) );
318 advLayout->addWidget( frameButton );
319 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
322 recordButton = new QPushButton( "R" );
323 setupSmallButton( recordButton );
324 advLayout->addWidget( recordButton );
325 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
326 qtr( "Record" ), record() );
328 /* Snapshot Button */
329 snapshotButton = new QPushButton( "S" );
330 setupSmallButton( snapshotButton );
331 advLayout->addWidget( snapshotButton );
332 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
335 AdvControlsWidget::~AdvControlsWidget()
338 void AdvControlsWidget::enableInput( bool enable )
340 ABButton->setEnabled( enable );
341 recordButton->setEnabled( enable );
344 void AdvControlsWidget::enableVideo( bool enable )
346 snapshotButton->setEnabled( enable );
348 frameButton->setEnabled( enable );
352 void AdvControlsWidget::snapshot()
354 vout_thread_t *p_vout =
355 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
356 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
359 /* Function called when the button is clicked() */
360 void AdvControlsWidget::fromAtoB()
364 timeA = var_GetTime( THEMIM->getInput(), "time" );
365 ABButton->setText( "A->..." );
370 timeB = var_GetTime( THEMIM->getInput(), "time" );
371 var_SetTime( THEMIM->getInput(), "time" , timeA );
372 ABButton->setText( "A<=>B" );
377 ABButton->setText( "AB" );
380 /* Function called regularly when in an AtoB loop */
381 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
385 if( i_time >= (int)(timeB/1000000) )
386 var_SetTime( THEMIM->getInput(), "time" , timeA );
390 /* FIXME Record function */
391 void AdvControlsWidget::record(){}
394 //FIXME Frame by frame function
395 void AdvControlsWidget::frame(){}
398 /*****************************
399 * DA Control Widget !
400 *****************************/
401 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
402 MainInterface *_p_mi,
406 QFrame( _p_mi ), p_intf( _p_i )
408 controlLayout = new QGridLayout( );
410 controlLayout->setSpacing( 0 );
411 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
414 setLayout( controlLayout );
416 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
418 /** The main Slider **/
419 slider = new InputSlider( Qt::Horizontal, NULL );
420 controlLayout->addWidget( slider, 0, 1, 1, 16 );
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() );
434 controlLayout->addWidget( slowerButton, 0, 0 );
436 fasterButton = new QToolButton;
437 fasterButton->setAutoRaise( true );
438 fasterButton->setMaximumSize( QSize( 26, 20 ) );
440 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
441 controlLayout->addWidget( fasterButton, 0, 17 );
443 /* advanced Controls handling */
444 b_advancedVisible = b_advControls;
446 advControls = new AdvControlsWidget( p_intf );
447 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
448 if( !b_advancedVisible ) advControls->hide();
450 /** Disc and Menus handling */
451 discFrame = new QWidget( this );
453 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
454 discLayout->setSpacing( 0 );
455 discLayout->setMargin( 0 );
457 prevSectionButton = new QPushButton( discFrame );
458 setupSmallButton( prevSectionButton );
459 discLayout->addWidget( prevSectionButton );
461 menuButton = new QPushButton( discFrame );
462 setupSmallButton( menuButton );
463 discLayout->addWidget( menuButton );
465 nextSectionButton = new QPushButton( discFrame );
466 setupSmallButton( nextSectionButton );
467 discLayout->addWidget( nextSectionButton );
469 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
471 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
472 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
473 BUTTON_SET_IMG( menuButton, "", previous.png, qtr( "Menu" ) );
477 /* Change the navigation button display when the IM navigation changes */
478 CONNECT( THEMIM->getIM(), navigationChanged( int ),
479 this, setNavigation( int ) );
480 /* Changes the IM navigation when triggered on the nav buttons */
481 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
483 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
485 CONNECT( menuButton, clicked(), THEMIM->getIM(),
490 * TODO: Merge with upper menu in a StackLayout
492 telexFrame = new QWidget( this );
493 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
494 telexLayout->setSpacing( 0 );
495 telexLayout->setMargin( 0 );
497 telexOn = new QPushButton;
498 setupSmallButton( telexOn );
499 telexLayout->addWidget( telexOn );
501 telexTransparent = new QPushButton;
502 setupSmallButton( telexTransparent );
503 telexLayout->addWidget( telexTransparent );
504 b_telexTransparent = false;
506 telexPage = new QSpinBox;
507 telexPage->setRange( 0, 999 );
508 telexPage->setValue( 100 );
509 telexPage->setAccelerated( true );
510 telexPage->setWrapping( true );
511 telexPage->setAlignment( Qt::AlignRight );
512 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
513 telexLayout->addWidget( telexPage );
516 controlLayout->addWidget( telexFrame, 1, 10, 2, 4, Qt::AlignBottom );
517 telexFrame->hide(); /* default hidden */
519 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
520 telexGotoPage( int ) );
521 CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
522 telexPage, setValue( int ) );
524 BUTTON_SET_IMG( telexOn, "", tv.png, qtr( "Teletext on" ) );
526 CONNECT( telexOn, clicked(), THEMIM->getIM(),
527 telexToggleButtons() );
528 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
529 telexToggle( bool ) );
530 CONNECT( THEMIM->getIM(), toggleTelexButtons(),
531 this, toggleTeletext() );
532 b_telexEnabled = false;
533 telexTransparent->setEnabled( false );
534 telexPage->setEnabled( false );
536 BUTTON_SET_IMG( telexTransparent, "", tvtelx.png, qtr( "Teletext" ) );
537 CONNECT( telexTransparent, clicked( bool ),
538 THEMIM->getIM(), telexSetTransparency() );
539 CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
540 this, toggleTeletextTransparency() );
541 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
542 telexFrame, setVisible( bool ) );
545 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
546 sizePolicy.setHorizontalStretch( 0 );
547 sizePolicy.setVerticalStretch( 0 );
550 playButton = new QPushButton;
551 playButton->setSizePolicy( sizePolicy );
552 playButton->setMaximumSize( QSize( 36, 36 ) );
553 playButton->setMinimumSize( QSize( 36, 36 ) );
554 playButton->setIconSize( QSize( 30, 30 ) );
556 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
558 controlLayout->setColumnMinimumWidth( 2, 20 );
559 controlLayout->setColumnStretch( 2, 0 );
561 /** Prev + Stop + Next Block **/
562 controlButLayout = new QHBoxLayout;
563 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
566 QPushButton *prevButton = new QPushButton;
567 prevButton->setSizePolicy( sizePolicy );
568 setupSmallButton( prevButton );
570 controlButLayout->addWidget( prevButton );
573 QPushButton *stopButton = new QPushButton;
574 stopButton->setSizePolicy( sizePolicy );
575 setupSmallButton( stopButton );
577 controlButLayout->addWidget( stopButton );
580 QPushButton *nextButton = new QPushButton;
581 nextButton->setSizePolicy( sizePolicy );
582 setupSmallButton( nextButton );
584 controlButLayout->addWidget( nextButton );
586 /* Add this block to the main layout */
588 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
590 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
591 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
592 qtr( "Previous" ), prev() );
593 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
594 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
596 controlLayout->setColumnMinimumWidth( 7, 20 );
597 controlLayout->setColumnStretch( 7, 0 );
598 controlLayout->setColumnStretch( 8, 0 );
599 controlLayout->setColumnStretch( 9, 0 );
602 * Other first Line buttons
604 /** Fullscreen/Visualisation **/
605 fullscreenButton = new QPushButton( "F" );
606 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
607 setupSmallButton( fullscreenButton );
608 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
610 /** Playlist Button **/
611 playlistButton = new QPushButton;
612 setupSmallButton( playlistButton );
613 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
614 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
615 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
617 /** extended Settings **/
618 extSettingsButton = new QPushButton;
619 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
621 setupSmallButton( extSettingsButton );
622 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
624 controlLayout->setColumnStretch( 13, 0 );
625 controlLayout->setColumnMinimumWidth( 13, 24 );
626 controlLayout->setColumnStretch( 14, 5 );
629 hVolLabel = new VolumeClickHandler( p_intf, this );
631 volMuteLabel = new QLabel;
632 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
633 volMuteLabel->setToolTip( qtr( "Mute" ) );
634 volMuteLabel->installEventFilter( hVolLabel );
635 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
639 volumeSlider = new SoundSlider( this,
640 config_GetInt( p_intf, "volume-step" ),
641 config_GetInt( p_intf, "qt-volume-complete" ),
642 config_GetPsz( p_intf, "qt-slider-colours" ) );
646 volumeSlider = new QSlider( this );
647 volumeSlider->setOrientation( Qt::Horizontal );
649 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
650 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
651 volumeSlider->setFocusPolicy( Qt::NoFocus );
652 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
654 /* Set the volume from the config */
655 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
656 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
658 /* Force the update at build time in order to have a muted icon if needed */
659 updateVolume( volumeSlider->value() );
661 /* Volume control connection */
662 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
663 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
668 ControlsWidget::~ControlsWidget()
671 void ControlsWidget::toggleTeletext()
673 bool b_enabled = THEMIM->teletextState();
676 telexTransparent->setEnabled( false );
677 telexPage->setEnabled( false );
678 b_telexEnabled = false;
682 telexTransparent->setEnabled( true );
683 telexPage->setEnabled( true );
684 b_telexEnabled = true;
688 void ControlsWidget::toggleTeletextTransparency()
690 if( b_telexTransparent )
692 telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx.png" ) );
693 telexTransparent->setToolTip( qtr( "Teletext" ) );
694 b_telexTransparent = false;
698 telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx-transparent.png" ) );
699 telexTransparent->setToolTip( qtr( "Transparent" ) );
700 b_telexTransparent = true;
704 void ControlsWidget::stop()
709 void ControlsWidget::play()
711 if( THEPL->current.i_size == 0 )
713 /* The playlist is empty, open a file requester */
714 THEDP->openFileDialog();
718 THEMIM->togglePlayPause();
721 void ControlsWidget::prev()
726 void ControlsWidget::next()
731 void ControlsWidget::setNavigation( int navigation )
733 #define HELP_PCH N_( "Previous chapter" )
734 #define HELP_NCH N_( "Next chapter" )
736 // 1 = chapter, 2 = title, 0 = no
737 if( navigation == 0 )
740 } else if( navigation == 1 ) {
741 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
742 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
746 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
747 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
753 static bool b_my_volume;
754 void ControlsWidget::updateVolume( int i_sliderVolume )
758 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
759 aout_VolumeSet( p_intf, i_res );
761 if( i_sliderVolume == 0 )
762 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
763 else if( i_sliderVolume < VOLUME_MAX / 3 )
764 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
765 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
766 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
767 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
770 void ControlsWidget::updateVolume()
773 audio_volume_t i_volume;
774 aout_VolumeGet( p_intf, &i_volume );
775 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
776 int i_gauge = volumeSlider->value();
778 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
781 volumeSlider->setValue( i_volume );
786 void ControlsWidget::updateInput()
788 /* Activate the interface buttons according to the presence of the input */
789 enableInput( THEMIM->getIM()->hasInput() );
790 enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
793 void ControlsWidget::setStatus( int status )
795 if( status == PLAYING_S ) /* Playing */
797 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
798 playButton->setToolTip( qtr( "Pause" ) );
802 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
803 playButton->setToolTip( qtr( "Play" ) );
809 * This functions toggle the fullscreen mode
810 * If there is no video, it should first activate Visualisations...
811 * This has also to be fixed in enableVideo()
813 void ControlsWidget::fullscreen()
815 vout_thread_t *p_vout =
816 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
819 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
820 vlc_object_release( p_vout );
824 void ControlsWidget::extSettings()
826 THEDP->extendedDialog();
829 void ControlsWidget::slower()
831 THEMIM->getIM()->slower();
834 void ControlsWidget::faster()
836 THEMIM->getIM()->faster();
839 void ControlsWidget::enableInput( bool enable )
841 slowerButton->setEnabled( enable );
842 slider->setEnabled( enable );
843 fasterButton->setEnabled( enable );
845 /* Advanced Buttons too */
846 advControls->enableInput( enable );
849 void ControlsWidget::enableVideo( bool enable )
851 // TODO Later make the fullscreenButton toggle Visualisation and so on.
852 fullscreenButton->setEnabled( enable );
854 /* Advanced Buttons too */
855 advControls->enableVideo( enable );
858 void ControlsWidget::toggleAdvanced()
860 if( !VISIBLE( advControls ) )
863 b_advancedVisible = true;
868 b_advancedVisible = false;
870 emit advancedControlsToggled( b_advancedVisible );
874 /**********************************************************************
875 * Fullscrenn control widget
876 **********************************************************************/
877 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
878 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
879 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
880 i_lastPosX( -1 ), i_lastPosY( -1 ), i_hideTimeout( 1 ),
881 b_mouseIsOver( false ), b_isFullscreen( false )
883 setWindowFlags( Qt::ToolTip );
885 setFrameShape( QFrame::StyledPanel );
886 setFrameStyle( QFrame::Sunken );
887 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
889 QGridLayout *fsLayout = new QGridLayout( this );
890 controlLayout->setSpacing( 0 );
891 controlLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
893 fsLayout->addWidget( slowerButton, 0, 0 );
894 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
895 fsLayout->addWidget( slider, 0, 1, 1, 6 );
896 fsLayout->addWidget( fasterButton, 0, 7 );
898 fsLayout->addWidget( volMuteLabel, 1, 0);
899 fsLayout->addWidget( volumeSlider, 1, 1 );
901 fsLayout->addLayout( controlButLayout, 1, 2 );
903 fsLayout->addWidget( playButton, 1, 3 );
905 fsLayout->addWidget( discFrame, 1, 4 );
907 fsLayout->addWidget( telexFrame, 1, 5 );
909 fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
911 fsLayout->addWidget( fullscreenButton, 1, 7 );
914 p_hideTimer = new QTimer( this );
915 CONNECT( p_hideTimer, timeout(), this, hideFSControllerWidget() );
916 p_hideTimer->setSingleShot( true );
918 /* slow hiding timer */
919 #if HAVE_TRANSPARENCY
920 p_slowHideTimer = new QTimer( this );
921 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
924 adjustSize (); /* need to get real width and height for moving */
927 QDesktopWidget * p_desktop = QApplication::desktop();
929 move( p_desktop->width() / 2 - width() / 2,
930 p_desktop->height() - height() );
933 setWindowOpacity( 0.0 );
939 FullscreenControllerWidget::~FullscreenControllerWidget()
944 * Hide fullscreen controller
945 * FIXME: under windows it have to be done by moving out of screen
946 * because hide() doesnt work
948 void FullscreenControllerWidget::hideFSControllerWidget()
952 setWindowOpacity( 0.0 ); // simulate hidding
959 * Hidding fullscreen controller slowly
960 * Linux: need composite manager
961 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
963 void FullscreenControllerWidget::slowHideFSC()
965 #if HAVE_TRANSPARENCY
966 static bool first_call = true;
972 p_slowHideTimer->stop();
973 /* the last part of time divided to 100 pieces */
974 p_slowHideTimer->start(
975 (int) ( i_hideTimeout / 2 / ( windowOpacity() * 100 ) ) );
980 if ( windowOpacity() > 0.0 && !fscHidden )
982 if ( windowOpacity() > 0.0 )
985 /* we should use 0.01 because of 100 pieces ^^^
986 but than it cannt be done in time */
987 setWindowOpacity( windowOpacity() - 0.02 );
990 if ( windowOpacity() == 0.0 )
993 p_slowHideTimer->stop();
1000 * Get state of visibility of FS controller on screen
1001 * On windows control if it is on hidden position
1003 bool FullscreenControllerWidget::isFSCHidden()
1014 * events: show, hide, start timer for hidding
1016 void FullscreenControllerWidget::customEvent( QEvent *event )
1018 int type = event->type();
1020 if ( type == FullscreenControlShow_Type && b_isFullscreen )
1023 // after quiting and going to fs, we need to call show()
1030 setWindowOpacity( 1.0 );
1036 #if HAVE_TRANSPARENCY
1037 setWindowOpacity( DEFAULT_OPACITY );
1040 else if ( type == FullscreenControlHide_Type )
1042 hideFSControllerWidget();
1044 else if ( type == FullscreenControlPlanHide_Type && !b_mouseIsOver )
1046 p_hideTimer->start( i_hideTimeout );
1047 #if HAVE_TRANSPARENCY
1048 p_slowHideTimer->start( i_hideTimeout / 2 );
1057 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1059 if ( event->buttons() == Qt::LeftButton )
1061 int i_moveX = event->globalX() - i_lastPosX;
1062 int i_moveY = event->globalY() - i_lastPosY;
1064 move( x() + i_moveX, y() + i_moveY );
1066 i_lastPosX = event->globalX();
1067 i_lastPosY = event->globalY();
1073 * store position of cursor
1075 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1077 i_lastPosX = event->globalX();
1078 i_lastPosY = event->globalY();
1082 * On mouse go above FSC
1084 void FullscreenControllerWidget::enterEvent( QEvent *event )
1086 p_hideTimer->stop();
1087 #if HAVE_TRANSPARENCY
1088 p_slowHideTimer->stop();
1090 b_mouseIsOver = true;
1094 * On mouse go out from FSC
1096 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1098 p_hideTimer->start( i_hideTimeout );
1099 #if HAVE_TRANSPARENCY
1100 p_slowHideTimer->start( i_hideTimeout / 2 );
1102 b_mouseIsOver = false;
1106 * When you get pressed key, send it to video output
1107 * FIXME: clearing focus by clearFocus() to not getting
1108 * key press events didnt work
1110 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1112 int i_vlck = qtEventToVLCKey( event );
1115 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1123 * It is called when video start
1125 void FullscreenControllerWidget::regFullscreenCallback( vout_thread_t *p_vout )
1129 var_AddCallback( p_vout, "fullscreen", regMouseMoveCallback, this );
1134 * It is called after turn off video, because p_vout is NULL now
1135 * we cannt delete callback, just hide if FScontroller is visible
1137 void FullscreenControllerWidget::unregFullscreenCallback()
1144 * Register and unregister callback for mouse moving
1146 static int regMouseMoveCallback( vlc_object_t *vlc_object, const char *variable,
1147 vlc_value_t old_val, vlc_value_t new_val,
1150 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1152 static bool b_registered = false;
1153 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1155 if ( var_GetBool( p_vout, "fullscreen" ) && !b_registered )
1157 p_fs->setHideTimeout( var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1158 p_fs->setIsFullscreen( true );
1159 var_AddCallback( p_vout, "mouse-moved",
1160 showFullscreenControllCallback, (void *) p_fs );
1161 b_registered = true;
1164 if ( !var_GetBool( p_vout, "fullscreen" ) && b_registered )
1166 p_fs->setIsFullscreen( false );
1168 var_DelCallback( p_vout, "mouse-moved",
1169 showFullscreenControllCallback, (void *) p_fs );
1170 b_registered = false;
1177 * Show fullscreen controller after mouse move
1178 * after show immediately plan hide event
1180 static int showFullscreenControllCallback( vlc_object_t *vlc_object, const char *variable,
1181 vlc_value_t old_val, vlc_value_t new_val,
1184 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1186 if ( p_fs->isFSCHidden() || p_fs->windowOpacity() < DEFAULT_OPACITY )
1188 IMEvent *event = new IMEvent( FullscreenControlShow_Type, 0 );
1189 QApplication::postEvent( p_fs, static_cast<QEvent *>(event) );
1192 IMEvent *e = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1193 QApplication::postEvent( p_fs, static_cast<QEvent *>(e) );
1198 /**********************************************************************
1199 * Speed control widget
1200 **********************************************************************/
1201 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1202 QFrame( NULL ), p_intf( _p_i )
1204 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1205 sizePolicy.setHorizontalStretch( 0 );
1206 sizePolicy.setVerticalStretch( 0 );
1208 speedSlider = new QSlider;
1209 speedSlider->setSizePolicy( sizePolicy );
1210 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1211 speedSlider->setOrientation( Qt::Vertical );
1212 speedSlider->setTickPosition( QSlider::TicksRight );
1214 speedSlider->setRange( -24, 24 );
1215 speedSlider->setSingleStep( 1 );
1216 speedSlider->setPageStep( 1 );
1217 speedSlider->setTickInterval( 12 );
1219 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1221 QToolButton *normalSpeedButton = new QToolButton( this );
1222 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1223 normalSpeedButton->setAutoRaise( true );
1224 normalSpeedButton->setText( "1x" );
1225 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1227 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1229 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1230 speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
1231 speedControlLayout->setSpacing( 4 );
1232 speedControlLayout->addWidget( speedSlider );
1233 speedControlLayout->addWidget( normalSpeedButton );
1234 setLayout( speedControlLayout );
1237 SpeedControlWidget::~SpeedControlWidget()
1240 void SpeedControlWidget::setEnable( bool b_enable )
1242 speedSlider->setEnabled( b_enable );
1245 void SpeedControlWidget::updateControls( int rate )
1247 if( speedSlider->isSliderDown() )
1249 //We don't want to change anything if the user is using the slider
1253 double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
1254 int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
1256 if( sliderValue < speedSlider->minimum() )
1258 sliderValue = speedSlider->minimum();
1260 else if( sliderValue > speedSlider->maximum() )
1262 sliderValue = speedSlider->maximum();
1265 //Block signals to avoid feedback loop
1266 speedSlider->blockSignals( true );
1267 speedSlider->setValue( sliderValue );
1268 speedSlider->blockSignals( false );
1271 void SpeedControlWidget::updateRate( int sliderValue )
1273 double speed = pow( 2, (double)sliderValue / 12 );
1274 int rate = INPUT_RATE_DEFAULT / speed;
1276 THEMIM->getIM()->setRate(rate);
1279 void SpeedControlWidget::resetRate()
1281 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);