[vlc-devel] [PATCH] Qt: synchronization: subtitles duration parameter
Yuval Tze
yuvaltze at gmail.com
Tue May 10 14:05:01 CEST 2011
- add a spin box to the synchronizations tab that enables the subsdelay filter when its value is changed and disables it when its value is set to 0.
- make the private function ExtVideo::ChangeVFiltersString accessible to other local panels.
---
modules/gui/qt4/components/extended_panels.cpp | 95 +++++++++++++++++++++++-
modules/gui/qt4/components/extended_panels.hpp | 8 ++-
2 files changed, 98 insertions(+), 5 deletions(-)
diff --git a/modules/gui/qt4/components/extended_panels.cpp b/modules/gui/qt4/components/extended_panels.cpp
index 0ffb381..df9b071 100644
--- a/modules/gui/qt4/components/extended_panels.cpp
+++ b/modules/gui/qt4/components/extended_panels.cpp
@@ -53,6 +53,8 @@
#include <vlc_charset.h> /* us_strtod */
+static void ChangeVFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add );
+
#if 0
class ConfClickHandler : public QObject
{
@@ -283,7 +285,7 @@ void ExtVideo::clean()
ui.cropRightPx->setValue( 0 );
}
-void ExtVideo::ChangeVFiltersString( const char *psz_name, bool b_add )
+static void ChangeVFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add )
{
char *psz_parser, *psz_string;
const char *psz_filter_type;
@@ -381,7 +383,7 @@ void ExtVideo::ChangeVFiltersString( const char *psz_name, bool b_add )
}
else
{
- p_vout = THEMIM->getVout();
+ vout_thread_t *p_vout = THEMIM->getVout();
if( p_vout )
{
var_SetString( p_vout, psz_filter_type, psz_string );
@@ -399,7 +401,7 @@ void ExtVideo::updateFilters()
QCheckBox *checkbox = qobject_cast<QCheckBox*>( sender() );
QGroupBox *groupbox = qobject_cast<QGroupBox*>( sender() );
- ChangeVFiltersString( qtu( module ),
+ ChangeVFiltersString( p_intf, qtu( module ),
checkbox ? checkbox->isChecked()
: groupbox->isChecked() );
}
@@ -1462,6 +1464,7 @@ SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
QToolButton *moinsAV, *plusAV;
QToolButton *moinssubs, *plussubs;
QToolButton *moinssubSpeed, *plussubSpeed;
+ QToolButton *moinssubDuration, *plussubDuration;
QToolButton *updateButton;
@@ -1559,6 +1562,30 @@ SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
subSpeedSpin->setSuffix( " fps" );
subsLayout->addWidget( subSpeedSpin, 1, 2, 1, 1 );
+ moinssubDuration = new QToolButton;
+ moinssubDuration->setToolButtonStyle( Qt::ToolButtonTextOnly );
+ moinssubDuration->setAutoRaise( true );
+ moinssubDuration->setText( "-" );
+ subsLayout->addWidget( moinssubDuration, 2, 1, 1, 1 );
+
+ plussubDuration = new QToolButton;
+ plussubDuration->setToolButtonStyle( Qt::ToolButtonTextOnly );
+ plussubDuration->setAutoRaise( true );
+ plussubDuration->setText( "+" );
+ subsLayout->addWidget( plussubDuration, 2, 3, 1, 1 );
+
+ QLabel *subDurationLabel = new QLabel;
+ subDurationLabel->setText( qtr( "Subtitles duration factor:" ) );
+ subsLayout->addWidget( subDurationLabel, 2, 0, 1, 1 );
+
+ subDurationSpin = new QDoubleSpinBox;
+ subDurationSpin->setAlignment( Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter );
+ subDurationSpin->setDecimals( 3 );
+ subDurationSpin->setMinimum( 0 );
+ subDurationSpin->setMaximum( 20 );
+ subDurationSpin->setSingleStep( 0.2 );
+ subsLayout->addWidget( subDurationSpin, 2, 2, 1, 1 );
+
mainLayout->addWidget( subsBox, 2, 0, 2, 5 );
updateButton = new QToolButton;
@@ -1573,10 +1600,14 @@ SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
CONNECT( plussubs, clicked(), subsSpin, stepUp () );
CONNECT( moinssubSpeed, clicked(), subSpeedSpin, stepDown () );
CONNECT( plussubSpeed, clicked(), subSpeedSpin, stepUp () );
+ CONNECT( moinssubDuration, clicked(), subDurationSpin, stepDown () );
+ CONNECT( plussubDuration, clicked(), subDurationSpin, stepUp () );
CONNECT( AVSpin, valueChanged ( double ), this, advanceAudio( double ) ) ;
CONNECT( subsSpin, valueChanged ( double ), this, advanceSubs( double ) ) ;
CONNECT( subSpeedSpin, valueChanged ( double ),
this, adjustSubsSpeed( double ) );
+ CONNECT( subDurationSpin, valueChanged ( double ),
+ this, adjustSubsDuration( double ) );
CONNECT( THEMIM->getIM(), synchroChanged(), this, update() );
BUTTON_SET_ACT_I( updateButton, "", update,
@@ -1586,12 +1617,19 @@ SyncControls::SyncControls( intf_thread_t *_p_intf, QWidget *_parent ) :
update();
}
+SyncControls::~SyncControls()
+{
+ subsdelayClean();
+}
+
void SyncControls::clean()
{
b_userAction = false;
AVSpin->setValue( 0.0 );
subsSpin->setValue( 0.0 );
subSpeedSpin->setValue( 1.0 );
+ subsdelayClean();
+ subDurationSpin->setValue( subsdelayGetFactor() );
b_userAction = true;
}
@@ -1607,6 +1645,7 @@ void SyncControls::update()
i_delay = var_GetTime( THEMIM->getInput(), "spu-delay" );
subsSpin->setValue( ( (double)i_delay ) / 1000000 );
subSpeedSpin->setValue( var_GetFloat( THEMIM->getInput(), "sub-fps" ) );
+ subDurationSpin->setValue( subsdelayGetFactor() );
}
b_userAction = true;
}
@@ -1637,6 +1676,56 @@ void SyncControls::adjustSubsSpeed( double f_fps )
}
}
+void SyncControls::adjustSubsDuration( double f_factor )
+{
+ input_thread_t *p_input = THEMIM->getInput();
+
+ if( p_input && b_userAction )
+ {
+ subsdelaySetFactor( f_factor );
+ ChangeVFiltersString( p_intf, "subsdelay", f_factor > 0 );
+ }
+}
+
+#define CFG_SUBSDELAY_FACTOR "subsdelay-factor"
+
+void SyncControls::subsdelayClean()
+{
+ var_Destroy( p_intf->p_libvlc, CFG_SUBSDELAY_FACTOR );
+ ChangeVFiltersString( p_intf, "subsdelay", false );
+}
+
+void SyncControls::subsdelaySetFactor( double f_factor )
+{
+ vlc_value_t val;
+
+ val.f_float = f_factor;
+ if( var_SetChecked( p_intf->p_libvlc, CFG_SUBSDELAY_FACTOR, VLC_VAR_FLOAT, val ) )
+ {
+ var_Create( p_intf->p_libvlc, CFG_SUBSDELAY_FACTOR, VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
+ var_SetFloat( p_intf->p_libvlc, CFG_SUBSDELAY_FACTOR, f_factor );
+ }
+
+ vlc_object_t *p_obj = ( vlc_object_t * ) vlc_object_find_name( p_intf->p_libvlc, "subsdelay", FIND_CHILD );
+ if( p_obj )
+ {
+ var_SetFloat( p_obj, CFG_SUBSDELAY_FACTOR, f_factor );
+ vlc_object_release( p_obj );
+ }
+}
+
+double SyncControls::subsdelayGetFactor()
+{
+ vlc_value_t val;
+
+ if( !var_GetChecked( p_intf->p_libvlc, CFG_SUBSDELAY_FACTOR, VLC_VAR_FLOAT, &val ) )
+ {
+ return val.f_float;
+ }
+
+ return var_CreateGetFloat( p_intf->p_libvlc, CFG_SUBSDELAY_FACTOR );
+}
+
/**********************************************************************
* Video filters / Adjust
**********************************************************************/
diff --git a/modules/gui/qt4/components/extended_panels.hpp b/modules/gui/qt4/components/extended_panels.hpp
index 5e1d9cd..100e00c 100644
--- a/modules/gui/qt4/components/extended_panels.hpp
+++ b/modules/gui/qt4/components/extended_panels.hpp
@@ -56,7 +56,6 @@ private:
vout_thread_t *p_vout;
void initComboBoxItems( QObject* );
void setWidgetValue( QObject* );
- void ChangeVFiltersString( const char *psz_name, bool b_add );
void clean();
private slots:
void updateFilters();
@@ -176,22 +175,27 @@ class SyncControls : public QWidget
friend class ExtendedDialog;
public:
SyncControls( intf_thread_t *, QWidget * );
- virtual ~SyncControls() {};
+ virtual ~SyncControls();
private:
intf_thread_t *p_intf;
QDoubleSpinBox *AVSpin;
QDoubleSpinBox *subsSpin;
QDoubleSpinBox *subSpeedSpin;
+ QDoubleSpinBox *subDurationSpin;
bool b_userAction;
void clean();
+ void subsdelayClean();
+ void subsdelaySetFactor( double );
+ double subsdelayGetFactor();
public slots:
void update();
private slots:
void advanceAudio( double );
void advanceSubs( double );
void adjustSubsSpeed( double );
+ void adjustSubsDuration( double );
};
#endif
--
1.7.1
More information about the vlc-devel
mailing list