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>
9 * Rafaël Carré <funman@videolanorg>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * ( at your option ) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 #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"
32 #include "util/customwidgets.hpp"
36 #include <QSpacerItem>
38 #include <QPushButton>
39 #include <QHBoxLayout>
42 #include <QResizeEvent>
44 /**********************************************************************
45 * Video Widget. A simple frame on which video is drawn
46 * This class handles resize issues
47 **********************************************************************/
48 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
49 unsigned int *, unsigned int * );
50 static void DoRelease( intf_thread_t *, void * );
51 static int DoControl( intf_thread_t *, void *, int, va_list );
53 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
55 vlc_mutex_init( p_intf, &lock );
58 CONNECT( this, askResize(), this, SetMinSize() );
59 CONNECT( this, askVideoToShow(), this, show() );
60 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
63 VideoWidget::~VideoWidget()
65 vlc_mutex_lock( &lock );
68 if( !p_intf->psz_switch_intf )
70 if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
71 vout_Control( p_vout, VOUT_REPARENT );
75 if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
76 vout_Control( p_vout, VOUT_CLOSE );
79 vlc_mutex_unlock( &lock );
80 vlc_mutex_destroy( &lock );
83 QSize VideoWidget::sizeHint() const
88 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
89 unsigned int *pi_width, unsigned int *pi_height )
91 emit askVideoToShow();
94 msg_Dbg( p_intf, "embedded video already in use" );
99 return ( void* )winId();
102 void VideoWidget::SetMinSize()
104 setMinimumSize( 16, 16 );
107 void VideoWidget::release( void *p_win )
113 /**********************************************************************
114 * Background Widget. Show a simple image background. Currently,
115 * it's a static cone.
116 **********************************************************************/
117 #define ICON_SIZE 128
118 #define MAX_BG_SIZE 400
119 #define MIN_BG_SIZE 64
121 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
122 QFrame( NULL ), p_intf( _p_i )
124 /* We should use that one to take the more size it can */
125 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding );
127 /* A dark background */
128 setAutoFillBackground( true );
130 plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
131 plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
134 /* A cone in the middle */
136 // label->setScaledContents( true );
137 label->setMargin( 5 );
138 label->setMaximumHeight( MAX_BG_SIZE );
139 label->setMaximumWidth( MAX_BG_SIZE );
140 label->setMinimumHeight( MIN_BG_SIZE );
141 label->setMinimumWidth( MIN_BG_SIZE );
142 label->setPixmap( QPixmap( ":/vlc128.png" ) );
144 QHBoxLayout *backgroundLayout = new QHBoxLayout( this );
145 backgroundLayout->addWidget( label );
151 BackgroundWidget::~BackgroundWidget()
154 void BackgroundWidget::setArt( QString url )
157 label->setPixmap( QPixmap( ":/vlc128.png" ) );
159 label->setPixmap( QPixmap( url ) );
163 QSize BackgroundWidget::sizeHint() const
165 return label->size();
168 void BackgroundWidget::resizeEvent( QResizeEvent *e )
170 msg_Dbg( p_intf, "BG size, %i, %i", e->size().width(), e->size().height() );
171 if( e->size().height() < label->height() )
173 label->resize( e->size().height(), e->size().height() );
177 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
179 QVLCMenu::PopupMenu( p_intf, true );
182 /**********************************************************************
183 * Visualization selector panel
184 **********************************************************************/
185 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
186 QFrame( NULL ), p_intf( _p_i )
188 QHBoxLayout *layout = new QHBoxLayout( this );
189 layout->setMargin( 0 );
190 QPushButton *prevButton = new QPushButton( "Prev" );
191 QPushButton *nextButton = new QPushButton( "Next" );
192 layout->addWidget( prevButton );
193 layout->addWidget( nextButton );
195 layout->addItem( new QSpacerItem( 40,20,
196 QSizePolicy::Expanding, QSizePolicy::Minimum ) );
197 layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
199 current = new QLabel( qtr( "None" ) );
200 layout->addWidget( current );
202 BUTTONACT( prevButton, prev() );
203 BUTTONACT( nextButton, next() );
206 setMaximumHeight( 35 );
209 VisualSelector::~VisualSelector()
213 void VisualSelector::prev()
215 char *psz_new = aout_VisualPrev( p_intf );
218 current->setText( qfu( psz_new ) );
223 void VisualSelector::next()
225 char *psz_new = aout_VisualNext( p_intf );
228 current->setText( qfu( psz_new ) );
233 /**********************************************************************
235 **********************************************************************/
237 #define setupSmallButton( aButton ){ \
238 aButton->setMaximumSize( QSize( 26, 26 ) ); \
239 aButton->setMinimumSize( QSize( 26, 26 ) ); \
240 aButton->setIconSize( QSize( 20, 20 ) ); }
242 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
243 QFrame( NULL ), p_intf( _p_i )
245 QHBoxLayout *advLayout = new QHBoxLayout( this );
246 advLayout->setMargin( 0 );
247 advLayout->setSpacing( 0 );
250 ABButton = new QPushButton( "AB" );
251 ABButton->setMaximumSize( QSize( 26, 26 ) );
252 ABButton->setIconSize( QSize( 20, 20 ) );
253 advLayout->addWidget( ABButton );
254 BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
256 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
257 this, AtoBLoop( float, int, int ) );
259 //FIXME Frame by frame function
260 frameButton = new QPushButton( "Fr" );
261 frameButton->setMaximumSize( QSize( 26, 26 ) );
262 frameButton->setIconSize( QSize( 20, 20 ) );
263 advLayout->addWidget( frameButton );
264 BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
266 /* FIXME Record function */
267 recordButton = new QPushButton( "R" );
268 recordButton->setMaximumSize( QSize( 26, 26 ) );
269 recordButton->setIconSize( QSize( 20, 20 ) );
270 advLayout->addWidget( recordButton );
271 BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
272 qtr( "Record" ), record() );
274 /* Snapshot Button */
275 snapshotButton = new QPushButton( "S" );
276 snapshotButton->setMaximumSize( QSize( 26, 26 ) );
277 snapshotButton->setIconSize( QSize( 20, 20 ) );
278 advLayout->addWidget( snapshotButton );
279 BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
282 AdvControlsWidget::~AdvControlsWidget()
285 void AdvControlsWidget::enableInput( bool enable )
287 ABButton->setEnabled( enable );
288 recordButton->setEnabled( enable );
291 void AdvControlsWidget::enableVideo( bool enable )
293 snapshotButton->setEnabled( enable );
294 frameButton->setEnabled( enable );
297 void AdvControlsWidget::snapshot()
299 vout_thread_t *p_vout =
300 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
301 if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
304 /* Function called when the button is clicked() */
305 void AdvControlsWidget::fromAtoB()
309 timeA = var_GetTime( THEMIM->getInput(), "time" );
310 ABButton->setText( "A->..." );
315 timeB = var_GetTime( THEMIM->getInput(), "time" );
316 var_SetTime( THEMIM->getInput(), "time" , timeA );
317 ABButton->setText( "A<=>B" );
322 ABButton->setText( "AB" );
325 /* Function called regularly when in an AtoB loop */
326 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
330 if( i_time >= (int)(timeB/1000000) )
331 var_SetTime( THEMIM->getInput(), "time" , timeA );
335 void AdvControlsWidget::record(){}
336 void AdvControlsWidget::frame(){}
338 /*****************************
339 * DA Control Widget !
340 *****************************/
341 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
344 QFrame( NULL ), p_intf( _p_i )
346 controlLayout = new QGridLayout( this );
347 controlLayout->setSpacing( 0 );
348 setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Minimum );
350 /** The main Slider **/
351 slider = new InputSlider( Qt::Horizontal, NULL );
352 controlLayout->addWidget( slider, 0, 1, 1, 16 );
353 /* Update the position when the IM has changed */
354 CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
355 slider, setPosition( float, int, int ) );
356 /* And update the IM, when the position has changed */
357 CONNECT( slider, sliderDragged( float ),
358 THEMIM->getIM(), sliderUpdate( float ) );
360 /** Slower and faster Buttons **/
361 slowerButton = new QPushButton;
362 slowerButton->setFlat( true );
363 slowerButton->setMaximumSize( QSize( 26, 20 ) );
365 BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
366 controlLayout->addWidget( slowerButton, 0, 0 );
368 fasterButton = new QPushButton;
369 fasterButton->setFlat( true );
370 fasterButton->setMaximumSize( QSize( 26, 20 ) );
372 BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
373 controlLayout->addWidget( fasterButton, 0, 17 );
375 /* advanced Controls handling */
376 b_advancedVisible = b_advControls;
378 advControls = new AdvControlsWidget( p_intf );
379 controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
380 if( !b_advancedVisible ) advControls->hide();
382 /** Disc and Menus handling */
383 discFrame = new QFrame( this );
385 QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
386 discLayout->setSpacing( 0 );
387 discLayout->setMargin( 0 );
389 prevSectionButton = new QPushButton( discFrame );
390 setupSmallButton( prevSectionButton );
391 discLayout->addWidget( prevSectionButton );
393 menuButton = new QPushButton( discFrame );
394 setupSmallButton( menuButton );
395 discLayout->addWidget( menuButton );
397 nextSectionButton = new QPushButton( discFrame );
398 setupSmallButton( nextSectionButton );
399 discLayout->addWidget( nextSectionButton );
401 controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
403 BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
404 BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
405 BUTTON_SET_IMG( menuButton, "", previous.png, "" );
409 /* Change the navigation button display when the IM navigation changes */
410 CONNECT( THEMIM->getIM(), navigationChanged( int ),
411 this, setNavigation( int ) );
412 /* Changes the IM navigation when triggered on the nav buttons */
413 CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
415 CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
417 CONNECT( menuButton, clicked(), THEMIM->getIM(),
422 * Merge with upper menu in a StackLayout
426 QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
427 sizePolicy.setHorizontalStretch( 0 );
428 sizePolicy.setVerticalStretch( 0 );
431 playButton = new QPushButton;
432 playButton->setSizePolicy( sizePolicy );
433 playButton->setMaximumSize( QSize( 38, 38 ) );
434 playButton->setMinimumSize( QSize( 45, 45 ) );
435 playButton->setIconSize( QSize( 30, 30 ) );
437 controlLayout->addWidget( playButton, 2, 0, 2, 2 );
439 controlLayout->setColumnMinimumWidth( 2, 20 );
440 controlLayout->setColumnStretch( 2, 0 );
442 /** Prev + Stop + Next Block **/
443 QHBoxLayout *controlButLayout = new QHBoxLayout;
444 controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
447 QPushButton *prevButton = new QPushButton;
448 prevButton->setSizePolicy( sizePolicy );
449 setupSmallButton( prevButton );
451 controlButLayout->addWidget( prevButton );
454 QPushButton *stopButton = new QPushButton;
455 stopButton->setSizePolicy( sizePolicy );
456 setupSmallButton( stopButton );
458 controlButLayout->addWidget( stopButton );
461 QPushButton *nextButton = new QPushButton;
462 nextButton->setSizePolicy( sizePolicy );
463 setupSmallButton( nextButton );
465 controlButLayout->addWidget( nextButton );
467 /* Add this block to the main layout */
468 controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
470 BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
471 BUTTON_SET_ACT_I( prevButton, "" , previous.png,
472 qtr( "Previous" ), prev() );
473 BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
474 BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
476 controlLayout->setColumnStretch( 7 , 2 );
479 * Other first Line buttons
480 * Might need to be inside a frame to avoid a few resizing pb
483 /** Fullscreen/Visualisation **/
484 fullscreenButton = new QPushButton( "F" );
485 BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
486 setupSmallButton( fullscreenButton );
487 controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
489 /** Playlist Button **/
490 playlistButton = new QPushButton;
491 setupSmallButton( playlistButton );
492 controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
493 BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
495 /** extended Settings **/
496 QPushButton *extSettingsButton = new QPushButton( "F" );
497 BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
499 setupSmallButton( extSettingsButton );
500 controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
502 controlLayout->setColumnStretch( 14, 5 );
505 VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
507 volMuteLabel = new QLabel;
508 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
509 volMuteLabel->setToolTip( qtr( "Mute" ) );
510 volMuteLabel->installEventFilter( hVolLabel );
511 controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
515 volumeSlider = new SoundSlider( this,
516 config_GetInt( p_intf, "volume-step" ),
517 config_GetInt( p_intf, "qt-volume-complete" ) );
521 volumeSlider = new QSlider( this );
522 volumeSlider->setOrientation( Qt::Horizontal );
524 volumeSlider->setMaximumSize( QSize( 200, 40 ) );
525 volumeSlider->setMinimumSize( QSize( 80, 20 ) );
526 volumeSlider->setFocusPolicy( Qt::NoFocus );
527 controlLayout->addWidget( volumeSlider, 3, 16, 1, 2, Qt::AlignBottom );
529 /* Set the volume from the config */
530 volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
531 VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
533 /* Volume control connection */
534 resize( QSize( 400, 60 ) );
535 CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
536 msg_Dbg( p_intf, "controls size: %i - %i", size().width(), size().height() );
539 ControlsWidget::~ControlsWidget()
544 QSize ControlsWidget::sizeHint() const
546 return QSize( 300, 50 );
550 void ControlsWidget::stop()
555 void ControlsWidget::play()
557 if( THEPL->current.i_size == 0 )
559 /* The playlist is empty, open a file requester */
560 THEDP->openFileDialog();
564 THEMIM->togglePlayPause();
567 void ControlsWidget::prev()
572 void ControlsWidget::next()
577 void ControlsWidget::setNavigation( int navigation )
579 #define HELP_MENU N_( "Menu" )
580 #define HELP_PCH N_( "Previous chapter" )
581 #define HELP_NCH N_( "Next chapter" )
582 #define HELP_PTR N_( "Previous track" )
583 #define HELP_NTR N_( "Next track" )
585 // 1 = chapter, 2 = title, 0 = no
586 if( navigation == 0 )
589 } else if( navigation == 1 ) {
590 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
591 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
595 prevSectionButton->setToolTip( qfu( HELP_PCH ) );
596 nextSectionButton->setToolTip( qfu( HELP_NCH ) );
602 static bool b_my_volume;
603 void ControlsWidget::updateVolume( int i_sliderVolume )
607 int i_res = i_sliderVolume * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
608 aout_VolumeSet( p_intf, i_res );
610 if( i_sliderVolume == 0 )
611 volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
612 else if( i_sliderVolume < VOLUME_MAX / 2 )
613 volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
614 else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
617 void ControlsWidget::updateOnTimer()
620 audio_volume_t i_volume;
621 aout_VolumeGet( p_intf, &i_volume );
622 i_volume = ( i_volume * VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
623 int i_gauge = volumeSlider->value();
625 if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
628 volumeSlider->setValue( i_volume );
632 /* Activate the interface buttons according to the presence of the input */
633 enableInput( THEMIM->getIM()->hasInput() );
634 //enableVideo( THEMIM->getIM()->hasVideo() );
638 void ControlsWidget::setStatus( int status )
640 if( status == PLAYING_S ) // Playing
641 playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
643 playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
648 * This functions toggle the fullscreen mode
649 * If there is no video, it should first activate Visualisations...
650 * This has also to be fixed in enableVideo()
652 void ControlsWidget::fullscreen()
654 vout_thread_t *p_vout =
655 (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
658 var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
659 vlc_object_release( p_vout );
663 void ControlsWidget::extSettings()
665 THEDP->extendedDialog();
668 void ControlsWidget::slower()
670 THEMIM->getIM()->slower();
673 void ControlsWidget::faster()
675 THEMIM->getIM()->faster();
678 void ControlsWidget::enableInput( bool enable )
680 slowerButton->setEnabled( enable );
681 slider->setEnabled( enable );
682 fasterButton->setEnabled( enable );
684 /* Advanced Buttons too */
685 advControls->enableInput( enable );
688 void ControlsWidget::enableVideo( bool enable )
690 // TODO Later make the fullscreenButton toggle Visualisation and so on.
691 fullscreenButton->setEnabled( enable );
693 /* Advanced Buttons too */
694 advControls->enableVideo( enable );
697 void ControlsWidget::toggleAdvanced()
699 if( !VISIBLE( advControls ) )
702 b_advancedVisible = true;
707 b_advancedVisible = false;
709 //FIXME connect this one :D
710 emit advancedControlsToggled( b_advancedVisible ); // doComponentsUpdate();
713 /**********************************************************************
714 * Playlist Widget. The embedded playlist
715 **********************************************************************/
716 #include "components/playlist/panels.hpp"
717 #include "components/playlist/selector.hpp"
721 PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i, QSettings *settings ) :
724 /* In case we want to keep the splitter informations */
725 settings->beginGroup( "Playlist" );
726 restoreState(settings->value("splitterSizes").toByteArray());
727 settings->endGroup();
729 /* Left Part and design */
730 QWidget *leftW = new QWidget( this );
731 QVBoxLayout *left = new QVBoxLayout( leftW );
733 /* Source Selector */
734 selector = new PLSelector( this, p_intf, THEPL );
735 left->addWidget( selector );
738 art = new QLabel( "" );
739 art->setMinimumHeight( 128 );
740 art->setMinimumWidth( 128 );
741 art->setMaximumHeight( 128 );
742 art->setMaximumWidth( 128 );
743 art->setScaledContents( true );
744 art->setPixmap( QPixmap( ":/noart.png" ) );
745 left->addWidget( art );
747 /* Initialisation of the playlist */
748 playlist_item_t *p_root = playlist_GetPreferredNode( THEPL,
749 THEPL->p_local_category );
751 rightPanel = qobject_cast<PLPanel *>( new StandardPLPanel( this,
752 p_intf, THEPL, p_root ) );
755 CONNECT( selector, activated( int ), rightPanel, setRoot( int ) );
757 CONNECT( qobject_cast<StandardPLPanel *>( rightPanel )->model,
758 artSet( QString ) , this, setArt( QString ) );
759 /* Forward removal requests from the selector to the main panel */
760 CONNECT( qobject_cast<PLSelector *>( selector )->model,
762 qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) );
764 connect( selector, SIGNAL( activated( int ) ),
765 this, SIGNAL( rootChanged( int ) ) );
766 emit rootChanged( p_root->i_id );
768 /* Add the two sides of the QSplitter */
770 addWidget( rightPanel );
772 leftW->setMaximumWidth( 250 );
773 setCollapsible( 1, false );
776 sizeList << 180 << 420 ;
777 setSizes( sizeList );
778 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Expanding );
783 void PlaylistWidget::setArt( QString url )
787 art->setPixmap( QPixmap( ":/noart.png" ) );
790 else if( prevArt != url )
792 art->setPixmap( QPixmap( url ) );
798 QSize PlaylistWidget::sizeHint() const
800 return QSize( 600 , 300 );
803 PlaylistWidget::~PlaylistWidget()
807 void PlaylistWidget::saveSettings( QSettings *settings )
809 settings->beginGroup( "Playlist" );
810 settings->setValue("splitterSizes", saveState() );
811 settings->endGroup();
814 /**********************************************************************
815 * Speed control widget
816 **********************************************************************/
817 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
818 QFrame( NULL ), p_intf( _p_i )
820 QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
821 sizePolicy.setHorizontalStretch( 0 );
822 sizePolicy.setVerticalStretch( 0 );
824 speedSlider = new QSlider;
825 speedSlider->setSizePolicy( sizePolicy );
826 speedSlider->setMaximumSize( QSize( 80, 200 ) );
827 speedSlider->setOrientation( Qt::Vertical );
828 speedSlider->setTickPosition( QSlider::TicksRight );
830 speedSlider->setRange( -100, 100 );
831 speedSlider->setSingleStep( 10 );
832 speedSlider->setPageStep( 20 );
833 speedSlider->setTickInterval( 20 );
835 CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
837 normalSpeedButton = new QPushButton( "N" );
838 normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
839 normalSpeedButton->setFlat( true );
840 normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
842 CONNECT( normalSpeedButton, clicked(), this, resetRate() );
844 QVBoxLayout *speedControlLayout = new QVBoxLayout;
845 speedControlLayout->addWidget(speedSlider);
846 speedControlLayout->addWidget(normalSpeedButton);
847 setLayout(speedControlLayout);
850 SpeedControlWidget::~SpeedControlWidget()
853 #define RATE_SLIDER_MAXIMUM 3.0
854 #define RATE_SLIDER_MINIMUM 0.3
855 #define RATE_SLIDER_LENGTH 100.0
857 void SpeedControlWidget::updateControls( int rate )
859 if( speedSlider->isSliderDown() )
861 //We don't want to change anything if the user is using the slider
866 double speed = INPUT_RATE_DEFAULT / (double)rate;
868 if( rate >= INPUT_RATE_DEFAULT )
870 if( speed < RATE_SLIDER_MINIMUM )
872 sliderValue = speedSlider->minimum();
876 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
877 / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
882 if( speed > RATE_SLIDER_MAXIMUM )
884 sliderValue = speedSlider->maximum();
888 sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
889 / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
893 //Block signals to avoid feedback loop
894 speedSlider->blockSignals( true );
895 speedSlider->setValue( sliderValue );
896 speedSlider->blockSignals( false );
899 void SpeedControlWidget::updateRate( int sliderValue )
903 if( sliderValue < 0.0 )
905 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
906 ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH );
910 rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
911 ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
914 THEMIM->getIM()->setRate(rate);
917 void SpeedControlWidget::resetRate()
919 THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);