EffectInstanceWidget.cpp 3.27 KB
Newer Older
1 2 3
/*****************************************************************************
 * EffectInstanceWidget.h: Display the settings for an EffectInstance
 *****************************************************************************
4
 * Copyright (C) 2008-2016 VideoLAN
5
 *
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
6
 * Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * 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.
 *****************************************************************************/

23 24 25 26
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

27 28
#include "EffectInstanceWidget.h"

29
#include "Gui/settings/BoolWidget.h"
luyikei's avatar
luyikei committed
30 31 32
#include "Gui/settings/IntWidget.h"
#include "Gui/settings/StringWidget.h"
#include "Gui/settings/DoubleWidget.h"
33
#include "Gui/settings/DoubleSliderWidget.h"
luyikei's avatar
luyikei committed
34 35
#include "EffectsEngine/EffectHelper.h"
#include "Backend/IFilter.h"
36
#include "Backend/IInfo.h"
luyikei's avatar
luyikei committed
37 38
#include "Main/Core.h"
#include "Tools/VlmcDebug.h"
39 40

#include <QFormLayout>
41
#include <QGroupBox>
42
#include <QLabel>
43
#include <QVBoxLayout>
44

45
EffectInstanceWidget::EffectInstanceWidget( QWidget *parent ) :
46
    QWidget( parent ),
47 48
    m_ui( new Ui::EffectSettingWidget ),
    m_helper( nullptr )
49
{
50
    m_ui->setupUi( this );
51
    clear();
52 53
    connect( m_ui->applyButton, SIGNAL( clicked() ),
             this, SLOT( save() ) );
54 55 56
}

void
57
EffectInstanceWidget::setEffectHelper( std::shared_ptr<EffectHelper> const& helper )
58
{
59
    clear();
60
    m_helper = helper;
61
    m_ui->effectWidget->setEffectHelper( helper );
62

63
    for ( auto param : helper->parameters() )
64
    {
65 66 67
        ISettingsCategoryWidget*    widget = widgetFactory( param );
        QLabel*                     label = new QLabel( param->name(), this );
        widget->setToolTip( param->description() );
68
        m_ui->settingsLayout->addRow( label , widget );
69
        m_settings.push_back( widget );
70 71 72
    }
}

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

83
ISettingsCategoryWidget*
luyikei's avatar
luyikei committed
84
EffectInstanceWidget::widgetFactory( SettingValue *s )
85 86 87 88 89 90
{
    switch ( s->type() )
    {
    case    SettingValue::Bool:
        return new BoolWidget( s, this );
    case    SettingValue::Double:
luyikei's avatar
luyikei committed
91 92 93 94 95 96 97 98
        if ( s->flags().testFlag( SettingValue::Clamped ) == true )
            return new DoubleSliderWidget( s, this );
        else
            return new DoubleWidget( s, this );
    case    SettingValue::Int:
        return new IntWidget( s, this );
    case    SettingValue::String:
        return new StringWidget( s, this );
99
    default:
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
100
        return nullptr;
101 102
    }
}
103 104 105 106

void
EffectInstanceWidget::save()
{
luyikei's avatar
luyikei committed
107
    for ( ISettingsCategoryWidget* val : m_settings )
108 109
        val->save();
}