Add v4l2 section in extended pannel. The code isn't v4l2 specific at all so it could...
authorAntoine Cellerier <dionoea@videolan.org>
Sat, 8 Dec 2007 19:38:49 +0000 (19:38 +0000)
committerAntoine Cellerier <dionoea@videolan.org>
Sat, 8 Dec 2007 19:38:49 +0000 (19:38 +0000)
modules/gui/qt4/Modules.am
modules/gui/qt4/components/extended_panels.cpp
modules/gui/qt4/components/extended_panels.hpp
modules/gui/qt4/dialogs/extended.cpp
modules/gui/qt4/ui/v4l2.ui [new file with mode: 0644]

index bfa292e..3807d12 100644 (file)
@@ -45,6 +45,7 @@ nodist_SOURCES_qt4 = \
                util/customwidgets.moc.cpp \
                resources.cpp \
                ui/equalizer.h \
+               ui/v4l2.h \
                ui/video_effects.h \
                ui/open_file.h \
                ui/open_disk.h \
@@ -149,6 +150,7 @@ noinst_HEADERS = \
 EXTRA_DIST += \
        res.qrc \
        ui/equalizer.ui \
+       ui/v4l2.ui \
        ui/video_effects.ui \
        ui/open_file.ui \
        ui/open_disk.ui \
index 38325dc..70ddd3a 100644 (file)
@@ -28,6 +28,7 @@
 #include <QFont>
 #include <QGridLayout>
 #include <QSignalMapper>
+#include <QComboBox>
 
 #include "components/extended_panels.hpp"
 #include "dialogs/preferences.hpp"
@@ -556,6 +557,188 @@ void ExtVideo::gotoConf( QObject* src )
 }
 #endif
 
+/**********************************************************************
+ * v4l2 controls
+ **********************************************************************/
+
+ExtV4l2::ExtV4l2( intf_thread_t *_p_intf, QWidget *_parent )
+    : QWidget( _parent ), p_intf( _p_intf )
+{
+    ui.setupUi( this );
+
+    BUTTONACT( ui.refresh, Refresh() );
+
+    layout = new QVBoxLayout;
+    ui.vboxLayout->addLayout( layout );
+
+    help = new QLabel( qtr( "No v4l2 instance found. Press the refresh button to try again." ) );
+    layout->addWidget( help );
+}
+
+ExtV4l2::~ExtV4l2()
+{
+    delete help;
+    delete layout;
+}
+
+void ExtV4l2::Refresh( void )
+{
+    vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
+    help->hide();
+    if( p_obj )
+    {
+        msg_Dbg( p_intf, "Found v4l2 instance" );
+        vlc_value_t val, text, name;
+        int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
+                                &val, &text );
+        if( i_ret < 0 )
+        {
+            msg_Err( p_intf, "Oops" );
+            vlc_object_release( p_obj );
+            return;
+        }
+        for( int i = 0; i < val.p_list->i_count; i++ )
+        {
+            const char *psz_var = text.p_list->p_values[i].psz_string;
+            var_Change( p_obj, psz_var, VLC_VAR_GETTEXT, &name, NULL );
+            const char *psz_label = name.psz_string;
+            msg_Dbg( p_intf, "v4l2 control \"%x\": %s (%s)",
+                     val.p_list->p_values[i].i_int, psz_var, name.psz_string );
+
+            int i_type = var_Type( p_obj, psz_var );
+            switch( i_type & VLC_VAR_TYPE )
+            {
+                case VLC_VAR_INTEGER:
+                {
+                    QLabel *label = new QLabel( psz_label );
+                    QHBoxLayout *hlayout = new QHBoxLayout;
+                    hlayout->addWidget( label );
+                    int i_val = var_GetInteger( p_obj, psz_var );
+                    if( i_type & VLC_VAR_HASCHOICE )
+                    {
+                        QComboBox *combobox = new QComboBox;
+                        combobox->setObjectName( psz_var );
+
+                        vlc_value_t val2, text2;
+                        var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
+                                    &val2, &text2 );
+                        for( int j = 0; j < val2.p_list->i_count; j++ )
+                        {
+                            combobox->addItem(
+                                       text2.p_list->p_values[j].psz_string,
+                                       val2.p_list->p_values[j].i_int );
+                            if( i_val == val2.p_list->p_values[j].i_int )
+                                combobox->setCurrentIndex( j );
+                        }
+                        var_Change( p_obj, psz_var, VLC_VAR_FREELIST,
+                                    &val2, &text2 );
+
+                        CONNECT( combobox, currentIndexChanged( int ), this,
+                                 ValueChange( int ) );
+                        hlayout->addWidget( combobox );
+                    }
+                    else
+                    {
+                        QSlider *slider = new QSlider;
+                        slider->setObjectName( psz_var );
+                        slider->setOrientation( Qt::Horizontal );
+                        vlc_value_t val2;
+                        var_Change( p_obj, psz_var, VLC_VAR_GETMIN,
+                                    &val2, NULL );
+                        slider->setMinimum( val2.i_int );
+                        var_Change( p_obj, psz_var, VLC_VAR_GETMAX,
+                                    &val2, NULL );
+                        slider->setMaximum( val2.i_int );
+                        var_Change( p_obj, psz_var, VLC_VAR_GETSTEP,
+                                    &val2, NULL );
+                        slider->setSingleStep( val2.i_int );
+                        slider->setValue( i_val );
+
+                        CONNECT( slider, valueChanged( int ), this,
+                                 ValueChange( int ) );
+                        hlayout->addWidget( slider );
+                    }
+                    layout->addLayout( hlayout );
+                    break;
+                }
+                case VLC_VAR_BOOL:
+                {
+                    QRadioButton *button = new QRadioButton( psz_label );
+                    button->setObjectName( psz_var );
+                    button->setChecked( var_GetBool( p_obj, psz_var ) );
+
+                    CONNECT( button, clicked( bool ), this,
+                             ValueChange( bool ) );
+                    layout->addWidget( button );
+                    break;
+                }
+                case VLC_VAR_VOID:
+                {
+                    QPushButton *button = new QPushButton( psz_label );
+                    button->setObjectName( psz_var );
+
+                    CONNECT( button, clicked( bool ), this,
+                             ValueChange( bool ) );
+                    layout->addWidget( button );
+                    break;
+                }
+                default:
+                    msg_Warn( p_intf, "Unhandled var type for %s", psz_var );
+                    break;
+            }
+            free( name.psz_string );
+        }
+        var_Change( p_obj, "controls", VLC_VAR_FREELIST, &val, &text );
+        vlc_object_release( p_obj );
+    }
+    else
+    {
+        msg_Dbg( p_intf, "Couldn't find v4l2 instance" );
+        help->show();
+    }
+
+}
+
+void ExtV4l2::ValueChange( bool value )
+{
+    ValueChange( (int)value );
+}
+
+void ExtV4l2::ValueChange( int value )
+{
+    QObject *s = sender();
+    vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( p_intf, "v4l2", FIND_ANYWHERE );
+    if( p_obj )
+    {
+        char *psz_var = strdup( s->objectName().toStdString().c_str() );
+        int i_type = var_Type( p_obj, psz_var );
+        switch( i_type & VLC_VAR_TYPE )
+        {
+            case VLC_VAR_INTEGER:
+                if( i_type & VLC_VAR_HASCHOICE )
+                {
+                    QComboBox *combobox = qobject_cast<QComboBox*>( s );
+                    value = combobox->itemData( value ).toInt();
+                }
+                var_SetInteger( p_obj, psz_var, value );
+                break;
+            case VLC_VAR_BOOL:
+                var_SetBool( p_obj, psz_var, value );
+                break;
+            case VLC_VAR_VOID:
+                var_SetVoid( p_obj, psz_var );
+                break;
+        }
+        free( psz_var );
+        vlc_object_release( p_obj );
+    }
+    else
+    {
+        msg_Warn( p_intf, "Oops, v4l2 object isn't available anymore" );
+        Refresh();
+    }
+}
+
 /**********************************************************************
  * Equalizer
  **********************************************************************/
