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 slowerButton = new QPushButton( "S" );
216 BUTTON_SET_ACT( slowerButton, "S", qtr("Slower" ), slower() );
217 layout->addWidget( slowerButton );
218 slowerButton->setMaximumWidth( 35 );
220 normalButton = new QPushButton( "N" );
221 BUTTON_SET_ACT( normalButton, "N", qtr("Normal rate"), normal() );
222 layout->addWidget( normalButton );
223 normalButton->setMaximumWidth( 35 );
225 fasterButton = new QPushButton( "F" );
226 BUTTON_SET_ACT( fasterButton, "F", qtr("Faster" ), faster() );
227 layout->addWidget( fasterButton );
228 fasterButton->setMaximumWidth( 35 );
230 layout->addItem( new QSpacerItem( 100,20,
231 QSizePolicy::Expanding, QSizePolicy::Minimum) );
233 snapshotButton = new QPushButton( "S" );
234 BUTTON_SET_ACT( snapshotButton, "S", qtr("Take a snapshot"), snapshot() );
235 layout->addWidget( snapshotButton );
236 snapshotButton->setMaximumWidth( 35 );
238 fullscreenButton = new QPushButton( "F" );
239 BUTTON_SET_ACT( fullscreenButton, "F", qtr("Fullscreen"), fullscreen() );
240 layout->addWidget( fullscreenButton );
241 fullscreenButton->setMaximumWidth( 35 );
244 AdvControlsWidget::~AdvControlsWidget()
248 void AdvControlsWidget::enableInput( bool enable )
250 slowerButton->setEnabled( enable );
251 normalButton->setEnabled( enable );
252 fasterButton->setEnabled( enable );
254 void AdvControlsWidget::enableVideo( bool enable )
256 snapshotButton->setEnabled( enable );
257 fullscreenButton->setEnabled( enable );
260 void AdvControlsWidget::slower()
262 THEMIM->getIM()->slower();
265 void AdvControlsWidget::faster()
267 THEMIM->getIM()->faster();
270 void AdvControlsWidget::normal()
272 THEMIM->getIM()->normalRate();
275 void AdvControlsWidget::snapshot()
279 void AdvControlsWidget::fullscreen()
283 ControlsWidget::ControlsWidget( intf_thread_t *_p_i ) :
284 QFrame( NULL ), p_intf( _p_i )
286 //QSize size( 500, 200 );
288 controlLayout = new QGridLayout( this );
290 /** The main Slider **/
291 slider = new InputSlider( Qt::Horizontal, NULL );
292 controlLayout->addWidget( slider, 0, 1, 1, 14 );
293 /* Update the position when the IM has changed */
294 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
295 slider, setPosition( float,int, int ) );
296 /* And update the IM, when the position has changed */
297 CONNECT( slider, sliderDragged( float ),
298 THEMIM->getIM(), sliderUpdate( float ) );
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(),
333 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
334 sizePolicy.setHorizontalStretch( 0 );
335 sizePolicy.setVerticalStretch( 0 );
336 // sizePolicy.setHeightForWidth( playButton->sizePolicy( ).hasHeightForWidth( ) );
339 QPushButton *playButton = new QPushButton;
340 playButton->setSizePolicy( sizePolicy );
341 playButton->setMaximumSize( QSize( 45, 45 ) );
342 playButton->setIconSize( QSize( 30, 30 ) );
344 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
346 /** Prev + Stop + Next Block **/
347 QHBoxLayout *controlButLayout = new QHBoxLayout;
348 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
351 QPushButton *prevButton = new QPushButton;
352 prevButton->setSizePolicy( sizePolicy );
353 prevButton->setMaximumSize( QSize( 26, 26 ) );
354 prevButton->setIconSize( QSize( 20, 20 ) );
356 controlButLayout->addWidget( prevButton );
359 QPushButton *stopButton = new QPushButton;
360 stopButton->setSizePolicy( sizePolicy );
361 stopButton->setMaximumSize( QSize( 26, 26 ) );
362 stopButton->setIconSize( QSize( 20, 20 ) );
364 controlButLayout->addWidget( stopButton );
367 QPushButton *nextButton = new QPushButton;
368 nextButton->setSizePolicy( sizePolicy );
369 nextButton->setMaximumSize( QSize( 26, 26 ) );
370 nextButton->setIconSize( QSize( 20, 20 ) );
372 controlButLayout->addWidget( nextButton );
374 /* Add this block to the main layout */
375 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3 );
377 BUTTON_SET_ACT_I( playButton, "", play.png, qtr("Play"), play() );
378 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
379 qtr("Previous"), prev() );
380 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr("Next"), next() );
381 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr("Stop"), stop() );
384 * Other first Line buttons
385 * Might need to be inside a frame to avoid a few resizing pb
388 /** Playlist Button **/
389 playlistButton = new QPushButton;
390 playlistButton->setMaximumSize(QSize(45, 45));
392 controlLayout->addWidget( playlistButton, 3, 10 );
394 /** Fullscreen/Visualisation **/
395 QPushButton *fullscreenButton = new QPushButton( "F" );
396 BUTTON_SET_ACT( fullscreenButton, "F", qtr("Fullscreen"), fullscreen() );
397 fullscreenButton->setMaximumSize( QSize( 26, 26 ) );
398 controlLayout->addWidget( fullscreenButton, 3, 11 );
400 /** extended Settings **/
401 QPushButton *extSettingsButton = new QPushButton( "F" );
402 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr("Extended Settings"),
404 extSettingsButton->setMaximumSize( QSize( 26, 26 ) );
405 controlLayout->addWidget( extSettingsButton, 3, 12 );
408 QPushButton *prefsButton = new QPushButton( "P" );
409 BUTTON_SET_ACT( prefsButton, "P", qtr("Preferences / Settings"), prefs() );
410 prefsButton->setMaximumSize( QSize( 26, 26 ) );
411 controlLayout->addWidget( prefsButton, 3, 13 );
414 VolumeClickHandler *h = new VolumeClickHandler( p_intf, this );
416 QLabel *volMuteLabel = new QLabel;
417 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
418 volMuteLabel->setToolTip( qtr( "Mute" ) );
419 volMuteLabel->installEventFilter(h);
421 volumeSlider = new QSlider;
422 volumeSlider->setSizePolicy( sizePolicy );
423 volumeSlider->setMaximumSize( QSize(80, 200) );
424 volumeSlider->setOrientation( Qt::Horizontal );
426 volumeSlider->setMaximum( 100 );
427 volumeSlider->setFocusPolicy( Qt::NoFocus );
428 controlLayout->addWidget( volMuteLabel, 3, 14 );
429 controlLayout->addWidget( volumeSlider, 3, 15, 1, 2 );
431 /* Volume control connection */
432 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
435 ControlsWidget::~ControlsWidget()
438 void ControlsWidget::stop()
443 void ControlsWidget::play()
445 if( playlist_IsEmpty(THEPL) )
447 /* The playlist is empty, open a file requester */
448 THEDP->openFileDialog();
452 THEMIM->togglePlayPause();
455 void ControlsWidget::prev()
460 void ControlsWidget::next()
465 void ControlsWidget::setNavigation( int navigation )
467 #define HELP_MENU N_("Menu")
468 #define HELP_PCH N_("Previous chapter")
469 #define HELP_NCH N_("Next chapter")
470 #define HELP_PTR N_("Previous track")
471 #define HELP_NTR N_("Next track")
473 // 1 = chapter, 2 = title, 0 = no
474 if( navigation == 0 )
477 } else if( navigation == 1 ) {
478 prevSectionButton->show();
479 prevSectionButton->setToolTip( qfu(HELP_PCH) );
480 nextSectionButton->show();
481 nextSectionButton->setToolTip( qfu(HELP_NCH) );
485 prevSectionButton->show();
486 prevSectionButton->setToolTip( qfu(HELP_PCH) );
487 nextSectionButton->show();
488 nextSectionButton->setToolTip( qfu(HELP_NCH) );
494 static bool b_my_volume;
495 void ControlsWidget::updateVolume( int sliderVolume )
499 int i_res = sliderVolume * AOUT_VOLUME_MAX /
500 ( 2*volumeSlider->maximum() );
501 aout_VolumeSet( p_intf, i_res );
505 void ControlsWidget::updateOnTimer()
507 audio_volume_t i_volume;
508 aout_VolumeGet( p_intf, &i_volume );
509 i_volume = (i_volume * 200 )/ AOUT_VOLUME_MAX ;
510 int i_gauge = volumeSlider->value();
512 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
515 volumeSlider->setValue( i_volume );
519 void ControlsWidget::setStatus( int status )
521 if( status == 1 ) // Playing
522 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
524 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
527 * This functions toggle the fullscreen mode
528 * If there is no video, it should first activate Visualisations... TODO
530 void ControlsWidget::fullscreen()
532 msg_Dbg(p_intf, "Not implemented yet");
535 void ControlsWidget::extSettings()
537 THEDP->extendedDialog();
539 void ControlsWidget::prefs()
541 THEDP->prefsDialog();
544 /**********************************************************************
545 * Playlist Widget. The embedded playlist
546 **********************************************************************/
547 #include "components/playlist/panels.hpp"
548 #include "components/playlist/selector.hpp"
550 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) :
553 /* Left Part and design */
554 QWidget *leftW = new QWidget( this );
555 QVBoxLayout *left = new QVBoxLayout( leftW );
557 /* Source Selector */
558 selector = new PLSelector( this, p_intf, THEPL );
559 left->addWidget( selector );
562 art = new QLabel( "" );
563 art->setMinimumHeight( 128 );
564 art->setMinimumWidth( 128 );
565 art->setMaximumHeight( 128 );
566 art->setMaximumWidth( 128 );
567 art->setScaledContents( true );
568 art->setPixmap( QPixmap( ":/noart.png" ) );
569 left->addWidget( art );
571 /* Initialisation of the playlist */
572 playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
573 THEPL->p_local_category );
575 rightPanel = qobject_cast<PLPanel *>(new StandardPLPanel( this,
576 p_intf, THEPL, p_root ) );
579 CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
581 CONNECT( qobject_cast<StandardPLPanel *>(rightPanel)->model,
582 artSet( QString ) , this, setArt( QString ) );
583 /* Forward removal requests from the selector to the main panel */
584 CONNECT( qobject_cast<PLSelector *>(selector)->model,
586 qobject_cast<StandardPLPanel *>(rightPanel), removeItem(int) );
588 connect( selector, SIGNAL(activated( int )),
589 this, SIGNAL( rootChanged( int ) ) );
590 emit rootChanged( p_root->i_id );
592 /* Add the two sides of the QSplitter */
594 addWidget( rightPanel );
596 leftW->setMaximumWidth( 250 );
597 setCollapsible( 1, false );
600 sizeList << 180 << 520 ;
601 setSizes( sizeList );
604 void PlaylistWidget::setArt( QString url )
607 art->setPixmap( QPixmap( ":/noart.png" ) );
608 else if( prevArt != url )
609 art->setPixmap( QPixmap( url ) );
614 PlaylistWidget::~PlaylistWidget()
618 QSize PlaylistWidget::sizeHint() const