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 **********************************************************************/
214 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
215 QFrame( NULL ), p_intf( _p_i )
217 QHBoxLayout *layout = new QHBoxLayout( this );
218 layout->setMargin( 0 );
220 normalButton = new QPushButton( "N" );
221 BUTTON_SET_ACT( normalButton, "N", qtr( "Normal rate" ), normal() );
222 layout->addWidget( normalButton );
223 normalButton->setMaximumWidth( 35 );
226 layout->addItem( new QSpacerItem( 100,20,
227 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
229 snapshotButton = new QPushButton( "S" );
230 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
231 layout->addWidget( snapshotButton );
232 snapshotButton->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, 20 ) );
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, 20 ) );
292 /** TODO: Insert here the AdvControls Widget
293 * and add - A->B button
296 * and put the snapshot in the same QFrame
297 * Then fix all the size issues in main_interface.cpp
300 /** Disc and Menus handling */
301 discFrame = new QFrame( this );
302 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
304 QPushButton *menuButton = new QPushButton( discFrame );
305 discLayout->addWidget( menuButton );
307 QPushButton *prevSectionButton = new QPushButton( discFrame );
308 discLayout->addWidget( prevSectionButton );
310 QPushButton *nextSectionButton = new QPushButton( discFrame );
311 discLayout->addWidget( nextSectionButton );
313 controlLayout->addWidget( discFrame, 1, 13, 1, 4 );
315 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
316 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
317 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
321 /* Change the navigation button display when the IM navigation changes */
322 CONNECT( THEMIM->getIM(), navigationChanged( int ),
323 this, setNavigation( int ) );
324 /* Changes the IM navigation when triggered on the nav buttons */
325 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
327 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
329 CONNECT( menuButton, clicked(), THEMIM->getIM(),
337 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
338 sizePolicy.setHorizontalStretch( 0 );
339 sizePolicy.setVerticalStretch( 0 );
340 // sizePolicy.setHeightForWidth( playButton->sizePolicy().hasHeightForWidth() );
343 QPushButton *playButton = new QPushButton;
344 playButton->setSizePolicy( sizePolicy );
345 playButton->setMaximumSize( QSize( 45, 45 ) );
346 playButton->setIconSize( QSize( 30, 30 ) );
348 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
350 /** Prev + Stop + Next Block **/
351 QHBoxLayout *controlButLayout = new QHBoxLayout;
352 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
355 QPushButton *prevButton = new QPushButton;
356 prevButton->setSizePolicy( sizePolicy );
357 prevButton->setMaximumSize( QSize( 26, 26 ) );
358 prevButton->setIconSize( QSize( 20, 20 ) );
360 controlButLayout->addWidget( prevButton );
363 QPushButton *stopButton = new QPushButton;
364 stopButton->setSizePolicy( sizePolicy );
365 stopButton->setMaximumSize( QSize( 26, 26 ) );
366 stopButton->setIconSize( QSize( 20, 20 ) );
368 controlButLayout->addWidget( stopButton );
371 QPushButton *nextButton = new QPushButton;
372 nextButton->setSizePolicy( sizePolicy );
373 nextButton->setMaximumSize( QSize( 26, 26 ) );
374 nextButton->setIconSize( QSize( 20, 20 ) );
376 controlButLayout->addWidget( nextButton );
378 /* Add this block to the main layout */
379 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
381 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
382 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
383 qtr( "Previous" ), prev() );
384 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
385 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
388 * Other first Line buttons
389 * Might need to be inside a frame to avoid a few resizing pb
392 /** Fullscreen/Visualisation **/
393 fullscreenButton = new QPushButton( "F" );
394 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
395 fullscreenButton->setMaximumSize( QSize( 26, 26 ) );
396 controlLayout->addWidget( fullscreenButton, 3, 10 );
398 /** Playlist Button **/
399 playlistButton = new QPushButton;
400 playlistButton->setMaximumSize( QSize( 26, 26 ) );
401 playlistButton->setIconSize( QSize( 20, 20 ) );
403 controlLayout->addWidget( playlistButton, 3, 11 );
405 /** extended Settings **/
406 QPushButton *extSettingsButton = new QPushButton( "F" );
407 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
409 extSettingsButton->setMaximumSize( QSize( 26, 26 ) );
410 controlLayout->addWidget( extSettingsButton, 3, 12 );
413 QPushButton *prefsButton = new QPushButton( "P" );
414 BUTTON_SET_ACT( prefsButton, "P", qtr( "Preferences / Settings" ), prefs() );
415 prefsButton->setMaximumSize( QSize( 26, 26 ) );
416 controlLayout->addWidget( prefsButton, 3, 13 );
419 VolumeClickHandler *h = new VolumeClickHandler( p_intf, this );
421 QLabel *volMuteLabel = new QLabel;
422 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
423 volMuteLabel->setToolTip( qtr( "Mute" ) );
424 volMuteLabel->installEventFilter( h );
427 * Change this slider to use a nice Amarok-like one
428 * Add a Context menu to change to the most useful %
431 * THis percerntage thing has to be handled correctly
432 * This has to match to the OSD
434 volumeSlider = new QSlider;
435 volumeSlider->setSizePolicy( sizePolicy );
436 volumeSlider->setMaximumSize( QSize( 80, 200 ) );
437 volumeSlider->setOrientation( Qt::Horizontal );
439 volumeSlider->setMaximum( 100 );
440 volumeSlider->setFocusPolicy( Qt::NoFocus );
441 controlLayout->addWidget( volMuteLabel, 3, 14 );
442 controlLayout->addWidget( volumeSlider, 3, 15, 1, 2 );
444 /* Volume control connection */
445 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
448 ControlsWidget::~ControlsWidget()
451 void ControlsWidget::stop()
456 void ControlsWidget::play()
458 if( playlist_IsEmpty( THEPL ) )
460 /* The playlist is empty, open a file requester */
461 THEDP->openFileDialog();
465 THEMIM->togglePlayPause();
468 void ControlsWidget::prev()
473 void ControlsWidget::next()
478 void ControlsWidget::setNavigation( int navigation )
480 #define HELP_MENU N_( "Menu" )
481 #define HELP_PCH N_( "Previous chapter" )
482 #define HELP_NCH N_( "Next chapter" )
483 #define HELP_PTR N_( "Previous track" )
484 #define HELP_NTR N_( "Next track" )
486 // 1 = chapter, 2 = title, 0 = no
487 if( navigation == 0 )
490 } else if( navigation == 1 ) {
491 prevSectionButton->show();
492 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
493 nextSectionButton->show();
494 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
498 prevSectionButton->show();
499 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
500 nextSectionButton->show();
501 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
507 static bool b_my_volume;
508 void ControlsWidget::updateVolume( int sliderVolume )
512 int i_res = sliderVolume * AOUT_VOLUME_MAX /
513 ( 2*volumeSlider->maximum() );
514 aout_VolumeSet( p_intf, i_res );
518 void ControlsWidget::updateOnTimer()
520 audio_volume_t i_volume;
521 aout_VolumeGet( p_intf, &i_volume );
522 i_volume = ( i_volume * 200 )/ AOUT_VOLUME_MAX ;
523 int i_gauge = volumeSlider->value();
525 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
528 volumeSlider->setValue( i_volume );
534 void ControlsWidget::setStatus( int status )
536 if( status == 1 ) // Playing
538 msg_Dbg( p_intf, "I was here %i", status );
539 // playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
543 msg_Dbg( p_intf, "I was here %i", status );
544 // playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
550 * This functions toggle the fullscreen mode
551 * If there is no video, it should first activate Visualisations...
552 * This has also to be fixed in enableVideo()
554 void ControlsWidget::fullscreen()
556 msg_Dbg( p_intf, "Not implemented yet" );
559 void ControlsWidget::extSettings()
561 THEDP->extendedDialog();
563 void ControlsWidget::prefs()
565 THEDP->prefsDialog();
568 void ControlsWidget::slower()
570 THEMIM->getIM()->slower();
573 void ControlsWidget::faster()
575 THEMIM->getIM()->faster();
578 void ControlsWidget::enableInput( bool enable )
580 slowerButton->setEnabled( enable );
581 slider->setEnabled( enable );
582 fasterButton->setEnabled( enable );
585 void ControlsWidget::enableVideo( bool enable )
587 // TODO Later make the fullscreenButton toggle Visualisation and so on.
588 fullscreenButton->setEnabled( enable );
592 /**********************************************************************
593 * Playlist Widget. The embedded playlist
594 **********************************************************************/
595 #include "components/playlist/panels.hpp"
596 #include "components/playlist/selector.hpp"
598 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) :
601 /* Left Part and design */
602 QWidget *leftW = new QWidget( this );
603 QVBoxLayout *left = new QVBoxLayout( leftW );
605 /* Source Selector */
606 selector = new PLSelector( this, p_intf, THEPL );
607 left->addWidget( selector );
610 art = new QLabel( "" );
611 art->setMinimumHeight( 128 );
612 art->setMinimumWidth( 128 );
613 art->setMaximumHeight( 128 );
614 art->setMaximumWidth( 128 );
615 art->setScaledContents( true );
616 art->setPixmap( QPixmap( ":/noart.png" ) );
617 left->addWidget( art );
619 /* Initialisation of the playlist */
620 playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
621 THEPL->p_local_category );
623 rightPanel = qobject_cast<PLPanel *>( new StandardPLPanel( this,
624 p_intf, THEPL, p_root ) );
627 CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
629 CONNECT( qobject_cast<StandardPLPanel *>( rightPanel )->model,
630 artSet( QString ) , this, setArt( QString ) );
631 /* Forward removal requests from the selector to the main panel */
632 CONNECT( qobject_cast<PLSelector *>( selector )->model,
634 qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );
636 connect( selector, SIGNAL( activated( int ) ),
637 this, SIGNAL( rootChanged( int ) ) );
638 emit rootChanged( p_root->i_id );
640 /* Add the two sides of the QSplitter */
642 addWidget( rightPanel );
644 leftW->setMaximumWidth( 250 );
645 setCollapsible( 1, false );
648 sizeList << 180 << 520 ;
649 setSizes( sizeList );
652 void PlaylistWidget::setArt( QString url )
655 art->setPixmap( QPixmap( ":/noart.png" ) );
656 else if( prevArt != url )
657 art->setPixmap( QPixmap( url ) );
662 PlaylistWidget::~PlaylistWidget()
666 QSize PlaylistWidget::sizeHint() const