]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/extended_panels.cpp
Do the cropping from the extended panel.
[vlc] / modules / gui / qt4 / components / extended_panels.cpp
1 /*****************************************************************************
2  * extended_panels.cpp : Extended controls panels
3  ****************************************************************************
4  * Copyright (C) 2006-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Antoine Cellerier <dionoea .t videolan d@t org>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include <QLabel>
29 #include <QVariant>
30 #include <QString>
31 #include <QFont>
32 #include <QGridLayout>
33 #include <QSignalMapper>
34 #include <QComboBox>
35
36 #include "components/extended_panels.hpp"
37 #include "dialogs/preferences.hpp"
38 #include "dialogs_provider.hpp"
39 #include "qt4.hpp"
40 #include "input_manager.hpp"
41
42 #include "../../audio_filter/equalizer_presets.h"
43 #include <vlc_aout.h>
44 #include <vlc_intf_strings.h>
45 #include <vlc_vout.h>
46 #include <vlc_osd.h>
47
48
49 #if 0
50 class ConfClickHandler : public QObject
51 {
52 public:
53     ConfClickHandler( intf_thread_t *_p_intf, ExtVideo *_e ) : QObject ( _e ) {
54         e = _e; p_intf = _p_intf;
55     }
56     virtual ~ConfClickHandler() {}
57     bool eventFilter( QObject *obj, QEvent *evt )
58     {
59         if( evt->type() == QEvent::MouseButtonPress )
60         {
61             e->gotoConf( obj );
62             return true;
63         }
64         return false;
65     }
66 private:
67     ExtVideo* e;
68     intf_thread_t *p_intf;
69 };
70 #endif
71
72 QString ModuleFromWidgetName( QObject *obj )
73 {
74     return obj->objectName().replace( "Enable","" );
75 }
76
77 QString OptionFromWidgetName( QObject *obj )
78 {
79     /* Gruik ? ... nah */
80     QString option = obj->objectName().replace( "Slider", "" )
81                                       .replace( "Combo" , "" )
82                                       .replace( "Dial"  , "" )
83                                       .replace( "Check" , "" )
84                                       .replace( "Spin"  , "" )
85                                       .replace( "Text"  , "" );
86     for( char a = 'A'; a <= 'Z'; a++ )
87     {
88         option = option.replace( QString( a ),
89                                  QString( '-' ) + QString( a + 'a' - 'A' ) );
90     }
91     return option;
92 }
93
94 ExtVideo::ExtVideo( intf_thread_t *_p_intf, QTabWidget *_parent ) :
95                            p_intf( _p_intf )
96 {
97     ui.setupUi( _parent );
98
99 #define SETUP_VFILTER( widget ) \
100     { \
101         vlc_object_t *p_obj = ( vlc_object_t * ) \
102             vlc_object_find_name( p_intf->p_libvlc, \
103                                   #widget, \
104                                   FIND_CHILD ); \
105         QCheckBox *checkbox = qobject_cast<QCheckBox*>( ui.widget##Enable ); \
106         QGroupBox *groupbox = qobject_cast<QGroupBox*>( ui.widget##Enable ); \
107         if( p_obj ) \
108         { \
109             vlc_object_release( p_obj ); \
110             if( checkbox ) checkbox->setChecked( true ); \
111             else groupbox->setChecked( true ); \
112         } \
113         else \
114         { \
115             if( checkbox ) checkbox->setChecked( false ); \
116             else groupbox->setChecked( false ); \
117         } \
118     } \
119     CONNECT( ui.widget##Enable, clicked(), this, updateFilters() );
120 #define SETUP_VFILTER_OPTION( widget, signal ) \
121     initComboBoxItems( ui.widget ); \
122     setWidgetValue( ui.widget ); \
123     CONNECT( ui.widget, signal, this, updateFilterOptions() );
124
125     SETUP_VFILTER( adjust )
126     SETUP_VFILTER_OPTION( hueSlider, valueChanged( int ) )
127     SETUP_VFILTER_OPTION( contrastSlider, valueChanged( int ) )
128     SETUP_VFILTER_OPTION( brightnessSlider, valueChanged( int ) )
129     SETUP_VFILTER_OPTION( saturationSlider, valueChanged( int ) )
130     SETUP_VFILTER_OPTION( gammaSlider, valueChanged( int ) )
131     SETUP_VFILTER_OPTION( brightnessThresholdCheck, stateChanged( int ) )
132
133     SETUP_VFILTER( extract )
134     SETUP_VFILTER_OPTION( extractComponentText, textChanged( QString ) )
135
136     SETUP_VFILTER( colorthres )
137     SETUP_VFILTER_OPTION( colorthresColorText, textChanged( QString ) )
138     SETUP_VFILTER_OPTION( colorthresSaturationthresSlider, valueChanged( int ) )
139     SETUP_VFILTER_OPTION( colorthresSimilaritythresSlider, valueChanged( int ) )
140
141     SETUP_VFILTER( invert )
142
143     SETUP_VFILTER( gradient )
144     SETUP_VFILTER_OPTION( gradientModeCombo, currentIndexChanged( QString ) )
145     SETUP_VFILTER_OPTION( gradientTypeCheck, stateChanged( int ) )
146     SETUP_VFILTER_OPTION( gradientCartoonCheck, stateChanged( int ) )
147
148     SETUP_VFILTER( motionblur )
149     SETUP_VFILTER_OPTION( blurFactorSlider, valueChanged( int ) )
150
151     SETUP_VFILTER( motiondetect )
152
153     SETUP_VFILTER( noise )
154
155     SETUP_VFILTER( psychedelic )
156
157     SETUP_VFILTER( sharpen )
158     SETUP_VFILTER_OPTION( sharpenSigmaSlider, valueChanged( int ) )
159
160     SETUP_VFILTER( ripple )
161
162     SETUP_VFILTER( wave )
163
164     SETUP_VFILTER( transform )
165     SETUP_VFILTER_OPTION( transformTypeCombo, currentIndexChanged( QString ) )
166
167     SETUP_VFILTER( rotate )
168     SETUP_VFILTER_OPTION( rotateAngleDial, valueChanged( int ) )
169     ui.rotateAngleDial->setWrapping( true );
170     ui.rotateAngleDial->setNotchesVisible( true );
171
172     SETUP_VFILTER( puzzle )
173     SETUP_VFILTER_OPTION( puzzleRowsSpin, valueChanged( int ) )
174     SETUP_VFILTER_OPTION( puzzleColsSpin, valueChanged( int ) )
175     SETUP_VFILTER_OPTION( puzzleBlackSlotCheck, stateChanged( int ) )
176
177     SETUP_VFILTER( magnify )
178
179     SETUP_VFILTER( clone )
180     SETUP_VFILTER_OPTION( cloneCountSpin, valueChanged( int ) )
181
182     SETUP_VFILTER( wall )
183     SETUP_VFILTER_OPTION( wallRowsSpin, valueChanged( int ) )
184     SETUP_VFILTER_OPTION( wallColsSpin, valueChanged( int ) )
185
186     SETUP_VFILTER( panoramix )
187     SETUP_VFILTER_OPTION( panoramixRowsSpin, valueChanged( int ) )
188     SETUP_VFILTER_OPTION( panoramixColsSpin, valueChanged( int ) )
189
190
191     SETUP_VFILTER( erase )
192     SETUP_VFILTER_OPTION( eraseMaskText, editingFinished() )
193     SETUP_VFILTER_OPTION( eraseYSpin, valueChanged( int ) )
194     SETUP_VFILTER_OPTION( eraseXSpin, valueChanged( int ) )
195
196     SETUP_VFILTER( marq )
197     SETUP_VFILTER_OPTION( marqMarqueeText, textChanged( QString ) )
198     SETUP_VFILTER_OPTION( marqPositionCombo, currentIndexChanged( QString ) )
199
200     SETUP_VFILTER( logo )
201     SETUP_VFILTER_OPTION( logoFileText, editingFinished() )
202     SETUP_VFILTER_OPTION( logoYSpin, valueChanged( int ) )
203     SETUP_VFILTER_OPTION( logoXSpin, valueChanged( int ) )
204     SETUP_VFILTER_OPTION( logoTransparencySlider, valueChanged( int ) )
205
206 #undef SETUP_VFILTER
207 #undef SETUP_VFILTER_OPTION
208
209     CONNECT( ui.cropTopPx, valueChanged( int ), this, cropChange() );
210     CONNECT( ui.cropBotPx, valueChanged( int ), this, cropChange() );
211     CONNECT( ui.cropLeftPx, valueChanged( int ), this, cropChange() );
212     CONNECT( ui.cropRightPx, valueChanged( int ), this, cropChange() );
213     CONNECT( ui.topBotCropSync, toggled( bool ),
214              ui.cropBotPx, setDisabled( bool ) );
215     CONNECT( ui.leftRightCropSync, toggled( bool ),
216              ui.cropRightPx, setDisabled( bool ) );
217 }
218
219 ExtVideo::~ExtVideo()
220 {
221 }
222
223 void ExtVideo::cropChange()
224 {
225     p_vout = ( vout_thread_t * )vlc_object_find( p_intf,
226                                 VLC_OBJECT_VOUT, FIND_CHILD );
227     if( p_vout )
228     {
229         var_SetInteger( p_vout, "crop-top", ui.cropTopPx->value() );
230         var_SetInteger( p_vout, "crop-bottom", ui.cropBotPx->value() );
231         var_SetInteger( p_vout, "crop-left", ui.cropLeftPx->value() );
232         var_SetInteger( p_vout, "crop-right", ui.cropRightPx->value() );
233     }
234 }
235
236 void ExtVideo::ChangeVFiltersString( char *psz_name, vlc_bool_t b_add )
237 {
238     char *psz_parser, *psz_string;
239     const char *psz_filter_type;
240
241     /* Please leave p_libvlc_global. This is where cached modules are
242      * stored. We're not trying to find a module instance. */
243     module_t *p_obj = module_Find( p_intf, psz_name );
244     if( !p_obj )
245     {
246         msg_Err( p_intf, "Unable to find filter module \"%s\n.", psz_name );
247         return;
248     }
249
250     if( module_IsCapable( p_obj, "video filter2" ) )
251     {
252         psz_filter_type = "video-filter";
253     }
254     else if( module_IsCapable( p_obj, "video filter" ) )
255     {
256         psz_filter_type = "vout-filter";
257     }
258     else if( module_IsCapable( p_obj, "sub filter" ) )
259     {
260         psz_filter_type = "sub-filter";
261     }
262     else
263     {
264         module_Put( p_obj );
265         msg_Err( p_intf, "Unknown video filter type." );
266         return;
267     }
268     module_Put( p_obj );
269
270     psz_string = config_GetPsz( p_intf, psz_filter_type );
271
272     if( !psz_string ) psz_string = strdup( "" );
273
274     psz_parser = strstr( psz_string, psz_name );
275
276     if( b_add )
277     {
278         if( !psz_parser )
279         {
280             psz_parser = psz_string;
281             if( asprintf( &psz_string, ( *psz_string ) ? "%s:%s" : "%s%s",
282                             psz_string, psz_name ) == -1 )
283                 return;
284             free( psz_parser );
285         }
286         else
287         {
288             return;
289         }
290     }
291     else
292     {
293         if( psz_parser )
294         {
295             if( *( psz_parser + strlen( psz_name ) ) == ':' )
296             {
297                 memmove( psz_parser, psz_parser + strlen( psz_name ) + 1,
298                          strlen( psz_parser + strlen( psz_name ) + 1 ) + 1 );
299             }
300             else
301             {
302                 *psz_parser = '\0';
303             }
304
305             /* Remove trailing : : */
306             if( strlen( psz_string ) > 0 &&
307                 *( psz_string + strlen( psz_string ) -1 ) == ':' )
308             {
309                 *( psz_string + strlen( psz_string ) -1 ) = '\0';
310             }
311         }
312         else
313         {
314             free( psz_string );
315             return;
316         }
317     }
318     /* Vout is not kept, so put that in the config */
319     config_PutPsz( p_intf, psz_filter_type, psz_string );
320     if( !strcmp( psz_filter_type, "video-filter" ) )
321         ui.videoFilterText->setText( psz_string );
322     else if( !strcmp( psz_filter_type, "vout-filter" ) )
323         ui.voutFilterText->setText( psz_string );
324     else if( !strcmp( psz_filter_type, "sub-filter" ) )
325         ui.subpictureFilterText->setText( psz_string );
326
327     /* Try to set on the fly */
328     p_vout = ( vout_thread_t * )vlc_object_find( p_intf, VLC_OBJECT_VOUT,
329                                               FIND_ANYWHERE );
330     if( p_vout )
331     {
332         if( !strcmp( psz_filter_type, "sub-filter" ) )
333             var_SetString( p_vout->p_spu, psz_filter_type, psz_string );
334         else
335             var_SetString( p_vout, psz_filter_type, psz_string );
336         vlc_object_release( p_vout );
337     }
338
339     free( psz_string );
340 }
341
342 void ExtVideo::updateFilters()
343 {
344     QString module = ModuleFromWidgetName( sender() );
345     //std::cout << "Module name: " << module.toStdString() << std::endl;
346
347     QCheckBox *checkbox = qobject_cast<QCheckBox*>( sender() );
348     QGroupBox *groupbox = qobject_cast<QGroupBox*>( sender() );
349
350     ChangeVFiltersString( qtu( module ),
351                           checkbox ? checkbox->isChecked()
352                                    : groupbox->isChecked() );
353 }
354
355 void ExtVideo::initComboBoxItems( QObject *widget )
356 {
357     QComboBox *combobox = qobject_cast<QComboBox*>( widget );
358     if( !combobox ) return;
359     QString option = OptionFromWidgetName( widget );
360     module_config_t *p_item = config_FindConfig( VLC_OBJECT( p_intf ),
361                                                  qtu( option ) );
362     if( p_item )
363     {
364         int i_type = p_item->i_type & CONFIG_ITEM;
365         for( int i_index = 0; i_index < p_item->i_list; i_index++ )
366         {
367             if( i_type == CONFIG_ITEM_INTEGER
368              || i_type == CONFIG_ITEM_BOOL )
369                 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ),
370                                    p_item->pi_list[i_index] );
371             else if( i_type == CONFIG_ITEM_STRING )
372                 combobox->addItem( qfu( p_item->ppsz_list_text[i_index] ),
373                                    p_item->ppsz_list[i_index] );
374         }
375     }
376     else
377     {
378         msg_Err( p_intf, "Couldn't find option \"%s\".",
379                  qtu( option ) );
380     }
381 }
382
383 void ExtVideo::setWidgetValue( QObject *widget )
384 {
385     QString module = ModuleFromWidgetName( widget->parent() );
386     //std::cout << "Module name: " << module.toStdString() << std::endl;
387     QString option = OptionFromWidgetName( widget );
388     //std::cout << "Option name: " << option.toStdString() << std::endl;
389
390     vlc_object_t *p_obj = ( vlc_object_t * )
391         vlc_object_find_name( p_intf->p_libvlc,
392                               qtu( module ),
393                               FIND_CHILD );
394     int i_type;
395     vlc_value_t val;
396
397     if( !p_obj )
398     {
399 #if 0
400         msg_Dbg( p_intf,
401                  "Module instance %s not found, looking in config values.",
402                  qtu( module ) );
403 #endif
404         i_type = config_GetType( p_intf, qtu( option ) ) & 0xf0;
405         switch( i_type )
406         {
407             case VLC_VAR_INTEGER:
408             case VLC_VAR_BOOL:
409                 val.i_int = config_GetInt( p_intf, qtu( option ) );
410                 break;
411             case VLC_VAR_FLOAT:
412                 val.f_float = config_GetFloat( p_intf, qtu( option ) );
413                 break;
414             case VLC_VAR_STRING:
415                 val.psz_string = config_GetPsz( p_intf, qtu( option ) );
416                 break;
417         }
418     }
419     else
420     {
421         i_type = var_Type( p_obj, qtu( option ) ) & 0xf0;
422         var_Get( p_obj, qtu( option ), &val );
423         vlc_object_release( p_obj );
424     }
425
426     /* Try to cast to all the widgets we're likely to encounter. Only
427      * one of the casts is expected to work. */
428     QSlider        *slider        = qobject_cast<QSlider*>       ( widget );
429     QCheckBox      *checkbox      = qobject_cast<QCheckBox*>     ( widget );
430     QSpinBox       *spinbox       = qobject_cast<QSpinBox*>      ( widget );
431     QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( widget );
432     QDial          *dial          = qobject_cast<QDial*>         ( widget );
433     QLineEdit      *lineedit      = qobject_cast<QLineEdit*>     ( widget );
434     QComboBox      *combobox      = qobject_cast<QComboBox*>     ( widget );
435
436     if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
437     {
438         int i_int = 0;
439         if( slider )        slider->setValue( val.i_int );
440         else if( checkbox ) checkbox->setCheckState( val.i_int? Qt::Checked
441                                                               : Qt::Unchecked );
442         else if( spinbox )  spinbox->setValue( val.i_int );
443         else if( dial )     dial->setValue( ( 540-val.i_int )%360 );
444         else if( lineedit )
445         {
446             char str[30];
447             sprintf( str, "%06X", val.i_int );
448             lineedit->setText( str );
449         }
450         else if( combobox ) combobox->setCurrentIndex(
451                             combobox->findData( val.i_int ) );
452         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
453     }
454     else if( i_type == VLC_VAR_FLOAT )
455     {
456         double f_float = 0;
457         if( slider ) slider->setValue( ( int )( val.f_float*( double )slider->tickInterval() ) ); /* hack alert! */
458         else if( doublespinbox ) doublespinbox->setValue( val.f_float );
459         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
460     }
461     else if( i_type == VLC_VAR_STRING )
462     {
463         if( lineedit ) lineedit->setText( qfu( val.psz_string ) );
464         else if( combobox ) combobox->setCurrentIndex(
465                             combobox->findData( qfu( val.psz_string ) ) );
466         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
467         free( val.psz_string );
468     }
469     else
470         msg_Err( p_intf,
471                  "Module %s's %s variable is of an unsupported type ( %d )",
472                  qtu( module ),
473                  qtu( option ),
474                  i_type );
475 }
476
477 void ExtVideo::updateFilterOptions()
478 {
479     QString module = ModuleFromWidgetName( sender()->parent() );
480     //std::cout << "Module name: " << module.toStdString() << std::endl;
481     QString option = OptionFromWidgetName( sender() );
482     //std::cout << "Option name: " << option.toStdString() << std::endl;
483
484     vlc_object_t *p_obj = ( vlc_object_t * )
485         vlc_object_find_name( p_intf->p_libvlc,
486                               qtu( module ),
487                               FIND_CHILD );
488     if( !p_obj )
489     {
490         msg_Err( p_intf, "Module %s not found.", qtu( module ) );
491         return;
492     }
493
494     int i_type = var_Type( p_obj, qtu( option ) );
495     bool b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
496     if( !b_is_command )
497     {
498         msg_Warn( p_intf, "Module %s's %s variable isn't a command. You'll need to restart the filter to take change into account.",
499                  qtu( module ),
500                  qtu( option ) );
501         /* FIXME: restart automatically somewhere near the end of this function */
502     }
503
504     /* Try to cast to all the widgets we're likely to encounter. Only
505      * one of the casts is expected to work. */
506     QSlider        *slider        = qobject_cast<QSlider*>       ( sender() );
507     QCheckBox      *checkbox      = qobject_cast<QCheckBox*>     ( sender() );
508     QSpinBox       *spinbox       = qobject_cast<QSpinBox*>      ( sender() );
509     QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
510     QDial          *dial          = qobject_cast<QDial*>         ( sender() );
511     QLineEdit      *lineedit      = qobject_cast<QLineEdit*>     ( sender() );
512     QComboBox      *combobox      = qobject_cast<QComboBox*>     ( sender() );
513
514     i_type &= 0xf0;
515     if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
516     {
517         int i_int = 0;
518         if( slider )        i_int = slider->value();
519         else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
520         else if( spinbox )  i_int = spinbox->value();
521         else if( dial )     i_int = ( 540-dial->value() )%360;
522         else if( lineedit ) i_int = lineedit->text().toInt( NULL,16 );
523         else if( combobox ) i_int = combobox->itemData( combobox->currentIndex() ).toInt();
524         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
525         config_PutInt( p_intf, qtu( option ), i_int );
526         if( b_is_command )
527         {
528             if( i_type == VLC_VAR_INTEGER )
529                 var_SetInteger( p_obj, qtu( option ), i_int );
530             else
531                 var_SetBool( p_obj, qtu( option ), i_int );
532         }
533     }
534     else if( i_type == VLC_VAR_FLOAT )
535     {
536         double f_float = 0;
537         if( slider )             f_float = ( double )slider->value()
538                                          / ( double )slider->tickInterval(); /* hack alert! */
539         else if( doublespinbox ) f_float = doublespinbox->value();
540         else if( lineedit ) f_float = lineedit->text().toDouble();
541         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
542         config_PutFloat( p_intf, qtu( option ), f_float );
543         if( b_is_command )
544             var_SetFloat( p_obj, qtu( option ), f_float );
545     }
546     else if( i_type == VLC_VAR_STRING )
547     {
548         char *psz_string = NULL;
549         if( lineedit ) psz_string = strdup( qtu( lineedit->text() ) );
550         else if( combobox ) psz_string = strdup( qtu( combobox->itemData(
551                                        combobox->currentIndex() ).toString() ) );
552         else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
553         config_PutPsz( p_intf, qtu( option ), psz_string );
554         if( b_is_command )
555             var_SetString( p_obj, qtu( option ), psz_string );
556         free( psz_string );
557     }
558     else
559         msg_Err( p_intf,
560                  "Module %s's %s variable is of an unsupported type ( %d )",
561                  qtu( module ),
562                  qtu( option ),
563                  i_type );
564
565     vlc_object_release( p_obj );
566 }
567
568 #if 0
569 void ExtVideo::gotoConf( QObject* src )
570 {
571 #define SHOWCONF( module ) \
572     if( src->objectName().contains( module ) ) \
573     { \
574         PrefsDialog::getInstance( p_intf )->showModulePrefs( module ); \
575         return; \
576     }
577     SHOWCONF( "clone" );
578     SHOWCONF( "magnify" );
579     SHOWCONF( "wave" );
580     SHOWCONF( "ripple" );
581     SHOWCONF( "invert" );
582     SHOWCONF( "puzzle" );
583     SHOWCONF( "wall" );
584     SHOWCONF( "gradient" );
585     SHOWCONF( "colorthres" )
586 }
587 #endif
588
589 /**********************************************************************
590  * v4l2 controls
591  **********************************************************************/
592
593 ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
594     : QWidget( _parent ), p_intf( _p_intf )
595 {
596     ui.setupUi( this );
597
598     BUTTONACT( ui.refresh, Refresh() );
599
600     box = NULL;
601 }
602
603 ExtV4l2::~ExtV4l2()
604 {
605     if( box )
606         delete box;
607 }
608
609 void ExtV4l2::showEvent( QShowEvent *event )
610 {
611     QWidget::showEvent( event );
612     Refresh();
613 }
614
615 void ExtV4l2::Refresh( void )
616 {
617     vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
618     ui.help->hide();
619     if( box )
620     {
621         ui.vboxLayout->removeWidget( box );
622         delete box;
623         box = NULL;
624     }
625     if( p_obj )
626     {
627         msg_Dbg( p_intf, "Found v4l2 instance" );
628         vlc_value_t val, text, name;
629         int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
630                                 &val, &text );
631         if( i_ret < 0 )
632         {
633             msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
634             ui.help->show();
635             vlc_object_release( p_obj );
636             return;
637         }
638
639         box = new QGroupBox( this );
640         ui.vboxLayout->addWidget( box );
641         QVBoxLayout *layout = new QVBoxLayout( box );
642         box->setLayout( layout );
643
644         for( int i = 0; i < val.p_list->i_count; i++ )
645         {
646             const char *psz_var = text.p_list->p_values[i].psz_string;
647             var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &name, NULL );
648             const char *psz_label = name.psz_string;
649             msg_Dbg( p_intf, "v4l2 control \"%x\": %s (%s)",
650                      val.p_list->p_values[i].i_int, psz_var, name.psz_string );
651
652             int i_type = var_Type( p_obj, psz_var );
653             switch( i_type & VLC_VAR_TYPE )
654             {
655                 case VLC_VAR_INTEGER:
656                 {
657                     QLabel *label = new QLabel( psz_label, box );
658                     QHBoxLayout *hlayout = new QHBoxLayout();
659                     hlayout->addWidget( label );
660                     int i_val = var_GetInteger( p_obj, psz_var );
661                     if( i_type & VLC_VAR_HASCHOICE )
662                     {
663                         QComboBox *combobox = new QComboBox( box );
664                         combobox->setObjectName( psz_var );
665
666                         vlc_value_t val2, text2;
667                         var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
668                                     &val2, &text2 );
669                         for( int j = 0; j < val2.p_list->i_count; j++ )
670                         {
671                             combobox->addItem(
672                                        text2.p_list->p_values[j].psz_string,
673                                        val2.p_list->p_values[j].i_int );
674                             if( i_val == val2.p_list->p_values[j].i_int )
675                                 combobox->setCurrentIndex( j );
676                         }
677                         var_Change( p_obj, psz_var, VLC_VAR_FREELIST,
678                                     &val2, &text2 );
679
680                         CONNECT( combobox, currentIndexChanged( int ), this,
681                                  ValueChange( int ) );
682                         hlayout->addWidget( combobox );
683                     }
684                     else
685                     {
686                         QSlider *slider = new QSlider( box );
687                         slider->setObjectName( psz_var );
688                         slider->setOrientation( Qt::Horizontal );
689                         vlc_value_t val2;
690                         var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
691                                     &val2, NULL );
692                         slider->setMinimum( val2.i_int );
693                         var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
694                                     &val2, NULL );
695                         slider->setMaximum( val2.i_int );
696                         var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
697                                     &val2, NULL );
698                         slider->setSingleStep( val2.i_int );
699                         slider->setValue( i_val );
700
701                         CONNECT( slider, valueChanged( int ), this,
702                                  ValueChange( int ) );
703                         hlayout->addWidget( slider );
704                     }
705                     layout->addLayout( hlayout );
706                     break;
707                 }
708                 case VLC_VAR_BOOL:
709                 {
710                     QCheckBox *button = new QCheckBox( psz_label, box );
711                     button->setObjectName( psz_var );
712                     button->setChecked( var_GetBool( p_obj, psz_var ) );
713
714                     CONNECT( button, clicked( bool ), this,
715                              ValueChange( bool ) );
716                     layout->addWidget( button );
717                     break;
718                 }
719                 case VLC_VAR_VOID:
720                 {
721                     if( i_type & VLC_VAR_ISCOMMAND )
722                     {
723                         QPushButton *button = new QPushButton( psz_label, box );
724                         button->setObjectName( psz_var );
725
726                         CONNECT( button, clicked( bool ), this,
727                                  ValueChange( bool ) );
728                         layout->addWidget( button );
729                     }
730                     else
731                     {
732                         QLabel *label = new QLabel( psz_label, box );
733                         layout->addWidget( label );
734                     }
735                     break;
736                 }
737                 default:
738                     msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
739                     break;
740             }
741             free( name.psz_string );
742         }
743         var_Change( p_obj, "controls", VLC_VAR_FREELIST, &val, &text );
744         vlc_object_release( p_obj );
745     }
746     else
747     {
748         msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
749         ui.help->show();
750     }
751
752 }
753
754 void ExtV4l2::ValueChange( bool value )
755 {
756     ValueChange( (int)value );
757 }
758
759 void ExtV4l2::ValueChange( int value )
760 {
761     QObject *s = sender();
762     vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
763     if( p_obj )
764     {
765         char *psz_var = strdup( qtu( s->objectName() ) );
766         int i_type = var_Type( p_obj, psz_var );
767         switch( i_type & VLC_VAR_TYPE )
768         {
769             case VLC_VAR_INTEGER:
770                 if( i_type & VLC_VAR_HASCHOICE )
771                 {
772                     QComboBox *combobox = qobject_cast<QComboBox*>( s );
773                     value = combobox->itemData( value ).toInt();
774                 }
775                 var_SetInteger( p_obj, psz_var, value );
776                 break;
777             case VLC_VAR_BOOL:
778                 var_SetBool( p_obj, psz_var, value );
779                 break;
780             case VLC_VAR_VOID:
781                 var_SetVoid( p_obj, psz_var );
782                 break;
783         }
784         free( psz_var );
785         vlc_object_release( p_obj );
786     }
787     else
788     {
789         msg_Warn( p_intf, "Oops, v4l2 object isn't available anymore" );
790         Refresh();
791     }
792 }
793
794 /**********************************************************************
795  * Equalizer
796  **********************************************************************/
797
798 static const QString band_frequencies[] =
799 {
800     "  60 Hz  ", " 170 Hz ", " 310 Hz ", " 600 Hz ", "  1 kHz ",
801     "  3 kHz  ", "  6 kHz ", " 12 kHz ", " 14 kHz ", " 16 kHz "
802 };
803
804 Equalizer::Equalizer( intf_thread_t *_p_intf, QWidget *_parent ) :
805                             QWidget( _parent ) , p_intf( _p_intf )
806 {
807     QFont smallFont = QApplication::font( static_cast<QWidget*>( 0 ) );
808     smallFont.setPointSize( smallFont.pointSize() - 3 );
809
810     ui.setupUi( this );
811     presetsComboBox = ui.presetsCombo;
812
813     ui.preampLabel->setFont( smallFont );
814     ui.preampSlider->setMaximum( 400 );
815     for( int i = 0 ; i < NB_PRESETS ; i ++ )
816     {
817         ui.presetsCombo->addItem( qtr( preset_list_text[i] ),
818                                   QVariant( i ) );
819     }
820     CONNECT( ui.presetsCombo, activated( int ), this, setPreset( int ) );
821
822     BUTTONACT( ui.enableCheck, enable() );
823     BUTTONACT( ui.eq2PassCheck, set2Pass() );
824
825     CONNECT( ui.preampSlider, valueChanged( int ), this, setPreamp() );
826
827     QGridLayout *grid = new QGridLayout( ui.frame );
828     grid->setMargin( 0 );
829     for( int i = 0 ; i < BANDS ; i++ )
830     {
831         bands[i] = new QSlider( Qt::Vertical );
832         bands[i]->setMaximum( 400 );
833         bands[i]->setValue( 200 );
834         CONNECT( bands[i], valueChanged( int ), this, setBand() );
835         band_texts[i] = new QLabel( band_frequencies[i] + "\n0.0dB" );
836         band_texts[i]->setFont( smallFont );
837         grid->addWidget( bands[i], 0, i );
838         grid->addWidget( band_texts[i], 1, i );
839     }
840
841     /* Write down initial values */
842     aout_instance_t *p_aout = ( aout_instance_t * )vlc_object_find( p_intf,
843                                     VLC_OBJECT_AOUT, FIND_ANYWHERE );
844     char *psz_af;
845     char *psz_bands;
846     float f_preamp;
847     if( p_aout )
848     {
849         psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
850         if( var_GetBool( p_aout, "equalizer-2pass" ) )
851             ui.eq2PassCheck->setChecked( true );
852         psz_bands = var_GetNonEmptyString( p_aout, "equalizer-bands" );
853         f_preamp = var_GetFloat( p_aout, "equalizer-preamp" );
854         vlc_object_release( p_aout );
855     }
856     else
857     {
858         psz_af = config_GetPsz( p_intf, "audio-filter" );
859         if( config_GetInt( p_intf, "equalizer-2pass" ) )
860             ui.eq2PassCheck->setChecked( true );
861         psz_bands = config_GetPsz( p_intf, "equalizer-bands" );
862         f_preamp = config_GetFloat( p_intf, "equalizer-preamp" );
863     }
864     if( psz_af && strstr( psz_af, "equalizer" ) != NULL )
865         ui.enableCheck->setChecked( true );
866     free( psz_af );
867     enable( ui.enableCheck->isChecked() );
868
869     setValues( psz_bands, f_preamp );
870 }
871
872 Equalizer::~Equalizer()
873 {
874 }
875
876 void Equalizer::enable()
877 {
878     bool en = ui.enableCheck->isChecked();
879     aout_EnableFilter( VLC_OBJECT( p_intf ), "equalizer",
880                        en ? VLC_TRUE : VLC_FALSE );
881 //    aout_EnableFilter( VLC_OBJECT( p_intf ), "upmixer",
882 //                       en ? VLC_TRUE : VLC_FALSE );
883 //     aout_EnableFilter( VLC_OBJECT( p_intf ), "vsurround",
884 //                       en ? VLC_TRUE : VLC_FALSE );
885      enable( en );
886 }
887
888 void Equalizer::enable( bool en )
889 {
890     ui.eq2PassCheck->setEnabled( en );
891     ui.preampLabel->setEnabled( en );
892     ui.preampSlider->setEnabled( en  );
893     for( int i = 0 ; i< BANDS; i++ )
894     {
895         bands[i]->setEnabled( en ); band_texts[i]->setEnabled( en );
896     }
897 }
898
899 void Equalizer::set2Pass()
900 {
901     aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
902                                  VLC_OBJECT_AOUT, FIND_ANYWHERE );
903     vlc_bool_t b_2p = ui.eq2PassCheck->isChecked();
904
905     if( p_aout == NULL )
906         config_PutInt( p_intf, "equalizer-2pass", b_2p );
907     else
908     {
909         var_SetBool( p_aout, "equalizer-2pass", b_2p );
910         config_PutInt( p_intf, "equalizer-2pass", b_2p );
911         for( int i = 0; i < p_aout->i_nb_inputs; i++ )
912         {
913             p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
914         }
915         vlc_object_release( p_aout );
916     }
917 }
918
919 void Equalizer::setPreamp()
920 {
921     float f= ( float )(  ui.preampSlider->value() ) /10 - 20;
922     char psz_val[5];
923     aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
924                                        VLC_OBJECT_AOUT, FIND_ANYWHERE );
925
926     sprintf( psz_val, "%.1f", f );
927     ui.preampLabel->setText( qtr( "Preamp\n" ) + psz_val + qtr( "dB" ) );
928     if( p_aout )
929     {
930         delCallbacks( p_aout );
931         var_SetFloat( p_aout, "equalizer-preamp", f );
932         addCallbacks( p_aout );
933         vlc_object_release( p_aout );
934     }
935     config_PutFloat( p_intf, "equalizer-preamp", f );
936 }
937
938 void Equalizer::setBand()
939 {
940     char psz_values[102]; memset( psz_values, 0, 102 );
941
942     /**\todo smoothing */
943
944     for( int i = 0 ; i< BANDS ; i++ )
945     {
946         char psz_val[5];
947         float f_val = ( float )(  bands[i]->value() ) / 10 - 20 ;
948         sprintf( psz_values, "%s %f", psz_values, f_val );
949         sprintf( psz_val, "% 5.1f", f_val );
950         band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val + "dB" );
951     }
952     aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
953                                           VLC_OBJECT_AOUT, FIND_ANYWHERE );
954     if( p_aout )
955     {
956         delCallbacks( p_aout );
957         var_SetString( p_aout, "equalizer-bands", psz_values );
958         addCallbacks( p_aout );
959         vlc_object_release( p_aout );
960     }
961 }
962 void Equalizer::setValues( char *psz_bands, float f_preamp )
963 {
964     char *p = psz_bands;
965     if ( p )
966     {
967         for( int i = 0; i < 10; i++ )
968         {
969             char psz_val[5];
970             float f = strtof( p, &p );
971             int  i_val= ( int )( ( f + 20 ) * 10 );
972             bands[i]->setValue(  i_val );
973             sprintf( psz_val, "% 5.1f", f );
974             band_texts[i]->setText( band_frequencies[i] + "\n" + psz_val +
975                                     "dB" );
976             if( p == NULL || *p == '\0' ) break;
977             p++;
978             if( *p == '\0' )  break;
979         }
980     }
981     char psz_val[5];
982     int i_val = ( int )( ( f_preamp + 20 ) * 10 );
983     sprintf( psz_val, "%.1f", f_preamp );
984     ui.preampSlider->setValue( i_val );
985     ui.preampLabel->setText( qtr( "Preamp\n" ) + psz_val + qtr( "dB" ) );
986 }
987
988 void Equalizer::setPreset( int preset )
989 {
990     aout_instance_t *p_aout= ( aout_instance_t * )vlc_object_find( p_intf,
991                                                 VLC_OBJECT_AOUT, FIND_ANYWHERE );
992
993     char psz_values[102]; memset( psz_values, 0, 102 );
994     for( int i = 0 ; i< 10 ;i++ )
995         sprintf( psz_values, "%s %.1f", psz_values,
996                                         eqz_preset_10b[preset]->f_amp[i] );
997
998     if( p_aout )
999     {
1000         delCallbacks( p_aout );
1001         var_SetString( p_aout, "equalizer-bands", psz_values );
1002         var_SetFloat( p_aout, "equalizer-preamp",
1003                       eqz_preset_10b[preset]->f_preamp );
1004         addCallbacks( p_aout );
1005         vlc_object_release( p_aout );
1006     }
1007     config_PutPsz( p_intf, "equalizer-bands", psz_values );
1008     config_PutFloat( p_intf, "equalizer-preamp",
1009                     eqz_preset_10b[preset]->f_preamp );
1010
1011     setValues( psz_values, eqz_preset_10b[preset]->f_preamp );
1012 }
1013
1014 static int PresetCallback( vlc_object_t *p_this, char const *psz_cmd,
1015                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
1016 {
1017     char *psz_preset = newval.psz_string;
1018     Equalizer *eq = ( Equalizer * )p_data;
1019     eq->presetsComboBox->setCurrentIndex( eq->presetsComboBox->findText( qfu( psz_preset ) ) );
1020     return VLC_SUCCESS;
1021 }
1022
1023 void Equalizer::delCallbacks( aout_instance_t *p_aout )
1024 {
1025     //var_DelCallback( p_aout, "equalizer-bands", EqzCallback, this );
1026     //var_DelCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1027     var_DelCallback( p_aout, "equalizer-preset", PresetCallback, this );
1028 }
1029
1030 void Equalizer::addCallbacks( aout_instance_t *p_aout )
1031 {
1032     //var_AddCallback( p_aout, "equalizer-bands", EqzCallback, this );
1033     //var_AddCallback( p_aout, "equalizer-preamp", EqzCallback, this );
1034     var_AddCallback( p_aout, "equalizer-preset", PresetCallback, this );
1035 }
1036
1037 /**********************************************************************
1038  * Audio filters
1039  **********************************************************************/
1040
1041 /**********************************************************************
1042  * Spatializer
1043  **********************************************************************/
1044 static const char *psz_control_names[] =
1045 {
1046     "Roomsize", "Width" , "Wet", "Dry", "Damp"
1047 };
1048
1049 Spatializer::Spatializer( intf_thread_t *_p_intf, QWidget *_parent ) :
1050     QWidget( _parent ) , p_intf( _p_intf )
1051 {
1052     QFont smallFont = QApplication::font( static_cast<QWidget*>( 0 ) );
1053     smallFont.setPointSize( smallFont.pointSize() - 3 );
1054
1055     QGridLayout *layout = new QGridLayout( this );
1056     layout->setMargin( 0 );
1057
1058     enableCheck = new QCheckBox( qfu( "Enable spatializer" ) );
1059     layout->addWidget( enableCheck, 0, 0, 1, NUM_SP_CTRL );
1060
1061     for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1062     {
1063         spatCtrl[i] = new QSlider( Qt::Vertical );
1064         if( i < 2 )
1065         {
1066             spatCtrl[i]->setMaximum( 10 );
1067             spatCtrl[i]->setValue( 2 );
1068         }
1069         else
1070         {
1071             spatCtrl[i]->setMaximum( 10 );
1072             spatCtrl[i]->setValue( 0 );
1073             spatCtrl[i]->setMinimum( -10 );
1074         }
1075         oldControlVars[i] = spatCtrl[i]->value();
1076         CONNECT( spatCtrl[i], valueChanged( int ), this, setInitValues() );
1077         ctrl_texts[i] = new QLabel( qfu( psz_control_names[i] ) + "\n" );
1078         ctrl_texts[i]->setFont( smallFont );
1079         ctrl_readout[i] = new QLabel( "" );
1080         ctrl_readout[i]->setFont( smallFont );
1081         layout->addWidget( spatCtrl[i], 1, i );
1082         layout->addWidget( ctrl_readout[i], 2, i );
1083         layout->addWidget( ctrl_texts[i], 3, i );
1084     }
1085
1086     BUTTONACT( enableCheck, enable() );
1087
1088     /* Write down initial values */
1089     aout_instance_t *p_aout = ( aout_instance_t * )
1090         vlc_object_find( p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1091     char *psz_af;
1092
1093     if( p_aout )
1094     {
1095         psz_af = var_GetNonEmptyString( p_aout, "audio-filter" );
1096         for( int i = 0; i < NUM_SP_CTRL ; i++ )
1097         {
1098             controlVars[i] = var_GetFloat( p_aout, psz_control_names[i] );
1099         }
1100         vlc_object_release( p_aout );
1101     }
1102     else
1103     {
1104         psz_af = config_GetPsz( p_intf, "audio-filter" );
1105         for( int i = 0; i < NUM_SP_CTRL ; i++ )
1106         {
1107             controlVars[i] = config_GetFloat( p_intf, psz_control_names[i] );
1108         }
1109     }
1110     if( psz_af && strstr( psz_af, "spatializer" ) != NULL )
1111         enableCheck->setChecked( true );
1112     free( psz_af );
1113     enable( enableCheck->isChecked() );
1114     setValues( controlVars );
1115 }
1116
1117 Spatializer::~Spatializer()
1118 {
1119 }
1120
1121 void Spatializer::enable()
1122 {
1123     bool en = enableCheck->isChecked();
1124     aout_EnableFilter( VLC_OBJECT( p_intf ), "spatializer",
1125             en ? VLC_TRUE : VLC_FALSE );
1126     enable( en );
1127 }
1128
1129 void Spatializer::enable( bool en )
1130 {
1131     for( int i = 0 ; i< NUM_SP_CTRL; i++ )
1132     {
1133         spatCtrl[i]->setEnabled( en );
1134         ctrl_texts[i]->setEnabled( en );
1135         ctrl_readout[i]->setEnabled( en );
1136     }
1137 }
1138 void Spatializer::setInitValues()
1139 {
1140     setValues( controlVars );
1141 }
1142
1143 void Spatializer::setValues( float *controlVars )
1144 {
1145     char psz_val[5];
1146     char var_name[5];
1147     aout_instance_t *p_aout= ( aout_instance_t * )
1148         vlc_object_find( p_intf, VLC_OBJECT_AOUT, FIND_ANYWHERE );
1149
1150     for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1151     {
1152         float f= ( float )(  spatCtrl[i]->value() );
1153         sprintf( psz_val, "%.1f", f );
1154         ctrl_readout[i]->setText( psz_val );
1155     }
1156     if( p_aout )
1157     {
1158         for( int i = 0 ; i < NUM_SP_CTRL ; i++ )
1159         {
1160             if( oldControlVars[i] != spatCtrl[i]->value() )
1161             {
1162                 var_SetFloat( p_aout, psz_control_names[i],
1163                         ( float )spatCtrl[i]->value() );
1164                 config_PutFloat( p_intf, psz_control_names[i],
1165                         ( float ) spatCtrl[i]->value() );
1166                 oldControlVars[i] = ( float ) spatCtrl[i]->value();
1167             }
1168         }
1169         vlc_object_release( p_aout );
1170     }
1171
1172 }
1173 void Spatializer::delCallbacks( aout_instance_t *p_aout )
1174 {
1175     //    var_DelCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1176     //    var_DelCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1177 }
1178
1179 void Spatializer::addCallbacks( aout_instance_t *p_aout )
1180 {
1181     //    var_AddCallback( p_aout, "Spatializer-bands", EqzCallback, this );
1182     //    var_AddCallback( p_aout, "Spatializer-preamp", EqzCallback, this );
1183 }
1184
1185 #include <QToolButton>
1186 #include <QGridLayout>
1187
1188 SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
1189                             QWidget( _parent ) , p_intf( _p_intf )
1190 {
1191     QGroupBox *AVBox, *subsBox;
1192
1193     QToolButton *moinsAV, *plusAV;
1194     QToolButton *moinssubs, *plussubs;
1195     QToolButton *moinssubSpeed, *plussubSpeed;
1196
1197     QToolButton *updateButton;
1198
1199     QGridLayout *mainLayout = new QGridLayout( this );
1200
1201     /* AV sync */
1202     AVBox = new QGroupBox( qtr( "Audio/Video" ) );
1203     QGridLayout *AVLayout = new QGridLayout( AVBox );
1204
1205     moinsAV = new QToolButton;
1206     moinsAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1207     moinsAV->setAutoRaise( true );
1208     moinsAV->setText( "-" );
1209     AVLayout->addWidget( moinsAV, 0, 1, 1, 1 );
1210
1211     plusAV = new QToolButton;
1212     plusAV->setToolButtonStyle( Qt::ToolButtonTextOnly );
1213     plusAV->setAutoRaise( true );
1214     plusAV->setText( "+" );
1215     AVLayout->addWidget( plusAV, 0, 3, 1, 1 );
1216
1217     QLabel *AVLabel = new QLabel;
1218     AVLabel->setText( qtr( "Advance of audio over video:" ) );
1219     AVLayout->addWidget( AVLabel, 0, 0, 1, 1 );
1220
1221     AVSpin = new QDoubleSpinBox;
1222     AVSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1223     AVSpin->setDecimals( 3 );
1224     AVSpin->setMinimum( -100 );
1225     AVSpin->setMaximum( 100 );
1226     AVSpin->setSingleStep( 0.1 );
1227     AVSpin->setToolTip( qtr( "A positive value means that\n"
1228                              "the audio is ahead of the video" ) );
1229     AVSpin->setSuffix( "s" );
1230     AVLayout->addWidget( AVSpin, 0, 2, 1, 1 );
1231     mainLayout->addWidget( AVBox, 1, 0, 1, 5 );
1232
1233
1234     /* Subs */
1235     subsBox = new QGroupBox( qtr( "Subtitles/Video" ) );
1236     QGridLayout *subsLayout = new QGridLayout( subsBox );
1237
1238     moinssubs = new QToolButton;
1239     moinssubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1240     moinssubs->setAutoRaise( true );
1241     moinssubs->setText( "-" );
1242     subsLayout->addWidget( moinssubs, 0, 1, 1, 1 );
1243
1244     plussubs = new QToolButton;
1245     plussubs->setToolButtonStyle( Qt::ToolButtonTextOnly );
1246     plussubs->setAutoRaise( true );
1247     plussubs->setText( "+" );
1248     subsLayout->addWidget( plussubs, 0, 3, 1, 1 );
1249
1250     QLabel *subsLabel = new QLabel;
1251     subsLabel->setText( qtr( "Advance of subtitles over video:" ) );
1252     subsLayout->addWidget( subsLabel, 0, 0, 1, 1 );
1253
1254     subsSpin = new QDoubleSpinBox;
1255     subsSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1256     subsSpin->setDecimals( 3 );
1257     subsSpin->setMinimum( -100 );
1258     subsSpin->setMaximum( 100 );
1259     subsSpin->setSingleStep( 0.1 );
1260     subsSpin->setToolTip( qtr( "A positive value means that\n"
1261                              "the subtitles are ahead of the video" ) );
1262     subsSpin->setSuffix( "s" );
1263     subsLayout->addWidget( subsSpin, 0, 2, 1, 1 );
1264
1265
1266     moinssubSpeed = new QToolButton;
1267     moinssubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1268     moinssubSpeed->setAutoRaise( true );
1269     moinssubSpeed->setText( "-" );
1270     subsLayout->addWidget( moinssubSpeed, 1, 1, 1, 1 );
1271
1272     plussubSpeed = new QToolButton;
1273     plussubSpeed->setToolButtonStyle( Qt::ToolButtonTextOnly );
1274     plussubSpeed->setAutoRaise( true );
1275     plussubSpeed->setText( "+" );
1276     subsLayout->addWidget( plussubSpeed, 1, 3, 1, 1 );
1277
1278     QLabel *subSpeedLabel = new QLabel;
1279     subSpeedLabel->setText( qtr( "Speed of the subtitles:" ) );
1280     subsLayout->addWidget( subSpeedLabel, 1, 0, 1, 3 );
1281
1282     subSpeedSpin = new QDoubleSpinBox;
1283     subSpeedSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
1284     subSpeedSpin->setDecimals( 3 );
1285     subSpeedSpin->setMinimum( 1 );
1286     subSpeedSpin->setMaximum( 100 );
1287     subSpeedSpin->setSingleStep( 0.2 );
1288     subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
1289
1290     mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
1291
1292     updateButton = new QToolButton;
1293     updateButton->setAutoRaise( true );
1294     updateButton->setText( "u" );
1295     updateButton->setToolTip( qtr( "Force update of the values in this dialog" ) );
1296     mainLayout->addWidget( updateButton, 0, 4, 1, 1 );
1297
1298
1299     /* Various Connects */
1300     CONNECT( moinsAV, clicked(), AVSpin, stepDown () );
1301     CONNECT( plusAV, clicked(), AVSpin, stepUp () );
1302     CONNECT( moinssubs, clicked(), subsSpin, stepDown () );
1303     CONNECT( plussubs, clicked(), subsSpin, stepUp () );
1304     CONNECT( moinssubSpeed, clicked(), subSpeedSpin, stepDown () );
1305     CONNECT( plussubSpeed, clicked(), subSpeedSpin, stepUp () );
1306     CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
1307     CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
1308     CONNECT( subSpeedSpin, valueChanged ( double ),
1309              this, adjustSubsSpeed( double ) );
1310     BUTTONACT( updateButton, update() );
1311
1312     /* Set it */
1313     update();
1314 }
1315
1316 void SyncControls::update()
1317 {
1318     int64_t i_delay;
1319     if( THEMIM->getInput() )
1320     {
1321         i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1322         AVSpin->setValue( ( (double)i_delay ) / 1000000 );
1323         i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1324         subsSpin->setValue( ( (double)i_delay ) / 1000000 );
1325         subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
1326     }
1327 }
1328
1329 void SyncControls::advanceAudio( double f_advance )
1330 {
1331     if( THEMIM->getInput() )
1332     {
1333         int64_t i_delay = var_GetTime( THEMIM->getInput(), "audio-delay" );
1334         i_delay += f_advance * 1000000;
1335         var_SetTime( THEMIM->getInput(), "audio-delay", i_delay );
1336         msg_Dbg( p_intf, "I am advancing Audio %d", f_advance );
1337     }
1338 }
1339
1340 void SyncControls::advanceSubs( double f_advance )
1341 {
1342     if( THEMIM->getInput() )
1343     {
1344         int64_t i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
1345         i_delay += f_advance * 1000000;
1346         var_SetTime( THEMIM->getInput(), "spu-delay", i_delay );
1347         msg_Dbg( p_intf, "I am advancing subtitles %d", f_advance );
1348     }
1349 }
1350
1351 void SyncControls::adjustSubsSpeed( double f_fps )
1352 {
1353     if( THEMIM->getInput() )
1354     {
1355         var_SetFloat( THEMIM->getInput(), "sub-fps", f_fps );
1356     }
1357 }
1358
1359 /**********************************************************************
1360  * Video filters / Adjust
1361  **********************************************************************/
1362
1363 /**********************************************************************
1364  * Extended playbak controls
1365  **********************************************************************/