diff --git a/plugins/tools/selectiontools/KisToolSelectGuided.cc b/plugins/tools/selectiontools/KisToolSelectGuided.cc index c024a1a9a0..7e7927f49a 100644 --- a/plugins/tools/selectiontools/KisToolSelectGuided.cc +++ b/plugins/tools/selectiontools/KisToolSelectGuided.cc @@ -1,152 +1,159 @@ #include "KisToolSelectGuided.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kis_painter.h" #include #include "canvas/kis_canvas2.h" #include "kis_pixel_selection.h" #include "kis_selection_tool_helper.h" #include "kis_algebra_2d.h" #include "KisHandlePainterHelper.h" #include #include #include #include #include #include #include #include KisToolSelectGuided::KisToolSelectGuided(KoCanvasBase *canvas) : KisToolSelect(canvas, - i18n("Guidedc Selection")), - m_started(false), m_finished(false),m_worker(image()->projection()), m_epsilon(70),m_filterRadius(3) + i18n("Guided Selection")), + m_finished(false), m_epsilon(70),m_filterRadius(3) { } -void KisToolSelectGuided::GuidedSelectGenerate() +/*void KisToolSelectGuided::GuidedSelectGenerate() { KisCanvas2 *kisCanvas = dynamic_cast(canvas()); KIS_ASSERT_RECOVER_RETURN(kisCanvas); kisCanvas->updateCanvas(); setMode(KisTool::HOVER_MODE); if (mode == PIXEL_SELECTION){ KisPaintDeviceSP image = KisPaintDeviceSP(new KisPaintDevice(currentImage()->projection())); image.ConvertTo(KoColorSpaceRegistry::instance()->rgb32()); KisLodTransformScalar t(image); - const qreal BoxBlurAmount = t.scale(m_filterRadius ? m_filterRadius.toDouble() : 1.0); + const qreal BoxBlurAmount = t.scale(m_filterEpsilon ? m_filterEpsilon.toDouble() : 1.0); QRect applyRect(QPoint(0, 0), image.width(),image.height()); const QRect boxNeedRect = this->neededRect(applyRect, config, originalimage->defaultBounds()->currentLevelOfDetail()); KisSequentialConstIterator it(imageDev, QRect(0, 0, image.width(), image.height())); for (int y = 0; y < image.height(); y++) { for (int x = 0; x < image.width(); x++) { it.nextPixel(); const quint8* pixel = it.rawDataConst(); for (int chan = 0; chan < 4; ++chan) { image &img = image[chan]; *(img.scanLine(y) + x) = cs->scaleToU8(pixel, chan); } } } } } QRect KisToolSelectGuided::neededRect(const QRect & rect, int lod) const { KisLodTransformScalar t(lod); const int halfSize = m_filterRadius ? KisGaussianKernel::kernelSizeFromRadius(t.scale(m_filterRadius.toFloat())) / 2 : 5; return rect.adjusted( -halfSize * 2, -halfSize * 2, halfSize * 2, halfSize * 2); } QRect KisToolSelectGuided::changedRect(const QRect & rect, int lod) const { KisLodTransformScalar t(lod); const int halfSize = m_filterRadius ? KisGaussianKernel::kernelSizeFromRadius(t.scale(m_filterRadius.toFloat())) / 2 : 5; return rect.adjusted( -halfSize, -halfSize, halfSize, halfSize); -} +}*/ QWidget * KisToolSelectGuided::createOptionWidget() { KisToolSelectBase::createOptionWidget(); KisSelectionOptions *selectionWidget = selectionOptionWidget(); - QHBoxLayout *f1 = new QHBoxLayout(); - QLabel *filterRadiusLabel = new QLabel(i18n("Filter Radius: "), selectionWidget); - f1->addWidget(filterRadiusLabel); - - KisSliderSpinBox *filterRadiusInput = new KisSliderSpinBox(selectionWidget); - filterRadiusInput->setObjectName("radius"); - filterRadiusInput->setRange(2.5, 100.0, 2); - filterRadiusInput->setSingleStep(0.5); - filterRadiusInput->setToolTip("Radius of the filter for the detecting edges, might take some time to calculate"); - f1->addWidget(filterRadiusInput); - connect(filterRadiusInput, SIGNAL(valueChanged(int)), this, SLOT(slotSetFilterRadius(int))); QHBoxLayout *f1 = new QHBoxLayout(); - QLabel *thresholdLabel = new QLabel(i18n("Threshold: "), selectionWidget); - f1->addWidget(thresholdLabel); - - KisDoubleSliderSpinBox *epsilonInput = new KisDoubleSliderSpinBox(selectionWidget); - thresholdInput->setObjectName("epsilon"); - thresholdInput->setRange(1, 255); - thresholdInput->setSingleStep(10); - thresholdInput->setToolTip("Variable to adjust guided selection end results"); - f2->addWidget(thresholdInput); - connect(filterRadiusInput, SIGNAL(valueChanged(qreal)), this, SLOT(slotSetFilterRadius(qreal))); + QLabel *RadiusLabel = new QLabel(i18n("Threshold: "), selectionWidget); + f1->addWidget(RadiusLabel); + + KisSliderSpinBox *RadiusInput = new KisSliderSpinBox(selectionWidget); + RadiusInput->setObjectName("Radius"); + RadiusInput->setRange(1, 255); + RadiusInput->setSingleStep(10); + RadiusInput->setToolTip("Threshold for determining the minimum intensity of the edges"); + f1->addWidget(RadiusInput); + connect(RadiusInput, SIGNAL(valueChanged(int)), this, SLOT(slotSetRadius(int))); + + QHBoxLayout *f2 = new QHBoxLayout(); + QLabel *filterEpsilonLabel = new QLabel(i18n("Filter Epsilon: "), selectionWidget); + f2->addWidget(filterEpsilonLabel); + + KisDoubleSliderSpinBox *filterEpsilonInput = new KisDoubleSliderSpinBox(selectionWidget); + filterEpsilonInput->setObjectName("radius"); + filterEpsilonInput->setRange(2.5, 100.0, 2); + filterEpsilonInput->setSingleStep(0.5); + filterEpsilonInput->setToolTip("Epsilon of the filter for the detecting edges, might take some time to calculate"); + f2->addWidget(filterEpsilonInput); + connect(filterEpsilonInput, SIGNAL(valueChanged(qreal)), this, SLOT(slotSetEpsilon(qreal))); QVBoxLayout *l = dynamic_cast(selectionWidget->layout()); - l->insertLayout(1, f1); - l->insertLayout(2, f2); + l->insertLayout(1, f2); + l->insertLayout(2, f1); - filterRadiusInput->setValue(m_configGroup.readEntry("filterradius", 3.0)); - epsilonInput->setValue(m_configGroup.readEntry("epsilon", 100)); + RadiusInput->setValue(m_configGroup.readEntry("filterradius", 3.0)); + filterEpsilonInput->setValue(m_configGroup.readEntry("Epsilon", 100)); return selectionWidget; -} // KisToolSelectGuided::createOptionWidget +} // KisToolSelectMagnetic::createOptionWidget + +void KisToolSelectGuided::activate(KoToolBase::ToolActivation activation, const QSet &shapes) +{ + m_configGroup = KSharedConfig::openConfig()->group(toolId()); + KisToolSelect::activate(activation, shapes); +} -void KisToolSelectGuided::slotSetFilterRadius(qreal r) +void KisToolSelectGuided::slotSetRadius(int r) { m_filterRadius = r; m_configGroup.writeEntry("filterradius", r); } -void KisToolSelectGuided::slotSetEpsilon(int e) +void KisToolSelectGuided::slotSetEpsilon(qreal e) { m_epsilon = e; m_configGroup.writeEntry("epsilon", e); } diff --git a/plugins/tools/selectiontools/KisToolSelectGuided.h b/plugins/tools/selectiontools/KisToolSelectGuided.h index 636e75a682..c135dc03de 100644 --- a/plugins/tools/selectiontools/KisToolSelectGuided.h +++ b/plugins/tools/selectiontools/KisToolSelectGuided.h @@ -1,61 +1,90 @@ +/* + * Copyright (c) 2019 Kuntal Majumder + * + * 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 KIS_TOOL_SELECT_GUIDED_H_ #define KIS_TOOL_SELECT_GUIDED_H_ #include #include "KisSelectionToolFactoryBase.h" #include #include #include class QPainterPath; class KisToolSelectGuided : public KisToolSelect { Q_OBJECT - + public: KisToolSelectGuided(KoCanvasBase *canvas); ~KisToolSelectGuided() override = default; + void paint(QPainter& gc, const KoViewConverter &converter) override; QWidget * createOptionWidget() override; + public Q_SLOTS: - void slotSetFilterRadius(int); + void activate(KoToolBase::ToolActivation activation, const QSet &shapes) override; + void slotSetRadius(int); void slotSetEpsilon(qreal); + protected: using KisToolSelectBase::m_widgetHelper; + private: + //const QRect& applyRect; + //const QRect& neededRect; + KConfigGroup m_configGroup; + bool m_finished; int m_filterRadius; qreal m_epsilon; + }; class KisToolSelectGuidedFactory : public KisSelectionToolFactoryBase { public: KisToolSelectGuidedFactory() : KisSelectionToolFactoryBase("KisToolSelectGuided") { setToolTip(i18n("Guided Selection Tool")); setSection(TOOL_TYPE_SELECTION); setIconName(koIconNameCStr("tool_guided_selection")); setPriority(9); setActivationShapeId(KRITA_TOOL_ACTIVATION_ID); } ~KisToolSelectGuidedFactory() override { } - + KoToolBase * createTool(KoCanvasBase *canvas) override { return new KisToolSelectGuided(canvas); } QList createActionsImpl() override { KisActionRegistry *actionRegistry = KisActionRegistry::instance(); QList actions = KisSelectionToolFactoryBase::createActionsImpl(); - actions << actionRegistry->makeQAction("undo_guided_selection"); + actions << actionRegistry->makeQAction("undo_polygon_selection"); return actions; } }; + #endif // __selecttoolguided_h__