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

EffectInstanceWidget: Adding a DoubleSliderWidget to handle clamped double values

parent ff4c6418
......@@ -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
......
......@@ -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 )
{
......
......@@ -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;
......
......@@ -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;
}
......
/*****************************************************************************
* DoubleSliderWidget.cpp Handle double settings using a slider for values.
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <beauze.h@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 ) );
}
/*****************************************************************************
* DoubleSliderWidget.h Handle double settings using a slider for values.
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <beauze.h@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
......@@ -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() )
......
......@@ -36,7 +36,7 @@ class DoubleWidget : public ISettingsCategoryWidget
public:
DoubleWidget( SettingValue *s, QWidget *parent = NULL );
QWidget* widget();
QWidget *widget();
void save();
private slots:
......
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