File indexing completed on 2024-12-22 04:16:21

0001 /*
0002  *  SPDX-FileCopyrightText: 2010 Lukáš Tvrdý <lukast.dev@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 #include "kis_particle_paintop_settings.h"
0007 
0008 #include "kis_particle_paintop_settings_widget.h"
0009 #include "KisParticleOpOptionData.h"
0010 
0011 #include <KisPaintingModeOptionData.h>
0012 
0013 struct KisParticlePaintOpSettings::Private
0014 {
0015     QList<KisUniformPaintOpPropertyWSP> uniformProperties;
0016 };
0017 
0018 KisParticlePaintOpSettings::KisParticlePaintOpSettings(KisResourcesInterfaceSP resourcesInterface)
0019     : KisNoSizePaintOpSettings(resourcesInterface),
0020       m_d(new Private)
0021 {
0022 }
0023 
0024 KisParticlePaintOpSettings::~KisParticlePaintOpSettings()
0025 {
0026 }
0027 
0028 bool KisParticlePaintOpSettings::paintIncremental()
0029 {
0030     KisPaintingModeOptionData data;
0031     data.read(this);
0032     return data.paintingMode == enumPaintingMode::BUILDUP;
0033 }
0034 
0035 
0036 #include <brushengine/kis_slider_based_paintop_property.h>
0037 #include "kis_paintop_preset.h"
0038 #include "KisPaintOpPresetUpdateProxy.h"
0039 #include "kis_standard_uniform_properties_factory.h"
0040 
0041 
0042 QList<KisUniformPaintOpPropertySP> KisParticlePaintOpSettings::uniformProperties(KisPaintOpSettingsSP settings, QPointer<KisPaintOpPresetUpdateProxy> updateProxy)
0043 {
0044     QList<KisUniformPaintOpPropertySP> props =
0045         listWeakToStrong(m_d->uniformProperties);
0046 
0047     if (props.isEmpty()) {
0048         {
0049             KisIntSliderBasedPaintOpPropertyCallback *prop = new KisIntSliderBasedPaintOpPropertyCallback(KisIntSliderBasedPaintOpPropertyCallback::Int,
0050                                                                                                           KoID("particle_particles", i18n("Particles")),
0051                                                                                                           settings,
0052                                                                                                           0);
0053 
0054             prop->setRange(1, 500);
0055             prop->setSingleStep(1);
0056 
0057             prop->setReadCallback(
0058                 [](KisUniformPaintOpProperty *prop) {
0059                     KisParticleOpOptionData option;
0060                     option.read(prop->settings().data());
0061 
0062                     prop->setValue(int(option.particleCount));
0063                 });
0064             prop->setWriteCallback(
0065                 [](KisUniformPaintOpProperty *prop) {
0066                     KisParticleOpOptionData option;
0067                     option.read(prop->settings().data());
0068                     option.particleCount = prop->value().toInt();
0069                     option.write(prop->settings().data());
0070                 });
0071 
0072             QObject::connect(updateProxy, SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue()));
0073             prop->requestReadValue();
0074             props << toQShared(prop);
0075         }
0076         {
0077             KisDoubleSliderBasedPaintOpPropertyCallback *prop =
0078                 new KisDoubleSliderBasedPaintOpPropertyCallback(KisDoubleSliderBasedPaintOpPropertyCallback::Double,
0079                                                                 KoID("particle_opecityweight", i18n("Opacity Weight")),
0080                                                                 settings,
0081                                                                 0);
0082 
0083             prop->setRange(0.01, 1.0);
0084             prop->setSingleStep(0.01);
0085             prop->setDecimals(2);
0086 
0087             prop->setReadCallback(
0088                 [](KisUniformPaintOpProperty *prop) {
0089                     KisParticleOpOptionData option;
0090                     option.read(prop->settings().data());
0091                     prop->setValue(option.particleWeight);
0092                 });
0093             prop->setWriteCallback(
0094                 [](KisUniformPaintOpProperty *prop) {
0095                     KisParticleOpOptionData option;
0096                     option.read(prop->settings().data());
0097                     option.particleWeight = prop->value().toReal();
0098                     option.write(prop->settings().data());
0099                 });
0100 
0101             QObject::connect(updateProxy, SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue()));
0102             prop->requestReadValue();
0103             props << toQShared(prop);
0104         }
0105         {
0106             KisDoubleSliderBasedPaintOpPropertyCallback *prop =
0107                 new KisDoubleSliderBasedPaintOpPropertyCallback(KisDoubleSliderBasedPaintOpPropertyCallback::Double,
0108                                                                 KoID("particle_dx_scale", i18n("dx scale")),
0109                                                                 settings,
0110                                                                 0);
0111 
0112             prop->setRange(-2, 2);
0113             prop->setSingleStep(0.01);
0114             prop->setDecimals(2);
0115 
0116             prop->setReadCallback(
0117                 [](KisUniformPaintOpProperty *prop) {
0118                     KisParticleOpOptionData option;
0119                     option.read(prop->settings().data());
0120                     prop->setValue(option.particleScaleX);
0121                 });
0122             prop->setWriteCallback(
0123                 [](KisUniformPaintOpProperty *prop) {
0124                     KisParticleOpOptionData option;
0125                     option.read(prop->settings().data());
0126                     option.particleScaleX = prop->value().toReal();
0127                     option.write(prop->settings().data());
0128                 });
0129 
0130             QObject::connect(updateProxy, SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue()));
0131             prop->requestReadValue();
0132             props << toQShared(prop);
0133         }
0134         {
0135             KisDoubleSliderBasedPaintOpPropertyCallback *prop =
0136                 new KisDoubleSliderBasedPaintOpPropertyCallback(KisDoubleSliderBasedPaintOpPropertyCallback::Double,
0137                                                                 KoID("particle_dy_scale", i18n("dy scale")),
0138                                                                 settings,
0139                                                                 0);
0140 
0141             prop->setRange(-2, 2);
0142             prop->setSingleStep(0.01);
0143             prop->setDecimals(2);
0144 
0145             prop->setReadCallback(
0146                 [](KisUniformPaintOpProperty *prop) {
0147                     KisParticleOpOptionData option;
0148                     option.read(prop->settings().data());
0149                     prop->setValue(option.particleScaleY);
0150                 });
0151             prop->setWriteCallback(
0152                 [](KisUniformPaintOpProperty *prop) {
0153                     KisParticleOpOptionData option;
0154                     option.read(prop->settings().data());
0155                     option.particleScaleY = prop->value().toReal();
0156                     option.write(prop->settings().data());
0157                 });
0158 
0159             QObject::connect(updateProxy, SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue()));
0160             prop->requestReadValue();
0161             props << toQShared(prop);
0162         }
0163         {
0164             KisDoubleSliderBasedPaintOpPropertyCallback *prop =
0165                 new KisDoubleSliderBasedPaintOpPropertyCallback(KisDoubleSliderBasedPaintOpPropertyCallback::Double,
0166                                                                 KoID("particle_gravity", i18n("Gravity")),
0167                                                                 settings,
0168                                                                 0);
0169 
0170             prop->setRange(0.01, 1.0);
0171             prop->setSingleStep(0.01);
0172             prop->setDecimals(2);
0173 
0174             prop->setReadCallback(
0175                 [](KisUniformPaintOpProperty *prop) {
0176                     KisParticleOpOptionData option;
0177                     option.read(prop->settings().data());
0178                     prop->setValue(option.particleGravity);
0179                 });
0180             prop->setWriteCallback(
0181                 [](KisUniformPaintOpProperty *prop) {
0182                     KisParticleOpOptionData option;
0183                     option.read(prop->settings().data());
0184                     option.particleGravity = prop->value().toReal();
0185                     option.write(prop->settings().data());
0186                 });
0187 
0188             QObject::connect(updateProxy, SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue()));
0189             prop->requestReadValue();
0190             props << toQShared(prop);
0191         }
0192         {
0193             KisIntSliderBasedPaintOpPropertyCallback *prop = new KisIntSliderBasedPaintOpPropertyCallback(KisIntSliderBasedPaintOpPropertyCallback::Int,
0194                                                                                                           KoID("particle_iterations", i18n("Iterations")),
0195                                                                                                           settings,
0196                                                                                                           0);
0197 
0198             prop->setRange(1, 300);
0199             prop->setSingleStep(1);
0200 
0201             prop->setReadCallback(
0202                 [](KisUniformPaintOpProperty *prop) {
0203                     KisParticleOpOptionData option;
0204                     option.read(prop->settings().data());
0205 
0206                     prop->setValue(int(option.particleIterations));
0207                 });
0208             prop->setWriteCallback(
0209                 [](KisUniformPaintOpProperty *prop) {
0210                     KisParticleOpOptionData option;
0211                     option.read(prop->settings().data());
0212                     option.particleIterations = prop->value().toInt();
0213                     option.write(prop->settings().data());
0214                 });
0215 
0216             QObject::connect(updateProxy, SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue()));
0217             prop->requestReadValue();
0218             props << toQShared(prop);
0219         }
0220     }
0221 
0222     {
0223         using namespace KisStandardUniformPropertiesFactory;
0224 
0225         Q_FOREACH (KisUniformPaintOpPropertySP prop, KisPaintOpSettings::uniformProperties(settings, updateProxy)) {
0226             if (prop->id() == opacity.id()) {
0227                 props.prepend(prop);
0228             }
0229         }
0230     }
0231 
0232     return props;
0233 }