1 /*****************************************************************************
2 * interface_widgets.cpp : Custom widgets for the main interface
3 ****************************************************************************
4 * Copyright ( C ) 2006 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Jean-Baptiste Kempf <jb@videolan.org>
9 * Rafaël Carré <funman@videolanorg>
10 * Ilkka Ollakka <ileoo@videolan.org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * ( at your option ) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
31 #include "dialogs_provider.hpp"
32 #include "components/interface_widgets.hpp"
33 #include "main_interface.hpp"
34 #include "input_manager.hpp"
36 #include "util/input_slider.hpp"
37 #include "util/customwidgets.hpp"
41 #include <QSpacerItem>
43 #include <QPushButton>
44 #include <QToolButton>
45 #include <QHBoxLayout>
48 #include <QResizeEvent>
51 # include <X11/Xlib.h>
52 # include <qx11info_x11.h>
55 /**********************************************************************
56 * Video Widget. A simple frame on which video is drawn
57 * This class handles resize issues
58 **********************************************************************/
60 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
63 vlc_mutex_init( &lock );
65 hide(); setMinimumSize( 16, 16 );
66 videoSize.rwidth() = -1;
67 videoSize.rheight() = -1;
68 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
70 /* Black background is more coherent for a Video Widget IMVHO */
71 QPalette plt = palette();
72 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
73 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
75 setAttribute( Qt::WA_PaintOnScreen, true );
77 /* The core can ask through a callback to show the video. */
78 connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
79 this, SLOT(SetSizing(unsigned int, unsigned int )),
80 Qt::BlockingQueuedConnection );
83 void VideoWidget::paintEvent(QPaintEvent *ev)
85 QFrame::paintEvent(ev);
87 XFlush( QX11Info::display() );
91 VideoWidget::~VideoWidget()
93 vlc_mutex_lock( &lock );
96 if( !p_intf->psz_switch_intf )
98 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
99 vout_Control( p_vout, VOUT_REPARENT );
103 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
104 vout_Control( p_vout, VOUT_CLOSE );
107 vlc_mutex_unlock( &lock );
108 vlc_mutex_destroy( &lock );
112 * Request the video to avoid the conflicts
114 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
115 unsigned int *pi_width, unsigned int *pi_height )
117 msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
118 emit askVideoWidgetToShow( *pi_width, *pi_height );
121 msg_Dbg( p_intf, "embedded video already in use" );
125 msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );
126 return ( void* )winId();
129 /* Set the Widget to the correct Size */
130 /* Function has to be called by the parent
131 Parent has to care about resizing himself*/
132 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
134 msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
135 videoSize.rwidth() = w;
136 videoSize.rheight() = h;
137 if( isHidden() ) show();
138 updateGeometry(); // Needed for deinterlace
141 void VideoWidget::release( void *p_win )
143 msg_Dbg( p_intf, "Video is non needed anymore" );
145 videoSize.rwidth() = 0;
146 videoSize.rheight() = 0;
148 updateGeometry(); // Needed for deinterlace
151 QSize VideoWidget::sizeHint() const
156 /**********************************************************************
157 * Background Widget. Show a simple image background. Currently,
158 * it's album art if present or cone.
159 **********************************************************************/
160 #define ICON_SIZE 128
161 #define MAX_BG_SIZE 400
162 #define MIN_BG_SIZE 64
164 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i )
165 :QWidget( NULL ), p_intf( _p_i )
167 /* We should use that one to take the more size it can */
168 // setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
170 /* A dark background */
171 setAutoFillBackground( true );
173 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
174 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
177 /* A cone in the middle */
179 label->setMargin( 5 );
180 label->setMaximumHeight( MAX_BG_SIZE );
181 label->setMaximumWidth( MAX_BG_SIZE );
182 label->setMinimumHeight( MIN_BG_SIZE );
183 label->setMinimumWidth( MIN_BG_SIZE );
184 if( QDate::currentDate().dayOfYear() >= 354 )
185 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
187 label->setPixmap( QPixmap( ":/vlc128.png" ) );
189 QGridLayout *backgroundLayout = new QGridLayout( this );
190 backgroundLayout->addWidget( label, 0, 1 );
191 backgroundLayout->setColumnStretch( 0, 1 );
192 backgroundLayout->setColumnStretch( 2, 1 );
194 CONNECT( THEMIM->getIM(), artChanged( QString ), this, updateArt( QString ) );
197 BackgroundWidget::~BackgroundWidget()
201 void BackgroundWidget::resizeEvent( QResizeEvent * event )
203 if( event->size().height() <= MIN_BG_SIZE )
209 void BackgroundWidget::updateArt( QString url )
213 if( QDate::currentDate().dayOfYear() >= 354 )
214 label->setPixmap( QPixmap( ":/vlc128-christmas.png" ) );
216 label->setPixmap( QPixmap( ":/vlc128.png" ) );
221 label->setPixmap( QPixmap( url ) );
225 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
227 QVLCMenu::PopupMenu( p_intf, true );
230 /**********************************************************************
231 * Visualization selector panel
232 **********************************************************************/
233 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
234 QFrame( NULL ), p_intf( _p_i )
236 QHBoxLayout *layout = new QHBoxLayout( this );
237 layout->setMargin( 0 );
238 QPushButton *prevButton = new QPushButton( "Prev" );
239 QPushButton *nextButton = new QPushButton( "Next" );
240 layout->addWidget( prevButton );
241 layout->addWidget( nextButton );
243 layout->addItem( new QSpacerItem( 40,20,
244 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
245 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
247 current = new QLabel( qtr( "None" ) );
248 layout->addWidget( current );
250 BUTTONACT( prevButton, prev() );
251 BUTTONACT( nextButton, next() );
254 setMaximumHeight( 35 );
257 VisualSelector::~VisualSelector()
261 void VisualSelector::prev()
263 char *psz_new = aout_VisualPrev( p_intf );
266 current->setText( qfu( psz_new ) );
271 void VisualSelector::next()
273 char *psz_new = aout_VisualNext( p_intf );
276 current->setText( qfu( psz_new ) );
281 /**********************************************************************
283 **********************************************************************/
285 #define setupSmallButton( aButton ){ \
286 aButton->setMaximumSize( QSize( 26, 26 ) ); \
287 aButton->setMinimumSize( QSize( 26, 26 ) ); \
288 aButton->setIconSize( QSize( 20, 20 ) ); }
290 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
291 QFrame( NULL ), p_intf( _p_i )
293 QHBoxLayout *advLayout = new QHBoxLayout( this );
294 advLayout->setMargin( 0 );
295 advLayout->setSpacing( 0 );
296 advLayout->setAlignment( Qt::AlignBottom );
299 ABButton = new QPushButton( "AB" );
300 setupSmallButton( ABButton );
301 advLayout->addWidget( ABButton );
302 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
304 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
305 this, AtoBLoop( float, int, int ) );
307 frameButton = new QPushButton( "Fr" );
308 frameButton->setMaximumSize( QSize( 26, 26 ) );
309 frameButton->setIconSize( QSize( 20, 20 ) );
310 advLayout->addWidget( frameButton );
311 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
314 recordButton = new QPushButton( "R" );
315 setupSmallButton( recordButton );
316 advLayout->addWidget( recordButton );
317 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
318 qtr( "Record" ), record() );
320 /* Snapshot Button */
321 snapshotButton = new QPushButton( "S" );
322 setupSmallButton( snapshotButton );
323 advLayout->addWidget( snapshotButton );
324 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
327 AdvControlsWidget::~AdvControlsWidget()
330 void AdvControlsWidget::enableInput( bool enable )
332 ABButton->setEnabled( enable );
333 recordButton->setEnabled( enable );
336 void AdvControlsWidget::enableVideo( bool enable )
338 snapshotButton->setEnabled( enable );
340 frameButton->setEnabled( enable );
344 void AdvControlsWidget::snapshot()
346 vout_thread_t *p_vout =
347 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
348 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
351 /* Function called when the button is clicked() */
352 void AdvControlsWidget::fromAtoB()
356 timeA = var_GetTime( THEMIM->getInput(), "time" );
357 ABButton->setText( "A->..." );
362 timeB = var_GetTime( THEMIM->getInput(), "time" );
363 var_SetTime( THEMIM->getInput(), "time" , timeA );
364 ABButton->setText( "A<=>B" );
369 ABButton->setText( "AB" );
372 /* Function called regularly when in an AtoB loop */
373 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
377 if( i_time >= (int)(timeB/1000000) )
378 var_SetTime( THEMIM->getInput(), "time" , timeA );
382 /* FIXME Record function */
383 void AdvControlsWidget::record(){}
386 //FIXME Frame by frame function
387 void AdvControlsWidget::frame(){}
390 /*****************************
391 * DA Control Widget !
392 *****************************/
393 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
394 MainInterface *_p_mi,
398 QFrame( _p_mi ), p_intf( _p_i )
400 controlLayout = new QGridLayout( );
402 controlLayout->setSpacing( 0 );
403 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
406 setLayout( controlLayout );
408 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
410 /** The main Slider **/
411 slider = new InputSlider( Qt::Horizontal, NULL );
412 controlLayout->addWidget( slider, 0, 1, 1, 16 );
413 /* Update the position when the IM has changed */
414 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
415 slider, setPosition( float, int, int ) );
416 /* And update the IM, when the position has changed */
417 CONNECT( slider, sliderDragged( float ),
418 THEMIM->getIM(), sliderUpdate( float ) );
420 /** Slower and faster Buttons **/
421 slowerButton = new QToolButton;
422 slowerButton->setAutoRaise( true );
423 slowerButton->setMaximumSize( QSize( 26, 20 ) );
425 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
426 controlLayout->addWidget( slowerButton, 0, 0 );
428 fasterButton = new QToolButton;
429 fasterButton->setAutoRaise( true );
430 fasterButton->setMaximumSize( QSize( 26, 20 ) );
432 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
433 controlLayout->addWidget( fasterButton, 0, 17 );
435 /* advanced Controls handling */
436 b_advancedVisible = b_advControls;
438 advControls = new AdvControlsWidget( p_intf );
439 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
440 if( !b_advancedVisible ) advControls->hide();
442 /** Disc and Menus handling */
443 discFrame = new QWidget( this );
445 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
446 discLayout->setSpacing( 0 );
447 discLayout->setMargin( 0 );
449 prevSectionButton = new QPushButton( discFrame );
450 setupSmallButton( prevSectionButton );
451 discLayout->addWidget( prevSectionButton );
453 menuButton = new QPushButton( discFrame );
454 setupSmallButton( menuButton );
455 discLayout->addWidget( menuButton );
457 nextSectionButton = new QPushButton( discFrame );
458 setupSmallButton( nextSectionButton );
459 discLayout->addWidget( nextSectionButton );
461 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
463 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
464 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
465 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
469 /* Change the navigation button display when the IM navigation changes */
470 CONNECT( THEMIM->getIM(), navigationChanged( int ),
471 this, setNavigation( int ) );
472 /* Changes the IM navigation when triggered on the nav buttons */
473 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
475 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
477 CONNECT( menuButton, clicked(), THEMIM->getIM(),
482 * TODO: Merge with upper menu in a StackLayout
484 telexFrame = new QWidget( this );
485 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
486 telexLayout->setSpacing( 0 );
487 telexLayout->setMargin( 0 );
489 telexOn = new QPushButton;
490 setupSmallButton( telexOn );
491 telexLayout->addWidget( telexOn );
493 telexTransparent = new QPushButton;
494 setupSmallButton( telexTransparent );
495 telexLayout->addWidget( telexTransparent );
496 b_telexTransparent = false;
498 telexPage = new QSpinBox;
499 telexPage->setRange( 0, 999 );
500 telexPage->setValue( 100 );
501 telexPage->setAccelerated( true );
502 telexPage->setWrapping( true );
503 telexPage->setAlignment( Qt::AlignRight );
504 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
505 telexLayout->addWidget( telexPage );
508 controlLayout->addWidget( telexFrame, 1, 10, 2, 4, Qt::AlignBottom );
509 telexFrame->hide(); /* default hidden */
511 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
512 telexGotoPage( int ) );
513 CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
514 telexPage, setValue( int ) );
516 BUTTON_SET_IMG( telexOn, "", tv.png, qtr( "Teletext on" ) );
518 CONNECT( telexOn, clicked(), THEMIM->getIM(),
519 telexToggleButtons() );
520 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
521 telexToggle( bool ) );
522 CONNECT( THEMIM->getIM(), toggleTelexButtons(),
523 this, toggleTeletext() );
524 b_telexEnabled = false;
525 telexTransparent->setEnabled( false );
526 telexPage->setEnabled( false );
528 BUTTON_SET_IMG( telexTransparent, "", tvtelx.png, qtr( "Teletext" ) );
529 CONNECT( telexTransparent, clicked( bool ),
530 THEMIM->getIM(), telexSetTransparency() );
531 CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
532 this, toggleTeletextTransparency() );
533 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
534 telexFrame, setVisible( bool ) );
537 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
538 sizePolicy.setHorizontalStretch( 0 );
539 sizePolicy.setVerticalStretch( 0 );
542 playButton = new QPushButton;
543 playButton->setSizePolicy( sizePolicy );
544 playButton->setMaximumSize( QSize( 36, 36 ) );
545 playButton->setMinimumSize( QSize( 36, 36 ) );
546 playButton->setIconSize( QSize( 30, 30 ) );
548 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
550 controlLayout->setColumnMinimumWidth( 2, 20 );
551 controlLayout->setColumnStretch( 2, 0 );
553 /** Prev + Stop + Next Block **/
554 controlButLayout = new QHBoxLayout;
555 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
558 QPushButton *prevButton = new QPushButton;
559 prevButton->setSizePolicy( sizePolicy );
560 setupSmallButton( prevButton );
562 controlButLayout->addWidget( prevButton );
565 QPushButton *stopButton = new QPushButton;
566 stopButton->setSizePolicy( sizePolicy );
567 setupSmallButton( stopButton );
569 controlButLayout->addWidget( stopButton );
572 QPushButton *nextButton = new QPushButton;
573 nextButton->setSizePolicy( sizePolicy );
574 setupSmallButton( nextButton );
576 controlButLayout->addWidget( nextButton );
578 /* Add this block to the main layout */
580 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
582 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
583 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
584 qtr( "Previous" ), prev() );
585 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
586 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
588 controlLayout->setColumnMinimumWidth( 7, 20 );
589 controlLayout->setColumnStretch( 7, 0 );
590 controlLayout->setColumnStretch( 8, 0 );
591 controlLayout->setColumnStretch( 9, 0 );
594 * Other first Line buttons
596 /** Fullscreen/Visualisation **/
597 fullscreenButton = new QPushButton( "F" );
598 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
599 setupSmallButton( fullscreenButton );
600 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
602 /** Playlist Button **/
603 playlistButton = new QPushButton;
604 setupSmallButton( playlistButton );
605 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
606 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
607 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
609 /** extended Settings **/
610 extSettingsButton = new QPushButton;
611 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
613 setupSmallButton( extSettingsButton );
614 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
616 controlLayout->setColumnStretch( 13, 0 );
617 controlLayout->setColumnMinimumWidth( 13, 24 );
618 controlLayout->setColumnStretch( 14, 5 );
621 hVolLabel = new VolumeClickHandler( p_intf, this );
623 volMuteLabel = new QLabel;
624 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
625 volMuteLabel->setToolTip( qtr( "Mute" ) );
626 volMuteLabel->installEventFilter( hVolLabel );
627 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
631 volumeSlider = new SoundSlider( this,
632 config_GetInt( p_intf, "volume-step" ),
633 config_GetInt( p_intf, "qt-volume-complete" ),
634 config_GetPsz( p_intf, "qt-slider-colours" ) );
638 volumeSlider = new QSlider( this );
639 volumeSlider->setOrientation( Qt::Horizontal );
641 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
642 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
643 volumeSlider->setFocusPolicy( Qt::NoFocus );
644 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
646 /* Set the volume from the config */
647 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
648 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
650 /* Force the update at build time in order to have a muted icon if needed */
651 updateVolume( volumeSlider->value() );
653 /* Volume control connection */
654 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
655 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
660 ControlsWidget::~ControlsWidget()
663 void ControlsWidget::toggleTeletext()
665 bool b_enabled = THEMIM->teletextState();
668 telexTransparent->setEnabled( false );
669 telexPage->setEnabled( false );
670 b_telexEnabled = false;
674 telexTransparent->setEnabled( true );
675 telexPage->setEnabled( true );
676 b_telexEnabled = true;
680 void ControlsWidget::toggleTeletextTransparency()
682 if( b_telexTransparent )
684 telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx.png" ) );
685 telexTransparent->setToolTip( qtr( "Teletext" ) );
686 b_telexTransparent = false;
690 telexTransparent->setIcon( QIcon( ":/pixmaps/tvtelx-transparent.png" ) );
691 telexTransparent->setToolTip( qtr( "Transparent" ) );
692 b_telexTransparent = true;
696 void ControlsWidget::stop()
701 void ControlsWidget::play()
703 if( THEPL->current.i_size == 0 )
705 /* The playlist is empty, open a file requester */
706 THEDP->openFileDialog();
710 THEMIM->togglePlayPause();
713 void ControlsWidget::prev()
718 void ControlsWidget::next()
723 void ControlsWidget::setNavigation( int navigation )
725 #define HELP_MENU N_( "Menu" )
726 #define HELP_PCH N_( "Previous chapter" )
727 #define HELP_NCH N_( "Next chapter" )
728 #define HELP_PTR N_( "Previous track" )
729 #define HELP_NTR N_( "Next track" )
731 // 1 = chapter, 2 = title, 0 = no
732 if( navigation == 0 )
735 } else if( navigation == 1 ) {
736 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
737 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
741 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
742 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
748 static bool b_my_volume;
749 void ControlsWidget::updateVolume( int i_sliderVolume )
753 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
754 aout_VolumeSet( p_intf, i_res );
756 if( i_sliderVolume == 0 )
757 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
758 else if( i_sliderVolume < VOLUME_MAX / 3 )
759 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
760 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
761 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
762 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-medium.png" ) );
765 void ControlsWidget::updateVolume()
768 audio_volume_t i_volume;
769 aout_VolumeGet( p_intf, &i_volume );
770 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
771 int i_gauge = volumeSlider->value();
773 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
776 volumeSlider->setValue( i_volume );
781 void ControlsWidget::updateInput()
783 /* Activate the interface buttons according to the presence of the input */
784 enableInput( THEMIM->getIM()->hasInput() );
785 enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
788 void ControlsWidget::setStatus( int status )
790 if( status == PLAYING_S ) /* Playing */
792 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
793 playButton->setToolTip( qtr( "Pause" ) );
797 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
798 playButton->setToolTip( qtr( "Play" ) );
804 * This functions toggle the fullscreen mode
805 * If there is no video, it should first activate Visualisations...
806 * This has also to be fixed in enableVideo()
808 void ControlsWidget::fullscreen()
810 vout_thread_t *p_vout =
811 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
814 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
815 vlc_object_release( p_vout );
819 void ControlsWidget::extSettings()
821 THEDP->extendedDialog();
824 void ControlsWidget::slower()
826 THEMIM->getIM()->slower();
829 void ControlsWidget::faster()
831 THEMIM->getIM()->faster();
834 void ControlsWidget::enableInput( bool enable )
836 slowerButton->setEnabled( enable );
837 slider->setEnabled( enable );
838 fasterButton->setEnabled( enable );
840 /* Advanced Buttons too */
841 advControls->enableInput( enable );
844 void ControlsWidget::enableVideo( bool enable )
846 // TODO Later make the fullscreenButton toggle Visualisation and so on.
847 fullscreenButton->setEnabled( enable );
849 /* Advanced Buttons too */
850 advControls->enableVideo( enable );
853 void ControlsWidget::toggleAdvanced()
855 if( !VISIBLE( advControls ) )
858 b_advancedVisible = true;
863 b_advancedVisible = false;
865 emit advancedControlsToggled( b_advancedVisible );
869 /**********************************************************************
870 * Fullscrenn control widget
871 **********************************************************************/
872 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
873 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
874 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
875 i_lastPosX( -1 ), i_lastPosY( -1 ), i_hideTimeout( 1 ),
876 b_mouseIsOver( false )
878 setWindowFlags( Qt::ToolTip );
880 setFrameShape( QFrame::StyledPanel );
881 setFrameStyle( QFrame::Sunken );
882 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
884 QGridLayout *fsLayout = new QGridLayout( this );
885 controlLayout->setSpacing( 0 );
886 controlLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
888 fsLayout->addWidget( slowerButton, 0, 0 );
889 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
890 fsLayout->addWidget( slider, 0, 1, 1, 6 );
891 fsLayout->addWidget( fasterButton, 0, 7 );
893 fsLayout->addWidget( volMuteLabel, 1, 0);
894 fsLayout->addWidget( volumeSlider, 1, 1 );
896 fsLayout->addLayout( controlButLayout, 1, 2 );
898 fsLayout->addWidget( playButton, 1, 3 );
900 fsLayout->addWidget( discFrame, 1, 4 );
902 fsLayout->addWidget( telexFrame, 1, 5 );
904 fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
906 fsLayout->addWidget( fullscreenButton, 1, 7 );
909 p_hideTimer = new QTimer( this );
910 CONNECT( p_hideTimer, timeout(), this, hideFSControllerWidget() );
911 p_hideTimer->setSingleShot( true );
913 /* slow hiding timer */
914 #if HAVE_TRANSPARENCY
915 p_slowHideTimer = new QTimer( this );
916 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
919 adjustSize (); /* need to get real width and height for moving */
922 QDesktopWidget * p_desktop = QApplication::desktop();
924 move( p_desktop->width() / 2 - width() / 2,
925 p_desktop->height() - height() );
928 setWindowOpacity( 0.0 );
934 FullscreenControllerWidget::~FullscreenControllerWidget()
939 * Hide fullscreen controller
940 * FIXME: under windows it have to be done by moving out of screen
941 * because hide() doesnt work
943 void FullscreenControllerWidget::hideFSControllerWidget()
947 setWindowOpacity( 0.0 ); // simulate hidding
954 * Hidding fullscreen controller slowly
955 * Linux: need composite manager
956 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
958 void FullscreenControllerWidget::slowHideFSC()
960 #if HAVE_TRANSPARENCY
961 static bool first_call = true;
967 p_slowHideTimer->stop();
968 /* the last part of time divided to 100 pieces */
969 p_slowHideTimer->start(
970 (int) ( i_hideTimeout / 2 / ( windowOpacity() * 100 ) ) );
974 if ( windowOpacity() > 0.0 )
976 /* we should use 0.01 because of 100 pieces ^^^
977 but than it cannt be done in time */
978 setWindowOpacity( windowOpacity() - 0.02 );
981 if ( windowOpacity() == 0.0 )
984 p_slowHideTimer->stop();
991 * Get state of visibility of FS controller on screen
992 * On windows control if it is on hidden position
994 bool FullscreenControllerWidget::isFSCHidden()
1005 * events: show, hide, start timer for hidding
1007 void FullscreenControllerWidget::customEvent( QEvent *event )
1009 int type = event->type();
1011 if ( type == FullscreenControlShow_Type )
1014 // after quiting and going to fs, we need to call show()
1021 setWindowOpacity( 1.0 );
1027 #if HAVE_TRANSPARENCY
1028 setWindowOpacity( DEFAULT_OPACITY );
1031 else if ( type == FullscreenControlHide_Type )
1033 hideFSControllerWidget();
1035 else if ( type == FullscreenControlPlanHide_Type && !b_mouseIsOver )
1037 p_hideTimer->start( i_hideTimeout );
1038 #if HAVE_TRANSPARENCY
1039 p_slowHideTimer->start( i_hideTimeout / 2 );
1048 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1050 if ( event->buttons() == Qt::LeftButton )
1052 int i_moveX = event->globalX() - i_lastPosX;
1053 int i_moveY = event->globalY() - i_lastPosY;
1055 move( x() + i_moveX, y() + i_moveY );
1057 i_lastPosX = event->globalX();
1058 i_lastPosY = event->globalY();
1064 * store position of cursor
1066 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1068 i_lastPosX = event->globalX();
1069 i_lastPosY = event->globalY();
1073 * On mouse go above FSC
1075 void FullscreenControllerWidget::enterEvent( QEvent *event )
1077 p_hideTimer->stop();
1078 #if HAVE_TRANSPARENCY
1079 p_slowHideTimer->stop();
1081 b_mouseIsOver = true;
1085 * On mouse go out from FSC
1087 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1089 p_hideTimer->start( i_hideTimeout );
1090 #if HAVE_TRANSPARENCY
1091 p_slowHideTimer->start( i_hideTimeout / 2 );
1093 b_mouseIsOver = false;
1097 * When you get pressed key, send it to video output
1098 * FIXME: clearing focus by clearFocus() to not getting
1099 * key press events didnt work
1101 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1103 int i_vlck = qtEventToVLCKey( event );
1106 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1114 * It is called when video start
1116 void FullscreenControllerWidget::regFullscreenCallback( vout_thread_t *p_vout )
1120 var_AddCallback( p_vout, "fullscreen", regMouseMoveCallback, this );
1125 * It is called after turn off video, because p_vout is NULL now
1126 * we cannt delete callback, just hide if FScontroller is visible
1128 void FullscreenControllerWidget::unregFullscreenCallback()
1135 * Register and unregister callback for mouse moving
1137 static int regMouseMoveCallback( vlc_object_t *vlc_object, const char *variable,
1138 vlc_value_t old_val, vlc_value_t new_val,
1141 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1143 static bool b_registered = false;
1144 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1146 if ( var_GetBool( p_vout, "fullscreen" ) && !b_registered )
1148 p_fs->SetHideTimeout( var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1149 var_AddCallback( p_vout, "mouse-moved",
1150 showFullscreenControllCallback, (void *) p_fs );
1151 b_registered = true;
1154 if ( !var_GetBool( p_vout, "fullscreen" ) && b_registered )
1156 var_DelCallback( p_vout, "mouse-moved",
1157 showFullscreenControllCallback, (void *) p_fs );
1158 b_registered = false;
1161 if ( !var_GetBool( p_vout, "fullscreen" ) )
1168 * Show fullscreen controller after mouse move
1169 * after show immediately plan hide event
1171 static int showFullscreenControllCallback( vlc_object_t *vlc_object, const char *variable,
1172 vlc_value_t old_val, vlc_value_t new_val,
1175 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *) data;
1177 if ( p_fs->isFSCHidden() || p_fs->windowOpacity() < DEFAULT_OPACITY )
1179 IMEvent *event = new IMEvent( FullscreenControlShow_Type, 0 );
1180 QApplication::postEvent( p_fs, static_cast<QEvent *>(event) );
1183 IMEvent *e = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1184 QApplication::postEvent( p_fs, static_cast<QEvent *>(e) );
1189 /**********************************************************************
1190 * Speed control widget
1191 **********************************************************************/
1192 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1193 QFrame( NULL ), p_intf( _p_i )
1195 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1196 sizePolicy.setHorizontalStretch( 0 );
1197 sizePolicy.setVerticalStretch( 0 );
1199 speedSlider = new QSlider;
1200 speedSlider->setSizePolicy( sizePolicy );
1201 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1202 speedSlider->setOrientation( Qt::Vertical );
1203 speedSlider->setTickPosition( QSlider::TicksRight );
1205 speedSlider->setRange( -100, 100 );
1206 speedSlider->setSingleStep( 10 );
1207 speedSlider->setPageStep( 20 );
1208 speedSlider->setTickInterval( 20 );
1210 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1212 QToolButton *normalSpeedButton = new QToolButton( this );
1213 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1214 normalSpeedButton->setAutoRaise( true );
1215 normalSpeedButton->setText( "N" );
1216 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1218 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1220 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1221 speedControlLayout->addWidget( speedSlider );
1222 speedControlLayout->addWidget( normalSpeedButton );
1223 setLayout( speedControlLayout );
1226 SpeedControlWidget::~SpeedControlWidget()
1229 void SpeedControlWidget::setEnable( bool b_enable )
1231 speedSlider->setEnabled( b_enable );
1234 #define RATE_SLIDER_MAXIMUM 3.0
1235 #define RATE_SLIDER_MINIMUM 0.3
1236 #define RATE_SLIDER_LENGTH 100.0
1238 void SpeedControlWidget::updateControls( int rate )
1240 if( speedSlider->isSliderDown() )
1242 //We don't want to change anything if the user is using the slider
1247 double speed = INPUT_RATE_DEFAULT / (double)rate;
1249 if( rate >= INPUT_RATE_DEFAULT )
1251 if( speed < RATE_SLIDER_MINIMUM )
1253 sliderValue = speedSlider->minimum();
1257 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
1258 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
1263 if( speed > RATE_SLIDER_MAXIMUM )
1265 sliderValue = speedSlider->maximum();
1269 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
1270 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
1274 //Block signals to avoid feedback loop
1275 speedSlider->blockSignals( true );
1276 speedSlider->setValue( sliderValue );
1277 speedSlider->blockSignals( false );
1280 void SpeedControlWidget::updateRate( int sliderValue )
1284 if( sliderValue < 0.0 )
1286 rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
1287 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH ));
1291 rate = (int)(INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
1292 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH ));
1295 THEMIM->getIM()->setRate(rate);
1298 void SpeedControlWidget::resetRate()
1300 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);