diff --git a/plugins/tools/karbonplugins/CMakeLists.txt b/plugins/tools/karbonplugins/CMakeLists.txt index 11fdd0957e..03cec287de 100644 --- a/plugins/tools/karbonplugins/CMakeLists.txt +++ b/plugins/tools/karbonplugins/CMakeLists.txt @@ -1,2 +1 @@ add_subdirectory( tools ) -add_subdirectory( filtereffects ) diff --git a/plugins/tools/karbonplugins/filtereffects/BlendEffect.cpp b/plugins/tools/karbonplugins/filtereffects/BlendEffect.cpp deleted file mode 100644 index 0f10b6db27..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/BlendEffect.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "BlendEffect.h" -#include "ColorChannelConversion.h" -#include -#include -#include -#include -#include -#include -#include - -BlendEffect::BlendEffect() - : KoFilterEffect(BlendEffectId, i18n("Blend")) - , m_blendMode(Normal) -{ - setRequiredInputCount(2); - setMaximalInputCount(2); -} - -BlendEffect::BlendMode BlendEffect::blendMode() const -{ - return m_blendMode; -} - -void BlendEffect::setBlendMode(BlendMode blendMode) -{ - m_blendMode = blendMode; -} - -QImage BlendEffect::processImage(const QImage &image, const KoFilterEffectRenderContext &context) const -{ - Q_UNUSED(context); - return image; -} - -QImage BlendEffect::processImages(const QList &images, const KoFilterEffectRenderContext &context) const -{ - int imageCount = images.count(); - if (!imageCount) { - return QImage(); - } - - QImage result = images[0]; - if (images.count() != 2) { - return result; - } - const QRgb *src = (const QRgb *)images[1].constBits(); - QRgb *dst = (QRgb *)result.bits(); - int w = result.width(); - - qreal sa, sr, sg, sb; - qreal da, dr, dg, db; - int pixel = 0; - - QRect roi = context.filterRegion().toRect(); - for (int row = roi.top(); row < roi.bottom(); ++row) { - for (int col = roi.left(); col < roi.right(); ++col) { - pixel = row * w + col; - const QRgb &s = src[pixel]; - QRgb &d = dst[pixel]; - - sa = fromIntColor[qAlpha(s)]; - sr = fromIntColor[qRed(s)]; - sg = fromIntColor[qGreen(s)]; - sb = fromIntColor[qBlue(s)]; - - da = fromIntColor[qAlpha(d)]; - dr = fromIntColor[qRed(d)]; - dg = fromIntColor[qGreen(d)]; - db = fromIntColor[qBlue(d)]; - - switch (m_blendMode) { - case Normal: - dr = (qreal(1.0) - da) * sr + dr; - dg = (qreal(1.0) - da) * sg + dg; - db = (qreal(1.0) - da) * sb + db; - break; - case Multiply: - dr = (qreal(1.0) - da) * sr + (qreal(1.0) - sa) * dr + dr * sr; - dg = (qreal(1.0) - da) * sg + (qreal(1.0) - sa) * dg + dg * sg; - db = (qreal(1.0) - da) * sb + (qreal(1.0) - sa) * db + db * sb; - break; - case Screen: - dr = sr + dr - dr * sr; - dg = sg + dg - dg * sg; - db = sb + db - db * sb; - break; - case Darken: - dr = qMin((qreal(1.0) - da) * sr + dr, (qreal(1.0) - sa) * dr + sr); - dg = qMin((qreal(1.0) - da) * sg + dg, (qreal(1.0) - sa) * dg + sg); - db = qMin((qreal(1.0) - da) * sb + db, (qreal(1.0) - sa) * db + sb); - break; - case Lighten: - dr = qMax((qreal(1.0) - da) * sr + dr, (qreal(1.0) - sa) * dr + sr); - dg = qMax((qreal(1.0) - da) * sg + dg, (qreal(1.0) - sa) * dg + sg); - db = qMax((qreal(1.0) - da) * sb + db, (qreal(1.0) - sa) * db + sb); - break; - } - da = qreal(1.0) - (qreal(1.0) - da) * (qreal(1.0) - sa); - - d = qRgba(static_cast(qBound(qreal(0.0), dr * qreal(255.0), qreal(255.0))), - static_cast(qBound(qreal(0.0), dg * qreal(255.0), qreal(255.0))), - static_cast(qBound(qreal(0.0), db * qreal(255.0), qreal(255.0))), - static_cast(qBound(qreal(0.0), da * qreal(255.0), qreal(255.0)))); - } - } - - return result; -} - -bool BlendEffect::load(const KoXmlElement &element, const KoFilterEffectLoadingContext &) -{ - if (element.tagName() != id()) { - return false; - } - - m_blendMode = Normal; // default blend mode - - QString modeStr = element.attribute("mode"); - if (!modeStr.isEmpty()) { - if (modeStr == "multiply") { - m_blendMode = Multiply; - } else if (modeStr == "screen") { - m_blendMode = Screen; - } else if (modeStr == "darken") { - m_blendMode = Darken; - } else if (modeStr == "lighten") { - m_blendMode = Lighten; - } - } - - if (element.hasAttribute("in2")) { - if (inputs().count() == 2) { - setInput(1, element.attribute("in2")); - } else { - addInput(element.attribute("in2")); - } - } - - return true; -} - -void BlendEffect::save(KoXmlWriter &writer) -{ - writer.startElement(BlendEffectId); - - saveCommonAttributes(writer); - - switch (m_blendMode) { - case Normal: - writer.addAttribute("mode", "normal"); - break; - case Multiply: - writer.addAttribute("mode", "multiply"); - break; - case Screen: - writer.addAttribute("mode", "screen"); - break; - case Darken: - writer.addAttribute("mode", "darken"); - break; - case Lighten: - writer.addAttribute("mode", "lighten"); - break; - } - - writer.addAttribute("in2", inputs().at(1)); - - writer.endElement(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/BlendEffect.h b/plugins/tools/karbonplugins/filtereffects/BlendEffect.h deleted file mode 100644 index 272133e200..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/BlendEffect.h +++ /dev/null @@ -1,61 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 BLENDEFFECT_H -#define BLENDEFFECT_H - -#include "KoFilterEffect.h" - -#define BlendEffectId "feBlend" - -/// A color matrix effect -class BlendEffect : public KoFilterEffect -{ -public: - enum BlendMode { - Normal, - Multiply, - Screen, - Darken, - Lighten - }; - - BlendEffect(); - - /// Returns the type of the color matrix - BlendMode blendMode() const; - - /// Sets the blend mode - void setBlendMode(BlendMode blendMode); - - /// reimplemented from KoFilterEffect - QImage processImage(const QImage &image, const KoFilterEffectRenderContext &context) const override; - /// reimplemented from KoFilterEffect - QImage processImages(const QList &images, const KoFilterEffectRenderContext &context) const override; - /// reimplemented from KoFilterEffect - bool load(const KoXmlElement &element, const KoFilterEffectLoadingContext &context) override; - /// reimplemented from KoFilterEffect - void save(KoXmlWriter &writer) override; - -private: - - BlendMode m_blendMode; ///< the blend mode -}; - -#endif // BLENDEFFECT_H diff --git a/plugins/tools/karbonplugins/filtereffects/BlendEffectConfigWidget.cpp b/plugins/tools/karbonplugins/filtereffects/BlendEffectConfigWidget.cpp deleted file mode 100644 index b0821bfc14..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/BlendEffectConfigWidget.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "BlendEffectConfigWidget.h" -#include "BlendEffect.h" -#include "KoFilterEffect.h" - -#include -#include - -#include -#include - -BlendEffectConfigWidget::BlendEffectConfigWidget(QWidget *parent) - : KoFilterEffectConfigWidgetBase(parent) - , m_effect(0) -{ - QGridLayout *g = new QGridLayout(this); - - g->addWidget(new QLabel(i18n("Blend mode"), this), 0, 0); - m_mode = new KComboBox(this); - m_mode->addItem(i18n("Normal")); - m_mode->addItem(i18n("Multiply")); - m_mode->addItem(i18n("Screen")); - m_mode->addItem(i18n("Darken")); - m_mode->addItem(i18n("Lighten")); - g->addWidget(m_mode, 0, 1); - g->addItem(new QSpacerItem(0, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 1, 0); - - setLayout(g); - - connect(m_mode, SIGNAL(currentIndexChanged(int)), this, SLOT(modeChanged(int))); -} - -bool BlendEffectConfigWidget::editFilterEffect(KoFilterEffect *filterEffect) -{ - m_effect = dynamic_cast(filterEffect); - if (!m_effect) { - return false; - } - - m_mode->blockSignals(true); - - switch (m_effect->blendMode()) { - case BlendEffect::Normal: - m_mode->setCurrentIndex(0); - break; - case BlendEffect::Multiply: - m_mode->setCurrentIndex(1); - break; - case BlendEffect::Screen: - m_mode->setCurrentIndex(2); - break; - case BlendEffect::Darken: - m_mode->setCurrentIndex(3); - break; - case BlendEffect::Lighten: - m_mode->setCurrentIndex(4); - break; - } - - m_mode->blockSignals(false); - - return true; -} - -void BlendEffectConfigWidget::modeChanged(int index) -{ - if (!m_effect) { - return; - } - - m_effect->setBlendMode(static_cast(index)); - - emit filterChanged(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/BlendEffectConfigWidget.h b/plugins/tools/karbonplugins/filtereffects/BlendEffectConfigWidget.h deleted file mode 100644 index d92753cba0..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/BlendEffectConfigWidget.h +++ /dev/null @@ -1,45 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 BLENDEFFECTCONFIGWIDGET_H -#define BLENDEFFECTCONFIGWIDGET_H - -#include "KoFilterEffectConfigWidgetBase.h" - -class BlendEffect; -class KoFilterEffect; -class KComboBox; - -class BlendEffectConfigWidget : public KoFilterEffectConfigWidgetBase -{ - Q_OBJECT -public: - explicit BlendEffectConfigWidget(QWidget *parent = 0); - - /// reimplemented from KoFilterEffectConfigWidgetBase - bool editFilterEffect(KoFilterEffect *filterEffect) override; - -private Q_SLOTS: - void modeChanged(int index); -private: - KComboBox *m_mode; - BlendEffect *m_effect; -}; - -#endif // BLENDEFFECTCONFIGWIDGET_H diff --git a/plugins/tools/karbonplugins/filtereffects/BlendEffectFactory.cpp b/plugins/tools/karbonplugins/filtereffects/BlendEffectFactory.cpp deleted file mode 100644 index bb0259087f..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/BlendEffectFactory.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "BlendEffectFactory.h" -#include "BlendEffect.h" -#include "BlendEffectConfigWidget.h" - -#include - -BlendEffectFactory::BlendEffectFactory() - : KoFilterEffectFactoryBase(BlendEffectId, i18n("Blend")) -{ -} - -KoFilterEffect *BlendEffectFactory::createFilterEffect() const -{ - return new BlendEffect(); -} - -KoFilterEffectConfigWidgetBase *BlendEffectFactory::createConfigWidget() const -{ - return new BlendEffectConfigWidget(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/BlendEffectFactory.h b/plugins/tools/karbonplugins/filtereffects/BlendEffectFactory.h deleted file mode 100644 index 9d300a9d1f..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/BlendEffectFactory.h +++ /dev/null @@ -1,35 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 BLENDEFFECTFACTORY_H -#define BLENDEFFECTFACTORY_H - -#include "KoFilterEffectFactoryBase.h" - -class KoFilterEffect; - -class BlendEffectFactory : public KoFilterEffectFactoryBase -{ -public: - BlendEffectFactory(); - KoFilterEffect *createFilterEffect() const override; - KoFilterEffectConfigWidgetBase *createConfigWidget() const override; -}; - -#endif // BLENDEFFECTFACTORY_H diff --git a/plugins/tools/karbonplugins/filtereffects/BlurEffect.cpp b/plugins/tools/karbonplugins/filtereffects/BlurEffect.cpp deleted file mode 100644 index 9f1b9918a0..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/BlurEffect.cpp +++ /dev/null @@ -1,350 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "BlurEffect.h" -#include "KoFilterEffectRenderContext.h" -#include "KoFilterEffectLoadingContext.h" -#include "KoViewConverter.h" -#include "KoXmlWriter.h" -#include "KoXmlReader.h" -#include -#include -#include - -// Stack Blur Algorithm by Mario Klingemann -// fixed to handle alpha channel correctly by Zack Rusin -void fastbluralpha(QImage &img, int radius) -{ - if (radius < 1) { - return; - } - - QRgb *pix = (QRgb *)img.bits(); - int w = img.width(); - int h = img.height(); - int wm = w - 1; - int hm = h - 1; - int wh = w * h; - int div = radius + radius + 1; - - int *r = new int[wh]; - int *g = new int[wh]; - int *b = new int[wh]; - int *a = new int[wh]; - int rsum, gsum, bsum, asum, x, y, i, yp, yi, yw; - QRgb p; - int *vmin = new int[qMax(w, h)]; - - int divsum = (div + 1) >> 1; - divsum *= divsum; - int *dv = new int[256 * divsum]; - for (i = 0; i < 256 * divsum; ++i) { - dv[i] = (i / divsum); - } - - yw = yi = 0; - - int **stack = new int *[div]; - for (int i = 0; i < div; ++i) { - stack[i] = new int[4]; - } - - int stackpointer; - int stackstart; - int *sir; - int rbs; - int r1 = radius + 1; - int routsum, goutsum, boutsum, aoutsum; - int rinsum, ginsum, binsum, ainsum; - - for (y = 0; y < h; ++y) { - rinsum = ginsum = binsum = ainsum - = routsum = goutsum = boutsum = aoutsum - = rsum = gsum = bsum = asum = 0; - for (i = - radius; i <= radius; ++i) { - p = pix[yi + qMin(wm, qMax(i, 0))]; - sir = stack[i + radius]; - sir[0] = qRed(p); - sir[1] = qGreen(p); - sir[2] = qBlue(p); - sir[3] = qAlpha(p); - - rbs = r1 - abs(i); - rsum += sir[0] * rbs; - gsum += sir[1] * rbs; - bsum += sir[2] * rbs; - asum += sir[3] * rbs; - - if (i > 0) { - rinsum += sir[0]; - ginsum += sir[1]; - binsum += sir[2]; - ainsum += sir[3]; - } else { - routsum += sir[0]; - goutsum += sir[1]; - boutsum += sir[2]; - aoutsum += sir[3]; - } - } - stackpointer = radius; - - for (x = 0; x < w; ++x) { - - r[yi] = dv[rsum]; - g[yi] = dv[gsum]; - b[yi] = dv[bsum]; - a[yi] = dv[asum]; - - rsum -= routsum; - gsum -= goutsum; - bsum -= boutsum; - asum -= aoutsum; - - stackstart = stackpointer - radius + div; - sir = stack[stackstart % div]; - - routsum -= sir[0]; - goutsum -= sir[1]; - boutsum -= sir[2]; - aoutsum -= sir[3]; - - if (y == 0) { - vmin[x] = qMin(x + radius + 1, wm); - } - p = pix[yw + vmin[x]]; - - sir[0] = qRed(p); - sir[1] = qGreen(p); - sir[2] = qBlue(p); - sir[3] = qAlpha(p); - - rinsum += sir[0]; - ginsum += sir[1]; - binsum += sir[2]; - ainsum += sir[3]; - - rsum += rinsum; - gsum += ginsum; - bsum += binsum; - asum += ainsum; - - stackpointer = (stackpointer + 1) % div; - sir = stack[(stackpointer) % div]; - - routsum += sir[0]; - goutsum += sir[1]; - boutsum += sir[2]; - aoutsum += sir[3]; - - rinsum -= sir[0]; - ginsum -= sir[1]; - binsum -= sir[2]; - ainsum -= sir[3]; - - ++yi; - } - yw += w; - } - for (x = 0; x < w; ++x) { - rinsum = ginsum = binsum = ainsum - = routsum = goutsum = boutsum = aoutsum - = rsum = gsum = bsum = asum = 0; - - yp = - radius * w; - - for (i = -radius; i <= radius; ++i) { - yi = qMax(0, yp) + x; - - sir = stack[i + radius]; - - sir[0] = r[yi]; - sir[1] = g[yi]; - sir[2] = b[yi]; - sir[3] = a[yi]; - - rbs = r1 - abs(i); - - rsum += r[yi] * rbs; - gsum += g[yi] * rbs; - bsum += b[yi] * rbs; - asum += a[yi] * rbs; - - if (i > 0) { - rinsum += sir[0]; - ginsum += sir[1]; - binsum += sir[2]; - ainsum += sir[3]; - } else { - routsum += sir[0]; - goutsum += sir[1]; - boutsum += sir[2]; - aoutsum += sir[3]; - } - - if (i < hm) { - yp += w; - } - } - - yi = x; - stackpointer = radius; - - for (y = 0; y < h; ++y) { - pix[yi] = qRgba(dv[rsum], dv[gsum], dv[bsum], dv[asum]); - - rsum -= routsum; - gsum -= goutsum; - bsum -= boutsum; - asum -= aoutsum; - - stackstart = stackpointer - radius + div; - sir = stack[stackstart % div]; - - routsum -= sir[0]; - goutsum -= sir[1]; - boutsum -= sir[2]; - aoutsum -= sir[3]; - - if (x == 0) { - vmin[y] = qMin(y + r1, hm) * w; - } - p = x + vmin[y]; - - sir[0] = r[p]; - sir[1] = g[p]; - sir[2] = b[p]; - sir[3] = a[p]; - - rinsum += sir[0]; - ginsum += sir[1]; - binsum += sir[2]; - ainsum += sir[3]; - - rsum += rinsum; - gsum += ginsum; - bsum += binsum; - asum += ainsum; - - stackpointer = (stackpointer + 1) % div; - sir = stack[stackpointer]; - - routsum += sir[0]; - goutsum += sir[1]; - boutsum += sir[2]; - aoutsum += sir[3]; - - rinsum -= sir[0]; - ginsum -= sir[1]; - binsum -= sir[2]; - ainsum -= sir[3]; - - yi += w; - } - } - delete [] r; - delete [] g; - delete [] b; - delete [] a; - delete [] vmin; - delete [] dv; - - for (int i = 0; i < div; ++i) { - delete [] stack[i]; - } - delete [] stack; -} - -BlurEffect::BlurEffect() - : KoFilterEffect(BlurEffectId, i18n("Gaussian blur")) - , m_deviation(0, 0) -{ -} - -QPointF BlurEffect::deviation() const -{ - return m_deviation; -} - -void BlurEffect::setDeviation(const QPointF &deviation) -{ - m_deviation.setX(qMax(qreal(0.0), deviation.x())); - m_deviation.setY(qMax(qreal(0.0), deviation.y())); -} - -QImage BlurEffect::processImage(const QImage &image, const KoFilterEffectRenderContext &context) const -{ - if (m_deviation.x() == 0.0 || m_deviation.y() == 0.0) { - return image; - } - - // TODO: take filter region into account - // TODO: blur with different kernels in x and y - // convert from bounding box coordinates - QPointF dev = context.toUserSpace(m_deviation); - // transform to view coordinates - dev = context.viewConverter()->documentToView(dev); - - QImage result = image; - fastbluralpha(result, dev.x()); - - return result; -} - -bool BlurEffect::load(const KoXmlElement &element, const KoFilterEffectLoadingContext &context) -{ - if (element.tagName() != id()) { - return false; - } - - QString deviationStr = element.attribute("stdDeviation"); - QStringList params = deviationStr.replace(',', ' ').simplified().split(' '); - - switch (params.count()) { - case 1: - m_deviation.rx() = params[0].toDouble(); - m_deviation.ry() = m_deviation.x(); - break; - case 2: - m_deviation.rx() = params[0].toDouble(); - m_deviation.ry() = params[1].toDouble(); - break; - default: - return false; - } - - m_deviation = context.convertFilterPrimitiveUnits(m_deviation); - - return true; -} - -void BlurEffect::save(KoXmlWriter &writer) -{ - writer.startElement(BlurEffectId); - - saveCommonAttributes(writer); - - if (m_deviation.x() != m_deviation.y()) { - writer.addAttribute("stdDeviation", QString("%1, %2").arg(m_deviation.x()).arg(m_deviation.y())); - } else { - writer.addAttribute("stdDeviation", m_deviation.x()); - } - - writer.endElement(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/BlurEffect.h b/plugins/tools/karbonplugins/filtereffects/BlurEffect.h deleted file mode 100644 index 076ea74dbc..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/BlurEffect.h +++ /dev/null @@ -1,48 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 BLUREFFECT_H -#define BLUREFFECT_H - -#include "KoFilterEffect.h" -#include - -#define BlurEffectId "feGaussianBlur" - -/// A gaussian blur effect -class BlurEffect : public KoFilterEffect -{ -public: - BlurEffect(); - - QPointF deviation() const; - void setDeviation(const QPointF &deviation); - - /// reimplemented from KoFilterEffect - QImage processImage(const QImage &image, const KoFilterEffectRenderContext &context) const override; - /// reimplemented from KoFilterEffect - bool load(const KoXmlElement &element, const KoFilterEffectLoadingContext &context) override; - /// reimplemented from KoFilterEffect - void save(KoXmlWriter &writer) override; - -private: - QPointF m_deviation; -}; - -#endif // BLUREFFECT_H diff --git a/plugins/tools/karbonplugins/filtereffects/BlurEffectConfigWidget.cpp b/plugins/tools/karbonplugins/filtereffects/BlurEffectConfigWidget.cpp deleted file mode 100644 index 85b57cdba5..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/BlurEffectConfigWidget.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "BlurEffectConfigWidget.h" -#include "BlurEffect.h" -#include "KoFilterEffect.h" - -#include -#include - -#include -#include - -#include "kis_double_parse_spin_box.h" - -BlurEffectConfigWidget::BlurEffectConfigWidget(QWidget *parent) - : KoFilterEffectConfigWidgetBase(parent), m_effect(0) -{ - QGridLayout *g = new QGridLayout(this); - - g->addWidget(new QLabel(i18n("Radius"), this), 0, 0); - m_stdDeviation = new KisDoubleParseSpinBox(this); - m_stdDeviation->setRange(0.0, 100); - m_stdDeviation->setSingleStep(0.5); - g->addWidget(m_stdDeviation, 0, 1); - setLayout(g); - - connect(m_stdDeviation, SIGNAL(valueChanged(double)), this, SLOT(stdDeviationChanged(double))); -} - -bool BlurEffectConfigWidget::editFilterEffect(KoFilterEffect *filterEffect) -{ - m_effect = dynamic_cast(filterEffect); - if (!m_effect) { - return false; - } - - m_stdDeviation->setValue(m_effect->deviation().x() * 100.0); - return true; -} - -void BlurEffectConfigWidget::stdDeviationChanged(double stdDeviation) -{ - if (!m_effect) { - return; - } - - qreal newDev = 0.01 * stdDeviation; - m_effect->setDeviation(QPointF(newDev, newDev)); - emit filterChanged(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/BlurEffectConfigWidget.h b/plugins/tools/karbonplugins/filtereffects/BlurEffectConfigWidget.h deleted file mode 100644 index 9543fbac0c..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/BlurEffectConfigWidget.h +++ /dev/null @@ -1,46 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 BLUREFFECTCONFIGWIDGET_H -#define BLUREFFECTCONFIGWIDGET_H - -#include "KoFilterEffectConfigWidgetBase.h" - -class KoFilterEffect; -class BlurEffect; -class QDoubleSpinBox; - -class BlurEffectConfigWidget : public KoFilterEffectConfigWidgetBase -{ - Q_OBJECT -public: - explicit BlurEffectConfigWidget(QWidget *parent = 0); - - /// reimplemented from KoFilterEffectConfigWidgetBase - bool editFilterEffect(KoFilterEffect *filterEffect) override; - -private Q_SLOTS: - void stdDeviationChanged(double stdDeviation); - -private: - BlurEffect *m_effect; - QDoubleSpinBox *m_stdDeviation; -}; - -#endif // BLUREFFECTCONFIGWIDGET_H diff --git a/plugins/tools/karbonplugins/filtereffects/BlurEffectFactory.cpp b/plugins/tools/karbonplugins/filtereffects/BlurEffectFactory.cpp deleted file mode 100644 index 4d7046308a..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/BlurEffectFactory.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "BlurEffectFactory.h" -#include "BlurEffect.h" -#include "BlurEffectConfigWidget.h" - -#include - -BlurEffectFactory::BlurEffectFactory() - : KoFilterEffectFactoryBase(BlurEffectId, i18n("Gaussian blur")) -{ -} - -KoFilterEffect *BlurEffectFactory::createFilterEffect() const -{ - return new BlurEffect(); -} - -KoFilterEffectConfigWidgetBase *BlurEffectFactory::createConfigWidget() const -{ - return new BlurEffectConfigWidget(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/BlurEffectFactory.h b/plugins/tools/karbonplugins/filtereffects/BlurEffectFactory.h deleted file mode 100644 index a932495b7c..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/BlurEffectFactory.h +++ /dev/null @@ -1,35 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 BLUREFFECTFACTORY_H -#define BLUREFFECTFACTORY_H - -#include "KoFilterEffectFactoryBase.h" - -class KoFilterEffect; - -class BlurEffectFactory : public KoFilterEffectFactoryBase -{ -public: - BlurEffectFactory(); - KoFilterEffect *createFilterEffect() const override; - KoFilterEffectConfigWidgetBase *createConfigWidget() const override; -}; - -#endif // BLUREFFECTFACTORY_H diff --git a/plugins/tools/karbonplugins/filtereffects/CMakeLists.txt b/plugins/tools/karbonplugins/filtereffects/CMakeLists.txt deleted file mode 100644 index 10e9997ab5..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/CMakeLists.txt +++ /dev/null @@ -1,43 +0,0 @@ -set(karbon_filtereffects_SOURCES - FilterEffectsPlugin.cpp - BlurEffect.cpp - BlurEffectFactory.cpp - BlurEffectConfigWidget.cpp - OffsetEffect.cpp - OffsetEffectFactory.cpp - OffsetEffectConfigWidget.cpp - MergeEffect.cpp - MergeEffectFactory.cpp - MergeEffectConfigWidget.cpp - ColorMatrixEffect.cpp - ColorMatrixEffectFactory.cpp - ColorMatrixEffectConfigWidget.cpp - FloodEffect.cpp - FloodEffectFactory.cpp - FloodEffectConfigWidget.cpp - CompositeEffect.cpp - CompositeEffectFactory.cpp - CompositeEffectConfigWidget.cpp - BlendEffect.cpp - BlendEffectFactory.cpp - BlendEffectConfigWidget.cpp - ComponentTransferEffect.cpp - ComponentTransferEffectFactory.cpp - ComponentTransferEffectConfigWidget.cpp - ImageEffect.cpp - ImageEffectFactory.cpp - ImageEffectConfigWidget.cpp - MorphologyEffect.cpp - MorphologyEffectFactory.cpp - MorphologyEffectConfigWidget.cpp - ConvolveMatrixEffect.cpp - ConvolveMatrixEffectFactory.cpp - ConvolveMatrixEffectConfigWidget.cpp - MatrixDataModel.cpp - ) - -add_library(krita_filtereffects MODULE ${karbon_filtereffects_SOURCES}) - -target_link_libraries(krita_filtereffects kritaflake kritawidgets kritaui KF5::Completion) - -install(TARGETS krita_filtereffects DESTINATION ${KRITA_PLUGIN_INSTALL_DIR}) diff --git a/plugins/tools/karbonplugins/filtereffects/ColorChannelConversion.h b/plugins/tools/karbonplugins/filtereffects/ColorChannelConversion.h deleted file mode 100644 index 66a10f0959..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ColorChannelConversion.h +++ /dev/null @@ -1,61 +0,0 @@ -/* This file is part of the KDE project -* Copyright (c) 2010 Jan Hambrecht -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU Lesser General Public -* License as published by the Free Software Foundation; either -* version 2.1 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 Lesser 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 COLORCHANNELCONVERSION_H -#define COLORCHANNELCONVERSION_H - -/** -* Lookup table to convert color value from int [0..255] to double [0..1] -*/ -static const qreal fromIntColor[256] = { - 0.00000000000000000, 0.00392156862745098, 0.007843137254901961, 0.01176470588235294, 0.01568627450980392, 0.0196078431372549, 0.02352941176470588, 0.02745098039215686, 0.03137254901960784, - 0.03529411764705882, 0.0392156862745098, 0.04313725490196078, 0.04705882352941176, 0.05098039215686274, 0.05490196078431372, 0.05882352941176471, 0.06274509803921569, - 0.06666666666666667, 0.07058823529411765, 0.07450980392156863, 0.07843137254901961, 0.08235294117647059, 0.08627450980392157, 0.09019607843137255, 0.09411764705882353, - 0.09803921568627451, 0.1019607843137255, 0.1058823529411765, 0.1098039215686274, 0.1137254901960784, 0.1176470588235294, 0.1215686274509804, 0.1254901960784314, - 0.1294117647058824, 0.1333333333333333, 0.1372549019607843, 0.1411764705882353, 0.1450980392156863, 0.1490196078431373, 0.1529411764705882, 0.1568627450980392, - 0.1607843137254902, 0.1647058823529412, 0.1686274509803922, 0.1725490196078431, 0.1764705882352941, 0.1803921568627451, 0.1843137254901961, 0.1882352941176471, - 0.1921568627450981, 0.196078431372549, 0.2, 0.203921568627451, 0.207843137254902, 0.2117647058823529, 0.2156862745098039, 0.2196078431372549, - 0.2235294117647059, 0.2274509803921569, 0.2313725490196079, 0.2352941176470588, 0.2392156862745098, 0.2431372549019608, 0.2470588235294118, 0.2509803921568627, - 0.2549019607843137, 0.2588235294117647, 0.2627450980392157, 0.2666666666666667, 0.2705882352941176, 0.2745098039215687, 0.2784313725490196, 0.2823529411764706, - 0.2862745098039216, 0.2901960784313726, 0.2941176470588235, 0.2980392156862745, 0.3019607843137255, 0.3058823529411765, 0.3098039215686275, 0.3137254901960784, - 0.3176470588235294, 0.3215686274509804, 0.3254901960784314, 0.3294117647058823, 0.3333333333333333, 0.3372549019607843, 0.3411764705882353, 0.3450980392156863, - 0.3490196078431372, 0.3529411764705883, 0.3568627450980392, 0.3607843137254902, 0.3647058823529412, 0.3686274509803922, 0.3725490196078431, 0.3764705882352941, - 0.3803921568627451, 0.3843137254901961, 0.3882352941176471, 0.392156862745098, 0.396078431372549, 0.4, 0.403921568627451, 0.407843137254902, - 0.4117647058823529, 0.4156862745098039, 0.4196078431372549, 0.4235294117647059, 0.4274509803921568, 0.4313725490196079, 0.4352941176470588, 0.4392156862745098, - 0.4431372549019608, 0.4470588235294118, 0.4509803921568628, 0.4549019607843137, 0.4588235294117647, 0.4627450980392157, 0.4666666666666667, 0.4705882352941176, - 0.4745098039215686, 0.4784313725490196, 0.4823529411764706, 0.4862745098039216, 0.4901960784313725, 0.4941176470588236, 0.4980392156862745, 0.5019607843137255, - 0.5058823529411764, 0.5098039215686274, 0.5137254901960784, 0.5176470588235295, 0.5215686274509804, 0.5254901960784314, 0.5294117647058824, 0.5333333333333333, - 0.5372549019607843, 0.5411764705882353, 0.5450980392156862, 0.5490196078431373, 0.5529411764705883, 0.5568627450980392, 0.5607843137254902, 0.5647058823529412, - 0.5686274509803921, 0.5725490196078431, 0.5764705882352941, 0.5803921568627451, 0.5843137254901961, 0.5882352941176471, 0.592156862745098, 0.596078431372549, - 0.6000000000000000, 0.6039215686274509, 0.6078431372549019, 0.611764705882353, 0.615686274509804, 0.6196078431372549, 0.6235294117647059, 0.6274509803921569, - 0.6313725490196078, 0.6352941176470588, 0.6392156862745098, 0.6431372549019608, 0.6470588235294118, 0.6509803921568628, 0.6549019607843137, 0.6588235294117647, - 0.6627450980392157, 0.6666666666666666, 0.6705882352941176, 0.6745098039215687, 0.6784313725490196, 0.6823529411764706, 0.6862745098039216, 0.6901960784313725, - 0.6941176470588235, 0.6980392156862745, 0.7019607843137254, 0.7058823529411765, 0.7098039215686275, 0.7137254901960784, 0.7176470588235294, 0.7215686274509804, - 0.7254901960784313, 0.7294117647058823, 0.7333333333333333, 0.7372549019607844, 0.7411764705882353, 0.7450980392156863, 0.7490196078431373, 0.7529411764705882, - 0.7568627450980392, 0.7607843137254902, 0.7647058823529411, 0.7686274509803922, 0.7725490196078432, 0.7764705882352941, 0.7803921568627451, 0.7843137254901961, - 0.788235294117647, 0.792156862745098, 0.796078431372549, 0.8, 0.803921568627451, 0.807843137254902, 0.8117647058823529, 0.8156862745098039, - 0.8196078431372549, 0.8235294117647058, 0.8274509803921568, 0.8313725490196079, 0.8352941176470589, 0.8392156862745098, 0.8431372549019608, 0.8470588235294118, - 0.8509803921568627, 0.8549019607843137, 0.8588235294117647, 0.8627450980392157, 0.8666666666666667, 0.8705882352941177, 0.8745098039215686, 0.8784313725490196, - 0.8823529411764706, 0.8862745098039215, 0.8901960784313725, 0.8941176470588236, 0.8980392156862745, 0.9019607843137255, 0.9058823529411765, 0.9098039215686274, - 0.9137254901960784, 0.9176470588235294, 0.9215686274509803, 0.9254901960784314, 0.9294117647058824, 0.9333333333333333, 0.9372549019607843, 0.9411764705882353, - 0.9450980392156862, 0.9490196078431372, 0.9529411764705882, 0.9568627450980393, 0.9607843137254902, 0.9647058823529412, 0.9686274509803922, 0.9725490196078431, - 0.9764705882352941, 0.9803921568627451, 0.984313725490196, 0.9882352941176471, 0.9921568627450981, 0.996078431372549, 1 -}; - -#endif // COLORCHANNELCONVERSION_H diff --git a/plugins/tools/karbonplugins/filtereffects/ColorMatrixEffect.cpp b/plugins/tools/karbonplugins/filtereffects/ColorMatrixEffect.cpp deleted file mode 100644 index 06ea096b45..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ColorMatrixEffect.cpp +++ /dev/null @@ -1,280 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "ColorMatrixEffect.h" -#include "ColorChannelConversion.h" -#include -#include -#include -#include -#include -#include -#include - -const int MatrixSize = 20; -const int MatrixRows = 4; -const int MatrixCols = 5; - -ColorMatrixEffect::ColorMatrixEffect() - : KoFilterEffect(ColorMatrixEffectId, i18n("Color Matrix")) - , m_type(Matrix) -{ - setIdentity(); -} - -void ColorMatrixEffect::setIdentity() -{ - // set identity matrix - m_matrix.resize(MatrixSize); - for (int r = 0; r < MatrixRows; ++r) { - for (int c = 0; c < MatrixCols; ++c) { - m_matrix[r * MatrixCols + c] = r == c ? 1.0 : 0.0; - } - } -} - -ColorMatrixEffect::Type ColorMatrixEffect::type() const -{ - return m_type; -} - -int ColorMatrixEffect::colorMatrixSize() -{ - return MatrixSize; -} - -int ColorMatrixEffect::colorMatrixRowCount() -{ - return MatrixRows; -} - -int ColorMatrixEffect::colorMatrixColumnCount() -{ - return MatrixCols; -} - -QVector ColorMatrixEffect::colorMatrix() const -{ - return m_matrix; -} - -void ColorMatrixEffect::setColorMatrix(const QVector &colorMatrix) -{ - if (colorMatrix.count() == MatrixSize) { - m_matrix = colorMatrix; - } - m_type = Matrix; -} - -void ColorMatrixEffect::setSaturate(qreal value) -{ - m_type = Saturate; - m_value = qBound(qreal(0.0), value, qreal(1.0)); - - setIdentity(); - - m_matrix[0] = 0.213 + 0.787 * value; - m_matrix[1] = 0.715 - 0.715 * value; - m_matrix[2] = 0.072 - 0.072 * value; - - m_matrix[5] = 0.213 - 0.213 * value; - m_matrix[6] = 0.715 + 0.285 * value; - m_matrix[7] = 0.072 - 0.072 * value; - - m_matrix[10] = 0.213 - 0.213 * value; - m_matrix[11] = 0.715 - 0.715 * value; - m_matrix[12] = 0.072 + 0.928 * value; -} - -qreal ColorMatrixEffect::saturate() const -{ - if (m_type == Saturate) { - return m_value; - } else { - return 1.0; - } -} - -void ColorMatrixEffect::setHueRotate(qreal value) -{ - m_type = HueRotate; - m_value = value; - - const qreal rad = m_value * M_PI / 180.0; - const qreal c = cos(rad); - const qreal s = sin(rad); - - setIdentity(); - - m_matrix[0] = 0.213 + 0.787 * c - 0.213 * s; - m_matrix[1] = 0.715 - 0.715 * c - 0.715 * s; - m_matrix[2] = 0.072 - 0.072 * c + 0.928 * s; - - m_matrix[5] = 0.213 - 0.213 * c + 0.143 * s; - m_matrix[6] = 0.715 + 0.285 * c + 0.140 * s; - m_matrix[7] = 0.072 - 0.072 * c - 0.283 * s; - - m_matrix[10] = 0.213 - 0.213 * c - 0.787 * s; - m_matrix[11] = 0.715 - 0.715 * c + 0.715 * s; - m_matrix[12] = 0.072 + 0.928 * c + 0.072 * s; -} - -qreal ColorMatrixEffect::hueRotate() const -{ - if (m_type == HueRotate) { - return m_value; - } else { - return 0.0; - } -} - -void ColorMatrixEffect::setLuminanceAlpha() -{ - m_type = LuminanceAlpha; - - memset(m_matrix.data(), 0, MatrixSize * sizeof(qreal)); - - m_matrix[15] = 0.2125; - m_matrix[16] = 0.7154; - m_matrix[17] = 0.0721; - m_matrix[18] = 0.0; -} - -QImage ColorMatrixEffect::processImage(const QImage &image, const KoFilterEffectRenderContext &context) const -{ - QImage result = image; - - const QRgb *src = (const QRgb *)image.constBits(); - QRgb *dst = (QRgb *)result.bits(); - int w = result.width(); - - const qreal *m = m_matrix.data(); - qreal sa, sr, sg, sb; - qreal da, dr, dg, db; - - QRect roi = context.filterRegion().toRect(); - for (int row = roi.top(); row < roi.bottom(); ++row) { - for (int col = roi.left(); col < roi.right(); ++col) { - const QRgb &s = src[row * w + col]; - sa = fromIntColor[qAlpha(s)]; - sr = fromIntColor[qRed(s)]; - sg = fromIntColor[qGreen(s)]; - sb = fromIntColor[qBlue(s)]; - // the matrix is applied to non-premultiplied color values - // so we have to convert colors by dividing by alpha value - if (sa > 0.0 && sa < 1.0) { - sr /= sa; - sb /= sa; - sg /= sa; - } - - // apply matrix to color values - dr = m[ 0] * sr + m[ 1] * sg + m[ 2] * sb + m[ 3] * sa + m[ 4]; - dg = m[ 5] * sr + m[ 6] * sg + m[ 7] * sb + m[ 8] * sa + m[ 9]; - db = m[10] * sr + m[11] * sg + m[12] * sb + m[13] * sa + m[14]; - da = m[15] * sr + m[16] * sg + m[17] * sb + m[18] * sa + m[19]; - - // the new alpha value - da *= 255.0; - - // set pre-multiplied color values on destination image - dst[row * w + col] = qRgba(static_cast(qBound(qreal(0.0), dr * da, qreal(255.0))), - static_cast(qBound(qreal(0.0), dg * da, qreal(255.0))), - static_cast(qBound(qreal(0.0), db * da, qreal(255.0))), - static_cast(qBound(qreal(0.0), da, qreal(255.0)))); - } - } - - return result; -} - -bool ColorMatrixEffect::load(const KoXmlElement &element, const KoFilterEffectLoadingContext &) -{ - if (element.tagName() != id()) { - return false; - } - - QString typeStr = element.attribute("type"); - if (typeStr.isEmpty()) { - return false; - } - - QString valueStr = element.attribute("values"); - - setIdentity(); - m_type = Matrix; - - if (typeStr == "matrix") { - // values are separated by whitespace and/or comma - QStringList values = valueStr.trimmed().split(QRegExp("(\\s+|,)"), QString::SkipEmptyParts); - if (values.count() == MatrixSize) { - for (int i = 0; i < MatrixSize; ++i) { - m_matrix[i] = values[i].toDouble(); - } - } - } else if (typeStr == "saturate") { - if (!valueStr.isEmpty()) { - setSaturate(valueStr.toDouble()); - } - } else if (typeStr == "hueRotate") { - if (!valueStr.isEmpty()) { - setHueRotate(valueStr.toDouble()); - } - } else if (typeStr == "luminanceToAlpha") { - setLuminanceAlpha(); - } else { - return false; - } - - return true; -} - -void ColorMatrixEffect::save(KoXmlWriter &writer) -{ - writer.startElement(ColorMatrixEffectId); - - saveCommonAttributes(writer); - - switch (m_type) { - case Matrix: { - writer.addAttribute("type", "matrix"); - QString matrix; - for (int r = 0; r < MatrixRows; ++r) { - for (int c = 0; c < MatrixCols; ++c) { - matrix += QString("%1 ").arg(m_matrix[r * MatrixCols + c]); - } - } - writer.addAttribute("values", matrix); - } - break; - case Saturate: - writer.addAttribute("type", "saturate"); - writer.addAttribute("values", QString("%1").arg(m_value)); - break; - case HueRotate: - writer.addAttribute("type", "hueRotate"); - writer.addAttribute("values", QString("%1").arg(m_value)); - break; - case LuminanceAlpha: - writer.addAttribute("type", "luminanceToAlpha"); - break; - } - - writer.endElement(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/ColorMatrixEffect.h b/plugins/tools/karbonplugins/filtereffects/ColorMatrixEffect.h deleted file mode 100644 index e2e2124411..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ColorMatrixEffect.h +++ /dev/null @@ -1,89 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 COLORMATRIXEFFECT_H -#define COLORMATRIXEFFECT_H - -#include "KoFilterEffect.h" -#include - -#define ColorMatrixEffectId "feColorMatrix" - -/// A color matrix effect -class ColorMatrixEffect : public KoFilterEffect -{ -public: - enum Type { - Matrix, - Saturate, - HueRotate, - LuminanceAlpha - }; - - ColorMatrixEffect(); - - /// Returns the type of the color matrix - Type type() const; - - /// Returns the size of the color matrix - static int colorMatrixSize(); - - /// Returns the row count of the color matrix - static int colorMatrixRowCount(); - - /// Returns the column count of the color matrix - static int colorMatrixColumnCount(); - - QVector colorMatrix() const; - - /// Sets a color matrix and changes type to Matrix - void setColorMatrix(const QVector &matrix); - - /// Sets a saturate value and changes type to Saturate - void setSaturate(qreal value); - - /// Returns the saturate value if type == Saturate - qreal saturate() const; - - /// Sets a hue rotate value and changes type to HueRotate - void setHueRotate(qreal value); - - /// Returns the saturate value if type == HueRotate - qreal hueRotate() const; - - /// Sets luminance alpha an changes type to LuminanceAlpha - void setLuminanceAlpha(); - - /// reimplemented from KoFilterEffect - QImage processImage(const QImage &image, const KoFilterEffectRenderContext &context) const override; - /// reimplemented from KoFilterEffect - bool load(const KoXmlElement &element, const KoFilterEffectLoadingContext &context) override; - /// reimplemented from KoFilterEffect - void save(KoXmlWriter &writer) override; - -private: - /// sets color matrix to identity matrix - void setIdentity(); - - Type m_type; ///< the color matrix type - QVector m_matrix; ///< the color matrix to apply - qreal m_value; ///< the value (saturate or hueRotate) -}; - -#endif // COLORMATRIXEFFECT_H diff --git a/plugins/tools/karbonplugins/filtereffects/ColorMatrixEffectConfigWidget.cpp b/plugins/tools/karbonplugins/filtereffects/ColorMatrixEffectConfigWidget.cpp deleted file mode 100644 index a97c78abe7..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ColorMatrixEffectConfigWidget.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009-2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "ColorMatrixEffectConfigWidget.h" -#include "ColorMatrixEffect.h" -#include "KoFilterEffect.h" -#include "MatrixDataModel.h" - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "kis_double_parse_spin_box.h" - -ColorMatrixEffectConfigWidget::ColorMatrixEffectConfigWidget(QWidget *parent) - : KoFilterEffectConfigWidgetBase(parent) - , m_effect(0) -{ - QGridLayout *g = new QGridLayout(this); - - m_type = new KComboBox(this); - m_type->addItem(i18n("Apply color matrix")); - m_type->addItem(i18n("Saturate colors")); - m_type->addItem(i18n("Rotate hue")); - m_type->addItem(i18n("Luminance to alpha")); - g->addWidget(m_type, 0, 0); - - m_stack = new QStackedWidget(this); - m_stack->setContentsMargins(0, 0, 0, 0); - g->addWidget(m_stack, 1, 0); - - m_matrixModel = new MatrixDataModel(this); - - QTableView *matrixWidget = new QTableView(m_stack); - matrixWidget->setModel(m_matrixModel); - matrixWidget->horizontalHeader()->hide(); - matrixWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); - matrixWidget->verticalHeader()->hide(); - matrixWidget->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); - m_stack->addWidget(matrixWidget); - - QWidget *saturateWidget = new QWidget(m_stack); - QGridLayout *saturateLayout = new QGridLayout(saturateWidget); - saturateLayout->addWidget(new QLabel(i18n("Saturate value"), saturateWidget), 0, 0); - m_saturate = new KisDoubleParseSpinBox(saturateWidget); - m_saturate->setRange(0.0, 1.0); - m_saturate->setSingleStep(0.05); - saturateLayout->addWidget(m_saturate, 0, 1); - saturateLayout->addItem(new QSpacerItem(0, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 1, 0); - saturateWidget->setLayout(saturateLayout); - m_stack->addWidget(saturateWidget); - - QWidget *hueRotateWidget = new QWidget(m_stack); - QGridLayout *hueRotateLayout = new QGridLayout(hueRotateWidget); - hueRotateLayout->addWidget(new QLabel(i18n("Angle"), hueRotateWidget), 0, 0); - m_hueRotate = new KisDoubleParseSpinBox(hueRotateWidget); - m_hueRotate->setRange(0.0, 360.0); - m_hueRotate->setSingleStep(1.0); - hueRotateLayout->addWidget(m_hueRotate, 0, 1); - hueRotateLayout->addItem(new QSpacerItem(0, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 1, 0); - hueRotateWidget->setLayout(hueRotateLayout); - m_stack->addWidget(hueRotateWidget); - - QWidget *luminanceWidget = new QWidget(m_stack); - m_stack->addWidget(luminanceWidget); - - setLayout(g); - - connect(m_type, SIGNAL(currentIndexChanged(int)), m_stack, SLOT(setCurrentIndex(int))); - connect(m_type, SIGNAL(currentIndexChanged(int)), this, SLOT(typeChanged(int))); - connect(m_saturate, SIGNAL(valueChanged(double)), this, SLOT(saturateChanged(double))); - connect(m_hueRotate, SIGNAL(valueChanged(double)), this, SLOT(hueRotateChanged(double))); - connect(m_matrixModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(matrixChanged())); -} - -bool ColorMatrixEffectConfigWidget::editFilterEffect(KoFilterEffect *filterEffect) -{ - m_effect = dynamic_cast(filterEffect); - if (!m_effect) { - return false; - } - - m_type->blockSignals(true); - - switch (m_effect->type()) { - case ColorMatrixEffect::Matrix: - m_type->setCurrentIndex(0); - m_matrixModel->setMatrix(m_effect->colorMatrix(), m_effect->colorMatrixRowCount(), m_effect->colorMatrixColumnCount()); - break; - case ColorMatrixEffect::Saturate: - m_type->setCurrentIndex(1); - m_saturate->blockSignals(true); - m_saturate->setValue(m_effect->saturate()); - m_saturate->blockSignals(false); - break; - case ColorMatrixEffect::HueRotate: - m_type->setCurrentIndex(2); - m_hueRotate->blockSignals(true); - m_hueRotate->setValue(m_effect->hueRotate()); - m_hueRotate->blockSignals(false); - break; - case ColorMatrixEffect::LuminanceAlpha: - m_type->setCurrentIndex(3); - break; - } - - m_type->blockSignals(false); - m_stack->setCurrentIndex(m_type->currentIndex()); - - return true; -} - -void ColorMatrixEffectConfigWidget::matrixChanged() -{ - if (!m_effect) { - return; - } - - m_effect->setColorMatrix(m_matrixModel->matrix()); - emit filterChanged(); -} - -void ColorMatrixEffectConfigWidget::saturateChanged(double saturate) -{ - if (!m_effect) { - return; - } - - m_effect->setSaturate(saturate); - emit filterChanged(); -} - -void ColorMatrixEffectConfigWidget::hueRotateChanged(double angle) -{ - if (!m_effect) { - return; - } - - m_effect->setHueRotate(angle); - emit filterChanged(); -} - -void ColorMatrixEffectConfigWidget::typeChanged(int index) -{ - if (!m_effect) { - return; - } - - if (index == ColorMatrixEffect::Matrix) { - m_effect->setColorMatrix(m_matrixModel->matrix()); - } else if (index == ColorMatrixEffect::Saturate) { - m_effect->setSaturate(m_saturate->value()); - } else if (index == ColorMatrixEffect::HueRotate) { - m_effect->setHueRotate(m_hueRotate->value()); - } else { - m_effect->setLuminanceAlpha(); - } - emit filterChanged(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/ColorMatrixEffectConfigWidget.h b/plugins/tools/karbonplugins/filtereffects/ColorMatrixEffectConfigWidget.h deleted file mode 100644 index 2c2f0dd7cd..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ColorMatrixEffectConfigWidget.h +++ /dev/null @@ -1,55 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 COLORMATRIXEFFECTCONFIGWIDGET_H -#define COLORMATRIXEFFECTCONFIGWIDGET_H - -#include "KoFilterEffectConfigWidgetBase.h" - -class ColorMatrixEffect; -class KoFilterEffect; -class KComboBox; -class QStackedWidget; -class QDoubleSpinBox; -class MatrixDataModel; - -class ColorMatrixEffectConfigWidget : public KoFilterEffectConfigWidgetBase -{ - Q_OBJECT -public: - explicit ColorMatrixEffectConfigWidget(QWidget *parent = 0); - - /// reimplemented from KoFilterEffectConfigWidgetBase - bool editFilterEffect(KoFilterEffect *filterEffect) override; - -private Q_SLOTS: - void matrixChanged(); - void saturateChanged(double saturate); - void hueRotateChanged(double angle); - void typeChanged(int index); -private: - KComboBox *m_type; - ColorMatrixEffect *m_effect; - MatrixDataModel *m_matrixModel; - QStackedWidget *m_stack; - QDoubleSpinBox *m_saturate; - QDoubleSpinBox *m_hueRotate; -}; - -#endif // COLORMATRIXEFFECTCONFIGWIDGET_H diff --git a/plugins/tools/karbonplugins/filtereffects/ColorMatrixEffectFactory.cpp b/plugins/tools/karbonplugins/filtereffects/ColorMatrixEffectFactory.cpp deleted file mode 100644 index aee4873e76..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ColorMatrixEffectFactory.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "ColorMatrixEffectFactory.h" -#include "ColorMatrixEffect.h" -#include "ColorMatrixEffectConfigWidget.h" - -#include - -ColorMatrixEffectFactory::ColorMatrixEffectFactory() - : KoFilterEffectFactoryBase(ColorMatrixEffectId, i18n("Color matrix")) -{ -} - -KoFilterEffect *ColorMatrixEffectFactory::createFilterEffect() const -{ - return new ColorMatrixEffect(); -} - -KoFilterEffectConfigWidgetBase *ColorMatrixEffectFactory::createConfigWidget() const -{ - return new ColorMatrixEffectConfigWidget(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/ColorMatrixEffectFactory.h b/plugins/tools/karbonplugins/filtereffects/ColorMatrixEffectFactory.h deleted file mode 100644 index 85288e9bfb..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ColorMatrixEffectFactory.h +++ /dev/null @@ -1,35 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 COLORMATRIXEFFECTFACTORY_H -#define COLORMATRIXEFFECTFACTORY_H - -#include "KoFilterEffectFactoryBase.h" - -class KoFilterEffect; - -class ColorMatrixEffectFactory : public KoFilterEffectFactoryBase -{ -public: - ColorMatrixEffectFactory(); - KoFilterEffect *createFilterEffect() const override; - KoFilterEffectConfigWidgetBase *createConfigWidget() const override; -}; - -#endif // COLORMATRIXEFFECTFACTORY_H diff --git a/plugins/tools/karbonplugins/filtereffects/ComponentTransferEffect.cpp b/plugins/tools/karbonplugins/filtereffects/ComponentTransferEffect.cpp deleted file mode 100644 index 10701a8a91..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ComponentTransferEffect.cpp +++ /dev/null @@ -1,331 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "ComponentTransferEffect.h" -#include "ColorChannelConversion.h" -#include -#include -#include -#include -#include -#include -#include - -ComponentTransferEffect::ComponentTransferEffect() - : KoFilterEffect(ComponentTransferEffectId, i18n("Component transfer")) -{ -} - -ComponentTransferEffect::Function ComponentTransferEffect::function(Channel channel) const -{ - return m_data[channel].function; -} - -void ComponentTransferEffect::setFunction(Channel channel, Function function) -{ - m_data[channel].function = function; -} - -QList ComponentTransferEffect::tableValues(Channel channel) const -{ - return m_data[channel].tableValues; -} - -void ComponentTransferEffect::setTableValues(Channel channel, QList tableValues) -{ - m_data[channel].tableValues = tableValues; -} - -void ComponentTransferEffect::setSlope(Channel channel, qreal slope) -{ - m_data[channel].slope = slope; -} - -qreal ComponentTransferEffect::slope(Channel channel) const -{ - return m_data[channel].slope; -} - -void ComponentTransferEffect::setIntercept(Channel channel, qreal intercept) -{ - m_data[channel].intercept = intercept; -} - -qreal ComponentTransferEffect::intercept(Channel channel) const -{ - return m_data[channel].intercept; -} - -void ComponentTransferEffect::setAmplitude(Channel channel, qreal amplitude) -{ - m_data[channel].amplitude = amplitude; -} - -qreal ComponentTransferEffect::amplitude(Channel channel) const -{ - return m_data[channel].amplitude; -} - -void ComponentTransferEffect::setExponent(Channel channel, qreal exponent) -{ - m_data[channel].exponent = exponent; -} - -qreal ComponentTransferEffect::exponent(Channel channel) const -{ - return m_data[channel].exponent; -} - -void ComponentTransferEffect::setOffset(Channel channel, qreal offset) -{ - m_data[channel].offset = offset; -} - -qreal ComponentTransferEffect::offset(Channel channel) const -{ - return m_data[channel].offset; -} - -QImage ComponentTransferEffect::processImage(const QImage &image, const KoFilterEffectRenderContext &context) const -{ - QImage result = image; - - const QRgb *src = (const QRgb *)image.constBits(); - QRgb *dst = (QRgb *)result.bits(); - int w = result.width(); - - qreal sa, sr, sg, sb; - qreal da, dr, dg, db; - int pixel; - - const QRect roi = context.filterRegion().toRect(); - const int minRow = roi.top(); - const int maxRow = roi.bottom(); - const int minCol = roi.left(); - const int maxCol = roi.right(); - - for (int row = minRow; row <= maxRow; ++row) { - for (int col = minCol; col <= maxCol; ++col) { - pixel = row * w + col; - const QRgb &s = src[pixel]; - - sa = fromIntColor[qAlpha(s)]; - sr = fromIntColor[qRed(s)]; - sg = fromIntColor[qGreen(s)]; - sb = fromIntColor[qBlue(s)]; - // the matrix is applied to non-premultiplied color values - // so we have to convert colors by dividing by alpha value - if (sa > 0.0 && sa < 1.0) { - sr /= sa; - sb /= sa; - sg /= sa; - } - - dr = transferChannel(ChannelR, sr); - dg = transferChannel(ChannelG, sg); - db = transferChannel(ChannelB, sb); - da = transferChannel(ChannelA, sa); - - da *= 255.0; - - // set pre-multiplied color values on destination image - dst[pixel] = qRgba(static_cast(qBound(qreal(0.0), dr * da, qreal(255.0))), - static_cast(qBound(qreal(0.0), dg * da, qreal(255.0))), - static_cast(qBound(qreal(0.0), db * da, qreal(255.0))), - static_cast(qBound(qreal(0.0), da, qreal(255.0)))); - } - } - - return result; -} - -qreal ComponentTransferEffect::transferChannel(Channel channel, qreal value) const -{ - const Data &d = m_data[channel]; - - switch (d.function) { - case Identity: - return value; - case Table: { - qreal valueCount = d.tableValues.count() - 1; - if (valueCount < 0.0) { - return value; - } - qreal k1 = static_cast(value * valueCount); - qreal k2 = qMin(k1 + 1, valueCount); - qreal vk1 = d.tableValues[k1]; - qreal vk2 = d.tableValues[k2]; - return vk1 + (value - static_cast(k1) / valueCount) * valueCount * (vk2 - vk1); - } - case Discrete: { - qreal valueCount = d.tableValues.count() - 1; - if (valueCount < 0.0) { - return value; - } - return d.tableValues[static_cast(value * valueCount)]; - } - case Linear: - return d.slope * value + d.intercept; - case Gamma: - return d.amplitude * pow(value, d.exponent) + d.offset; - } - - return value; -} - -bool ComponentTransferEffect::load(const KoXmlElement &element, const KoFilterEffectLoadingContext &) -{ - if (element.tagName() != id()) { - return false; - } - - // reset data - m_data[ChannelR] = Data(); - m_data[ChannelG] = Data(); - m_data[ChannelB] = Data(); - m_data[ChannelA] = Data(); - - for (KoXmlNode n = element.firstChild(); !n.isNull(); n = n.nextSibling()) { - KoXmlElement node = n.toElement(); - if (node.tagName() == "feFuncR") { - loadChannel(ChannelR, node); - } else if (node.tagName() == "feFuncG") { - loadChannel(ChannelG, node); - } else if (node.tagName() == "feFuncB") { - loadChannel(ChannelB, node); - } else if (node.tagName() == "feFuncA") { - loadChannel(ChannelA, node); - } - } - - return true; -} - -void ComponentTransferEffect::loadChannel(Channel channel, const KoXmlElement &element) -{ - QString typeStr = element.attribute("type"); - if (typeStr.isEmpty()) { - return; - } - - Data &d = m_data[channel]; - - if (typeStr == "table" || typeStr == "discrete") { - d.function = typeStr == "table" ? Table : Discrete; - QString valueStr = element.attribute("tableValues"); - QStringList values = valueStr.split(QRegExp("(\\s+|,)"), QString::SkipEmptyParts); - Q_FOREACH (const QString &v, values) { - d.tableValues.append(v.toDouble()); - } - } else if (typeStr == "linear") { - d.function = Linear; - if (element.hasAttribute("slope")) { - d.slope = element.attribute("slope").toDouble(); - } - if (element.hasAttribute("intercept")) { - d.intercept = element.attribute("intercept").toDouble(); - } - } else if (typeStr == "gamma") { - d.function = Gamma; - if (element.hasAttribute("amplitude")) { - d.amplitude = element.attribute("amplitude").toDouble(); - } - if (element.hasAttribute("exponent")) { - d.exponent = element.attribute("exponent").toDouble(); - } - if (element.hasAttribute("offset")) { - d.offset = element.attribute("offset").toDouble(); - } - } -} - -void ComponentTransferEffect::save(KoXmlWriter &writer) -{ - writer.startElement(ComponentTransferEffectId); - - saveCommonAttributes(writer); - - saveChannel(ChannelR, writer); - saveChannel(ChannelG, writer); - saveChannel(ChannelB, writer); - saveChannel(ChannelA, writer); - - writer.endElement(); -} - -void ComponentTransferEffect::saveChannel(Channel channel, KoXmlWriter &writer) -{ - Function function = m_data[channel].function; - // we can omit writing the transfer function when - if (function == Identity) { - return; - } - - switch (channel) { - case ChannelR: - writer.startElement("feFuncR"); - break; - case ChannelG: - writer.startElement("feFuncG"); - break; - case ChannelB: - writer.startElement("feFuncB"); - break; - case ChannelA: - writer.startElement("feFuncA"); - break; - } - - Data defaultData; - const Data ¤tData = m_data[channel]; - - if (function == Linear) { - writer.addAttribute("type", "linear"); - // only write non default data - if (defaultData.slope != currentData.slope) { - writer.addAttribute("slope", QString("%1").arg(currentData.slope)); - } - if (defaultData.intercept != currentData.intercept) { - writer.addAttribute("intercept", QString("%1").arg(currentData.intercept)); - } - } else if (function == Gamma) { - writer.addAttribute("type", "gamma"); - // only write non default data - if (defaultData.amplitude != currentData.amplitude) { - writer.addAttribute("amplitude", QString("%1").arg(currentData.amplitude)); - } - if (defaultData.exponent != currentData.exponent) { - writer.addAttribute("exponent", QString("%1").arg(currentData.exponent)); - } - if (defaultData.offset != currentData.offset) { - writer.addAttribute("offset", QString("%1").arg(currentData.offset)); - } - } else { - writer.addAttribute("type", function == Table ? "table" : "discrete"); - if (currentData.tableValues.count()) { - QString tableStr; - Q_FOREACH (qreal v, currentData.tableValues) { - tableStr += QString("%1 ").arg(v); - } - writer.addAttribute("tableValues", tableStr.trimmed()); - } - } - - writer.endElement(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/ComponentTransferEffect.h b/plugins/tools/karbonplugins/filtereffects/ComponentTransferEffect.h deleted file mode 100644 index d5706cd692..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ComponentTransferEffect.h +++ /dev/null @@ -1,128 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 COMPONENTTRANSFEREFFECT_H -#define COMPONENTTRANSFEREFFECT_H - -#include "KoFilterEffect.h" - -#define ComponentTransferEffectId "feComponentTransfer" - -/// A component transfer effect -class ComponentTransferEffect : public KoFilterEffect -{ -public: - /// the different transfer functions - enum Function { - Identity, - Table, - Discrete, - Linear, - Gamma - }; - - /// the different color channels - enum Channel { - ChannelR, - ChannelG, - ChannelB, - ChannelA - }; - - ComponentTransferEffect(); - - /// Returns the component transfer function of the specified channel - Function function(Channel channel) const; - - /// Sets the component transfer function to use for the specified channel - void setFunction(Channel channel, Function function); - - /// Returns the lookup table for the specified channel - QList tableValues(Channel channel) const; - - /// Sets the lookup table for the specified channel - void setTableValues(Channel channel, QList tableValues); - - /// Sets the slope for the specified channel - void setSlope(Channel channel, qreal slope); - - /// Returns the slope for the specified channel - qreal slope(Channel channel) const; - - /// Sets the intercept for the specified channel - void setIntercept(Channel channel, qreal intercept); - - /// Returns the intercept for the specified channel - qreal intercept(Channel channel) const; - - /// Sets the amplitude for the specified channel - void setAmplitude(Channel channel, qreal amplitude); - - /// Returns the amplitude for the specified channel - qreal amplitude(Channel channel) const; - - /// Sets the exponent for the specified channel - void setExponent(Channel channel, qreal exponent); - - /// Returns the exponent for the specified channel - qreal exponent(Channel channel) const; - - /// Sets the offset for the specified channel - void setOffset(Channel channel, qreal offset); - - /// Returns the offset for the specified channel - qreal offset(Channel channel) const; - - /// reimplemented from KoFilterEffect - QImage processImage(const QImage &image, const KoFilterEffectRenderContext &context) const override; - /// reimplemented from KoFilterEffect - bool load(const KoXmlElement &element, const KoFilterEffectLoadingContext &context) override; - /// reimplemented from KoFilterEffect - void save(KoXmlWriter &writer) override; - -private: - /// loads channel transfer function from given xml element - void loadChannel(Channel channel, const KoXmlElement &element); - - /// saves channel transfer function to given xml writer - void saveChannel(Channel channel, KoXmlWriter &writer); - - /// transfers color channel - qreal transferChannel(Channel channel, qreal value) const; - - struct Data { - Data() - : function(Identity), slope(1.0), intercept(0.0) - , amplitude(1.0), exponent(1.0), offset(0.0) - { - } - - Function function; ///< the component transfer function - QList tableValues; ///< lookup table for table or discrete function - qreal slope; ///< slope for linear function - qreal intercept; ///< intercept for linear function - qreal amplitude; ///< amplitude for gamma function - qreal exponent; ///< exponent for gamma function - qreal offset; ///< offset for gamma function - }; - - Data m_data[4]; -}; - -#endif // COMPONENTTRANSFEREFFECT_H diff --git a/plugins/tools/karbonplugins/filtereffects/ComponentTransferEffectConfigWidget.cpp b/plugins/tools/karbonplugins/filtereffects/ComponentTransferEffectConfigWidget.cpp deleted file mode 100644 index a47c1e1eb4..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ComponentTransferEffectConfigWidget.cpp +++ /dev/null @@ -1,305 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "ComponentTransferEffectConfigWidget.h" -#include "KoFilterEffect.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "kis_double_parse_spin_box.h" - -const qreal ValueStep = 0.1; - -ComponentTransferEffectConfigWidget::ComponentTransferEffectConfigWidget(QWidget *parent) - : KoFilterEffectConfigWidgetBase(parent) - , m_effect(0) - , m_currentChannel(ComponentTransferEffect::ChannelR) -{ - QGridLayout *g = new QGridLayout(this); - - QButtonGroup *group = new QButtonGroup(this); - - QRadioButton *butR = new QRadioButton("R", this); - QRadioButton *butG = new QRadioButton("G", this); - QRadioButton *butB = new QRadioButton("B", this); - QRadioButton *butA = new QRadioButton("A", this); - g->addWidget(butR, 0, 0); - g->addWidget(butG, 0, 1); - g->addWidget(butB, 0, 2); - g->addWidget(butA, 0, 3); - group->addButton(butR, ComponentTransferEffect::ChannelR); - group->addButton(butG, ComponentTransferEffect::ChannelG); - group->addButton(butB, ComponentTransferEffect::ChannelB); - group->addButton(butA, ComponentTransferEffect::ChannelA); - butR->setChecked(true); - - g->addWidget(new QLabel(i18n("Function"), this), 1, 0, 1, 2); - m_function = new KComboBox(this); - m_function->addItem(i18n("Identity")); - m_function->addItem(i18n("Table")); - m_function->addItem(i18n("Discrete")); - m_function->addItem(i18n("Linear")); - m_function->addItem(i18n("Gamma")); - g->addWidget(m_function, 1, 2, 1, 2); - - m_stack = new QStackedWidget(this); - m_stack->setContentsMargins(0, 0, 0, 0); - g->addWidget(m_stack, 2, 0, 1, 4); - - // Identity widget - m_stack->addWidget(new QWidget(this)); - - // Table widget - QWidget *tableWidget = new QWidget(m_stack); - QGridLayout *tableLayout = new QGridLayout(tableWidget); - tableLayout->addWidget(new QLabel(i18n("Values"), tableWidget), 0, 0); - m_tableValues = new KLineEdit(tableWidget); - tableLayout->addWidget(m_tableValues, 0, 1); - tableLayout->setContentsMargins(0, 0, 0, 0); - tableLayout->addItem(new QSpacerItem(0, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 1, 0); - m_stack->addWidget(tableWidget); - - // Discrete widget - QWidget *discreteWidget = new QWidget(m_stack); - QGridLayout *discreteLayout = new QGridLayout(discreteWidget); - discreteLayout->addWidget(new QLabel(i18n("Values"), discreteWidget), 0, 0); - m_discreteValues = new KLineEdit(discreteWidget); - discreteLayout->addWidget(m_discreteValues, 0, 1); - discreteLayout->setContentsMargins(0, 0, 0, 0); - discreteLayout->addItem(new QSpacerItem(0, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 1, 0); - m_stack->addWidget(discreteWidget); - - // Linear widget - QWidget *linearWidget = new QWidget(m_stack); - QGridLayout *linearLayout = new QGridLayout(linearWidget); - linearLayout->addWidget(new QLabel(i18n("Slope"), linearWidget), 0, 0); - m_slope = new KisDoubleParseSpinBox(linearWidget); - m_slope->setRange(m_slope->minimum(), m_slope->maximum()); - m_slope->setSingleStep(ValueStep); - linearLayout->addWidget(m_slope, 0, 1); - linearLayout->addWidget(new QLabel(i18n("Intercept")), 1, 0); - m_intercept = new KisDoubleParseSpinBox(linearWidget); - m_intercept->setRange(m_intercept->minimum(), m_intercept->maximum()); - m_intercept->setSingleStep(ValueStep); - linearLayout->addWidget(m_intercept, 1, 1); - linearLayout->addItem(new QSpacerItem(0, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 2, 0); - linearLayout->setContentsMargins(0, 0, 0, 0); - linearWidget->setLayout(linearLayout); - m_stack->addWidget(linearWidget); - - QWidget *gammaWidget = new QWidget(m_stack); - QGridLayout *gammaLayout = new QGridLayout(gammaWidget); - gammaLayout->addWidget(new QLabel(i18n("Amplitude"), gammaWidget), 0, 0); - m_amplitude = new KisDoubleParseSpinBox(gammaWidget); - m_amplitude->setRange(m_amplitude->minimum(), m_amplitude->maximum()); - m_amplitude->setSingleStep(ValueStep); - gammaLayout->addWidget(m_amplitude, 0, 1); - gammaLayout->addWidget(new QLabel(i18n("Exponent"), gammaWidget), 1, 0); - m_exponent = new KisDoubleParseSpinBox(gammaWidget); - m_exponent->setRange(m_exponent->minimum(), m_exponent->maximum()); - m_exponent->setSingleStep(ValueStep); - gammaLayout->addWidget(m_exponent, 1, 1); - gammaLayout->addWidget(new QLabel(i18n("Offset"), gammaWidget), 2, 0); - m_offset = new KisDoubleParseSpinBox(gammaWidget); - m_offset->setRange(m_offset->minimum(), m_offset->maximum()); - m_offset->setSingleStep(ValueStep); - gammaLayout->addWidget(m_offset, 2, 1); - gammaLayout->addItem(new QSpacerItem(0, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 3, 0); - gammaLayout->setContentsMargins(0, 0, 0, 0); - gammaWidget->setLayout(gammaLayout); - m_stack->addWidget(gammaWidget); - - setLayout(g); - - connect(m_function, SIGNAL(currentIndexChanged(int)), m_stack, SLOT(setCurrentIndex(int))); - connect(m_function, SIGNAL(currentIndexChanged(int)), this, SLOT(functionChanged(int))); - connect(m_tableValues, SIGNAL(editingFinished()), this, SLOT(tableValuesChanged())); - connect(m_discreteValues, SIGNAL(editingFinished()), this, SLOT(discreteValuesChanged())); - connect(m_slope, SIGNAL(valueChanged(double)), this, SLOT(slopeChanged(double))); - connect(m_intercept, SIGNAL(valueChanged(double)), this, SLOT(interceptChanged(double))); - connect(m_amplitude, SIGNAL(valueChanged(double)), this, SLOT(amplitudeChanged(double))); - connect(m_exponent, SIGNAL(valueChanged(double)), this, SLOT(exponentChanged(double))); - connect(m_offset, SIGNAL(valueChanged(double)), this, SLOT(offsetChanged(double))); - connect(group, SIGNAL(buttonClicked(int)), this, SLOT(channelSelected(int))); -} - -void ComponentTransferEffectConfigWidget::updateControls() -{ - m_function->blockSignals(true); - - QString values; - - switch (m_effect->function(m_currentChannel)) { - case ComponentTransferEffect::Identity: - m_function->setCurrentIndex(0); - break; - case ComponentTransferEffect::Table: - m_function->setCurrentIndex(1); - m_tableValues->blockSignals(true); - Q_FOREACH (qreal v, m_effect->tableValues(m_currentChannel)) { - values += QString("%1;").arg(v); - } - m_tableValues->setText(values); - m_tableValues->blockSignals(false); - break; - case ComponentTransferEffect::Discrete: - m_function->setCurrentIndex(2); - m_discreteValues->blockSignals(true); - Q_FOREACH (qreal v, m_effect->tableValues(m_currentChannel)) { - values += QString("%1;").arg(v); - } - m_discreteValues->setText(values); - m_discreteValues->blockSignals(false); - break; - case ComponentTransferEffect::Linear: - m_function->setCurrentIndex(3); - m_slope->blockSignals(true); - m_slope->setValue(m_effect->slope(m_currentChannel)); - m_slope->blockSignals(false); - m_intercept->blockSignals(true); - m_intercept->setValue(m_effect->intercept(m_currentChannel)); - m_intercept->blockSignals(false); - break; - case ComponentTransferEffect::Gamma: - m_function->setCurrentIndex(4); - m_amplitude->blockSignals(true); - m_amplitude->setValue(m_effect->amplitude(m_currentChannel)); - m_amplitude->blockSignals(false); - m_exponent->blockSignals(true); - m_exponent->setValue(m_effect->exponent(m_currentChannel)); - m_exponent->blockSignals(false); - m_offset->blockSignals(true); - m_offset->setValue(m_effect->offset(m_currentChannel)); - m_offset->blockSignals(false); - break; - } - - m_function->blockSignals(false); - m_stack->setCurrentIndex(m_function->currentIndex()); -} - -bool ComponentTransferEffectConfigWidget::editFilterEffect(KoFilterEffect *filterEffect) -{ - m_effect = dynamic_cast(filterEffect); - if (!m_effect) { - return false; - } - - updateControls(); - - return true; -} - -void ComponentTransferEffectConfigWidget::slopeChanged(double slope) -{ - if (!m_effect) { - return; - } - - m_effect->setSlope(m_currentChannel, slope); - emit filterChanged(); -} - -void ComponentTransferEffectConfigWidget::interceptChanged(double intercept) -{ - if (!m_effect) { - return; - } - - m_effect->setIntercept(m_currentChannel, intercept); - emit filterChanged(); -} - -void ComponentTransferEffectConfigWidget::amplitudeChanged(double amplitude) -{ - if (!m_effect) { - return; - } - - m_effect->setAmplitude(m_currentChannel, amplitude); - emit filterChanged(); -} - -void ComponentTransferEffectConfigWidget::exponentChanged(double exponent) -{ - if (!m_effect) { - return; - } - - m_effect->setExponent(m_currentChannel, exponent); - emit filterChanged(); -} - -void ComponentTransferEffectConfigWidget::offsetChanged(double offset) -{ - if (!m_effect) { - return; - } - - m_effect->setOffset(m_currentChannel, offset); - emit filterChanged(); -} - -void ComponentTransferEffectConfigWidget::tableValuesChanged() -{ - QStringList values = m_tableValues->text().split(';', QString::SkipEmptyParts); - QList tableValues; - Q_FOREACH (const QString &v, values) { - tableValues.append(v.toDouble()); - } - m_effect->setTableValues(m_currentChannel, tableValues); - emit filterChanged(); -} - -void ComponentTransferEffectConfigWidget::discreteValuesChanged() -{ - QStringList values = m_discreteValues->text().split(';', QString::SkipEmptyParts); - QList tableValues; - Q_FOREACH (const QString &v, values) { - tableValues.append(v.toDouble()); - } - m_effect->setTableValues(m_currentChannel, tableValues); - emit filterChanged(); -} - -void ComponentTransferEffectConfigWidget::functionChanged(int index) -{ - if (!m_effect) { - return; - } - - m_effect->setFunction(m_currentChannel, static_cast(index)); - - emit filterChanged(); -} - -void ComponentTransferEffectConfigWidget::channelSelected(int channel) -{ - m_currentChannel = static_cast(channel); - updateControls(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/ComponentTransferEffectConfigWidget.h b/plugins/tools/karbonplugins/filtereffects/ComponentTransferEffectConfigWidget.h deleted file mode 100644 index 6d438e6d18..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ComponentTransferEffectConfigWidget.h +++ /dev/null @@ -1,67 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 COMPONENTTRANSFEREFFECTCONFIGWIDGET_H -#define COMPONENTTRANSFEREFFECTCONFIGWIDGET_H - -#include "KoFilterEffectConfigWidgetBase.h" -#include "ComponentTransferEffect.h" - -class KoFilterEffect; -class QDoubleSpinBox; -class KComboBox; -class KLineEdit; -class QStackedWidget; - -class ComponentTransferEffectConfigWidget : public KoFilterEffectConfigWidgetBase -{ - Q_OBJECT -public: - explicit ComponentTransferEffectConfigWidget(QWidget *parent = 0); - - /// reimplemented from KoFilterEffectConfigWidgetBase - bool editFilterEffect(KoFilterEffect *filterEffect) override; - -private Q_SLOTS: - void slopeChanged(double slope); - void interceptChanged(double intercept); - void amplitudeChanged(double amplitude); - void exponentChanged(double exponent); - void offsetChanged(double offset); - void functionChanged(int index); - void channelSelected(int channel); - void tableValuesChanged(); - void discreteValuesChanged(); -private: - void updateControls(); - - ComponentTransferEffect *m_effect; - KComboBox *m_function; - QStackedWidget *m_stack; - KLineEdit *m_tableValues; - KLineEdit *m_discreteValues; - QDoubleSpinBox *m_slope; - QDoubleSpinBox *m_intercept; - QDoubleSpinBox *m_amplitude; - QDoubleSpinBox *m_exponent; - QDoubleSpinBox *m_offset; - ComponentTransferEffect::Channel m_currentChannel; -}; - -#endif // COMPONENTTRANSFEREFFECTCONFIGWIDGET_H diff --git a/plugins/tools/karbonplugins/filtereffects/ComponentTransferEffectFactory.cpp b/plugins/tools/karbonplugins/filtereffects/ComponentTransferEffectFactory.cpp deleted file mode 100644 index bf4d8f64ba..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ComponentTransferEffectFactory.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "ComponentTransferEffectFactory.h" -#include "ComponentTransferEffect.h" -#include "ComponentTransferEffectConfigWidget.h" - -#include - -ComponentTransferEffectFactory::ComponentTransferEffectFactory() - : KoFilterEffectFactoryBase(ComponentTransferEffectId, i18n("Component transfer")) -{ -} - -KoFilterEffect *ComponentTransferEffectFactory::createFilterEffect() const -{ - return new ComponentTransferEffect(); -} - -KoFilterEffectConfigWidgetBase *ComponentTransferEffectFactory::createConfigWidget() const -{ - return new ComponentTransferEffectConfigWidget(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/ComponentTransferEffectFactory.h b/plugins/tools/karbonplugins/filtereffects/ComponentTransferEffectFactory.h deleted file mode 100644 index 51f10d4d1d..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ComponentTransferEffectFactory.h +++ /dev/null @@ -1,35 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 COMPONENTTRANSFEREFFECTFACTORY_H -#define COMPONENTTRANSFEREFFECTFACTORY_H - -#include "KoFilterEffectFactoryBase.h" - -class KoFilterEffect; - -class ComponentTransferEffectFactory : public KoFilterEffectFactoryBase -{ -public: - ComponentTransferEffectFactory(); - KoFilterEffect *createFilterEffect() const override; - KoFilterEffectConfigWidgetBase *createConfigWidget() const override; -}; - -#endif // COMPONENTTRANSFEREFFECTFACTORY_H diff --git a/plugins/tools/karbonplugins/filtereffects/CompositeEffect.cpp b/plugins/tools/karbonplugins/filtereffects/CompositeEffect.cpp deleted file mode 100644 index a16bd57548..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/CompositeEffect.cpp +++ /dev/null @@ -1,228 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "CompositeEffect.h" -#include "ColorChannelConversion.h" -#include -#include -#include -#include -#include -#include -#include -#include - -CompositeEffect::CompositeEffect() - : KoFilterEffect(CompositeEffectId, i18n("Composite")) - , m_operation(CompositeOver) -{ - setRequiredInputCount(2); - setMaximalInputCount(2); - memset(m_k, 0, 4 * sizeof(qreal)); -} - -CompositeEffect::Operation CompositeEffect::operation() const -{ - return m_operation; -} - -void CompositeEffect::setOperation(Operation op) -{ - m_operation = op; -} - -const qreal *CompositeEffect::arithmeticValues() const -{ - return m_k; -} - -void CompositeEffect::setArithmeticValues(qreal *values) -{ - memcpy(m_k, values, 4 * sizeof(qreal)); -} - -QImage CompositeEffect::processImage(const QImage &image, const KoFilterEffectRenderContext &) const -{ - return image; -} - -QImage CompositeEffect::processImages(const QList &images, const KoFilterEffectRenderContext &context) const -{ - int imageCount = images.count(); - if (!imageCount) { - return QImage(); - } - - QImage result = images[0]; - if (images.count() != 2) { - return result; - } - - if (m_operation == Arithmetic) { - const QRgb *src = (QRgb *)images[1].constBits(); - QRgb *dst = (QRgb *)result.bits(); - int w = result.width(); - - qreal sa, sr, sg, sb; - qreal da, dr, dg, db; - int pixel = 0; - - // TODO: do we have to calculate with non-premuliplied colors here ??? - - QRect roi = context.filterRegion().toRect(); - for (int row = roi.top(); row < roi.bottom(); ++row) { - for (int col = roi.left(); col < roi.right(); ++col) { - pixel = row * w + col; - const QRgb &s = src[pixel]; - QRgb &d = dst[pixel]; - - sa = fromIntColor[qAlpha(s)]; - sr = fromIntColor[qRed(s)]; - sg = fromIntColor[qGreen(s)]; - sb = fromIntColor[qBlue(s)]; - - da = fromIntColor[qAlpha(d)]; - dr = fromIntColor[qRed(d)]; - dg = fromIntColor[qGreen(d)]; - db = fromIntColor[qBlue(d)]; - - da = m_k[0] * sa * da + m_k[1] * da + m_k[2] * sa + m_k[3]; - dr = m_k[0] * sr * dr + m_k[1] * dr + m_k[2] * sr + m_k[3]; - dg = m_k[0] * sg * dg + m_k[1] * dg + m_k[2] * sg + m_k[3]; - db = m_k[0] * sb * db + m_k[1] * db + m_k[2] * sb + m_k[3]; - - da *= 255.0; - - // set pre-multiplied color values on destination image - d = qRgba(static_cast(qBound(qreal(0.0), dr * da, qreal(255.0))), - static_cast(qBound(qreal(0.0), dg * da, qreal(255.0))), - static_cast(qBound(qreal(0.0), db * da, qreal(255.0))), - static_cast(qBound(qreal(0.0), da, qreal(255.0)))); - } - } - } else { - QPainter painter(&result); - - switch (m_operation) { - case CompositeOver: - painter.setCompositionMode(QPainter::CompositionMode_DestinationOver); - break; - case CompositeIn: - painter.setCompositionMode(QPainter::CompositionMode_DestinationIn); - break; - case CompositeOut: - painter.setCompositionMode(QPainter::CompositionMode_DestinationOut); - break; - case CompositeAtop: - painter.setCompositionMode(QPainter::CompositionMode_DestinationAtop); - break; - case CompositeXor: - painter.setCompositionMode(QPainter::CompositionMode_Xor); - break; - default: - // no composition mode - break; - } - painter.drawImage(context.filterRegion(), images[1], context.filterRegion()); - } - - return result; -} - -bool CompositeEffect::load(const KoXmlElement &element, const KoFilterEffectLoadingContext &) -{ - if (element.tagName() != id()) { - return false; - } - - QString opStr = element.attribute("operator"); - if (opStr == "over") { - m_operation = CompositeOver; - } else if (opStr == "in") { - m_operation = CompositeIn; - } else if (opStr == "out") { - m_operation = CompositeOut; - } else if (opStr == "atop") { - m_operation = CompositeAtop; - } else if (opStr == "xor") { - m_operation = CompositeXor; - } else if (opStr == "arithmetic") { - m_operation = Arithmetic; - if (element.hasAttribute("k1")) { - m_k[0] = element.attribute("k1").toDouble(); - } - if (element.hasAttribute("k2")) { - m_k[1] = element.attribute("k2").toDouble(); - } - if (element.hasAttribute("k3")) { - m_k[2] = element.attribute("k3").toDouble(); - } - if (element.hasAttribute("k4")) { - m_k[3] = element.attribute("k4").toDouble(); - } - } else { - return false; - } - - if (element.hasAttribute("in2")) { - if (inputs().count() == 2) { - setInput(1, element.attribute("in2")); - } else { - addInput(element.attribute("in2")); - } - } - - return true; -} - -void CompositeEffect::save(KoXmlWriter &writer) -{ - writer.startElement(CompositeEffectId); - - saveCommonAttributes(writer); - - switch (m_operation) { - case CompositeOver: - writer.addAttribute("operator", "over"); - break; - case CompositeIn: - writer.addAttribute("operator", "in"); - break; - case CompositeOut: - writer.addAttribute("operator", "out"); - break; - case CompositeAtop: - writer.addAttribute("operator", "atop"); - break; - case CompositeXor: - writer.addAttribute("operator", "xor"); - break; - case Arithmetic: - writer.addAttribute("operator", "arithmetic"); - writer.addAttribute("k1", QString("%1").arg(m_k[0])); - writer.addAttribute("k2", QString("%1").arg(m_k[1])); - writer.addAttribute("k3", QString("%1").arg(m_k[2])); - writer.addAttribute("k4", QString("%1").arg(m_k[3])); - break; - } - - writer.addAttribute("in2", inputs().at(1)); - - writer.endElement(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/CompositeEffect.h b/plugins/tools/karbonplugins/filtereffects/CompositeEffect.h deleted file mode 100644 index 143506e943..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/CompositeEffect.h +++ /dev/null @@ -1,68 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 COMPOSITEEFFECT_H -#define COMPOSITEEFFECT_H - -#include "KoFilterEffect.h" - -#define CompositeEffectId "feComposite" - -/// A flood fill effect -class CompositeEffect : public KoFilterEffect -{ -public: - enum Operation { - CompositeOver, - CompositeIn, - CompositeOut, - CompositeAtop, - CompositeXor, - Arithmetic - }; - - CompositeEffect(); - - /// Returns the composite operation - Operation operation() const; - - /// Sets the composite operation - void setOperation(Operation op); - - /// Returns the arithmetic values - const qreal *arithmeticValues() const; - - /// Sets the arithmetic values - void setArithmeticValues(qreal *values); - - /// reimplemented from KoFilterEffect - QImage processImage(const QImage &image, const KoFilterEffectRenderContext &context) const override; - /// reimplemented from KoFilterEffect - QImage processImages(const QList &images, const KoFilterEffectRenderContext &context) const override; - /// reimplemented from KoFilterEffect - bool load(const KoXmlElement &element, const KoFilterEffectLoadingContext &context) override; - /// reimplemented from KoFilterEffect - void save(KoXmlWriter &writer) override; - -private: - Operation m_operation; - qreal m_k[4]; -}; - -#endif // COMPOSITEEFFECT_H diff --git a/plugins/tools/karbonplugins/filtereffects/CompositeEffectConfigWidget.cpp b/plugins/tools/karbonplugins/filtereffects/CompositeEffectConfigWidget.cpp deleted file mode 100644 index 53ea1d4a0e..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/CompositeEffectConfigWidget.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "CompositeEffectConfigWidget.h" -#include "CompositeEffect.h" -#include "KoFilterEffect.h" - -#include -#include -#include - -#include -#include - -#include "kis_double_parse_spin_box.h" - -CompositeEffectConfigWidget::CompositeEffectConfigWidget(QWidget *parent) - : KoFilterEffectConfigWidgetBase(parent) - , m_effect(0) -{ - QGridLayout *g = new QGridLayout(this); - - g->addWidget(new QLabel(i18n("Operation"), this), 0, 0); - - m_operation = new KComboBox(this); - m_operation->addItem(i18nc("blending mode", "Over")); - m_operation->addItem(i18nc("blending mode", "In")); - m_operation->addItem(i18nc("blending mode", "Out")); - m_operation->addItem(i18nc("blending mode", "Atop")); - m_operation->addItem(i18nc("blending mode", "Xor")); - m_operation->addItem(i18nc("blending mode", "Arithmetic")); - g->addWidget(m_operation, 0, 1); - - m_arithmeticWidget = new QWidget(this); - QGridLayout *arithmeticLayout = new QGridLayout(m_arithmeticWidget); - for (int i = 0; i < 4; ++i) { - m_k[i] = new KisDoubleParseSpinBox(m_arithmeticWidget); - arithmeticLayout->addWidget(new QLabel(QString("k%1").arg(i + 1)), i / 2, (2 * i) % 4); - arithmeticLayout->addWidget(m_k[i], i / 2, (2 * i + 1) % 4); - connect(m_k[i], SIGNAL(valueChanged(double)), this, SLOT(valueChanged())); - } - m_arithmeticWidget->setContentsMargins(0, 0, 0, 0); - g->addWidget(m_arithmeticWidget, 1, 0, 1, 2); - g->addItem(new QSpacerItem(0, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 2, 0); - - connect(m_operation, SIGNAL(currentIndexChanged(int)), this, SLOT(operationChanged(int))); -} - -bool CompositeEffectConfigWidget::editFilterEffect(KoFilterEffect *filterEffect) -{ - m_effect = dynamic_cast(filterEffect); - if (!m_effect) { - return false; - } - - m_operation->blockSignals(true); - m_operation->setCurrentIndex(m_effect->operation()); - m_operation->blockSignals(false); - - const qreal *k = m_effect->arithmeticValues(); - for (int i = 0; i < 4; ++i) { - m_k[i]->blockSignals(true); - m_k[i]->setValue(k[i]); - m_k[i]->blockSignals(false); - } - m_arithmeticWidget->setVisible(m_effect->operation() == CompositeEffect::Arithmetic); - - return true; -} - -void CompositeEffectConfigWidget::operationChanged(int index) -{ - m_arithmeticWidget->setVisible(index == 6); - if (m_effect) { - m_effect->setOperation(static_cast(index)); - emit filterChanged(); - } -} - -void CompositeEffectConfigWidget::valueChanged() -{ - if (!m_effect) { - return; - } - - qreal k[4] = {0}; - for (int i = 0; i < 4; ++i) { - k[i] = m_k[i]->value(); - } - - m_effect->setArithmeticValues(k); - emit filterChanged(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/CompositeEffectConfigWidget.h b/plugins/tools/karbonplugins/filtereffects/CompositeEffectConfigWidget.h deleted file mode 100644 index 475d7970ff..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/CompositeEffectConfigWidget.h +++ /dev/null @@ -1,50 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 COMPOSITEEFFECTCONFIGWIDGET_H -#define COMPOSITEEFFECTCONFIGWIDGET_H - -#include "KoFilterEffectConfigWidgetBase.h" - -class KoFilterEffect; -class CompositeEffect; -class QDoubleSpinBox; -class KComboBox; - -class CompositeEffectConfigWidget : public KoFilterEffectConfigWidgetBase -{ - Q_OBJECT -public: - explicit CompositeEffectConfigWidget(QWidget *parent = 0); - - /// reimplemented from KoFilterEffectConfigWidgetBase - bool editFilterEffect(KoFilterEffect *filterEffect) override; - -private Q_SLOTS: - void valueChanged(); - void operationChanged(int index); - -private: - CompositeEffect *m_effect; - KComboBox *m_operation; - QDoubleSpinBox *m_k[4]; - QWidget *m_arithmeticWidget; -}; - -#endif // COMPOSITEEFFECTCONFIGWIDGET_H diff --git a/plugins/tools/karbonplugins/filtereffects/CompositeEffectFactory.cpp b/plugins/tools/karbonplugins/filtereffects/CompositeEffectFactory.cpp deleted file mode 100644 index 8971612562..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/CompositeEffectFactory.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "CompositeEffectFactory.h" -#include "CompositeEffect.h" -#include "CompositeEffectConfigWidget.h" - -#include - -CompositeEffectFactory::CompositeEffectFactory() - : KoFilterEffectFactoryBase(CompositeEffectId, i18n("Composite")) -{ -} - -KoFilterEffect *CompositeEffectFactory::createFilterEffect() const -{ - return new CompositeEffect(); -} - -KoFilterEffectConfigWidgetBase *CompositeEffectFactory::createConfigWidget() const -{ - return new CompositeEffectConfigWidget(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/CompositeEffectFactory.h b/plugins/tools/karbonplugins/filtereffects/CompositeEffectFactory.h deleted file mode 100644 index 1495393903..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/CompositeEffectFactory.h +++ /dev/null @@ -1,35 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 COMPOSITEEFFECTFACTORY_H -#define COMPOSITEEFFECTFACTORY_H - -#include "KoFilterEffectFactoryBase.h" - -class KoFilterEffect; - -class CompositeEffectFactory : public KoFilterEffectFactoryBase -{ -public: - CompositeEffectFactory(); - KoFilterEffect *createFilterEffect() const override; - KoFilterEffectConfigWidgetBase *createConfigWidget() const override; -}; - -#endif // COMPOSITEEFFECTFACTORY_H diff --git a/plugins/tools/karbonplugins/filtereffects/ConvolveMatrixEffect.cpp b/plugins/tools/karbonplugins/filtereffects/ConvolveMatrixEffect.cpp deleted file mode 100644 index 2f6a7f069a..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ConvolveMatrixEffect.cpp +++ /dev/null @@ -1,365 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "ConvolveMatrixEffect.h" -#include "KoFilterEffectRenderContext.h" -#include "KoFilterEffectLoadingContext.h" -#include "KoViewConverter.h" -#include "KoXmlWriter.h" -#include "KoXmlReader.h" -#include -#include -#include -#include -#include - -#include - -ConvolveMatrixEffect::ConvolveMatrixEffect() - : KoFilterEffect(ConvolveMatrixEffectId, i18n("Convolve Matrix")) -{ - setDefaults(); -} - -void ConvolveMatrixEffect::setDefaults() -{ - m_order = QPoint(3, 3); - m_divisor = 0.0; - m_bias = 0.0; - m_target = QPoint(-1, -1); - m_edgeMode = Duplicate; - m_preserveAlpha = false; - m_kernel.resize(m_order.x()*m_order.y()); - for (int i = 0; i < m_kernel.size(); ++i) { - m_kernel[i] = 0.0; - } - m_kernelUnitLength = QPointF(1, 1); -} - -QPoint ConvolveMatrixEffect::order() const -{ - return m_order; -} - -void ConvolveMatrixEffect::setOrder(const QPoint &order) -{ - m_order = QPoint(qMax(1, order.x()), qMax(1, order.y())); -} - -QVector ConvolveMatrixEffect::kernel() const -{ - return m_kernel; -} - -void ConvolveMatrixEffect::setKernel(const QVector &kernel) -{ - if (m_order.x()*m_order.y() != kernel.count()) { - return; - } - m_kernel = kernel; -} - -qreal ConvolveMatrixEffect::divisor() const -{ - return m_divisor; -} - -void ConvolveMatrixEffect::setDivisor(qreal divisor) -{ - m_divisor = divisor; -} - -qreal ConvolveMatrixEffect::bias() const -{ - return m_bias; -} - -void ConvolveMatrixEffect::setBias(qreal bias) -{ - m_bias = bias; -} - -QPoint ConvolveMatrixEffect::target() const -{ - return m_target; -} - -void ConvolveMatrixEffect::setTarget(const QPoint &target) -{ - m_target = target; -} - -ConvolveMatrixEffect::EdgeMode ConvolveMatrixEffect::edgeMode() const -{ - return m_edgeMode; -} - -void ConvolveMatrixEffect::setEdgeMode(EdgeMode edgeMode) -{ - m_edgeMode = edgeMode; -} - -bool ConvolveMatrixEffect::isPreserveAlphaEnabled() const -{ - return m_preserveAlpha; -} - -void ConvolveMatrixEffect::enablePreserveAlpha(bool on) -{ - m_preserveAlpha = on; -} - -QImage ConvolveMatrixEffect::processImage(const QImage &image, const KoFilterEffectRenderContext &context) const -{ - QImage result = image; - - const int rx = m_order.x(); - const int ry = m_order.y(); - if (rx == 0 && ry == 0) { - return result; - } - - const int tx = m_target.x() >= 0 && m_target.x() <= rx ? m_target.x() : rx >> 1; - const int ty = m_target.y() >= 0 && m_target.y() <= ry ? m_target.y() : ry >> 1; - - const int w = result.width(); - const int h = result.height(); - - // setup mask - const int maskSize = rx * ry; - QVector offset(maskSize); - int index = 0; - for (int y = 0; y < ry; ++y) { - for (int x = 0; x < rx; ++x) { - offset[index] = QPoint(x - tx, y - ty); - index++; - } - } - - qreal divisor = m_divisor; - // if no divisor given, it is the sum of all kernel values - // if sum of kernel values is zero, divisor is set to 1 - if (divisor == 0.0) { - Q_FOREACH (qreal k, m_kernel) { - divisor += k; - } - if (divisor == 0.0) { - divisor = 1.0; - } - } - - int dstPixel, srcPixel; - qreal sumA, sumR, sumG, sumB; - const QRgb *src = (const QRgb *)image.constBits(); - QRgb *dst = (QRgb *)result.bits(); - - const QRect roi = context.filterRegion().toRect(); - const int minX = roi.left(); - const int maxX = roi.right(); - const int minY = roi.top(); - const int maxY = roi.bottom(); - - int srcRow, srcCol; - for (int row = minY; row <= maxY; ++row) { - for (int col = minX; col <= maxX; ++col) { - dstPixel = row * w + col; - sumA = sumR = sumG = sumB = 0; - for (int i = 0; i < maskSize; ++i) { - srcRow = row + offset[i].y(); - srcCol = col + offset[i].x(); - // handle top and bottom edge - if (srcRow < 0 || srcRow >= h) { - switch (m_edgeMode) { - case Duplicate: - srcRow = srcRow >= h ? h - 1 : 0; - break; - case Wrap: - srcRow = (srcRow + h) % h; - break; - case None: - // zero for all color channels - continue; - break; - } - } - // handle left and right edge - if (srcCol < 0 || srcCol >= w) { - switch (m_edgeMode) { - case Duplicate: - srcCol = srcCol >= w ? w - 1 : 0; - break; - case Wrap: - srcCol = (srcCol + w) % w; - break; - case None: - // zero for all color channels - continue; - break; - } - } - srcPixel = srcRow * w + srcCol; - const QRgb &s = src[srcPixel]; - const qreal &k = m_kernel[i]; - if (!m_preserveAlpha) { - sumA += qAlpha(s) * k; - } - sumR += qRed(s) * k; - sumG += qGreen(s) * k; - sumB += qBlue(s) * k; - } - if (m_preserveAlpha) { - dst[dstPixel] = qRgba(qBound(0, static_cast(sumR / divisor + m_bias), 255), - qBound(0, static_cast(sumG / divisor + m_bias), 255), - qBound(0, static_cast(sumB / divisor + m_bias), 255), - qAlpha(dst[dstPixel])); - } else { - dst[dstPixel] = qRgba(qBound(0, static_cast(sumR / divisor + m_bias), 255), - qBound(0, static_cast(sumG / divisor + m_bias), 255), - qBound(0, static_cast(sumB / divisor + m_bias), 255), - qBound(0, static_cast(sumA / divisor + m_bias), 255)); - } - } - } - - return result; -} - -bool ConvolveMatrixEffect::load(const KoXmlElement &element, const KoFilterEffectLoadingContext &/*context*/) -{ - if (element.tagName() != id()) { - return false; - } - - setDefaults(); - - if (element.hasAttribute("order")) { - QString orderStr = element.attribute("order"); - QStringList params = orderStr.replace(',', ' ').simplified().split(' '); - switch (params.count()) { - case 1: - m_order.rx() = qMax(1, params[0].toInt()); - m_order.ry() = m_order.x(); - break; - case 2: - m_order.rx() = qMax(1, params[0].toInt()); - m_order.ry() = qMax(1, params[1].toInt()); - break; - } - } - if (element.hasAttribute("kernelMatrix")) { - QString matrixStr = element.attribute("kernelMatrix"); - // values are separated by whitespace and/or comma - QStringList values = matrixStr.replace(',', ' ').simplified().split(' '); - if (values.count() == m_order.x()*m_order.y()) { - m_kernel.resize(values.count()); - for (int i = 0; i < values.count(); ++i) { - m_kernel[i] = values[i].toDouble(); - } - } else { - m_kernel.resize(m_order.x()*m_order.y()); - for (int i = 0; i < m_kernel.size(); ++i) { - m_kernel[i] = 0.0; - } - } - } - if (element.hasAttribute("divisor")) { - m_divisor = element.attribute("divisor").toDouble(); - } - if (element.hasAttribute("bias")) { - m_bias = element.attribute("bias").toDouble(); - } - if (element.hasAttribute("targetX")) { - m_target.rx() = qBound(0, element.attribute("targetX").toInt(), m_order.x()); - } - if (element.hasAttribute("targetY")) { - m_target.ry() = qBound(0, element.attribute("targetY").toInt(), m_order.y()); - } - if (element.hasAttribute("edgeMode")) { - QString mode = element.attribute("edgeMode"); - if (mode == "wrap") { - m_edgeMode = Wrap; - } else if (mode == "none") { - m_edgeMode = None; - } else { - m_edgeMode = Duplicate; - } - } - if (element.hasAttribute("kernelUnitLength")) { - QString kernelUnitLengthStr = element.attribute("kernelUnitLength"); - QStringList params = kernelUnitLengthStr.replace(',', ' ').simplified().split(' '); - switch (params.count()) { - case 1: - m_kernelUnitLength.rx() = params[0].toDouble(); - m_kernelUnitLength.ry() = m_kernelUnitLength.x(); - break; - case 2: - m_kernelUnitLength.rx() = params[0].toDouble(); - m_kernelUnitLength.ry() = params[1].toDouble(); - break; - } - } - if (element.hasAttribute("preserveAlpha")) { - m_preserveAlpha = (element.attribute("preserveAlpha") == "true"); - } - - return true; -} - -void ConvolveMatrixEffect::save(KoXmlWriter &writer) -{ - writer.startElement(ConvolveMatrixEffectId); - - saveCommonAttributes(writer); - - if (m_order.x() == m_order.y()) { - writer.addAttribute("order", QString("%1").arg(m_order.x())); - } else { - writer.addAttribute("order", QString("%1 %2").arg(m_order.x()).arg(m_order.y())); - } - QString kernel; - for (int i = 0; i < m_kernel.size(); ++i) { - kernel += QString("%1 ").arg(m_kernel[i]); - } - writer.addAttribute("kernelMatrix", kernel); - writer.addAttribute("divisor", QString("%1").arg(m_divisor)); - if (m_bias != 0.0) { - writer.addAttribute("bias", QString("%1").arg(m_bias)); - } - writer.addAttribute("targetX", QString("%1").arg(m_target.x())); - writer.addAttribute("targetY", QString("%1").arg(m_target.y())); - switch (m_edgeMode) { - case Wrap: - writer.addAttribute("edgeMode", "wrap"); - break; - case None: - writer.addAttribute("edgeMode", "none"); - break; - case Duplicate: - // fall through as it is the default - Q_FALLTHROUGH(); - default: - ; - } - writer.addAttribute("kernelUnitLength", QString("%1 %2").arg(m_kernelUnitLength.x()).arg(m_kernelUnitLength.y())); - if (m_preserveAlpha) { - writer.addAttribute("preserveAlpha", "true"); - } - - writer.endElement(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/ConvolveMatrixEffect.h b/plugins/tools/karbonplugins/filtereffects/ConvolveMatrixEffect.h deleted file mode 100644 index ea673e35cc..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ConvolveMatrixEffect.h +++ /dev/null @@ -1,106 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 CONVOLVEMATRIXEFFECT_H -#define CONVOLVEMATRIXEFFECT_H - -#include "KoFilterEffect.h" -#include -#include - -#define ConvolveMatrixEffectId "feConvolveMatrix" - -class KoFilterEffectLoadingContext; - -/// A convolve matrix effect -class ConvolveMatrixEffect : public KoFilterEffect -{ -public: - /// Edge mode, i.e. how the kernel behaves at image edges - enum EdgeMode { - Duplicate, ///< duplicates colors at the edges - Wrap, ///< takes the colors at the opposite edge - None ///< uses values of zero for each color channel - }; - - ConvolveMatrixEffect(); - - /// Returns the order of the kernel matrix - QPoint order() const; - - /// Sets the order of the kernel matrix - void setOrder(const QPoint &order); - - /// Returns the kernel matrix - QVector kernel() const; - - /// Sets the kernel matrix - void setKernel(const QVector &kernel); - - /// Returns the divisor - qreal divisor() const; - - /// Sets the divisor - void setDivisor(qreal divisor); - - /// Returns the bias - qreal bias() const; - - /// Sets the bias - void setBias(qreal bias); - - /// Returns the target cell within the kernel - QPoint target() const; - - /// Sets the target cell within the kernel - void setTarget(const QPoint &target); - - /// Returns edge mode - EdgeMode edgeMode() const; - - /// Sets the edge mode - void setEdgeMode(EdgeMode edgeMode); - - /// Returns if alpha values are preserved - bool isPreserveAlphaEnabled() const; - - /// Enables/disables preserving alpha values - void enablePreserveAlpha(bool on); - - /// reimplemented from KoFilterEffect - QImage processImage(const QImage &image, const KoFilterEffectRenderContext &context) const override; - /// reimplemented from KoFilterEffect - bool load(const KoXmlElement &element, const KoFilterEffectLoadingContext &context) override; - /// reimplemented from KoFilterEffect - void save(KoXmlWriter &writer) override; - -private: - void setDefaults(); - - QPoint m_order; ///< the dimension of the kernel - QVector m_kernel; ///< the kernel - qreal m_divisor; ///< the divisor - qreal m_bias; ///< the bias - QPoint m_target; ///< target cell within the kernel - EdgeMode m_edgeMode; ///< the edge mode - QPointF m_kernelUnitLength; ///< the kernel unit length - bool m_preserveAlpha; ///< indicates if original alpha values are left intact -}; - -#endif // CONVOLVEMATRIXEFFECT_H diff --git a/plugins/tools/karbonplugins/filtereffects/ConvolveMatrixEffectConfigWidget.cpp b/plugins/tools/karbonplugins/filtereffects/ConvolveMatrixEffectConfigWidget.cpp deleted file mode 100644 index 7d8a7e8c2f..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ConvolveMatrixEffectConfigWidget.cpp +++ /dev/null @@ -1,262 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "ConvolveMatrixEffectConfigWidget.h" -#include "ConvolveMatrixEffect.h" -#include "KoFilterEffect.h" -#include "MatrixDataModel.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kis_double_parse_spin_box.h" -#include "kis_int_parse_spin_box.h" - -ConvolveMatrixEffectConfigWidget::ConvolveMatrixEffectConfigWidget(QWidget *parent) - : KoFilterEffectConfigWidgetBase(parent) - , m_effect(0) -{ - QGridLayout *g = new QGridLayout(this); - - m_edgeMode = new KComboBox(this); - m_edgeMode->addItem(i18n("Duplicate")); - m_edgeMode->addItem(i18n("Wrap")); - m_edgeMode->addItem(i18n("None")); - g->addWidget(new QLabel(i18n("Edge mode:"), this), 0, 0); - g->addWidget(m_edgeMode, 0, 1, 1, 3); - - m_orderX = new KisIntParseSpinBox(this); - m_orderX->setRange(1, 30); - m_orderY = new KisIntParseSpinBox(this); - m_orderY->setRange(1, 30); - g->addWidget(new QLabel(i18n("Kernel size:"), this), 1, 0); - g->addWidget(m_orderX, 1, 1); - g->addWidget(new QLabel("X", this), 1, 2, Qt::AlignHCenter); - g->addWidget(m_orderY, 1, 3); - - m_targetX = new KisIntParseSpinBox(this); - m_targetX->setRange(0, 30); - m_targetY = new KisIntParseSpinBox(this); - m_targetY->setRange(0, 30); - g->addWidget(new QLabel(i18n("Target point:"), this), 2, 0); - g->addWidget(m_targetX, 2, 1); - g->addWidget(new QLabel("X", this), 2, 2, Qt::AlignHCenter); - g->addWidget(m_targetY, 2, 3); - - m_divisor = new KisDoubleParseSpinBox(this); - m_bias = new KisDoubleParseSpinBox(this); - g->addWidget(new QLabel(i18n("Divisor:"), this), 3, 0); - g->addWidget(m_divisor, 3, 1); - g->addWidget(new QLabel(i18n("Bias:"), this), 3, 2); - g->addWidget(m_bias, 3, 3); - - m_preserveAlpha = new QCheckBox(i18n("Preserve alpha"), this); - g->addWidget(m_preserveAlpha, 4, 1, 1, 3); - - QPushButton *kernelButton = new QPushButton(i18n("Edit kernel"), this); - g->addWidget(kernelButton, 5, 0, 1, 4); - - setLayout(g); - - connect(m_edgeMode, SIGNAL(currentIndexChanged(int)), this, SLOT(edgeModeChanged(int))); - connect(m_orderX, SIGNAL(valueChanged(int)), this, SLOT(orderChanged(int))); - connect(m_orderY, SIGNAL(valueChanged(int)), this, SLOT(orderChanged(int))); - connect(m_targetX, SIGNAL(valueChanged(int)), this, SLOT(targetChanged(int))); - connect(m_targetY, SIGNAL(valueChanged(int)), this, SLOT(targetChanged(int))); - connect(m_divisor, SIGNAL(valueChanged(double)), this, SLOT(divisorChanged(double))); - connect(m_bias, SIGNAL(valueChanged(double)), this, SLOT(biasChanged(double))); - connect(kernelButton, SIGNAL(clicked(bool)), this, SLOT(editKernel())); - connect(m_preserveAlpha, SIGNAL(toggled(bool)), this, SLOT(preserveAlphaChanged(bool))); - - m_matrixModel = new MatrixDataModel(this); -} - -bool ConvolveMatrixEffectConfigWidget::editFilterEffect(KoFilterEffect *filterEffect) -{ - m_effect = dynamic_cast(filterEffect); - if (!m_effect) { - return false; - } - - m_edgeMode->blockSignals(true); - m_edgeMode->setCurrentIndex(m_effect->edgeMode()); - m_edgeMode->blockSignals(false); - m_orderX->blockSignals(true); - m_orderX->setValue(m_effect->order().x()); - m_orderX->blockSignals(false); - m_orderY->blockSignals(true); - m_orderY->setValue(m_effect->order().y()); - m_orderY->blockSignals(false); - m_targetX->blockSignals(true); - m_targetX->setMaximum(m_orderX->value()); - m_targetX->setValue(m_effect->target().x() + 1); - m_targetX->blockSignals(false); - m_targetY->blockSignals(true); - m_targetY->setMaximum(m_orderY->value()); - m_targetY->setValue(m_effect->target().y() + 1); - m_targetY->blockSignals(false); - m_divisor->blockSignals(true); - m_divisor->setValue(m_effect->divisor()); - m_divisor->blockSignals(false); - m_bias->blockSignals(true); - m_bias->setValue(m_effect->bias()); - m_bias->blockSignals(false); - m_preserveAlpha->blockSignals(true); - m_preserveAlpha->setChecked(m_effect->isPreserveAlphaEnabled()); - m_preserveAlpha->blockSignals(false); - - return true; -} - -void ConvolveMatrixEffectConfigWidget::edgeModeChanged(int id) -{ - if (!m_effect) { - return; - } - - switch (id) { - case ConvolveMatrixEffect::Duplicate: - m_effect->setEdgeMode(ConvolveMatrixEffect::Duplicate); - break; - case ConvolveMatrixEffect::Wrap: - m_effect->setEdgeMode(ConvolveMatrixEffect::Wrap); - break; - case ConvolveMatrixEffect::None: - m_effect->setEdgeMode(ConvolveMatrixEffect::None); - break; - } - emit filterChanged(); -} - -void ConvolveMatrixEffectConfigWidget::orderChanged(int) -{ - if (!m_effect) { - return; - } - - QPoint newOrder(m_orderX->value(), m_orderY->value()); - QPoint oldOrder = m_effect->order(); - if (newOrder != oldOrder) { - m_effect->setOrder(newOrder); - emit filterChanged(); - } - - m_targetX->setMaximum(newOrder.x()); - m_targetY->setMaximum(newOrder.y()); -} - -void ConvolveMatrixEffectConfigWidget::targetChanged(int) -{ - if (!m_effect) { - return; - } - - QPoint newTarget(m_targetX->value() - 1, m_targetY->value() - 1); - QPoint oldTarget = m_effect->target(); - if (newTarget != oldTarget) { - m_effect->setTarget(newTarget); - emit filterChanged(); - } -} - -void ConvolveMatrixEffectConfigWidget::divisorChanged(double divisor) -{ - if (!m_effect) { - return; - } - - if (divisor != m_effect->divisor()) { - m_effect->setDivisor(divisor); - emit filterChanged(); - } -} - -void ConvolveMatrixEffectConfigWidget::biasChanged(double bias) -{ - if (!m_effect) { - return; - } - - if (bias != m_effect->bias()) { - m_effect->setBias(bias); - emit filterChanged(); - } -} - -void ConvolveMatrixEffectConfigWidget::preserveAlphaChanged(bool checked) -{ - if (!m_effect) { - return; - } - - m_effect->enablePreserveAlpha(checked); - emit filterChanged(); -} - -void ConvolveMatrixEffectConfigWidget::editKernel() -{ - if (!m_effect) { - return; - } - - QVector oldKernel = m_effect->kernel(); - QPoint kernelSize = m_effect->order(); - m_matrixModel->setMatrix(oldKernel, kernelSize.y(), kernelSize.x()); - connect(m_matrixModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(kernelChanged())); - - QPointer dlg = new QDialog(this); - QTableView *table = new QTableView(dlg); - table->setModel(m_matrixModel); - table->horizontalHeader()->hide(); - table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); - table->verticalHeader()->hide(); - table->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); - QVBoxLayout *mainLayout = new QVBoxLayout; - dlg->setLayout(mainLayout); - mainLayout->addWidget(table); - if (dlg->exec() == QDialog::Accepted) { - m_effect->setKernel(m_matrixModel->matrix()); - emit filterChanged(); - } else { - m_effect->setKernel(oldKernel); - } - delete dlg; - - disconnect(m_matrixModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(kernelChanged())); -} - -void ConvolveMatrixEffectConfigWidget::kernelChanged() -{ - if (!m_effect) { - return; - } - - m_effect->setKernel(m_matrixModel->matrix()); - emit filterChanged(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/ConvolveMatrixEffectConfigWidget.h b/plugins/tools/karbonplugins/filtereffects/ConvolveMatrixEffectConfigWidget.h deleted file mode 100644 index e32bbf9fac..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ConvolveMatrixEffectConfigWidget.h +++ /dev/null @@ -1,64 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 CONVOLVEMATRIXEFFECTCONFIGWIDGET_H -#define CONVOLVEMATRIXEFFECTCONFIGWIDGET_H - -#include "KoFilterEffectConfigWidgetBase.h" - -class QDoubleSpinBox; -class KoFilterEffect; -class ConvolveMatrixEffect; -class KComboBox; -class QSpinBox; -class QCheckBox; -class MatrixDataModel; - -class ConvolveMatrixEffectConfigWidget : public KoFilterEffectConfigWidgetBase -{ - Q_OBJECT -public: - explicit ConvolveMatrixEffectConfigWidget(QWidget *parent = 0); - - /// reimplemented from KoFilterEffectConfigWidgetBase - bool editFilterEffect(KoFilterEffect *filterEffect) override; - -private Q_SLOTS: - void orderChanged(int value); - void targetChanged(int value); - void divisorChanged(double divisor); - void biasChanged(double bias); - void edgeModeChanged(int mode); - void preserveAlphaChanged(bool checked); - void editKernel(); - void kernelChanged(); -private: - ConvolveMatrixEffect *m_effect; - KComboBox *m_edgeMode; - QSpinBox *m_orderX; - QSpinBox *m_orderY; - QSpinBox *m_targetX; - QSpinBox *m_targetY; - QDoubleSpinBox *m_divisor; - QDoubleSpinBox *m_bias; - QCheckBox *m_preserveAlpha; - MatrixDataModel *m_matrixModel; -}; - -#endif // CONVOLVEMATRIXEFFECTCONFIGWIDGET_H diff --git a/plugins/tools/karbonplugins/filtereffects/ConvolveMatrixEffectFactory.cpp b/plugins/tools/karbonplugins/filtereffects/ConvolveMatrixEffectFactory.cpp deleted file mode 100644 index b038c2f9de..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ConvolveMatrixEffectFactory.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "ConvolveMatrixEffectFactory.h" -#include "ConvolveMatrixEffect.h" -#include "ConvolveMatrixEffectConfigWidget.h" - -#include - -ConvolveMatrixEffectFactory::ConvolveMatrixEffectFactory() - : KoFilterEffectFactoryBase(ConvolveMatrixEffectId, i18n("Convolve Matrix")) -{ -} - -KoFilterEffect *ConvolveMatrixEffectFactory::createFilterEffect() const -{ - return new ConvolveMatrixEffect(); -} - -KoFilterEffectConfigWidgetBase *ConvolveMatrixEffectFactory::createConfigWidget() const -{ - return new ConvolveMatrixEffectConfigWidget(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/ConvolveMatrixEffectFactory.h b/plugins/tools/karbonplugins/filtereffects/ConvolveMatrixEffectFactory.h deleted file mode 100644 index 437a065c6a..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ConvolveMatrixEffectFactory.h +++ /dev/null @@ -1,35 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 CONVOLVEMATRIXEFFECTFACTORY_H -#define CONVOLVEMATRIXEFFECTFACTORY_H - -#include "KoFilterEffectFactoryBase.h" - -class KoFilterEffect; - -class ConvolveMatrixEffectFactory : public KoFilterEffectFactoryBase -{ -public: - ConvolveMatrixEffectFactory(); - KoFilterEffect *createFilterEffect() const override; - KoFilterEffectConfigWidgetBase *createConfigWidget() const override; -}; - -#endif // CONVOLVEMATRIXEFFECTFACTORY_H diff --git a/plugins/tools/karbonplugins/filtereffects/FilterEffectsPlugin.cpp b/plugins/tools/karbonplugins/filtereffects/FilterEffectsPlugin.cpp deleted file mode 100644 index 25511c2388..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/FilterEffectsPlugin.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* This file is part of the KDE project -* Copyright (C) 2009 Jan Hambrecht -* -* 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 "FilterEffectsPlugin.h" -#include "BlurEffectFactory.h" -#include "OffsetEffectFactory.h" -#include "MergeEffectFactory.h" -#include "ColorMatrixEffectFactory.h" -#include "FloodEffectFactory.h" -#include "CompositeEffectFactory.h" -#include "BlendEffectFactory.h" -#include "ComponentTransferEffectFactory.h" -#include "ImageEffectFactory.h" -#include "MorphologyEffectFactory.h" -#include "ConvolveMatrixEffectFactory.h" - -#include "KoFilterEffectRegistry.h" - -#include - -K_PLUGIN_FACTORY_WITH_JSON(FilterEffectsPluginFacory, "karbon_filtereffects.json", registerPlugin();) - -FilterEffectsPlugin::FilterEffectsPlugin(QObject *parent, const QList &) - : QObject(parent) -{ - KoFilterEffectRegistry::instance()->add(new BlurEffectFactory()); - KoFilterEffectRegistry::instance()->add(new OffsetEffectFactory()); - KoFilterEffectRegistry::instance()->add(new MergeEffectFactory()); - KoFilterEffectRegistry::instance()->add(new ColorMatrixEffectFactory()); - KoFilterEffectRegistry::instance()->add(new FloodEffectFactory()); - KoFilterEffectRegistry::instance()->add(new CompositeEffectFactory()); - KoFilterEffectRegistry::instance()->add(new BlendEffectFactory()); - KoFilterEffectRegistry::instance()->add(new ComponentTransferEffectFactory()); - KoFilterEffectRegistry::instance()->add(new ImageEffectFactory()); - KoFilterEffectRegistry::instance()->add(new MorphologyEffectFactory()); - KoFilterEffectRegistry::instance()->add(new ConvolveMatrixEffectFactory()); -} -#include diff --git a/plugins/tools/karbonplugins/filtereffects/FilterEffectsPlugin.h b/plugins/tools/karbonplugins/filtereffects/FilterEffectsPlugin.h deleted file mode 100644 index c29db0df23..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/FilterEffectsPlugin.h +++ /dev/null @@ -1,33 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2009 Jan Hambrecht - * - * 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 KARBONFILTEREFFECTSPLUGIN_H -#define KARBONFILTEREFFECTSPLUGIN_H - -#include - -class FilterEffectsPlugin : public QObject -{ - Q_OBJECT -public: - FilterEffectsPlugin(QObject *parent, const QList &); - ~FilterEffectsPlugin() override {} -}; - -#endif // KARBONFILTEREFFECTSPLUGIN_H diff --git a/plugins/tools/karbonplugins/filtereffects/FloodEffect.cpp b/plugins/tools/karbonplugins/filtereffects/FloodEffect.cpp deleted file mode 100644 index 7dd82dd16b..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/FloodEffect.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "FloodEffect.h" -#include "KoFilterEffectRenderContext.h" -#include "KoViewConverter.h" -#include "KoXmlWriter.h" -#include "KoXmlReader.h" -#include -#include - -FloodEffect::FloodEffect() - : KoFilterEffect(FloodEffectId, i18n("Flood fill")) - , m_color(Qt::black) -{ -} - -QColor FloodEffect::floodColor() const -{ - return m_color; -} - -void FloodEffect::setFloodColor(const QColor &color) -{ - m_color = color; -} - -QImage FloodEffect::processImage(const QImage &image, const KoFilterEffectRenderContext &context) const -{ - QImage result = image; - QPainter painter(&result); - painter.fillRect(context.filterRegion(), m_color); - - return result; -} - -bool FloodEffect::load(const KoXmlElement &element, const KoFilterEffectLoadingContext &) -{ - if (element.tagName() != id()) { - return false; - } - - m_color = Qt::black; - - if (element.hasAttribute("flood-color")) { - QString colorStr = element.attribute("flood-color").trimmed(); - if (colorStr.startsWith(QLatin1String("rgb("))) { - QStringList channels = colorStr.mid(4, colorStr.length() - 5).split(','); - float r = channels[0].toDouble(); - if (channels[0].contains('%')) { - r /= 100.0; - } else { - r /= 255.0; - } - float g = channels[1].toDouble(); - if (channels[1].contains('%')) { - g /= 100.0; - } else { - g /= 255.0; - } - float b = channels[2].toDouble(); - if (channels[2].contains('%')) { - b /= 100.0; - } else { - b /= 255.0; - } - m_color.setRgbF(r, g, b); - - } else { - m_color.setNamedColor(colorStr); - } - // TODO: add support for currentColor - } - - if (element.hasAttribute("flood-opacity")) { - m_color.setAlphaF(element.attribute("flood-opacity").toDouble()); - } - - return true; -} - -void FloodEffect::save(KoXmlWriter &writer) -{ - writer.startElement(FloodEffectId); - - saveCommonAttributes(writer); - - writer.addAttribute("flood-color", m_color.name()); - if (m_color.alpha() < 255) { - writer.addAttribute("flood-opacity", QString("%1").arg(m_color.alphaF())); - } - - writer.endElement(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/FloodEffect.h b/plugins/tools/karbonplugins/filtereffects/FloodEffect.h deleted file mode 100644 index 724fea492d..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/FloodEffect.h +++ /dev/null @@ -1,50 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 FLOODEFFECT_H -#define FLOODEFFECT_H - -#include "KoFilterEffect.h" -#include - -#define FloodEffectId "feFlood" - -class KoFilterEffectLoadingContext; - -/// A flood fill effect -class FloodEffect : public KoFilterEffect -{ -public: - FloodEffect(); - - QColor floodColor() const; - void setFloodColor(const QColor &color); - - /// reimplemented from KoFilterEffect - QImage processImage(const QImage &image, const KoFilterEffectRenderContext &context) const override; - /// reimplemented from KoFilterEffect - bool load(const KoXmlElement &element, const KoFilterEffectLoadingContext &context) override; - /// reimplemented from KoFilterEffect - void save(KoXmlWriter &writer) override; - -private: - QColor m_color; -}; - -#endif // FLOODEFFECT_H diff --git a/plugins/tools/karbonplugins/filtereffects/FloodEffectConfigWidget.cpp b/plugins/tools/karbonplugins/filtereffects/FloodEffectConfigWidget.cpp deleted file mode 100644 index 3517d6ce26..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/FloodEffectConfigWidget.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "FloodEffectConfigWidget.h" -#include "FloodEffect.h" -#include "KoFilterEffect.h" - -#include - -#include - -#include -#include -#include - -FloodEffectConfigWidget::FloodEffectConfigWidget(QWidget *parent) - : KoFilterEffectConfigWidgetBase(parent) - , m_effect(0) -{ - QGridLayout *g = new QGridLayout(this); - - g->addWidget(new QLabel(i18n("Flood color"), this), 0, 0); - QToolButton *button = new QToolButton(this); - g->addWidget(button, 0, 1); - m_actionStopColor = new KoColorPopupAction(this); - button->setDefaultAction(m_actionStopColor); - setLayout(g); - - connect(m_actionStopColor, SIGNAL(colorChanged(KoColor)), this, SLOT(colorChanged())); -} - -bool FloodEffectConfigWidget::editFilterEffect(KoFilterEffect *filterEffect) -{ - m_effect = dynamic_cast(filterEffect); - if (!m_effect) { - return false; - } - - m_actionStopColor->setCurrentColor(m_effect->floodColor()); - return true; -} - -void FloodEffectConfigWidget::colorChanged() -{ - if (!m_effect) { - return; - } - - m_effect->setFloodColor(m_actionStopColor->currentColor()); - emit filterChanged(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/FloodEffectConfigWidget.h b/plugins/tools/karbonplugins/filtereffects/FloodEffectConfigWidget.h deleted file mode 100644 index 40aa5a988c..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/FloodEffectConfigWidget.h +++ /dev/null @@ -1,46 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 FLOODEFFECTCONFIGWIDGET_H -#define FLOODEFFECTCONFIGWIDGET_H - -#include "KoFilterEffectConfigWidgetBase.h" - -class KoFilterEffect; -class FloodEffect; -class KoColorPopupAction; - -class FloodEffectConfigWidget : public KoFilterEffectConfigWidgetBase -{ - Q_OBJECT -public: - explicit FloodEffectConfigWidget(QWidget *parent = 0); - - /// reimplemented from KoFilterEffectConfigWidgetBase - bool editFilterEffect(KoFilterEffect *filterEffect) override; - -private Q_SLOTS: - void colorChanged(); - -private: - FloodEffect *m_effect; - KoColorPopupAction *m_actionStopColor; -}; - -#endif // FLOODEFFECTCONFIGWIDGET_H diff --git a/plugins/tools/karbonplugins/filtereffects/FloodEffectFactory.cpp b/plugins/tools/karbonplugins/filtereffects/FloodEffectFactory.cpp deleted file mode 100644 index a59005b4c9..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/FloodEffectFactory.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "FloodEffectFactory.h" -#include "FloodEffect.h" -#include "FloodEffectConfigWidget.h" - -#include - -FloodEffectFactory::FloodEffectFactory() - : KoFilterEffectFactoryBase(FloodEffectId, i18n("Flood fill")) -{ -} - -KoFilterEffect *FloodEffectFactory::createFilterEffect() const -{ - return new FloodEffect(); -} - -KoFilterEffectConfigWidgetBase *FloodEffectFactory::createConfigWidget() const -{ - return new FloodEffectConfigWidget(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/FloodEffectFactory.h b/plugins/tools/karbonplugins/filtereffects/FloodEffectFactory.h deleted file mode 100644 index 432a7c6362..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/FloodEffectFactory.h +++ /dev/null @@ -1,35 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 FLOODEFFECTFACTORY_H -#define FLOODEFFECTFACTORY_H - -#include "KoFilterEffectFactoryBase.h" - -class KoFilterEffect; - -class FloodEffectFactory : public KoFilterEffectFactoryBase -{ -public: - FloodEffectFactory(); - KoFilterEffect *createFilterEffect() const override; - KoFilterEffectConfigWidgetBase *createConfigWidget() const override; -}; - -#endif // FLOODEFFECTFACTORY_H diff --git a/plugins/tools/karbonplugins/filtereffects/ImageEffect.cpp b/plugins/tools/karbonplugins/filtereffects/ImageEffect.cpp deleted file mode 100644 index 62a71d6050..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ImageEffect.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "ImageEffect.h" - -#include "KoFilterEffectRenderContext.h" -#include "KoFilterEffectLoadingContext.h" -#include "KoViewConverter.h" -#include "KoXmlWriter.h" -#include "KoXmlReader.h" - -#include -#include -#include -#include - -#include - -ImageEffect::ImageEffect() - : KoFilterEffect(ImageEffectId, i18n("Image")) -{ - setRequiredInputCount(0); - setMaximalInputCount(0); -} - -QImage ImageEffect::image() const -{ - return m_image; -} - -void ImageEffect::setImage(const QImage &image) -{ - m_image = image; -} - -QImage ImageEffect::processImage(const QImage &image, const KoFilterEffectRenderContext &context) const -{ - QImage result(image.size(), QImage::Format_ARGB32_Premultiplied); - result.fill(qRgba(0, 0, 0, 0)); - - QPainter p(&result); - p.drawImage(context.filterRegion(), m_image); - return result; -} - -bool ImageEffect::load(const KoXmlElement &element, const KoFilterEffectLoadingContext &context) -{ - if (element.tagName() != id()) { - return false; - } - - QString href = element.attribute("xlink:href"); - if (href.startsWith(QLatin1String("data:"))) { - int start = href.indexOf("base64,"); - if (start <= 0 || !m_image.loadFromData(QByteArray::fromBase64(href.mid(start + 7).toLatin1()))) { - return false; - } - } else if (!m_image.load(context.pathFromHref(href))) { - return false; - } - - return true; -} - -void ImageEffect::save(KoXmlWriter &writer) -{ - writer.startElement(ImageEffectId); - - saveCommonAttributes(writer); - - QByteArray ba; - QBuffer buffer(&ba); - buffer.open(QIODevice::WriteOnly); - if (m_image.save(&buffer, "PNG")) { - writer.addAttribute("xlink:href", "data:image/png;base64," + ba.toBase64()); - } - - writer.endElement(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/ImageEffect.h b/plugins/tools/karbonplugins/filtereffects/ImageEffect.h deleted file mode 100644 index b81ede9a72..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ImageEffect.h +++ /dev/null @@ -1,52 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 IMAGEEFFECT_H -#define IMAGEEFFECT_H - -#include "KoFilterEffect.h" -#include - -#define ImageEffectId "feImage" - -/// An image offset effect -class ImageEffect : public KoFilterEffect -{ -public: - ImageEffect(); - - /// Returns the image - QImage image() const; - - /// Sets the image - void setImage(const QImage &image); - - /// reimplemented from KoFilterEffect - QImage processImage(const QImage &image, const KoFilterEffectRenderContext &context) const override; - /// reimplemented from KoFilterEffect - bool load(const KoXmlElement &element, const KoFilterEffectLoadingContext &context) override; - /// reimplemented from KoFilterEffect - void save(KoXmlWriter &writer) override; - -private: - QImage m_image; - QRectF m_bound; -}; - -#endif // IMAGEEFFECT_H diff --git a/plugins/tools/karbonplugins/filtereffects/ImageEffectConfigWidget.cpp b/plugins/tools/karbonplugins/filtereffects/ImageEffectConfigWidget.cpp deleted file mode 100644 index 32d1957802..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ImageEffectConfigWidget.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "ImageEffectConfigWidget.h" -#include "ImageEffect.h" - -#include "KoFilterEffect.h" -#include - -#include - -#include -#include -#include -#include -#include - -ImageEffectConfigWidget::ImageEffectConfigWidget(QWidget *parent) - : KoFilterEffectConfigWidgetBase(parent) - , m_effect(0) -{ - QGridLayout *g = new QGridLayout(this); - - m_image = new QLabel(this); - QPushButton *button = new QPushButton(i18n("Select image..."), this); - - g->addWidget(m_image, 0, 0, Qt::AlignCenter); - g->addWidget(button, 0, 1); - - setLayout(g); - - connect(button, SIGNAL(clicked()), this, SLOT(selectImage())); -} - -bool ImageEffectConfigWidget::editFilterEffect(KoFilterEffect *filterEffect) -{ - m_effect = dynamic_cast(filterEffect); - if (!m_effect) { - return false; - } - - m_image->setPixmap(QPixmap::fromImage(m_effect->image().scaledToWidth(80))); - - return true; -} - -void ImageEffectConfigWidget::selectImage() -{ - if (!m_effect) { - return; - } - - QStringList imageFilter; - // add filters for all formats supported by QImage - Q_FOREACH (const QByteArray &format, QImageReader::supportedImageFormats()) { - imageFilter << QString("image/") + format; - } - - KoFileDialog dialog(0, KoFileDialog::OpenFile, "OpenDocument"); - dialog.setCaption(i18n("Select image")); - dialog.setImageFilters(); - - QString fname = dialog.filename(); - - if (fname.isEmpty()) { - return; - } - - QImage newImage; - if (!newImage.load(fname)) { - return; - } - - m_effect->setImage(newImage); - editFilterEffect(m_effect); - - emit filterChanged(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/ImageEffectConfigWidget.h b/plugins/tools/karbonplugins/filtereffects/ImageEffectConfigWidget.h deleted file mode 100644 index dfe635723d..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ImageEffectConfigWidget.h +++ /dev/null @@ -1,46 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 IMAGEEFFECTCONFIGWIDGET_H -#define IMAGEEFFECTCONFIGWIDGET_H - -#include "KoFilterEffectConfigWidgetBase.h" - -class KoFilterEffect; -class ImageEffect; -class QLabel; - -class ImageEffectConfigWidget : public KoFilterEffectConfigWidgetBase -{ - Q_OBJECT -public: - explicit ImageEffectConfigWidget(QWidget *parent = 0); - - /// reimplemented from KoFilterEffectConfigWidgetBase - bool editFilterEffect(KoFilterEffect *filterEffect) override; - -private Q_SLOTS: - void selectImage(); - -private: - ImageEffect *m_effect; - QLabel *m_image; -}; - -#endif // IMAGEEFFECTCONFIGWIDGET_H diff --git a/plugins/tools/karbonplugins/filtereffects/ImageEffectFactory.cpp b/plugins/tools/karbonplugins/filtereffects/ImageEffectFactory.cpp deleted file mode 100644 index d1d381e4a1..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ImageEffectFactory.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "ImageEffectFactory.h" -#include "ImageEffect.h" -#include "ImageEffectConfigWidget.h" -#include - -ImageEffectFactory::ImageEffectFactory() - : KoFilterEffectFactoryBase(ImageEffectId, i18n("Image")) -{ -} - -KoFilterEffect *ImageEffectFactory::createFilterEffect() const -{ - return new ImageEffect(); -} - -KoFilterEffectConfigWidgetBase *ImageEffectFactory::createConfigWidget() const -{ - return new ImageEffectConfigWidget(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/ImageEffectFactory.h b/plugins/tools/karbonplugins/filtereffects/ImageEffectFactory.h deleted file mode 100644 index 22e0192ee4..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/ImageEffectFactory.h +++ /dev/null @@ -1,35 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 IMAGEEFFECTFACTORY_H -#define IMAGEEFFECTFACTORY_H - -#include "KoFilterEffectFactoryBase.h" - -class KoFilterEffect; - -class ImageEffectFactory : public KoFilterEffectFactoryBase -{ -public: - ImageEffectFactory(); - KoFilterEffect *createFilterEffect() const override; - KoFilterEffectConfigWidgetBase *createConfigWidget() const override; -}; - -#endif // IMAGEEFFECTFACTORY_H diff --git a/plugins/tools/karbonplugins/filtereffects/MatrixDataModel.cpp b/plugins/tools/karbonplugins/filtereffects/MatrixDataModel.cpp deleted file mode 100644 index 6c0a699657..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/MatrixDataModel.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* This file is part of the KDE project -* Copyright (c) 2010 Jan Hambrecht -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU Lesser General Public -* License as published by the Free Software Foundation; either -* version 2.1 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 Lesser 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 "MatrixDataModel.h" - -#include "kis_num_parser.h" - -MatrixDataModel::MatrixDataModel(QObject *parent) - : QAbstractTableModel(parent) - , m_rows(0) - , m_cols(0) -{ -} - -void MatrixDataModel::setMatrix(const QVector &matrix, int rows, int cols) -{ - m_matrix = matrix; - m_rows = rows; - m_cols = cols; - Q_ASSERT(m_rows); - Q_ASSERT(m_cols); - Q_ASSERT(m_matrix.count() == m_rows * m_cols); - beginResetModel(); - endResetModel(); -} - -QVector MatrixDataModel::matrix() const -{ - return m_matrix; -} - -int MatrixDataModel::rowCount(const QModelIndex &/*parent*/) const -{ - return m_rows; -} - -int MatrixDataModel::columnCount(const QModelIndex &/*parent*/) const -{ - return m_cols; -} - -QVariant MatrixDataModel::data(const QModelIndex &index, int role) const -{ - int element = index.row() * m_cols + index.column(); - switch (role) { - case Qt::DisplayRole: - case Qt::EditRole: - return QVariant(QString("%1").arg(m_matrix[element], 2)); - break; - default: - return QVariant(); - } -} - -bool MatrixDataModel::setData(const QModelIndex &index, const QVariant &value, int /*role*/) -{ - int element = index.row() * m_cols + index.column(); - bool valid = false; - qreal elementValue = KisNumericParser::parseSimpleMathExpr(value.toString(), &valid); - if (!valid) { - return false; - } - m_matrix[element] = elementValue; - emit dataChanged(index, index); - return true; -} - -Qt::ItemFlags MatrixDataModel::flags(const QModelIndex &/*index*/) const -{ - return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; -} diff --git a/plugins/tools/karbonplugins/filtereffects/MatrixDataModel.h b/plugins/tools/karbonplugins/filtereffects/MatrixDataModel.h deleted file mode 100644 index 65cbc5953b..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/MatrixDataModel.h +++ /dev/null @@ -1,55 +0,0 @@ -/* This file is part of the KDE project -* Copyright (c) 2010 Jan Hambrecht -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU Lesser General Public -* License as published by the Free Software Foundation; either -* version 2.1 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 Lesser 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 MATRIXDATAMODEL_H -#define MATRIXDATAMODEL_H - -#include -#include - -class MatrixDataModel : public QAbstractTableModel -{ -public: - /// Creates a new matrix data model - explicit MatrixDataModel(QObject *parent = 0); - - /// Sets the matrix data and rows/columns to use - void setMatrix(const QVector &matrix, int rows, int cols); - - /// Returns the matrix data - QVector matrix() const; - - // reimplemented - int rowCount(const QModelIndex &/*parent*/) const override; - // reimplemented - int columnCount(const QModelIndex &/*parent*/) const override; - // reimplemented - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - // reimplemented - bool setData(const QModelIndex &index, const QVariant &value, int /*role*/) override; - // reimplemented - Qt::ItemFlags flags(const QModelIndex &/*index*/) const override; - -private: - QVector m_matrix; ///< the matrix data to handle - int m_rows; ///< the number or rows in the matrix - int m_cols; ///< the number of columns in the matrix -}; - -#endif // MATRIXDATAMODEL_H diff --git a/plugins/tools/karbonplugins/filtereffects/MergeEffect.cpp b/plugins/tools/karbonplugins/filtereffects/MergeEffect.cpp deleted file mode 100644 index 2c9acb253a..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/MergeEffect.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "MergeEffect.h" -#include "KoViewConverter.h" -#include "KoXmlWriter.h" -#include "KoXmlReader.h" -#include -#include -#include - -MergeEffect::MergeEffect() - : KoFilterEffect(MergeEffectId, i18n("Merge")) -{ - setRequiredInputCount(2); - setMaximalInputCount(INT_MAX); -} - -QImage MergeEffect::processImage(const QImage &image, const KoFilterEffectRenderContext &/*context*/) const -{ - Q_UNUSED(image); - - return image; -} - -QImage MergeEffect::processImages(const QList &images, const KoFilterEffectRenderContext &/*context*/) const -{ - int imageCount = images.count(); - if (!imageCount) { - return QImage(); - } - - QImage result = images[0]; - if (imageCount == 1) { - return result; - } - - QPainter p(&result); - - for (int i = 1; i < imageCount; ++i) { - p.drawImage(QPoint(), images[i]); - } - - return result; -} - -bool MergeEffect::load(const KoXmlElement &element, const KoFilterEffectLoadingContext &) -{ - if (element.tagName() != id()) { - return false; - } - - int inputCount = inputs().count(); - int inputIndex = 0; - for (KoXmlNode n = element.firstChild(); !n.isNull(); n = n.nextSibling()) { - KoXmlElement node = n.toElement(); - if (node.tagName() == "feMergeNode") { - if (node.hasAttribute("in")) { - if (inputIndex < inputCount) { - setInput(inputIndex, node.attribute("in")); - } else { - addInput(node.attribute("in")); - } - inputIndex++; - } - } - } - - return true; -} - -void MergeEffect::save(KoXmlWriter &writer) -{ - writer.startElement(MergeEffectId); - - saveCommonAttributes(writer); - - Q_FOREACH (const QString &input, inputs()) { - writer.startElement("feMergeNode"); - writer.addAttribute("in", input); - writer.endElement(); - } - - writer.endElement(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/MergeEffect.h b/plugins/tools/karbonplugins/filtereffects/MergeEffect.h deleted file mode 100644 index 93ea481eb5..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/MergeEffect.h +++ /dev/null @@ -1,43 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 MERGEEFFECT_H -#define MERGEEFFECT_H - -#include "KoFilterEffect.h" - -#define MergeEffectId "feMerge" - -/// A gaussian blur effect -class MergeEffect : public KoFilterEffect -{ -public: - MergeEffect(); - - /// reimplemented from KoFilterEffect - QImage processImage(const QImage &image, const KoFilterEffectRenderContext &context) const override; - /// reimplemented from KoFilterEffect - QImage processImages(const QList &images, const KoFilterEffectRenderContext &context) const override; - /// reimplemented from KoFilterEffect - bool load(const KoXmlElement &element, const KoFilterEffectLoadingContext &context) override; - /// reimplemented from KoFilterEffect - void save(KoXmlWriter &writer) override; -}; - -#endif // MERGEEFFECT_H diff --git a/plugins/tools/karbonplugins/filtereffects/MergeEffectConfigWidget.cpp b/plugins/tools/karbonplugins/filtereffects/MergeEffectConfigWidget.cpp deleted file mode 100644 index 09d4118c80..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/MergeEffectConfigWidget.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "MergeEffectConfigWidget.h" -#include "MergeEffect.h" -#include "KoFilterEffect.h" -#include - -MergeEffectConfigWidget::MergeEffectConfigWidget(QWidget *parent) - : KoFilterEffectConfigWidgetBase(parent) - , m_effect(0) -{ - QGridLayout *g = new QGridLayout(this); - - setLayout(g); -} - -bool MergeEffectConfigWidget::editFilterEffect(KoFilterEffect *filterEffect) -{ - m_effect = dynamic_cast(filterEffect); - if (!m_effect) { - return false; - } - - return true; -} diff --git a/plugins/tools/karbonplugins/filtereffects/MergeEffectConfigWidget.h b/plugins/tools/karbonplugins/filtereffects/MergeEffectConfigWidget.h deleted file mode 100644 index 2c22881cd5..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/MergeEffectConfigWidget.h +++ /dev/null @@ -1,43 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 MERGEEFFECTCONFIGWIDGET_H -#define MERGEEFFECTCONFIGWIDGET_H - -#include "KoFilterEffectConfigWidgetBase.h" - -class KoFilterEffect; -class MergeEffect; - -class MergeEffectConfigWidget : public KoFilterEffectConfigWidgetBase -{ - Q_OBJECT -public: - explicit MergeEffectConfigWidget(QWidget *parent = 0); - - /// reimplemented from KoFilterEffectConfigWidgetBase - bool editFilterEffect(KoFilterEffect *filterEffect) override; - -private Q_SLOTS: - -private: - MergeEffect *m_effect; -}; - -#endif // MERGEEFFECTCONFIGWIDGET_H diff --git a/plugins/tools/karbonplugins/filtereffects/MergeEffectFactory.cpp b/plugins/tools/karbonplugins/filtereffects/MergeEffectFactory.cpp deleted file mode 100644 index 82bed73e98..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/MergeEffectFactory.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "MergeEffectFactory.h" -#include "MergeEffect.h" -#include "MergeEffectConfigWidget.h" - -#include - -MergeEffectFactory::MergeEffectFactory() - : KoFilterEffectFactoryBase(MergeEffectId, i18n("Merge")) -{ -} - -KoFilterEffect *MergeEffectFactory::createFilterEffect() const -{ - return new MergeEffect(); -} - -KoFilterEffectConfigWidgetBase *MergeEffectFactory::createConfigWidget() const -{ - return new MergeEffectConfigWidget(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/MergeEffectFactory.h b/plugins/tools/karbonplugins/filtereffects/MergeEffectFactory.h deleted file mode 100644 index b18026e7e4..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/MergeEffectFactory.h +++ /dev/null @@ -1,35 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 MERGEEFFECTFACTORY_H -#define MERGEEFFECTFACTORY_H - -#include "KoFilterEffectFactoryBase.h" - -class KoFilterEffect; - -class MergeEffectFactory : public KoFilterEffectFactoryBase -{ -public: - MergeEffectFactory(); - KoFilterEffect *createFilterEffect() const override; - KoFilterEffectConfigWidgetBase *createConfigWidget() const override; -}; - -#endif // MERGEEFFECTFACTORY_H diff --git a/plugins/tools/karbonplugins/filtereffects/MorphologyEffect.cpp b/plugins/tools/karbonplugins/filtereffects/MorphologyEffect.cpp deleted file mode 100644 index f48bfbbe0f..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/MorphologyEffect.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "MorphologyEffect.h" -#include "KoFilterEffectRenderContext.h" -#include "KoFilterEffectLoadingContext.h" -#include "KoViewConverter.h" -#include "KoXmlWriter.h" -#include "KoXmlReader.h" -#include -#include -#include -#include - -MorphologyEffect::MorphologyEffect() - : KoFilterEffect(MorphologyEffectId, i18n("Morphology")) - , m_radius(0, 0) - , m_operator(Erode) -{ -} - -QPointF MorphologyEffect::morphologyRadius() const -{ - return m_radius; -} - -void MorphologyEffect::setMorphologyRadius(const QPointF &radius) -{ - m_radius = radius; -} - -MorphologyEffect::Operator MorphologyEffect::morphologyOperator() const -{ - return m_operator; -} - -void MorphologyEffect::setMorphologyOperator(Operator op) -{ - m_operator = op; -} - -QImage MorphologyEffect::processImage(const QImage &image, const KoFilterEffectRenderContext &context) const -{ - QImage result = image; - - QPointF radius = context.toUserSpace(m_radius); - - const int rx = static_cast(ceil(radius.x())); - const int ry = static_cast(ceil(radius.y())); - - const int w = result.width(); - const int h = result.height(); - - // setup mask - const int maskSize = (1 + 2 * rx) * (1 + 2 * ry); - int *mask = new int[maskSize]; - int index = 0; - for (int y = -ry; y <= ry; ++y) { - for (int x = -rx; x <= rx; ++x) { - mask[index] = y * w + x; - index++; - } - } - - int dstPixel, srcPixel; - uchar s0, s1, s2, s3; - const uchar *src = image.constBits(); - uchar *dst = result.bits(); - - const QRect roi = context.filterRegion().toRect(); - const int minX = qMax(rx, roi.left()); - const int maxX = qMin(w - rx, roi.right()); - const int minY = qMax(ry, roi.top()); - const int maxY = qMin(h - ry, roi.bottom()); - const int defValue = m_operator == Erode ? 255 : 0; - - uchar *d = 0; - - for (int row = minY; row < maxY; ++row) { - for (int col = minX; col < maxX; ++col) { - dstPixel = row * w + col; - s0 = s1 = s2 = s3 = defValue; - for (int i = 0; i < maskSize; ++i) { - srcPixel = dstPixel + mask[i]; - const uchar *s = &src[4 * srcPixel]; - if (m_operator == Erode) { - s0 = qMin(s0, s[0]); - s1 = qMin(s1, s[1]); - s2 = qMin(s2, s[2]); - s3 = qMin(s3, s[3]); - } else { - s0 = qMax(s0, s[0]); - s1 = qMax(s1, s[1]); - s2 = qMax(s2, s[2]); - s3 = qMax(s3, s[3]); - } - } - d = &dst[4 * dstPixel]; - d[0] = s0; - d[1] = s1; - d[2] = s2; - d[3] = s3; - } - } - - delete [] mask; - - return result; -} - -bool MorphologyEffect::load(const KoXmlElement &element, const KoFilterEffectLoadingContext &context) -{ - if (element.tagName() != id()) { - return false; - } - - m_radius = QPointF(); - m_operator = Erode; - - if (element.hasAttribute("radius")) { - QString radiusStr = element.attribute("radius").trimmed(); - QStringList params = radiusStr.replace(',', ' ').simplified().split(' '); - switch (params.count()) { - case 1: - m_radius.rx() = params[0].toDouble() * 72. / 90.; - m_radius.ry() = m_radius.x(); - break; - case 2: - m_radius.rx() = params[0].toDouble() * 72. / 90.; - m_radius.ry() = params[1].toDouble() * 72. / 90.; - break; - default: - m_radius = QPointF(); - } - } - - m_radius = context.convertFilterPrimitiveUnits(m_radius); - - if (element.hasAttribute("operator")) { - QString op = element.attribute("operator"); - if (op == "dilate") { - m_operator = Dilate; - } - } - - return true; -} - -void MorphologyEffect::save(KoXmlWriter &writer) -{ - writer.startElement(MorphologyEffectId); - - saveCommonAttributes(writer); - - if (m_operator != Erode) { - writer.addAttribute("operator", "dilate"); - } - if (!m_radius.isNull()) { - if (m_radius.x() == m_radius.y()) { - writer.addAttribute("radius", QString("%1").arg(m_radius.x())); - } else { - writer.addAttribute("radius", QString("%1 %2").arg(m_radius.x()).arg(m_radius.y())); - } - } - - writer.endElement(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/MorphologyEffect.h b/plugins/tools/karbonplugins/filtereffects/MorphologyEffect.h deleted file mode 100644 index 9d91520275..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/MorphologyEffect.h +++ /dev/null @@ -1,66 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 MORPHOLOGYEFFECT_H -#define MORPHOLOGYEFFECT_H - -#include "KoFilterEffect.h" -#include - -#define MorphologyEffectId "feMorphology" - -class KoFilterEffectLoadingContext; - -/// A morphology filter effect -class MorphologyEffect : public KoFilterEffect -{ -public: - /// Morphology operator type - enum Operator { - Erode, - Dilate - }; - - MorphologyEffect(); - - /// Returns the morphology radius - QPointF morphologyRadius() const; - - /// Sets the morphology radius - void setMorphologyRadius(const QPointF &radius); - - /// Returns the morphology operator - Operator morphologyOperator() const; - - /// Sets the morphology operator - void setMorphologyOperator(Operator op); - - /// reimplemented from KoFilterEffect - QImage processImage(const QImage &image, const KoFilterEffectRenderContext &context) const override; - /// reimplemented from KoFilterEffect - bool load(const KoXmlElement &element, const KoFilterEffectLoadingContext &context) override; - /// reimplemented from KoFilterEffect - void save(KoXmlWriter &writer) override; - -private: - QPointF m_radius; - Operator m_operator; -}; - -#endif // MORPHOLOGYEFFECT_H diff --git a/plugins/tools/karbonplugins/filtereffects/MorphologyEffectConfigWidget.cpp b/plugins/tools/karbonplugins/filtereffects/MorphologyEffectConfigWidget.cpp deleted file mode 100644 index 242a5ff688..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/MorphologyEffectConfigWidget.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "MorphologyEffectConfigWidget.h" -#include "MorphologyEffect.h" -#include "KoFilterEffect.h" - -#include -#include - -#include -#include -#include -#include - -#include "kis_double_parse_spin_box.h" - -MorphologyEffectConfigWidget::MorphologyEffectConfigWidget(QWidget *parent) - : KoFilterEffectConfigWidgetBase(parent) - , m_effect(0) -{ - QGridLayout *g = new QGridLayout(this); - - m_operator = new QButtonGroup(this); - QRadioButton *erode = new QRadioButton(i18n("Erode"), this); - QRadioButton *dilate = new QRadioButton(i18n("Dilate"), this); - m_operator->addButton(erode, MorphologyEffect::Erode); - m_operator->addButton(dilate, MorphologyEffect::Dilate); - g->addWidget(new QLabel(i18n("Operator:"), this), 0, 0); - g->addWidget(erode, 0, 1); - g->addWidget(dilate, 0, 2); - - g->addWidget(new QLabel(i18n("Radius x:"), this), 1, 0); - m_radiusX = new KisDoubleParseSpinBox(this); - m_radiusX->setRange(0.0, 100); - m_radiusX->setSingleStep(0.5); - g->addWidget(m_radiusX, 1, 1, 1, 2); - - g->addWidget(new QLabel(i18n("Radius y:"), this), 2, 0); - m_radiusY = new KisDoubleParseSpinBox(this); - m_radiusY->setRange(0.0, 100); - m_radiusY->setSingleStep(0.5); - g->addWidget(m_radiusY, 2, 1, 1, 2); - - setLayout(g); - - connect(m_operator, SIGNAL(buttonClicked(int)), this, SLOT(operatorChanged(int))); - connect(m_radiusX, SIGNAL(valueChanged(double)), this, SLOT(radiusXChanged(double))); - connect(m_radiusY, SIGNAL(valueChanged(double)), this, SLOT(radiusYChanged(double))); -} - -bool MorphologyEffectConfigWidget::editFilterEffect(KoFilterEffect *filterEffect) -{ - m_effect = dynamic_cast(filterEffect); - if (!m_effect) { - return false; - } - - m_operator->blockSignals(true); - m_operator->button(m_effect->morphologyOperator())->setChecked(true); - m_operator->blockSignals(false); - m_radiusX->blockSignals(true); - m_radiusX->setValue(m_effect->morphologyRadius().x() * 100); - m_radiusX->blockSignals(false); - m_radiusY->blockSignals(true); - m_radiusY->setValue(m_effect->morphologyRadius().y() * 100); - m_radiusY->blockSignals(false); - - return true; -} - -void MorphologyEffectConfigWidget::operatorChanged(int id) -{ - if (!m_effect) { - return; - } - - switch (id) { - case MorphologyEffect::Erode: - m_effect->setMorphologyOperator(MorphologyEffect::Erode); - break; - case MorphologyEffect::Dilate: - m_effect->setMorphologyOperator(MorphologyEffect::Dilate); - break; - } - emit filterChanged(); -} - -void MorphologyEffectConfigWidget::radiusXChanged(double x) -{ - if (!m_effect) { - return; - } - - QPointF radius = m_effect->morphologyRadius(); - if (radius.x() != x) { - m_effect->setMorphologyRadius(QPointF(x * 0.01, radius.y())); - } - - emit filterChanged(); -} - -void MorphologyEffectConfigWidget::radiusYChanged(double y) -{ - if (!m_effect) { - return; - } - - QPointF radius = m_effect->morphologyRadius(); - if (radius.y() != y) { - m_effect->setMorphologyRadius(QPointF(radius.x(), y * 0.01)); - } - - emit filterChanged(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/MorphologyEffectConfigWidget.h b/plugins/tools/karbonplugins/filtereffects/MorphologyEffectConfigWidget.h deleted file mode 100644 index f0b68afcf7..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/MorphologyEffectConfigWidget.h +++ /dev/null @@ -1,50 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 MORPHOLOGYEFFECTCONFIGWIDGET_H -#define MORPHOLOGYEFFECTCONFIGWIDGET_H - -#include "KoFilterEffectConfigWidgetBase.h" - -class KoFilterEffect; -class MorphologyEffect; -class QDoubleSpinBox; -class QButtonGroup; - -class MorphologyEffectConfigWidget : public KoFilterEffectConfigWidgetBase -{ - Q_OBJECT -public: - explicit MorphologyEffectConfigWidget(QWidget *parent = 0); - - /// reimplemented from KoFilterEffectConfigWidgetBase - bool editFilterEffect(KoFilterEffect *filterEffect) override; - -private Q_SLOTS: - void radiusXChanged(double x); - void radiusYChanged(double y); - void operatorChanged(int op); -private: - MorphologyEffect *m_effect; - QButtonGroup *m_operator; - QDoubleSpinBox *m_radiusX; - QDoubleSpinBox *m_radiusY; -}; - -#endif // MORPHOLOGYEFFECTCONFIGWIDGET_H diff --git a/plugins/tools/karbonplugins/filtereffects/MorphologyEffectFactory.cpp b/plugins/tools/karbonplugins/filtereffects/MorphologyEffectFactory.cpp deleted file mode 100644 index 5ed3d9b3a5..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/MorphologyEffectFactory.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "MorphologyEffectFactory.h" -#include "MorphologyEffect.h" -#include "MorphologyEffectConfigWidget.h" - -#include - -MorphologyEffectFactory::MorphologyEffectFactory() - : KoFilterEffectFactoryBase(MorphologyEffectId, i18n("Morphology")) -{ -} - -KoFilterEffect *MorphologyEffectFactory::createFilterEffect() const -{ - return new MorphologyEffect(); -} - -KoFilterEffectConfigWidgetBase *MorphologyEffectFactory::createConfigWidget() const -{ - return new MorphologyEffectConfigWidget(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/MorphologyEffectFactory.h b/plugins/tools/karbonplugins/filtereffects/MorphologyEffectFactory.h deleted file mode 100644 index 1706120062..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/MorphologyEffectFactory.h +++ /dev/null @@ -1,35 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 MORPHOLOGYEFFECTFACTORY_H -#define MORPHOLOGYEFFECTFACTORY_H - -#include "KoFilterEffectFactoryBase.h" - -class KoFilterEffect; - -class MorphologyEffectFactory : public KoFilterEffectFactoryBase -{ -public: - MorphologyEffectFactory(); - KoFilterEffect *createFilterEffect() const override; - KoFilterEffectConfigWidgetBase *createConfigWidget() const override; -}; - -#endif // MORPHOLOGYEFFECTFACTORY_H diff --git a/plugins/tools/karbonplugins/filtereffects/OffsetEffect.cpp b/plugins/tools/karbonplugins/filtereffects/OffsetEffect.cpp deleted file mode 100644 index 87c0329ad4..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/OffsetEffect.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "OffsetEffect.h" -#include "KoFilterEffectRenderContext.h" -#include "KoFilterEffectLoadingContext.h" -#include "KoViewConverter.h" -#include "KoXmlWriter.h" -#include "KoXmlReader.h" -#include -#include - -OffsetEffect::OffsetEffect() - : KoFilterEffect(OffsetEffectId, i18n("Offset")) - , m_offset(0, 0) -{ -} - -QPointF OffsetEffect::offset() const -{ - return m_offset; -} - -void OffsetEffect::setOffset(const QPointF &offset) -{ - m_offset = offset; -} - -QImage OffsetEffect::processImage(const QImage &image, const KoFilterEffectRenderContext &context) const -{ - if (m_offset.x() == 0.0 && m_offset.y() == 0.0) { - return image; - } - - // transform from bounding box coordinates - QPointF offset = context.toUserSpace(m_offset); - // transform to view coordinates - offset = context.viewConverter()->documentToView(offset); - - QImage result(image.size(), image.format()); - result.fill(qRgba(0, 0, 0, 0)); - - QPainter p(&result); - p.drawImage(context.filterRegion().topLeft() + offset, image, context.filterRegion()); - return result; -} - -bool OffsetEffect::load(const KoXmlElement &element, const KoFilterEffectLoadingContext &context) -{ - if (element.tagName() != id()) { - return false; - } - - if (element.hasAttribute("dx")) { - m_offset.rx() = element.attribute("dx").toDouble(); - } - if (element.hasAttribute("dy")) { - m_offset.ry() = element.attribute("dy").toDouble(); - } - - m_offset = context.convertFilterPrimitiveUnits(m_offset); - - return true; -} - -void OffsetEffect::save(KoXmlWriter &writer) -{ - writer.startElement(OffsetEffectId); - - saveCommonAttributes(writer); - - if (m_offset.x() != 0.0) { - writer.addAttribute("dx", m_offset.x()); - } - if (m_offset.y() != 0.0) { - writer.addAttribute("dy", m_offset.x()); - } - - writer.endElement(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/OffsetEffect.h b/plugins/tools/karbonplugins/filtereffects/OffsetEffect.h deleted file mode 100644 index 9543ade734..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/OffsetEffect.h +++ /dev/null @@ -1,48 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 OFFSETEFFECT_H -#define OFFSETEFFECT_H - -#include "KoFilterEffect.h" -#include - -#define OffsetEffectId "feOffset" - -/// An image offset effect -class OffsetEffect : public KoFilterEffect -{ -public: - OffsetEffect(); - - QPointF offset() const; - void setOffset(const QPointF &offset); - - /// reimplemented from KoFilterEffect - QImage processImage(const QImage &image, const KoFilterEffectRenderContext &context) const override; - /// reimplemented from KoFilterEffect - bool load(const KoXmlElement &element, const KoFilterEffectLoadingContext &context) override; - /// reimplemented from KoFilterEffect - void save(KoXmlWriter &writer) override; - -private: - QPointF m_offset; -}; - -#endif // OFFSETEFFECT_H diff --git a/plugins/tools/karbonplugins/filtereffects/OffsetEffectConfigWidget.cpp b/plugins/tools/karbonplugins/filtereffects/OffsetEffectConfigWidget.cpp deleted file mode 100644 index 5c60535ec8..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/OffsetEffectConfigWidget.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "OffsetEffectConfigWidget.h" -#include "OffsetEffect.h" -#include "KoFilterEffect.h" -#include -#include -#include -#include - -#include "kis_double_parse_spin_box.h" - -const qreal OffsetLimit = 100.0; - -OffsetEffectConfigWidget::OffsetEffectConfigWidget(QWidget *parent) - : KoFilterEffectConfigWidgetBase(parent) - , m_effect(0) -{ - QGridLayout *g = new QGridLayout(this); - - g->addWidget(new QLabel(i18n("dx"), this), 0, 0); - m_offsetX = new KisDoubleParseSpinBox(this); - m_offsetX->setRange(-OffsetLimit, OffsetLimit); - m_offsetX->setSingleStep(1.0); - g->addWidget(m_offsetX, 0, 1); - - g->addWidget(new QLabel(i18n("dy"), this), 0, 2); - m_offsetY = new KisDoubleParseSpinBox(this); - m_offsetY->setRange(-OffsetLimit, OffsetLimit); - m_offsetY->setSingleStep(1.0); - g->addWidget(m_offsetY, 0, 3); - setLayout(g); - - connect(m_offsetX, SIGNAL(valueChanged(double)), this, SLOT(offsetChanged(double))); - connect(m_offsetY, SIGNAL(valueChanged(double)), this, SLOT(offsetChanged(double))); -} - -bool OffsetEffectConfigWidget::editFilterEffect(KoFilterEffect *filterEffect) -{ - m_effect = dynamic_cast(filterEffect); - if (!m_effect) { - return false; - } - - m_offsetX->blockSignals(true); - m_offsetY->blockSignals(true); - m_offsetX->setValue(m_effect->offset().x() * 100.0); - m_offsetY->setValue(m_effect->offset().y() * 100.0); - m_offsetX->blockSignals(false); - m_offsetY->blockSignals(false); - - return true; -} - -void OffsetEffectConfigWidget::offsetChanged(double /*offset*/) -{ - if (!m_effect) { - return; - } - - m_effect->setOffset(0.01 * QPointF(m_offsetX->value(), m_offsetY->value())); - emit filterChanged(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/OffsetEffectConfigWidget.h b/plugins/tools/karbonplugins/filtereffects/OffsetEffectConfigWidget.h deleted file mode 100644 index 9bd17de7a3..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/OffsetEffectConfigWidget.h +++ /dev/null @@ -1,47 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 OFFSETEFFECTCONFIGWIDGET_H -#define OFFSETEFFECTCONFIGWIDGET_H - -#include "KoFilterEffectConfigWidgetBase.h" - -class KoFilterEffect; -class OffsetEffect; -class QDoubleSpinBox; - -class OffsetEffectConfigWidget : public KoFilterEffectConfigWidgetBase -{ - Q_OBJECT -public: - explicit OffsetEffectConfigWidget(QWidget *parent = 0); - - /// reimplemented from KoFilterEffectConfigWidgetBase - bool editFilterEffect(KoFilterEffect *filterEffect) override; - -private Q_SLOTS: - void offsetChanged(double offset); - -private: - OffsetEffect *m_effect; - QDoubleSpinBox *m_offsetX; - QDoubleSpinBox *m_offsetY; -}; - -#endif // OFFSETEFFECTCONFIGWIDGET_H diff --git a/plugins/tools/karbonplugins/filtereffects/OffsetEffectFactory.cpp b/plugins/tools/karbonplugins/filtereffects/OffsetEffectFactory.cpp deleted file mode 100644 index cb438a6a1c..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/OffsetEffectFactory.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "OffsetEffectFactory.h" -#include "OffsetEffect.h" -#include "OffsetEffectConfigWidget.h" -#include - -OffsetEffectFactory::OffsetEffectFactory() - : KoFilterEffectFactoryBase(OffsetEffectId, i18n("Offset")) -{ -} - -KoFilterEffect *OffsetEffectFactory::createFilterEffect() const -{ - return new OffsetEffect(); -} - -KoFilterEffectConfigWidgetBase *OffsetEffectFactory::createConfigWidget() const -{ - return new OffsetEffectConfigWidget(); -} diff --git a/plugins/tools/karbonplugins/filtereffects/OffsetEffectFactory.h b/plugins/tools/karbonplugins/filtereffects/OffsetEffectFactory.h deleted file mode 100644 index 679c9a56c2..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/OffsetEffectFactory.h +++ /dev/null @@ -1,35 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 OFFSETEFFECTFACTORY_H -#define OFFSETEFFECTFACTORY_H - -#include "KoFilterEffectFactoryBase.h" - -class KoFilterEffect; - -class OffsetEffectFactory : public KoFilterEffectFactoryBase -{ -public: - OffsetEffectFactory(); - KoFilterEffect *createFilterEffect() const override; - KoFilterEffectConfigWidgetBase *createConfigWidget() const override; -}; - -#endif // OFFSETEFFECTFACTORY_H diff --git a/plugins/tools/karbonplugins/filtereffects/karbon_filtereffects.json b/plugins/tools/karbonplugins/filtereffects/karbon_filtereffects.json deleted file mode 100644 index 0cb19b12f5..0000000000 --- a/plugins/tools/karbonplugins/filtereffects/karbon_filtereffects.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "Icon": "", - "Id": "Filter Effects", - - "Type": "Service", - "X-Flake-MinVersion": "28", - "X-Flake-PluginVersion": "28", - "X-KDE-Library": "krita_filtereffects", - "X-KDE-ServiceTypes": [ - "Calligra/FilterEffect" - ] -} diff --git a/plugins/tools/karbonplugins/tools/22-actions-pattern.png b/plugins/tools/karbonplugins/tools/22-actions-pattern.png deleted file mode 100644 index a5665e618d..0000000000 Binary files a/plugins/tools/karbonplugins/tools/22-actions-pattern.png and /dev/null differ diff --git a/plugins/tools/karbonplugins/tools/32-actions-tool_imageeffects.png b/plugins/tools/karbonplugins/tools/32-actions-tool_imageeffects.png deleted file mode 100644 index 238eb9c65a..0000000000 Binary files a/plugins/tools/karbonplugins/tools/32-actions-tool_imageeffects.png and /dev/null differ diff --git a/plugins/tools/karbonplugins/tools/CMakeLists.txt b/plugins/tools/karbonplugins/tools/CMakeLists.txt index 277596400a..d11c693f3b 100644 --- a/plugins/tools/karbonplugins/tools/CMakeLists.txt +++ b/plugins/tools/karbonplugins/tools/CMakeLists.txt @@ -1,49 +1,20 @@ -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/filterEffectTool -) - -########### next target ############### - set(karbon_tools_SOURCES KarbonToolsPlugin.cpp KarbonCursor.cpp CalligraphyTool/KarbonCalligraphyTool.cpp CalligraphyTool/KarbonCalligraphyOptionWidget.cpp CalligraphyTool/KarbonCalligraphyToolFactory.cpp CalligraphyTool/KarbonCalligraphicShape.cpp CalligraphyTool/KarbonCalligraphicShapeFactory.cpp CalligraphyTool/KarbonSimplifyPath.cpp - KarbonPatternTool.cpp - KarbonPatternToolFactory.cpp - KarbonPatternEditStrategy.cpp - filterEffectTool/KarbonFilterEffectsTool.cpp - filterEffectTool/KarbonFilterEffectsToolFactory.cpp - filterEffectTool/FilterEffectEditWidget.cpp - filterEffectTool/FilterEffectScene.cpp - filterEffectTool/FilterEffectSceneItems.cpp - filterEffectTool/FilterInputChangeCommand.cpp - filterEffectTool/FilterAddCommand.cpp - filterEffectTool/FilterRemoveCommand.cpp - filterEffectTool/FilterStackSetCommand.cpp - filterEffectTool/FilterRegionChangeCommand.cpp - filterEffectTool/FilterEffectResource.cpp - filterEffectTool/FilterResourceServerProvider.cpp - filterEffectTool/FilterRegionEditStrategy.cpp - filterEffectTool/KoResourceSelector.cpp - KarbonPatternOptionsWidget.cpp -) - -ki18n_wrap_ui(karbon_tools_SOURCES - filterEffectTool/FilterEffectEditWidget.ui - KarbonPatternOptionsWidget.ui ) qt5_add_resources(karbon_tools_SOURCES karbontools.qrc) add_library(krita_karbontools MODULE ${karbon_tools_SOURCES}) target_link_libraries(krita_karbontools kritaui kritawidgets KF5::Completion) install(TARGETS krita_karbontools DESTINATION ${KRITA_PLUGIN_INSTALL_DIR}) install(FILES CalligraphyTool/KarbonCalligraphyTool.action DESTINATION ${DATA_INSTALL_DIR}/krita/actions) diff --git a/plugins/tools/karbonplugins/tools/KarbonPatternEditStrategy.cpp b/plugins/tools/karbonplugins/tools/KarbonPatternEditStrategy.cpp deleted file mode 100644 index edfa32909e..0000000000 --- a/plugins/tools/karbonplugins/tools/KarbonPatternEditStrategy.cpp +++ /dev/null @@ -1,392 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2007,2009 Jan Hambrecht - * - * 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 "KarbonPatternEditStrategy.h" - -#include -#include -#include - -#include -#include - -#include - -uint KarbonPatternEditStrategyBase::m_handleRadius = 3; -uint KarbonPatternEditStrategyBase::m_grabSensitivity = 3; - -KarbonPatternEditStrategyBase::KarbonPatternEditStrategyBase(KoShape *s, KoImageCollection *imageCollection) - : m_selectedHandle(-1) - , m_oldFill(new KoPatternBackground(imageCollection)) - , m_newFill(new KoPatternBackground(imageCollection)) - , m_shape(s) - , m_imageCollection(imageCollection) - , m_editing(false) - , m_modified(false) -{ - Q_ASSERT(m_shape); - Q_ASSERT(imageCollection); - // cache the shapes transformation matrix - m_matrix = shape()->absoluteTransformation(0); -} - -KarbonPatternEditStrategyBase::~KarbonPatternEditStrategyBase() -{ -} - -void KarbonPatternEditStrategyBase::setEditing(bool on) -{ - m_editing = on; - // if we are going into editing mode, save the old background - // for use inside the command emitted when finished - if (on) { - m_modified = false; - QSharedPointer fill = qSharedPointerDynamicCast(m_shape->background()); - if (fill) { - m_oldFill = fill; - } - } -} - -void KarbonPatternEditStrategyBase::setModified() -{ - m_modified = true; -} - -bool KarbonPatternEditStrategyBase::isModified() const -{ - return m_modified; -} - -KUndo2Command *KarbonPatternEditStrategyBase::createCommand() -{ - QSharedPointer fill = qSharedPointerDynamicCast(m_shape->background()); - if (fill && isModified()) { - fill = m_oldFill; - QSharedPointer newFill(new KoPatternBackground(m_imageCollection)); - newFill = m_newFill; - return new KoShapeBackgroundCommand(m_shape, newFill, 0); - } - return 0; -} - -void KarbonPatternEditStrategyBase::paintHandle(QPainter &painter, const KoViewConverter &converter, const QPointF &position) const -{ - QRectF handleRect = converter.viewToDocument(QRectF(0, 0, 2 * m_handleRadius, 2 * m_handleRadius)); - handleRect.moveCenter(position); - painter.drawRect(handleRect); -} - -bool KarbonPatternEditStrategyBase::mouseInsideHandle(const QPointF &mousePos, const QPointF &handlePos, const KoViewConverter &converter) const -{ - qreal grabSensitivityInPt = converter.viewToDocumentX(m_grabSensitivity); - if (mousePos.x() < handlePos.x() - grabSensitivityInPt) { - return false; - } - if (mousePos.x() > handlePos.x() + grabSensitivityInPt) { - return false; - } - if (mousePos.y() < handlePos.y() - grabSensitivityInPt) { - return false; - } - if (mousePos.y() > handlePos.y() + grabSensitivityInPt) { - return false; - } - return true; -} - -void KarbonPatternEditStrategyBase::repaint() const -{ - m_shape->update(); -} - -KoShape *KarbonPatternEditStrategyBase::shape() const -{ - return m_shape; -} - -KoImageCollection *KarbonPatternEditStrategyBase::imageCollection() -{ - return m_imageCollection; -} - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// - -KarbonPatternEditStrategy::KarbonPatternEditStrategy(KoShape *s, KoImageCollection *imageCollection) - : KarbonPatternEditStrategyBase(s, imageCollection) -{ - // cache the shapes transformation matrix - m_matrix = shape()->absoluteTransformation(0); - QSizeF size = shape()->size(); - // the fixed length of half the average shape dimension - m_normalizedLength = 0.25 * (size.width() + size.height()); - // get the brush transformation matrix - QTransform brushMatrix; - QSharedPointer fill = qSharedPointerDynamicCast(shape()->background()); - if (fill) { - brushMatrix = fill->transform(); - } - - // the center handle at the center point of the shape - //m_origin = QPointF( 0.5 * size.width(), 0.5 * size.height() ); - m_handles.append(brushMatrix.map(QPointF())); - // the direction handle with the length of half the average shape dimension - QPointF dirVec = QPointF(m_normalizedLength, 0.0); - m_handles.append(brushMatrix.map(dirVec)); -} - -KarbonPatternEditStrategy::~KarbonPatternEditStrategy() -{ -} - -void KarbonPatternEditStrategy::paint(QPainter &painter, const KoViewConverter &converter) const -{ - QPointF centerPoint = m_matrix.map(m_origin + m_handles[center]); - QPointF directionPoint = m_matrix.map(m_origin + m_handles[direction]); - - KoShape::applyConversion(painter, converter); - painter.drawLine(centerPoint, directionPoint); - paintHandle(painter, converter, centerPoint); - paintHandle(painter, converter, directionPoint); -} - -bool KarbonPatternEditStrategy::selectHandle(const QPointF &mousePos, const KoViewConverter &converter) -{ - int handleIndex = 0; - Q_FOREACH (const QPointF &handle, m_handles) { - if (mouseInsideHandle(mousePos, m_matrix.map(m_origin + handle), converter)) { - m_selectedHandle = handleIndex; - return true; - } - handleIndex++; - } - m_selectedHandle = -1; - return false; -} - -void KarbonPatternEditStrategy::handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) -{ - Q_UNUSED(modifiers) - - if (m_selectedHandle == direction) { - QPointF newPos = m_matrix.inverted().map(mouseLocation) - m_origin - m_handles[center]; - // calculate the temporary length after handle movement - qreal newLength = sqrt(newPos.x() * newPos.x() + newPos.y() * newPos.y()); - // set the new direction vector with the new direction and normalized length - m_handles[m_selectedHandle] = m_handles[center] + m_normalizedLength / newLength * newPos; - } else if (m_selectedHandle == center) { - QPointF diffPos = m_matrix.inverted().map(mouseLocation) - m_origin - m_handles[center]; - m_handles[center] += diffPos; - m_handles[direction] += diffPos; - } else { - return; - } - - setModified(); - - QSharedPointer fill = qSharedPointerDynamicCast(shape()->background()); - if (fill) { - m_newFill = updatedBackground(); - fill = m_newFill; - } -} - -QRectF KarbonPatternEditStrategy::boundingRect() const -{ - // calculate the bounding rect of the handles - QRectF bbox(m_matrix.map(m_origin + m_handles[0]), QSize(0, 0)); - for (int i = 1; i < m_handles.count(); ++i) { - QPointF handle = m_matrix.map(m_origin + m_handles[i]); - bbox.setLeft(qMin(handle.x(), bbox.left())); - bbox.setRight(qMax(handle.x(), bbox.right())); - bbox.setTop(qMin(handle.y(), bbox.top())); - bbox.setBottom(qMax(handle.y(), bbox.bottom())); - } - qreal hr = handleRadius(); - return bbox.adjusted(-hr, -hr, hr, hr); -} - -QSharedPointer KarbonPatternEditStrategy::updatedBackground() -{ - // the direction vector controls the rotation of the pattern - QPointF dirVec = m_handles[direction] - m_handles[center]; - qreal angle = atan2(dirVec.y(), dirVec.x()) * 180.0 / M_PI; - QTransform matrix; - // the center handle controls the translation - matrix.translate(m_handles[center].x(), m_handles[center].y()); - matrix.rotate(angle); - - QSharedPointer newFill(new KoPatternBackground(imageCollection())); - newFill->setTransform(matrix); - - return newFill; -} - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// - -KarbonOdfPatternEditStrategy::KarbonOdfPatternEditStrategy(KoShape *s, KoImageCollection *imageCollection) - : KarbonPatternEditStrategyBase(s, imageCollection) -{ - m_handles.append(QPointF()); - m_handles.append(QPointF()); - updateHandles(qSharedPointerDynamicCast(shape()->background())); -} - -KarbonOdfPatternEditStrategy::~KarbonOdfPatternEditStrategy() -{ -} - -void KarbonOdfPatternEditStrategy::paint(QPainter &painter, const KoViewConverter &converter) const -{ - KoShape::applyConversion(painter, converter); - - QSharedPointer fill = qSharedPointerDynamicCast(shape()->background()); - if (!fill) { - return; - } - - painter.save(); - painter.setTransform(m_matrix * painter.transform()); - painter.setBrush(Qt::NoBrush); - painter.drawRect(QRectF(m_handles[origin], m_handles[size])); - painter.restore(); - - if (fill->repeat() == KoPatternBackground::Tiled) { - paintHandle(painter, converter, m_matrix.map(m_handles[origin])); - } - if (fill->repeat() != KoPatternBackground::Stretched) { - paintHandle(painter, converter, m_matrix.map(m_handles[size])); - } - -} - -bool KarbonOdfPatternEditStrategy::selectHandle(const QPointF &mousePos, const KoViewConverter &converter) -{ - QSharedPointer fill = qSharedPointerDynamicCast(shape()->background()); - if (!fill) { - return false; - } - - if (fill->repeat() == KoPatternBackground::Stretched) { - return false; - } - - m_selectedHandle = -1; - - if (mouseInsideHandle(mousePos, m_matrix.map(m_handles[size]), converter)) { - m_selectedHandle = size; - return true; - } - - if (fill->repeat() == KoPatternBackground::Original) { - return false; - } - - if (mouseInsideHandle(mousePos, m_matrix.map(m_handles[origin]), converter)) { - m_selectedHandle = origin; - return true; - } - - return false; -} - -void KarbonOdfPatternEditStrategy::handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) -{ - Q_UNUSED(modifiers); - - QSharedPointer fill = qSharedPointerDynamicCast(shape()->background()); - if (!fill) { - return; - } - - if (fill->repeat() == KoPatternBackground::Stretched) { - return; - } - - if (m_selectedHandle == origin) { - if (fill->repeat() == KoPatternBackground::Original) { - return; - } - - QPointF diffPos = m_matrix.inverted().map(mouseLocation) - m_handles[origin]; - m_handles[origin] += diffPos; - m_handles[size] += diffPos; - } else if (m_selectedHandle == size) { - QPointF newPos = m_matrix.inverted().map(mouseLocation); - newPos.setX(qMax(newPos.x(), m_handles[origin].x())); - newPos.setY(qMax(newPos.y(), m_handles[origin].y())); - if (fill->repeat() == KoPatternBackground::Original) { - QPointF diffPos = newPos - m_handles[size]; - m_handles[size] += 0.5 * diffPos; - m_handles[origin] -= 0.5 * diffPos; - } else { - m_handles[size] = newPos; - } - } else { - return; - } - - setModified(); - - m_newFill = updatedBackground(); - updateHandles(m_newFill); -} - -QRectF KarbonOdfPatternEditStrategy::boundingRect() const -{ - // calculate the bounding rect of the handles - QRectF bbox(m_matrix.map(m_handles[origin]), m_matrix.map(m_handles[size])); - qreal hr = handleRadius(); - return bbox.adjusted(-hr, -hr, hr, hr); -} - -QSharedPointer KarbonOdfPatternEditStrategy::updatedBackground() -{ - QSizeF displaySize(m_handles[size].x() - m_handles[origin].x(), m_handles[size].y() - m_handles[origin].y()); - qreal offsetX = 100.0 * (m_handles[origin].x() / displaySize.width()); - qreal offsetY = 100.0 * (m_handles[origin].y() / displaySize.height()); - - QSharedPointer newFill(new KoPatternBackground(imageCollection())); - newFill = m_oldFill; - newFill->setReferencePoint(KoPatternBackground::TopLeft); - newFill->setReferencePointOffset(QPointF(offsetX, offsetY)); - newFill->setPatternDisplaySize(displaySize); - - return newFill; -} - -void KarbonOdfPatternEditStrategy::updateHandles(QSharedPointer fill) -{ - if (!fill) { - return; - } - - QRectF patternRect = fill->patternRectFromFillSize(shape()->size()); - m_handles[origin] = patternRect.topLeft(); - m_handles[size] = patternRect.bottomRight(); -} - -void KarbonOdfPatternEditStrategy::updateHandles() -{ - updateHandles(qSharedPointerDynamicCast(shape()->background())); -} diff --git a/plugins/tools/karbonplugins/tools/KarbonPatternEditStrategy.h b/plugins/tools/karbonplugins/tools/KarbonPatternEditStrategy.h deleted file mode 100644 index 5b79d3e336..0000000000 --- a/plugins/tools/karbonplugins/tools/KarbonPatternEditStrategy.h +++ /dev/null @@ -1,174 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2007,2009 Jan Hambrecht - * - * 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 _KARBONPATTERNEDITSTRATEGY_H_ -#define _KARBONPATTERNEDITSTRATEGY_H_ - -#include -#include -#include - -class KoShape; -class KoViewConverter; -class KoImageCollection; - -class QPainter; -class KUndo2Command; - -/// The class used for editing a shapes pattern -class KarbonPatternEditStrategyBase -{ -public: - /// constructs an edit strategy working on the given shape - explicit KarbonPatternEditStrategyBase(KoShape *shape, KoImageCollection *imageCollection); - - /// destroy the edit strategy - virtual ~KarbonPatternEditStrategyBase(); - - /// painting of the pattern editing handles - virtual void paint(QPainter &painter, const KoViewConverter &converter) const = 0; - - /// selects handle at the given position - virtual bool selectHandle(const QPointF &mousePos, const KoViewConverter &converter) = 0; - - /// mouse position handling for moving handles - virtual void handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) = 0; - - /// sets the strategy into editing mode - void setEditing(bool on); - - /// checks if strategy is in editing mode - bool isEditing() const - { - return m_editing; - } - - /// create the command for changing the shapes background - KUndo2Command *createCommand(); - - /// schedules a repaint of the shape and gradient handles - void repaint() const; - - /// returns the pattern handles bounding rect - virtual QRectF boundingRect() const = 0; - - /// returns the actual background brush - virtual QSharedPointer updatedBackground() = 0; - - /// Returns the shape we are working on - KoShape *shape() const; - - /// sets the handle radius in pixel used for painting the handles - static void setHandleRadius(uint radius) - { - m_handleRadius = radius; - } - - /// returns the actual handle radius in pixel - static uint handleRadius() - { - return m_handleRadius; - } - - /// sets the grab sensitivity in pixel used for grabbing the handles - static void setGrabSensitivity(uint grabSensitivity) - { - m_grabSensitivity = grabSensitivity; - } - - /// returns the actual grab sensitivity in pixel - static uint grabSensitivity() - { - return m_grabSensitivity; - } - - virtual void updateHandles() {} - -protected: - /// Returns the image collectio used to create new pattern background - KoImageCollection *imageCollection(); - - /// Flags the background as modified - void setModified(); - - /// Returns if background is modified - bool isModified() const; - - /// paints a single handle - void paintHandle(QPainter &painter, const KoViewConverter &converter, const QPointF &position) const; - - /// checks if mouse position is inside handle rect - bool mouseInsideHandle(const QPointF &mousePos, const QPointF &handlePos, const KoViewConverter &converter) const; - - QList m_handles; ///< the list of handles - int m_selectedHandle; ///< index of currently deleted handle or -1 if none selected - QSharedPointer m_oldFill; - QSharedPointer m_newFill; - QTransform m_matrix; ///< matrix to map handle into document coordinate system - -private: - - static uint m_handleRadius; ///< the handle radius for all gradient strategies - static uint m_grabSensitivity; ///< the grab sensitivity - KoShape *m_shape; ///< the shape we are working on - KoImageCollection *m_imageCollection; - bool m_editing; ///< the edit mode flag - bool m_modified; ///< indicated if background was modified -}; - -/// The class used for editing a shapes pattern -class KarbonPatternEditStrategy : public KarbonPatternEditStrategyBase -{ -public: - explicit KarbonPatternEditStrategy(KoShape *shape, KoImageCollection *imageCollection); - ~KarbonPatternEditStrategy() override; - void paint(QPainter &painter, const KoViewConverter &converter) const override; - bool selectHandle(const QPointF &mousePos, const KoViewConverter &converter) override; - void handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) override; - QRectF boundingRect() const override; - QSharedPointer updatedBackground() override; - -private: - - enum Handles { center, direction }; - - qreal m_normalizedLength; ///< the normalized direction vector length - QPointF m_origin; ///< the pattern handle origin -}; - -/// The class used for editing a shapes pattern -class KarbonOdfPatternEditStrategy : public KarbonPatternEditStrategyBase -{ -public: - explicit KarbonOdfPatternEditStrategy(KoShape *shape, KoImageCollection *imageCollection); - ~KarbonOdfPatternEditStrategy() override; - void paint(QPainter &painter, const KoViewConverter &converter) const override; - bool selectHandle(const QPointF &mousePos, const KoViewConverter &converter) override; - void handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) override; - QRectF boundingRect() const override; - QSharedPointer updatedBackground() override; - void updateHandles() override; -private: - - enum Handles { origin, size }; - - void updateHandles(QSharedPointer fill); -}; - -#endif // _KARBONPATTERNEDITSTRATEGY_H_ diff --git a/plugins/tools/karbonplugins/tools/KarbonPatternOptionsWidget.cpp b/plugins/tools/karbonplugins/tools/KarbonPatternOptionsWidget.cpp deleted file mode 100644 index ccc876586e..0000000000 --- a/plugins/tools/karbonplugins/tools/KarbonPatternOptionsWidget.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2008 Jan Hambrecht - * - * 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 "KarbonPatternOptionsWidget.h" -#include "ui_KarbonPatternOptionsWidget.h" - -class Q_DECL_HIDDEN KarbonPatternOptionsWidget::Private -{ -public: - Ui_PatternOptionsWidget widget; -}; - -KarbonPatternOptionsWidget::KarbonPatternOptionsWidget(QWidget *parent) - : QWidget(parent) - , d(new Private()) -{ - d->widget.setupUi(this); - - d->widget.patternRepeat->insertItem(0, i18n("Original")); - d->widget.patternRepeat->insertItem(1, i18n("Tiled")); - d->widget.patternRepeat->insertItem(2, i18n("Stretched")); - - d->widget.referencePoint->insertItem(0, i18n("Top Left")); - d->widget.referencePoint->insertItem(1, i18n("Top")); - d->widget.referencePoint->insertItem(2, i18n("Top Right")); - d->widget.referencePoint->insertItem(3, i18n("Left")); - d->widget.referencePoint->insertItem(4, i18n("Center")); - d->widget.referencePoint->insertItem(5, i18n("Right")); - d->widget.referencePoint->insertItem(6, i18n("Bottom Left")); - d->widget.referencePoint->insertItem(7, i18n("Bottom")); - d->widget.referencePoint->insertItem(8, i18n("Bottom Right")); - - d->widget.refPointOffsetX->setRange(0.0, 100.0); - d->widget.refPointOffsetX->setSuffix(QString('%')); - d->widget.refPointOffsetY->setRange(0.0, 100.0); - d->widget.refPointOffsetY->setSuffix(QString('%')); - d->widget.tileOffsetX->setRange(0.0, 100.0); - d->widget.tileOffsetX->setSuffix(QString('%')); - d->widget.tileOffsetY->setRange(0.0, 100.0); - d->widget.tileOffsetY->setSuffix(QString('%')); - d->widget.patternWidth->setRange(1, 10000); - d->widget.patternHeight->setRange(1, 10000); - - connect(d->widget.patternRepeat, SIGNAL(activated(int)), this, SIGNAL(patternChanged())); - connect(d->widget.patternRepeat, SIGNAL(activated(int)), this, SLOT(updateControls())); - connect(d->widget.referencePoint, SIGNAL(activated(int)), this, SIGNAL(patternChanged())); - connect(d->widget.refPointOffsetX, SIGNAL(valueChanged(double)), this, SIGNAL(patternChanged())); - connect(d->widget.refPointOffsetY, SIGNAL(valueChanged(double)), this, SIGNAL(patternChanged())); - connect(d->widget.tileOffsetX, SIGNAL(valueChanged(double)), this, SIGNAL(patternChanged())); - connect(d->widget.tileOffsetY, SIGNAL(valueChanged(double)), this, SIGNAL(patternChanged())); - connect(d->widget.patternWidth, SIGNAL(valueChanged(int)), this, SIGNAL(patternChanged())); - connect(d->widget.patternHeight, SIGNAL(valueChanged(int)), this, SIGNAL(patternChanged())); -} - -KarbonPatternOptionsWidget::~KarbonPatternOptionsWidget() -{ - delete d; -} - -void KarbonPatternOptionsWidget::setRepeat(KoPatternBackground::PatternRepeat repeat) -{ - d->widget.patternRepeat->blockSignals(true); - d->widget.patternRepeat->setCurrentIndex(repeat); - d->widget.patternRepeat->blockSignals(false); - updateControls(); -} - -KoPatternBackground::PatternRepeat KarbonPatternOptionsWidget::repeat() const -{ - return static_cast(d->widget.patternRepeat->currentIndex()); -} - -KoPatternBackground::ReferencePoint KarbonPatternOptionsWidget::referencePoint() const -{ - return static_cast(d->widget.referencePoint->currentIndex()); -} - -void KarbonPatternOptionsWidget::setReferencePoint(KoPatternBackground::ReferencePoint referencePoint) -{ - d->widget.referencePoint->blockSignals(true); - d->widget.referencePoint->setCurrentIndex(referencePoint); - d->widget.referencePoint->blockSignals(false); -} - -QPointF KarbonPatternOptionsWidget::referencePointOffset() const -{ - return QPointF(d->widget.refPointOffsetX->value(), d->widget.refPointOffsetY->value()); -} - -void KarbonPatternOptionsWidget::setReferencePointOffset(const QPointF &offset) -{ - d->widget.refPointOffsetX->blockSignals(true); - d->widget.refPointOffsetY->blockSignals(true); - d->widget.refPointOffsetX->setValue(offset.x()); - d->widget.refPointOffsetY->setValue(offset.y()); - d->widget.refPointOffsetX->blockSignals(false); - d->widget.refPointOffsetY->blockSignals(false); -} - -QPointF KarbonPatternOptionsWidget::tileRepeatOffset() const -{ - return QPointF(d->widget.tileOffsetX->value(), d->widget.tileOffsetY->value()); -} - -void KarbonPatternOptionsWidget::setTileRepeatOffset(const QPointF &offset) -{ - d->widget.tileOffsetX->blockSignals(true); - d->widget.tileOffsetY->blockSignals(true); - d->widget.tileOffsetX->setValue(offset.x()); - d->widget.tileOffsetY->setValue(offset.y()); - d->widget.tileOffsetX->blockSignals(false); - d->widget.tileOffsetY->blockSignals(false); -} - -QSize KarbonPatternOptionsWidget::patternSize() const -{ - return QSize(d->widget.patternWidth->value(), d->widget.patternHeight->value()); -} - -void KarbonPatternOptionsWidget::setPatternSize(const QSize &size) -{ - d->widget.patternWidth->blockSignals(true); - d->widget.patternHeight->blockSignals(true); - d->widget.patternWidth->setValue(size.width()); - d->widget.patternHeight->setValue(size.height()); - d->widget.patternWidth->blockSignals(false); - d->widget.patternHeight->blockSignals(false); -} - -void KarbonPatternOptionsWidget::updateControls() -{ - bool stretch = d->widget.patternRepeat->currentIndex() == KoPatternBackground::Stretched; - d->widget.patternWidth->setEnabled(! stretch); - d->widget.patternHeight->setEnabled(! stretch); - - bool tiled = d->widget.patternRepeat->currentIndex() == KoPatternBackground::Tiled; - d->widget.referencePoint->setEnabled(tiled); - d->widget.refPointOffsetX->setEnabled(tiled); - d->widget.refPointOffsetY->setEnabled(tiled); - d->widget.tileOffsetX->setEnabled(tiled); - d->widget.tileOffsetY->setEnabled(tiled); -} - diff --git a/plugins/tools/karbonplugins/tools/KarbonPatternOptionsWidget.h b/plugins/tools/karbonplugins/tools/KarbonPatternOptionsWidget.h deleted file mode 100644 index 62e9b63d9e..0000000000 --- a/plugins/tools/karbonplugins/tools/KarbonPatternOptionsWidget.h +++ /dev/null @@ -1,75 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2008 Jan Hambrecht - * - * 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 KARBONPATTERNOPTIONSWIDGET_H -#define KARBONPATTERNOPTIONSWIDGET_H - -#include - -#include - -class KarbonPatternOptionsWidget : public QWidget -{ - Q_OBJECT -public: - explicit KarbonPatternOptionsWidget(QWidget *parent = 0); - ~KarbonPatternOptionsWidget() override; - - /// Sets the pattern repeat - void setRepeat(KoPatternBackground::PatternRepeat repeat); - - /// Return the pattern repeat - KoPatternBackground::PatternRepeat repeat() const; - - /// Returns the pattern reference point identifier - KoPatternBackground::ReferencePoint referencePoint() const; - - /// Sets the pattern reference point - void setReferencePoint(KoPatternBackground::ReferencePoint referencePoint); - - /// Returns reference point offset in percent of the size to fill - QPointF referencePointOffset() const; - - /// Sets the reference point offset in percent of the size to fill - void setReferencePointOffset(const QPointF &offset); - - /// Returns tile repeat offset in percent of the size to fill - QPointF tileRepeatOffset() const; - - /// Sets the tile repeat offset in percent of the size to fill - void setTileRepeatOffset(const QPointF &offset); - - /// Returns the pattern size - QSize patternSize() const; - - /// Sets the pattern size - void setPatternSize(const QSize &size); - -Q_SIGNALS: - /// is emitted whenever an option has changed - void patternChanged(); -private Q_SLOTS: - void updateControls(); -private: - class Private; - Private *const d; - -}; - -#endif // KARBONPATTERNOPTIONSWIDGET_H diff --git a/plugins/tools/karbonplugins/tools/KarbonPatternOptionsWidget.ui b/plugins/tools/karbonplugins/tools/KarbonPatternOptionsWidget.ui deleted file mode 100644 index ddd78a06cc..0000000000 --- a/plugins/tools/karbonplugins/tools/KarbonPatternOptionsWidget.ui +++ /dev/null @@ -1,161 +0,0 @@ - - - PatternOptionsWidget - - - - 0 - 0 - 240 - 253 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Repeat: - - - - - - - - - - Reference Point: - - - - - - - - - - Reference Point Offset - - - - - - - X: - - - - - - - - - - Y: - - - - - - - - - - Tile Offset - - - - - - - X: - - - - - - - - - - Y: - - - - - - - - - - Pattern Size - - - - - - - W: - - - - - - - - - - H: - - - - - - - - - - Qt::Vertical - - - - 94 - 121 - - - - - - - - - KisIntParseSpinBox - QSpinBox -
kis_int_parse_spin_box.h
-
- - KisDoubleParseSpinBox - QDoubleSpinBox -
kis_double_parse_spin_box.h
-
- - KComboBox - QComboBox -
kcombobox.h
-
-
- - -
diff --git a/plugins/tools/karbonplugins/tools/KarbonPatternTool.cpp b/plugins/tools/karbonplugins/tools/KarbonPatternTool.cpp deleted file mode 100644 index c95ad2a3a5..0000000000 --- a/plugins/tools/karbonplugins/tools/KarbonPatternTool.cpp +++ /dev/null @@ -1,366 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2007,2009,2011 Jan Hambrecht - * - * 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 "KarbonPatternTool.h" -#include "KarbonPatternEditStrategy.h" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -KarbonPatternTool::KarbonPatternTool(KoCanvasBase *canvas) - : KoToolBase(canvas) - , m_currentStrategy(0) - , m_optionsWidget(0) -{ -} - -KarbonPatternTool::~KarbonPatternTool() -{ -} - -void KarbonPatternTool::paint(QPainter &painter, const KoViewConverter &converter) -{ - painter.setBrush(Qt::green); //TODO make configurable - painter.setPen(Qt::blue); //TODO make configurable - - // paint all the strategies - Q_FOREACH (KarbonPatternEditStrategyBase *strategy, m_strategies) { - if (strategy == m_currentStrategy) { - continue; - } - - painter.save(); - strategy->paint(painter, converter); - painter.restore(); - } - - // paint selected strategy with another color - if (m_currentStrategy) { - painter.setBrush(Qt::red); //TODO make configurable - m_currentStrategy->paint(painter, converter); - } -} - -void KarbonPatternTool::repaintDecorations() -{ - Q_FOREACH (KarbonPatternEditStrategyBase *strategy, m_strategies) { - canvas()->updateCanvas(strategy->boundingRect()); - } -} - -void KarbonPatternTool::mousePressEvent(KoPointerEvent *event) -{ - //m_currentStrategy = 0; - - Q_FOREACH (KarbonPatternEditStrategyBase *strategy, m_strategies) { - if (strategy->selectHandle(event->point, *canvas()->viewConverter())) { - m_currentStrategy = strategy; - m_currentStrategy->repaint(); - useCursor(Qt::SizeAllCursor); - break; - } - } - if (m_currentStrategy) { - m_currentStrategy->setEditing(true); - updateOptionsWidget(); - } -} - -void KarbonPatternTool::mouseMoveEvent(KoPointerEvent *event) -{ - if (m_currentStrategy) { - m_currentStrategy->repaint(); - if (m_currentStrategy->isEditing()) { - m_currentStrategy->handleMouseMove(event->point, event->modifiers()); - m_currentStrategy->repaint(); - return; - } - } - Q_FOREACH (KarbonPatternEditStrategyBase *strategy, m_strategies) { - if (strategy->selectHandle(event->point, *canvas()->viewConverter())) { - useCursor(Qt::SizeAllCursor); - return; - } - } - useCursor(Qt::ArrowCursor); -} - -void KarbonPatternTool::mouseReleaseEvent(KoPointerEvent *event) -{ - Q_UNUSED(event) - // if we are editing, get out of edit mode and add a command to the stack - if (m_currentStrategy && m_currentStrategy->isEditing()) { - m_currentStrategy->setEditing(false); - KUndo2Command *cmd = m_currentStrategy->createCommand(); - if (cmd) { - canvas()->addCommand(cmd); - } - - updateOptionsWidget(); - } -} - -void KarbonPatternTool::keyPressEvent(QKeyEvent *event) -{ - switch (event->key()) { - case Qt::Key_I: { - KoDocumentResourceManager *rm = canvas()->shapeController()->resourceManager(); - uint handleRadius = rm->handleRadius(); - if (event->modifiers() & Qt::ControlModifier) { - handleRadius--; - } else { - handleRadius++; - } - rm->setHandleRadius(handleRadius); - } - break; - default: - event->ignore(); - return; - } - event->accept(); -} - -void KarbonPatternTool::initialize() -{ - if (m_currentStrategy && m_currentStrategy->isEditing()) { - return; - } - - QList selectedShapes = canvas()->shapeManager()->selection()->selectedShapes(); - - // remove all pattern strategies no longer applicable - Q_FOREACH (KarbonPatternEditStrategyBase *strategy, m_strategies) { - // is this gradient shape still selected ? - if (!selectedShapes.contains(strategy->shape()) || ! strategy->shape()->isShapeEditable()) { - m_strategies.remove(strategy->shape()); - if (m_currentStrategy == strategy) { - m_currentStrategy = 0; - } - delete strategy; - continue; - } - - // does the shape has no fill pattern anymore ? - QSharedPointer fill = qSharedPointerDynamicCast(strategy->shape()->background()); - if (!fill) { - // delete the gradient - m_strategies.remove(strategy->shape()); - if (m_currentStrategy == strategy) { - m_currentStrategy = 0; - } - delete strategy; - continue; - } - - strategy->updateHandles(); - strategy->repaint(); - } - - KoImageCollection *imageCollection = canvas()->shapeController()->resourceManager()->imageCollection(); - - // now create new strategies if needed - Q_FOREACH (KoShape *shape, selectedShapes) { - if (!shape->isShapeEditable()) { - continue; - } - - // do we already have a strategy for that shape? - if (m_strategies.contains(shape)) { - continue; - } - - if (qSharedPointerDynamicCast(shape->background())) { - KarbonPatternEditStrategyBase *s = new KarbonOdfPatternEditStrategy(shape, imageCollection); - m_strategies.insert(shape, s); - s->repaint(); - } - } - // automatically select strategy when editing single shape - if (m_strategies.count() == 1 && ! m_currentStrategy) { - m_currentStrategy = m_strategies.begin().value(); - updateOptionsWidget(); - } - - if (m_currentStrategy) { - m_currentStrategy->repaint(); - } -} - -void KarbonPatternTool::activate(ToolActivation activation, const QSet &shapes) -{ - KoToolBase::activate(activation, shapes); - - if (shapes.isEmpty()) { - emit done(); - return; - } - - initialize(); - - KarbonPatternEditStrategyBase::setHandleRadius(handleRadius()); - KarbonPatternEditStrategyBase::setGrabSensitivity(grabSensitivity()); - - useCursor(Qt::ArrowCursor); - - connect(canvas()->shapeManager(), SIGNAL(selectionContentChanged()), this, SLOT(initialize())); -} - -void KarbonPatternTool::deactivate() -{ - // we are not interested in selection content changes when not active - disconnect(canvas()->shapeManager(), SIGNAL(selectionContentChanged()), this, SLOT(initialize())); - - Q_FOREACH (KarbonPatternEditStrategyBase *strategy, m_strategies) { - strategy->repaint(); - } - - qDeleteAll(m_strategies); - m_strategies.clear(); - - Q_FOREACH (KoShape *shape, canvas()->shapeManager()->selection()->selectedShapes()) { - shape->update(); - } - - m_currentStrategy = 0; - - KoToolBase::deactivate(); -} - -void KarbonPatternTool::documentResourceChanged(int key, const QVariant &res) -{ - switch (key) { - case KoDocumentResourceManager::HandleRadius: - Q_FOREACH (KarbonPatternEditStrategyBase *strategy, m_strategies) { - strategy->repaint(); - } - - KarbonPatternEditStrategyBase::setHandleRadius(res.toUInt()); - - Q_FOREACH (KarbonPatternEditStrategyBase *strategy, m_strategies) { - strategy->repaint(); - } - break; - case KoDocumentResourceManager::GrabSensitivity: - KarbonPatternEditStrategyBase::setGrabSensitivity(res.toUInt()); - break; - default: - return; - } -} - -QList > KarbonPatternTool::createOptionWidgets() -{ - QList > widgets; - - m_optionsWidget = new KarbonPatternOptionsWidget(); - connect(m_optionsWidget, SIGNAL(patternChanged()), - this, SLOT(patternChanged())); - - KisResourceItemChooser *chooser = new KisResourceItemChooser(ResourceType::Patterns, false, m_optionsWidget); - chooser->setObjectName("KarbonPatternChooser"); - - connect(chooser, SIGNAL(resourceSelected(KoResourceSP )), - this, SLOT(patternSelected(KoResourceSP ))); - - m_optionsWidget->setWindowTitle(i18n("Pattern Options")); - widgets.append(m_optionsWidget); - chooser->setWindowTitle(i18n("Patterns")); - widgets.append(chooser); - updateOptionsWidget(); - return widgets; -} - -void KarbonPatternTool::patternSelected(KoResourceSP resource) -{ - KoPatternSP currentPattern = resource.dynamicCast(); - if (!currentPattern || ! currentPattern->valid()) { - return; - } - - KoImageCollection *imageCollection = canvas()->shapeController()->resourceManager()->imageCollection(); - if (imageCollection) { - QList selectedShapes = canvas()->shapeManager()->selection()->selectedShapes(); - QSharedPointer newFill(new KoPatternBackground(imageCollection)); - newFill->setPattern(currentPattern->pattern()); - canvas()->addCommand(new KoShapeBackgroundCommand(selectedShapes, newFill)); - initialize(); - } -} - -void KarbonPatternTool::updateOptionsWidget() -{ - if (m_optionsWidget && m_currentStrategy) { - QSharedPointer fill = qSharedPointerDynamicCast(m_currentStrategy->shape()->background()); - if (fill) { - m_optionsWidget->setRepeat(fill->repeat()); - m_optionsWidget->setReferencePoint(fill->referencePoint()); - m_optionsWidget->setReferencePointOffset(fill->referencePointOffset()); - m_optionsWidget->setTileRepeatOffset(fill->tileRepeatOffset()); - m_optionsWidget->setPatternSize(fill->patternDisplaySize().toSize()); - } - } -} - -void KarbonPatternTool::patternChanged() -{ - if (m_currentStrategy) { - KoShape *shape = m_currentStrategy->shape(); - QSharedPointer oldFill = qSharedPointerDynamicCast(shape->background()); - if (!oldFill) { - return; - } - KoImageCollection *imageCollection = canvas()->shapeController()->resourceManager()->imageCollection(); - if (!imageCollection) { - return; - } - QSharedPointer newFill(new KoPatternBackground(imageCollection)); - if (!newFill) { - return; - } - newFill->setTransform(oldFill->transform()); - newFill->setPattern(oldFill->pattern()); - - newFill->setRepeat(m_optionsWidget->repeat()); - newFill->setReferencePoint(m_optionsWidget->referencePoint()); - newFill->setReferencePointOffset(m_optionsWidget->referencePointOffset()); - newFill->setTileRepeatOffset(m_optionsWidget->tileRepeatOffset()); - newFill->setPatternDisplaySize(m_optionsWidget->patternSize()); - canvas()->addCommand(new KoShapeBackgroundCommand(shape, newFill)); - } -} - diff --git a/plugins/tools/karbonplugins/tools/KarbonPatternTool.h b/plugins/tools/karbonplugins/tools/KarbonPatternTool.h deleted file mode 100644 index 85bb46c3ea..0000000000 --- a/plugins/tools/karbonplugins/tools/KarbonPatternTool.h +++ /dev/null @@ -1,70 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2007,2009 Jan Hambrecht - * - * 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 _KARBONPATTERNTOOL_H_ -#define _KARBONPATTERNTOOL_H_ - -#include -#include - -#include - -class QPainter; - -class KarbonPatternEditStrategyBase; -class KarbonPatternOptionsWidget; -class KoShape; - -class KarbonPatternTool : public KoToolBase -{ - Q_OBJECT -public: - explicit KarbonPatternTool(KoCanvasBase *canvas); - ~KarbonPatternTool() override; - - void paint(QPainter &painter, const KoViewConverter &converter) override; - void repaintDecorations() override; - - void mousePressEvent(KoPointerEvent *event) override; - void mouseMoveEvent(KoPointerEvent *event) override; - void mouseReleaseEvent(KoPointerEvent *event) override; - void keyPressEvent(QKeyEvent *event) override; - - void activate(ToolActivation activation, const QSet &shapes) override; - void deactivate() override; - -public Q_SLOTS: - void documentResourceChanged(int key, const QVariant &res) override; - -protected: - QList > createOptionWidgets() override; - -private Q_SLOTS: - void patternSelected(KoResourceSP resource); - void initialize(); - /// updates options widget from selected pattern - void updateOptionsWidget(); - void patternChanged(); -private: - QMap m_strategies; ///< the list of editing strategies, one for each shape - KarbonPatternEditStrategyBase *m_currentStrategy; ///< the current editing strategy - KarbonPatternOptionsWidget *m_optionsWidget; -}; - -#endif // _KARBONPATTERNTOOL_H_ diff --git a/plugins/tools/karbonplugins/tools/KarbonPatternToolFactory.cpp b/plugins/tools/karbonplugins/tools/KarbonPatternToolFactory.cpp deleted file mode 100644 index eb8df40727..0000000000 --- a/plugins/tools/karbonplugins/tools/KarbonPatternToolFactory.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2007 Jan Hambrecht - * - * 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 "KarbonPatternToolFactory.h" -#include "KarbonPatternTool.h" - -#include -#include -#include - -KarbonPatternToolFactory::KarbonPatternToolFactory() - : KoToolFactoryBase("KarbonPatternTool") -{ - setToolTip(i18n("Pattern editing")); - setSection(mainToolType()); - setIconName(koIconNameCStr("pattern")); - setPriority(8); -} - -KarbonPatternToolFactory::~KarbonPatternToolFactory() -{ -} - -KoToolBase *KarbonPatternToolFactory::createTool(KoCanvasBase *canvas) -{ - return new KarbonPatternTool(canvas); -} diff --git a/plugins/tools/karbonplugins/tools/KarbonPatternToolFactory.h b/plugins/tools/karbonplugins/tools/KarbonPatternToolFactory.h deleted file mode 100644 index 976dffb9c1..0000000000 --- a/plugins/tools/karbonplugins/tools/KarbonPatternToolFactory.h +++ /dev/null @@ -1,34 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2007 Jan Hambrecht - * - * 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 _KARBONPATTERNTOOLFACTORY_H_ -#define _KARBONPATTERNTOOLFACTORY_H_ - -#include - -class KarbonPatternToolFactory : public KoToolFactoryBase -{ -public: - KarbonPatternToolFactory(); - ~KarbonPatternToolFactory() override; - - KoToolBase *createTool(KoCanvasBase *canvas) override; -}; - -#endif // _KARBONPATTERNTOOLFACTORY_H_ diff --git a/plugins/tools/karbonplugins/tools/KarbonToolsPlugin.cpp b/plugins/tools/karbonplugins/tools/KarbonToolsPlugin.cpp index 9e48d217cf..3d2a0805fc 100644 --- a/plugins/tools/karbonplugins/tools/KarbonToolsPlugin.cpp +++ b/plugins/tools/karbonplugins/tools/KarbonToolsPlugin.cpp @@ -1,43 +1,38 @@ /* This file is part of the KDE project * Copyright (C) 2007 Jan Hambrecht * * 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 "KarbonToolsPlugin.h" #include "CalligraphyTool/KarbonCalligraphyToolFactory.h" #include "CalligraphyTool/KarbonCalligraphicShapeFactory.h" -#include "KarbonPatternToolFactory.h" -#include "KarbonFilterEffectsToolFactory.h" #include #include #include #include K_PLUGIN_FACTORY_WITH_JSON(KarbonToolsPluginFactory, "karbon_tools.json", registerPlugin();) KarbonToolsPlugin::KarbonToolsPlugin(QObject *parent, const QVariantList &) : QObject(parent) { KoToolRegistry::instance()->add(new KarbonCalligraphyToolFactory()); - //KoToolRegistry::instance()->add(new KarbonPatternToolFactory()); - //KoToolRegistry::instance()->add(new KarbonFilterEffectsToolFactory()); - KoShapeRegistry::instance()->add(new KarbonCalligraphicShapeFactory()); } #include diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterAddCommand.cpp b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterAddCommand.cpp deleted file mode 100644 index 719bf205c7..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterAddCommand.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "FilterAddCommand.h" -#include "KoShape.h" -#include "KoFilterEffect.h" -#include "KoFilterEffectStack.h" - -#include - -FilterAddCommand::FilterAddCommand(KoFilterEffect *filterEffect, KoShape *shape, KUndo2Command *parent) - : KUndo2Command(parent) - , m_filterEffect(filterEffect) - , m_shape(shape) - , m_isAdded(false) -{ - Q_ASSERT(m_shape); - setText(kundo2_i18n("Add filter effect")); -} - -FilterAddCommand::~FilterAddCommand() -{ - if (!m_isAdded) { - delete m_filterEffect; - } -} - -void FilterAddCommand::redo() -{ - KUndo2Command::redo(); - - if (m_shape->filterEffectStack()) { - m_shape->update(); - m_shape->filterEffectStack()->appendFilterEffect(m_filterEffect); - m_shape->update(); - m_isAdded = true; - } -} - -void FilterAddCommand::undo() -{ - if (m_shape->filterEffectStack()) { - int index = m_shape->filterEffectStack()->filterEffects().indexOf(m_filterEffect); - if (index >= 0) { - m_shape->update(); - m_shape->filterEffectStack()->takeFilterEffect(index); - m_shape->update(); - } - m_isAdded = false; - } - KUndo2Command::undo(); -} diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterAddCommand.h b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterAddCommand.h deleted file mode 100644 index e13bc801e0..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterAddCommand.h +++ /dev/null @@ -1,45 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 FILTERADDCOMMAND_H -#define FILTERADDCOMMAND_H - -#include - -class KoShape; -class KoFilterEffect; - -/// A command do add a new filter effect to a filter effect stack -class FilterAddCommand : public KUndo2Command -{ -public: - FilterAddCommand(KoFilterEffect *filterEffect, KoShape *shape, KUndo2Command *parent = 0); - ~FilterAddCommand() override; - /// redo the command - void redo() override; - /// revert the actions done in redo - void undo() override; - -private: - KoFilterEffect *m_filterEffect; - KoShape *m_shape; - bool m_isAdded; -}; - -#endif // FILTERADDCOMMAND_H diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectEditWidget.cpp b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectEditWidget.cpp deleted file mode 100644 index 686d63955c..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectEditWidget.cpp +++ /dev/null @@ -1,550 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "FilterEffectEditWidget.h" -#include "FilterEffectResource.h" -#include "FilterResourceServerProvider.h" -#include "FilterInputChangeCommand.h" -#include "FilterAddCommand.h" -#include "FilterRemoveCommand.h" -#include "FilterStackSetCommand.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -#include -#include - -FilterEffectEditWidget::FilterEffectEditWidget(QWidget *parent) - : QWidget(parent) - , m_scene(new FilterEffectScene(this)) - , m_shape(0) - , m_canvas(0) - , m_effects(0) -{ - setupUi(this); - - presets->setDisplayMode(KoResourceSelector::TextMode); - presets->setSingleColumn(true); - - connect(presets, SIGNAL(resourceSelected(KoResourceSP )), - this, SLOT(presetSelected(KoResourceSP ))); - - connect(presets, SIGNAL(resourceApplied(KoResourceSP )), - this, SLOT(presetSelected(KoResourceSP ))); - - KoGenericRegistryModel *filterEffectModel = new KoGenericRegistryModel(KoFilterEffectRegistry::instance()); - - effectSelector->setModel(filterEffectModel); - removeEffect->setIcon(koIcon("list-remove")); - connect(removeEffect, SIGNAL(clicked()), this, SLOT(removeSelectedItem())); - addEffect->setIcon(koIcon("list-add")); - addEffect->setToolTip(i18n("Add effect to current filter stack")); - connect(addEffect, SIGNAL(clicked()), this, SLOT(addSelectedEffect())); - - // TODO: make these buttons do something useful - raiseEffect->setIcon(koIcon("arrow-up")); - raiseEffect->hide(); - lowerEffect->setIcon(koIcon("arrow-down")); - lowerEffect->hide(); - - addPreset->setIcon(koIcon("list-add")); - addPreset->setToolTip(i18n("Add to filter presets")); - connect(addPreset, SIGNAL(clicked()), this, SLOT(addToPresets())); - - removePreset->setIcon(koIcon("list-remove")); - removePreset->setToolTip(i18n("Remove filter preset")); - connect(removePreset, SIGNAL(clicked()), this, SLOT(removeFromPresets())); - - view->setScene(m_scene); - view->setRenderHint(QPainter::Antialiasing, true); - view->setResizeAnchor(QGraphicsView::AnchorViewCenter); - - connect(m_scene, SIGNAL(connectionCreated(ConnectionSource,ConnectionTarget)), - this, SLOT(connectionCreated(ConnectionSource,ConnectionTarget))); - connect(m_scene, SIGNAL(selectionChanged()), this, SLOT(sceneSelectionChanged())); - - QSet inputs; - inputs << ConnectionSource::SourceGraphic; - inputs << ConnectionSource::SourceAlpha; - inputs << ConnectionSource::BackgroundImage; - inputs << ConnectionSource::BackgroundAlpha; - inputs << ConnectionSource::FillPaint; - inputs << ConnectionSource::StrokePaint; - - m_defaultSourceSelector = new KComboBox(this); - Q_FOREACH (ConnectionSource::SourceType source, inputs) { - m_defaultSourceSelector->addItem(ConnectionSource::typeToString(source)); - } - m_defaultSourceSelector->hide(); - m_defaultSourceSelector->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - connect(m_defaultSourceSelector, SIGNAL(currentIndexChanged(int)), - this, SLOT(defaultSourceChanged(int))); -} - -FilterEffectEditWidget::~FilterEffectEditWidget() -{ - if (!m_shape) { - delete m_effects; - } -} - -void FilterEffectEditWidget::editShape(KoShape *shape, KoCanvasBase *canvas) -{ - if (!m_shape) { - delete m_effects; - m_effects = 0; - } - - m_shape = shape; - m_canvas = canvas; - - if (m_shape) { - m_effects = m_shape->filterEffectStack(); - } - if (!m_effects) { - m_effects = new KoFilterEffectStack(); - } - - m_scene->initialize(m_effects); - fitScene(); -} - -void FilterEffectEditWidget::fitScene() -{ - QRectF bbox = m_scene->itemsBoundingRect(); - m_scene->setSceneRect(bbox); - bbox.adjust(-25, -25, 25, 25); - view->centerOn(bbox.center()); - view->fitInView(bbox, Qt::KeepAspectRatio); -} - -void FilterEffectEditWidget::resizeEvent(QResizeEvent *event) -{ - Q_UNUSED(event); - fitScene(); -} - -void FilterEffectEditWidget::showEvent(QShowEvent *event) -{ - Q_UNUSED(event); - fitScene(); -} - -void FilterEffectEditWidget::addSelectedEffect() -{ - KoFilterEffectRegistry *registry = KoFilterEffectRegistry::instance(); - KoFilterEffectFactoryBase *factory = registry->values()[effectSelector->currentIndex()]; - if (!factory) { - return; - } - - KoFilterEffect *effect = factory->createFilterEffect(); - if (!effect) { - return; - } - - if (m_shape) { - if (!m_shape->filterEffectStack()) { - m_effects->appendFilterEffect(effect); - m_canvas->addCommand(new FilterStackSetCommand(m_effects, m_shape)); - } else { - m_canvas->addCommand(new FilterAddCommand(effect, m_shape)); - } - } else { - m_effects->appendFilterEffect(effect); - } - - m_scene->initialize(m_effects); - fitScene(); -} - -void FilterEffectEditWidget::removeSelectedItem() -{ - QList selectedItems = m_scene->selectedEffectItems(); - if (!selectedItems.count()) { - return; - } - - QList changeData; - QList filterEffects = m_effects->filterEffects(); - int effectIndexToDelete = -1; - - const ConnectionSource &item = selectedItems.first(); - KoFilterEffect *effect = item.effect(); - if (item.type() == ConnectionSource::Effect) { - int effectIndex = filterEffects.indexOf(effect); - // adjust inputs of all following effects in the stack - for (int i = effectIndex + 1; i < filterEffects.count(); ++i) { - KoFilterEffect *nextEffect = filterEffects[i]; - QList inputs = nextEffect->inputs(); - int inputIndex = 0; - Q_FOREACH (const QString &input, inputs) { - if (input == effect->output()) { - InputChangeData data(nextEffect, inputIndex, input, ""); - changeData.append(data); - } - } - // if one of the next effects has the same output name we stop - if (nextEffect->output() == effect->output()) { - break; - } - } - effectIndexToDelete = effectIndex; - } else { - QString outputName = ConnectionSource::typeToString(item.type()); - QList inputs = effect->inputs(); - int inputIndex = 0; - Q_FOREACH (const QString &input, inputs) { - if (input == outputName) { - InputChangeData data(effect, inputIndex, input, ""); - changeData.append(data); - } - inputIndex++; - } - } - - KUndo2Command *cmd = new KUndo2Command(); - if (changeData.count()) { - KUndo2Command *subCmd = new FilterInputChangeCommand(changeData, m_shape, cmd); - cmd->setText(subCmd->text()); - } - if (effectIndexToDelete >= 0) { - KUndo2Command *subCmd = new FilterRemoveCommand(effectIndexToDelete, m_effects, m_shape, cmd); - cmd->setText(subCmd->text()); - } - if (m_canvas && m_shape) { - m_canvas->addCommand(cmd); - } else { - cmd->redo(); - delete cmd; - } - m_scene->initialize(m_effects); - fitScene(); -} - -void FilterEffectEditWidget::connectionCreated(ConnectionSource source, ConnectionTarget target) -{ - QList filterEffects = m_effects->filterEffects(); - - int targetEffectIndex = filterEffects.indexOf(target.effect()); - if (targetEffectIndex < 0) { - return; - } - - QList changeData; - QString sourceName; - - if (source.type() == ConnectionSource::Effect) { - sourceName = source.effect()->output(); - int sourceEffectIndex = filterEffects.indexOf(source.effect()); - if (targetEffectIndex - sourceEffectIndex > 1) { - // there are effects between source effect and target effect - // so we have to take extra care - bool renameOutput = false; - if (sourceName.isEmpty()) { - // output is not named so we have to rename the source output - // and adjust the next effect in case it uses this output - renameOutput = true; - } else { - // output is named but if there is an effect with the same - // output name, we have to rename the source output - for (int i = sourceEffectIndex + 1; i < targetEffectIndex; ++i) { - KoFilterEffect *effect = filterEffects[i]; - if (effect->output() == sourceName) { - renameOutput = true; - break; - } - } - } - if (renameOutput) { - QSet uniqueOutputNames; - Q_FOREACH (KoFilterEffect *effect, filterEffects) { - uniqueOutputNames.insert(effect->output()); - } - int index = 0; - QString newOutputName; - do { - newOutputName = QString("result%1").arg(index); - } while (uniqueOutputNames.contains(newOutputName)); - - // rename source output - source.effect()->setOutput(newOutputName); - // adjust following effects - for (int i = sourceEffectIndex + 1; i < targetEffectIndex; ++i) { - KoFilterEffect *effect = filterEffects[i]; - int inputIndex = 0; - Q_FOREACH (const QString &input, effect->inputs()) { - if (input.isEmpty() && (i == sourceEffectIndex + 1 || input == sourceName)) { - InputChangeData data(effect, inputIndex, input, newOutputName); - changeData.append(data); - } - inputIndex++; - } - if (sourceName.isEmpty() || effect->output() == sourceName) { - break; - } - } - sourceName = newOutputName; - } - } - } else { - // source is an predefined input image - sourceName = ConnectionSource::typeToString(source.type()); - } - - // finally set the input of the target - if (target.inputIndex() >= target.effect()->inputs().count()) { - // insert new input here - target.effect()->addInput(sourceName); - } else { - QString oldInput = target.effect()->inputs()[target.inputIndex()]; - InputChangeData data(target.effect(), target.inputIndex(), oldInput, sourceName); - changeData.append(data); - } - - if (changeData.count()) { - KUndo2Command *cmd = new FilterInputChangeCommand(changeData, m_shape); - if (m_canvas) { - m_canvas->addCommand(cmd); - } else { - cmd->redo(); - delete cmd; - } - } - m_scene->initialize(m_effects); - fitScene(); -} - -void FilterEffectEditWidget::addToPresets() -{ - if (!m_effects) { - return; - } - - bool ok = false; - QString effectName = QInputDialog::getText(this, i18n("Effect name"), - i18n("Please enter a name for the filter effect"), - QLineEdit::Normal, - QString(), - &ok); - if (!ok) { - return; - } - - QSharedPointer resource(FilterEffectResource::fromFilterEffectStack(m_effects)); - if (!resource) { - return; - } - - resource->setName(effectName); - - FilterResourceServerProvider *serverProvider = FilterResourceServerProvider::instance(); - KoResourceServer *server = serverProvider->filterEffectServer(); - - QString savePath = server->saveLocation(); - - int i = 1; - QFileInfo fileInfo; - - do { - fileInfo.setFile(savePath + QString("%1.svg").arg(i++, 4, 10, QChar('0'))); - } while (fileInfo.exists()); - - resource->setFilename(fileInfo.filePath()); - resource->setValid(true); -} - -void FilterEffectEditWidget::removeFromPresets() -{ - if (!presets->count()) { - return; - } - - FilterResourceServerProvider *serverProvider = FilterResourceServerProvider::instance(); - if (!serverProvider) { - return; - } - - KoResourceServer *server = serverProvider->filterEffectServer(); - if (!server) { - return; - } - - QSharedPointer resource = server->resources().at(presets->currentIndex()); - if (!resource) { - return; - } - - server->removeResourceFromServer(resource); -} - -void FilterEffectEditWidget::presetSelected(KoResourceSP resource) -{ - QSharedPointer effectResource = resource.dynamicCast(); - if (!effectResource) { - return; - } - - KoFilterEffectStack *filterStack = effectResource->toFilterStack(); - if (!filterStack) { - return; - } - - if (m_shape) { - KUndo2Command *cmd = new FilterStackSetCommand(filterStack, m_shape); - if (m_canvas) { - m_canvas->addCommand(cmd); - } else { - cmd->redo(); - delete cmd; - } - } else { - delete m_effects; - } - m_effects = filterStack; - - m_scene->initialize(m_effects); - fitScene(); -} - -void FilterEffectEditWidget::addWidgetForItem(ConnectionSource item) -{ - // get the filter effect from the item - KoFilterEffect *filterEffect = item.effect(); - if (item.type() != ConnectionSource::Effect) { - filterEffect = 0; - } - - KoFilterEffect *currentEffect = m_currentItem.effect(); - if (m_currentItem.type() != ConnectionSource::Effect) { - currentEffect = 0; - } - - m_defaultSourceSelector->hide(); - - // remove current widget if new effect is zero or effect type has changed - if (!filterEffect || !currentEffect || (filterEffect->id() != currentEffect->id())) { - while (configStack->count()) { - configStack->removeWidget(configStack->widget(0)); - } - } - - m_currentItem = item; - - KoFilterEffectConfigWidgetBase *currentPanel = 0; - - if (!filterEffect) { - if (item.type() != ConnectionSource::Effect) { - configStack->insertWidget(0, m_defaultSourceSelector); - m_defaultSourceSelector->blockSignals(true); - m_defaultSourceSelector->setCurrentIndex(item.type() - 1); - m_defaultSourceSelector->blockSignals(false); - m_defaultSourceSelector->show(); - } - } else if (!currentEffect || currentEffect->id() != filterEffect->id()) { - // when a shape is set and is differs from the previous one - // get the config widget and insert it into the option widget - - KoFilterEffectRegistry *registry = KoFilterEffectRegistry::instance(); - KoFilterEffectFactoryBase *factory = registry->value(filterEffect->id()); - if (!factory) { - return; - } - - currentPanel = factory->createConfigWidget(); - if (!currentPanel) { - return; - } - - configStack->insertWidget(0, currentPanel); - connect(currentPanel, SIGNAL(filterChanged()), this, SLOT(filterChanged())); - } - - currentPanel = qobject_cast(configStack->widget(0)); - if (currentPanel) { - currentPanel->editFilterEffect(filterEffect); - } -} - -void FilterEffectEditWidget::filterChanged() -{ - if (m_shape) { - m_shape->update(); - } -} - -void FilterEffectEditWidget::sceneSelectionChanged() -{ - QList selectedItems = m_scene->selectedEffectItems(); - if (!selectedItems.count()) { - addWidgetForItem(ConnectionSource()); - } else { - addWidgetForItem(selectedItems.first()); - } -} - -void FilterEffectEditWidget::defaultSourceChanged(int index) -{ - if (m_currentItem.type() == ConnectionSource::Effect) { - return; - } - - KoFilterEffect *filterEffect = m_currentItem.effect(); - if (!filterEffect) { - return; - } - - QString oldInput = ConnectionSource::typeToString(m_currentItem.type()); - QString newInput = m_defaultSourceSelector->itemText(index); - - const QString defInput = "SourceGraphic"; - int effectIndex = m_effects->filterEffects().indexOf(filterEffect); - - InputChangeData data; - int inputIndex = 0; - Q_FOREACH (const QString &input, filterEffect->inputs()) { - if (input == oldInput || (effectIndex == 0 && oldInput == defInput)) { - data = InputChangeData(filterEffect, inputIndex, input, newInput); - break; - } - inputIndex++; - } - KUndo2Command *cmd = new FilterInputChangeCommand(data, m_shape); - if (m_canvas && m_shape) { - m_canvas->addCommand(cmd); - } else { - cmd->redo(); - delete cmd; - } - - m_scene->initialize(m_effects); - fitScene(); -} diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectEditWidget.h b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectEditWidget.h deleted file mode 100644 index 956254e3fe..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectEditWidget.h +++ /dev/null @@ -1,71 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 FILTEREFFECTEDITWIDGET_H -#define FILTEREFFECTEDITWIDGET_H - -#include "ui_FilterEffectEditWidget.h" -#include "FilterEffectScene.h" -#include -#include - -#include - -class KoShape; -class KoFilterEffect; -class KoFilterEffectStack; - -class FilterEffectEditWidget : public QWidget, Ui::FilterEffectEditWidget -{ - Q_OBJECT -public: - explicit FilterEffectEditWidget(QWidget *parent = 0); - ~FilterEffectEditWidget() override; - - /// Edits effects of given shape - void editShape(KoShape *shape, KoCanvasBase *canvas); - -protected: - /// reimplemented from QWidget - void resizeEvent(QResizeEvent *event) override; - /// reimplemented from QWidget - void showEvent(QShowEvent *event) override; -private Q_SLOTS: - void addSelectedEffect(); - void removeSelectedItem(); - void connectionCreated(ConnectionSource source, ConnectionTarget target); - void addToPresets(); - void removeFromPresets(); - void presetSelected(KoResourceSP resource); - void filterChanged(); - void sceneSelectionChanged(); - void defaultSourceChanged(int); -private: - void fitScene(); - void addWidgetForItem(ConnectionSource item); - - FilterEffectScene *m_scene; - KoShape *m_shape; - QPointer m_canvas; - KoFilterEffectStack *m_effects; - ConnectionSource m_currentItem; - KComboBox *m_defaultSourceSelector; -}; - -#endif // FILTEREFFECTEDITWIDGET_H diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectEditWidget.ui b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectEditWidget.ui deleted file mode 100644 index d507339135..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectEditWidget.ui +++ /dev/null @@ -1,175 +0,0 @@ - - - FilterEffectEditWidget - - - - 0 - 0 - 446 - 414 - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - Filter Effect Editor - - - - - - - - Effects and Connections - - - - - - - - 0 - 350 - - - - - - - - ... - - - - - - - - - - ... - - - - - - - ... - - - - - - - ... - - - - - - - - - - - Filter Presets - - - - - - - - - - ... - - - - - - - ... - - - - - - - Effect Properties - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - 1 - - - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 20 - 295 - - - - - - - - - - - KComboBox - QComboBox -
kcombobox.h
-
- - KoResourceSelector - QComboBox -
KoResourceSelector.h
-
-
- - -
diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectResource.cpp b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectResource.cpp deleted file mode 100644 index 380fbe1de3..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectResource.cpp +++ /dev/null @@ -1,196 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "FilterEffectResource.h" -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -double fromPercentage(QString s) -{ - if (s.endsWith('%')) { - return s.remove('%').toDouble() / 100.0; - } else { - return s.toDouble(); - } -} - -FilterEffectResource::FilterEffectResource(const QString &filename) - : KoResource(filename) -{ -} - -bool FilterEffectResource::load() -{ - QFile file(filename()); - - if (file.size() == 0) { - return false; - } - if (!file.open(QIODevice::ReadOnly)) { - return false; - } - - bool res = loadFromDevice(&file); - - file.close(); - return res; -} - -bool FilterEffectResource::loadFromDevice(QIODevice *dev) -{ - if (!m_data.setContent(dev)) { - return false; - } - - setName(m_data.documentElement().attribute("id")); - setValid(true); - - return true; -} - -bool FilterEffectResource::save() -{ - QFile file(filename()); - if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - return false; - } - bool result = saveToDevice(&file); - file.close(); - return result; -} - -bool FilterEffectResource::saveToDevice(QIODevice *dev) const -{ - m_data.documentElement().setAttribute("id", name()); - QByteArray ba = m_data.toByteArray(2); - bool success = (dev->write(ba) == ba.size()); - return success; -} - -QString FilterEffectResource::defaultFileExtension() const -{ - return QString(".svg"); -} - -FilterEffectResource *FilterEffectResource::fromFilterEffectStack(KoFilterEffectStack *filterStack) -{ - if (!filterStack) { - return 0; - } - - QByteArray ba; - QBuffer buffer(&ba); - buffer.open(QIODevice::ReadWrite); - KoXmlWriter writer(&buffer); - - filterStack->save(writer, ""); - - buffer.close(); - - FilterEffectResource *resource = new FilterEffectResource(QString()); - if (!resource->m_data.setContent(ba)) { - delete resource; - return 0; - } - - return resource; -} - -KoFilterEffectStack *FilterEffectResource::toFilterStack() const -{ - QScopedPointer filterStack(new KoFilterEffectStack()); - - QByteArray data = m_data.toByteArray(); - KoXmlDocument doc; - doc.setContent(data); - KoXmlElement e = doc.documentElement(); - - // only allow object bounding box units - if (e.hasAttribute("filterUnits") && e.attribute("filterUnits") != "objectBoundingBox") { - return 0; - } - - if (e.attribute("primitiveUnits") != "objectBoundingBox") { - return 0; - } - - // parse filter region rectangle - QRectF filterRegion; - filterRegion.setX(fromPercentage(e.attribute("x", "-0.1"))); - filterRegion.setY(fromPercentage(e.attribute("y", "-0.1"))); - filterRegion.setWidth(fromPercentage(e.attribute("width", "1.2"))); - filterRegion.setHeight(fromPercentage(e.attribute("height", "1.2"))); - filterStack->setClipRect(filterRegion); - - KoFilterEffectLoadingContext context; - - KoFilterEffectRegistry *registry = KoFilterEffectRegistry::instance(); - - // create the filter effects and add them to the shape - for (KoXmlNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) { - KoXmlElement primitive = n.toElement(); - KoFilterEffect *filterEffect = registry->createFilterEffectFromXml(primitive, context); - if (!filterEffect) { - qWarning() << "filter effect" << primitive.tagName() << "is not implemented yet"; - continue; - } - - // parse subregion - qreal x = fromPercentage(primitive.attribute("x", "0")); - qreal y = fromPercentage(primitive.attribute("y", "0")); - qreal w = fromPercentage(primitive.attribute("width", "1")); - qreal h = fromPercentage(primitive.attribute("height", "1")); - QRectF subRegion(QPointF(x, y), QSizeF(w, h)); - - if (primitive.hasAttribute("in")) { - filterEffect->setInput(0, primitive.attribute("in")); - } - if (primitive.hasAttribute("result")) { - filterEffect->setOutput(primitive.attribute("result")); - } - - filterEffect->setFilterRect(subRegion); - - filterStack->appendFilterEffect(filterEffect); - } - - return filterStack.take(); -} - -QByteArray FilterEffectResource::generateMD5() const -{ - QByteArray ba = m_data.toByteArray(); - if (!ba.isEmpty()) { - QCryptographicHash md5(QCryptographicHash::Md5); - md5.addData(ba); - return md5.result(); - } - return ba; - -} diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectResource.h b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectResource.h deleted file mode 100644 index 56b6d99582..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectResource.h +++ /dev/null @@ -1,60 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 FILTEREFFECTRESOURCE_H -#define FILTEREFFECTRESOURCE_H - -#include -#include -#include - -class KoFilterEffectStack; - -class FilterEffectResource : public KoResource -{ -public: - explicit FilterEffectResource(const QString &filename); - - /// reimplemented from KoResource - bool load() override; - - /// reimplemented from KoResource - bool loadFromDevice(QIODevice *dev) override; - - /// reimplemented from KoResource - bool save() override; - - /// reimplemented from KoResource - bool saveToDevice(QIODevice *dev) const override; - - /// reimplemented from KoResource - QString defaultFileExtension() const override; - - /// Creates resource from given filter effect stack - static FilterEffectResource *fromFilterEffectStack(KoFilterEffectStack *filterStack); - - /// Creates a new filter stack from this filter resource - KoFilterEffectStack *toFilterStack() const; -protected: - QByteArray generateMD5() const override; -private: - QDomDocument m_data; -}; - -#endif // FILTEREFFECTRESOURCE_H diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectScene.cpp b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectScene.cpp deleted file mode 100644 index fca94d5be3..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectScene.cpp +++ /dev/null @@ -1,369 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "FilterEffectScene.h" -#include "FilterEffectSceneItems.h" -#include "KoShape.h" -#include "KoFilterEffect.h" -#include "KoFilterEffectStack.h" - -#include -#include - -#include -#include - -const qreal ItemSpacing = 10.0; -const qreal ConnectionDistance = 10.0; - -ConnectionSource::ConnectionSource() - : m_type(Effect) - , m_effect(0) -{ -} - -ConnectionSource::ConnectionSource(KoFilterEffect *effect, SourceType type) - : m_type(type) - , m_effect(effect) -{ -} - -ConnectionSource::SourceType ConnectionSource::type() const -{ - return m_type; -} - -KoFilterEffect *ConnectionSource::effect() const -{ - return m_effect; -} - -ConnectionSource::SourceType ConnectionSource::typeFromString(const QString &str) -{ - if (str == "SourceGraphic") { - return SourceGraphic; - } else if (str == "SourceAlpha") { - return SourceAlpha; - } else if (str == "BackgroundImage") { - return BackgroundImage; - } else if (str == "BackgroundAlpha") { - return BackgroundAlpha; - } else if (str == "FillPaint") { - return FillPaint; - } else if (str == "StrokePaint") { - return StrokePaint; - } else { - return Effect; - } -} - -QString ConnectionSource::typeToString(SourceType type) -{ - if (type == SourceGraphic) { - return "SourceGraphic"; - } else if (type == SourceAlpha) { - return "SourceAlpha"; - } else if (type == BackgroundImage) { - return "BackgroundImage"; - } else if (type == BackgroundAlpha) { - return "BackgroundAlpha"; - } else if (type == FillPaint) { - return "FillPaint"; - } else if (type == StrokePaint) { - return "StrokePaint"; - } else { - return ""; - } -} - -ConnectionTarget::ConnectionTarget() - : m_inputIndex(0) - , m_effect(0) -{ -} - -ConnectionTarget::ConnectionTarget(KoFilterEffect *effect, int inputIndex) - : m_inputIndex(inputIndex) - , m_effect(effect) -{ -} - -int ConnectionTarget::inputIndex() const -{ - return m_inputIndex; -} - -KoFilterEffect *ConnectionTarget::effect() const -{ - return m_effect; -} - -FilterEffectScene::FilterEffectScene(QObject *parent) - : QGraphicsScene(parent) - , m_effectStack(0) -{ - m_defaultInputs << "SourceGraphic" << "SourceAlpha"; - m_defaultInputs << "FillPaint" << "StrokePaint"; - m_defaultInputs << "BackgroundImage" << "BackgroundAlpha"; - - connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); -} - -FilterEffectScene::~FilterEffectScene() -{ -} - -void FilterEffectScene::initialize(KoFilterEffectStack *effectStack) -{ - m_items.clear(); - m_connectionItems.clear(); - m_outputs.clear(); - clear(); - - m_effectStack = effectStack; - - if (!m_effectStack) { - return; - } - - QList filterEffects = m_effectStack->filterEffects(); - if (!filterEffects.count()) { - return; - } - - Q_FOREACH (KoFilterEffect *effect, filterEffects) { - createEffectItems(effect); - } - - layoutEffects(); - layoutConnections(); -} - -void FilterEffectScene::createEffectItems(KoFilterEffect *effect) -{ - const bool isFirstItem = m_items.count() == 0; - const QString defaultInput = isFirstItem ? "SourceGraphic" : m_items.last()->outputName(); - - QList inputs = effect->inputs(); - for (int i = inputs.count(); i < effect->requiredInputCount(); ++i) { - inputs.append(defaultInput); - } - - QSet defaultItems; - Q_FOREACH (const QString ¤tInput, inputs) { - const QString &input = currentInput.isEmpty() ? defaultInput : currentInput; - if (m_defaultInputs.contains(input) && ! defaultItems.contains(input)) { - DefaultInputItem *item = new DefaultInputItem(input, effect); - addSceneItem(item); - m_outputs.insert(item->outputName(), item); - defaultItems.insert(input); - } - } - - EffectItem *effectItem = new EffectItem(effect); - - // create connections - int index = 0; - Q_FOREACH (const QString ¤tInput, inputs) { - const QString &input = currentInput.isEmpty() ? defaultInput : currentInput; - EffectItemBase *outputItem = m_outputs.value(input, 0); - if (outputItem) { - ConnectionItem *connectionItem = new ConnectionItem(outputItem, effectItem, index); - addSceneItem(connectionItem); - } - index++; - } - - addSceneItem(effectItem); - - m_outputs.insert(effectItem->outputName(), effectItem); -} - -void FilterEffectScene::addSceneItem(QGraphicsItem *item) -{ - addItem(item); - EffectItemBase *effectItem = dynamic_cast(item); - if (effectItem) { - m_items.append(effectItem); - } else { - ConnectionItem *connectionItem = dynamic_cast(item); - if (connectionItem) { - m_connectionItems.append(connectionItem); - } - } -} - -void FilterEffectScene::layoutEffects() -{ - QPointF position(25, 25); - Q_FOREACH (EffectItemBase *item, m_items) { - item->setPos(position); - position.ry() += item->rect().height() + ItemSpacing; - } -} - -void FilterEffectScene::layoutConnections() -{ - QList > sortedConnections; - - // calculate connection sizes from item distances - int connectionIndex = 0; - Q_FOREACH (ConnectionItem *item, m_connectionItems) { - int sourceIndex = m_items.indexOf(item->sourceItem()); - int targetIndex = m_items.indexOf(item->targetItem()); - sortedConnections.append(QPair(targetIndex - sourceIndex, connectionIndex)); - connectionIndex++; - } - - std::sort(sortedConnections.begin(), sortedConnections.end()); - qreal distance = ConnectionDistance; - int lastSize = -1; - int connectionCount = sortedConnections.count(); - for (int i = 0; i < connectionCount; ++i) { - const QPair &connection = sortedConnections[i]; - - int size = connection.first; - if (size > lastSize) { - lastSize = size; - distance += ConnectionDistance; - } - - ConnectionItem *connectionItem = m_connectionItems[connection.second]; - if (!connectionItem) { - continue; - } - EffectItemBase *sourceItem = connectionItem->sourceItem(); - EffectItemBase *targetItem = connectionItem->targetItem(); - if (!sourceItem || ! targetItem) { - continue; - } - - int targetInput = connectionItem->targetInput(); - QPointF sourcePos = sourceItem->mapToScene(sourceItem->outputPosition()); - QPointF targetPos = targetItem->mapToScene(targetItem->inputPosition(targetInput)); - QPainterPath path; - path.moveTo(sourcePos + QPointF(0.5 * sourceItem->connectorSize().width(), 0)); - path.lineTo(sourcePos + QPointF(distance, 0)); - path.lineTo(targetPos + QPointF(distance, 0)); - path.lineTo(targetPos + QPointF(0.5 * targetItem->connectorSize().width(), 0)); - connectionItem->setPath(path); - } -} - -void FilterEffectScene::selectionChanged() -{ - if (selectedItems().count()) { - Q_FOREACH (EffectItemBase *item, m_items) { - if (item->isSelected()) { - item->setOpacity(1.0); - } else { - item->setOpacity(0.25); - } - } - } else { - Q_FOREACH (EffectItemBase *item, m_items) { - item->setOpacity(1); - } - } -} - -QList FilterEffectScene::selectedEffectItems() const -{ - QList effectItems; - - QList selectedGraphicsItems = selectedItems(); - if (!selectedGraphicsItems.count()) { - return effectItems; - } - if (!m_items.count()) { - return effectItems; - } - - Q_FOREACH (QGraphicsItem *item, selectedGraphicsItems) { - EffectItemBase *effectItem = dynamic_cast(item); - if (!effectItem) { - continue; - } - - ConnectionSource::SourceType type = ConnectionSource::Effect; - - KoFilterEffect *effect = effectItem->effect(); - if (dynamic_cast(item)) { - type = ConnectionSource::typeFromString(effectItem->outputName()); - } - - effectItems.append(ConnectionSource(effect, type)); - } - - return effectItems; -} - -void FilterEffectScene::dropEvent(QGraphicsSceneDragDropEvent *event) -{ - ConnectorItem *dropTargetItem = 0; - QList itemsAtPositon = items(event->scenePos()); - Q_FOREACH (QGraphicsItem *item, itemsAtPositon) { - dropTargetItem = dynamic_cast(item); - if (dropTargetItem) { - break; - } - } - if (!dropTargetItem) { - return; - } - - const ConnectorMimeData *data = dynamic_cast(event->mimeData()); - if (!data) { - return; - } - - ConnectorItem *dropSourceItem = data->connector(); - if (!dropSourceItem) { - return; - } - - EffectItemBase *outputParentItem = 0; - KoFilterEffect *inputEffect = 0; - KoFilterEffect *outputEffect = 0; - int inputIndex = 0; - - if (dropTargetItem->connectorType() == ConnectorItem::Input) { - // dropped output onto an input - outputParentItem = dynamic_cast(dropSourceItem->parentItem()); - outputEffect = dropSourceItem->effect(); - inputEffect = dropTargetItem->effect(); - inputIndex = dropTargetItem->connectorIndex(); - } else { - // dropped input onto an output - outputParentItem = dynamic_cast(dropTargetItem->parentItem()); - outputEffect = dropTargetItem->effect(); - inputEffect = dropSourceItem->effect(); - inputIndex = dropSourceItem->connectorIndex(); - } - - ConnectionSource::SourceType outputType = ConnectionSource::Effect; - // check if item with the output is a predefined one - if (m_defaultInputs.contains(outputParentItem->outputName())) { - outputType = ConnectionSource::typeFromString(outputParentItem->outputName()); - outputEffect = 0; - } - ConnectionSource source(outputEffect, outputType); - ConnectionTarget target(inputEffect, inputIndex); - emit connectionCreated(source, target); -} diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectScene.h b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectScene.h deleted file mode 100644 index e7092e5be5..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectScene.h +++ /dev/null @@ -1,113 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 FILTEREFFECTSCENE_H -#define FILTEREFFECTSCENE_H - -#include -#include -#include - -class KoFilterEffect; -class KoFilterEffectStack; -class QGraphicsItem; -class EffectItemBase; -class EffectItem; -class ConnectionItem; - -class ConnectionSource -{ -public: - enum SourceType { - Effect, ///< a complete effect item - SourceGraphic, ///< SourceGraphic predefined input image - SourceAlpha, ///< SourceAlpha predefined input image - BackgroundImage, ///< BackgroundImage predefined input image - BackgroundAlpha, ///< BackgroundAlpha predefined input image - FillPaint, ///< FillPaint predefined input image - StrokePaint ///< StrokePaint predefined input image - }; - ConnectionSource(); - ConnectionSource(KoFilterEffect *effect, SourceType type); - /// Returns the source type - SourceType type() const; - /// Returns the corresponding filter effect, or 0 if type == Effect - KoFilterEffect *effect() const; - - static SourceType typeFromString(const QString &str); - static QString typeToString(SourceType type); - -private: - SourceType m_type; ///< the source type - KoFilterEffect *m_effect; ///< the corresponding effect if type == Effect, 0 otherwise -}; - -class ConnectionTarget -{ -public: - ConnectionTarget(); - ConnectionTarget(KoFilterEffect *effect, int inputIndex); - - /// Returns the target input index - int inputIndex() const; - /// Returns the corresponding filter effect - KoFilterEffect *effect() const; - -private: - int m_inputIndex; ///< the index of the input of the target effect - KoFilterEffect *m_effect; ///< the target effect -}; - -class FilterEffectScene : public QGraphicsScene -{ - Q_OBJECT -public: - explicit FilterEffectScene(QObject *parent = 0); - ~FilterEffectScene() override; - - /// initializes the scene from the filter effect stack - void initialize(KoFilterEffectStack *effectStack); - - /// Returns list of selected effect items - QList selectedEffectItems() const; - -Q_SIGNALS: - void connectionCreated(ConnectionSource source, ConnectionTarget target); - -protected: - /// reimplemented from QGraphicsScene - void dropEvent(QGraphicsSceneDragDropEvent *event) override; - -private Q_SLOTS: - void selectionChanged(); -private: - void createEffectItems(KoFilterEffect *effect); - void addSceneItem(QGraphicsItem *item); - void layoutConnections(); - void layoutEffects(); - - QList m_defaultInputs; - KoFilterEffectStack *m_effectStack; - QList m_items; - QList m_connectionItems; - QMap m_outputs; - QGraphicsProxyWidget *m_defaultInputProxy; -}; - -#endif // FILTEREFFECTSCENE_H diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectSceneItems.cpp b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectSceneItems.cpp deleted file mode 100644 index c06d4059d3..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectSceneItems.cpp +++ /dev/null @@ -1,321 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "FilterEffectSceneItems.h" -#include "KoFilterEffect.h" - -#include -#include -#include -#include -#include - -const QSizeF ConnectorSize = QSize(20, 20); -const qreal ItemWidth = 15 * ConnectorSize.height(); -const qreal FontSize = 0.8 * ConnectorSize.height(); - -ConnectorItem::ConnectorItem(ConnectorType type, int index, QGraphicsItem *parent) - : QGraphicsEllipseItem(parent) - , m_type(type) - , m_index(index) -{ - if (m_type == Output) { - setBrush(QBrush(Qt::red)); - } else if (m_type == Input) { - setBrush(QBrush(Qt::green)); - } - setAcceptDrops(true); - setRect(QRectF(QPointF(), ConnectorSize)); -} - -void ConnectorItem::setCenter(const QPointF &position) -{ - QRectF r = rect(); - r.moveCenter(position); - setRect(r); -} - -ConnectorItem::ConnectorType ConnectorItem::connectorType() -{ - return m_type; -} - -int ConnectorItem::connectorIndex() const -{ - return m_index; -} - -KoFilterEffect *ConnectorItem::effect() const -{ - if (!parentItem()) { - return 0; - } - EffectItemBase *effectItem = dynamic_cast(parentItem()); - if (!effectItem) { - return 0; - } - - return effectItem->effect(); -} - -ConnectorMimeData::ConnectorMimeData(ConnectorItem *connector) - : m_connector(connector) -{ -} - -ConnectorItem *ConnectorMimeData::connector() const -{ - return m_connector; -} - -EffectItemBase::EffectItemBase(KoFilterEffect *effect) - : QGraphicsRectItem(0), m_effect(effect) -{ - setZValue(1); - setFlags(QGraphicsItem::ItemIsSelectable); - setAcceptDrops(true); - setHandlesChildEvents(true); -} - -void EffectItemBase::createText(const QString &text) -{ - QGraphicsSimpleTextItem *textItem = new QGraphicsSimpleTextItem(text, this); - QFont font = textItem->font(); - font.setPointSize(FontSize); - textItem->setFont(font); - QRectF textBox = textItem->boundingRect(); - QPointF offset = rect().center() - textBox.center(); - setTransform(QTransform::fromTranslate(offset.x(), offset.y()), true); -} - -void EffectItemBase::createOutput(const QPointF &position, const QString &name) -{ - ConnectorItem *connector = new ConnectorItem(ConnectorItem::Output, 0, this); - connector->setCenter(position); - - m_outputPosition = position; - m_outputName = name; -} - -void EffectItemBase::createInput(const QPointF &position) -{ - int inputCount = m_inputPositions.count(); - ConnectorItem *connector = new ConnectorItem(ConnectorItem::Input, inputCount, this); - connector->setCenter(position); - - m_inputPositions.append(position); -} - -QPointF EffectItemBase::outputPosition() const -{ - return m_outputPosition; -} - -QPointF EffectItemBase::inputPosition(int index) const -{ - if (index < 0 || index >= m_inputPositions.count()) { - return QPointF(); - } - return m_inputPositions[index]; -} - -QString EffectItemBase::outputName() const -{ - return m_outputName; -} - -QSizeF EffectItemBase::connectorSize() const -{ - return ConnectorSize; -} - -KoFilterEffect *EffectItemBase::effect() const -{ - return m_effect; -} - -void EffectItemBase::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - ConnectorItem *connector = connectorAtPosition(event->scenePos()); - if (!connector) { - return; - } - - ConnectorMimeData *data = new ConnectorMimeData(connector); - - QDrag *drag = new QDrag(event->widget()); - drag->setMimeData(data); - drag->exec(); -} - -void EffectItemBase::dragMoveEvent(QGraphicsSceneDragDropEvent *event) -{ - event->ignore(); - ConnectorItem *targetItem = connectorAtPosition(event->scenePos()); - if (!targetItem) { - return; - } - - const ConnectorMimeData *data = dynamic_cast(event->mimeData()); - if (!data) { - return; - } - - ConnectorItem *sourceItem = data->connector(); - int sourceItemType = sourceItem->connectorType(); - int targetItemType = targetItem->connectorType(); - - if (sourceItemType == targetItemType) { - return; - } - - // do not accept connection within single effect item - if (sourceItem->parentItem() == targetItem->parentItem()) { - return; - } - - if (sourceItemType == ConnectorItem::Input) { - // we can only connect input with output above - if (sourceItem->scenePos().y() < targetItem->scenePos().y()) { - return; - } - } - if (sourceItemType == ConnectorItem::Output) { - // we can only connect output with input below - if (sourceItem->scenePos().y() > targetItem->scenePos().y()) { - return; - } - } - - event->accept(); -} - -void EffectItemBase::dropEvent(QGraphicsSceneDragDropEvent *event) -{ - ConnectorItem *connector = connectorAtPosition(event->scenePos()); - if (!connector) { - return; - } - - const ConnectorMimeData *data = dynamic_cast(event->mimeData()); - if (!data) { - return; - } -} - -ConnectorItem *EffectItemBase::connectorAtPosition(const QPointF &scenePosition) -{ - Q_FOREACH (QGraphicsItem *childItem, childItems()) { - ConnectorItem *connector = dynamic_cast(childItem); - if (!connector) { - continue; - } - if (connector->contains(connector->mapFromScene(scenePosition))) { - return connector; - } - } - - return 0; -} - -DefaultInputItem::DefaultInputItem(const QString &name, KoFilterEffect *effect) - : EffectItemBase(effect), m_name(name) -{ - setRect(0, 0, ItemWidth, 2 * ConnectorSize.height()); - - createOutput(QPointF(ItemWidth, 0.5 * rect().height()), name); - createText(name); - - QLinearGradient g(QPointF(0, 0), QPointF(1, 1)); - g.setCoordinateMode(QGradient::ObjectBoundingMode); - g.setColorAt(0, Qt::white); - g.setColorAt(1, QColor(255, 168, 88)); - setBrush(QBrush(g)); -} - -EffectItem::EffectItem(KoFilterEffect *effect) - : EffectItemBase(effect) -{ - Q_ASSERT(effect); - //QRectF circle(QPointF(), ConnectorSize); - - QPointF position(ItemWidth, ConnectorSize.height()); - - // create input connectors - int requiredInputCount = effect->requiredInputCount(); - int usedInputCount = qMax(requiredInputCount, effect->inputs().count()); - for (int i = 0; i < usedInputCount; ++i) { - createInput(position); - position.ry() += 1.5 * ConnectorSize.height(); - } - - // create a new input connector when maximal input count in not reached yet - if (usedInputCount < effect->maximalInputCount()) { - createInput(position); - position.ry() += 1.5 * ConnectorSize.height(); - } - // create output connector - position.ry() += 0.5 * ConnectorSize.height(); - createOutput(position, effect->output()); - - setRect(0, 0, ItemWidth, position.y() + ConnectorSize.height()); - - createText(effect->id()); - - QLinearGradient g(QPointF(0, 0), QPointF(1, 1)); - g.setCoordinateMode(QGradient::ObjectBoundingMode); - g.setColorAt(0, Qt::white); - g.setColorAt(1, QColor(0, 192, 192)); - setBrush(QBrush(g)); -} - -ConnectionItem::ConnectionItem(EffectItemBase *source, EffectItemBase *target, int targetInput) - : QGraphicsPathItem(0) - , m_source(source) - , m_target(target) - , m_targetInput(targetInput) -{ - setPen(QPen(Qt::black)); -} - -EffectItemBase *ConnectionItem::sourceItem() const -{ - return m_source; -} - -EffectItemBase *ConnectionItem::targetItem() const -{ - return m_target; -} - -int ConnectionItem::targetInput() const -{ - return m_targetInput; -} - -void ConnectionItem::setSourceItem(EffectItemBase *source) -{ - m_source = source; -} - -void ConnectionItem::setTargetItem(EffectItemBase *target, int targetInput) -{ - m_target = target; - m_targetInput = targetInput; -} diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectSceneItems.h b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectSceneItems.h deleted file mode 100644 index f552009dca..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterEffectSceneItems.h +++ /dev/null @@ -1,134 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 FILTEREFFECTSCENEITEMS_H -#define FILTEREFFECTSCENEITEMS_H - -#include -#include -#include - -class KoFilterEffect; - -/// Graphics item representing a connector (input/output) -class ConnectorItem : public QGraphicsEllipseItem -{ -public: - enum ConnectorType { Input, Output }; - - ConnectorItem(ConnectorType type, int index, QGraphicsItem *parent); - void setCenter(const QPointF &position); - ConnectorType connectorType(); - int connectorIndex() const; - KoFilterEffect *effect() const; -private: - ConnectorType m_type; - int m_index; -}; - -/// Custom mime data for connector drag and drop -class ConnectorMimeData : public QMimeData -{ -public: - explicit ConnectorMimeData(ConnectorItem *connector); - ConnectorItem *connector() const; -private: - ConnectorItem *m_connector; -}; - -/// Base class for effect items -class EffectItemBase : public QGraphicsRectItem -{ -public: - explicit EffectItemBase(KoFilterEffect *effect); - - /// Returns the position of the output connector - QPointF outputPosition() const; - - /// Returns the position of the specified input connector - QPointF inputPosition(int index) const; - - /// Returns the name of the output - QString outputName() const; - - /// Returns the size of the connectors - QSizeF connectorSize() const; - - /// Returns the corresponding filter effect - KoFilterEffect *effect() const; - -protected: - void createText(const QString &text); - void createOutput(const QPointF &position, const QString &name); - void createInput(const QPointF &position); - - void mousePressEvent(QGraphicsSceneMouseEvent *event) override; - void dragMoveEvent(QGraphicsSceneDragDropEvent *event) override; - void dropEvent(QGraphicsSceneDragDropEvent *event) override; - - ConnectorItem *connectorAtPosition(const QPointF &scenePosition); - -private: - QPointF m_outputPosition; - QString m_outputName; - QList m_inputPositions; - KoFilterEffect *m_effect; -}; - -/// Graphics item representing a predefined input image -class DefaultInputItem : public EffectItemBase -{ -public: - DefaultInputItem(const QString &name, KoFilterEffect *effect); -private: - QString m_name; -}; - -/// Graphics item representing a effect primitive -class EffectItem : public EffectItemBase -{ -public: - explicit EffectItem(KoFilterEffect *effect); -}; - -/// Graphics item representing an connection between an output and input -class ConnectionItem : public QGraphicsPathItem -{ -public: - ConnectionItem(EffectItemBase *source, EffectItemBase *target, int targetInput); - - /// Returns the source item of the connection - EffectItemBase *sourceItem() const; - /// Returns the target item of the connection - EffectItemBase *targetItem() const; - /// Returns the input index of the target item - int targetInput() const; - - /// Sets the source item - void setSourceItem(EffectItemBase *source); - /// Set the target item and the corresponding input index - void setTargetItem(EffectItemBase *target, int targetInput); - -private: - EffectItemBase *m_source; - EffectItemBase *m_target; - int m_targetInput; -}; - -#endif // FILTEREFFECTSCENEITEMS_H diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterInputChangeCommand.cpp b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterInputChangeCommand.cpp deleted file mode 100644 index 45230ee4e2..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterInputChangeCommand.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "FilterInputChangeCommand.h" -#include "KoFilterEffect.h" -#include "KoShape.h" - -FilterInputChangeCommand::FilterInputChangeCommand(const InputChangeData &data, KoShape *shape, KUndo2Command *parent) - : KUndo2Command(parent) - , m_shape(shape) -{ - m_data.append(data); -} - -FilterInputChangeCommand::FilterInputChangeCommand(const QList &data, KoShape *shape, KUndo2Command *parent) - : KUndo2Command(parent) - , m_data(data) - , m_shape(shape) -{ -} - -void FilterInputChangeCommand::redo() -{ - if (m_shape) { - m_shape->update(); - } - - Q_FOREACH (const InputChangeData &data, m_data) { - data.filterEffect->setInput(data.inputIndex, data.newInput); - } - - if (m_shape) { - m_shape->update(); - } - - KUndo2Command::redo(); -} - -void FilterInputChangeCommand::undo() -{ - if (m_shape) { - m_shape->update(); - } - - Q_FOREACH (const InputChangeData &data, m_data) { - data.filterEffect->setInput(data.inputIndex, data.oldInput); - } - - if (m_shape) { - m_shape->update(); - } - - KUndo2Command::undo(); -} diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterInputChangeCommand.h b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterInputChangeCommand.h deleted file mode 100644 index c31e975204..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterInputChangeCommand.h +++ /dev/null @@ -1,62 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 FILTERINPUTCHANGECOMMAND_H -#define FILTERINPUTCHANGECOMMAND_H - -#include - -class KoShape; -class KoFilterEffect; - -struct InputChangeData { - InputChangeData() - : filterEffect(0), inputIndex(-1) - { - } - - InputChangeData(KoFilterEffect *effect, int index, const QString &oldIn, const QString &newIn) - : filterEffect(effect), inputIndex(index), oldInput(oldIn), newInput(newIn) - { - } - - KoFilterEffect *filterEffect; - int inputIndex; - QString oldInput; - QString newInput; -}; - -/// A command to change the input of a filter effect -class FilterInputChangeCommand : public KUndo2Command -{ -public: - explicit FilterInputChangeCommand(const InputChangeData &data, KoShape *shape = 0, KUndo2Command *parent = 0); - - explicit FilterInputChangeCommand(const QList &data, KoShape *shape = 0, KUndo2Command *parent = 0); - - /// redo the command - void redo() override; - /// revert the actions done in redo - void undo() override; -private: - QList m_data; - KoShape *m_shape; -}; - -#endif // FILTERINPUTCHANGECOMMAND_H diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterRegionChangeCommand.cpp b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterRegionChangeCommand.cpp deleted file mode 100644 index 8ad46ba6df..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterRegionChangeCommand.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "FilterRegionChangeCommand.h" -#include "KoFilterEffect.h" -#include "KoShape.h" - -FilterRegionChangeCommand::FilterRegionChangeCommand(KoFilterEffect *effect, const QRectF &filterRegion, KoShape *shape, KUndo2Command *parent) - : KUndo2Command(parent) - , m_effect(effect) - , m_newRegion(filterRegion) - , m_shape(shape) -{ - Q_ASSERT(m_effect); - m_oldRegion = m_effect->filterRect(); -} - -void FilterRegionChangeCommand::redo() -{ - if (m_shape) { - m_shape->update(); - } - - m_effect->setFilterRect(m_newRegion); - - if (m_shape) { - m_shape->update(); - m_shape->notifyChanged(); - } - - KUndo2Command::redo(); -} - -void FilterRegionChangeCommand::undo() -{ - if (m_shape) { - m_shape->update(); - } - - m_effect->setFilterRect(m_oldRegion); - - if (m_shape) { - m_shape->update(); - m_shape->notifyChanged(); - } - - KUndo2Command::undo(); -} diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterRegionChangeCommand.h b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterRegionChangeCommand.h deleted file mode 100644 index 5080e597a5..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterRegionChangeCommand.h +++ /dev/null @@ -1,54 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 FILTERREGIONCHANGECOMMAND_H -#define FILTERREGIONCHANGECOMMAND_H - -#include -#include - -class KoShape; -class KoFilterEffect; - -/// A command to change the region of a filter effect -class FilterRegionChangeCommand : public KUndo2Command -{ -public: - /** - * Creates new command to change filter region of a filter effect - * @param effect the effect to change the filter region of - * @param filterRegion the new filter region to set - * @param shape the shape the filter effect is applied to - * @param parent the parent undo command - */ - explicit FilterRegionChangeCommand(KoFilterEffect *effect, const QRectF &filterRegion, KoShape *shape = 0, KUndo2Command *parent = 0); - - /// redo the command - void redo() override; - /// revert the actions done in redo - void undo() override; - -private: - KoFilterEffect *m_effect; ///< the filter effect we are working on - QRectF m_oldRegion; ///< the old filter region - QRectF m_newRegion; ///< the new filter region - KoShape *m_shape; ///< the shape the effect is applied to, might be zero -}; - -#endif // FILTERREGIONCHANGECOMMAND_H diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterRegionEditStrategy.cpp b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterRegionEditStrategy.cpp deleted file mode 100644 index cf1e766985..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterRegionEditStrategy.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* This file is part of the KDE project -* Copyright (c) 2010 Jan Hambrecht -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU Lesser General Public -* License as published by the Free Software Foundation; either -* version 2.1 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 Lesser 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 "FilterRegionEditStrategy.h" -#include "FilterRegionChangeCommand.h" -#include -#include -#include -#include - -FilterRegionEditStrategy::FilterRegionEditStrategy(KoToolBase *parent, KoShape *shape, KoFilterEffect *effect, KarbonFilterEffectsTool::EditMode mode) - : KoInteractionStrategy(parent) - , m_effect(effect) - , m_shape(shape) - , m_editMode(mode) -{ - Q_ASSERT(m_effect); - Q_ASSERT(m_shape); - // get the size rect of the shape - m_sizeRect = QRectF(QPointF(), m_shape->size()); - // get the filter rectangle in shape coordinates - m_filterRect = m_effect->filterRectForBoundingRect(m_sizeRect); -} - -void FilterRegionEditStrategy::handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) -{ - Q_UNUSED(modifiers); - QPointF shapePoint = m_shape->documentToShape(mouseLocation); - if (m_lastPosition.isNull()) { - m_lastPosition = shapePoint; - } - QPointF delta = shapePoint - m_lastPosition; - if (delta.isNull()) { - return; - } - - switch (m_editMode) { - case KarbonFilterEffectsTool::MoveAll: - m_filterRect.translate(delta.x(), delta.y()); - break; - case KarbonFilterEffectsTool::MoveLeft: - m_filterRect.setLeft(m_filterRect.left() + delta.x()); - break; - case KarbonFilterEffectsTool::MoveRight: - m_filterRect.setRight(m_filterRect.right() + delta.x()); - break; - case KarbonFilterEffectsTool::MoveTop: - m_filterRect.setTop(m_filterRect.top() + delta.y()); - break; - case KarbonFilterEffectsTool::MoveBottom: - m_filterRect.setBottom(m_filterRect.bottom() + delta.y()); - break; - default: - // nothing to do here - return; - } - tool()->repaintDecorations(); - m_lastPosition = shapePoint; -} - -KUndo2Command *FilterRegionEditStrategy::createCommand() -{ - qreal x = m_filterRect.left() / m_sizeRect.width(); - qreal y = m_filterRect.top() / m_sizeRect.height(); - qreal w = m_filterRect.width() / m_sizeRect.width(); - qreal h = m_filterRect.height() / m_sizeRect.height(); - return new FilterRegionChangeCommand(m_effect, QRectF(x, y, w, h), m_shape); -} - -void FilterRegionEditStrategy::finishInteraction(Qt::KeyboardModifiers modifiers) -{ - Q_UNUSED(modifiers); -} - -void FilterRegionEditStrategy::paint(QPainter &painter, const KoViewConverter &converter) -{ - Q_UNUSED(converter); - // paint the filter subregion rect - painter.setBrush(Qt::NoBrush); - painter.setPen(Qt::red); - painter.drawRect(m_filterRect); -} diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterRegionEditStrategy.h b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterRegionEditStrategy.h deleted file mode 100644 index 1f60cc5f02..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterRegionEditStrategy.h +++ /dev/null @@ -1,54 +0,0 @@ -/* This file is part of the KDE project -* Copyright (c) 2010 Jan Hambrecht -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU Lesser General Public -* License as published by the Free Software Foundation; either -* version 2.1 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 Lesser 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 FILTERREGIONEDITSTRATEGY_H -#define FILTERREGIONEDITSTRATEGY_H - -#include -#include "KarbonFilterEffectsTool.h" - -#include - -class KoShape; -class KoFilterEffect; - -class FilterRegionEditStrategy : public KoInteractionStrategy -{ -public: - FilterRegionEditStrategy(KoToolBase *parent, KoShape *shape, KoFilterEffect *effect, KarbonFilterEffectsTool::EditMode mode); - - // reimplemented from KoInteractionStrategy - void handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers) override; - // reimplemented from KoInteractionStrategy - KUndo2Command *createCommand() override; - // reimplemented from KoInteractionStrategy - void finishInteraction(Qt::KeyboardModifiers modifiers) override; - // reimplemented from KoInteractionStrategy - void paint(QPainter &painter, const KoViewConverter &converter) override; - -private: - KoFilterEffect *m_effect; - KoShape *m_shape; - QRectF m_sizeRect; - QRectF m_filterRect; - KarbonFilterEffectsTool::EditMode m_editMode; - QPointF m_lastPosition; -}; - -#endif // FILTERREGIONEDITSTRATEGY_H diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterRemoveCommand.cpp b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterRemoveCommand.cpp deleted file mode 100644 index a04816ef3f..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterRemoveCommand.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "FilterRemoveCommand.h" -#include "KoShape.h" -#include "KoFilterEffect.h" -#include "KoFilterEffectStack.h" - -#include - -FilterRemoveCommand::FilterRemoveCommand(int filterEffectIndex, KoFilterEffectStack *filterStack, KoShape *shape, KUndo2Command *parent) - : KUndo2Command(parent) - , m_filterEffect(0) - , m_filterStack(filterStack) - , m_shape(shape) - , m_isRemoved(false) - , m_filterEffectIndex(filterEffectIndex) -{ - Q_ASSERT(filterStack); - setText(kundo2_i18n("Remove filter effect")); -} - -FilterRemoveCommand::~FilterRemoveCommand() -{ - if (m_isRemoved) { - delete m_filterEffect; - } -} - -void FilterRemoveCommand::redo() -{ - KUndo2Command::redo(); - - if (m_shape) { - m_shape->update(); - } - - m_filterEffect = m_filterStack->takeFilterEffect(m_filterEffectIndex); - m_isRemoved = true; - - if (m_shape) { - m_shape->update(); - } -} - -void FilterRemoveCommand::undo() -{ - if (m_shape) { - m_shape->update(); - } - - m_filterStack->insertFilterEffect(m_filterEffectIndex, m_filterEffect); - m_isRemoved = false; - - if (m_shape) { - m_shape->update(); - } - - KUndo2Command::undo(); -} diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterRemoveCommand.h b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterRemoveCommand.h deleted file mode 100644 index 3733b59917..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterRemoveCommand.h +++ /dev/null @@ -1,48 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 FILTERREMOVECOMMAND_H -#define FILTERREMOVECOMMAND_H - -#include - -class KoShape; -class KoFilterEffect; -class KoFilterEffectStack; - -/// A command do remove a filter effect from a filter effect stack -class FilterRemoveCommand : public KUndo2Command -{ -public: - FilterRemoveCommand(int filterEffectIndex, KoFilterEffectStack *filterStack, KoShape *shape, KUndo2Command *parent = 0); - ~FilterRemoveCommand() override; - /// redo the command - void redo() override; - /// revert the actions done in redo - void undo() override; - -private: - KoFilterEffect *m_filterEffect; - KoFilterEffectStack *m_filterStack; - KoShape *m_shape; - bool m_isRemoved; - int m_filterEffectIndex; -}; - -#endif // FILTERREMOVECOMMAND_H diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterResourceServerProvider.cpp b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterResourceServerProvider.cpp deleted file mode 100644 index 1704164427..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterResourceServerProvider.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* This file is part of the KDE project - - Copyright (c) 1999 Matthias Elter - Copyright (c) 2003 Patrick Julien - Copyright (c) 2005 Sven Langkamp - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "FilterResourceServerProvider.h" -#include "FilterEffectResource.h" - -#include -#include - -#include -#include -#include -#include - -FilterResourceServerProvider *FilterResourceServerProvider::m_singleton = 0; - -FilterResourceServerProvider::FilterResourceServerProvider() -{ - m_filterEffectServer = new KoResourceServer(ResourceType::FilterEffects); - if (!QFileInfo(m_filterEffectServer->saveLocation()).exists()) { - QDir().mkpath(m_filterEffectServer->saveLocation()); - } -} - -FilterResourceServerProvider::~FilterResourceServerProvider() -{ - delete m_filterEffectServer; -} - -FilterResourceServerProvider *FilterResourceServerProvider::instance() -{ - if (FilterResourceServerProvider::m_singleton == 0) { - FilterResourceServerProvider::m_singleton = new FilterResourceServerProvider(); - } - return FilterResourceServerProvider::m_singleton; -} - -KoResourceServer *FilterResourceServerProvider::filterEffectServer() -{ - return m_filterEffectServer; -} diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterResourceServerProvider.h b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterResourceServerProvider.h deleted file mode 100644 index b429fa4be8..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterResourceServerProvider.h +++ /dev/null @@ -1,51 +0,0 @@ -/* This file is part of the KDE project - - Copyright (c) 1999 Matthias Elter - Copyright (c) 2003 Patrick Julien - Copyright (c) 2005 Sven Langkamp - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef FILTERRESOURCESERVERPROVIDER_H -#define FILTERRESOURCESERVERPROVIDER_H - -#include "KoResourceServer.h" - -class FilterEffectResource; - -/// Provides resource server for filter effect resources -class FilterResourceServerProvider : public QObject -{ - Q_OBJECT - -public: - ~FilterResourceServerProvider() override; - - static FilterResourceServerProvider *instance(); - - KoResourceServer *filterEffectServer(); - -private: - - FilterResourceServerProvider(); - FilterResourceServerProvider(const FilterResourceServerProvider &); - FilterResourceServerProvider operator=(const FilterResourceServerProvider &); - - static FilterResourceServerProvider *m_singleton; - KoResourceServer *m_filterEffectServer; -}; - -#endif // FILTERRESOURCESERVERPROVIDER_H diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterStackSetCommand.cpp b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterStackSetCommand.cpp deleted file mode 100644 index 3a71a702b9..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterStackSetCommand.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "FilterStackSetCommand.h" -#include "KoShape.h" -#include "KoFilterEffectStack.h" - -#include - -FilterStackSetCommand::FilterStackSetCommand(KoFilterEffectStack *newStack, KoShape *shape, KUndo2Command *parent) - : KUndo2Command(parent) - , m_newFilterStack(newStack) - , m_shape(shape) -{ - Q_ASSERT(m_shape); - m_oldFilterStack = m_shape->filterEffectStack(); - if (m_newFilterStack) { - m_newFilterStack->ref(); - } - if (m_oldFilterStack) { - m_oldFilterStack->ref(); - } - - setText(kundo2_i18n("Set filter stack")); -} - -FilterStackSetCommand::~FilterStackSetCommand() -{ - if (m_newFilterStack && !m_newFilterStack->deref()) { - delete m_newFilterStack; - } - if (m_oldFilterStack && !m_oldFilterStack->deref()) { - delete m_oldFilterStack; - } -} - -void FilterStackSetCommand::redo() -{ - KUndo2Command::redo(); - - m_shape->update(); - m_shape->setFilterEffectStack(m_newFilterStack); - m_shape->update(); -} - -void FilterStackSetCommand::undo() -{ - m_shape->update(); - m_shape->setFilterEffectStack(m_oldFilterStack); - m_shape->update(); - - KUndo2Command::undo(); -} diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterStackSetCommand.h b/plugins/tools/karbonplugins/tools/filterEffectTool/FilterStackSetCommand.h deleted file mode 100644 index 2b5dc2044b..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/FilterStackSetCommand.h +++ /dev/null @@ -1,46 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 FILTERSTACKSETCOMMAND_H -#define FILTERSTACKSETCOMMAND_H - -#include - -class KoFilterEffectStack; -class KoShape; - -/// Command to set a filter stack on a shape -class FilterStackSetCommand : public KUndo2Command -{ -public: - FilterStackSetCommand(KoFilterEffectStack *newStack, KoShape *shape, KUndo2Command *parent = 0); - ~FilterStackSetCommand() override; - - /// redo the command - void redo() override; - /// revert the actions done in redo - void undo() override; - -private: - KoFilterEffectStack *m_newFilterStack; - KoFilterEffectStack *m_oldFilterStack; - KoShape *m_shape; -}; - -#endif // FILTERSTACKSETCOMMAND_H diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/KarbonFilterEffectsTool.cpp b/plugins/tools/karbonplugins/tools/filterEffectTool/KarbonFilterEffectsTool.cpp deleted file mode 100644 index f2192bac4a..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/KarbonFilterEffectsTool.cpp +++ /dev/null @@ -1,551 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009-2011 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "KarbonFilterEffectsTool.h" - -#include "KoFilterEffect.h" -#include "KoFilterEffectStack.h" -#include "KoFilterEffectFactoryBase.h" -#include "KoFilterEffectRegistry.h" -#include "KoFilterEffectConfigWidgetBase.h" -#include "KoCanvasBase.h" -#include "KoDocumentResourceManager.h" -#include "KoSelectedShapesProxy.h" -#include "KoViewConverter.h" -#include "KoSelection.h" -#include "FilterEffectEditWidget.h" -#include "FilterEffectResource.h" -#include "FilterResourceServerProvider.h" -#include "FilterStackSetCommand.h" -#include "FilterRegionChangeCommand.h" -#include "FilterRegionEditStrategy.h" -#include "KoResourceSelector.h" -#include - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kis_double_parse_spin_box.h" - -class KarbonFilterEffectsTool::Private -{ -public: - Private() - : filterSelector(0) - , configSelector(0) - , configStack(0) - , posX(0) - , posY(0) - , posW(0) - , posH(0) - , clearButton(0) - , currentEffect(0) - , currentPanel(0) - , currentShape(0) - { - } - - void fillConfigSelector(KoShape *shape, KarbonFilterEffectsTool *tool) - { - if (!configSelector) { - return; - } - - configSelector->clear(); - clearButton->setEnabled(false); - - if (!shape || !shape->filterEffectStack()) { - addWidgetForEffect(0, tool); - return; - } - - configSelector->blockSignals(true); - - int index = 0; - Q_FOREACH (KoFilterEffect *effect, shape->filterEffectStack()->filterEffects()) { - configSelector->addItem(QString("%1 - ").arg(index) + effect->name()); - index++; - } - - configSelector->blockSignals(false); - - KoFilterEffect *effect = index > 0 ? shape->filterEffectStack()->filterEffects().first() : 0; - - addWidgetForEffect(effect, tool); - clearButton->setEnabled(shape->filterEffectStack() != 0); - } - - void addWidgetForEffect(KoFilterEffect *filterEffect, KarbonFilterEffectsTool *tool) - { - // remove current widget if new effect is zero or effect type has changed - if (!filterEffect || (currentEffect && filterEffect->id() != currentEffect->id())) { - while (configStack->count()) { - configStack->removeWidget(configStack->widget(0)); - } - } - - if (!filterEffect) { - currentEffect = 0; - currentPanel = 0; - } else if (!currentEffect || currentEffect->id() != filterEffect->id()) { - // when a effect is set and is differs from the previous one - // get the config widget and insert it into the option widget - currentEffect = filterEffect; - - KoFilterEffectRegistry *registry = KoFilterEffectRegistry::instance(); - KoFilterEffectFactoryBase *factory = registry->value(currentEffect->id()); - if (!factory) { - return; - } - - currentPanel = factory->createConfigWidget(); - if (!currentPanel) { - return; - } - - currentPanel->layout()->setContentsMargins(0, 0, 0, 0); - configStack->insertWidget(0, currentPanel); - configStack->layout()->setContentsMargins(0, 0, 0, 0); - connect(currentPanel, SIGNAL(filterChanged()), tool, SLOT(filterChanged())); - } - - if (currentPanel) { - currentPanel->editFilterEffect(filterEffect); - } - - updateFilterRegion(); - } - - void updateFilterRegion() - { - QRectF region = currentEffect ? currentEffect->filterRect() : QRectF(0, 0, 0, 0); - - posX->blockSignals(true); - posX->setValue(100.0 * region.x()); - posX->blockSignals(false); - posX->setEnabled(currentEffect != 0); - posY->blockSignals(true); - posY->setValue(100.0 * region.y()); - posY->blockSignals(false); - posY->setEnabled(currentEffect != 0); - posW->blockSignals(true); - posW->setValue(100.0 * region.width()); - posW->blockSignals(false); - posW->setEnabled(currentEffect != 0); - posH->blockSignals(true); - posH->setValue(100.0 * region.height()); - posH->blockSignals(false); - posH->setEnabled(currentEffect != 0); - } - - EditMode editModeFromMousePosition(const QPointF &mousePosition, KarbonFilterEffectsTool *tool) - { - if (currentShape && currentShape->filterEffectStack() && currentEffect) { - // get the size rect of the shape - QRectF sizeRect(QPointF(), currentShape->size()); - // get the filter rectangle in shape coordinates - QRectF filterRect = currentEffect->filterRectForBoundingRect(sizeRect); - // get the transformation from document to shape coordinates - QTransform transform = currentShape->absoluteTransformation(0).inverted(); - // adjust filter rectangle by grab sensitivity - const int grabDistance = tool->grabSensitivity(); - QPointF border = tool->canvas()->viewConverter()->viewToDocument(QPointF(grabDistance, grabDistance)); - filterRect.adjust(-border.x(), -border.y(), border.x(), border.y()); - // map event point from document to shape coordinates - QPointF shapePoint = transform.map(mousePosition); - // check if the mouse is inside/near our filter rect - if (filterRect.contains(shapePoint)) { - if (qAbs(shapePoint.x() - filterRect.left()) <= border.x()) { - return MoveLeft; - } else if (qAbs(shapePoint.x() - filterRect.right()) <= border.x()) { - return MoveRight; - } else if (qAbs(shapePoint.y() - filterRect.top()) <= border.y()) { - return MoveTop; - } else if (qAbs(shapePoint.y() - filterRect.bottom()) <= border.y()) { - return MoveBottom; - } else { - return MoveAll; - } - } else { - return None; - } - } - return None; - } - - KoResourceSelector *filterSelector; - KComboBox *configSelector; - QStackedWidget *configStack; - QDoubleSpinBox *posX; - QDoubleSpinBox *posY; - QDoubleSpinBox *posW; - QDoubleSpinBox *posH; - QToolButton *clearButton; - KoFilterEffect *currentEffect; - KoFilterEffectConfigWidgetBase *currentPanel; - KoShape *currentShape; -}; - -KarbonFilterEffectsTool::KarbonFilterEffectsTool(KoCanvasBase *canvas) - : KoInteractionTool(canvas) - , d(new Private()) -{ - connect(canvas->selectedShapesProxy(), SIGNAL(selectionChanged()), - this, SLOT(selectionChanged())); - connect(canvas->selectedShapesProxy(), SIGNAL(selectionContentChanged()), - this, SLOT(selectionChanged())); -} - -KarbonFilterEffectsTool::~KarbonFilterEffectsTool() -{ - delete d; -} - -void KarbonFilterEffectsTool::paint(QPainter &painter, const KoViewConverter &converter) -{ - if (d->currentShape && d->currentShape->filterEffectStack()) { - painter.save(); - // apply the shape transformation - QTransform transform = d->currentShape->absoluteTransformation(&converter); - painter.setTransform(transform, true); - // apply the zoom transformation - KoShape::applyConversion(painter, converter); - // get the size rect of the shape - QRectF sizeRect(QPointF(), d->currentShape->size()); - // get the clipping rect of the filter stack - KoFilterEffectStack *filterStack = d->currentShape->filterEffectStack(); - QRectF clipRect = filterStack->clipRectForBoundingRect(sizeRect); - // finally paint the clipping rect - painter.setBrush(Qt::NoBrush); - painter.setPen(Qt::blue); - painter.drawRect(clipRect); - - if (currentStrategy()) { - currentStrategy()->paint(painter, converter); - } else if (d->currentEffect) { - QRectF filterRect = d->currentEffect->filterRectForBoundingRect(sizeRect); - // paint the filter subregion rect - painter.setBrush(Qt::NoBrush); - painter.setPen(Qt::red); - painter.drawRect(filterRect); - } - - painter.restore(); - } -} - -void KarbonFilterEffectsTool::repaintDecorations() -{ - if (d->currentShape && d->currentShape->filterEffectStack()) { - QRectF bb = d->currentShape->boundingRect(); - const int radius = handleRadius(); - canvas()->updateCanvas(bb.adjusted(-radius, -radius, radius, radius)); - } -} - -void KarbonFilterEffectsTool::activate(ToolActivation toolActivation, const QSet &shapes) -{ - Q_UNUSED(toolActivation); - if (shapes.isEmpty()) { - emit done(); - return; - } - - d->currentShape = canvas()->selectedShapesProxy()->selection()->firstSelectedShape(); - d->fillConfigSelector(d->currentShape, this); -} - -void KarbonFilterEffectsTool::mouseMoveEvent(KoPointerEvent *event) -{ - if (currentStrategy()) { - KoInteractionTool::mouseMoveEvent(event); - } else { - EditMode mode = d->editModeFromMousePosition(event->point, this); - switch (mode) { - case MoveAll: - useCursor(Qt::SizeAllCursor); - break; - case MoveLeft: - case MoveRight: - useCursor(Qt::SizeHorCursor); - break; - case MoveTop: - case MoveBottom: - useCursor(Qt::SizeVerCursor); - break; - case None: - useCursor(Qt::ArrowCursor); - break; - } - } -} - -KoInteractionStrategy *KarbonFilterEffectsTool::createStrategy(KoPointerEvent *event) -{ - EditMode mode = d->editModeFromMousePosition(event->point, this); - if (mode == None) { - return 0; - } - - return new FilterRegionEditStrategy(this, d->currentShape, d->currentEffect, mode); -} - -void KarbonFilterEffectsTool::presetSelected(KoResourceSP resource) -{ - if (!d->currentShape) { - return; - } - - QSharedPointer effectResource = resource.dynamicCast(); - if (!effectResource) { - return; - } - - KoFilterEffectStack *filterStack = effectResource->toFilterStack(); - if (!filterStack) { - return; - } - - canvas()->addCommand(new FilterStackSetCommand(filterStack, d->currentShape)); - d->fillConfigSelector(d->currentShape, this); -} - -void KarbonFilterEffectsTool::editFilter() -{ - QPointer dlg = new QDialog(); - dlg->setWindowTitle(i18n("Filter Effect Editor")); - QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close); - QWidget *mainWidget = new QWidget(0); - QVBoxLayout *mainLayout = new QVBoxLayout; - dlg->setLayout(mainLayout); - mainLayout->addWidget(mainWidget); - connect(buttonBox->button(QDialogButtonBox::Close), SIGNAL(clicked()), dlg, SLOT(close())); - - FilterEffectEditWidget *editor = new FilterEffectEditWidget(dlg); - editor->editShape(d->currentShape, canvas()); - - mainLayout->addWidget(editor); - mainLayout->addWidget(buttonBox); - dlg->exec(); - delete dlg; - - d->fillConfigSelector(d->currentShape, this); -} - -void KarbonFilterEffectsTool::clearFilter() -{ - if (!d->currentShape) { - return; - } - if (!d->currentShape->filterEffectStack()) { - return; - } - - canvas()->addCommand(new FilterStackSetCommand(0, d->currentShape)); - - d->fillConfigSelector(d->currentShape, this); -} - -void KarbonFilterEffectsTool::filterChanged() -{ - if (!d->currentShape) { - return; - } - - d->currentShape->update(); -} - -void KarbonFilterEffectsTool::filterSelected(int index) -{ - if (!d->currentShape || ! d->currentShape->filterEffectStack()) { - return; - } - - KoFilterEffect *effect = 0; - QList filterEffects = d->currentShape->filterEffectStack()->filterEffects(); - if (index >= 0 && index < filterEffects.count()) { - effect = filterEffects[index]; - } - - d->addWidgetForEffect(effect, this); - - repaintDecorations(); -} - -void KarbonFilterEffectsTool::selectionChanged() -{ - d->currentShape = canvas()->selectedShapesProxy()->selection()->firstSelectedShape(); - d->fillConfigSelector(d->currentShape, this); -} - -void KarbonFilterEffectsTool::regionXChanged(double x) -{ - if (!d->currentEffect) { - return; - } - - QRectF region = d->currentEffect->filterRect(); - region.setX(x / 100.0); - canvas()->addCommand(new FilterRegionChangeCommand(d->currentEffect, region, d->currentShape)); -} - -void KarbonFilterEffectsTool::regionYChanged(double y) -{ - if (!d->currentEffect) { - return; - } - - QRectF region = d->currentEffect->filterRect(); - region.setY(y / 100.0); - canvas()->addCommand(new FilterRegionChangeCommand(d->currentEffect, region, d->currentShape)); -} - -void KarbonFilterEffectsTool::regionWidthChanged(double width) -{ - if (!d->currentEffect) { - return; - } - - QRectF region = d->currentEffect->filterRect(); - region.setWidth(width / 100.0); - canvas()->addCommand(new FilterRegionChangeCommand(d->currentEffect, region, d->currentShape)); -} - -void KarbonFilterEffectsTool::regionHeightChanged(double height) -{ - if (!d->currentEffect) { - return; - } - - QRectF region = d->currentEffect->filterRect(); - region.setHeight(height / 100.0); - canvas()->addCommand(new FilterRegionChangeCommand(d->currentEffect, region, d->currentShape)); -} - -QList > KarbonFilterEffectsTool::createOptionWidgets() -{ - QList > widgets; - - //--------------------------------------------------------------------- - - QWidget *addFilterWidget = new QWidget(); - addFilterWidget->setObjectName("AddEffect"); - QGridLayout *addFilterLayout = new QGridLayout(addFilterWidget); - - d->filterSelector = new KoResourceSelector(addFilterWidget); - - d->filterSelector->setDisplayMode(KoResourceSelector::TextMode); - d->filterSelector->setSingleColumn(true); - addFilterLayout->addWidget(new QLabel(i18n("Effects"), addFilterWidget), 0, 0); - addFilterLayout->addWidget(d->filterSelector, 0, 1); - connect(d->filterSelector, SIGNAL(resourceSelected(KoResourceSP )), - this, SLOT(presetSelected(KoResourceSP ))); - - connect(d->filterSelector, SIGNAL(resourceApplied(KoResourceSP )), - this, SLOT(presetSelected(KoResourceSP ))); - - QToolButton *editButton = new QToolButton(addFilterWidget); - editButton->setIcon(koIcon("view-filter")); - editButton->setToolTip(i18n("View and edit filter")); - addFilterLayout->addWidget(editButton, 0, 2); - connect(editButton, SIGNAL(clicked()), this, SLOT(editFilter())); - - d->clearButton = new QToolButton(addFilterWidget); - d->clearButton->setIcon(koIcon("edit-delete")); - d->clearButton->setToolTip(i18n("Remove filter from object")); - addFilterLayout->addWidget(d->clearButton, 0, 3); - connect(d->clearButton, SIGNAL(clicked()), this, SLOT(clearFilter())); - - addFilterWidget->setWindowTitle(i18n("Add Filter")); - widgets.append(addFilterWidget); - - //--------------------------------------------------------------------- - - QWidget *configFilterWidget = new QWidget(); - configFilterWidget->setObjectName("ConfigEffect"); - QGridLayout *configFilterLayout = new QGridLayout(configFilterWidget); - - d->configSelector = new KComboBox(configFilterWidget); - configFilterLayout->addWidget(d->configSelector, 0, 0); - connect(d->configSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(filterSelected(int))); - - d->configStack = new QStackedWidget(configFilterWidget); - configFilterLayout->addWidget(d->configStack, 1, 0); - configFilterLayout->setContentsMargins(0, 0, 0, 0); - - configFilterWidget->setWindowTitle(i18n("Effect Properties")); - widgets.append(configFilterWidget); - - //--------------------------------------------------------------------- - - QWidget *filterRegionWidget = new QWidget(); - filterRegionWidget->setObjectName("EffectRegion"); - QGridLayout *filterRegionLayout = new QGridLayout(filterRegionWidget); - - d->posX = new KisDoubleParseSpinBox(filterRegionWidget); - d->posX->setSuffix(i18n("%")); - connect(d->posX, SIGNAL(valueChanged(double)), this, SLOT(regionXChanged(double))); - filterRegionLayout->addWidget(new QLabel(i18n("X:")), 0, 0); - filterRegionLayout->addWidget(d->posX, 0, 1); - - d->posY = new KisDoubleParseSpinBox(filterRegionWidget); - d->posY->setSuffix(i18n("%")); - connect(d->posY, SIGNAL(valueChanged(double)), this, SLOT(regionYChanged(double))); - filterRegionLayout->addWidget(new QLabel(i18n("Y:")), 1, 0); - filterRegionLayout->addWidget(d->posY, 1, 1); - - d->posW = new KisDoubleParseSpinBox(filterRegionWidget); - d->posW->setSuffix(i18n("%")); - connect(d->posW, SIGNAL(valueChanged(double)), this, SLOT(regionWidthChanged(double))); - filterRegionLayout->addWidget(new QLabel(i18n("W:")), 0, 2); - filterRegionLayout->addWidget(d->posW, 0, 3); - - d->posH = new KisDoubleParseSpinBox(filterRegionWidget); - d->posH->setSuffix(i18n("%")); - connect(d->posH, SIGNAL(valueChanged(double)), this, SLOT(regionHeightChanged(double))); - filterRegionLayout->addWidget(new QLabel(i18n("H:")), 1, 2); - filterRegionLayout->addWidget(d->posH, 1, 3); - filterRegionLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 2, 0); - filterRegionLayout->setContentsMargins(0, 0, 0, 0); - - filterRegionWidget->setWindowTitle(i18n("Effect Region")); - widgets.append(filterRegionWidget); - - //--------------------------------------------------------------------- - - d->fillConfigSelector(d->currentShape, this); - - return widgets; -} - diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/KarbonFilterEffectsTool.h b/plugins/tools/karbonplugins/tools/filterEffectTool/KarbonFilterEffectsTool.h deleted file mode 100644 index 0ce5fef917..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/KarbonFilterEffectsTool.h +++ /dev/null @@ -1,76 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009-2010 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 KARBONFILTEREFFECTSTOOL_H -#define KARBONFILTEREFFECTSTOOL_H - -#include "KoInteractionTool.h" - -#include - -class KoInteractionStrategy; - -class KarbonFilterEffectsTool : public KoInteractionTool -{ - Q_OBJECT -public: - enum EditMode { - None, - MoveAll, - MoveLeft, - MoveRight, - MoveTop, - MoveBottom - }; - - explicit KarbonFilterEffectsTool(KoCanvasBase *canvas); - ~KarbonFilterEffectsTool() override; - - /// reimplemented from KoToolBase - void paint(QPainter &painter, const KoViewConverter &converter) override; - /// reimplemented from KoToolBase - void repaintDecorations() override; - /// reimplemented from KoToolBase - void mouseMoveEvent(KoPointerEvent *event) override; - - /// reimplemented from KoToolBase - void activate(ToolActivation toolActivation, const QSet &shapes) override; - -protected: - /// reimplemented from KoToolBase - QList > createOptionWidgets() override; - /// reimplemented from KoToolBase - KoInteractionStrategy *createStrategy(KoPointerEvent *event) override; -private Q_SLOTS: - void editFilter(); - void clearFilter(); - void filterChanged(); - void filterSelected(int index); - void selectionChanged(); - void presetSelected(KoResourceSP resource); - void regionXChanged(double x); - void regionYChanged(double y); - void regionWidthChanged(double width); - void regionHeightChanged(double height); -private: - class Private; - Private *const d; -}; - -#endif // KARBONFILTEREFFECTSTOOL_H diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/KarbonFilterEffectsToolFactory.cpp b/plugins/tools/karbonplugins/tools/filterEffectTool/KarbonFilterEffectsToolFactory.cpp deleted file mode 100644 index b5d1ca5dff..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/KarbonFilterEffectsToolFactory.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 "KarbonFilterEffectsToolFactory.h" -#include "KarbonFilterEffectsTool.h" - -#include -#include - -KarbonFilterEffectsToolFactory::KarbonFilterEffectsToolFactory() - : KoToolFactoryBase("KarbonFilterEffectsTool") -{ - setToolTip(i18n("Filter effects editing")); - setSection("karbon,krita"); - setIconName(koIconNameCStr("tool_imageeffects")); // TODO: better icon, e.g. black Fx bad on dark UI - setPriority(3); -} - -KarbonFilterEffectsToolFactory::~KarbonFilterEffectsToolFactory() -{ -} - -KoToolBase *KarbonFilterEffectsToolFactory::createTool(KoCanvasBase *canvas) -{ - return new KarbonFilterEffectsTool(canvas); -} diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/KarbonFilterEffectsToolFactory.h b/plugins/tools/karbonplugins/tools/filterEffectTool/KarbonFilterEffectsToolFactory.h deleted file mode 100644 index 821e2c6ca9..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/KarbonFilterEffectsToolFactory.h +++ /dev/null @@ -1,33 +0,0 @@ -/* This file is part of the KDE project - * Copyright (c) 2009 Jan Hambrecht - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 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 Lesser 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 KARBONFILTEREFFECTSTOOLFACTORY_H -#define KARBONFILTEREFFECTSTOOLFACTORY_H - -#include - -class KarbonFilterEffectsToolFactory : public KoToolFactoryBase -{ -public: - KarbonFilterEffectsToolFactory(); - ~KarbonFilterEffectsToolFactory() override; - KoToolBase *createTool(KoCanvasBase *canvas) override; -}; - -#endif // KARBONFILTEREFFECTSTOOLFACTORY_H diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/KoResourceSelector.cpp b/plugins/tools/karbonplugins/tools/filterEffectTool/KoResourceSelector.cpp deleted file mode 100644 index 43e767306f..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/KoResourceSelector.cpp +++ /dev/null @@ -1,190 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2008 Jan Hambrecht - * - * 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 "KoResourceSelector.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -class Q_DECL_HIDDEN KoResourceSelector::Private -{ -public: - Private() : displayMode(ImageMode) {} - DisplayMode displayMode; - KisResourceModel *model; - - void updateIndex( KoResourceSelector * me ) - { - KisResourceModel *resourceModel = qobject_cast(me->model()); - if (!resourceModel) - return; - if (!resourceModel->rowCount()) - return; - - int currentIndex = me->currentIndex(); - QModelIndex currentModelIndex = me->view()->currentIndex(); - - if (currentIndex < 0 || !currentModelIndex.isValid()) { - me->blockSignals(true); - me->view()->setCurrentIndex( resourceModel->index( 0, 0 ) ); - me->setCurrentIndex(0); - me->blockSignals(false); - me->update(); - } - } -}; - -KoResourceSelector::KoResourceSelector(QWidget * parent ) - : QComboBox(parent), d(new Private()) -{ - setView(new KisResourceItemListView(this)); - d->model = KisResourceModelProvider::resourceModel(ResourceType::FilterEffects); - setModel(d->model); - setItemDelegate(new KisResourceItemDelegate(this)); - setMouseTracking(true); - d->updateIndex(this); - - connect( this, SIGNAL(currentIndexChanged(int)), - this, SLOT(indexChanged(int)) ); -} - -KoResourceSelector::~KoResourceSelector() -{ - delete d; -} - -void KoResourceSelector::paintEvent( QPaintEvent *pe ) -{ - QComboBox::paintEvent( pe ); - - if (d->displayMode == ImageMode) { - QStyleOptionComboBox option; - option.initFrom( this ); - QRect r = style()->subControlRect( QStyle::CC_ComboBox, &option, QStyle::SC_ComboBoxEditField, this ); - - QStyleOptionViewItem viewOption; - viewOption.initFrom( this ); - viewOption.rect = r; - - QPainter painter( this ); - itemDelegate()->paint( &painter, viewOption, view()->currentIndex() ); - } -} - -void KoResourceSelector::mousePressEvent( QMouseEvent * event ) -{ - QStyleOptionComboBox opt; - opt.initFrom( this ); - opt.subControls = QStyle::SC_All; - opt.activeSubControls = QStyle::SC_ComboBoxArrow; - QStyle::SubControl sc = style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt, - mapFromGlobal(event->globalPos()), - this); - // only clicking on combobox arrow shows popup, - // otherwise the resourceApplied signal is send with the current resource - if (sc == QStyle::SC_ComboBoxArrow) - QComboBox::mousePressEvent( event ); - else { - QModelIndex index = view()->currentIndex(); - if( ! index.isValid() ) - return; - - KoResourceSP resource = d->model->resourceForIndex(index); - - if (resource) { - emit resourceApplied(resource); - } - } -} - -void KoResourceSelector::mouseMoveEvent( QMouseEvent * event ) -{ - QStyleOptionComboBox option; - option.initFrom( this ); - QRect r = style()->subControlRect( QStyle::CC_ComboBox, &option, QStyle::SC_ComboBoxEditField, this ); - if (r.contains(event->pos())) - setCursor(Qt::PointingHandCursor); - else - unsetCursor(); -} - - -void KoResourceSelector::setDisplayMode(DisplayMode mode) -{ - if (mode == d->displayMode) - return; - - switch(mode) { - case ImageMode: - setItemDelegate(new KisResourceItemDelegate(this)); - setView( new KisResourceItemListView(this) ); - break; - case TextMode: - setItemDelegate(new QStyledItemDelegate(this)); - setView(new QListView(this)); - break; - } - - d->displayMode = mode; - d->updateIndex(this); -} - -void KoResourceSelector::setSingleColumn(bool singleColumn) { - qDebug() << "setting single column" << singleColumn; - KisResourceItemListView * listView = qobject_cast(view()); - if (!listView) return; - if (singleColumn) { - qDebug() << "resource item view exists and is set single column"; - listView->setViewMode(QListView::ListMode); - listView->setItemSize(QSize(listView->viewport()->width(),listView->iconSize().height())); - } else { - listView->setViewMode(QListView::IconMode); - listView->setItemSize(QSize(listView->iconSize().height(), listView->iconSize().height())); - } -} - -void KoResourceSelector::setRowHeight( int rowHeight ) -{ - KisResourceItemListView * listView = qobject_cast(view()); - if (listView) { - listView->setItemSize(QSize(listView->iconSize().width(), rowHeight)); - } -} - -void KoResourceSelector::indexChanged( int ) -{ - QModelIndex index = view()->currentIndex(); - if(!index.isValid()) { - return; - } - KoResourceSP resource = d->model->resourceForIndex(index); - if (resource) { - emit resourceSelected( resource ); - } -} diff --git a/plugins/tools/karbonplugins/tools/filterEffectTool/KoResourceSelector.h b/plugins/tools/karbonplugins/tools/filterEffectTool/KoResourceSelector.h deleted file mode 100644 index 78a5d38b33..0000000000 --- a/plugins/tools/karbonplugins/tools/filterEffectTool/KoResourceSelector.h +++ /dev/null @@ -1,81 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2008 Jan Hambrecht - * - * 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 KORESOURCESELECTOR_H -#define KORESOURCESELECTOR_H - -#include -#include -class QMouseEvent; -class KoAbstractResourceServerAdapter; - -/** - * A custom combobox widget for selecting resource items like gradients or patterns. - */ -class KoResourceSelector : public QComboBox -{ - Q_OBJECT -public: - enum DisplayMode { - ImageMode, ///< Displays image of resources (default) - TextMode ///< Displays name of resources - }; - - /** - * Constructs a new resource selector. - * @param parent the parent widget - */ - explicit KoResourceSelector(QWidget *parent = 0); - - /// Destroys the resource selector - ~KoResourceSelector() override; - - /// Sets the display mode - void setDisplayMode(DisplayMode mode); - - //Whether to use single column mode; - void setSingleColumn(bool singleColumn); - - /// Sets the height of the popup view rows - void setRowHeight( int rowHeight ); - -Q_SIGNALS: - /// Emitted when a resource was selected - void resourceSelected( KoResourceSP resource ); - - /// Is emitted when the user has clicked on the current resource - void resourceApplied( KoResourceSP resource ); - -protected: - /// reimplemented - void paintEvent( QPaintEvent * ) override; - /// reimplemented - void mousePressEvent( QMouseEvent * ) override; - /// reimplemented - void mouseMoveEvent( QMouseEvent * event ) override; - -private Q_SLOTS: - void indexChanged( int index ); - -private: - class Private; - Private * const d; -}; - -#endif // KORESOURCESELECTOR_H diff --git a/plugins/tools/karbonplugins/tools/karbontools.qrc b/plugins/tools/karbonplugins/tools/karbontools.qrc index b2323305b3..4b38d80356 100644 --- a/plugins/tools/karbonplugins/tools/karbontools.qrc +++ b/plugins/tools/karbonplugins/tools/karbontools.qrc @@ -1,7 +1,5 @@ 22-actions-calligraphy.png - 22-actions-pattern.png - 32-actions-tool_imageeffects.png