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