chalk

kis_multi_integer_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_integer_filter_widget.h"
20
21#include <tqlabel.h>
22#include <tqlayout.h>
23#include <tqtimer.h>
24
25#include <knuminput.h>
26#include <tdelocale.h>
27
28KisDelayedActionIntegerInput::KisDelayedActionIntegerInput(TQWidget * parent, const char * name)
29 : KIntNumInput(parent, name)
30{
31 m_timer = new TQTimer(this, name);
32 connect(m_timer, TQ_SIGNAL(timeout()), TQ_SLOT(slotValueChanged()));
33 connect(this, TQ_SIGNAL(valueChanged( int )), TQ_SLOT(slotTimeToUpdate()));
34}
35
36void KisDelayedActionIntegerInput::slotTimeToUpdate()
37{
38 m_timer->start(50, true);
39}
40
41void KisDelayedActionIntegerInput::slotValueChanged()
42{
43 emit valueChangedDelayed( value() );
44}
45
46void KisDelayedActionIntegerInput::cancelDelayedSignal()
47{
48 m_timer->stop();
49}
50
51KisIntegerWidgetParam::KisIntegerWidgetParam( TQ_INT32 nmin, TQ_INT32 nmax, TQ_INT32 ninitvalue, TQString label, TQString nname) :
52 min(nmin),
53 max(nmax),
54 initvalue(ninitvalue),
55 label(label),
56 name(nname)
57{
58}
59
60KisMultiIntegerFilterWidget::KisMultiIntegerFilterWidget(TQWidget * parent,
61 const char * name,
62 const char * caption,
63 vKisIntegerWidgetParam iwparam)
64 : KisFilterConfigWidget( parent, name )
65{
66 m_nbintegerWidgets = iwparam.size();
67 this->setCaption(caption);
68
69 TQGridLayout *widgetLayout = new TQGridLayout(this, m_nbintegerWidgets + 1, 3);
70 widgetLayout->setColStretch ( 1, 1 );
71
72 m_integerWidgets = new KisDelayedActionIntegerInput*[ m_nbintegerWidgets ];
73
74 for( TQ_INT32 i = 0; i < m_nbintegerWidgets; ++i)
75 {
76 m_integerWidgets[i] = new KisDelayedActionIntegerInput( this, iwparam[i].name.ascii());
77 m_integerWidgets[i]->setRange( iwparam[i].min, iwparam[i].max);
78 m_integerWidgets[i]->setValue( iwparam[i].initvalue );
79 m_integerWidgets[i]->cancelDelayedSignal();
80
81 connect(m_integerWidgets[i], TQ_SIGNAL(valueChangedDelayed( int )), TQ_SIGNAL(sigPleaseUpdatePreview()));
82
83 TQLabel* lbl = new TQLabel(iwparam[i].label+":", this);
84 widgetLayout->addWidget( lbl, i , 0);
85
86 widgetLayout->addWidget( m_integerWidgets[i], i , 1);
87 }
88 TQSpacerItem * sp = new TQSpacerItem(1, 1);
89 widgetLayout->addItem(sp, m_nbintegerWidgets, 0);
90}
91
92void KisMultiIntegerFilterWidget::setConfiguration( KisFilterConfiguration * config )
93{
94 for (int i = 0; i < nbValues(); ++i) {
95 KisDelayedActionIntegerInput * w = m_integerWidgets[i];
96 if (w) {
97 int val = config->getInt(m_integerWidgets[i]->name());
98 m_integerWidgets[i]->setValue(val);
99 m_integerWidgets[i]->cancelDelayedSignal();
100 }
101 }
102}
103
104#include "kis_multi_integer_filter_widget.moc"
A KisFilterConfiguration is the serializable representation of the filter parameters.