index 0aee525..596bd2a 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "ui/equalizer.h"
 #include "ui/video_effects.h"
+#include "ui/v4l2.h"
 
 #define BANDS 10
 #define NUM_SP_CTRL 5
@@ -54,6 +55,25 @@ private slots:
     void updateFilterOptions();
 };
 
+class ExtV4l2 : public QWidget
+{
+    Q_OBJECT
+public:
+    ExtV4l2( intf_thread_t *, QWidget * );
+    virtual ~ExtV4l2();
+
+private:
+    intf_thread_t *p_intf;
+    Ui::ExtV4l2Widget ui;
+    QVBoxLayout *layout;
+    QLabel *help;
+
+private slots:
+    void Refresh( void );
+    void ValueChange( int value );
+    void ValueChange( bool value );
+};
+
 class Equalizer: public QWidget
 {
     Q_OBJECT
index 085042b..826f47c 100644 (file)
@@ -58,6 +58,12 @@ ExtendedDialog::ExtendedDialog( intf_thread_t *_p_intf ): QVLCFrame( _p_intf )
     ExtVideo *videoEffect = new ExtVideo( p_intf, this );
     mainTab->addTab( videoEffect, qtr( "Video Adjustments and Effects" ) );
 
+    if( module_Exists( p_intf, "v4l2" ) )
+    {
+        ExtV4l2 *v4l2 = new ExtV4l2( p_intf, this );
+        mainTab->addTab( v4l2, qtr( "v4l2 controls" ) );
+    }
+
     layout->addWidget( mainTab, 0, 0, 1, 5 );
 
     QPushButton *closeButton = new QPushButton( qtr( "Close" ) );
diff --git a/modules/gui/qt4/ui/v4l2.ui b/modules/gui/qt4/ui/v4l2.ui
new file mode 100644 (file)
index 0000000..9077f93
--- /dev/null
@@ -0,0 +1,27 @@
+<ui version="4.0" >
+ <class>ExtV4l2Widget</class>
+ <widget class="QWidget" name="ExtV4l2Widget" >
+  <property name="geometry" >
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle" >
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" >
+   <item>
+    <widget class="QPushButton" name="refresh" >
+     <property name="text" >
+      <string>Refresh</string>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>