[vlc-commits] Qt: helpers for setting video filter values

Jean-Baptiste Kempf git at videolan.org
Fri Aug 15 20:39:27 CEST 2014


vlc/vlc-2.2 | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Fri Aug 15 07:18:27 2014 +0200| [1961ae181dbcd3f69de427e9f970343251ac16ca] | committer: Jean-Baptiste Kempf

Qt: helpers for setting video filter values

This is mostly splitting Qt and core code

Ref #11613

(cherry picked from commit c803336b8b6c859bf529dbc944668e63b30e2828)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=1961ae181dbcd3f69de427e9f970343251ac16ca
---

 modules/gui/qt4/components/extended_panels.cpp |  127 +++++++++++++-----------
 modules/gui/qt4/components/extended_panels.hpp |    2 +
 2 files changed, 73 insertions(+), 56 deletions(-)

diff --git a/modules/gui/qt4/components/extended_panels.cpp b/modules/gui/qt4/components/extended_panels.cpp
index 1d2f4ac..c579732 100644
--- a/modules/gui/qt4/components/extended_panels.cpp
+++ b/modules/gui/qt4/components/extended_panels.cpp
@@ -583,106 +583,121 @@ void ExtVideo::setWidgetValue( QObject *widget )
                      i_type );
 }
 
-void ExtVideo::updateFilterOptions()
+void ExtVideo::setFilterOption( struct intf_thread_t *p_intf, const char *psz_module, const char *psz_option,
+        int i_int, double f_float, QString val )
 {
-    QString module = ModuleFromWidgetName( sender()->parent() );
-    //msg_Dbg( p_intf, "Module name: %s", qtu( module ) );
-    QString option = OptionFromWidgetName( sender() );
-    //msg_Dbg( p_intf, "Option name: %s", qtu( option ) );
-
-    vlc_object_t *p_obj = ( vlc_object_t * )
-        vlc_object_find_name( p_intf->p_libvlc, qtu( module ) );
+    vlc_object_t *p_obj = ( vlc_object_t * )vlc_object_find_name( p_intf->p_libvlc, psz_module );
     int i_type;
     bool b_is_command;
+
     if( !p_obj )
     {
-        msg_Warn( p_intf, "Module %s not found. You'll need to restart the filter to take the change into account.", qtu( module ) );
-        i_type = config_GetType( p_intf, qtu( option ) );
+        msg_Warn( p_intf, "Module %s not found. You'll need to restart the filter to take the change into account.", psz_module );
+        i_type = config_GetType( p_intf, psz_option );
         b_is_command = false;
     }
     else
     {
-        i_type = var_Type( p_obj, qtu( option ) );
+        i_type = var_Type( p_obj, psz_option );
         if( i_type == 0 )
-            i_type = config_GetType( p_intf, qtu( option ) );
+            i_type = config_GetType( p_intf, psz_option );
         b_is_command = ( i_type & VLC_VAR_ISCOMMAND );
     }
 
-    /* Try to cast to all the widgets we're likely to encounter. Only
-     * one of the casts is expected to work. */
-    QSlider        *slider        = qobject_cast<QSlider*>       ( sender() );
-    QCheckBox      *checkbox      = qobject_cast<QCheckBox*>     ( sender() );
-    QSpinBox       *spinbox       = qobject_cast<QSpinBox*>      ( sender() );
-    QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
-    VLCQDial       *dial          = qobject_cast<VLCQDial*>      ( sender() );
-    QLineEdit      *lineedit      = qobject_cast<QLineEdit*>     ( sender() );
-    QComboBox      *combobox      = qobject_cast<QComboBox*>     ( sender() );
-
     i_type &= VLC_VAR_CLASS;
     if( i_type == VLC_VAR_INTEGER || i_type == VLC_VAR_BOOL )
     {
-        int i_int = 0;
-        if( slider )        i_int = slider->value();
-        else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
-        else if( spinbox )  i_int = spinbox->value();
-        else if( dial )     i_int = ( 540-dial->value() )%360;
-        else if( lineedit ) i_int = lineedit->text().toInt( NULL,16 );
-        else if( combobox ) i_int = combobox->itemData( combobox->currentIndex() ).toInt();
-        else msg_Warn( p_intf, "Could not find the correct Integer widget" );
-        config_PutInt( p_intf, qtu( option ), i_int );
+        if( i_int == -1 )
+            msg_Warn( p_intf, "Could not find the correct Integer widget" );
+        config_PutInt( p_intf, psz_option, i_int );
         if( b_is_command )
         {
             if( i_type == VLC_VAR_INTEGER )
-                var_SetInteger( p_obj, qtu( option ), i_int );
+                var_SetInteger( p_obj, psz_option, i_int );
             else
-                var_SetBool( p_obj, qtu( option ), i_int );
+                var_SetBool( p_obj, psz_option, i_int );
         }
     }
     else if( i_type == VLC_VAR_FLOAT )
     {
-        double f_float = 0;
-        if( slider )             f_float = ( double )slider->value()
-                                         / ( double )slider->tickInterval(); /* hack alert! */
-        else if( doublespinbox ) f_float = doublespinbox->value();
-        else if( dial ) f_float = (540 - dial->value()) % 360;
-        else if( lineedit ) f_float = lineedit->text().toDouble();
-        else msg_Warn( p_intf, "Could not find the correct Float widget" );
-        config_PutFloat( p_intf, qtu( option ), f_float );
+        if( f_float == -1 )
+            msg_Warn( p_intf, "Could not find the correct Float widget" );
+        config_PutFloat( p_intf, psz_option, f_float );
         if( b_is_command )
-            var_SetFloat( p_obj, qtu( option ), f_float );
+            var_SetFloat( p_obj, psz_option, f_float );
     }
     else if( i_type == VLC_VAR_STRING )
     {
-        QString val;
-        if( lineedit )
-            val = lineedit->text();
-        else if( combobox )
-            val = combobox->itemData( combobox->currentIndex() ).toString();
-        else
+        if( val.isNull() )
             msg_Warn( p_intf, "Could not find the correct String widget" );
-        config_PutPsz( p_intf, qtu( option ), qtu( val ) );
+        config_PutPsz( p_intf, psz_option, qtu( val ) );
         if( b_is_command )
-            var_SetString( p_obj, qtu( option ), qtu( val ) );
+            var_SetString( p_obj, psz_option, qtu( val ) );
     }
     else
         msg_Err( p_intf,
                  "Module %s's %s variable is of an unsupported type ( %d )",
-                 qtu( module ),
-                 qtu( option ),
+                 psz_module,
+                 psz_option,
                  i_type );
 
     if( !b_is_command )
     {
         msg_Warn( p_intf, "Module %s's %s variable isn't a command. Brute-restarting the filter.",
-                 qtu( module ),
-                 qtu( option ) );
-        ChangeVFiltersString( p_intf, qtu( module ), false );
-        ChangeVFiltersString( p_intf, qtu( module ), true );
+                 psz_module,
+                 psz_option );
+        ChangeVFiltersString( p_intf, psz_module, false );
+        ChangeVFiltersString( p_intf, psz_module, true );
     }
 
     if( p_obj ) vlc_object_release( p_obj );
 }
 
