]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.cpp
Qt4 - Hide the grey rectangle on the top of the interface, try to fix the zoom reiszing
[vlc] / modules / gui / qt4 / components / interface_widgets.cpp
1 /*****************************************************************************
2  * interface_widgets.cpp : Custom widgets for the main interface
3  ****************************************************************************
4  * Copyright ( C ) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Clément Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste Kempf <jb@videolan.org>
9  *          Rafaël Carré <funman@videolanorg>
10  *          Ilkka Ollakka <ileoo@videolan.org>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * ( at your option ) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25  *****************************************************************************/
26
27 #include "dialogs_provider.hpp"
28 #include "components/interface_widgets.hpp"
29 #include "main_interface.hpp"
30 #include "input_manager.hpp"
31 #include "menus.hpp"
32 #include "util/input_slider.hpp"
33 #include "util/customwidgets.hpp"
34 #include <vlc_vout.h>
35
36 #include <QLabel>
37 #include <QSpacerItem>
38 #include <QCursor>
39 #include <QPushButton>
40 #include <QToolButton>
41 #include <QHBoxLayout>
42 #include <QMenu>
43 #include <QPalette>
44 #include <QResizeEvent>
45
46 /**********************************************************************
47  * Video Widget. A simple frame on which video is drawn
48  * This class handles resize issues
49  **********************************************************************/
50 static void *DoRequest( intf_thread_t *, vout_thread_t *, int*,int*,
51                         unsigned int *, unsigned int * );
52 static void DoRelease( intf_thread_t *, void * );
53 static int DoControl( intf_thread_t *, void *, int, va_list );
54
55 VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
56 {
57     vlc_mutex_init( p_intf, &lock );
58     p_vout = NULL;
59     hide(); setMinimumSize( 16, 16 );
60  
61    // CONNECT( this, askResize( int, int ), this, SetSizing( int, int ) );
62     CONNECT( this, askVideoWidgetToShow(), this, show() );
63     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred );
64 }
65
66 VideoWidget::~VideoWidget()
67 {
68     vlc_mutex_lock( &lock );
69     if( p_vout )
70     {
71         if( !p_intf->psz_switch_intf )
72         {
73             if( vout_Control( p_vout, VOUT_CLOSE ) != VLC_SUCCESS )
74                 vout_Control( p_vout, VOUT_REPARENT );
75         }
76         else
77         {
78             if( vout_Control( p_vout, VOUT_REPARENT ) != VLC_SUCCESS )
79                 vout_Control( p_vout, VOUT_CLOSE );
80         }
81     }
82     vlc_mutex_unlock( &lock );
83     vlc_mutex_destroy( &lock );
84 }
85
86 QSize VideoWidget::sizeHint() const
87 {
88     return widgetSize;
89 }
90
91 /**
92  * Request the video to avoid the conflicts 
93  **/
94 void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
95                            unsigned int *pi_width, unsigned int *pi_height )
96 {
97     emit askVideoWidgetToShow();
98     if( p_vout )
99     {
100         msg_Dbg( p_intf, "embedded video already in use" );
101         return NULL;
102     }
103     p_vout = p_nvout;
104     return ( void* )winId();
105 }
106
107 /* Set the Widget to the correct Size */
108 void VideoWidget::SetSizing( unsigned int w, unsigned int h )
109 {
110     widgetSize = QSize( w, h );
111     resize( w, h );
112     //updateGeometry(); // Needed for deinterlace
113     msg_Dbg( p_intf, "%i %i", sizeHint().height(), sizeHint().width() );
114     emit askResize();
115 }
116
117 void VideoWidget::release( void *p_win )
118 {
119     p_vout = NULL;
120 }
121
122
123 /**********************************************************************
124  * Background Widget. Show a simple image background. Currently,
125  * it's a static cone.
126  **********************************************************************/
127 #define ICON_SIZE 128
128 #define MAX_BG_SIZE 400
129 #define MIN_BG_SIZE 64
130
131 BackgroundWidget::BackgroundWidget( intf_thread_t *_p_i ) :
132                                         QFrame( NULL ), p_intf( _p_i )
133 {
134     /* We should use that one to take the more size it can */
135     setSizePolicy( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding );
136
137     /* A dark background */
138     setAutoFillBackground( true );
139     plt =  palette();
140     plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
141     plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
142     setPalette( plt );
143
144     /* A cone in the middle */
145     label = new QLabel;
146     label->setScaledContents( true );
147     label->setMargin( 5 );
148     label->setMaximumHeight( MAX_BG_SIZE );
149     label->setMaximumWidth( MAX_BG_SIZE );
150     label->setMinimumHeight( MIN_BG_SIZE );
151     label->setMinimumWidth( MIN_BG_SIZE );
152     label->setPixmap( QPixmap( ":/vlc128.png" ) );
153
154     QHBoxLayout *backgroundLayout = new QHBoxLayout( this );
155     backgroundLayout->addWidget( label );
156
157     resize( 300, 150 );
158     updateGeometry();
159     CONNECT( THEMIM, inputChanged( input_thread_t *), this, update( input_thread_t * ) );
160 }
161
162 BackgroundWidget::~BackgroundWidget()
163 {
164 }
165
166
167 void BackgroundWidget::update( input_thread_t *p_input )
168 {
169     if( !p_input || p_input->b_dead )
170     {
171         label->setPixmap( QPixmap( ":/vlc128.png" ) );
172         return;
173     }
174
175
176     vlc_object_yield( p_input );
177     char *psz_arturl = input_item_GetArtURL( input_GetItem(p_input) );
178     vlc_object_release( p_input );
179     QString url = qfu( psz_arturl );
180     QString arturl = url.replace( "file://",QString("" ) );
181     if( arturl.isNull() )
182         label->setPixmap( QPixmap( ":/vlc128.png" ) );
183     else
184     {
185         label->setPixmap( QPixmap( arturl ) );
186         msg_Dbg( p_intf, "changing input b_need_update done %s", psz_arturl );
187     }
188     free( psz_arturl );
189 }
190
191 QSize BackgroundWidget::sizeHint() const
192 {
193     return label->size();
194 }
195
196 void BackgroundWidget::resizeEvent( QResizeEvent *e )
197 {
198     if( e->size().height() < MAX_BG_SIZE -1 )
199     {
200         label->setMaximumWidth( e->size().height() );
201         label->setMaximumHeight( e->size().width() );
202     }
203     else
204     {
205         label->setMaximumHeight( MAX_BG_SIZE );
206         label->setMaximumWidth( MAX_BG_SIZE );
207     }
208 }
209
210 void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
211 {
212     QVLCMenu::PopupMenu( p_intf, true );
213 }
214
215 /**********************************************************************
216  * Visualization selector panel
217  **********************************************************************/
218 VisualSelector::VisualSelector( intf_thread_t *_p_i ) :
219                                 QFrame( NULL ), p_intf( _p_i )
220 {
221     QHBoxLayout *layout = new QHBoxLayout( this );
222     layout->setMargin( 0 );
223     QPushButton *prevButton = new QPushButton( "Prev" );
224     QPushButton *nextButton = new QPushButton( "Next" );
225     layout->addWidget( prevButton );
226     layout->addWidget( nextButton );
227
228     layout->addItem( new QSpacerItem( 40,20,
229                               QSizePolicy::Expanding, QSizePolicy::Minimum ) );
230     layout->addWidget( new QLabel( qtr( "Current visualization:" ) ) );
231
232     current = new QLabel( qtr( "None" ) );
233     layout->addWidget( current );
234
235     BUTTONACT( prevButton, prev() );
236     BUTTONACT( nextButton, next() );
237
238     setLayout( layout );
239     setMaximumHeight( 35 );
240 }
241
242 VisualSelector::~VisualSelector()
243 {
244 }
245
246 void VisualSelector::prev()
247 {
248     char *psz_new = aout_VisualPrev( p_intf );
249     if( psz_new )
250     {
251         current->setText( qfu( psz_new ) );
252         free( psz_new );
253     }
254 }
255
256 void VisualSelector::next()
257 {
258     char *psz_new = aout_VisualNext( p_intf );
259     if( psz_new )
260     {
261         current->setText( qfu( psz_new ) );
262         free( psz_new );
263     }
264 }
265
266 /**********************************************************************
267  * TEH controls
268  **********************************************************************/
269
270 #define setupSmallButton( aButton ){  \
271     aButton->setMaximumSize( QSize( 26, 26 ) ); \
272     aButton->setMinimumSize( QSize( 26, 26 ) ); \
273     aButton->setIconSize( QSize( 20, 20 ) ); }
274
275 AdvControlsWidget::AdvControlsWidget( intf_thread_t *_p_i ) :
276                                            QFrame( NULL ), p_intf( _p_i )
277 {
278     QHBoxLayout *advLayout = new QHBoxLayout( this );
279     advLayout->setMargin( 0 );
280     advLayout->setSpacing( 0 );
281
282     /* A to B Button */
283     ABButton = new QPushButton( "AB" );
284     ABButton->setMaximumSize( QSize( 26, 26 ) );
285     ABButton->setIconSize( QSize( 20, 20 ) );
286     advLayout->addWidget( ABButton );
287     BUTTON_SET_ACT( ABButton, "AB", qtr( "A to B" ), fromAtoB() );
288     timeA = timeB = 0;
289     CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
290              this, AtoBLoop( float, int, int ) );
291
292     frameButton = new QPushButton( "Fr" );
293     frameButton->setMaximumSize( QSize( 26, 26 ) );
294     frameButton->setIconSize( QSize( 20, 20 ) );
295     advLayout->addWidget( frameButton );
296     BUTTON_SET_ACT( frameButton, "Fr", qtr( "Frame by Frame" ), frame() );
297
298     recordButton = new QPushButton( "R" );
299     recordButton->setMaximumSize( QSize( 26, 26 ) );
300     recordButton->setIconSize( QSize( 20, 20 ) );
301     advLayout->addWidget( recordButton );
302     BUTTON_SET_ACT_I( recordButton, "", record_16px.png,
303             qtr( "Record" ), record() );
304
305     /* Snapshot Button */
306     snapshotButton = new QPushButton( "S" );
307     snapshotButton->setMaximumSize( QSize( 26, 26 ) );
308     snapshotButton->setIconSize( QSize( 20, 20 ) );
309     advLayout->addWidget( snapshotButton );
310     BUTTON_SET_ACT( snapshotButton, "S", qtr( "Take a snapshot" ), snapshot() );
311 }
312
313 AdvControlsWidget::~AdvControlsWidget()
314 {}
315
316 void AdvControlsWidget::enableInput( bool enable )
317 {
318     ABButton->setEnabled( enable );
319     recordButton->setEnabled( enable );
320 }
321
322 void AdvControlsWidget::enableVideo( bool enable )
323 {
324     snapshotButton->setEnabled( enable );
325     frameButton->setEnabled( enable );
326 }
327
328 void AdvControlsWidget::snapshot()
329 {
330     vout_thread_t *p_vout =
331         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
332     if( p_vout ) vout_Control( p_vout, VOUT_SNAPSHOT );
333 }
334
335 /* Function called when the button is clicked() */
336 void AdvControlsWidget::fromAtoB()
337 {
338     if( !timeA )
339     {
340         timeA = var_GetTime( THEMIM->getInput(), "time"  );
341         ABButton->setText( "A->..." );
342         return;
343     }
344     if( !timeB )
345     {
346         timeB = var_GetTime( THEMIM->getInput(), "time"  );
347         var_SetTime( THEMIM->getInput(), "time" , timeA );
348         ABButton->setText( "A<=>B" );
349         return;
350     }
351     timeA = 0;
352     timeB = 0;
353     ABButton->setText( "AB" );
354 }
355
356 /* Function called regularly when in an AtoB loop */
357 void AdvControlsWidget::AtoBLoop( float f_pos, int i_time, int i_length )
358 {
359     if( timeB )
360     {
361         if( i_time >= (int)(timeB/1000000) )
362             var_SetTime( THEMIM->getInput(), "time" , timeA );
363     }
364 }
365
366 /* FIXME Record function */
367 void AdvControlsWidget::record(){}
368
369 //FIXME Frame by frame function
370 void AdvControlsWidget::frame(){}
371
372 /*****************************
373  * DA Control Widget !
374  *****************************/
375 ControlsWidget::ControlsWidget( intf_thread_t *_p_i,
376                                 MainInterface *_p_mi,
377                                 bool b_advControls,
378                                 bool b_shiny ) :
379                                 QFrame( NULL ), p_intf( _p_i )
380 {
381     controlLayout = new QGridLayout( this );
382     controlLayout->setSpacing( 0 );
383 #if QT43
384     controlLayout->setContentsMargins( 9, 6, 9, 6 );
385 #else
386     controlLayout->setMargin( 6 );
387 #endif
388
389     setSizePolicy( QSizePolicy::Preferred , QSizePolicy::Maximum );
390
391     /** The main Slider **/
392     slider = new InputSlider( Qt::Horizontal, NULL );
393     controlLayout->addWidget( slider, 0, 1, 1, 16 );
394     /* Update the position when the IM has changed */
395     CONNECT( THEMIM->getIM(), positionUpdated( float, int, int ),
396              slider, setPosition( float, int, int ) );
397     /* And update the IM, when the position has changed */
398     CONNECT( slider, sliderDragged( float ),
399              THEMIM->getIM(), sliderUpdate( float ) );
400
401     /** Slower and faster Buttons **/
402     slowerButton = new QPushButton;
403     slowerButton->setFlat( true );
404     slowerButton->setMaximumSize( QSize( 26, 20 ) );
405
406     BUTTON_SET_ACT( slowerButton, "-", qtr( "Slower" ), slower() );
407     controlLayout->addWidget( slowerButton, 0, 0 );
408
409     fasterButton = new QPushButton;
410     fasterButton->setFlat( true );
411     fasterButton->setMaximumSize( QSize( 26, 20 ) );
412
413     BUTTON_SET_ACT( fasterButton, "+", qtr( "Faster" ), faster() );
414     controlLayout->addWidget( fasterButton, 0, 17 );
415
416     /* advanced Controls handling */
417     b_advancedVisible = b_advControls;
418
419     advControls = new AdvControlsWidget( p_intf );
420     controlLayout->addWidget( advControls, 1, 3, 2, 4, Qt::AlignBottom );
421     if( !b_advancedVisible ) advControls->hide();
422
423     /** Disc and Menus handling */
424     discFrame = new QWidget( this );
425
426     QHBoxLayout *discLayout = new QHBoxLayout( discFrame );
427     discLayout->setSpacing( 0 );
428     discLayout->setMargin( 0 );
429
430     prevSectionButton = new QPushButton( discFrame );
431     setupSmallButton( prevSectionButton );
432     discLayout->addWidget( prevSectionButton );
433
434     menuButton = new QPushButton( discFrame );
435     setupSmallButton( menuButton );
436     discLayout->addWidget( menuButton );
437
438     nextSectionButton = new QPushButton( discFrame );
439     setupSmallButton( nextSectionButton );
440     discLayout->addWidget( nextSectionButton );
441
442     controlLayout->addWidget( discFrame, 1, 10, 2, 3, Qt::AlignBottom );
443
444     BUTTON_SET_IMG( prevSectionButton, "", previous.png, "" );
445     BUTTON_SET_IMG( nextSectionButton, "", next.png, "" );
446     BUTTON_SET_IMG( menuButton, "", previous.png, "" );
447
448     discFrame->hide();
449
450     /* Change the navigation button display when the IM navigation changes */
451     CONNECT( THEMIM->getIM(), navigationChanged( int ),
452              this, setNavigation( int ) );
453     /* Changes the IM navigation when triggered on the nav buttons */
454     CONNECT( prevSectionButton, clicked(), THEMIM->getIM(),
455              sectionPrev() );
456     CONNECT( nextSectionButton, clicked(), THEMIM->getIM(),
457              sectionNext() );
458     CONNECT( menuButton, clicked(), THEMIM->getIM(),
459              sectionMenu() );
460     /** TODO
461      * Telextext QFrame
462      * Merge with upper menu in a StackLayout
463      **/
464     telexFrame = new QWidget( this );
465     QHBoxLayout *telexLayout = new QHBoxLayout( telexFrame );
466     telexLayout->setSpacing( 0 );
467     telexLayout->setMargin( 0 );
468
469     QToolButton *telexOn = new QToolButton;
470     telexOn->setText( qtr( "On" ) );
471     setupSmallButton( telexOn );
472     telexLayout->addWidget( telexOn );
473
474     QToolButton *telexTransparent = new QToolButton;
475     telexTransparent->setText( qtr( "Transparent" ) );
476     setupSmallButton( telexTransparent );
477     telexLayout->addWidget( telexTransparent );
478
479     QSpinBox *telexPage = new QSpinBox;
480     telexPage->setRange( 0, 999 );
481     telexPage->setValue( 100 );
482     telexPage->setAlignment( Qt::AlignRight );
483     telexLayout->addWidget( telexPage );
484
485     controlLayout->addWidget( telexFrame, 1, 10, 2, 3, Qt::AlignBottom );
486     telexFrame->hide();
487
488     CONNECT( telexPage, valueChanged( int ), THEMIM->getIM(),
489              telexGotoPage( int ) );
490     CONNECT( telexOn, clicked( bool ), THEMIM->getIM(),
491              telexToggle( bool ) );
492     CONNECT( telexTransparent, clicked( bool ),
493              THEMIM->getIM(), telexSetTransparency( bool ) );
494     CONNECT( THEMIM->getIM(), teletextEnabled( bool ),
495              telexFrame, setVisible( bool ) );
496
497     /** Play Buttons **/
498     QSizePolicy sizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
499     sizePolicy.setHorizontalStretch( 0 );
500     sizePolicy.setVerticalStretch( 0 );
501
502     /* Play */
503     playButton = new QPushButton;
504     playButton->setSizePolicy( sizePolicy );
505     playButton->setMaximumSize( QSize( 36, 36 ) );
506     playButton->setMinimumSize( QSize( 36, 36 ) );
507     playButton->setIconSize( QSize( 30, 30 ) );
508
509     controlLayout->addWidget( playButton, 2, 0, 2, 2 );
510
511     controlLayout->setColumnMinimumWidth( 2, 20 );
512     controlLayout->setColumnStretch( 2, 0 );
513
514     /** Prev + Stop + Next Block **/
515     QHBoxLayout *controlButLayout = new QHBoxLayout;
516     controlButLayout->setSpacing( 0 ); /* Don't remove that, will be useful */
517
518     /* Prev */
519     QPushButton *prevButton = new QPushButton;
520     prevButton->setSizePolicy( sizePolicy );
521     setupSmallButton( prevButton );
522
523     controlButLayout->addWidget( prevButton );
524
525     /* Stop */
526     QPushButton *stopButton = new QPushButton;
527     stopButton->setSizePolicy( sizePolicy );
528     setupSmallButton( stopButton );
529
530     controlButLayout->addWidget( stopButton );
531
532     /* next */
533     QPushButton *nextButton = new QPushButton;
534     nextButton->setSizePolicy( sizePolicy );
535     setupSmallButton( nextButton );
536
537     controlButLayout->addWidget( nextButton );
538
539     /* Add this block to the main layout */
540     controlLayout->addLayout( controlButLayout, 3, 3, 1, 3, Qt::AlignBottom );
541
542     BUTTON_SET_ACT_I( playButton, "", play.png, qtr( "Play" ), play() );
543     BUTTON_SET_ACT_I( prevButton, "" , previous.png,
544                       qtr( "Previous" ), prev() );
545     BUTTON_SET_ACT_I( nextButton, "", next.png, qtr( "Next" ), next() );
546     BUTTON_SET_ACT_I( stopButton, "", stop.png, qtr( "Stop" ), stop() );
547
548     controlLayout->setColumnMinimumWidth( 7, 20 );
549     controlLayout->setColumnStretch( 7, 0 );
550     controlLayout->setColumnStretch( 8, 0 );
551     controlLayout->setColumnStretch( 9, 0 );
552
553     /*
554      * Other first Line buttons
555      */
556     /** Fullscreen/Visualisation **/
557     fullscreenButton = new QPushButton( "F" );
558     BUTTON_SET_ACT( fullscreenButton, "F", qtr( "Fullscreen" ), fullscreen() );
559     setupSmallButton( fullscreenButton );
560     controlLayout->addWidget( fullscreenButton, 3, 10, Qt::AlignBottom );
561
562     /** Playlist Button **/
563     playlistButton = new QPushButton;
564     setupSmallButton( playlistButton );
565     controlLayout->addWidget( playlistButton, 3, 11, Qt::AlignBottom );
566     BUTTON_SET_IMG( playlistButton, "" , playlist.png, qtr( "Show playlist" ) );
567     CONNECT( playlistButton, clicked(), _p_mi, togglePlaylist() );
568
569     /** extended Settings **/
570     QPushButton *extSettingsButton = new QPushButton( "F" );
571     BUTTON_SET_ACT( extSettingsButton, "Ex", qtr( "Extended Settings" ),
572             extSettings() );
573     setupSmallButton( extSettingsButton );
574     controlLayout->addWidget( extSettingsButton, 3, 12, Qt::AlignBottom );
575
576     controlLayout->setColumnStretch( 13, 0 );
577     controlLayout->setColumnMinimumWidth( 13, 24 );
578     controlLayout->setColumnStretch( 14, 5 );
579
580     /* Volume */
581     VolumeClickHandler *hVolLabel = new VolumeClickHandler( p_intf, this );
582
583     volMuteLabel = new QLabel;
584     volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
585     volMuteLabel->setToolTip( qtr( "Mute" ) );
586     volMuteLabel->installEventFilter( hVolLabel );
587     controlLayout->addWidget( volMuteLabel, 3, 15, Qt::AlignBottom );
588
589     if( b_shiny )
590     {
591         volumeSlider = new SoundSlider( this,
592             config_GetInt( p_intf, "volume-step" ),
593             config_GetInt( p_intf, "qt-volume-complete" ) );
594     }
595     else
596     {
597         volumeSlider = new QSlider( this );
598         volumeSlider->setOrientation( Qt::Horizontal );
599     }
600     volumeSlider->setMaximumSize( QSize( 200, 40 ) );
601     volumeSlider->setMinimumSize( QSize( 106, 30 ) );
602     volumeSlider->setFocusPolicy( Qt::NoFocus );
603     controlLayout->addWidget( volumeSlider, 2, 16, 2 , 2, Qt::AlignBottom );
604
605     /* Set the volume from the config */
606     volumeSlider->setValue( ( config_GetInt( p_intf, "volume" ) ) *
607                               VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
608
609     /* Volume control connection */
610     //resize( QSize( 300, 60 ) );
611     CONNECT( volumeSlider, valueChanged( int ), this, updateVolume( int ) );
612     msg_Dbg( p_intf, "controls size: %i - %i", size().width(), size().height() );
613 }
614
615 ControlsWidget::~ControlsWidget()
616 {}
617
618 /*
619 QSize ControlsWidget::sizeHint() const
620 {
621     return QSize( 300, 50 );
622 }
623 */
624
625 void ControlsWidget::stop()
626 {
627     THEMIM->stop();
628 }
629
630 void ControlsWidget::play()
631 {
632     if( THEPL->current.i_size == 0 )
633     {
634         /* The playlist is empty, open a file requester */
635         THEDP->openFileDialog();
636         setStatus( 0 );
637         return;
638     }
639     THEMIM->togglePlayPause();
640 }
641
642 void ControlsWidget::prev()
643 {
644     THEMIM->prev();
645 }
646
647 void ControlsWidget::next()
648 {
649     THEMIM->next();
650 }
651
652 void ControlsWidget::setNavigation( int navigation )
653 {
654 #define HELP_MENU N_( "Menu" )
655 #define HELP_PCH N_( "Previous chapter" )
656 #define HELP_NCH N_( "Next chapter" )
657 #define HELP_PTR N_( "Previous track" )
658 #define HELP_NTR N_( "Next track" )
659
660     // 1 = chapter, 2 = title, 0 = no
661     if( navigation == 0 )
662     {
663         discFrame->hide();
664     } else if( navigation == 1 ) {
665         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
666         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
667         menuButton->show();
668         discFrame->show();
669     } else {
670         prevSectionButton->setToolTip( qfu( HELP_PCH ) );
671         nextSectionButton->setToolTip( qfu( HELP_NCH ) );
672         menuButton->hide();
673         discFrame->show();
674     }
675 }
676
677 static bool b_my_volume;
678 void ControlsWidget::updateVolume( int i_sliderVolume )
679 {
680     if( !b_my_volume )
681     {
682         int i_res = i_sliderVolume  * (AOUT_VOLUME_MAX / 2) / VOLUME_MAX;
683         aout_VolumeSet( p_intf, i_res );
684     }
685     if( i_sliderVolume == 0 )
686         volMuteLabel->setPixmap( QPixmap(":/pixmaps/volume-muted.png" ) );
687     else if( i_sliderVolume < VOLUME_MAX / 2 )
688         volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-low.png" ) );
689     else volMuteLabel->setPixmap( QPixmap( ":/pixmaps/volume-high.png" ) );
690 }
691
692 void ControlsWidget::updateOnTimer()
693 {
694     /* Audio part */
695     audio_volume_t i_volume;
696     aout_VolumeGet( p_intf, &i_volume );
697     i_volume = ( i_volume *  VOLUME_MAX )/ (AOUT_VOLUME_MAX/2);
698     int i_gauge = volumeSlider->value();
699     b_my_volume = false;
700     if( i_volume - i_gauge > 1 || i_gauge - i_volume > 1 )
701     {
702         b_my_volume = true;
703         volumeSlider->setValue( i_volume );
704         b_my_volume = false;
705     }
706
707     /* Activate the interface buttons according to the presence of the input */
708     enableInput( THEMIM->getIM()->hasInput() );
709     //enableVideo( THEMIM->getIM()->hasVideo() );
710     enableVideo( true );
711 }
712
713 void ControlsWidget::setStatus( int status )
714 {
715     if( status == PLAYING_S ) // Playing
716         playButton->setIcon( QIcon( ":/pixmaps/pause.png" ) );
717     else
718         playButton->setIcon( QIcon( ":/pixmaps/play.png" ) );
719 }
720
721 /**
722  * TODO
723  * This functions toggle the fullscreen mode
724  * If there is no video, it should first activate Visualisations...
725  *  This has also to be fixed in enableVideo()
726  */
727 void ControlsWidget::fullscreen()
728 {
729     vout_thread_t *p_vout =
730         (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
731     if( p_vout)
732     {
733         var_SetBool( p_vout, "fullscreen", !var_GetBool( p_vout, "fullscreen" ) );
734         vlc_object_release( p_vout );
735     }
736 }
737
738 void ControlsWidget::extSettings()
739 {
740     THEDP->extendedDialog();
741 }
742
743 void ControlsWidget::slower()
744 {
745     THEMIM->getIM()->slower();
746 }
747
748 void ControlsWidget::faster()
749 {
750     THEMIM->getIM()->faster();
751 }
752
753 void ControlsWidget::enableInput( bool enable )
754 {
755     slowerButton->setEnabled( enable );
756     slider->setEnabled( enable );
757     fasterButton->setEnabled( enable );
758
759     /* Advanced Buttons too */
760     advControls->enableInput( enable );
761 }
762
763 void ControlsWidget::enableVideo( bool enable )
764 {
765     // TODO Later make the fullscreenButton toggle Visualisation and so on.
766     fullscreenButton->setEnabled( enable );
767
768     /* Advanced Buttons too */
769     advControls->enableVideo( enable );
770 }
771
772 void ControlsWidget::toggleAdvanced()
773 {
774     if( !VISIBLE( advControls ) )
775     {
776         advControls->show();
777         b_advancedVisible = true;
778     }
779     else
780     {
781         advControls->hide();
782         b_advancedVisible = false;
783     }
784     emit advancedControlsToggled( b_advancedVisible );
785 }
786
787
788 /**********************************************************************
789  * Speed control widget
790  **********************************************************************/
791 SpeedControlWidget::SpeedControlWidget( intf_thread_t *_p_i ) :
792                              QFrame( NULL ), p_intf( _p_i )
793 {
794     QSizePolicy sizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
795     sizePolicy.setHorizontalStretch( 0 );
796     sizePolicy.setVerticalStretch( 0 );
797
798     speedSlider = new QSlider;
799     speedSlider->setSizePolicy( sizePolicy );
800     speedSlider->setMaximumSize( QSize( 80, 200 ) );
801     speedSlider->setOrientation( Qt::Vertical );
802     speedSlider->setTickPosition( QSlider::TicksRight );
803
804     speedSlider->setRange( -100, 100 );
805     speedSlider->setSingleStep( 10 );
806     speedSlider->setPageStep( 20 );
807     speedSlider->setTickInterval( 20 );
808
809     CONNECT( speedSlider, valueChanged( int ), this, updateRate( int ) );
810
811     normalSpeedButton = new QPushButton( "N" );
812     normalSpeedButton->setMaximumSize( QSize( 26, 20 ) );
813     normalSpeedButton->setFlat( true );
814     normalSpeedButton->setToolTip( qtr( "Revert to normal play speed" ) );
815
816     CONNECT( normalSpeedButton, clicked(), this, resetRate() );
817
818     QVBoxLayout *speedControlLayout = new QVBoxLayout;
819     speedControlLayout->addWidget(speedSlider);
820     speedControlLayout->addWidget(normalSpeedButton);
821     setLayout(speedControlLayout);
822 }
823
824 SpeedControlWidget::~SpeedControlWidget()
825 {}
826
827 #define RATE_SLIDER_MAXIMUM 3.0
828 #define RATE_SLIDER_MINIMUM 0.3
829 #define RATE_SLIDER_LENGTH 100.0
830
831 void SpeedControlWidget::updateControls( int rate )
832 {
833     if( speedSlider->isSliderDown() )
834     {
835         //We don't want to change anything if the user is using the slider
836         return;
837     }
838
839     int sliderValue;
840     double speed = INPUT_RATE_DEFAULT / (double)rate;
841
842     if( rate >= INPUT_RATE_DEFAULT )
843     {
844         if( speed < RATE_SLIDER_MINIMUM )
845         {
846             sliderValue = speedSlider->minimum();
847         }
848         else
849         {
850             sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
851                                         / ( 1.0 - RATE_SLIDER_MAXIMUM ) );
852         }
853     }
854     else
855     {
856         if( speed > RATE_SLIDER_MAXIMUM )
857         {
858             sliderValue = speedSlider->maximum();
859         }
860         else
861         {
862             sliderValue = (int)( ( speed - 1.0 ) * RATE_SLIDER_LENGTH
863                                         / ( RATE_SLIDER_MAXIMUM - 1.0 ) );
864         }
865     }
866
867     //Block signals to avoid feedback loop
868     speedSlider->blockSignals( true );
869     speedSlider->setValue( sliderValue );
870     speedSlider->blockSignals( false );
871 }
872
873 void SpeedControlWidget::updateRate( int sliderValue )
874 {
875     int rate;
876
877     if( sliderValue < 0.0 )
878     {
879         rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
880             ( sliderValue * ( 1.0 - RATE_SLIDER_MINIMUM ) + RATE_SLIDER_LENGTH );
881     }
882     else
883     {
884         rate = INPUT_RATE_DEFAULT* RATE_SLIDER_LENGTH /
885             ( sliderValue * ( RATE_SLIDER_MAXIMUM - 1.0 ) + RATE_SLIDER_LENGTH );
886     }
887
888     THEMIM->getIM()->setRate(rate);
889 }
890
891 void SpeedControlWidget::resetRate()
892 {
893     THEMIM->getIM()->setRate(INPUT_RATE_DEFAULT);
894 }