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 /** Fullscreen/Visualisation **/
381 fullscreenButton = new QPushButton( "F" );
382 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
383 fullscreenButton->setMaximumSize( QSize( 26, 26 ) );
384 controlLayout->addWidget( fullscreenButton, 3, 11 );
386 /** Playlist Button **/
387 playlistButton = new QPushButton;
388 playlistButton->setMaximumSize( QSize( 26, 26 ) );
389 playlistButton->setIconSize( QSize( 20, 20 ) );
391 controlLayout->addWidget( playlistButton, 3, 10 );
393 /** extended Settings **/
394 QPushButton *extSettingsButton = new QPushButton( "F" );
395 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
397 extSettingsButton->setMaximumSize( QSize( 26, 26 ) );
398 controlLayout->addWidget( extSettingsButton, 3, 12 );
401 QPushButton *prefsButton = new QPushButton( "P" );
402 BUTTON_SET_ACT( prefsButton, "P", qtr( "Preferences / Settings" ), prefs() );
403 prefsButton->setMaximumSize( QSize( 26, 26 ) );
404 controlLayout->addWidget( prefsButton, 3, 13 );
407 VolumeClickHandler *h = new VolumeClickHandler( p_intf, this );
409 QLabel *volMuteLabel = new QLabel;
410 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
411 volMuteLabel->setToolTip( qtr( "Mute" ) );
412 volMuteLabel->installEventFilter( h );
414 volumeSlider = new QSlider;
415 volumeSlider->setSizePolicy( sizePolicy );
416 volumeSlider->setMaximumSize( QSize( 80, 200 ) );
417 volumeSlider->setOrientation( Qt::Horizontal );
419 volumeSlider->setMaximum( 100 );
420 volumeSlider->setFocusPolicy( Qt::NoFocus );
421 controlLayout->addWidget( volMuteLabel, 3, 14 );
422 controlLayout->addWidget( volumeSlider, 3, 15, 1, 2 );
424 /* Volume control connection */
425 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
428 ControlsWidget::~ControlsWidget()
431 void ControlsWidget::stop()
436 void ControlsWidget::play()
438 if( playlist_IsEmpty( THEPL ) )
440 /* The playlist is empty, open a file requester */
441 THEDP->openFileDialog();
445 THEMIM->togglePlayPause();
448 void ControlsWidget::prev()
453 void ControlsWidget::next()
458 void ControlsWidget::setNavigation( int navigation )
460 #define HELP_MENU N_( "Menu" )
461 #define HELP_PCH N_( "Previous chapter" )
462 #define HELP_NCH N_( "Next chapter" )
463 #define HELP_PTR N_( "Previous track" )
464 #define HELP_NTR N_( "Next track" )
466 // 1 = chapter, 2 = title, 0 = no
467 if( navigation == 0 )
470 } else if( navigation == 1 ) {
471 prevSectionButton->show();
472 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
473 nextSectionButton->show();
474 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
478 prevSectionButton->show();
479 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
480 nextSectionButton->show();
481 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
487 static bool b_my_volume;
488 void ControlsWidget::updateVolume( int sliderVolume )
492 int i_res = sliderVolume * AOUT_VOLUME_MAX /
493 ( 2*volumeSlider->maximum() );
494 aout_VolumeSet( p_intf, i_res );
498 void ControlsWidget::updateOnTimer()
500 audio_volume_t i_volume;
501 aout_VolumeGet( p_intf, &i_volume );
502 i_volume = ( i_volume * 200 )/ AOUT_VOLUME_MAX ;
503 int i_gauge = volumeSlider->value();
505 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
508 volumeSlider->setValue( i_volume );
514 void ControlsWidget::setStatus( int status )
516 if( status == 1 ) // Playing
518 msg_Dbg( p_intf, "I was here %i", status );
519 // playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
523 msg_Dbg( p_intf, "I was here %i", status );
524 // playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
529 * This functions toggle the fullscreen mode
530 * If there is no video, it should first activate Visualisations... TODO
532 void ControlsWidget::fullscreen()
534 msg_Dbg( p_intf, "Not implemented yet" );
537 void ControlsWidget::extSettings()
539 THEDP->extendedDialog();
541 void ControlsWidget::prefs()
543 THEDP->prefsDialog();
546 void ControlsWidget::slower()
548 THEMIM->getIM()->slower();
551 void ControlsWidget::faster()
553 THEMIM->getIM()->faster();
556 void ControlsWidget::enableInput( bool enable )
558 slowerButton->setEnabled( enable );
559 slider->setEnabled( enable );
560 fasterButton->setEnabled( enable );
563 void ControlsWidget::enableVideo( bool enable )
565 // TODO Later make the fullscreenButton toggle Visualisation and so on.
566 fullscreenButton->setEnabled( enable );
570 /**********************************************************************
571 * Playlist Widget. The embedded playlist
572 **********************************************************************/
573 #include "components/playlist/panels.hpp"
574 #include "components/playlist/selector.hpp"
576 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) :
579 /* Left Part and design */
580 QWidget *leftW = new QWidget( this );
581 QVBoxLayout *left = new QVBoxLayout( leftW );
583 /* Source Selector */
584 selector = new PLSelector( this, p_intf, THEPL );
585 left->addWidget( selector );
588 art = new QLabel( "" );
589 art->setMinimumHeight( 128 );
590 art->setMinimumWidth( 128 );
591 art->setMaximumHeight( 128 );
592 art->setMaximumWidth( 128 );
593 art->setScaledContents( true );
594 art->setPixmap( QPixmap( ":/noart.png" ) );
595 left->addWidget( art );
597 /* Initialisation of the playlist */
598 playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
599 THEPL->p_local_category );
601 rightPanel = qobject_cast<PLPanel *>( new StandardPLPanel( this,
602 p_intf, THEPL, p_root ) );
605 CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
607 CONNECT( qobject_cast<StandardPLPanel *>( rightPanel )->model,
608 artSet( QString ) , this, setArt( QString ) );
609 /* Forward removal requests from the selector to the main panel */
610 CONNECT( qobject_cast<PLSelector *>( selector )->model,
612 qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );
614 connect( selector, SIGNAL( activated( int ) ),
615 this, SIGNAL( rootChanged( int ) ) );
616 emit rootChanged( p_root->i_id );
618 /* Add the two sides of the QSplitter */
620 addWidget( rightPanel );
622 leftW->setMaximumWidth( 250 );
623 setCollapsible( 1, false );
626 sizeList << 180 << 520 ;
627 setSizes( sizeList );
630 void PlaylistWidget::setArt( QString url )
633 art->setPixmap( QPixmap( ":/noart.png" ) );
634 else if( prevArt != url )
635 art->setPixmap( QPixmap( url ) );
640 PlaylistWidget::~PlaylistWidget()
644 QSize PlaylistWidget::sizeHint() const