From 347dd6ad8fad01b437a9739f53ac42a74ddeae0f Mon Sep 17 00:00:00 2001 From: Antoine Cellerier Date: Sat, 8 Dec 2007 19:38:49 +0000 Subject: [PATCH] Add v4l2 section in extended pannel. The code isn't v4l2 specific at all so it could be adapted for other modules (as long as those define the "controls" variables with a list of controls that can be changed at runtime). --- modules/gui/qt4/Modules.am | 2 + .../gui/qt4/components/extended_panels.cpp | 183 ++++++++++++++++++ .../gui/qt4/components/extended_panels.hpp | 20 ++ modules/gui/qt4/dialogs/extended.cpp | 6 + modules/gui/qt4/ui/v4l2.ui | 27 +++ 5 files changed, 238 insertions(+) create mode 100644 modules/gui/qt4/ui/v4l2.ui diff --git a/modules/gui/qt4/Modules.am b/modules/gui/qt4/Modules.am index bfa292ed0f..3807d129cc 100644 --- a/modules/gui/qt4/Modules.am +++ b/modules/gui/qt4/Modules.am @@ -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 \ diff --git a/modules/gui/qt4/components/extended_panels.cpp b/modules/gui/qt4/components/extended_panels.cpp index 38325dc6d1..70ddd3a42a 100644 --- a/modules/gui/qt4/components/extended_panels.cpp +++ b/modules/gui/qt4/components/extended_panels.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #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( 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 **********************************************************************/ diff --git a/modules/gui/qt4/components/extended_panels.hpp b/modules/gui/qt4/components/extended_panels.hpp index 0aee52505b..596bd2adfd 100644 --- a/modules/gui/qt4/components/extended_panels.hpp +++ b/modules/gui/qt4/components/extended_panels.hpp @@ -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 diff --git a/modules/gui/qt4/dialogs/extended.cpp b/modules/gui/qt4/dialogs/extended.cpp index 085042b9ef..826f47cdd6 100644 --- a/modules/gui/qt4/dialogs/extended.cpp +++ b/modules/gui/qt4/dialogs/extended.cpp @@ -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 index 0000000000..9077f93ec0 --- /dev/null +++ b/modules/gui/qt4/ui/v4l2.ui @@ -0,0 +1,27 @@ + + ExtV4l2Widget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Refresh + + + + + + + + -- 2.39.5