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>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * ( at your option ) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #include "dialogs_provider.hpp"
27 #include "components/interface_widgets.hpp"
28 #include "main_interface.hpp"
29 #include "input_manager.hpp"
31 #include "util/input_slider.hpp"
35 #include <QSpacerItem>
37 #include <QPushButton>
38 #include <QHBoxLayout>
41 #include <QResizeEvent>
45 /**********************************************************************
46 * Video Widget. A simple frame on which video is drawn
47 * This class handles resize issues
48 **********************************************************************/
49 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
50 unsigned int *, unsigned int * );
51 static void DoRelease( intf_thread_t *, void * );
52 static int DoControl( intf_thread_t *, void *, int, va_list );
54 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
56 vlc_mutex_init( p_intf, &lock );
58 CONNECT( this, askResize(), this, SetMinSize() );
59 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
62 VideoWidget::~VideoWidget()
64 vlc_mutex_lock( &lock );
67 if( !p_intf->psz_switch_intf )
69 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
70 vout_Control( p_vout, VOUT_REPARENT );
74 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
75 vout_Control( p_vout, VOUT_CLOSE );
78 vlc_mutex_unlock( &lock );
79 vlc_mutex_destroy( &lock );
82 QSize VideoWidget::sizeHint() const
87 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
88 unsigned int *pi_width, unsigned int *pi_height )
92 msg_Dbg( p_intf, "embedded video already in use" );
97 return ( void* )winId();
100 void VideoWidget::SetMinSize()
102 setMinimumSize( 16, 16 );
105 void VideoWidget::release( void *p_win )
109 /**********************************************************************
110 * Background Widget. Show a simple image background. Currently,
111 * it's a static cone.
112 **********************************************************************/
113 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
114 QFrame( NULL ), p_intf( _p_i )
117 setAutoFillBackground( true );
119 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
120 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
123 label = new QLabel( "" );
124 label->setMaximumHeight( ICON_SIZE );
125 label->setMaximumWidth( ICON_SIZE );
126 label->setScaledContents( true );
127 label->setPixmap( QPixmap( ":/vlc128.png" ) );
128 backgroundLayout = new QHBoxLayout;
129 backgroundLayout->addWidget( label );
130 setLayout( backgroundLayout );
133 BackgroundWidget::~BackgroundWidget()
135 backgroundLayout->takeAt( 0 );
136 delete backgroundLayout;
139 void BackgroundWidget::setArt( QString url )
142 label->setPixmap( QPixmap( ":/vlc128.png" ) );
144 label->setPixmap( QPixmap( url ) );
147 QSize BackgroundWidget::sizeHint() const
152 void BackgroundWidget::resizeEvent( QResizeEvent *e )
154 if( e->size().height() < ICON_SIZE -1 )
155 label->setMaximumWidth( e->size().height() );
157 label->setMaximumWidth( ICON_SIZE );
160 /**********************************************************************
161 * Visualization selector panel
162 **********************************************************************/
163 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
164 QFrame( NULL ), p_intf( _p_i )
166 QHBoxLayout *layout = new QHBoxLayout( this );
167 layout->setMargin( 0 );
168 QPushButton *prevButton = new QPushButton( "Prev" );
169 QPushButton *nextButton = new QPushButton( "Next" );
170 layout->addWidget( prevButton );
171 layout->addWidget( nextButton );
173 layout->addItem( new QSpacerItem( 40,20,
174 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
175 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
177 current = new QLabel( qtr( "None" ) );
178 layout->addWidget( current );
180 BUTTONACT( prevButton, prev() );
181 BUTTONACT( nextButton, next() );
184 setMaximumHeight( 35 );
187 VisualSelector::~VisualSelector()
191 void VisualSelector::prev()
193 char *psz_new = aout_VisualPrev( p_intf );
196 current->setText( qfu( psz_new ) );
201 void VisualSelector::next()
203 char *psz_new = aout_VisualNext( p_intf );
206 current->setText( qfu( psz_new ) );
211 /**********************************************************************
213 **********************************************************************/
215 #define setupSmallButton( aButton ){ \
216 aButton->setMaximumSize( QSize( 26, 26 ) ); \
217 aButton->setMinimumSize( QSize( 26, 26 ) ); \
218 aButton->setIconSize( QSize( 20, 20 ) ); }
220 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
221 QFrame( NULL ), p_intf( _p_i )
223 QHBoxLayout *advLayout = new QHBoxLayout( this );
224 advLayout->setMargin( 0 );
225 advLayout->setSpacing( 0 );
227 /* FIXME A to B function */
228 ABButton = new QPushButton( "AB" );
229 ABButton->setMaximumSize( QSize( 26, 26 ) );
230 ABButton->setIconSize( QSize( 20, 20 ) );
231 advLayout->addWidget( ABButton );
232 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
234 snapshotButton = new QPushButton( "S" );
235 snapshotButton->setMaximumSize( QSize( 26, 26 ) );
236 snapshotButton->setIconSize( QSize( 20, 20 ) );
237 advLayout->addWidget( snapshotButton );
238 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
240 //FIXME Frame by frame function
241 frameButton = new QPushButton( "Fr" );
242 frameButton->setMaximumSize( QSize( 26, 26 ) );
243 frameButton->setIconSize( QSize( 20, 20 ) );
244 advLayout->addWidget( frameButton );
245 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
247 /* FIXME Record function */
248 recordButton = new QPushButton( "R" );
249 recordButton->setMaximumSize( QSize( 26, 26 ) );
250 recordButton->setIconSize( QSize( 20, 20 ) );
251 advLayout->addWidget( recordButton );
252 BUTTON_SET_ACT( recordButton, "R", qtr( "Record" ), record() );
254 normalButton = new QPushButton( "N" );
255 normalButton->setMaximumSize( QSize( 26, 26 ) );
256 normalButton->setIconSize( QSize( 20, 20 ) );
257 advLayout->addWidget( normalButton );
258 BUTTON_SET_ACT( normalButton, "N", qtr( "Normal rate" ), normal() );
262 AdvControlsWidget::~AdvControlsWidget()
266 void AdvControlsWidget::enableInput( bool enable )
268 // slowerButton->setEnabled( enable );
269 ABButton->setEnabled( enable );
270 recordButton->setEnabled( enable );
271 normalButton->setEnabled( enable );
272 // fasterButton->setEnabled( enable );
274 void AdvControlsWidget::enableVideo( bool enable )
276 snapshotButton->setEnabled( enable );
277 frameButton->setEnabled( enable );
278 //fullscreenButton->setEnabled( enable );
281 void AdvControlsWidget::normal()
283 THEMIM->getIM()->normalRate();
286 void AdvControlsWidget::snapshot()
288 vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
289 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
292 void AdvControlsWidget::frame(){}
293 void AdvControlsWidget::fromAtoB(){}
294 void AdvControlsWidget::record(){}
296 /*****************************
297 * DA Control Widget !
298 *****************************/
299 ControlsWidget::ControlsWidget( intf_thread_t *_p_i, bool b_advControls ) :
300 QFrame( NULL ), p_intf( _p_i )
302 //QSize size( 500, 200 );
304 controlLayout = new QGridLayout( this );
308 palette2.setColor(this->backgroundRole(), Qt::magenta);
309 setPalette(palette2);
312 /** The main Slider **/
313 slider = new InputSlider( Qt::Horizontal, NULL );
314 controlLayout->addWidget( slider, 0, 1, 1, 16 );
315 /* Update the position when the IM has changed */
316 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
317 slider, setPosition( float,int, int ) );
318 /* And update the IM, when the position has changed */
319 CONNECT( slider, sliderDragged( float ),
320 THEMIM->getIM(), sliderUpdate( float ) );
322 /** Slower and faster Buttons **/
323 slowerButton = new QPushButton( "S" );
324 BUTTON_SET_ACT( slowerButton, "S", qtr( "Slower" ), slower() );
325 controlLayout->addWidget( slowerButton, 0, 0 );
326 slowerButton->setMaximumSize( QSize( 26, 20 ) );
328 fasterButton = new QPushButton( "F" );
329 BUTTON_SET_ACT( fasterButton, "F", qtr( "Faster" ), faster() );
330 controlLayout->addWidget( fasterButton, 0, 17 );
331 fasterButton->setMaximumSize( QSize( 26, 20 ) );
333 /** TODO: Insert here the AdvControls Widget
334 * Then fix all the size issues in main_interface.cpp
336 /* advanced Controls handling */
337 b_advancedVisible = b_advControls;
339 advControls = new AdvControlsWidget( p_intf );
340 controlLayout->addWidget( advControls, 1, 3, 2, 5, Qt::AlignBottom );
341 if( !b_advancedVisible ) advControls->hide();
342 //THIS should be removed. need_components_update = true;
344 /** Disc and Menus handling */
345 discFrame = new QFrame( this );
347 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
348 discLayout->setSpacing( 0 );
349 discLayout->setMargin( 0 );
351 prevSectionButton = new QPushButton( discFrame );
352 setupSmallButton( prevSectionButton );
353 discLayout->addWidget( prevSectionButton );
355 menuButton = new QPushButton( discFrame );
356 setupSmallButton( menuButton );
357 discLayout->addWidget( menuButton );
359 nextSectionButton = new QPushButton( discFrame );
360 setupSmallButton( nextSectionButton );
361 discLayout->addWidget( nextSectionButton );
363 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
365 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
366 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
367 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
371 /* Change the navigation button display when the IM navigation changes */
372 CONNECT( THEMIM->getIM(), navigationChanged( int ),
373 this, setNavigation( int ) );
374 /* Changes the IM navigation when triggered on the nav buttons */
375 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
377 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
379 CONNECT( menuButton, clicked(), THEMIM->getIM(),
387 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
388 sizePolicy.setHorizontalStretch( 0 );
389 sizePolicy.setVerticalStretch( 0 );
390 // sizePolicy.setHeightForWidth( playButton->sizePolicy().hasHeightForWidth() );
393 playButton = new QPushButton;
394 playButton->setSizePolicy( sizePolicy );
395 playButton->setMaximumSize( QSize( 45, 45 ) );
396 playButton->setIconSize( QSize( 30, 30 ) );
398 controlLayout->addWidget( playButton, 2, 0, 2, 2, Qt::AlignBottom );
400 controlLayout->setColumnMinimumWidth( 2, 20 );
401 controlLayout->setColumnStretch( 2, 0 );
403 /** Prev + Stop + Next Block **/
404 QHBoxLayout *controlButLayout = new QHBoxLayout;
405 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
408 QPushButton *prevButton = new QPushButton;
409 prevButton->setSizePolicy( sizePolicy );
410 setupSmallButton( prevButton );
412 controlButLayout->addWidget( prevButton );
415 QPushButton *stopButton = new QPushButton;
416 stopButton->setSizePolicy( sizePolicy );
417 setupSmallButton( stopButton );
419 controlButLayout->addWidget( stopButton );
422 QPushButton *nextButton = new QPushButton;
423 nextButton->setSizePolicy( sizePolicy );
424 setupSmallButton( nextButton );
426 controlButLayout->addWidget( nextButton );
428 /* Add this block to the main layout */
429 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
431 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
432 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
433 qtr( "Previous" ), prev() );
434 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
435 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
437 controlLayout->setColumnStretch( 8 , 10 );
438 controlLayout->setColumnStretch( 9, 0 );
441 * Other first Line buttons
442 * Might need to be inside a frame to avoid a few resizing pb
445 /** Fullscreen/Visualisation **/
446 fullscreenButton = new QPushButton( "F" );
447 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
448 setupSmallButton( fullscreenButton );
449 controlLayout->addWidget( fullscreenButton, 3, 10 );
451 /** Playlist Button **/
452 playlistButton = new QPushButton;
453 setupSmallButton( playlistButton );
455 controlLayout->addWidget( playlistButton, 3, 11 );
457 /** extended Settings **/
458 QPushButton *extSettingsButton = new QPushButton( "F" );
459 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
461 setupSmallButton( extSettingsButton );
462 controlLayout->addWidget( extSettingsButton, 3, 12 );
465 QPushButton *prefsButton = new QPushButton( "P" );
466 BUTTON_SET_ACT( prefsButton, "P", qtr( "Preferences / Settings" ),
468 setupSmallButton( prefsButton );
469 controlLayout->addWidget( prefsButton, 3, 13 );
471 controlLayout->setColumnStretch( 14, 5 );
474 VolumeClickHandler *h = new VolumeClickHandler( p_intf, this );
476 QLabel *volMuteLabel = new QLabel;
477 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
478 volMuteLabel->setToolTip( qtr( "Mute" ) );
479 volMuteLabel->installEventFilter( h );
482 * Change this slider to use a nice Amarok-like one
483 * Add a Context menu to change to the most useful %
486 * THis percerntage thing has to be handled correctly
487 * This has to match to the OSD
489 volumeSlider = new QSlider;
490 volumeSlider->setSizePolicy( sizePolicy );
491 volumeSlider->setMaximumSize( QSize( 80, 200 ) );
492 volumeSlider->setOrientation( Qt::Horizontal );
494 volumeSlider->setMaximum( 100 );
495 volumeSlider->setFocusPolicy( Qt::NoFocus );
496 controlLayout->addWidget( volMuteLabel, 3, 15 );
497 controlLayout->addWidget( volumeSlider, 3, 16, 1, 2 );
499 /* Volume control connection */
500 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
503 ControlsWidget::~ControlsWidget()
506 void ControlsWidget::stop()
511 void ControlsWidget::play()
514 msg_Dbg( p_intf, "There is %i playlist items", THEPL->items.i_size ); /* FIXME: remove me */
515 if( playlist_IsEmpty( THEPL ) )
517 /* The playlist is empty, open a file requester */
518 THEDP->openFileDialog();
522 THEMIM->togglePlayPause();
525 void ControlsWidget::prev()
530 void ControlsWidget::next()
535 void ControlsWidget::setNavigation( int navigation )
537 #define HELP_MENU N_( "Menu" )
538 #define HELP_PCH N_( "Previous chapter" )
539 #define HELP_NCH N_( "Next chapter" )
540 #define HELP_PTR N_( "Previous track" )
541 #define HELP_NTR N_( "Next track" )
543 // 1 = chapter, 2 = title, 0 = no
544 if( navigation == 0 )
547 } else if( navigation == 1 ) {
548 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
549 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
553 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
554 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
560 static bool b_my_volume;
561 void ControlsWidget::updateVolume( int sliderVolume )
565 int i_res = sliderVolume * AOUT_VOLUME_MAX /
566 ( 2*volumeSlider->maximum() );
567 aout_VolumeSet( p_intf, i_res );
571 void ControlsWidget::updateOnTimer()
574 audio_volume_t i_volume;
575 aout_VolumeGet( p_intf, &i_volume );
576 i_volume = ( i_volume * 200 )/ AOUT_VOLUME_MAX ;
577 int i_gauge = volumeSlider->value();
579 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
582 volumeSlider->setValue( i_volume );
586 /* Activate the interface buttons according to the presence of the input */
587 enableInput( THEMIM->getIM()->hasInput() );
589 //enableVideo( THEMIM->getIM()->hasVideo() );
592 void ControlsWidget::setStatus( int status )
594 if( status == PLAYING_S ) // Playing
595 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
597 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
602 * This functions toggle the fullscreen mode
603 * If there is no video, it should first activate Visualisations...
604 * This has also to be fixed in enableVideo()
606 void ControlsWidget::fullscreen()
608 vout_thread_t *p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_CHILD );
611 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
615 void ControlsWidget::extSettings()
617 THEDP->extendedDialog();
619 void ControlsWidget::prefs()
621 THEDP->prefsDialog();
624 void ControlsWidget::slower()
626 THEMIM->getIM()->slower();
629 void ControlsWidget::faster()
631 THEMIM->getIM()->faster();
634 void ControlsWidget::enableInput( bool enable )
636 slowerButton->setEnabled( enable );
637 slider->setEnabled( enable );
638 fasterButton->setEnabled( enable );
640 /* Advanced Buttons too */
641 advControls->enableInput( enable );
644 void ControlsWidget::enableVideo( bool enable )
646 // TODO Later make the fullscreenButton toggle Visualisation and so on.
647 fullscreenButton->setEnabled( enable );
649 /* Advanced Buttons too */
650 advControls->enableVideo( enable );
653 void ControlsWidget::toggleAdvanced()
655 if( !VISIBLE( advControls ) )
658 b_advancedVisible = true;
663 b_advancedVisible = false;
665 //FIXME connect this one :D
666 emit advancedControlsToggled( b_advancedVisible ); // doComponentsUpdate();
669 /**********************************************************************
670 * Playlist Widget. The embedded playlist
671 **********************************************************************/
672 #include "components/playlist/panels.hpp"
673 #include "components/playlist/selector.hpp"
675 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) :
678 /* Left Part and design */
679 QWidget *leftW = new QWidget( this );
680 QVBoxLayout *left = new QVBoxLayout( leftW );
682 /* Source Selector */
683 selector = new PLSelector( this, p_intf, THEPL );
684 left->addWidget( selector );
687 art = new QLabel( "" );
688 art->setMinimumHeight( 128 );
689 art->setMinimumWidth( 128 );
690 art->setMaximumHeight( 128 );
691 art->setMaximumWidth( 128 );
692 art->setScaledContents( true );
693 art->setPixmap( QPixmap( ":/noart.png" ) );
694 left->addWidget( art );
696 /* Initialisation of the playlist */
697 playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
698 THEPL->p_local_category );
700 rightPanel = qobject_cast<PLPanel *>( new StandardPLPanel( this,
701 p_intf, THEPL, p_root ) );
704 CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
706 CONNECT( qobject_cast<StandardPLPanel *>( rightPanel )->model,
707 artSet( QString ) , this, setArt( QString ) );
708 /* Forward removal requests from the selector to the main panel */
709 CONNECT( qobject_cast<PLSelector *>( selector )->model,
711 qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );
713 connect( selector, SIGNAL( activated( int ) ),
714 this, SIGNAL( rootChanged( int ) ) );
715 emit rootChanged( p_root->i_id );
717 /* Add the two sides of the QSplitter */
719 addWidget( rightPanel );
721 leftW->setMaximumWidth( 250 );
722 setCollapsible( 1, false );
725 sizeList << 180 << 520 ;
726 setSizes( sizeList );
729 void PlaylistWidget::setArt( QString url )
732 art->setPixmap( QPixmap( ":/noart.png" ) );
733 else if( prevArt != url )
734 art->setPixmap( QPixmap( url ) );
739 PlaylistWidget::~PlaylistWidget()
743 QSize PlaylistWidget::sizeHint() const