+void ExtVideo::updateFilterOptions()
+{
+    QString module = ModuleFromWidgetName( sender()->parent() );
+    //msg_Dbg( p_intf, "Module name: %s", qtu( module ) );
+    QString option = OptionFromWidgetName( sender() );
+    //msg_Dbg( p_intf, "Option name: %s", qtu( option ) );
+
+    /* Try to cast to all the widgets we're likely to encounter. Only
+     * one of the casts is expected to work. */
+    QSlider        *slider        = qobject_cast<QSlider*>       ( sender() );
+    QCheckBox      *checkbox      = qobject_cast<QCheckBox*>     ( sender() );
+    QSpinBox       *spinbox       = qobject_cast<QSpinBox*>      ( sender() );
+    QDoubleSpinBox *doublespinbox = qobject_cast<QDoubleSpinBox*>( sender() );
+    VLCQDial       *dial          = qobject_cast<VLCQDial*>      ( sender() );
+    QLineEdit      *lineedit      = qobject_cast<QLineEdit*>     ( sender() );
+    QComboBox      *combobox      = qobject_cast<QComboBox*>     ( sender() );
+
+    int i_int = -1;
+    double f_float = -1.;
+    QString val;
+
+    if( slider ) {
+        i_int = slider->value();
+        f_float = ( double )slider->value() / ( double )slider->tickInterval(); /* hack alert! */
+    }
+    else if( checkbox ) i_int = checkbox->checkState() == Qt::Checked;
+    else if( spinbox ) i_int = spinbox->value();
+    else if( doublespinbox ) f_float = doublespinbox->value();
+    else if( dial ) {
+        i_int = (540 - dial->value()) % 360;
+        f_float = (540 - dial->value()) / 360.;
+    }
+    else if( lineedit ) {
+        i_int = lineedit->text().toInt( NULL,16 );
+        f_float = lineedit->text().toDouble();
+        val = lineedit->text();
+    }
+    else if( combobox ) {
+        i_int = combobox->itemData( combobox->currentIndex() ).toInt();
+        val = combobox->itemData( combobox->currentIndex() ).toString();
+    }
+
+    setFilterOption( p_intf, qtu( module ), qtu( option ), i_int, f_float, val);
+}
+
 /**********************************************************************
  * v4l2 controls
  **********************************************************************/
diff --git a/modules/gui/qt4/components/extended_panels.hpp b/modules/gui/qt4/components/extended_panels.hpp
index 770f558..2e20830 100644
--- a/modules/gui/qt4/components/extended_panels.hpp
+++ b/modules/gui/qt4/components/extended_panels.hpp
@@ -53,6 +53,8 @@ private:
     void initComboBoxItems( QObject* );
     void setWidgetValue( QObject* );
     void clean();
+    static void setFilterOption( struct intf_thread_t *, const char *psz_module, const char *psz_option, int, double, QString );
+
 private slots:
     void updateFilters();
     void updateFilterOptions();



More information about the vlc-commits mailing list