File indexing completed on 2024-12-22 04:15:36
0001 /* 0002 * KDE. Krita Project. 0003 * 0004 * SPDX-FileCopyrightText: 2019 Eoin O 'Neill <eoinoneill1991@gmail.com> 0005 * SPDX-FileCopyrightText: 2019 Emmet O 'Neill <emmetoneill.pdx@gmail.com> 0006 * 0007 * SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #include "kis_wdg_simplex_noise.h" 0011 #include "ui_wdgsimplexnoiseoptions.h" 0012 0013 #include <QLayout> 0014 #include <filter/kis_filter_configuration.h> 0015 #include <KisGlobalResourcesInterface.h> 0016 0017 KisWdgSimplexNoise::KisWdgSimplexNoise(KisFilter* /*nfilter*/, QWidget* parent) 0018 : KisConfigWidget(parent), 0019 updateCompressor(250, KisSignalCompressor::Mode::POSTPONE) 0020 { 0021 m_widget = new Ui_WdgSimplexNoiseOptions(); 0022 m_widget->setupUi(this); 0023 connect(m_widget->slider_frequency, SIGNAL(valueChanged(qreal)), &updateCompressor, SLOT(start())); 0024 connect(m_widget->cb_looping, SIGNAL(stateChanged(int)), &updateCompressor, SLOT(start())); 0025 connect(m_widget->seed_text, SIGNAL(textChanged(QString)), &updateCompressor, SLOT(start())); 0026 connect(m_widget->ratiox_slider, SIGNAL(valueChanged(qreal)), &updateCompressor, SLOT(start())); 0027 connect(m_widget->ratioy_slider, SIGNAL(valueChanged(qreal)), &updateCompressor, SLOT(start())); 0028 connect(&updateCompressor, SIGNAL(timeout()), this, SIGNAL(sigConfigurationItemChanged())); 0029 m_widget->slider_frequency->setRange(1.0f, 500.0f, 2); 0030 m_widget->slider_frequency->setValue(25.0f); 0031 m_widget->slider_frequency->setExponentRatio(3.0); 0032 m_widget->ratiox_slider->setRange(0.0f, 2.0f, 2); 0033 m_widget->ratiox_slider->setValue(1.0f); 0034 m_widget->ratioy_slider->setRange(0.0f, 2.0f, 2); 0035 m_widget->ratioy_slider->setValue(1.0f); 0036 } 0037 0038 KisWdgSimplexNoise::~KisWdgSimplexNoise() 0039 { 0040 delete m_widget; 0041 } 0042 0043 void KisWdgSimplexNoise::setConfiguration(const KisPropertiesConfigurationSP config) 0044 { 0045 QVariant value; 0046 if( config->getProperty("looping", value)) { 0047 Qt::CheckState state = value.toBool() ? Qt::CheckState::Checked : Qt::CheckState::Unchecked; 0048 widget()->cb_looping->setCheckState(state); 0049 } 0050 if( config->getProperty("frequency", value)) { 0051 widget()->slider_frequency->setValue(value.toDouble()); 0052 } 0053 if( config->getProperty("custom_seed_string", value)) { 0054 m_widget->seed_text->setText(value.toString()); 0055 } 0056 if( config->getProperty("ratio_x", value)) { 0057 m_widget->ratiox_slider->setValue(value.toDouble()); 0058 } 0059 if( config->getProperty("ratio_y", value)) { 0060 m_widget->ratioy_slider->setValue(value.toDouble()); 0061 } 0062 if( config->getProperty("seed", value)) { 0063 this->seed = value.toUInt(); 0064 } 0065 } 0066 0067 KisPropertiesConfigurationSP KisWdgSimplexNoise::configuration() const 0068 { 0069 KisFilterConfigurationSP config = new KisFilterConfiguration("simplex_noise", 1, KisGlobalResourcesInterface::instance()); 0070 config->setProperty("looping", m_widget->cb_looping->isChecked()); 0071 config->setProperty("frequency", m_widget->slider_frequency->value()); 0072 config->setProperty("ratio_x", m_widget->ratiox_slider->value()); 0073 config->setProperty("ratio_y", m_widget->ratioy_slider->value()); 0074 config->setProperty("custom_seed_string", m_widget->seed_text->text()); 0075 config->setProperty("seed", this->seed); 0076 return config; 0077 } 0078 0079