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

0001 /*
0002  *  SPDX-FileCopyrightText: 2008, 2009 Lukáš Tvrdý <lukast.dev@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 #include <kis_curve_paintop_settings.h>
0007 #include <KisPaintingModeOptionData.h>
0008 #include "KisCurveOpOptionData.h"
0009 
0010 struct KisCurvePaintOpSettings::Private
0011 {
0012     QList<KisUniformPaintOpPropertyWSP> uniformProperties;
0013 };
0014 
0015 KisCurvePaintOpSettings::KisCurvePaintOpSettings(KisResourcesInterfaceSP resourcesInterface)
0016     : KisPaintOpSettings(resourcesInterface),
0017       m_d(new Private)
0018 {
0019 }
0020 
0021 KisCurvePaintOpSettings::~KisCurvePaintOpSettings()
0022 {
0023 }
0024 
0025 void KisCurvePaintOpSettings::setPaintOpSize(qreal value)
0026 {
0027     KisCurveOpOptionData option;
0028     option.read(this);
0029     option.curve_line_width = value;
0030     option.write(this);
0031 }
0032 
0033 qreal KisCurvePaintOpSettings::paintOpSize() const
0034 {
0035     KisCurveOpOptionData option;
0036     option.read(this);
0037     return option.curve_line_width;
0038 }
0039 
0040 void KisCurvePaintOpSettings::setPaintOpAngle(qreal value)
0041 {
0042     Q_UNUSED(value);
0043 }
0044 
0045 qreal KisCurvePaintOpSettings::paintOpAngle() const
0046 {
0047     return 0.0;
0048 }
0049 
0050 bool KisCurvePaintOpSettings::paintIncremental()
0051 {
0052     KisPaintingModeOptionData data;
0053     data.read(this);
0054     return data.paintingMode == enumPaintingMode::BUILDUP;
0055 }
0056 
0057 
0058 #include <brushengine/kis_slider_based_paintop_property.h>
0059 #include "kis_paintop_preset.h"
0060 #include "KisPaintOpPresetUpdateProxy.h"
0061 #include "kis_standard_uniform_properties_factory.h"
0062 
0063 
0064 QList<KisUniformPaintOpPropertySP> KisCurvePaintOpSettings::uniformProperties(KisPaintOpSettingsSP settings, QPointer<KisPaintOpPresetUpdateProxy> updateProxy)
0065 {
0066     QList<KisUniformPaintOpPropertySP> props =
0067         listWeakToStrong(m_d->uniformProperties);
0068 
0069     if (props.isEmpty()) {
0070         {
0071             KisIntSliderBasedPaintOpPropertyCallback *prop = new KisIntSliderBasedPaintOpPropertyCallback(KisIntSliderBasedPaintOpPropertyCallback::Int,
0072                                                                                                           KoID("curve_linewidth", i18n("Line Width")),
0073                                                                                                           settings,
0074                                                                                                           0);
0075 
0076             prop->setRange(1, 100);
0077             prop->setSingleStep(1);
0078             prop->setSuffix(i18n(" px"));
0079 
0080             prop->setReadCallback(
0081                 [](KisUniformPaintOpProperty *prop) {
0082                     KisCurveOpOptionData option;
0083                     option.read(prop->settings().data());
0084 
0085                     prop->setValue(option.curve_line_width);
0086                 });
0087             prop->setWriteCallback(
0088                 [](KisUniformPaintOpProperty *prop) {
0089                     KisCurveOpOptionData option;
0090                     option.read(prop->settings().data());
0091                     option.curve_line_width = prop->value().toInt();
0092                     option.write(prop->settings().data());
0093                 });
0094 
0095             QObject::connect(updateProxy, SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue()));
0096             prop->requestReadValue();
0097             props << toQShared(prop);
0098         }
0099         {
0100             KisIntSliderBasedPaintOpPropertyCallback *prop = new KisIntSliderBasedPaintOpPropertyCallback(KisIntSliderBasedPaintOpPropertyCallback::Int,
0101                                                                                                           KoID("curve_historysize", i18n("History Size")),
0102                                                                                                           settings,
0103                                                                                                           0);
0104 
0105             prop->setRange(2, 300);
0106             prop->setSingleStep(1);
0107 
0108             prop->setReadCallback(
0109                 [](KisUniformPaintOpProperty *prop) {
0110                     KisCurveOpOptionData option;
0111                     option.read(prop->settings().data());
0112 
0113                     prop->setValue(option.curve_stroke_history_size);
0114                 });
0115             prop->setWriteCallback(
0116                 [](KisUniformPaintOpProperty *prop) {
0117                     KisCurveOpOptionData option;
0118                     option.read(prop->settings().data());
0119                     option.curve_stroke_history_size = prop->value().toInt();
0120                     option.write(prop->settings().data());
0121                 });
0122             QObject::connect(updateProxy, SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue()));
0123             prop->requestReadValue();
0124             props << toQShared(prop);
0125         }
0126 
0127         {
0128             KisDoubleSliderBasedPaintOpPropertyCallback *prop =
0129                 new KisDoubleSliderBasedPaintOpPropertyCallback(KisDoubleSliderBasedPaintOpPropertyCallback::Double,
0130                                                                 KoID("curve_lineopacity", i18n("Line Opacity")),
0131                                                                 settings,
0132                                                                 0);
0133 
0134             prop->setRange(0, 100.0);
0135             prop->setSingleStep(0.01);
0136             prop->setDecimals(2);
0137             prop->setSuffix(i18n("%"));
0138 
0139             prop->setReadCallback(
0140                 [](KisUniformPaintOpProperty *prop) {
0141                     KisCurveOpOptionData option;
0142                     option.read(prop->settings().data());
0143                     prop->setValue(option.curve_curves_opacity * 100.0);
0144                 });
0145             prop->setWriteCallback(
0146                 [](KisUniformPaintOpProperty *prop) {
0147                     KisCurveOpOptionData option;
0148                     option.read(prop->settings().data());
0149                     option.curve_curves_opacity = prop->value().toReal() / 100.0;
0150                     option.write(prop->settings().data());
0151                 });
0152 
0153             QObject::connect(updateProxy, SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue()));
0154             prop->requestReadValue();
0155             props << toQShared(prop);
0156         }
0157 
0158         {
0159             KisUniformPaintOpPropertyCallback *prop = new KisUniformPaintOpPropertyCallback(KisUniformPaintOpPropertyCallback::Bool,
0160                                                                                             KoID("curve_connectionline", i18n("Connection Line")),
0161                                                                                             settings,
0162                                                                                             0);
0163 
0164             prop->setReadCallback(
0165                 [](KisUniformPaintOpProperty *prop) {
0166                     KisCurveOpOptionData option;
0167                     option.read(prop->settings().data());
0168 
0169                     prop->setValue(option.curve_paint_connection_line);
0170                 });
0171             prop->setWriteCallback(
0172                 [](KisUniformPaintOpProperty *prop) {
0173                     KisCurveOpOptionData option;
0174                     option.read(prop->settings().data());
0175                     option.curve_paint_connection_line = prop->value().toBool();
0176                     option.write(prop->settings().data());
0177                 });
0178 
0179             QObject::connect(updateProxy, SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue()));
0180             prop->requestReadValue();
0181             props << toQShared(prop);
0182         }
0183     }
0184 
0185     {
0186         using namespace KisStandardUniformPropertiesFactory;
0187 
0188         Q_FOREACH (KisUniformPaintOpPropertySP prop, KisPaintOpSettings::uniformProperties(settings, updateProxy)) {
0189             if (prop->id() == opacity.id()) {
0190                 props.prepend(prop);
0191             }
0192         }
0193     }
0194 
0195     return props;
0196 }