chalk

kis_multi_double_filter_widget.cpp
1/*
2 * Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#include "kis_multi_double_filter_widget.h"
20
21#include <tqlabel.h>
22#include <tqlayout.h>
23#include <tqtimer.h>
24
25#include <knuminput.h>
26#include <kis_filter_config_widget.h>
27#include <tdelocale.h>
28
29KisDelayedActionDoubleInput::KisDelayedActionDoubleInput(TQWidget * parent, const char * name)
30 : KDoubleNumInput(parent, name)
31{
32 m_timer = new TQTimer(this, name);
33 connect(m_timer, TQ_SIGNAL(timeout()), TQ_SLOT(slotValueChanged()));
34 connect(this, TQ_SIGNAL(valueChanged( double )), TQ_SLOT(slotTimeToUpdate()));
35}
36
37void KisDelayedActionDoubleInput::slotTimeToUpdate()
38{
39 m_timer->start(50, true);
40}
41
42void KisDelayedActionDoubleInput::slotValueChanged()
43{
44 emit valueChangedDelayed( value() );
45}
46
47void KisDelayedActionDoubleInput::cancelDelayedSignal()
48{
49 m_timer->stop();
50}
51
52KisDoubleWidgetParam::KisDoubleWidgetParam(double nmin, double nmax, double ninitvalue, TQString nlabel, TQString nname) :
53 min(nmin),
54 max(nmax),
55 initvalue(ninitvalue),
56 label(nlabel),
57 name(nname)
58{
59
60}
61
62KisMultiDoubleFilterWidget::KisMultiDoubleFilterWidget(TQWidget * parent, const char * name, const char * caption, vKisDoubleWidgetParam dwparam)
63 : KisFilterConfigWidget( parent, name )
64{
65 TQ_INT32 m_nbdoubleWidgets = dwparam.size();
66
67 this->setCaption(caption);
68
69 TQGridLayout *widgetLayout = new TQGridLayout(this, m_nbdoubleWidgets + 1, 3);
70 widgetLayout->setColStretch ( 1, 1 );
71
72 m_doubleWidgets = new KisDelayedActionDoubleInput*[ m_nbdoubleWidgets ];
73
74 for( TQ_INT32 i = 0; i < m_nbdoubleWidgets; ++i)
75 {
76 m_doubleWidgets[i] = new KisDelayedActionDoubleInput(this, dwparam[i].name.ascii());
77 m_doubleWidgets[i]->setRange( dwparam[i].min, dwparam[i].max );
78 m_doubleWidgets[i]->setValue( dwparam[i].initvalue );
79 m_doubleWidgets[i]->cancelDelayedSignal();
80
81 connect(m_doubleWidgets[i], TQ_SIGNAL(valueChangedDelayed(double)), TQ_SIGNAL(sigPleaseUpdatePreview()));
82
83 TQLabel* lbl = new TQLabel(dwparam[i].label+":", this);
84 widgetLayout->addWidget( lbl, i , 0);
85
86 widgetLayout->addWidget( m_doubleWidgets[i], i , 1);
87 }
88 TQSpacerItem * sp = new TQSpacerItem(1, 1);
89 widgetLayout->addItem(sp, m_nbdoubleWidgets, 0);
90
91}
92
93void KisMultiDoubleFilterWidget::setConfiguration(KisFilterConfiguration * config)
94{
95
96 for (int i = 0; i < m_nbdoubleWidgets ; ++i) {
97 double val = config->getDouble(m_doubleWidgets[i]->name());
98 m_doubleWidgets[i]->setValue(val);
99 m_doubleWidgets[i]->cancelDelayedSignal();
100 }
101}
102
103#include "kis_multi_double_filter_widget.moc"
A KisFilterConfiguration is the serializable representation of the filter parameters.