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 );
230 AdvControlsWidget::~AdvControlsWidget()
234 void AdvControlsWidget::enableInput( bool enable )
236 // slowerButton->setEnabled( enable );
237 normalButton->setEnabled( enable );
238 // fasterButton->setEnabled( enable );
240 void AdvControlsWidget::enableVideo( bool enable )
242 snapshotButton->setEnabled( enable );
243 //fullscreenButton->setEnabled( enable );
246 void AdvControlsWidget::normal()
248 THEMIM->getIM()->normalRate();
251 void AdvControlsWidget::snapshot()
255 void AdvControlsWidget::fullscreen()
259 ControlsWidget::ControlsWidget( intf_thread_t *_p_i ) :
260 QFrame( NULL ), p_intf( _p_i )
262 //QSize size( 500, 200 );
264 controlLayout = new QGridLayout( this );
266 /** The main Slider **/
267 slider = new InputSlider( Qt::Horizontal, NULL );
268 controlLayout->addWidget( slider, 0, 1, 1, 15 );
269 /* Update the position when the IM has changed */
270 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
271 slider, setPosition( float,int, int ) );
272 /* And update the IM, when the position has changed */
273 CONNECT( slider, sliderDragged( float ),
274 THEMIM->getIM(), sliderUpdate( float ) );
276 /** Slower and faster Buttons **/
277 slowerButton = new QPushButton( "S" );
278 BUTTON_SET_ACT( slowerButton, "S", qtr( "Slower" ), slower() );
279 controlLayout->addWidget( slowerButton, 0, 0 );
280 slowerButton->setMaximumSize( QSize( 26, 20 ) );
282 fasterButton = new QPushButton( "F" );
283 BUTTON_SET_ACT( fasterButton, "F", qtr( "Faster" ), faster() );
284 controlLayout->addWidget( fasterButton, 0, 16 );
285 fasterButton->setMaximumSize( QSize( 26, 20 ) );
287 /** Disc and Menus handling */
288 discFrame = new QFrame( this );
289 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
291 QPushButton *menuButton = new QPushButton( discFrame );
292 discLayout->addWidget( menuButton );
294 QPushButton *prevSectionButton = new QPushButton( discFrame );
295 discLayout->addWidget( prevSectionButton );
297 QPushButton *nextSectionButton = new QPushButton( discFrame );
298 discLayout->addWidget( nextSectionButton );
300 controlLayout->addWidget( discFrame, 1, 13, 1, 4 );
302 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
303 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
304 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
308 /* Change the navigation button display when the IM navigation changes */
309 CONNECT( THEMIM->getIM(), navigationChanged( int ),
310 this, setNavigation( int ) );
311 /* Changes the IM navigation when triggered on the nav buttons */
312 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
314 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
316 CONNECT( menuButton, clicked(), THEMIM->getIM(),
320 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
321 sizePolicy.setHorizontalStretch( 0 );
322 sizePolicy.setVerticalStretch( 0 );
323 // sizePolicy.setHeightForWidth( playButton->sizePolicy().hasHeightForWidth() );
326 QPushButton *playButton = new QPushButton;
327 playButton->setSizePolicy( sizePolicy );
328 playButton->setMaximumSize( QSize( 45, 45 ) );
329 playButton->setIconSize( QSize( 30, 30 ) );
331 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
333 /** Prev + Stop + Next Block **/
334 QHBoxLayout *controlButLayout = new QHBoxLayout;
335 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
338 QPushButton *prevButton = new QPushButton;
339 prevButton->setSizePolicy( sizePolicy );
340 prevButton->setMaximumSize( QSize( 26, 26 ) );
341 prevButton->setIconSize( QSize( 20, 20 ) );
343 controlButLayout->addWidget( prevButton );
346 QPushButton *stopButton = new QPushButton;
347 stopButton->setSizePolicy( sizePolicy );
348 stopButton->setMaximumSize( QSize( 26, 26 ) );
349 stopButton->setIconSize( QSize( 20, 20 ) );
351 controlButLayout->addWidget( stopButton );
354 QPushButton *nextButton = new QPushButton;
355 nextButton->setSizePolicy( sizePolicy );
356 nextButton->setMaximumSize( QSize( 26, 26 ) );
357 nextButton->setIconSize( QSize( 20, 20 ) );
359 controlButLayout->addWidget( nextButton );
361 /* Add this block to the main layout */
362 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
364 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
365 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
366 qtr( "Previous" ), prev() );
367 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
368 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
371 * Other first Line buttons
372 * Might need to be inside a frame to avoid a few resizing pb
375 /** Fullscreen/Visualisation **/
376 fullscreenButton = new QPushButton( "F" );
377 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
378 fullscreenButton->setMaximumSize( QSize( 26, 26 ) );
379 controlLayout->addWidget( fullscreenButton, 3, 10 );
381 /** Playlist Button **/
382 playlistButton = new QPushButton;
383 playlistButton->setMaximumSize( QSize( 26, 26 ) );
384 playlistButton->setIconSize( QSize( 20, 20 ) );
386 controlLayout->addWidget( playlistButton, 3, 11 );
388 /** extended Settings **/
389 QPushButton *extSettingsButton = new QPushButton( "F" );
390 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
392 extSettingsButton->setMaximumSize( QSize( 26, 26 ) );
393 controlLayout->addWidget( extSettingsButton, 3, 12 );
396 QPushButton *prefsButton = new QPushButton( "P" );
397 BUTTON_SET_ACT( prefsButton, "P", qtr( "Preferences / Settings" ), prefs() );
398 prefsButton->setMaximumSize( QSize( 26, 26 ) );
399 controlLayout->addWidget( prefsButton, 3, 13 );
402 VolumeClickHandler *h = new VolumeClickHandler( p_intf, this );
404 QLabel *volMuteLabel = new QLabel;
405 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
406 volMuteLabel->setToolTip( qtr( "Mute" ) );
407 volMuteLabel->installEventFilter( h );
409 volumeSlider = new QSlider;
410 volumeSlider->setSizePolicy( sizePolicy );
411 volumeSlider->setMaximumSize( QSize( 80, 200 ) );
412 volumeSlider->setOrientation( Qt::Horizontal );
414 volumeSlider->setMaximum( 100 );
415 volumeSlider->setFocusPolicy( Qt::NoFocus );
416 controlLayout->addWidget( volMuteLabel, 3, 14 );
417 controlLayout->addWidget( volumeSlider, 3, 15, 1, 2 );
419 /* Volume control connection */
420 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
423 ControlsWidget::~ControlsWidget()
426 void ControlsWidget::stop()
431 void ControlsWidget::play()
433 if( playlist_IsEmpty( THEPL ) )
435 /* The playlist is empty, open a file requester */
436 THEDP->openFileDialog();
440 THEMIM->togglePlayPause();
443 void ControlsWidget::prev()
448 void ControlsWidget::next()
453 void ControlsWidget::setNavigation( int navigation )
455 #define HELP_MENU N_( "Menu" )
456 #define HELP_PCH N_( "Previous chapter" )
457 #define HELP_NCH N_( "Next chapter" )
458 #define HELP_PTR N_( "Previous track" )
459 #define HELP_NTR N_( "Next track" )
461 // 1 = chapter, 2 = title, 0 = no
462 if( navigation == 0 )
465 } else if( navigation == 1 ) {
466 prevSectionButton->show();
467 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
468 nextSectionButton->show();
469 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
473 prevSectionButton->show();
474 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
475 nextSectionButton->show();
476 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
482 static bool b_my_volume;
483 void ControlsWidget::updateVolume( int sliderVolume )
487 int i_res = sliderVolume * AOUT_VOLUME_MAX /
488 ( 2*volumeSlider->maximum() );
489 aout_VolumeSet( p_intf, i_res );
493 void ControlsWidget::updateOnTimer()
495 audio_volume_t i_volume;
496 aout_VolumeGet( p_intf, &i_volume );
497 i_volume = ( i_volume * 200 )/ AOUT_VOLUME_MAX ;
498 int i_gauge = volumeSlider->value();
500 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
503 volumeSlider->setValue( i_volume );
509 void ControlsWidget::setStatus( int status )
511 if( status == 1 ) // Playing
513 msg_Dbg( p_intf, "I was here %i", status );
514 // playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
518 msg_Dbg( p_intf, "I was here %i", status );
519 // playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
524 * This functions toggle the fullscreen mode
525 * If there is no video, it should first activate Visualisations... TODO
527 void ControlsWidget::fullscreen()
529 msg_Dbg( p_intf, "Not implemented yet" );
532 void ControlsWidget::extSettings()
534 THEDP->extendedDialog();
536 void ControlsWidget::prefs()
538 THEDP->prefsDialog();
541 void ControlsWidget::slower()
543 THEMIM->getIM()->slower();
546 void ControlsWidget::faster()
548 THEMIM->getIM()->faster();
551 void ControlsWidget::enableInput( bool enable )
553 slowerButton->setEnabled( enable );
554 slider->setEnabled( enable );
555 fasterButton->setEnabled( enable );
558 void ControlsWidget::enableVideo( bool enable )
560 // TODO Later make the fullscreenButton toggle Visualisation and so on.
561 fullscreenButton->setEnabled( enable );
565 /**********************************************************************
566 * Playlist Widget. The embedded playlist
567 **********************************************************************/
568 #include "components/playlist/panels.hpp"
569 #include "components/playlist/selector.hpp"
571 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) :
574 /* Left Part and design */
575 QWidget *leftW = new QWidget( this );
576 QVBoxLayout *left = new QVBoxLayout( leftW );
578 /* Source Selector */
579 selector = new PLSelector( this, p_intf, THEPL );
580 left->addWidget( selector );
583 art = new QLabel( "" );
584 art->setMinimumHeight( 128 );
585 art->setMinimumWidth( 128 );
586 art->setMaximumHeight( 128 );
587 art->setMaximumWidth( 128 );
588 art->setScaledContents( true );
589 art->setPixmap( QPixmap( ":/noart.png" ) );
590 left->addWidget( art );
592 /* Initialisation of the playlist */
593 playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
594 THEPL->p_local_category );
596 rightPanel = qobject_cast<PLPanel *>( new StandardPLPanel( this,
597 p_intf, THEPL, p_root ) );
600 CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
602 CONNECT( qobject_cast<StandardPLPanel *>( rightPanel )->model,
603 artSet( QString ) , this, setArt( QString ) );
604 /* Forward removal requests from the selector to the main panel */
605 CONNECT( qobject_cast<PLSelector *>( selector )->model,
607 qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );
609 connect( selector, SIGNAL( activated( int ) ),
610 this, SIGNAL( rootChanged( int ) ) );
611 emit rootChanged( p_root->i_id );
613 /* Add the two sides of the QSplitter */
615 addWidget( rightPanel );
617 leftW->setMaximumWidth( 250 );
618 setCollapsible( 1, false );
621 sizeList << 180 << 520 ;
622 setSizes( sizeList );
625 void PlaylistWidget::setArt( QString url )
628 art->setPixmap( QPixmap( ":/noart.png" ) );
629 else if( prevArt != url )
630 art->setPixmap( QPixmap( url ) );
635 PlaylistWidget::~PlaylistWidget()
639 QSize PlaylistWidget::sizeHint() const