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>
57 /**********************************************************************
58 * Video Widget. A simple frame on which video is drawn
59 * This class handles resize issues
60 **********************************************************************/
62 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
66 hide(); setMinimumSize( 16, 16 );
67 videoSize.rwidth() = -1;
68 videoSize.rheight() = -1;
69 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
71 /* Black background is more coherent for a Video Widget IMVHO */
72 QPalette plt = palette();
73 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
74 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
76 setAttribute( Qt::WA_PaintOnScreen, true );
78 /* The core can ask through a callback to show the video. */
80 connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
81 this, SLOT(SetSizing(unsigned int, unsigned int )),
82 Qt::BlockingQueuedConnection );
84 #error This is broken. Fix it with a QEventLoop with a processEvents ()
85 connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
86 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()
211 void BackgroundWidget::resizeEvent( QResizeEvent * event )
213 if( event->size().height() <= MIN_BG_SIZE )
219 void BackgroundWidget::updateArt( QString url )
223 if( QDate::currentDate().dayOfYear() >= 354 )
224 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
226 label->setPixmap( QPixmap( ":/vlc128.png" ) );
231 label->setPixmap( QPixmap( url ) );
235 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
237 QVLCMenu::PopupMenu( p_intf, true );
240 /**********************************************************************
241 * Visualization selector panel
242 **********************************************************************/
243 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
244 QFrame( NULL ), p_intf( _p_i )
246 QHBoxLayout *layout = new QHBoxLayout( this );
247 layout->setMargin( 0 );
248 QPushButton *prevButton = new QPushButton( "Prev" );
249 QPushButton *nextButton = new QPushButton( "Next" );
250 layout->addWidget( prevButton );
251 layout->addWidget( nextButton );
253 layout->addItem( new QSpacerItem( 40,20,
254 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
255 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
257 current = new QLabel( qtr( "None" ) );
258 layout->addWidget( current );
260 BUTTONACT( prevButton, prev() );
261 BUTTONACT( nextButton, next() );
264 setMaximumHeight( 35 );
267 VisualSelector::~VisualSelector()
271 void VisualSelector::prev()
273 char *psz_new = aout_VisualPrev( p_intf );
276 current->setText( qfu( psz_new ) );
281 void VisualSelector::next()
283 char *psz_new = aout_VisualNext( p_intf );
286 current->setText( qfu( psz_new ) );
291 /**********************************************************************
293 **********************************************************************/
295 #define setupSmallButton( aButton ){ \
296 aButton->setMaximumSize( QSize( 26, 26 ) ); \
297 aButton->setMinimumSize( QSize( 26, 26 ) ); \
298 aButton->setIconSize( QSize( 20, 20 ) ); }
300 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
301 QFrame( NULL ), p_intf( _p_i )
303 QHBoxLayout *advLayout = new QHBoxLayout( this );
304 advLayout->setMargin( 0 );
305 advLayout->setSpacing( 0 );
306 advLayout->setAlignment( Qt::AlignBottom );
309 ABButton = new QPushButton( "AB" );
310 setupSmallButton( ABButton );
311 advLayout->addWidget( ABButton );
312 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
314 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
315 this, AtoBLoop( float, int, int ) );
317 frameButton = new QPushButton( "Fr" );
318 frameButton->setMaximumSize( QSize( 26, 26 ) );
319 frameButton->setIconSize( QSize( 20, 20 ) );
320 advLayout->addWidget( frameButton );
321 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
324 recordButton = new QPushButton( "R" );
325 setupSmallButton( recordButton );
326 advLayout->addWidget( recordButton );
327 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
328 qtr( "Record" ), record() );
330 /* Snapshot Button */
331 snapshotButton = new QPushButton( "S" );
332 setupSmallButton( snapshotButton );
333 advLayout->addWidget( snapshotButton );
334 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
337 AdvControlsWidget::~AdvControlsWidget()
340 void AdvControlsWidget::enableInput( bool enable )
342 ABButton->setEnabled( enable );
343 recordButton->setEnabled( enable );
346 void AdvControlsWidget::enableVideo( bool enable )
348 snapshotButton->setEnabled( enable );
350 frameButton->setEnabled( enable );
354 void AdvControlsWidget::snapshot()
356 vout_thread_t *p_vout =
357 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
358 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
361 /* Function called when the button is clicked() */
362 void AdvControlsWidget::fromAtoB()
366 timeA = var_GetTime( THEMIM->getInput(), "time" );
367 ABButton->setText( "A->..." );
372 timeB = var_GetTime( THEMIM->getInput(), "time" );
373 var_SetTime( THEMIM->getInput(), "time" , timeA );
374 ABButton->setText( "A<=>B" );
379 ABButton->setText( "AB" );
382 /* Function called regularly when in an AtoB loop */
383 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
387 if( i_time >= (int)(timeB/1000000) )
388 var_SetTime( THEMIM->getInput(), "time" , timeA );
392 /* FIXME Record function */
393 void AdvControlsWidget::record(){}
396 //FIXME Frame by frame function
397 void AdvControlsWidget::frame(){}
400 /*****************************
401 * DA Control Widget !
402 *****************************/
403 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
404 MainInterface *_p_mi,
408 QFrame( _p_mi ), p_intf( _p_i )
410 controlLayout = new QGridLayout( );
412 controlLayout->setSpacing( 0 );
413 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
416 setLayout( controlLayout );
418 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
420 /** The main Slider **/
421 slider = new InputSlider( Qt::Horizontal, NULL );
422 controlLayout->addWidget( slider, 0, 1, 1, 16 );
423 /* Update the position when the IM has changed */
424 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
425 slider, setPosition( float, int, int ) );
426 /* And update the IM, when the position has changed */
427 CONNECT( slider, sliderDragged( float ),
428 THEMIM->getIM(), sliderUpdate( float ) );
430 /** Slower and faster Buttons **/
431 slowerButton = new QToolButton;
432 slowerButton->setAutoRaise( true );
433 slowerButton->setMaximumSize( QSize( 26, 20 ) );
435 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
436 controlLayout->addWidget( slowerButton, 0, 0 );
438 fasterButton = new QToolButton;
439 fasterButton->setAutoRaise( true );
440 fasterButton->setMaximumSize( QSize( 26, 20 ) );
442 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
443 controlLayout->addWidget( fasterButton, 0, 17 );
445 /* advanced Controls handling */
446 b_advancedVisible = b_advControls;
448 advControls = new AdvControlsWidget( p_intf );
449 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
450 if( !b_advancedVisible ) advControls->hide();
452 /** Disc and Menus handling */
453 discFrame = new QWidget( this );
455 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
456 discLayout->setSpacing( 0 );
457 discLayout->setMargin( 0 );
459 prevSectionButton = new QPushButton( discFrame );
460 setupSmallButton( prevSectionButton );
461 discLayout->addWidget( prevSectionButton );
463 menuButton = new QPushButton( discFrame );
464 setupSmallButton( menuButton );
465 discLayout->addWidget( menuButton );
467 nextSectionButton = new QPushButton( discFrame );
468 setupSmallButton( nextSectionButton );
469 discLayout->addWidget( nextSectionButton );
471 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
473 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
474 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
475 BUTTON_SET_IMG( menuButton, "", previous.png, qtr( "Menu" ) );
479 /* Change the navigation button display when the IM navigation changes */
480 CONNECT( THEMIM->getIM(), navigationChanged( int ),
481 this, setNavigation( int ) );
482 /* Changes the IM navigation when triggered on the nav buttons */
483 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
485 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
487 CONNECT( menuButton, clicked(), THEMIM->getIM(),
492 * TODO: Merge with upper menu in a StackLayout
494 telexFrame = new QWidget( this );
495 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
496 telexLayout->setSpacing( 0 );
497 telexLayout->setMargin( 0 );
499 telexOn = new QPushButton;
500 setupSmallButton( telexOn );
501 telexLayout->addWidget( telexOn );
503 telexTransparent = new QPushButton;
504 setupSmallButton( telexTransparent );
505 telexLayout->addWidget( telexTransparent );
506 b_telexTransparent = false;
508 telexPage = new QSpinBox;
509 telexPage->setRange( 0, 999 );
510 telexPage->setValue( 100 );
511 telexPage->setAccelerated( true );
512 telexPage->setWrapping( true );
513 telexPage->setAlignment( Qt::AlignRight );
514 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
515 telexLayout->addWidget( telexPage );
518 controlLayout->addWidget( telexFrame, 1, 10, 2, 4, Qt::AlignBottom );
519 telexFrame->hide(); /* default hidden */
521 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
522 telexGotoPage( int ) );
523 CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
524 telexPage, setValue( int ) );
526 BUTTON_SET_IMG( telexOn, "", tv.png, qtr( "Teletext on" ) );
528 CONNECT( telexOn, clicked(), THEMIM->getIM(),
529 telexToggleButtons() );
530 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
531 telexToggle( bool ) );
532 CONNECT( THEMIM->getIM(), toggleTelexButtons(),
533 this, toggleTeletext() );
534 b_telexEnabled = false;
535 telexTransparent->setEnabled( false );
536 telexPage->setEnabled( false );
538 BUTTON_SET_IMG( telexTransparent, "", tvtelx.png, qtr( "Teletext" ) );
539 CONNECT( telexTransparent, clicked( bool ),
540 THEMIM->getIM(), telexSetTransparency() );
541 CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
542 this, toggleTeletextTransparency() );
543 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
544 telexFrame, setVisible( bool ) );
547 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
548 sizePolicy.setHorizontalStretch( 0 );
549 sizePolicy.setVerticalStretch( 0 );
552 playButton = new QPushButton;
553 playButton->setSizePolicy( sizePolicy );
554 playButton->setMaximumSize( QSize( 36, 36 ) );
555 playButton->setMinimumSize( QSize( 36, 36 ) );
556 playButton->setIconSize( QSize( 30, 30 ) );
558 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
560 controlLayout->setColumnMinimumWidth( 2, 20 );
561 controlLayout->setColumnStretch( 2, 0 );
563 /** Prev + Stop + Next Block **/
564 controlButLayout = new QHBoxLayout;
565 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
568 QPushButton *prevButton = new QPushButton;
569 prevButton->setSizePolicy( sizePolicy );
570 setupSmallButton( prevButton );
572 controlButLayout->addWidget( prevButton );
575 QPushButton *stopButton = new QPushButton;
576 stopButton->setSizePolicy( sizePolicy );
577 setupSmallButton( stopButton );
579 controlButLayout->addWidget( stopButton );
582 QPushButton *nextButton = new QPushButton;
583 nextButton->setSizePolicy( sizePolicy );
584 setupSmallButton( nextButton );
586 controlButLayout->addWidget( nextButton );
588 /* Add this block to the main layout */
590 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
592 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
593 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
594 qtr( "Previous" ), prev() );
595 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
596 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
598 controlLayout->setColumnMinimumWidth( 7, 20 );
599 controlLayout->setColumnStretch( 7, 0 );
600 controlLayout->setColumnStretch( 8, 0 );
601 controlLayout->setColumnStretch( 9, 0 );
604 * Other first Line buttons
606 /** Fullscreen/Visualisation **/
607 fullscreenButton = new QPushButton( "F" );
608 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
609 setupSmallButton( fullscreenButton );
610 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
612 /** Playlist Button **/
613 playlistButton = new QPushButton;
614 setupSmallButton( playlistButton );
615 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
616 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
617 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
619 /** extended Settings **/
620 extSettingsButton = new QPushButton;
621 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
623 setupSmallButton( extSettingsButton );
624 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
626 controlLayout->setColumnStretch( 13, 0 );
627 controlLayout->setColumnMinimumWidth( 13, 24 );
628 controlLayout->setColumnStretch( 14, 5 );
631 hVolLabel = new VolumeClickHandler( p_intf, this );
633 volMuteLabel = new QLabel;
634 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
635 volMuteLabel->setToolTip( qtr( "Mute" ) );
636 volMuteLabel->installEventFilter( hVolLabel );
637 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
641 volumeSlider = new SoundSlider( this,
642 config_GetInt( p_intf, "volume-step" ),
643 config_GetInt( p_intf, "qt-volume-complete" ),
644 config_GetPsz( p_intf, "qt-slider-colours" ) );
648 volumeSlider = new QSlider( this );
649 volumeSlider->setOrientation( Qt::Horizontal );
651 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
652 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
653 volumeSlider->setFocusPolicy( Qt::NoFocus );
654 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
656 /* Set the volume from the config */
657 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
658 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
660 /* Force the update at build time in order to have a muted icon if needed */
661 updateVolume( volumeSlider->value() );
663 /* Volume control connection */
664 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
665 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
670 ControlsWidget::~ControlsWidget()
673 void ControlsWidget::toggleTeletext()
675 bool b_enabled = THEMIM->teletextState();
678 telexTransparent->setEnabled( false );
679 telexPage->setEnabled( false );
680 b_telexEnabled = false;
684 telexTransparent->setEnabled( true );
685 telexPage->setEnabled( true );
686 b_telexEnabled = true;
690 void ControlsWidget::toggleTeletextTransparency()
692 if( b_telexTransparent )
694 telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx.png" ) );
695 telexTransparent->setToolTip( qtr( "Teletext" ) );
696 b_telexTransparent = false;
700 telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx-transparent.png" ) );
701 telexTransparent->setToolTip( qtr( "Transparent" ) );
702 b_telexTransparent = true;
706 void ControlsWidget::stop()
711 void ControlsWidget::play()
713 if( THEPL->current.i_size == 0 )
715 /* The playlist is empty, open a file requester */
716 THEDP->openFileDialog();
720 THEMIM->togglePlayPause();
723 void ControlsWidget::prev()
728 void ControlsWidget::next()
733 void ControlsWidget::setNavigation( int navigation )
735 #define HELP_PCH N_( "Previous chapter" )
736 #define HELP_NCH N_( "Next chapter" )
738 // 1 = chapter, 2 = title, 0 = no
739 if( navigation == 0 )
742 } else if( navigation == 1 ) {
743 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
744 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
748 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
749 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
755 static bool b_my_volume;
756 void ControlsWidget::updateVolume( int i_sliderVolume )
760 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
761 aout_VolumeSet( p_intf, i_res );
763 if( i_sliderVolume == 0 )
764 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
765 else if( i_sliderVolume < VOLUME_MAX / 3 )
766 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
767 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
768 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
769 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
772 void ControlsWidget::updateVolume()
775 audio_volume_t i_volume;
776 aout_VolumeGet( p_intf, &i_volume );
777 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
778 int i_gauge = volumeSlider->value();
780 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
783 volumeSlider->setValue( i_volume );
788 void ControlsWidget::updateInput()
790 /* Activate the interface buttons according to the presence of the input */
791 enableInput( THEMIM->getIM()->hasInput() );
792 enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
795 void ControlsWidget::setStatus( int status )
797 if( status == PLAYING_S ) /* Playing */
799 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
800 playButton->setToolTip( qtr( "Pause" ) );
804 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
805 playButton->setToolTip( qtr( "Play" ) );
811 * This functions toggle the fullscreen mode
812 * If there is no video, it should first activate Visualisations...
813 * This has also to be fixed in enableVideo()
815 void ControlsWidget::fullscreen()
817 vout_thread_t *p_vout =
818 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
821 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
822 vlc_object_release( p_vout );
826 void ControlsWidget::extSettings()
828 THEDP->extendedDialog();
831 void ControlsWidget::slower()
833 THEMIM->getIM()->slower();
836 void ControlsWidget::faster()
838 THEMIM->getIM()->faster();
841 void ControlsWidget::enableInput( bool enable )
843 slowerButton->setEnabled( enable );
844 slider->setEnabled( enable );
845 fasterButton->setEnabled( enable );
847 /* Advanced Buttons too */
848 advControls->enableInput( enable );
851 void ControlsWidget::enableVideo( bool enable )
853 // TODO Later make the fullscreenButton toggle Visualisation and so on.
854 fullscreenButton->setEnabled( enable );
856 /* Advanced Buttons too */
857 advControls->enableVideo( enable );
860 void ControlsWidget::toggleAdvanced()
862 if( !VISIBLE( advControls ) )
865 b_advancedVisible = true;
870 b_advancedVisible = false;
872 emit advancedControlsToggled( b_advancedVisible );
876 /**********************************************************************
877 * Fullscrenn control widget
878 **********************************************************************/
879 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
880 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
881 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
882 i_lastPosX( -1 ), i_lastPosY( -1 ), i_hideTimeout( 1 ),
883 b_mouseIsOver( false ), b_isFullscreen( false )
885 setWindowFlags( Qt::ToolTip );
887 setFrameShape( QFrame::StyledPanel );
888 setFrameStyle( QFrame::Sunken );
889 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
891 QGridLayout *fsLayout = new QGridLayout( this );
892 controlLayout->setSpacing( 0 );
893 controlLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
895 fsLayout->addWidget( slowerButton, 0, 0 );
896 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
897 fsLayout->addWidget( slider, 0, 1, 1, 6 );
898 fsLayout->addWidget( fasterButton, 0, 7 );
900 fsLayout->addWidget( volMuteLabel, 1, 0);
901 fsLayout->addWidget( volumeSlider, 1, 1 );
903 fsLayout->addLayout( controlButLayout, 1, 2 );
905 fsLayout->addWidget( playButton, 1, 3 );
907 fsLayout->addWidget( discFrame, 1, 4 );
909 fsLayout->addWidget( telexFrame, 1, 5 );
911 fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
913 fsLayout->addWidget( fullscreenButton, 1, 7 );
916 p_hideTimer = new QTimer( this );
917 CONNECT( p_hideTimer, timeout(), this, hideFSControllerWidget() );
918 p_hideTimer->setSingleShot( true );
920 /* slow hiding timer */
921 #if HAVE_TRANSPARENCY
922 p_slowHideTimer = new QTimer( this );
923 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
926 adjustSize (); /* need to get real width and height for moving */
929 QDesktopWidget * p_desktop = QApplication::desktop();
931 move( p_desktop->width() / 2 - width() / 2,
932 p_desktop->height() - height() );
935 setWindowOpacity( 0.0 );
941 FullscreenControllerWidget::~FullscreenControllerWidget()
946 * Hide fullscreen controller
947 * FIXME: under windows it have to be done by moving out of screen
948 * because hide() doesnt work
950 void FullscreenControllerWidget::hideFSControllerWidget()
954 setWindowOpacity( 0.0 ); // simulate hidding
961 * Hidding fullscreen controller slowly
962 * Linux: need composite manager
963 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
965 void FullscreenControllerWidget::slowHideFSC()
967 #if HAVE_TRANSPARENCY
968 static bool first_call = true;
974 p_slowHideTimer->stop();
975 /* the last part of time divided to 100 pieces */
976 p_slowHideTimer->start(
977 (int) ( i_hideTimeout / 2 / ( windowOpacity() * 100 ) ) );
982 if ( windowOpacity() > 0.0 && !fscHidden )
984 if ( windowOpacity() > 0.0 )
987 /* we should use 0.01 because of 100 pieces ^^^
988 but than it cannt be done in time */
989 setWindowOpacity( windowOpacity() - 0.02 );
992 if ( windowOpacity() == 0.0 )
995 p_slowHideTimer->stop();
1002 * Get state of visibility of FS controller on screen
1003 * On windows control if it is on hidden position
1005 bool FullscreenControllerWidget::isFSCHidden()
1016 * events: show, hide, start timer for hidding
1018 void FullscreenControllerWidget::customEvent( QEvent *event )
1020 int type = event->type();
1022 if ( type == FullscreenControlShow_Type && b_isFullscreen )
1025 // after quiting and going to fs, we need to call show()
1032 setWindowOpacity( 1.0 );
1038 #if HAVE_TRANSPARENCY
1039 setWindowOpacity( DEFAULT_OPACITY );
1042 else if ( type == FullscreenControlHide_Type )
1044 hideFSControllerWidget();
1046 else if ( type == FullscreenControlPlanHide_Type && !b_mouseIsOver )
1048 p_hideTimer->start( i_hideTimeout );
1049 #if HAVE_TRANSPARENCY
1050 p_slowHideTimer->start( i_hideTimeout / 2 );
1059 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1061 if ( event->buttons() == Qt::LeftButton )
1063 int i_moveX = event->globalX() - i_lastPosX;
1064 int i_moveY = event->globalY() - i_lastPosY;
1066 move( x() + i_moveX, y() + i_moveY );
1068 i_lastPosX = event->globalX();
1069 i_lastPosY = event->globalY();
1075 * store position of cursor
1077 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1079 i_lastPosX = event->globalX();
1080 i_lastPosY = event->globalY();
1084 * On mouse go above FSC
1086 void FullscreenControllerWidget::enterEvent( QEvent *event )
1088 p_hideTimer->stop();
1089 #if HAVE_TRANSPARENCY
1090 p_slowHideTimer->stop();
1092 b_mouseIsOver = true;
1096 * On mouse go out from FSC
1098 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1100 p_hideTimer->start( i_hideTimeout );
1101 #if HAVE_TRANSPARENCY
1102 p_slowHideTimer->start( i_hideTimeout / 2 );
1104 b_mouseIsOver = false;
1108 * When you get pressed key, send it to video output
1109 * FIXME: clearing focus by clearFocus() to not getting
1110 * key press events didnt work
1112 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1114 int i_vlck = qtEventToVLCKey( event );
1117 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1125 * It is called when video start
1127 void FullscreenControllerWidget::regFullscreenCallback( vout_thread_t *p_vout )
1131 var_AddCallback( p_vout, "fullscreen", regMouseMoveCallback, this );
1136 * It is called after turn off video, because p_vout is NULL now
1137 * we cannt delete callback, just hide if FScontroller is visible
1139 void FullscreenControllerWidget::unregFullscreenCallback()
1146 * Register and unregister callback for mouse moving
1148 static int regMouseMoveCallback( 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;
1154 static bool b_registered = false;
1155 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1157 if ( var_GetBool( p_vout, "fullscreen" ) && !b_registered )
1159 p_fs->setHideTimeout( var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1160 p_fs->setIsFullscreen( true );
1161 var_AddCallback( p_vout, "mouse-moved",
1162 showFullscreenControllCallback, (void *) p_fs );
1163 b_registered = true;
1166 if ( !var_GetBool( p_vout, "fullscreen" ) && b_registered )
1168 p_fs->setIsFullscreen( false );
1170 var_DelCallback( p_vout, "mouse-moved",
1171 showFullscreenControllCallback, (void *) p_fs );
1172 b_registered = false;
1179 * Show fullscreen controller after mouse move
1180 * after show immediately plan hide event
1182 static int showFullscreenControllCallback( vlc_object_t *vlc_object, const char *variable,
1183 vlc_value_t old_val, vlc_value_t new_val,
1186 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1188 if ( p_fs->isFSCHidden() || p_fs->windowOpacity() < DEFAULT_OPACITY )
1190 IMEvent *event = new IMEvent( FullscreenControlShow_Type, 0 );
1191 QApplication::postEvent( p_fs, static_cast<QEvent *>(event) );
1194 IMEvent *e = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1195 QApplication::postEvent( p_fs, static_cast<QEvent *>(e) );
1200 /**********************************************************************
1201 * Speed control widget
1202 **********************************************************************/
1203 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1204 QFrame( NULL ), p_intf( _p_i )
1206 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1207 sizePolicy.setHorizontalStretch( 0 );
1208 sizePolicy.setVerticalStretch( 0 );
1210 speedSlider = new QSlider;
1211 speedSlider->setSizePolicy( sizePolicy );
1212 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1213 speedSlider->setOrientation( Qt::Vertical );
1214 speedSlider->setTickPosition( QSlider::TicksRight );
1216 speedSlider->setRange( -24, 24 );
1217 speedSlider->setSingleStep( 1 );
1218 speedSlider->setPageStep( 1 );
1219 speedSlider->setTickInterval( 12 );
1221 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1223 QToolButton *normalSpeedButton = new QToolButton( this );
1224 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1225 normalSpeedButton->setAutoRaise( true );
1226 normalSpeedButton->setText( "1x" );
1227 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1229 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1231 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1232 speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
1233 speedControlLayout->setSpacing( 4 );
1234 speedControlLayout->addWidget( speedSlider );
1235 speedControlLayout->addWidget( normalSpeedButton );
1236 setLayout( speedControlLayout );
1239 SpeedControlWidget::~SpeedControlWidget()
1242 void SpeedControlWidget::setEnable( bool b_enable )
1244 speedSlider->setEnabled( b_enable );
1247 void SpeedControlWidget::updateControls( int rate )
1249 if( speedSlider->isSliderDown() )
1251 //We don't want to change anything if the user is using the slider
1255 double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
1256 int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
1258 if( sliderValue < speedSlider->minimum() )
1260 sliderValue = speedSlider->minimum();
1262 else if( sliderValue > speedSlider->maximum() )
1264 sliderValue = speedSlider->maximum();
1267 //Block signals to avoid feedback loop
1268 speedSlider->blockSignals( true );
1269 speedSlider->setValue( sliderValue );
1270 speedSlider->blockSignals( false );
1273 void SpeedControlWidget::updateRate( int sliderValue )
1275 double speed = pow( 2, (double)sliderValue / 12 );
1276 int rate = INPUT_RATE_DEFAULT / speed;
1278 THEMIM->getIM()->setRate(rate);
1281 void SpeedControlWidget::resetRate()
1283 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);