[vlmc-devel] commit: EffectInstanceWidget: Adding a DoubleSliderWidget to handle clamped double values ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Sun Aug 22 22:54:19 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Sat Aug 21 23:10:30 2010 +0200| [92455d707a287c6bdd82462cc586a60562241511] | committer: Hugo Beauzée-Luyssen 

EffectInstanceWidget: Adding a DoubleSliderWidget to handle clamped double values

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

 src/CMakeLists.txt                             |    2 +
 src/EffectsEngine/EffectInstance.cpp           |   19 +++++-
 src/EffectsEngine/EffectInstance.h             |    2 +
 src/Gui/effectsengine/EffectInstanceWidget.cpp |    4 +-
 src/Gui/settings/DoubleSliderWidget.cpp        |   78 ++++++++++++++++++++++++
 src/Gui/settings/DoubleSliderWidget.h          |   53 ++++++++++++++++
 src/Gui/settings/DoubleWidget.cpp              |    3 +-
 src/Gui/settings/DoubleWidget.h                |    2 +-
 8 files changed, 155 insertions(+), 8 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b9c76d3..f4e3d59 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -178,6 +178,7 @@ ELSE(NOT WITH_GUI)
         Gui/project/GuiProjectManager.cpp
         Gui/settings/BoolWidget.cpp
         Gui/settings/DoubleWidget.cpp
+        Gui/settings/DoubleSliderWidget.cpp
         Gui/settings/IntWidget.cpp
         Gui/settings/KeyboardShortcut.cpp
         Gui/settings/KeyboardShortcutInput.cpp
@@ -244,6 +245,7 @@ ELSE(NOT WITH_GUI)
         Gui/project/GuiProjectManager.h
         Gui/settings/BoolWidget.h
         Gui/settings/DoubleWidget.h
+        Gui/settings/DoubleSliderWidget.h
         Gui/settings/ISettingsCategoryWidget.h
         Gui/settings/IntWidget.h
         Gui/settings/KeyboardShortcut.h
diff --git a/src/EffectsEngine/EffectInstance.cpp b/src/EffectsEngine/EffectInstance.cpp
index 0a385e1..630ebe5 100644
--- a/src/EffectsEngine/EffectInstance.cpp
+++ b/src/EffectsEngine/EffectInstance.cpp
@@ -40,9 +40,7 @@ EffectInstance::EffectInstance( Effect *effect ) :
     while ( it != ite )
     {
         f0r_param_info_t    *info = *it;
-        m_params[info->name] = new EffectSettingValue( EffectSettingValue::frei0rToVlmc( info->type ),
-                                                    this, i, QVariant(),
-                                                    info->name, info->explanation );
+        m_params[info->name] = settingValueFactory( info, i );
         ++it;
         ++i;
     }
@@ -53,6 +51,21 @@ EffectInstance::~EffectInstance()
     m_effect->m_f0r_destruct( m_instance );
 }
 
+EffectSettingValue*
+EffectInstance::settingValueFactory( f0r_param_info_t *info, quint32 index )
+{
+    SettingValue::Flag      flags = SettingValue::Nothing;
+
+    if ( info->type == F0R_PARAM_DOUBLE )
+        flags = SettingValue::Clamped;
+    EffectSettingValue  *val = new EffectSettingValue( EffectSettingValue::frei0rToVlmc( info->type ),
+                                                        this, index, QVariant(),
+                                                        info->name, info->explanation );
+    if ( info->type == F0R_PARAM_DOUBLE )
+        val->setLimits( 0.0, 1.0 );
+    return val;
+}
+
 void
 EffectInstance::init( quint32 width, quint32 height )
 {
diff --git a/src/EffectsEngine/EffectInstance.h b/src/EffectsEngine/EffectInstance.h
index c586a9b..7557232 100644
--- a/src/EffectsEngine/EffectInstance.h
+++ b/src/EffectsEngine/EffectInstance.h
@@ -40,6 +40,8 @@ class EffectInstance
     protected:
         EffectInstance( Effect *effect );
         virtual ~EffectInstance();
+        EffectSettingValue*         settingValueFactory( f0r_param_info_t* info, quint32 index );
+    protected:
 
         Effect                      *m_effect;
         quint32                     m_width;
diff --git a/src/Gui/effectsengine/EffectInstanceWidget.cpp b/src/Gui/effectsengine/EffectInstanceWidget.cpp
index 4051b37..42c0a51 100644
--- a/src/Gui/effectsengine/EffectInstanceWidget.cpp
+++ b/src/Gui/effectsengine/EffectInstanceWidget.cpp
@@ -23,7 +23,7 @@
 #include "EffectInstanceWidget.h"
 
 #include "BoolWidget.h"
-#include "DoubleWidget.h"
+#include "DoubleSliderWidget.h"
 #include "Effect.h"
 #include "EffectInstance.h"
 #include "EffectSettingValue.h"
@@ -81,7 +81,7 @@ EffectInstanceWidget::widgetFactory( EffectSettingValue *s )
     case    SettingValue::Bool:
         return new BoolWidget( s, this );
     case    SettingValue::Double:
-        return new DoubleWidget( s, this );
+        return new DoubleSliderWidget( s, this );
     default:
         return NULL;
     }
