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->addStretch( 10 );
253 layout->addWidget( new QLabel( qtr( "Current visualization" ) ) );
255 current = new QLabel( qtr( "None" ) );
256 layout->addWidget( current );
258 BUTTONACT( prevButton, prev() );
259 BUTTONACT( nextButton, next() );
262 setMaximumHeight( 35 );
265 VisualSelector::~VisualSelector()
268 void VisualSelector::prev()
270 char *psz_new = aout_VisualPrev( p_intf );
273 current->setText( qfu( psz_new ) );
278 void VisualSelector::next()
280 char *psz_new = aout_VisualNext( p_intf );
283 current->setText( qfu( psz_new ) );
288 /**********************************************************************
290 **********************************************************************/
292 #define setupSmallButton( aButton ){ \
293 aButton->setMaximumSize( QSize( 26, 26 ) ); \
294 aButton->setMinimumSize( QSize( 26, 26 ) ); \
295 aButton->setIconSize( QSize( 20, 20 ) ); }
297 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
298 QFrame( NULL ), p_intf( _p_i )
300 QHBoxLayout *advLayout = new QHBoxLayout( this );
301 advLayout->setMargin( 0 );
302 advLayout->setSpacing( 0 );
303 advLayout->setAlignment( Qt::AlignBottom );
306 ABButton = new QPushButton( "AB" );
307 setupSmallButton( ABButton );
308 advLayout->addWidget( ABButton );
309 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
311 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
312 this, AtoBLoop( float, int, int ) );
314 frameButton = new QPushButton( "Fr" );
315 frameButton->setMaximumSize( QSize( 26, 26 ) );
316 frameButton->setIconSize( QSize( 20, 20 ) );
317 advLayout->addWidget( frameButton );
318 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by frame" ), frame() );
321 recordButton = new QPushButton( "R" );
322 setupSmallButton( recordButton );
323 advLayout->addWidget( recordButton );
324 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
325 qtr( "Record" ), record() );
327 /* Snapshot Button */
328 snapshotButton = new QPushButton( "S" );
329 setupSmallButton( snapshotButton );
330 advLayout->addWidget( snapshotButton );
331 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
334 AdvControlsWidget::~AdvControlsWidget()
337 void AdvControlsWidget::enableInput( bool enable )
339 ABButton->setEnabled( enable );
340 recordButton->setEnabled( enable );
343 void AdvControlsWidget::enableVideo( bool enable )
345 snapshotButton->setEnabled( enable );
347 frameButton->setEnabled( enable );
351 void AdvControlsWidget::snapshot()
353 vout_thread_t *p_vout =
354 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
355 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
358 /* Function called when the button is clicked() */
359 void AdvControlsWidget::fromAtoB()
363 timeA = var_GetTime( THEMIM->getInput(), "time" );
364 ABButton->setText( "A->..." );
369 timeB = var_GetTime( THEMIM->getInput(), "time" );
370 var_SetTime( THEMIM->getInput(), "time" , timeA );
371 ABButton->setText( "A<=>B" );
376 ABButton->setText( "AB" );
379 /* Function called regularly when in an AtoB loop */
380 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
384 if( i_time >= (int)(timeB/1000000) )
385 var_SetTime( THEMIM->getInput(), "time" , timeA );
389 /* FIXME Record function */
390 void AdvControlsWidget::record(){}
393 //FIXME Frame by frame function
394 void AdvControlsWidget::frame(){}
397 /*****************************
398 * DA Control Widget !
399 *****************************/
400 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
401 MainInterface *_p_mi,
405 QFrame( _p_mi ), p_intf( _p_i )
407 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
409 /** The main Slider **/
410 slider = new InputSlider( Qt::Horizontal, NULL );
411 /* Update the position when the IM has changed */
412 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
413 slider, setPosition( float, int, int ) );
414 /* And update the IM, when the position has changed */
415 CONNECT( slider, sliderDragged( float ),
416 THEMIM->getIM(), sliderUpdate( float ) );
418 /** Slower and faster Buttons **/
419 slowerButton = new QToolButton;
420 slowerButton->setAutoRaise( true );
421 slowerButton->setMaximumSize( QSize( 26, 20 ) );
423 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
425 fasterButton = new QToolButton;
426 fasterButton->setAutoRaise( true );
427 fasterButton->setMaximumSize( QSize( 26, 20 ) );
429 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
431 /* advanced Controls handling */
432 b_advancedVisible = b_advControls;
434 advControls = new AdvControlsWidget( p_intf );
435 if( !b_advancedVisible ) advControls->hide();
437 /** Disc and Menus handling */
438 discFrame = new QWidget( this );
440 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
441 discLayout->setSpacing( 0 );
442 discLayout->setMargin( 0 );
444 prevSectionButton = new QPushButton( discFrame );
445 setupSmallButton( prevSectionButton );
446 discLayout->addWidget( prevSectionButton );
448 menuButton = new QPushButton( discFrame );
449 setupSmallButton( menuButton );
450 discLayout->addWidget( menuButton );
452 nextSectionButton = new QPushButton( discFrame );
453 setupSmallButton( nextSectionButton );
454 discLayout->addWidget( nextSectionButton );
456 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
457 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
458 BUTTON_SET_IMG( menuButton, "", previous.png, qtr( "Menu" ) );
462 /* Change the navigation button display when the IM navigation changes */
463 CONNECT( THEMIM->getIM(), navigationChanged( int ),
464 this, setNavigation( int ) );
465 /* Changes the IM navigation when triggered on the nav buttons */
466 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
468 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
470 CONNECT( menuButton, clicked(), THEMIM->getIM(),
475 * TODO: Merge with upper menu in a StackLayout
477 telexFrame = new QWidget( this );
478 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
479 telexLayout->setSpacing( 0 );
480 telexLayout->setMargin( 0 );
482 telexOn = new QPushButton;
483 setupSmallButton( telexOn );
484 telexLayout->addWidget( telexOn );
486 telexTransparent = new QPushButton;
487 setupSmallButton( telexTransparent );
488 telexLayout->addWidget( telexTransparent );
489 b_telexTransparent = false;
491 telexPage = new QSpinBox;
492 telexPage->setRange( 0, 999 );
493 telexPage->setValue( 100 );
494 telexPage->setAccelerated( true );
495 telexPage->setWrapping( true );
496 telexPage->setAlignment( Qt::AlignRight );
497 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
498 telexLayout->addWidget( telexPage );
500 telexFrame->hide(); /* default hidden */
502 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
503 telexGotoPage( int ) );
504 CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
505 telexPage, setValue( int ) );
507 BUTTON_SET_IMG( telexOn, "", tv.png, qtr( "Teletext on" ) );
509 CONNECT( telexOn, clicked(), THEMIM->getIM(),
510 telexToggleButtons() );
511 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
512 telexToggle( bool ) );
513 CONNECT( THEMIM->getIM(), toggleTelexButtons(),
514 this, toggleTeletext() );
515 b_telexEnabled = false;
516 telexTransparent->setEnabled( false );
517 telexPage->setEnabled( false );
519 BUTTON_SET_IMG( telexTransparent, "", tvtelx.png, qtr( "Teletext" ) );
520 CONNECT( telexTransparent, clicked( bool ),
521 THEMIM->getIM(), telexSetTransparency() );
522 CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
523 this, toggleTeletextTransparency() );
524 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
525 this, enableTeletext( bool ) );
528 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
529 sizePolicy.setHorizontalStretch( 0 );
530 sizePolicy.setVerticalStretch( 0 );
533 playButton = new QPushButton;
534 playButton->setSizePolicy( sizePolicy );
535 playButton->setMaximumSize( QSize( 36, 36 ) );
536 playButton->setMinimumSize( QSize( 36, 36 ) );
537 playButton->setIconSize( QSize( 30, 30 ) );
540 /** Prev + Stop + Next Block **/
541 controlButLayout = new QHBoxLayout;
542 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
545 QPushButton *prevButton = new QPushButton;
546 prevButton->setSizePolicy( sizePolicy );
547 setupSmallButton( prevButton );
549 controlButLayout->addWidget( prevButton );
552 QPushButton *stopButton = new QPushButton;
553 stopButton->setSizePolicy( sizePolicy );
554 setupSmallButton( stopButton );
556 controlButLayout->addWidget( stopButton );
559 QPushButton *nextButton = new QPushButton;
560 nextButton->setSizePolicy( sizePolicy );
561 setupSmallButton( nextButton );
563 controlButLayout->addWidget( nextButton );
565 /* Add this block to the main layout */
567 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
568 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
569 qtr( "Previous" ), prev() );
570 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
571 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
574 * Other first Line buttons
576 /** Fullscreen/Visualisation **/
577 fullscreenButton = new QPushButton( "F" );
578 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
579 setupSmallButton( fullscreenButton );
581 /** Playlist Button **/
582 playlistButton = new QPushButton;
583 setupSmallButton( playlistButton );
584 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
585 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
587 /** extended Settings **/
588 extSettingsButton = new QPushButton;
589 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended settings" ),
591 setupSmallButton( extSettingsButton );
595 hVolLabel = new VolumeClickHandler( p_intf, this );
597 volMuteLabel = new QLabel;
598 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
599 volMuteLabel->setToolTip( qtr( "Mute" ) );
600 volMuteLabel->installEventFilter( hVolLabel );
604 volumeSlider = new SoundSlider( this,
605 config_GetInt( p_intf, "volume-step" ),
606 config_GetInt( p_intf, "qt-volume-complete" ),
607 config_GetPsz( p_intf, "qt-slider-colours" ) );
611 volumeSlider = new QSlider( this );
612 volumeSlider->setOrientation( Qt::Horizontal );
614 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
615 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
616 volumeSlider->setFocusPolicy( Qt::NoFocus );
618 /* Set the volume from the config */
619 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
620 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
622 /* Force the update at build time in order to have a muted icon if needed */
623 updateVolume( volumeSlider->value() );
625 /* Volume control connection */
626 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
627 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
631 controlLayout = new QGridLayout( this );
633 controlLayout->setSpacing( 0 );
634 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
636 controlLayout->addWidget( slider, 0, 1, 1, 16 );
637 controlLayout->addWidget( slowerButton, 0, 0 );
638 controlLayout->addWidget( fasterButton, 0, 17 );
640 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
641 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
642 controlLayout->addWidget( telexFrame, 1, 10, 2, 4, Qt::AlignBottom );
644 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
645 controlLayout->setColumnMinimumWidth( 2, 20 );
646 controlLayout->setColumnStretch( 2, 0 );
648 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
649 controlLayout->setColumnMinimumWidth( 7, 20 );
650 controlLayout->setColumnStretch( 7, 0 );
651 controlLayout->setColumnStretch( 8, 0 );
652 controlLayout->setColumnStretch( 9, 0 );
654 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
655 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
656 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
658 controlLayout->setColumnStretch( 13, 0 );
659 controlLayout->setColumnMinimumWidth( 13, 24 );
660 controlLayout->setColumnStretch( 14, 5 );
662 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
663 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
669 ControlsWidget::~ControlsWidget()
672 void ControlsWidget::toggleTeletext()
674 bool b_enabled = THEMIM->teletextState();
677 telexTransparent->setEnabled( false );
678 telexPage->setEnabled( false );
679 b_telexEnabled = false;
683 telexTransparent->setEnabled( true );
684 telexPage->setEnabled( true );
685 b_telexEnabled = true;
689 void ControlsWidget::enableTeletext( bool b_enable )
691 telexFrame->setVisible( b_enable );
692 bool b_on = THEMIM->teletextState();
694 telexOn->setChecked( b_on );
695 telexTransparent->setEnabled( b_on );
696 telexPage->setEnabled( b_on );
697 b_telexEnabled = b_on;
700 void ControlsWidget::toggleTeletextTransparency()
702 if( b_telexTransparent )
704 telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx.png" ) );
705 telexTransparent->setToolTip( qtr( "Teletext" ) );
706 b_telexTransparent = false;
710 telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx-transparent.png" ) );
711 telexTransparent->setToolTip( qtr( "Transparent" ) );
712 b_telexTransparent = true;
716 void ControlsWidget::stop()
721 void ControlsWidget::play()
723 if( THEPL->current.i_size == 0 )
725 /* The playlist is empty, open a file requester */
726 THEDP->openFileDialog();
730 THEMIM->togglePlayPause();
733 void ControlsWidget::prev()
738 void ControlsWidget::next()
743 void ControlsWidget::setNavigation( int navigation )
745 #define HELP_PCH N_( "Previous chapter" )
746 #define HELP_NCH N_( "Next chapter" )
748 // 1 = chapter, 2 = title, 0 = no
749 if( navigation == 0 )
752 } else if( navigation == 1 ) {
753 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
754 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
758 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
759 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
765 static bool b_my_volume;
766 void ControlsWidget::updateVolume( int i_sliderVolume )
770 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
771 aout_VolumeSet( p_intf, i_res );
773 if( i_sliderVolume == 0 )
774 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
775 else if( i_sliderVolume < VOLUME_MAX / 3 )
776 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
777 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
778 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
779 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
782 void ControlsWidget::updateVolume()
785 audio_volume_t i_volume;
786 aout_VolumeGet( p_intf, &i_volume );
787 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
788 int i_gauge = volumeSlider->value();
790 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
793 volumeSlider->setValue( i_volume );
798 void ControlsWidget::updateInput()
800 /* Activate the interface buttons according to the presence of the input */
801 enableInput( THEMIM->getIM()->hasInput() );
802 enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
805 void ControlsWidget::setStatus( int status )
807 if( status == PLAYING_S ) /* Playing */
809 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
810 playButton->setToolTip( qtr( "Pause" ) );
814 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
815 playButton->setToolTip( qtr( "Play" ) );
821 * This functions toggle the fullscreen mode
822 * If there is no video, it should first activate Visualisations...
823 * This has also to be fixed in enableVideo()
825 void ControlsWidget::fullscreen()
827 vout_thread_t *p_vout =
828 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
831 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
832 vlc_object_release( p_vout );
836 void ControlsWidget::extSettings()
838 THEDP->extendedDialog();
841 void ControlsWidget::slower()
843 THEMIM->getIM()->slower();
846 void ControlsWidget::faster()
848 THEMIM->getIM()->faster();
851 void ControlsWidget::enableInput( bool enable )
853 slowerButton->setEnabled( enable );
854 slider->setEnabled( enable );
855 fasterButton->setEnabled( enable );
857 /* Advanced Buttons too */
858 advControls->enableInput( enable );
861 void ControlsWidget::enableVideo( bool enable )
863 // TODO Later make the fullscreenButton toggle Visualisation and so on.
864 fullscreenButton->setEnabled( enable );
866 /* Advanced Buttons too */
867 advControls->enableVideo( enable );
870 void ControlsWidget::toggleAdvanced()
872 if( !VISIBLE( advControls ) )
875 b_advancedVisible = true;
880 b_advancedVisible = false;
882 emit advancedControlsToggled( b_advancedVisible );
886 /**********************************************************************
887 * Fullscrenn control widget
888 **********************************************************************/
889 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
890 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
891 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
892 i_mouse_last_x( -1 ), i_mouse_last_y( -1 ), b_mouse_over(false),
893 b_slow_hide_begin(false), i_slow_hide_timeout(1),
894 b_fullscreen( false ), i_hide_timeout( 1 )
896 setWindowFlags( Qt::ToolTip );
898 setFrameShape( QFrame::StyledPanel );
899 setFrameStyle( QFrame::Sunken );
900 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
902 QGridLayout *fsLayout = new QGridLayout( this );
903 fsLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
905 fsLayout->addWidget( slowerButton, 0, 0 );
906 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
907 fsLayout->addWidget( slider, 0, 1, 1, 6 );
908 fsLayout->addWidget( fasterButton, 0, 7 );
910 fsLayout->addWidget( volMuteLabel, 1, 0);
911 fsLayout->addWidget( volumeSlider, 1, 1 );
913 fsLayout->addLayout( controlButLayout, 1, 2 );
915 fsLayout->addWidget( playButton, 1, 3 );
917 fsLayout->addWidget( discFrame, 1, 4 );
919 fsLayout->addWidget( telexFrame, 1, 5 );
921 fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
923 fsLayout->addWidget( fullscreenButton, 1, 7 );
926 p_hideTimer = new QTimer( this );
927 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
928 p_hideTimer->setSingleShot( true );
930 /* slow hiding timer */
931 #if HAVE_TRANSPARENCY
932 p_slowHideTimer = new QTimer( this );
933 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
936 adjustSize (); /* need to get real width and height for moving */
939 QDesktopWidget * p_desktop = QApplication::desktop();
941 move( p_desktop->width() / 2 - width() / 2,
942 p_desktop->height() - height() );
945 setWindowOpacity( 0.0 );
950 vlc_mutex_init_recursive( &lock );
953 FullscreenControllerWidget::~FullscreenControllerWidget()
955 vlc_mutex_destroy( &lock );
959 * Show fullscreen controller
961 void FullscreenControllerWidget::showFSC()
964 // after quiting and going to fs, we need to call show()
971 setWindowOpacity( 1.0 );
977 #if HAVE_TRANSPARENCY
978 setWindowOpacity( DEFAULT_OPACITY );
983 * Hide fullscreen controller
984 * FIXME: under windows it have to be done by moving out of screen
985 * because hide() doesnt work
987 void FullscreenControllerWidget::hideFSC()
991 setWindowOpacity( 0.0 ); // simulate hidding
998 * Plane to hide fullscreen controller
1000 void FullscreenControllerWidget::planHideFSC()
1002 vlc_mutex_lock( &lock );
1003 int i_timeout = i_hide_timeout;
1004 vlc_mutex_unlock( &lock );
1006 p_hideTimer->start( i_timeout );
1008 #if HAVE_TRANSPARENCY
1009 b_slow_hide_begin = true;
1010 i_slow_hide_timeout = i_timeout;
1011 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
1016 * Hidding fullscreen controller slowly
1017 * Linux: need composite manager
1018 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
1020 void FullscreenControllerWidget::slowHideFSC()
1022 #if HAVE_TRANSPARENCY
1023 if( b_slow_hide_begin )
1025 b_slow_hide_begin = false;
1027 p_slowHideTimer->stop();
1028 /* the last part of time divided to 100 pieces */
1029 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
1035 if ( windowOpacity() > 0.0 && !fscHidden )
1037 if ( windowOpacity() > 0.0 )
1040 /* we should use 0.01 because of 100 pieces ^^^
1041 but than it cannt be done in time */
1042 setWindowOpacity( windowOpacity() - 0.02 );
1045 if ( windowOpacity() <= 0.0 )
1046 p_slowHideTimer->stop();
1053 * events: show, hide, start timer for hidding
1055 void FullscreenControllerWidget::customEvent( QEvent *event )
1059 switch( event->type() )
1061 case FullscreenControlShow_Type:
1062 vlc_mutex_lock( &lock );
1063 b_fs = b_fullscreen;
1064 vlc_mutex_unlock( &lock );
1066 if( b_fs ) // FIXME I am not sure about that one
1069 case FullscreenControlHide_Type:
1072 case FullscreenControlPlanHide_Type:
1073 if( !b_mouse_over ) // Only if the mouse is not over FSC
1083 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1085 if ( event->buttons() == Qt::LeftButton )
1087 int i_moveX = event->globalX() - i_mouse_last_x;
1088 int i_moveY = event->globalY() - i_mouse_last_y;
1090 move( x() + i_moveX, y() + i_moveY );
1092 i_mouse_last_x = event->globalX();
1093 i_mouse_last_y = event->globalY();
1099 * store position of cursor
1101 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1103 i_mouse_last_x = event->globalX();
1104 i_mouse_last_y = event->globalY();
1108 * On mouse go above FSC
1110 void FullscreenControllerWidget::enterEvent( QEvent *event )
1112 b_mouse_over = true;
1114 p_hideTimer->stop();
1115 #if HAVE_TRANSPARENCY
1116 p_slowHideTimer->stop();
1121 * On mouse go out from FSC
1123 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1127 b_mouse_over = false;
1131 * When you get pressed key, send it to video output
1132 * FIXME: clearing focus by clearFocus() to not getting
1133 * key press events didnt work
1135 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1137 int i_vlck = qtEventToVLCKey( event );
1140 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1148 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object, const char *variable,
1149 vlc_value_t old_val, vlc_value_t new_val,
1152 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1153 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1155 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1160 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1161 vlc_value_t old_val, vlc_value_t new_val,
1164 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1167 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1168 QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1170 /* Plan hide event */
1171 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1172 QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1179 * It is called when video start
1181 void FullscreenControllerWidget::attachVout( vout_thread_t *p_vout )
1185 vlc_mutex_lock( &lock );
1186 var_AddCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this ); /* I miss a add and fire */
1187 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ), var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1188 vlc_mutex_unlock( &lock );
1191 * It is called after turn off video.
1193 void FullscreenControllerWidget::detachVout( vout_thread_t *p_vout )
1197 var_DelCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this );
1198 vlc_mutex_lock( &lock );
1199 fullscreenChanged( p_vout, false, 0 );
1200 vlc_mutex_unlock( &lock );
1204 * Register and unregister callback for mouse moving
1206 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout, bool b_fs, int i_timeout )
1208 vlc_mutex_lock( &lock );
1209 if( b_fs && !b_fullscreen )
1211 b_fullscreen = true;
1212 i_hide_timeout = i_timeout;
1213 var_AddCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1215 else if( !b_fs && b_fullscreen )
1217 b_fullscreen = false;
1218 i_hide_timeout = i_timeout;
1219 var_DelCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1221 /* Force fs hidding */
1222 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1223 QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1225 vlc_mutex_unlock( &lock );
1228 /**********************************************************************
1229 * Speed control widget
1230 **********************************************************************/
1231 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1232 QFrame( NULL ), p_intf( _p_i )
1234 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1235 sizePolicy.setHorizontalStretch( 0 );
1236 sizePolicy.setVerticalStretch( 0 );
1238 speedSlider = new QSlider;
1239 speedSlider->setSizePolicy( sizePolicy );
1240 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1241 speedSlider->setOrientation( Qt::Vertical );
1242 speedSlider->setTickPosition( QSlider::TicksRight );
1244 speedSlider->setRange( -24, 24 );
1245 speedSlider->setSingleStep( 1 );
1246 speedSlider->setPageStep( 1 );
1247 speedSlider->setTickInterval( 12 );
1249 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1251 QToolButton *normalSpeedButton = new QToolButton( this );
1252 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1253 normalSpeedButton->setAutoRaise( true );
1254 normalSpeedButton->setText( "1x" );
1255 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1257 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1259 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1260 speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
1261 speedControlLayout->setSpacing( 4 );
1262 speedControlLayout->addWidget( speedSlider );
1263 speedControlLayout->addWidget( normalSpeedButton );
1264 setLayout( speedControlLayout );
1267 SpeedControlWidget::~SpeedControlWidget()
1270 void SpeedControlWidget::setEnable( bool b_enable )
1272 speedSlider->setEnabled( b_enable );
1275 void SpeedControlWidget::updateControls( int rate )
1277 if( speedSlider->isSliderDown() )
1279 //We don't want to change anything if the user is using the slider
1283 double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
1284 int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
1286 if( sliderValue < speedSlider->minimum() )
1288 sliderValue = speedSlider->minimum();
1290 else if( sliderValue > speedSlider->maximum() )
1292 sliderValue = speedSlider->maximum();
1295 //Block signals to avoid feedback loop
1296 speedSlider->blockSignals( true );
1297 speedSlider->setValue( sliderValue );
1298 speedSlider->blockSignals( false );
1301 void SpeedControlWidget::updateRate( int sliderValue )
1303 double speed = pow( 2, (double)sliderValue / 12 );
1304 int rate = INPUT_RATE_DEFAULT / speed;
1306 THEMIM->getIM()->setRate(rate);
1309 void SpeedControlWidget::resetRate()
1311 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);