[vlmc-devel] commit: Settings: Allow Int and Double widget to have editable boundaries. ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Mon Jul 26 22:15:18 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Mon Jul 26 11:17:12 2010 +0200| [caf9c00bc56d1c4db0c6e9c64a873060903e83b6] | committer: Hugo Beauzée-Luyssen 

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

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=caf9c00bc56d1c4db0c6e9c64a873060903e83b6
---

 src/Gui/settings/DoubleWidget.cpp |    7 +++++++
 src/Gui/settings/IntWidget.cpp    |    7 +++++++
 src/Project/ProjectManager.cpp    |   12 ++++++++----
 src/Settings/SettingValue.cpp     |   21 +++++++++++++++++++++
 src/Settings/SettingValue.h       |    7 +++++++
 src/Settings/SettingsManager.cpp  |   14 +++++++++++---
 src/Settings/SettingsManager.h    |    2 +-
 7 files changed, 62 insertions(+), 8 deletions(-)

diff --git a/src/Gui/settings/DoubleWidget.cpp b/src/Gui/settings/DoubleWidget.cpp
index 5269613..7570082 100644
--- a/src/Gui/settings/DoubleWidget.cpp
+++ b/src/Gui/settings/DoubleWidget.cpp
@@ -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*
diff --git a/src/Gui/settings/IntWidget.cpp b/src/Gui/settings/IntWidget.cpp
index d76005e..4792ab1 100644
--- a/src/Gui/settings/IntWidget.cpp
+++ b/src/Gui/settings/IntWidget.cpp
@@ -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() );
 }
 
diff --git a/src/Project/ProjectManager.cpp b/src/Project/ProjectManager.cpp
index 1a2a233..e0e9122 100644
--- a/src/Project/ProjectManager.cpp
+++ b/src/Project/ProjectManager.cpp
@@ -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" ) );
diff --git a/src/Settings/SettingValue.cpp b/src/Settings/SettingValue.cpp
index 86fd8cb..39b4d8f 100644
--- a/src/Settings/SettingValue.cpp
+++ b/src/Settings/SettingValue.cpp
@@ -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;
+}
diff --git a/src/Settings/SettingValue.h b/src/Settings/SettingValue.h
index b00c9f7..8170504 100644
--- a/src/Settings/SettingValue.h
+++ b/src/Settings/SettingValue.h
@@ -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
diff --git a/src/Settings/SettingsManager.cpp b/src/Settings/SettingsManager.cpp
index b232138..5eddd18 100644
--- a/src/Settings/SettingsManager.cpp
+++ b/src/Settings/SettingsManager.cpp
@@ -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 ) :
diff --git a/src/Settings/SettingsManager.h b/src/Settings/SettingsManager.h
index f786d04..b15f36f 100644
--- a/src/Settings/SettingsManager.h
+++ b/src/Settings/SettingsManager.h
@@ -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,



More information about the Vlmc-devel mailing list