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 );
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" );
96 setMinimumSize( 16, 16 );
97 return ( void* )winId();
100 void VideoWidget::release( void *p_win )
104 /**********************************************************************
105 * Background Widget. Show a simple image background. Currently,
106 * it's a static cone.
107 **********************************************************************/
108 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
109 QFrame( NULL ), p_intf( _p_i )
112 setAutoFillBackground( true );
114 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
115 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
118 label = new QLabel( "" );
119 label->setMaximumHeight( ICON_SIZE );
120 label->setMaximumWidth( ICON_SIZE );
121 label->setScaledContents( true );
122 label->setPixmap( QPixmap( ":/vlc128.png" ) );
123 backgroundLayout = new QHBoxLayout;
124 backgroundLayout->addWidget( label );
125 setLayout( backgroundLayout );
128 BackgroundWidget::~BackgroundWidget()
130 backgroundLayout->takeAt( 0 );
131 delete backgroundLayout;
134 void BackgroundWidget::setArt( QString url )
137 label->setPixmap( QPixmap( ":/vlc128.png" ) );
139 label->setPixmap( QPixmap( url ) );
142 QSize BackgroundWidget::sizeHint() const
147 void BackgroundWidget::resizeEvent( QResizeEvent *e )
149 if( e->size().height() < ICON_SIZE -1 )
150 label->setMaximumWidth( e->size().height() );
152 label->setMaximumWidth( ICON_SIZE );
155 /**********************************************************************
156 * Visualization selector panel
157 **********************************************************************/
158 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
159 QFrame( NULL ), p_intf( _p_i )
161 QHBoxLayout *layout = new QHBoxLayout( this );
162 layout->setMargin( 0 );
163 QPushButton *prevButton = new QPushButton( "Prev" );
164 QPushButton *nextButton = new QPushButton( "Next" );
165 layout->addWidget( prevButton );
166 layout->addWidget( nextButton );
168 layout->addItem( new QSpacerItem( 40,20,
169 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
170 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
172 current = new QLabel( qtr( "None" ) );
173 layout->addWidget( current );
175 BUTTONACT( prevButton, prev() );
176 BUTTONACT( nextButton, next() );
179 setMaximumHeight( 35 );
182 VisualSelector::~VisualSelector()
186 void VisualSelector::prev()
188 char *psz_new = aout_VisualPrev( p_intf );
191 current->setText( qfu( psz_new ) );
196 void VisualSelector::next()
198 char *psz_new = aout_VisualNext( p_intf );
201 current->setText( qfu( psz_new ) );
206 /**********************************************************************
208 **********************************************************************/
209 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
210 QFrame( NULL ), p_intf( _p_i )
212 QHBoxLayout *layout = new QHBoxLayout( this );
213 layout->setMargin( 0 );
215 normalButton = new QPushButton( "N" );
216 BUTTON_SET_ACT( normalButton, "N", qtr( "Normal rate" ), normal() );
217 layout->addWidget( normalButton );
218 normalButton->setMaximumWidth( 35 );
221 layout->addItem( new QSpacerItem( 100,20,
222 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
224 snapshotButton = new QPushButton( "S" );
225 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
226 layout->addWidget( snapshotButton );
227 snapshotButton->setMaximumWidth( 35 );
229 fullscreenButton = new QPushButton( "F" );
230 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
231 layout->addWidget( fullscreenButton );
232 fullscreenButton->setMaximumWidth( 35 );
235 AdvControlsWidget::~AdvControlsWidget()
239 void AdvControlsWidget::enableInput( bool enable )
241 // slowerButton->setEnabled( enable );
242 normalButton->setEnabled( enable );
243 // fasterButton->setEnabled( enable );
245 void AdvControlsWidget::enableVideo( bool enable )
247 snapshotButton->setEnabled( enable );
248 fullscreenButton->setEnabled( enable );
251 void AdvControlsWidget::normal()
253 THEMIM->getIM()->normalRate();
256 void AdvControlsWidget::snapshot()
260 void AdvControlsWidget::fullscreen()
264 ControlsWidget::ControlsWidget( intf_thread_t *_p_i ) :
265 QFrame( NULL ), p_intf( _p_i )
267 //QSize size( 500, 200 );
269 controlLayout = new QGridLayout( this );
271 /** The main Slider **/
272 slider = new InputSlider( Qt::Horizontal, NULL );
273 controlLayout->addWidget( slider, 0, 1, 1, 15 );
274 /* Update the position when the IM has changed */
275 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
276 slider, setPosition( float,int, int ) );
277 /* And update the IM, when the position has changed */
278 CONNECT( slider, sliderDragged( float ),
279 THEMIM->getIM(), sliderUpdate( float ) );
281 /** Slower and faster Buttons **/
282 slowerButton = new QPushButton( "S" );
283 BUTTON_SET_ACT( slowerButton, "S", qtr( "Slower" ), slower() );
284 controlLayout->addWidget( slowerButton, 0, 0 );
285 slowerButton->setMaximumSize( QSize( 26, 26 ) );
287 fasterButton = new QPushButton( "F" );
288 BUTTON_SET_ACT( fasterButton, "F", qtr( "Faster" ), faster() );
289 controlLayout->addWidget( fasterButton, 0, 16 );
290 fasterButton->setMaximumSize( QSize( 26, 26 ) );
292 /** Disc and Menus handling */
293 discFrame = new QFrame( this );
294 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
296 QPushButton *menuButton = new QPushButton( discFrame );
297 discLayout->addWidget( menuButton );
299 QPushButton *prevSectionButton = new QPushButton( discFrame );
300 discLayout->addWidget( prevSectionButton );
302 QPushButton *nextSectionButton = new QPushButton( discFrame );
303 discLayout->addWidget( nextSectionButton );
305 controlLayout->addWidget( discFrame, 1, 13, 1, 4 );
307 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
308 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
309 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
313 /* Change the navigation button display when the IM navigation changes */
314 CONNECT( THEMIM->getIM(), navigationChanged( int ),
315 this, setNavigation( int ) );
316 /* Changes the IM navigation when triggered on the nav buttons */
317 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
319 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
321 CONNECT( menuButton, clicked(), THEMIM->getIM(),
325 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
326 sizePolicy.setHorizontalStretch( 0 );
327 sizePolicy.setVerticalStretch( 0 );
328 // sizePolicy.setHeightForWidth( playButton->sizePolicy().hasHeightForWidth() );
331 QPushButton *playButton = new QPushButton;
332 playButton->setSizePolicy( sizePolicy );
333 playButton->setMaximumSize( QSize( 26, 26 ) );
334 playButton->setIconSize( QSize( 20, 20 ) );
336 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
338 /** Prev + Stop + Next Block **/
339 QHBoxLayout *controlButLayout = new QHBoxLayout;
340 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
343 QPushButton *prevButton = new QPushButton;
344 prevButton->setSizePolicy( sizePolicy );
345 prevButton->setMaximumSize( QSize( 26, 26 ) );
346 prevButton->setIconSize( QSize( 20, 20 ) );
348 controlButLayout->addWidget( prevButton );
351 QPushButton *stopButton = new QPushButton;
352 stopButton->setSizePolicy( sizePolicy );
353 stopButton->setMaximumSize( QSize( 26, 26 ) );
354 stopButton->setIconSize( QSize( 20, 20 ) );
356 controlButLayout->addWidget( stopButton );
359 QPushButton *nextButton = new QPushButton;
360 nextButton->setSizePolicy( sizePolicy );
361 nextButton->setMaximumSize( QSize( 26, 26 ) );
362 nextButton->setIconSize( QSize( 20, 20 ) );
364 controlButLayout->addWidget( nextButton );
366 /* Add this block to the main layout */
367 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
369 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
370 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
371 qtr( "Previous" ), prev() );
372 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
373 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
376 * Other first Line buttons
377 * Might need to be inside a frame to avoid a few resizing pb
380 /** Playlist Button **/
381 playlistButton = new QPushButton;
382 playlistButton->setMaximumSize( QSize( 26, 26 ) );
384 controlLayout->addWidget( playlistButton, 3, 10 );
386 /** Fullscreen/Visualisation **/
387 QPushButton *fullscreenButton = new QPushButton( "F" );
388 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
389 fullscreenButton->setMaximumSize( QSize( 26, 26 ) );
390 controlLayout->addWidget( fullscreenButton, 3, 11 );
392 /** extended Settings **/
393 QPushButton *extSettingsButton = new QPushButton( "F" );
394 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
396 extSettingsButton->setMaximumSize( QSize( 26, 26 ) );
397 controlLayout->addWidget( extSettingsButton, 3, 12 );
400 QPushButton *prefsButton = new QPushButton( "P" );
401 BUTTON_SET_ACT( prefsButton, "P", qtr( "Preferences / Settings" ), prefs() );
402 prefsButton->setMaximumSize( QSize( 26, 26 ) );
403 controlLayout->addWidget( prefsButton, 3, 13 );
406 VolumeClickHandler *h = new VolumeClickHandler( p_intf, this );
408 QLabel *volMuteLabel = new QLabel;
409 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
410 volMuteLabel->setToolTip( qtr( "Mute" ) );
411 volMuteLabel->installEventFilter( h );
413 volumeSlider = new QSlider;
414 volumeSlider->setSizePolicy( sizePolicy );
415 volumeSlider->setMaximumSize( QSize( 80, 200 ) );
416 volumeSlider->setOrientation( Qt::Horizontal );
418 volumeSlider->setMaximum( 100 );
419 volumeSlider->setFocusPolicy( Qt::NoFocus );
420 controlLayout->addWidget( volMuteLabel, 3, 14 );
421 controlLayout->addWidget( volumeSlider, 3, 15, 1, 2 );
423 /* Volume control connection */
424 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
427 ControlsWidget::~ControlsWidget()
430 void ControlsWidget::stop()
435 void ControlsWidget::play()
437 if( playlist_IsEmpty( THEPL ) )
439 /* The playlist is empty, open a file requester */
440 THEDP->openFileDialog();
444 THEMIM->togglePlayPause();
447 void ControlsWidget::prev()
452 void ControlsWidget::next()
457 void ControlsWidget::setNavigation( int navigation )
459 #define HELP_MENU N_( "Menu" )
460 #define HELP_PCH N_( "Previous chapter" )
461 #define HELP_NCH N_( "Next chapter" )
462 #define HELP_PTR N_( "Previous track" )
463 #define HELP_NTR N_( "Next track" )
465 // 1 = chapter, 2 = title, 0 = no
466 if( navigation == 0 )
469 } else if( navigation == 1 ) {
470 prevSectionButton->show();
471 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
472 nextSectionButton->show();
473 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
477 prevSectionButton->show();
478 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
479 nextSectionButton->show();
480 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
486 static bool b_my_volume;
487 void ControlsWidget::updateVolume( int sliderVolume )
491 int i_res = sliderVolume * AOUT_VOLUME_MAX /
492 ( 2*volumeSlider->maximum() );
493 aout_VolumeSet( p_intf, i_res );
497 void ControlsWidget::updateOnTimer()
499 audio_volume_t i_volume;
500 aout_VolumeGet( p_intf, &i_volume );
501 i_volume = ( i_volume * 200 )/ AOUT_VOLUME_MAX ;
502 int i_gauge = volumeSlider->value();
504 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
507 volumeSlider->setValue( i_volume );
513 void ControlsWidget::setStatus( int status )
515 if( status == 1 ) // Playing
517 msg_Dbg( p_intf, "I was here %i", status );
518 // playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
522 msg_Dbg( p_intf, "I was here %i", status );
523 // playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
528 * This functions toggle the fullscreen mode
529 * If there is no video, it should first activate Visualisations... TODO
531 void ControlsWidget::fullscreen()
533 msg_Dbg( p_intf, "Not implemented yet" );
536 void ControlsWidget::extSettings()
538 THEDP->extendedDialog();
540 void ControlsWidget::prefs()
542 THEDP->prefsDialog();
545 void ControlsWidget::slower()
547 THEMIM->getIM()->slower();
550 void ControlsWidget::faster()
552 THEMIM->getIM()->faster();
555 void ControlsWidget::enableInput( bool enable )
557 slowerButton->setEnabled( enable );
558 slider->setEnabled( enable );
559 fasterButton->setEnabled( enable );
562 /**********************************************************************
563 * Playlist Widget. The embedded playlist
564 **********************************************************************/
565 #include "components/playlist/panels.hpp"
566 #include "components/playlist/selector.hpp"
568 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) :
571 /* Left Part and design */
572 QWidget *leftW = new QWidget( this );
573 QVBoxLayout *left = new QVBoxLayout( leftW );
575 /* Source Selector */
576 selector = new PLSelector( this, p_intf, THEPL );
577 left->addWidget( selector );
580 art = new QLabel( "" );
581 art->setMinimumHeight( 128 );
582 art->setMinimumWidth( 128 );
583 art->setMaximumHeight( 128 );
584 art->setMaximumWidth( 128 );
585 art->setScaledContents( true );
586 art->setPixmap( QPixmap( ":/noart.png" ) );
587 left->addWidget( art );
589 /* Initialisation of the playlist */
590 playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
591 THEPL->p_local_category );
593 rightPanel = qobject_cast<PLPanel *>( new StandardPLPanel( this,
594 p_intf, THEPL, p_root ) );
597 CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
599 CONNECT( qobject_cast<StandardPLPanel *>( rightPanel )->model,
600 artSet( QString ) , this, setArt( QString ) );
601 /* Forward removal requests from the selector to the main panel */
602 CONNECT( qobject_cast<PLSelector *>( selector )->model,
604 qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );
606 connect( selector, SIGNAL( activated( int ) ),
607 this, SIGNAL( rootChanged( int ) ) );
608 emit rootChanged( p_root->i_id );
610 /* Add the two sides of the QSplitter */
612 addWidget( rightPanel );
614 leftW->setMaximumWidth( 250 );
615 setCollapsible( 1, false );
618 sizeList << 180 << 520 ;
619 setSizes( sizeList );
622 void PlaylistWidget::setArt( QString url )
625 art->setPixmap( QPixmap( ":/noart.png" ) );
626 else if( prevArt != url )
627 art->setPixmap( QPixmap( url ) );
632 PlaylistWidget::~PlaylistWidget()
636 QSize PlaylistWidget::sizeHint() const