Changeset View
Changeset View
Standalone View
Standalone View
plugins/generators/simplexnoise/kis_wdg_simplex_noise.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * KDE. Krita Project. | ||||
3 | * | ||||
4 | * Copyright (c) 2019 Eoin O'Neill <eoinoneill1991@gmail.com> | ||||
5 | * Copyright (c) 2019 Emmet O'Neill <emmetoneill.pdx@gmail.com> | ||||
6 | * | ||||
7 | * This program is free software; you can redistribute it and/or modify | ||||
8 | * it under the terms of the GNU General Public License as published by | ||||
9 | * the Free Software Foundation; either version 2 of the License, or | ||||
10 | * (at your option) any later version. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program; if not, write to the Free Software | ||||
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
20 | */ | ||||
21 | | ||||
22 | #include "kis_wdg_simplex_noise.h" | ||||
23 | #include "ui_wdgsimplexnoiseoptions.h" | ||||
24 | | ||||
25 | #include <QLayout> | ||||
26 | #include <filter/kis_filter_configuration.h> | ||||
27 | | ||||
28 | KisWdgSimplexNoise::KisWdgSimplexNoise(KisFilter* /*nfilter*/, QWidget* parent) | ||||
29 | : KisConfigWidget(parent), | ||||
30 | updateCompressor(250, KisSignalCompressor::Mode::POSTPONE) | ||||
31 | { | ||||
32 | m_widget = new Ui_WdgSimplexNoiseOptions(); | ||||
33 | m_widget->setupUi(this); | ||||
34 | connect(m_widget->slider_frequency, SIGNAL(valueChanged(qreal)), &updateCompressor, SLOT(start())); | ||||
35 | connect(m_widget->cb_looping, SIGNAL(stateChanged(int)), &updateCompressor, SLOT(start())); | ||||
36 | connect(m_widget->seed_text, SIGNAL(textChanged(QString)), &updateCompressor, SLOT(start())); | ||||
37 | connect(m_widget->ratiox_slider, SIGNAL(valueChanged(qreal)), &updateCompressor, SLOT(start())); | ||||
38 | connect(m_widget->ratioy_slider, SIGNAL(valueChanged(qreal)), &updateCompressor, SLOT(start())); | ||||
39 | connect(&updateCompressor, SIGNAL(timeout()), this, SIGNAL(sigConfigurationItemChanged())); | ||||
40 | m_widget->slider_frequency->setRange(1.0f, 500.0f, 2); | ||||
41 | m_widget->slider_frequency->setValue(25.0f); | ||||
42 | m_widget->slider_frequency->setExponentRatio(3.0); | ||||
43 | m_widget->ratiox_slider->setRange(0.0f, 2.0f, 2); | ||||
44 | m_widget->ratiox_slider->setValue(1.0f); | ||||
45 | m_widget->ratioy_slider->setRange(0.0f, 2.0f, 2); | ||||
46 | m_widget->ratioy_slider->setValue(1.0f); | ||||
47 | } | ||||
48 | | ||||
49 | KisWdgSimplexNoise::~KisWdgSimplexNoise() | ||||
50 | { | ||||
51 | delete m_widget; | ||||
52 | } | ||||
53 | | ||||
54 | void KisWdgSimplexNoise::setConfiguration(const KisPropertiesConfigurationSP config) | ||||
55 | { | ||||
56 | QVariant value; | ||||
57 | if( config->getProperty("looping", value)) { | ||||
58 | Qt::CheckState state = value.toBool() ? Qt::CheckState::Checked : Qt::CheckState::Unchecked; | ||||
59 | widget()->cb_looping->setCheckState(state); | ||||
60 | } | ||||
61 | if( config->getProperty("frequency", value)) { | ||||
62 | widget()->slider_frequency->setValue(value.toDouble()); | ||||
63 | } | ||||
64 | if( config->getProperty("custom_seed_string", value)) { | ||||
65 | m_widget->seed_text->setText(value.toString()); | ||||
66 | } | ||||
67 | if( config->getProperty("ratio_x", value)) { | ||||
68 | m_widget->ratiox_slider->setValue(value.toDouble()); | ||||
69 | } | ||||
70 | if( config->getProperty("ratio_y", value)) { | ||||
71 | m_widget->ratioy_slider->setValue(value.toDouble()); | ||||
72 | } | ||||
73 | if( config->getProperty("seed", value)) { | ||||
74 | this->seed = value.toUInt(); | ||||
75 | } | ||||
76 | } | ||||
77 | | ||||
78 | KisPropertiesConfigurationSP KisWdgSimplexNoise::configuration() const | ||||
79 | { | ||||
80 | KisFilterConfigurationSP config = new KisFilterConfiguration("simplex_noise", 1); | ||||
81 | config->setProperty("looping", m_widget->cb_looping->isChecked()); | ||||
82 | config->setProperty("frequency", m_widget->slider_frequency->value()); | ||||
83 | config->setProperty("ratio_x", m_widget->ratiox_slider->value()); | ||||
84 | config->setProperty("ratio_y", m_widget->ratioy_slider->value()); | ||||
85 | config->setProperty("custom_seed_string", m_widget->seed_text->text()); | ||||
86 | config->setProperty("seed", this->seed); | ||||
87 | return config; | ||||
88 | } | ||||
89 | | ||||
90 | |