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_I( ABButton, "", atob_nob,
310 qtr( "Loop from point A to point B continuously\nClick to set point A" ), fromAtoB() );
312 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
313 this, AtoBLoop( float, int, int ) );
315 frameButton = new QPushButton( "Fr" );
316 frameButton->setMaximumSize( QSize( 26, 26 ) );
317 frameButton->setIconSize( QSize( 20, 20 ) );
318 advLayout->addWidget( frameButton );
319 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by frame" ), frame() );
322 recordButton = new QPushButton( "R" );
323 setupSmallButton( recordButton );
324 advLayout->addWidget( recordButton );
325 BUTTON_SET_ACT_I( recordButton, "", record,
326 qtr( "Record" ), record() );
328 /* Snapshot Button */
329 snapshotButton = new QPushButton( "S" );
330 setupSmallButton( snapshotButton );
331 advLayout->addWidget( snapshotButton );
332 BUTTON_SET_ACT_I( snapshotButton, "", snapshot,
333 qtr( "Take a snapshot" ), snapshot() );
336 AdvControlsWidget::~AdvControlsWidget()
339 void AdvControlsWidget::enableInput( bool enable )
341 ABButton->setEnabled( enable );
342 recordButton->setEnabled( enable );
345 void AdvControlsWidget::enableVideo( bool enable )
347 snapshotButton->setEnabled( enable );
349 frameButton->setEnabled( enable );
353 void AdvControlsWidget::snapshot()
355 vout_thread_t *p_vout =
356 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
357 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
360 /* Function called when the button is clicked() */
361 void AdvControlsWidget::fromAtoB()
365 timeA = var_GetTime( THEMIM->getInput(), "time" );
366 ABButton->setToolTip( "Click to set point B" );
367 ABButton->setIcon( QIcon( ":/atob_noa" ) );
372 timeB = var_GetTime( THEMIM->getInput(), "time" );
373 var_SetTime( THEMIM->getInput(), "time" , timeA );
374 ABButton->setIcon( QIcon( ":/atob" ) );
375 ABButton->setToolTip( "Stop the A to B loop" );
380 ABButton->setToolTip( qtr( "Loop from point A to point B continuously\nClick to set point A" ) );
381 ABButton->setIcon( QIcon( ":/atob_nob" ) );
384 /* Function called regularly when in an AtoB loop */
385 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
389 if( i_time >= (int)(timeB/1000000) )
390 var_SetTime( THEMIM->getInput(), "time" , timeA );
394 /* FIXME Record function */
395 void AdvControlsWidget::record(){}
398 //FIXME Frame by frame function
399 void AdvControlsWidget::frame(){}
402 /*****************************
403 * DA Control Widget !
404 *****************************/
405 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
406 MainInterface *_p_mi,
410 QFrame( _p_mi ), p_intf( _p_i )
412 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
414 /** The main Slider **/
415 slider = new InputSlider( Qt::Horizontal, NULL );
416 /* Update the position when the IM has changed */
417 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
418 slider, setPosition( float, int, int ) );
419 /* And update the IM, when the position has changed */
420 CONNECT( slider, sliderDragged( float ),
421 THEMIM->getIM(), sliderUpdate( float ) );
423 /** Slower and faster Buttons **/
424 slowerButton = new QToolButton;
425 slowerButton->setAutoRaise( true );
426 slowerButton->setMaximumSize( QSize( 26, 20 ) );
428 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
430 fasterButton = new QToolButton;
431 fasterButton->setAutoRaise( true );
432 fasterButton->setMaximumSize( QSize( 26, 20 ) );
434 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
436 /* advanced Controls handling */
437 b_advancedVisible = b_advControls;
439 advControls = new AdvControlsWidget( p_intf );
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 BUTTON_SET_IMG( prevSectionButton, "", dvd_prev, "" );
462 BUTTON_SET_IMG( nextSectionButton, "", dvd_next, "" );
463 BUTTON_SET_IMG( menuButton, "", dvd_menu, qtr( "Menu" ) );
467 /* Change the navigation button display when the IM navigation changes */
468 CONNECT( THEMIM->getIM(), navigationChanged( int ),
469 this, setNavigation( int ) );
470 /* Changes the IM navigation when triggered on the nav buttons */
471 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
473 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
475 CONNECT( menuButton, clicked(), THEMIM->getIM(),
480 * TODO: Merge with upper menu in a StackLayout
482 telexFrame = new QWidget( this );
483 QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
484 telexLayout->setSpacing( 0 );
485 telexLayout->setMargin( 0 );
487 telexOn = new QPushButton;
488 setupSmallButton( telexOn );
489 telexLayout->addWidget( telexOn );
491 telexTransparent = new QPushButton;
492 setupSmallButton( telexTransparent );
493 telexLayout->addWidget( telexTransparent );
494 b_telexTransparent = false;
496 telexPage = new QSpinBox;
497 telexPage->setRange( 0, 999 );
498 telexPage->setValue( 100 );
499 telexPage->setAccelerated( true );
500 telexPage->setWrapping( true );
501 telexPage->setAlignment( Qt::AlignRight );
502 telexPage->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Minimum );
503 telexLayout->addWidget( telexPage );
505 telexFrame->hide(); /* default hidden */
507 CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
508 telexGotoPage( int ) );
509 CONNECT( THEMIM->getIM(), setNewTelexPage( int ),
510 telexPage, setValue( int ) );
512 BUTTON_SET_IMG( telexOn, "", tv, qtr( "Teletext on" ) );
514 CONNECT( telexOn, clicked(), THEMIM->getIM(),
515 telexToggleButtons() );
516 CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
517 telexToggle( bool ) );
518 CONNECT( THEMIM->getIM(), toggleTelexButtons(),
519 this, toggleTeletext() );
520 b_telexEnabled = false;
521 telexTransparent->setEnabled( false );
522 telexPage->setEnabled( false );
524 BUTTON_SET_IMG( telexTransparent, "", tvtelx, qtr( "Teletext" ) );
525 CONNECT( telexTransparent, clicked( bool ),
526 THEMIM->getIM(), telexSetTransparency() );
527 CONNECT( THEMIM->getIM(), toggleTelexTransparency(),
528 this, toggleTeletextTransparency() );
529 CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
530 this, enableTeletext( bool ) );
533 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
534 sizePolicy.setHorizontalStretch( 0 );
535 sizePolicy.setVerticalStretch( 0 );
538 playButton = new QPushButton;
539 playButton->setSizePolicy( sizePolicy );
540 playButton->setMaximumSize( QSize( 36, 36 ) );
541 playButton->setMinimumSize( QSize( 36, 36 ) );
542 playButton->setIconSize( QSize( 30, 30 ) );
545 /** Prev + Stop + Next Block **/
546 controlButLayout = new QHBoxLayout;
547 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
550 QPushButton *prevButton = new QPushButton;
551 prevButton->setSizePolicy( sizePolicy );
552 setupSmallButton( prevButton );
554 controlButLayout->addWidget( prevButton );
557 QPushButton *stopButton = new QPushButton;
558 stopButton->setSizePolicy( sizePolicy );
559 setupSmallButton( stopButton );
561 controlButLayout->addWidget( stopButton );
564 QPushButton *nextButton = new QPushButton;
565 nextButton->setSizePolicy( sizePolicy );
566 setupSmallButton( nextButton );
568 controlButLayout->addWidget( nextButton );
570 /* Add this block to the main layout */
572 BUTTON_SET_ACT_I( playButton, "", play_b, qtr( "Play" ), play() );
573 BUTTON_SET_ACT_I( prevButton, "" , previous_b,
574 qtr( "Previous" ), prev() );
575 BUTTON_SET_ACT_I( nextButton, "", next_b, qtr( "Next" ), next() );
576 BUTTON_SET_ACT_I( stopButton, "", stop_b, qtr( "Stop" ), stop() );
579 * Other first Line buttons
581 /** Fullscreen/Visualisation **/
582 fullscreenButton = new QPushButton;
583 BUTTON_SET_ACT_I( fullscreenButton, "", fullscreen, qtr( "Fullscreen" ),
585 setupSmallButton( fullscreenButton );
589 /** Playlist Button **/
590 playlistButton = new QPushButton;
591 setupSmallButton( playlistButton );
592 BUTTON_SET_IMG( playlistButton, "" , playlist, qtr( "Show playlist" ) );
593 CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
595 /** extended Settings **/
596 extSettingsButton = new QPushButton;
597 BUTTON_SET_ACT_I( extSettingsButton, "", extended,
598 qtr( "Extended settings" ), extSettings() );
599 setupSmallButton( extSettingsButton );
603 hVolLabel = new VolumeClickHandler( p_intf, this );
605 volMuteLabel = new QLabel;
606 volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
607 volMuteLabel->setToolTip( qtr( "Mute" ) );
608 volMuteLabel->installEventFilter( hVolLabel );
612 volumeSlider = new SoundSlider( this,
613 config_GetInt( p_intf, "volume-step" ),
614 config_GetInt( p_intf, "qt-volume-complete" ),
615 config_GetPsz( p_intf, "qt-slider-colours" ) );
619 volumeSlider = new QSlider( this );
620 volumeSlider->setOrientation( Qt::Horizontal );
622 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
623 volumeSlider->setMinimumSize( QSize( 106, 30 ) );
624 volumeSlider->setFocusPolicy( Qt::NoFocus );
626 /* Set the volume from the config */
627 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
628 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
630 /* Force the update at build time in order to have a muted icon if needed */
631 updateVolume( volumeSlider->value() );
633 /* Volume control connection */
634 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
635 CONNECT( THEMIM, volumeChanged( void ), this, updateVolume( void ) );
639 controlLayout = new QGridLayout( this );
641 controlLayout->setSpacing( 0 );
642 controlLayout->setLayoutMargins( 7, 5, 7, 3, 6 );
644 controlLayout->addWidget( slider, 0, 1, 1, 16 );
645 controlLayout->addWidget( slowerButton, 0, 0 );
646 controlLayout->addWidget( fasterButton, 0, 17 );
648 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
649 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
650 controlLayout->addWidget( telexFrame, 1, 10, 2, 4, Qt::AlignBottom );
652 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
653 controlLayout->setColumnMinimumWidth( 2, 20 );
654 controlLayout->setColumnStretch( 2, 0 );
656 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
657 controlLayout->setColumnMinimumWidth( 7, 20 );
658 controlLayout->setColumnStretch( 7, 0 );
659 controlLayout->setColumnStretch( 8, 0 );
660 controlLayout->setColumnStretch( 9, 0 );
662 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
663 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
664 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
666 controlLayout->setColumnStretch( 13, 0 );
667 controlLayout->setColumnMinimumWidth( 13, 24 );
668 controlLayout->setColumnStretch( 14, 5 );
670 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
671 controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
677 ControlsWidget::~ControlsWidget()
680 void ControlsWidget::toggleTeletext()
682 bool b_enabled = THEMIM->teletextState();
685 telexTransparent->setEnabled( false );
686 telexPage->setEnabled( false );
687 b_telexEnabled = false;
691 telexTransparent->setEnabled( true );
692 telexPage->setEnabled( true );
693 b_telexEnabled = true;
697 void ControlsWidget::enableTeletext( bool b_enable )
699 telexFrame->setVisible( b_enable );
700 bool b_on = THEMIM->teletextState();
702 telexOn->setChecked( b_on );
703 telexTransparent->setEnabled( b_on );
704 telexPage->setEnabled( b_on );
705 b_telexEnabled = b_on;
708 void ControlsWidget::toggleTeletextTransparency()
710 if( b_telexTransparent )
712 telexTransparent->setIcon( QIcon( ":/tvtelx" ) );
713 telexTransparent->setToolTip( qtr( "Teletext" ) );
714 b_telexTransparent = false;
718 telexTransparent->setIcon( QIcon( ":/tvtelx-transparent" ) );
719 telexTransparent->setToolTip( qtr( "Transparent" ) );
720 b_telexTransparent = true;
724 void ControlsWidget::stop()
729 void ControlsWidget::play()
731 if( THEPL->current.i_size == 0 )
733 /* The playlist is empty, open a file requester */
734 THEDP->openFileDialog();
738 THEMIM->togglePlayPause();
741 void ControlsWidget::prev()
746 void ControlsWidget::next()
751 void ControlsWidget::setNavigation( int navigation )
753 #define HELP_PCH N_( "Previous chapter" )
754 #define HELP_NCH N_( "Next chapter" )
756 // 1 = chapter, 2 = title, 0 = no
757 if( navigation == 0 )
760 } else if( navigation == 1 ) {
761 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
762 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
766 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
767 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
773 static bool b_my_volume;
774 void ControlsWidget::updateVolume( int i_sliderVolume )
778 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
779 aout_VolumeSet( p_intf, i_res );
781 if( i_sliderVolume == 0 )
782 volMuteLabel->setPixmap( QPixmap(":/volume-muted" ) );
783 else if( i_sliderVolume < VOLUME_MAX / 3 )
784 volMuteLabel->setPixmap( QPixmap( ":/volume-low" ) );
785 else if( i_sliderVolume > (VOLUME_MAX * 2 / 3 ) )
786 volMuteLabel->setPixmap( QPixmap( ":/volume-high" ) );
787 else volMuteLabel->setPixmap( QPixmap( ":/volume-medium" ) );
790 void ControlsWidget::updateVolume()
793 audio_volume_t i_volume;
794 aout_VolumeGet( p_intf, &i_volume );
795 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
796 int i_gauge = volumeSlider->value();
798 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
801 volumeSlider->setValue( i_volume );
806 void ControlsWidget::updateInput()
808 /* Activate the interface buttons according to the presence of the input */
809 enableInput( THEMIM->getIM()->hasInput() );
810 enableVideo( THEMIM->getIM()->hasVideo() && THEMIM->getIM()->hasInput() );
813 void ControlsWidget::setStatus( int status )
815 if( status == PLAYING_S ) /* Playing */
817 playButton->setIcon( QIcon( ":/pause_b" ) );
818 playButton->setToolTip( qtr( "Pause" ) );
822 playButton->setIcon( QIcon( ":/play_b" ) );
823 playButton->setToolTip( qtr( "Play" ) );
829 * This functions toggle the fullscreen mode
830 * If there is no video, it should first activate Visualisations...
831 * This has also to be fixed in enableVideo()
833 void ControlsWidget::fullscreen()
835 vout_thread_t *p_vout =
836 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
839 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
840 vlc_object_release( p_vout );
844 void ControlsWidget::extSettings()
846 THEDP->extendedDialog();
849 void ControlsWidget::slower()
851 THEMIM->getIM()->slower();
854 void ControlsWidget::faster()
856 THEMIM->getIM()->faster();
859 void ControlsWidget::enableInput( bool enable )
861 slowerButton->setEnabled( enable );
862 slider->setEnabled( enable );
863 fasterButton->setEnabled( enable );
865 /* Advanced Buttons too */
866 advControls->enableInput( enable );
869 void ControlsWidget::enableVideo( bool enable )
871 // TODO Later make the fullscreenButton toggle Visualisation and so on.
872 fullscreenButton->setEnabled( enable );
874 /* Advanced Buttons too */
875 advControls->enableVideo( enable );
878 void ControlsWidget::toggleAdvanced()
880 if( !VISIBLE( advControls ) )
883 b_advancedVisible = true;
888 b_advancedVisible = false;
890 emit advancedControlsToggled( b_advancedVisible );
894 /**********************************************************************
895 * Fullscrenn control widget
896 **********************************************************************/
897 FullscreenControllerWidget::FullscreenControllerWidget( intf_thread_t *_p_i,
898 MainInterface *_p_mi, bool b_advControls, bool b_shiny )
899 : ControlsWidget( _p_i, _p_mi, b_advControls, b_shiny, true ),
900 i_mouse_last_x( -1 ), i_mouse_last_y( -1 ), b_mouse_over(false),
901 b_slow_hide_begin(false), i_slow_hide_timeout(1),
902 b_fullscreen( false ), i_hide_timeout( 1 )
904 setWindowFlags( Qt::ToolTip );
906 setFrameShape( QFrame::StyledPanel );
907 setFrameStyle( QFrame::Sunken );
908 setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
910 QGridLayout *fsLayout = new QGridLayout( this );
911 fsLayout->setLayoutMargins( 5, 1, 5, 1, 5 );
913 fsLayout->addWidget( slowerButton, 0, 0 );
914 slider->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum);
915 fsLayout->addWidget( slider, 0, 1, 1, 6 );
916 fsLayout->addWidget( fasterButton, 0, 7 );
918 fsLayout->addWidget( volMuteLabel, 1, 0);
919 fsLayout->addWidget( volumeSlider, 1, 1 );
921 fsLayout->addLayout( controlButLayout, 1, 2 );
923 fsLayout->addWidget( playButton, 1, 3 );
925 fsLayout->addWidget( discFrame, 1, 4 );
927 fsLayout->addWidget( telexFrame, 1, 5 );
929 fsLayout->addWidget( advControls, 1, 6, Qt::AlignVCenter );
931 fsLayout->addWidget( fullscreenButton, 1, 7 );
934 p_hideTimer = new QTimer( this );
935 CONNECT( p_hideTimer, timeout(), this, hideFSC() );
936 p_hideTimer->setSingleShot( true );
938 /* slow hiding timer */
939 #if HAVE_TRANSPARENCY
940 p_slowHideTimer = new QTimer( this );
941 CONNECT( p_slowHideTimer, timeout(), this, slowHideFSC() );
944 adjustSize (); /* need to get real width and height for moving */
947 QDesktopWidget * p_desktop = QApplication::desktop();
949 move( p_desktop->width() / 2 - width() / 2,
950 p_desktop->height() - height() );
953 setWindowOpacity( 0.0 );
958 vlc_mutex_init_recursive( &lock );
961 FullscreenControllerWidget::~FullscreenControllerWidget()
963 vlc_mutex_destroy( &lock );
967 * Show fullscreen controller
969 void FullscreenControllerWidget::showFSC()
972 // after quiting and going to fs, we need to call show()
979 setWindowOpacity( 1.0 );
985 #if HAVE_TRANSPARENCY
986 setWindowOpacity( DEFAULT_OPACITY );
991 * Hide fullscreen controller
992 * FIXME: under windows it have to be done by moving out of screen
993 * because hide() doesnt work
995 void FullscreenControllerWidget::hideFSC()
999 setWindowOpacity( 0.0 ); // simulate hidding
1006 * Plane to hide fullscreen controller
1008 void FullscreenControllerWidget::planHideFSC()
1010 vlc_mutex_lock( &lock );
1011 int i_timeout = i_hide_timeout;
1012 vlc_mutex_unlock( &lock );
1014 p_hideTimer->start( i_timeout );
1016 #if HAVE_TRANSPARENCY
1017 b_slow_hide_begin = true;
1018 i_slow_hide_timeout = i_timeout;
1019 p_slowHideTimer->start( i_slow_hide_timeout / 2 );
1024 * Hidding fullscreen controller slowly
1025 * Linux: need composite manager
1026 * Windows: it is blinking, so it can be enabled by define TRASPARENCY
1028 void FullscreenControllerWidget::slowHideFSC()
1030 #if HAVE_TRANSPARENCY
1031 if( b_slow_hide_begin )
1033 b_slow_hide_begin = false;
1035 p_slowHideTimer->stop();
1036 /* the last part of time divided to 100 pieces */
1037 p_slowHideTimer->start( (int)( i_slow_hide_timeout / 2 / ( windowOpacity() * 100 ) ) );
1043 if ( windowOpacity() > 0.0 && !fscHidden )
1045 if ( windowOpacity() > 0.0 )
1048 /* we should use 0.01 because of 100 pieces ^^^
1049 but than it cannt be done in time */
1050 setWindowOpacity( windowOpacity() - 0.02 );
1053 if ( windowOpacity() <= 0.0 )
1054 p_slowHideTimer->stop();
1061 * events: show, hide, start timer for hidding
1063 void FullscreenControllerWidget::customEvent( QEvent *event )
1067 switch( event->type() )
1069 case FullscreenControlShow_Type:
1070 vlc_mutex_lock( &lock );
1071 b_fs = b_fullscreen;
1072 vlc_mutex_unlock( &lock );
1074 if( b_fs ) // FIXME I am not sure about that one
1077 case FullscreenControlHide_Type:
1080 case FullscreenControlPlanHide_Type:
1081 if( !b_mouse_over ) // Only if the mouse is not over FSC
1091 void FullscreenControllerWidget::mouseMoveEvent( QMouseEvent *event )
1093 if ( event->buttons() == Qt::LeftButton )
1095 int i_moveX = event->globalX() - i_mouse_last_x;
1096 int i_moveY = event->globalY() - i_mouse_last_y;
1098 move( x() + i_moveX, y() + i_moveY );
1100 i_mouse_last_x = event->globalX();
1101 i_mouse_last_y = event->globalY();
1107 * store position of cursor
1109 void FullscreenControllerWidget::mousePressEvent( QMouseEvent *event )
1111 i_mouse_last_x = event->globalX();
1112 i_mouse_last_y = event->globalY();
1116 * On mouse go above FSC
1118 void FullscreenControllerWidget::enterEvent( QEvent *event )
1120 b_mouse_over = true;
1122 p_hideTimer->stop();
1123 #if HAVE_TRANSPARENCY
1124 p_slowHideTimer->stop();
1129 * On mouse go out from FSC
1131 void FullscreenControllerWidget::leaveEvent( QEvent *event )
1135 b_mouse_over = false;
1139 * When you get pressed key, send it to video output
1140 * FIXME: clearing focus by clearFocus() to not getting
1141 * key press events didnt work
1143 void FullscreenControllerWidget::keyPressEvent( QKeyEvent *event )
1145 int i_vlck = qtEventToVLCKey( event );
1148 var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlck );
1156 static int FullscreenControllerWidgetFullscreenChanged( vlc_object_t *vlc_object, const char *variable,
1157 vlc_value_t old_val, vlc_value_t new_val,
1160 vout_thread_t *p_vout = (vout_thread_t *) vlc_object;
1161 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1163 p_fs->fullscreenChanged( p_vout, new_val.b_bool, var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1168 static int FullscreenControllerWidgetMouseMoved( vlc_object_t *vlc_object, const char *variable,
1169 vlc_value_t old_val, vlc_value_t new_val,
1172 FullscreenControllerWidget *p_fs = (FullscreenControllerWidget *)data;
1175 IMEvent *eShow = new IMEvent( FullscreenControlShow_Type, 0 );
1176 QApplication::postEvent( p_fs, static_cast<QEvent *>(eShow) );
1178 /* Plan hide event */
1179 IMEvent *eHide = new IMEvent( FullscreenControlPlanHide_Type, 0 );
1180 QApplication::postEvent( p_fs, static_cast<QEvent *>(eHide) );
1187 * It is called when video start
1189 void FullscreenControllerWidget::attachVout( vout_thread_t *p_vout )
1193 vlc_mutex_lock( &lock );
1194 var_AddCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this ); /* I miss a add and fire */
1195 fullscreenChanged( p_vout, var_GetBool( p_vout, "fullscreen" ), var_GetInteger( p_vout, "mouse-hide-timeout" ) );
1196 vlc_mutex_unlock( &lock );
1199 * It is called after turn off video.
1201 void FullscreenControllerWidget::detachVout( vout_thread_t *p_vout )
1205 var_DelCallback( p_vout, "fullscreen", FullscreenControllerWidgetFullscreenChanged, this );
1206 vlc_mutex_lock( &lock );
1207 fullscreenChanged( p_vout, false, 0 );
1208 vlc_mutex_unlock( &lock );
1212 * Register and unregister callback for mouse moving
1214 void FullscreenControllerWidget::fullscreenChanged( vout_thread_t *p_vout, bool b_fs, int i_timeout )
1216 vlc_mutex_lock( &lock );
1217 if( b_fs && !b_fullscreen )
1219 b_fullscreen = true;
1220 i_hide_timeout = i_timeout;
1221 var_AddCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1223 else if( !b_fs && b_fullscreen )
1225 b_fullscreen = false;
1226 i_hide_timeout = i_timeout;
1227 var_DelCallback( p_vout, "mouse-moved", FullscreenControllerWidgetMouseMoved, this );
1229 /* Force fs hidding */
1230 IMEvent *eHide = new IMEvent( FullscreenControlHide_Type, 0 );
1231 QApplication::postEvent( this, static_cast<QEvent *>(eHide) );
1233 vlc_mutex_unlock( &lock );
1236 /**********************************************************************
1237 * Speed control widget
1238 **********************************************************************/
1239 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
1240 QFrame( NULL ), p_intf( _p_i )
1242 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
1243 sizePolicy.setHorizontalStretch( 0 );
1244 sizePolicy.setVerticalStretch( 0 );
1246 speedSlider = new QSlider;
1247 speedSlider->setSizePolicy( sizePolicy );
1248 speedSlider->setMaximumSize( QSize( 80, 200 ) );
1249 speedSlider->setOrientation( Qt::Vertical );
1250 speedSlider->setTickPosition( QSlider::TicksRight );
1252 speedSlider->setRange( -24, 24 );
1253 speedSlider->setSingleStep( 1 );
1254 speedSlider->setPageStep( 1 );
1255 speedSlider->setTickInterval( 12 );
1257 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
1259 QToolButton *normalSpeedButton = new QToolButton( this );
1260 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
1261 normalSpeedButton->setAutoRaise( true );
1262 normalSpeedButton->setText( "1x" );
1263 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
1265 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
1267 QVBoxLayout *speedControlLayout = new QVBoxLayout;
1268 speedControlLayout->setLayoutMargins( 4, 4, 4, 4, 4 );
1269 speedControlLayout->setSpacing( 4 );
1270 speedControlLayout->addWidget( speedSlider );
1271 speedControlLayout->addWidget( normalSpeedButton );
1272 setLayout( speedControlLayout );
1275 SpeedControlWidget::~SpeedControlWidget()
1278 void SpeedControlWidget::setEnable( bool b_enable )
1280 speedSlider->setEnabled( b_enable );
1283 void SpeedControlWidget::updateControls( int rate )
1285 if( speedSlider->isSliderDown() )
1287 //We don't want to change anything if the user is using the slider
1291 double value = 12 * log( (double)INPUT_RATE_DEFAULT / rate ) / log( 2 );
1292 int sliderValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
1294 if( sliderValue < speedSlider->minimum() )
1296 sliderValue = speedSlider->minimum();
1298 else if( sliderValue > speedSlider->maximum() )
1300 sliderValue = speedSlider->maximum();
1303 //Block signals to avoid feedback loop
1304 speedSlider->blockSignals( true );
1305 speedSlider->setValue( sliderValue );
1306 speedSlider->blockSignals( false );
1309 void SpeedControlWidget::updateRate( int sliderValue )
1311 double speed = pow( 2, (double)sliderValue / 12 );
1312 int rate = INPUT_RATE_DEFAULT / speed;
1314 THEMIM->getIM()->setRate(rate);
1317 void SpeedControlWidget::resetRate()
1319 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);