diff --git a/plugins/paintops/watercolor/kis_base_splats_plane.cpp b/plugins/paintops/watercolor/kis_base_splats_plane.cpp index ff162f5bed..eea58db66c 100644 --- a/plugins/paintops/watercolor/kis_base_splats_plane.cpp +++ b/plugins/paintops/watercolor/kis_base_splats_plane.cpp @@ -1,92 +1,100 @@ /* This file is part of the KDE project * * Copyright (C) 2017 Grigory Tantsevov * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kis_base_splats_plane.h" KisBaseSplatsPlane::KisBaseSplatsPlane(bool useCaching, KisBaseSplatsPlane *lowLvlPlane, const KoColorSpace* colorSpace) : m_lowLvlPlane(lowLvlPlane), m_useCaching(useCaching) { if (useCaching) m_cachedPD = new KisPaintDevice(colorSpace); + m_splatsTree = new KoRTree(4, 2); } KisBaseSplatsPlane::~KisBaseSplatsPlane() { } void KisBaseSplatsPlane::add(KisSplat *splat) { m_splats << splat; + m_splatsTree->insert(splat->boundingRect().toAlignedRect(), splat); if (m_useCaching) { KisPainter *painter = new KisPainter(m_cachedPD); splat->doPaint(painter); } } void KisBaseSplatsPlane::remove(KisSplat *splat) { m_splats.removeOne(splat); + m_splatsTree->remove(splat); if (m_useCaching) { m_cachedPD->clear(splat->boundingRect().toAlignedRect()); } } void KisBaseSplatsPlane::paint(KisPainter *gc, QRect rect) { if (rect.isNull()) return; if (m_useCaching) { gc->bitBlt(rect.topLeft(), m_cachedPD, rect); } else { Q_FOREACH (KisSplat *splat, m_splats) { - if (rect.contains(splat->boundingRect().toAlignedRect())) +// if (rect.contains(splat->boundingRect().toAlignedRect())) splat->doPaint(gc); } } } QRect KisBaseSplatsPlane::update(KisWetMap *wetMap) { QRect dirtyRect; for (auto it = m_splats.begin(); it != m_splats.end();) { KisSplat *splat = *it; dirtyRect |= splat->boundingRect().toAlignedRect(); if (splat->update(wetMap) == KisSplat::Fixed) { m_lowLvlPlane->add(splat); { // move to protected call to parent class it = m_splats.erase(it); dirtyRect |= splat->boundingRect().toAlignedRect(); } } else { dirtyRect |= splat->boundingRect().toAlignedRect(); ++it; } } return dirtyRect; } + +KoRTree *KisBaseSplatsPlane::splatsTree() const +{ + return m_splatsTree; +} diff --git a/plugins/paintops/watercolor/kis_base_splats_plane.h b/plugins/paintops/watercolor/kis_base_splats_plane.h index 4cc21529a9..6f93b32c8b 100644 --- a/plugins/paintops/watercolor/kis_base_splats_plane.h +++ b/plugins/paintops/watercolor/kis_base_splats_plane.h @@ -1,85 +1,88 @@ /* This file is part of the KDE project * * Copyright (C) 2017 Grigory Tantsevov * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIS_ABSTRACT_SPLATS_PLANE_H #define KIS_ABSTRACT_SPLATS_PLANE_H #include "kis_splat.h" #include "kis_wetmap.h" #include "kis_paint_device.h" #include +#include "KoRTree.h" /** * Base class for the splats' containers in watercolor * brush. It needs for separating splats in different states. * This plane storages list of splats and paint it on * paint device. So for this it can: * * 1) add() splats to list and paint device; * * 2) remove() splats from list and paint device; * * 3) paint() paint device with given painter */ class KisBaseSplatsPlane { public: KisBaseSplatsPlane(bool useCaching, KisBaseSplatsPlane *lowLvlPlane = 0, const KoColorSpace *colorSpace = 0); virtual ~KisBaseSplatsPlane(); /** * @brief add splat to list of splats and paint device * @param splat - new splat */ void add(KisSplat *splat); /** * @brief revome splat from plane * @param splat - removing splat */ void remove(KisSplat *splat); /** * @brief paint plane on given painter in given rect * @param gc - painter * @param rect - zone of paint */ void paint(KisPainter *gc, QRect rect); /** * @brief update plane * @param wetMap - base for updating */ virtual QRect update(KisWetMap *wetMap); - protected: QList m_splats; + KoRTree *m_splatsTree; KisBaseSplatsPlane *m_lowLvlPlane; + KoRTree *splatsTree() const; + protected: bool m_useCaching; KisPaintDeviceSP m_cachedPD; }; #endif // KIS_ABSTRACT_SPLATS_PLANE_H diff --git a/plugins/paintops/watercolor/kis_fixed_splats_plane.cpp b/plugins/paintops/watercolor/kis_fixed_splats_plane.cpp index aab3736260..6e78f0eef6 100644 --- a/plugins/paintops/watercolor/kis_fixed_splats_plane.cpp +++ b/plugins/paintops/watercolor/kis_fixed_splats_plane.cpp @@ -1,61 +1,66 @@ /* * Copyright (c) 2017 Dmitry Kazakov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kis_fixed_splats_plane.h" KisFixedSplatsPlane::KisFixedSplatsPlane(KisBaseSplatsPlane *driedPlane, const KoColorSpace *colorSpace) - : KisBaseSplatsPlane(true, driedPlane, colorSpace), - m_splatsTree(4, 2) + : KisBaseSplatsPlane(true, driedPlane, colorSpace) { } QRect KisFixedSplatsPlane::update(KisWetMap *wetMap) { QRect dirtyRect; for (auto it = m_splats.begin(); it != m_splats.end();) { KisSplat *splat = *it; if (splat->update(wetMap) == KisSplat::Dried) { m_lowLvlPlane->add(splat); { // move to protected call to parent class it = m_splats.erase(it); + splatsTree()->remove(splat); m_cachedPD->clear(splat->boundingRect().toAlignedRect()); dirtyRect |= splat->boundingRect().toAlignedRect(); + QList rePaint = splatsTree()->intersects(splat->boundingRect().toAlignedRect()); + KisPainter *painter = new KisPainter(m_cachedPD); + Q_FOREACH(KisSplat *reSplat, rePaint) { + if (reSplat != splat) + reSplat->doPaint(painter, splat->boundingRect().toAlignedRect()); + } } } else { ++it; } } return dirtyRect; } void KisFixedSplatsPlane::rewet(KisWetMap *wetMap, QPointF pos, qreal rad, KisBaseSplatsPlane *flowingPlane) { QRectF rect(pos.x() - rad, pos.y() - rad, rad * 2, rad * 2); - QList reweted = m_splatsTree.intersects(rect);\ + QList reweted = splatsTree()->intersects(rect);\ Q_FOREACH(KisSplat *splat, reweted) { splat->rewet(wetMap, pos, rad); remove(splat); - m_splatsTree.remove(splat); flowingPlane->add(splat); } } diff --git a/plugins/paintops/watercolor/kis_fixed_splats_plane.h b/plugins/paintops/watercolor/kis_fixed_splats_plane.h index 8f6fbb8653..14829b4264 100644 --- a/plugins/paintops/watercolor/kis_fixed_splats_plane.h +++ b/plugins/paintops/watercolor/kis_fixed_splats_plane.h @@ -1,39 +1,37 @@ /* * Copyright (c) 2017 Dmitry Kazakov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KISFIXEDSPLATSPLANE_H #define KISFIXEDSPLATSPLANE_H #include "kis_base_splats_plane.h" -#include "KoRTree.h" class KisFixedSplatsPlane : public KisBaseSplatsPlane { public: KisFixedSplatsPlane(KisBaseSplatsPlane *driedPlane, const KoColorSpace *colorSpace); QRect update(KisWetMap *wetMap) override; void rewet(KisWetMap *wetMap, QPointF pos, qreal rad, KisBaseSplatsPlane *flowingPlane); private: KisBaseSplatsPlane *m_flowingPlane; - KoRTree m_splatsTree; }; #endif // KISFIXEDSPLATSPLANE_H diff --git a/plugins/paintops/watercolor/kis_splat.cpp b/plugins/paintops/watercolor/kis_splat.cpp index 1dda8bdc2f..4604a7c4ff 100644 --- a/plugins/paintops/watercolor/kis_splat.cpp +++ b/plugins/paintops/watercolor/kis_splat.cpp @@ -1,245 +1,268 @@ /* This file is part of the KDE project * * Copyright (C) 2017 Grigory Tantsevov * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kis_splat.h" #include "kis_random_generator.h" #include #include #include "kis_sequential_iterator.h" #define START_OPACITY 70 #define STANDART_LIFETIME 60 double get_random(qreal min, qreal max) { return (qreal)rand() / RAND_MAX*(max - min) + min; } KisSplat::KisSplat(QPointF offset, int width, const KoColor &color, int gravityX, int gravityY) : m_life(STANDART_LIFETIME), m_roughness(1.f), m_flow(1.f), m_motionBias(QPointF(0.f, 0.f)), m_state(Flowing), m_gravityX(gravityX), m_gravityY(gravityY) { m_initColor.fromKoColor(color); m_fix = STANDART_LIFETIME; int r = width / 2; int n = 128; qreal dt = 2.f * M_PI / n; QPointF p; for (int i = 0; i < n; i++) { p.setX(cos(i * dt)); p.setY(sin(i * dt)); m_vertices.push_back(QPointF(static_cast (r * p.x()) + offset.x(), static_cast (r * p.y()) + offset.y())); m_velocities.push_back(QPointF(2.f * p.x(), 2.f * p.y())); } m_initSize = CalcSize(); m_startTime = QTime::currentTime(); } KisSplat::KisSplat(QPointF offset, QPointF velocityBias, int width, int life, qreal roughness, qreal flow, qreal radialSpeed, const KoColor &color, int gravityX, int gravityY) : m_life(life), m_roughness(roughness), m_flow(flow), m_motionBias(velocityBias), m_state(Flowing), m_gravityX(gravityX), m_gravityY(gravityY) { m_initColor.fromKoColor(color); m_fix = STANDART_LIFETIME; int r = width / 2; int n = 128; qreal dt = 2.f * M_PI / n; QPointF p; for (int i = 0; i < n; i++) { p.setX(cos(i * dt)); p.setY(sin(i * dt)); m_vertices.push_back(QPointF(static_cast (r * p.x()) + offset.x(), static_cast (r * p.y()) + offset.y())); m_velocities.push_back(QPointF(radialSpeed * p.x(), radialSpeed * p.y())); } m_initSize = CalcSize(); m_startTime = QTime::currentTime(); } qreal KisSplat::CalcSize() { if (m_vertices.length() < 3) return 0.f; QPointF v0 = m_vertices[0]; qreal v0x = v0.x(); qreal v0y = v0.y(); QPointF e0 = m_vertices[1] - v0; qreal e0x = e0.x(); qreal e0y = e0.y(); qreal s = 0.f; int length = m_vertices.length(); for (int i = 2; i < length; i++) { QPointF v2 = m_vertices[i]; qreal e1x = v2.x() - v0x; qreal e1y = v2.y() - v0y; s += e0x * e1y - e0y * e1x; e0x = e1x; e0y = e1y; } return s >= 0 ? s : -s; } void KisSplat::clearOldPath(KisPaintDeviceSP dev) { QRect rect = m_oldPath.boundingRect().toRect(); KisSequentialIterator it(dev, rect); do { QPoint place(it.x(), it.y()); if (m_oldPath.contains(place)) { qint16 *mydata = reinterpret_cast(it.rawData()); mydata[0] = 0; } } while (it.nextPixel()); } void KisSplat::doPaint(KisPainter *painter) { qreal multiply = m_initSize / CalcSize(); if (multiply < 0.f || multiply > 1.f) multiply = 1; qint8 oldOpacity = painter->opacity(); KisPainter::FillStyle oldFillStyle = painter->fillStyle(); KoColor oldColor = painter->paintColor(); painter->setOpacity(START_OPACITY * multiply); painter->setFillStyle(KisPainter::FillStyleForegroundColor); painter->setPaintColor(m_initColor); painter->fillPainterPath(this->shape()); painter->setOpacity(oldOpacity); painter->setFillStyle(oldFillStyle); painter->setPaintColor(oldColor); } +void KisSplat::doPaint(KisPainter *painter, QRectF rect) +{ + qreal multiply = m_initSize / CalcSize(); + if (multiply < 0.f || multiply > 1.f) + multiply = 1; + + qint8 oldOpacity = painter->opacity(); + KisPainter::FillStyle oldFillStyle = painter->fillStyle(); + KoColor oldColor = painter->paintColor(); + + painter->setOpacity(START_OPACITY * multiply); + painter->setFillStyle(KisPainter::FillStyleForegroundColor); + painter->setPaintColor(m_initColor); + QPainterPath rectPath; + rectPath.addRect(rect); + QPainterPath shapeIn = shape().intersected(rectPath); + painter->fillPainterPath(shapeIn); + + painter->setOpacity(oldOpacity); + painter->setFillStyle(oldFillStyle); + painter->setPaintColor(oldColor); +} + QPainterPath KisSplat::shape() const { QPainterPath path; int len = m_vertices.length(); path = *(new QPainterPath(m_vertices[0])); for (int i = 0; i < len-2; i+=2) { path.quadTo(m_vertices[i+1], m_vertices[i+2]); } path.quadTo(m_vertices[len-1], m_vertices[0]); return path; } QRectF KisSplat::boundingRect() const { return m_vertices.boundingRect(); } int KisSplat::update(KisWetMap *wetMap) { if (m_life <= 0) { if (m_fix <= 0) { m_state = Dried; return KisSplat::Dried; } else { m_state = Fixed; m_fix--; return KisSplat::Fixed; } } m_life--; m_oldPath = shape(); QVector newVertices; for (int i = 0; i < m_vertices.length(); i++) { QPointF x = m_vertices[i]; QPointF v = m_velocities[i]; QPointF d = (1.f - alpha) * m_motionBias + alpha / get_random(1.f, 1.f + m_roughness) * v; - QPointF x1 = x + m_flow * d + QPointF(m_gravityX / 12, m_gravityY / 12)/* + QPointF x1 = x + m_flow * d + QPointF(m_gravityX / 10, m_gravityY / 10)/* + QPointF(get_random(-m_roughness, m_roughness) / 5, get_random(-m_roughness, m_roughness) / 5)*/; newVertices.push_back(x1); } QVector wetPoints = wetMap->getWater(newVertices); for (int i = 0; i < wetPoints.size(); i++) { if (wetPoints.at(i) > 0) m_vertices[i] = newVertices.at(i); } if (!m_life) { for (int i = 0; i < m_vertices.length(); i++) { m_velocities[i] = QPointF(0, 0); } } m_state = Flowing; return KisSplat::Flowing; } int KisSplat::rewet(KisWetMap *wetMap, QPointF pos, qreal radius) { QVector vertNum; QVector vertUpdate; for (int i = 0; i < m_vertices.size(); i++) { QVector2D vec(m_vertices.at(i) - pos); if (vec.length() <= radius) { vertNum.push_back(i); vertUpdate.push_back(m_vertices[i]); } } if (vertNum.size() > 0) { QVector newSpeed = wetMap->getSpeed(vertUpdate); for (int i = 0; i < vertNum.size(); i++) { int num = vertNum.at(i); m_velocities[num] = newSpeed.at(i); } m_life = STANDART_LIFETIME; m_fix = STANDART_LIFETIME; m_state = Flowing; return KisSplat::Flowing; } else { m_state = Fixed; return KisSplat::Fixed; } } diff --git a/plugins/paintops/watercolor/kis_splat.h b/plugins/paintops/watercolor/kis_splat.h index ae7cef7e91..4c6c6ea1b0 100644 --- a/plugins/paintops/watercolor/kis_splat.h +++ b/plugins/paintops/watercolor/kis_splat.h @@ -1,89 +1,90 @@ /* This file is part of the KDE project * * Copyright (C) 2017 Grigory Tantsevov * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIS_SPLAT_H #define KIS_SPLAT_H #include #include #include #include #include #include "kis_wetmap.h" #include "kis_random_generator.h" #include "kritawatercolorpaintop_export.h" #include "kis_painter.h" double get_random(qreal min, qreal max); class WATERCOLORPAINT_EXPORT KisSplat { public: enum SplatState { Flowing, Fixed, Dried }; KisSplat(QPointF offset, int width, const KoColor &color, int gravityX, int gravityY); KisSplat(QPointF offset, QPointF velocityBias, int width, int life, qreal roughness, qreal flow, qreal radialSpeed, const KoColor &color, int gravityX, int gravityY); void doPaint(KisPainter *painter); + void doPaint(KisPainter *painter, QRectF rect); QPainterPath shape() const; QRectF boundingRect() const; int update(KisWetMap *wetMap); int rewet(KisWetMap *wetMap, QPointF pos, qreal radius); private: qreal CalcSize(); void clearOldPath(KisPaintDeviceSP dev); const float alpha = 0.33f; QPolygonF m_vertices; QVector m_velocities; int m_life; qreal m_roughness; qreal m_flow; QPointF m_motionBias; QTime m_startTime; qreal m_initSize; KoColor m_initColor; int m_fix; int m_state; QPainterPath m_oldPath; int m_gravityX, m_gravityY; }; #endif diff --git a/plugins/paintops/watercolor/kis_watercolor_paintop_settings.cpp b/plugins/paintops/watercolor/kis_watercolor_paintop_settings.cpp index db6de566f1..1a1c57ad64 100644 --- a/plugins/paintops/watercolor/kis_watercolor_paintop_settings.cpp +++ b/plugins/paintops/watercolor/kis_watercolor_paintop_settings.cpp @@ -1,222 +1,226 @@ /* This file is part of the KDE project * * Copyright (C) 2017 Grigory Tantsevov * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kis_watercolor_paintop_settings.h" #include "kis_watercolorop_option.h" struct KisWatercolorPaintOpSettings::Private { QList uniformProperties; }; KisWatercolorPaintOpSettings::KisWatercolorPaintOpSettings() : m_d(new Private) { } KisWatercolorPaintOpSettings::~KisWatercolorPaintOpSettings() { } bool KisWatercolorPaintOpSettings::paintIncremental() { /** * The watercolor brush supports working in the * WASH mode only! */ return false; } void KisWatercolorPaintOpSettings::setPaintOpSize(qreal value) { + qDebug() << "\n setSize"; WatercolorOption op; op.readOptionSettingImpl(this); - op.radius = qRound(0.5 * value); + op.radius = value; + qDebug() << ppVar(op.radius); op.writeOptionSettingImpl(this); } qreal KisWatercolorPaintOpSettings::paintOpSize() const { + qDebug() << "\nreadSize"; WatercolorOption op; op.readOptionSettingImpl(this); + qDebug() << ppVar(op.radius); return op.radius; } #include #include "kis_paintop_preset.h" #include "kis_paintop_settings_update_proxy.h" #include "kis_watercolorop_option.h" #include "kis_standard_uniform_properties_factory.h" QList KisWatercolorPaintOpSettings::uniformProperties(KisPaintOpSettingsSP settings) { QList props = listWeakToStrong(m_d->uniformProperties); if (props.isEmpty()) { { KisDoubleSliderBasedPaintOpPropertyCallback *prop = new KisDoubleSliderBasedPaintOpPropertyCallback( KisDoubleSliderBasedPaintOpPropertyCallback::Double, "watercolor_gravityX", i18n("GravityX"), settings, 0); prop->setRange(-10.0, 10.0); prop->setSingleStep(1.0); prop->setReadCallback( [](KisUniformPaintOpProperty *prop) { WatercolorOption option; option.readOptionSettingImpl(prop->settings().data()); prop->setValue(qreal(option.gravityX)); }); prop->setWriteCallback( [](KisUniformPaintOpProperty *prop) { WatercolorOption option; option.readOptionSettingImpl(prop->settings().data()); option.gravityX = prop->value().toDouble(); option.writeOptionSetting(prop->settings().data()); }); QObject::connect(preset()->updateProxy(), SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue())); prop->requestReadValue(); props << toQShared(prop); } { KisDoubleSliderBasedPaintOpPropertyCallback *prop = new KisDoubleSliderBasedPaintOpPropertyCallback( KisDoubleSliderBasedPaintOpPropertyCallback::Double, "watercolor_gravityY", i18n("GravityY"), settings, 0); prop->setRange(-10.0, 10.0); prop->setSingleStep(1.0); prop->setReadCallback( [](KisUniformPaintOpProperty *prop) { WatercolorOption option; option.readOptionSettingImpl(prop->settings().data()); prop->setValue(qreal(option.gravityY)); }); prop->setWriteCallback( [](KisUniformPaintOpProperty *prop) { WatercolorOption option; option.readOptionSettingImpl(prop->settings().data()); option.gravityY = prop->value().toDouble(); option.writeOptionSettingImpl(prop->settings().data()); }); QObject::connect(preset()->updateProxy(), SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue())); prop->requestReadValue(); props << toQShared(prop); } { KisUniformPaintOpPropertyCallback *prop = new KisUniformPaintOpPropertyCallback( KisUniformPaintOpPropertyCallback::Int, "watercolor_brushType", i18n("BrushType"), settings, 0); prop->setReadCallback( [](KisUniformPaintOpProperty *prop) { WatercolorOption option; option.readOptionSettingImpl(prop->settings().data()); prop->setValue(int(option.type)); }); prop->setWriteCallback( [](KisUniformPaintOpProperty *prop) { WatercolorOption option; option.readOptionSettingImpl(prop->settings().data()); option.type = prop->value().toInt(); option.writeOptionSettingImpl(prop->settings().data()); }); QObject::connect(preset()->updateProxy(), SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue())); prop->requestReadValue(); props << toQShared(prop); } { KisDoubleSliderBasedPaintOpPropertyCallback *prop = new KisDoubleSliderBasedPaintOpPropertyCallback( KisDoubleSliderBasedPaintOpPropertyCallback::Double, "watercolor_radius", i18n("Radius"), settings, 0); prop->setRange(0, 1000.0); prop->setSingleStep(1.0); prop->setReadCallback( [](KisUniformPaintOpProperty *prop) { WatercolorOption option; option.readOptionSettingImpl(prop->settings().data()); prop->setValue(qreal(option.radius)); }); prop->setWriteCallback( [](KisUniformPaintOpProperty *prop) { WatercolorOption option; option.readOptionSettingImpl(prop->settings().data()); option.radius = prop->value().toDouble(); option.writeOptionSettingImpl(prop->settings().data()); }); QObject::connect(preset()->updateProxy(), SIGNAL(sigSettingsChanged()), prop, SLOT(requestReadValue())); prop->requestReadValue(); props << toQShared(prop); } } { using namespace KisStandardUniformPropertiesFactory; Q_FOREACH (KisUniformPaintOpPropertySP prop, KisPaintOpSettings::uniformProperties(settings)) { if (prop->id() == opacity.id()) { props.prepend(prop); } } } return props; } bool KisWatercolorPaintOpSettings::needsContinuedStroke() { return true; } QPainterPath KisWatercolorPaintOpSettings::brushOutline(const KisPaintInformation &info, KisPaintOpSettings::OutlineMode mode) { QPainterPath path; if (mode == CursorIsOutline || mode == CursorIsCircleOutline || mode == CursorTiltOutline) { qreal size = getInt(WATERCOLOR_RADIUS) + 1; path = ellipseOutline(size, size, 1.0, 0.0); if (mode == CursorTiltOutline) { path.addPath(makeTiltIndicator(info, QPointF(0.0, 0.0), size * 0.5, 3.0)); } path.translate(info.pos()); } return path; } diff --git a/plugins/paintops/watercolor/kis_watercolor_paintop_settings.h b/plugins/paintops/watercolor/kis_watercolor_paintop_settings.h index 7d901a1b9b..91dbf8e88c 100644 --- a/plugins/paintops/watercolor/kis_watercolor_paintop_settings.h +++ b/plugins/paintops/watercolor/kis_watercolor_paintop_settings.h @@ -1,49 +1,49 @@ /* This file is part of the KDE project * * Copyright (C) 2017 Grigory Tantsevov * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIS_WATERCOLOR_PAINTOP_SETTINGS_H_ #define KIS_WATERCOLOR_PAINTOP_SETTINGS_H_ #include #include class KisWatercolorPaintOpSettings : public KisPaintOpSettings { public: KisWatercolorPaintOpSettings(); virtual ~KisWatercolorPaintOpSettings(); bool paintIncremental() override; - void setPaintOpSize(qreal value) override; - qreal paintOpSize() const override; - QList uniformProperties(KisPaintOpSettingsSP settings); bool needsContinuedStroke() override; QPainterPath brushOutline(const KisPaintInformation &info, OutlineMode mode) override; + void setPaintOpSize(qreal value) override; + qreal paintOpSize() const override; + private: struct Private; const QScopedPointer m_d; }; #endif diff --git a/plugins/paintops/watercolor/kis_watercolorop_option.cpp b/plugins/paintops/watercolor/kis_watercolorop_option.cpp index 63e76ab349..222cc66daa 100644 --- a/plugins/paintops/watercolor/kis_watercolorop_option.cpp +++ b/plugins/paintops/watercolor/kis_watercolorop_option.cpp @@ -1,99 +1,86 @@ /* This file is part of the KDE project * * Copyright (C) 2017 Grigory Tantsevov * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kis_watercolorop_option.h" #include #include #include #include "ui_wdgwatercoloroptions.h" class KisWatercolorOpOptionsWidget: public QWidget, public Ui::WdgWatercolorOptions { public: KisWatercolorOpOptionsWidget(QWidget *parent = 0) : QWidget(parent) { setupUi(this); gravityX->setRange(-10.0, 10.0); gravityX->setValue(0); gravityX->setSingleStep(1.0); gravityY->setRange(-10.0, 10.0); gravityY->setValue(0); gravityY->setSingleStep(1.0); radius->setRange(0.0, 1000.0); - radius->setPrefix("px"); - radius->setValue(25); + radius->setSuffix(i18n(" px")); + radius->setValue(100.0); radius->setSingleStep(1.0); } }; KisWatercolorOpOption::KisWatercolorOpOption() : KisPaintOpOption(KisPaintOpOption::GENERAL, false) { setObjectName("KisWatercolorOpOption"); m_checkable = false; m_options = new KisWatercolorOpOptionsWidget(); connect(m_options->gravityX, SIGNAL(valueChanged(qreal)), SLOT(emitSettingChanged())); connect(m_options->gravityY, SIGNAL(valueChanged(qreal)), SLOT(emitSettingChanged())); connect(m_options->brushType, SIGNAL(currentIndexChanged(QString)), SLOT(emitSettingChanged())); connect(m_options->radius, SIGNAL(valueChanged(qreal)), SLOT(emitSettingChanged())); setConfigurationPage(m_options); } KisWatercolorOpOption::~KisWatercolorOpOption() { delete m_options; } void KisWatercolorOpOption::writeOptionSetting(KisPropertiesConfigurationSP setting) const { setting->setProperty(WATERCOLOR_GRAVITY_X, m_options->gravityX->value()); setting->setProperty(WATERCOLOR_GRAVITY_Y, m_options->gravityY->value()); setting->setProperty(WATERCOLOR_TYPE, m_options->brushType->currentIndex()); setting->setProperty(WATERCOLOR_RADIUS, m_options->radius->value()); -// WatercolorOption op; - -// op.gravityX = m_options->gravityX->value(); -// op.gravityY = m_options->gravityY->value(); - -// op.type = m_options->brushType->currentIndex(); - -// op.radius = m_options->radius->value(); - -// op.writeOptionSettingImpl(setting); } void KisWatercolorOpOption::readOptionSetting(const KisPropertiesConfigurationSP setting) { -// WatercolorOption op; -// op.readOptionSettingImpl(setting); - m_options->gravityX->setValue(setting->getDouble(WATERCOLOR_GRAVITY_X)); m_options->gravityY->setValue(setting->getDouble(WATERCOLOR_GRAVITY_Y)); m_options->brushType->setCurrentIndex(setting->getInt(WATERCOLOR_TYPE)); m_options->radius->setValue(setting->getDouble(WATERCOLOR_RADIUS)); }