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

0001 /*
0002  *  SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "kis_roundmarkerop_settings.h"
0008 #include "KisRoundMarkerOpOptionData.h"
0009 #include <KisOptimizedBrushOutline.h>
0010 #include <QPointer>
0011 
0012 
0013 struct KisRoundMarkerOpSettings::Private
0014 {
0015     QList<KisUniformPaintOpPropertyWSP> uniformProperties;
0016 };
0017 
0018 KisRoundMarkerOpSettings::KisRoundMarkerOpSettings(KisResourcesInterfaceSP resourcesInterface)
0019     : KisOutlineGenerationPolicy<KisPaintOpSettings>(KisCurrentOutlineFetcher::SIZE_OPTION |
0020                                                      KisCurrentOutlineFetcher::ROTATION_OPTION |
0021                                                      KisCurrentOutlineFetcher::MIRROR_OPTION,
0022                                                      resourcesInterface),
0023     m_d(new Private)
0024 {
0025 }
0026 
0027 KisRoundMarkerOpSettings::~KisRoundMarkerOpSettings()
0028 {
0029 }
0030 
0031 bool KisRoundMarkerOpSettings::paintIncremental() {
0032     return false;
0033 }
0034 
0035 void KisRoundMarkerOpSettings::setPaintOpSize(qreal value)
0036 {
0037     KisRoundMarkerOpOptionData option;
0038     option.read(this);
0039     option.diameter = value;
0040     option.write(this);
0041 }
0042 
0043 qreal KisRoundMarkerOpSettings::paintOpSize() const
0044 {
0045     KisRoundMarkerOpOptionData option;
0046     option.read(this);
0047     return option.diameter;
0048 }
0049 
0050 void KisRoundMarkerOpSettings::setPaintOpAngle(qreal value)
0051 {
0052     Q_UNUSED(value);
0053 }
0054 
0055 qreal KisRoundMarkerOpSettings::paintOpAngle() const
0056 {
0057     return 0.0;
0058 }
0059 
0060 KisOptimizedBrushOutline KisRoundMarkerOpSettings::brushOutline(const KisPaintInformation &info, const OutlineMode &mode, qreal alignForZoom)
0061 {
0062     KisOptimizedBrushOutline path;
0063 
0064     if (mode.isVisible) {
0065         qreal finalScale = 1.0;
0066 
0067         KisRoundMarkerOpOptionData option;
0068         option.read(this);
0069         // Adding 1 for the antialiasing/fade.
0070         const qreal radius = (0.5 * option.diameter) + 1;
0071 
0072         QPainterPath realOutline;
0073         realOutline.addEllipse(QPointF(), radius, radius);
0074 
0075         path = outlineFetcher()->fetchOutline(info, this, realOutline, mode, alignForZoom, finalScale);
0076 
0077         if (mode.showTiltDecoration) {
0078             QPainterPath tiltLine = makeTiltIndicator(info,
0079                 realOutline.boundingRect().center(),
0080                 realOutline.boundingRect().width() * 0.5,
0081                 3.0);
0082             path.addPath(outlineFetcher()->fetchOutline(info, this, tiltLine, mode, alignForZoom, finalScale, 0.0, true, realOutline.boundingRect().center().x(), realOutline.boundingRect().center().y()));
0083         }
0084     }
0085 
0086     return path;
0087 }
0088 
0089 #include "kis_standard_uniform_properties_factory.h"
0090 #include <brushengine/kis_slider_based_paintop_property.h>
0091 #include "KisPaintOpPresetUpdateProxy.h"
0092 
0093 QList<KisUniformPaintOpPropertySP> KisRoundMarkerOpSettings::uniformProperties(KisPaintOpSettingsSP settings, QPointer<KisPaintOpPresetUpdateProxy> updateProxy)
0094 {
0095     QList<KisUniformPaintOpPropertySP> props =
0096         listWeakToStrong(m_d->uniformProperties);
0097 
0098     if (props.isEmpty()) {
0099         {
0100             KisUniformPaintOpPropertyCallback *prop =
0101                 new KisUniformPaintOpPropertyCallback(KisUniformPaintOpPropertyCallback::Bool, KoID("auto_spacing", i18n("Auto Spacing")), settings, 0);
0102 
0103             prop->setReadCallback(
0104                 [](KisUniformPaintOpProperty *prop) {
0105                     KisRoundMarkerOpOptionData data;
0106                     data.read(prop->settings().data());
0107 
0108                     prop->setValue(data.useAutoSpacing);
0109                 });
0110             prop->setWriteCallback(
0111                 [](KisUniformPaintOpProperty *prop) {
0112                     KisRoundMarkerOpOptionData data;
0113                     data.read(prop->settings().data());
0114                     data.useAutoSpacing = prop->value().toBool();
0115                     data.write(prop->settings().data());
0116                 });
0117 
0118             QObject::connect(updateProxy, SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue()));
0119             prop->requestReadValue();
0120             props << toQShared(prop);
0121         }
0122 
0123         {
0124             KisDoubleSliderBasedPaintOpPropertyCallback *prop =
0125                 new KisDoubleSliderBasedPaintOpPropertyCallback(KisDoubleSliderBasedPaintOpPropertyCallback::Double,
0126                                                                 KoID("spacing", i18n("Spacing")),
0127                                                                 settings,
0128                                                                 0);
0129 
0130             prop->setRange(0.01, 10);
0131             prop->setSingleStep(0.01);
0132             prop->setExponentRatio(3.0);
0133 
0134             prop->setReadCallback(
0135                 [](KisUniformPaintOpProperty *prop) {
0136                     KisRoundMarkerOpOptionData data;
0137                     data.read(prop->settings().data());
0138 
0139                     prop->setValue(data.autoSpacingCoeff);
0140                 });
0141             prop->setWriteCallback(
0142                 [](KisUniformPaintOpProperty *prop) {
0143                     KisRoundMarkerOpOptionData data;
0144                     data.read(prop->settings().data());
0145                     data.autoSpacingCoeff = prop->value().toBool();
0146                     data.write(prop->settings().data());
0147                 });
0148 
0149             QObject::connect(updateProxy, SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue()));
0150             prop->requestReadValue();
0151             props << toQShared(prop);
0152         }
0153     }
0154 
0155     return KisPaintOpSettings::uniformProperties(settings, updateProxy) + props;
0156 }