Commit caf9c00b authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Settings: Allow Int and Double widget to have editable boundaries.

parent 6477c350
......@@ -32,6 +32,13 @@ DoubleWidget::DoubleWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
changed( s->get() );
connect( s, SIGNAL( changed( const QVariant& ) ),
this, SLOT( changed( const QVariant& ) ) );
if ( ( s->flags() & SettingValue::Clamped ) != 0 )
{
if ( s->min().isValid() )
m_spinbox->setMinimum( s->min().toDouble() );
if ( s->max().isValid() )
m_spinbox->setMaximum( s->max().toDouble() );
}
}
QWidget*
......
......@@ -31,6 +31,13 @@ IntWidget::IntWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
m_spinbox = new QSpinBox( parent );
connect( s, SIGNAL( changed( const QVariant& ) ),
this, SLOT( changed( const QVariant& ) ) );
if ( ( s->flags() & SettingValue::Clamped ) != 0 )
{
if ( s->min().isValid() )
m_spinbox->setMinimum( s->min().toInt() );
if ( s->max().isValid() )
m_spinbox->setMaximum( s->max().toInt() );
}
changed( s->get() );
}
......
......@@ -49,12 +49,16 @@ ProjectManager::ProjectManager() : m_projectFile( NULL ), m_needSave( false )
VLMC_CREATE_PROJECT_DOUBLE( "video/VLMCOutputFPS", 29.97,
QT_TRANSLATE_NOOP( "PreferenceWidget", "Output video FPS" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Frame Per Second used when previewing and rendering the project" ) );
VLMC_CREATE_PROJECT_INT( "video/VideoProjectWidth", 480,
SettingValue *width = VLMC_CREATE_PROJECT_VAR( SettingValue::Int, "video/VideoProjectWidth", 480,
QT_TRANSLATE_NOOP( "PreferenceWidget", "Video width" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Width resolution of the output video" ) );
VLMC_CREATE_PROJECT_INT( "video/VideoProjectHeight", 300,
QT_TRANSLATE_NOOP( "PreferenceWidget", "Width resolution of the output video" ),
SettingValue::Clamped );
width->setLimits( 0, 2048 );
SettingValue *height = VLMC_CREATE_PROJECT_VAR( SettingValue::Int, "video/VideoProjectHeight", 300,
QT_TRANSLATE_NOOP( "PreferenceWidget", "Video height" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Height resolution of the output video" ) );
QT_TRANSLATE_NOOP( "PreferenceWidget", "Height resolution of the output video" ),
SettingValue::Clamped );
height->setLimits( 0, 2048 );
VLMC_CREATE_PROJECT_INT( "audio/AudioSampleRate", 0,
QT_TRANSLATE_NOOP( "PreferenceWidget", "Audio samplerate" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "Output project audio samplerate" ) );
......
......@@ -79,3 +79,24 @@ SettingValue::flags() const
{
return m_flags;
}
void
SettingValue::setLimits( const QVariant& min, const QVariant& max )
{
if ( min.isValid() == true )
m_min = min;
if ( max.isValid() == true )
m_max = max;
}
const QVariant&
SettingValue::min() const
{
return m_min;
}
const QVariant&
SettingValue::max() const
{
return m_max;
}
......@@ -53,6 +53,7 @@ class SettingValue : public QObject
/// If this flag is used, then the variable should not be shown in the config widgets.
Private = 1 << 0,
Password = 1 << 1,
Clamped = 1 << 2, ///< When used, the m_min and m_max will be used
};
/**
......@@ -88,6 +89,10 @@ class SettingValue : public QObject
Type type() const;
Flags flags() const;
void setLimits( const QVariant& min, const QVariant& max );
const QVariant& min() const;
const QVariant& max() const;
private:
/**
* \brief the QVariant containingthe value of the settings
......@@ -98,6 +103,8 @@ class SettingValue : public QObject
const char* m_desc;
Type m_type;
Flags m_flags;
QVariant m_min;
QVariant m_max;
signals:
/**
* \brief This signal is emmited while the m_val
......
......@@ -227,7 +227,7 @@ SettingsManager::load( const QDomElement &root )
return true;
}
void
SettingValue*
SettingsManager::createVar( SettingValue::Type type, const QString &key,
const QVariant &defaultValue, const char *name,
const char *desc, SettingsManager::Type varType /*= Vlmc*/,
......@@ -235,12 +235,20 @@ SettingsManager::createVar( SettingValue::Type type, const QString &key,
{
QWriteLocker wlock( &m_rwLock );
SettingValue *val = NULL;
if ( varType == Vlmc && getPair( m_classicSettings, key ) == m_classicSettings.end() )
m_classicSettings.push_back( Pair( key, new SettingValue( type, defaultValue, name, desc, flags ) ) );
{
val = new SettingValue( type, defaultValue, name, desc, flags );
m_classicSettings.push_back( Pair( key, val ) );
}
else if ( varType == Project && getPair( m_xmlSettings, key ) == m_xmlSettings.end() )
m_xmlSettings.push_back( Pair( key, new SettingValue( type, defaultValue, name, desc, flags ) ) );
{
val = new SettingValue( type, defaultValue, name, desc, flags );
m_xmlSettings.push_back( Pair( key, val ) );
}
else
Q_ASSERT_X( false, __FILE__, "creating an already created variable" );
return val;
}
SettingsManager::Pair::Pair( const QString &_key, SettingValue *_value ) :
......
......@@ -125,7 +125,7 @@ class SettingsManager : public QObject, public Singleton<SettingsManager>
SettingList group( const QString &groupName,
SettingsManager::Type type = Vlmc );
void createVar( SettingValue::Type type, const QString &key,
SettingValue *createVar( SettingValue::Type type, const QString &key,
const QVariant &defaultValue,
const char *name, const char *desc,
Type varType = Vlmc,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment