krita

kis_multi_double_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_double_filter_widget.h"
00020 
00021 #include <qlabel.h>
00022 #include <qlayout.h>
00023 #include <qtimer.h>
00024 
00025 #include <knuminput.h>
00026 #include <kis_filter_config_widget.h>
00027 #include <klocale.h>
00028 
00029 KisDelayedActionDoubleInput::KisDelayedActionDoubleInput(QWidget * parent, const char * name)
00030     : KDoubleNumInput(parent, name)
00031 {
00032     m_timer = new QTimer(this, name);
00033     connect(m_timer, SIGNAL(timeout()), SLOT(slotValueChanged()));
00034     connect(this, SIGNAL(valueChanged( double )), SLOT(slotTimeToUpdate()));
00035 }
00036 
00037 void KisDelayedActionDoubleInput::slotTimeToUpdate()
00038 {
00039     m_timer->start(50, true);
00040 }
00041 
00042 void KisDelayedActionDoubleInput::slotValueChanged()
00043 {
00044     emit valueChangedDelayed( value() );
00045 }
00046 
00047 void KisDelayedActionDoubleInput::cancelDelayedSignal()
00048 {
00049     m_timer->stop();
00050 }
00051 
00052 KisDoubleWidgetParam::KisDoubleWidgetParam(double nmin, double nmax, double ninitvalue, QString nlabel, QString nname) :
00053     min(nmin),
00054     max(nmax),
00055     initvalue(ninitvalue),
00056     label(nlabel),
00057     name(nname)
00058 {
00059 
00060 }
00061 
00062 KisMultiDoubleFilterWidget::KisMultiDoubleFilterWidget(QWidget * parent, const char * name, const char * caption, vKisDoubleWidgetParam dwparam)
00063     : KisFilterConfigWidget( parent, name )
00064 {
00065     Q_INT32 m_nbdoubleWidgets = dwparam.size();
00066 
00067     this->setCaption(caption);
00068 
00069     QGridLayout *widgetLayout = new QGridLayout(this, m_nbdoubleWidgets + 1, 3);
00070     widgetLayout->setColStretch ( 1, 1 );
00071 
00072     m_doubleWidgets = new KisDelayedActionDoubleInput*[ m_nbdoubleWidgets ];
00073 
00074     for( Q_INT32 i = 0; i < m_nbdoubleWidgets; ++i)
00075     {
00076         m_doubleWidgets[i] = new KisDelayedActionDoubleInput(this, dwparam[i].name.ascii());
00077         m_doubleWidgets[i]->setRange( dwparam[i].min, dwparam[i].max );
00078         m_doubleWidgets[i]->setValue( dwparam[i].initvalue );
00079         m_doubleWidgets[i]->cancelDelayedSignal();
00080 
00081         connect(m_doubleWidgets[i], SIGNAL(valueChangedDelayed(double)), SIGNAL(sigPleaseUpdatePreview()));
00082 
00083         QLabel* lbl = new QLabel(dwparam[i].label+":", this);
00084         widgetLayout->addWidget( lbl, i , 0);
00085 
00086         widgetLayout->addWidget( m_doubleWidgets[i], i , 1);
00087     }
00088     QSpacerItem * sp = new QSpacerItem(1, 1);
00089     widgetLayout->addItem(sp, m_nbdoubleWidgets, 0);
00090 
00091 }
00092 
00093 void KisMultiDoubleFilterWidget::setConfiguration(KisFilterConfiguration * config)
00094 {
00095     
00096     for (int i = 0; i < m_nbdoubleWidgets ; ++i) {
00097         double val = config->getDouble(m_doubleWidgets[i]->name());
00098         m_doubleWidgets[i]->setValue(val);
00099         m_doubleWidgets[i]->cancelDelayedSignal();
00100     }
00101 }
00102 
00103 #include "kis_multi_double_filter_widget.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys