EffectInstanceWidget.cpp 3.14 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*****************************************************************************
 * EffectInstanceWidget.h: Display the settings for an EffectInstance
 *****************************************************************************
 * 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 "EffectInstanceWidget.h"

#include "BoolWidget.h"
26
#include "ColorWidget.h"
27
#include "DoubleSliderWidget.h"
28 29 30 31 32
#include "Effect.h"
#include "EffectInstance.h"
#include "EffectSettingValue.h"

#include <QFormLayout>
33
#include <QGroupBox>
34
#include <QLabel>
35
#include <QVBoxLayout>
36

37 38
#include <QtDebug>

39
EffectInstanceWidget::EffectInstanceWidget( QWidget *parent ) :
40
    QWidget( parent ),
41
    m_ui( new Ui::EffectSettingWidget )
42
{
43
    m_ui->setupUi( this );
44
    clear();
45 46
    connect( m_ui->applyButton, SIGNAL( clicked() ),
             this, SLOT( save() ) );
47 48 49 50 51
}

void
EffectInstanceWidget::setEffectInstance( EffectInstance *instance )
{
52
    clear();
53
    m_effect = instance;
54 55
    m_ui->effectWidget->setEffect( instance->effect() );

56 57
    EffectInstance::ParamList::iterator         it = instance->params().begin();
    EffectInstance::ParamList::iterator         ite = instance->params().end();
58 59 60 61 62
    while ( it != ite )
    {
        EffectSettingValue          *s = it.value();
        ISettingsCategoryWidget     *widget = widgetFactory( s );
        QLabel                      *label = new QLabel( tr( s->name() ), this );
63 64
        m_widgets.push_back( label );
        m_widgets.push_back( widget->widget() );
65
        widget->widget()->setToolTip( s->description() );
66 67
        m_ui->settingsLayout->addRow( label , widget->widget() );
        m_settings.push_back( widget );
68 69 70 71
        ++it;
    }
}

72 73 74
void
EffectInstanceWidget::clear()
{
75
    m_ui->effectWidget->clear();
76 77 78 79 80 81
    qDeleteAll( m_settings );
    m_settings.clear();
    qDeleteAll( m_widgets );
    m_widgets.clear();
}

82 83 84 85 86 87 88 89
ISettingsCategoryWidget*
EffectInstanceWidget::widgetFactory( EffectSettingValue *s )
{
    switch ( s->type() )
    {
    case    SettingValue::Bool:
        return new BoolWidget( s, this );
    case    SettingValue::Double:
90
        return new DoubleSliderWidget( s, this );
91 92
    case    SettingValue::Color:
        return new ColorWidget( s, this );
93 94 95 96
    default:
        return NULL;
    }
}
97 98 99 100 101 102 103

void
EffectInstanceWidget::save()
{
    foreach ( ISettingsCategoryWidget* val, m_settings )
        val->save();
}