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