diff --git a/src/Gui/settings/DoubleSliderWidget.cpp b/src/Gui/settings/DoubleSliderWidget.cpp
new file mode 100644
index 0000000..0608c0e
--- /dev/null
+++ b/src/Gui/settings/DoubleSliderWidget.cpp
@@ -0,0 +1,78 @@
+/*****************************************************************************
+ * DoubleSliderWidget.cpp Handle double settings using a slider for values.
+ *****************************************************************************
+ * Copyright (C) 2008-2010 VideoLAN
+ *
+ * Authors: Hugo Beauzée-Luyssen <beauze.h at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include "DoubleSliderWidget.h"
+
+#include "SettingValue.h"
+
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QSlider>
+
+DoubleSliderWidget::DoubleSliderWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
+        m_setting( s )
+{
+    m_container = new QWidget( parent );
+    //Creating the slider
+    m_slider = new QSlider( m_container );
+    m_slider->setOrientation( Qt::Horizontal );
+    //Creating the label
+    m_valueDisplayer = new QLabel( QString::number( s->get().toDouble() ), m_container );
+    //Avoid label resizing due to roundups
+    const QFontMetrics  &fm = m_valueDisplayer->fontMetrics();
+    m_valueDisplayer->setFixedWidth( fm.width( "0.00" ) );
+    //Setting the layout:
+    QHBoxLayout *layout = new QHBoxLayout( m_container );
+    layout->addWidget( m_slider );
+    layout->addWidget( m_valueDisplayer );
+    //TODO: check if the value is clamped
+    m_slider->setMaximum( s->max().toDouble() * 100.0 );
+    m_slider->setMinimum( s->min().toDouble() * 100.0 );
+    changed ( s->get() );
+    connect( s, SIGNAL( changed( const QVariant& ) ),
+             this, SLOT( changed( const QVariant& ) ) );
+    connect( m_slider, SIGNAL( valueChanged( int ) ), this, SLOT( sliderMoved( int ) ) );
+}
+
+QWidget*
+DoubleSliderWidget::widget()
+{
+    return m_container;
+}
+
+void
+DoubleSliderWidget::save()
+{
+    m_setting->set( m_slider->value() / 100.0 );
+}
+
+void
+DoubleSliderWidget::changed( const QVariant &val )
+{
+    m_slider->setValue( val.toDouble() * 100.0 );
+}
+
+void
+DoubleSliderWidget::sliderMoved( int value )
+{
+    m_valueDisplayer->setText( QString::number( (double)value / 100.0 ) );
+}
diff --git a/src/Gui/settings/DoubleSliderWidget.h b/src/Gui/settings/DoubleSliderWidget.h
new file mode 100644
index 0000000..fbc538a
--- /dev/null
+++ b/src/Gui/settings/DoubleSliderWidget.h
@@ -0,0 +1,53 @@
+/*****************************************************************************
+ * DoubleSliderWidget.h Handle double settings using a slider for values.
+ *****************************************************************************
+ * Copyright (C) 2008-2010 VideoLAN
+ *
+ * Authors: Hugo Beauzée-Luyssen <beauze.h at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef DOUBLESLIDERWIDGET_H
+#define DOUBLESLIDERWIDGET_H
+
+#include "ISettingsCategoryWidget.h"
+
+class   SettingValue;
+
+class   QSlider;
+class   QLabel;
+
+class DoubleSliderWidget : public ISettingsCategoryWidget
+{
+    Q_OBJECT
+
+    public:
+        DoubleSliderWidget( SettingValue *s, QWidget *parent = NULL );
+        QWidget     *widget();
+        void        save();
+
+    private:
+        SettingValue    *m_setting;
+        QSlider         *m_slider;
+        QWidget         *m_container;
+        QLabel          *m_valueDisplayer;
+
+    private slots:
+        virtual void    changed( const QVariant& );
+        void            sliderMoved( int value );
+};
+
+#endif // DOUBLESLIDERWIDGET_H
diff --git a/src/Gui/settings/DoubleWidget.cpp b/src/Gui/settings/DoubleWidget.cpp
index 7570082..719dfe3 100644
--- a/src/Gui/settings/DoubleWidget.cpp
+++ b/src/Gui/settings/DoubleWidget.cpp
@@ -30,8 +30,7 @@ DoubleWidget::DoubleWidget( SettingValue *s, QWidget *parent /*= NULL*/ ) :
 {
     m_spinbox = new QDoubleSpinBox( parent );
     changed( s->get() );
-    connect( s, SIGNAL( changed( const QVariant& ) ),
-             this, SLOT( changed( const QVariant& ) ) );
+
     if ( ( s->flags() & SettingValue::Clamped ) != 0 )
     {
         if ( s->min().isValid() )
diff --git a/src/Gui/settings/DoubleWidget.h b/src/Gui/settings/DoubleWidget.h
index a69be78..c4d12f7 100644
--- a/src/Gui/settings/DoubleWidget.h
+++ b/src/Gui/settings/DoubleWidget.h
@@ -36,7 +36,7 @@ class   DoubleWidget : public ISettingsCategoryWidget
 
     public:
         DoubleWidget( SettingValue *s, QWidget *parent = NULL );
-        QWidget*                widget();
+        QWidget                 *widget();
         void                    save();
 
     private slots:



More information about the Vlmc-devel mailing list