krita

kis_multi_integer_filter_widget.cc

00001 /*
00002  *  Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #include "kis_multi_integer_filter_widget.h"
00020 
00021 #include <qlabel.h>
00022 #include <qlayout.h>
00023 #include <qtimer.h>
00024 
00025 #include <knuminput.h>
00026 #include <klocale.h>
00027 
00028 KisDelayedActionIntegerInput::KisDelayedActionIntegerInput(QWidget * parent, const char * name)
00029         : KIntNumInput(parent, name)
00030 {
00031         m_timer = new QTimer(this, name);
00032         connect(m_timer, SIGNAL(timeout()), SLOT(slotValueChanged()));
00033         connect(this, SIGNAL(valueChanged( int )), SLOT(slotTimeToUpdate()));
00034 }
00035 
00036 void KisDelayedActionIntegerInput::slotTimeToUpdate()
00037 {
00038     m_timer->start(50, true);
00039 }
00040 
00041 void KisDelayedActionIntegerInput::slotValueChanged()
00042 {
00043     emit valueChangedDelayed( value() );
00044 }
00045 
00046 void KisDelayedActionIntegerInput::cancelDelayedSignal()
00047 {
00048     m_timer->stop();
00049 }
00050 
00051 KisIntegerWidgetParam::KisIntegerWidgetParam(  Q_INT32 nmin, Q_INT32 nmax, Q_INT32 ninitvalue, QString label, QString nname) :
00052     min(nmin),
00053     max(nmax),
00054     initvalue(ninitvalue),
00055     label(label),
00056     name(nname)
00057 {
00058 }
00059 
00060 KisMultiIntegerFilterWidget::KisMultiIntegerFilterWidget(QWidget * parent,
00061                                                          const char * name,
00062                                                          const char * caption,
00063                                                          vKisIntegerWidgetParam iwparam)
00064     : KisFilterConfigWidget( parent, name )
00065 {
00066     m_nbintegerWidgets = iwparam.size();
00067     this->setCaption(caption);
00068 
00069     QGridLayout *widgetLayout = new QGridLayout(this, m_nbintegerWidgets + 1, 3);
00070     widgetLayout->setColStretch ( 1, 1 );
00071 
00072     m_integerWidgets = new KisDelayedActionIntegerInput*[ m_nbintegerWidgets ];
00073 
00074     for( Q_INT32 i = 0; i < m_nbintegerWidgets; ++i)
00075     {
00076         m_integerWidgets[i] = new KisDelayedActionIntegerInput( this, iwparam[i].name.ascii());
00077         m_integerWidgets[i]->setRange( iwparam[i].min, iwparam[i].max);
00078         m_integerWidgets[i]->setValue( iwparam[i].initvalue );
00079         m_integerWidgets[i]->cancelDelayedSignal();
00080 
00081         connect(m_integerWidgets[i], SIGNAL(valueChangedDelayed( int )), SIGNAL(sigPleaseUpdatePreview()));
00082 
00083         QLabel* lbl = new QLabel(iwparam[i].label+":", this);
00084         widgetLayout->addWidget( lbl, i , 0);
00085 
00086         widgetLayout->addWidget( m_integerWidgets[i], i , 1);
00087     }
00088     QSpacerItem * sp = new QSpacerItem(1, 1);
00089     widgetLayout->addItem(sp, m_nbintegerWidgets, 0);
00090 }
00091 
00092 void KisMultiIntegerFilterWidget::setConfiguration( KisFilterConfiguration * config )
00093 {
00094     for (int i = 0; i < nbValues(); ++i) {
00095         KisDelayedActionIntegerInput *  w = m_integerWidgets[i];
00096         if (w) {
00097             int val = config->getInt(m_integerWidgets[i]->name());
00098             m_integerWidgets[i]->setValue(val);
00099             m_integerWidgets[i]->cancelDelayedSignal();
00100         }
00101     }
00102 }
00103 
00104 #include "kis_multi_integer_filter_widget.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys