[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [calligra] krita/plugins/paintops/colorsmudge: Add a new smudging behavior to the the Color Smudge b
From:       Silvio Heinrich <plassy () web ! de>
Date:       2012-05-04 10:28:32
Message-ID: 20120504102832.4EF80A60A9 () git ! kde ! org
[Download RAW message or body]

Git commit ad11929002ffd2c8862564a99d705ca267edc162 by Silvio Heinrich.
Committed on 04/05/2012 at 12:16.
Pushed by heinrich into branch 'master'.

Add a new smudging behavior to the the Color Smudge brush.

I added an option to the "Smudge Rate" setting to choose between
the default smudging (smearing) behaviour and an behaviour similar to mypaint \
smudging (dulling).

M  +3    -1    krita/plugins/paintops/colorsmudge/CMakeLists.txt
M  +19   -3    krita/plugins/paintops/colorsmudge/kis_colorsmudgeop.cpp
M  +2    -1    krita/plugins/paintops/colorsmudge/kis_colorsmudgeop.h
M  +4    -1    krita/plugins/paintops/colorsmudge/kis_colorsmudgeop_settings_widget.cpp
 M  +3    -2    krita/plugins/paintops/colorsmudge/kis_rate_option.cpp
M  +2    -2    krita/plugins/paintops/colorsmudge/kis_rate_option.h
C  +21   -5    krita/plugins/paintops/colorsmudge/kis_smudge_option.cpp [from: \
krita/plugins/paintops/colorsmudge/kis_rate_option.cpp - 062% similarity] C  +20   \
-10   krita/plugins/paintops/colorsmudge/kis_smudge_option.h [from: \
krita/plugins/paintops/colorsmudge/kis_rate_option.h - 063% similarity] A  +69   -0   \
krita/plugins/paintops/colorsmudge/kis_smudge_option_widget.cpp     [License: LGPL \
(v2+)] C  +17   -19   krita/plugins/paintops/colorsmudge/kis_smudge_option_widget.h \
[from: krita/plugins/paintops/colorsmudge/kis_rate_option.h - 053% similarity]     \
[License: UNKNOWN]  *

The files marked with a * at the end have a non valid license. Please read: \
http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are \
listed at that page.


http://commits.kde.org/calligra/ad11929002ffd2c8862564a99d705ca267edc162

diff --git a/krita/plugins/paintops/colorsmudge/CMakeLists.txt \
b/krita/plugins/paintops/colorsmudge/CMakeLists.txt index a79fa39..e1823f8 100644
--- a/krita/plugins/paintops/colorsmudge/CMakeLists.txt
+++ b/krita/plugins/paintops/colorsmudge/CMakeLists.txt
@@ -4,7 +4,9 @@ set(kritacolorsmudgepaintop_PART_SRCS
     kis_colorsmudgeop_settings_widget.cpp
     kis_rate_option.cpp
     kis_rate_option_widget.cpp
-    )
+    kis_smudge_option.cpp
+    kis_smudge_option_widget.cpp
+)
 
 kde4_add_plugin(kritacolorsmudgepaintop ${kritacolorsmudgepaintop_PART_SRCS})
 
diff --git a/krita/plugins/paintops/colorsmudge/kis_colorsmudgeop.cpp \
b/krita/plugins/paintops/colorsmudge/kis_colorsmudgeop.cpp index a36d0be..25c5c23 \
                100644
--- a/krita/plugins/paintops/colorsmudge/kis_colorsmudgeop.cpp
+++ b/krita/plugins/paintops/colorsmudge/kis_colorsmudgeop.cpp
@@ -19,6 +19,7 @@
 #include "kis_colorsmudgeop.h"
 
 #include <cmath>
+#include <memory>
 #include <QRect>
 
 #include <KoColorSpaceRegistry.h>
@@ -182,11 +183,26 @@ qreal KisColorSmudgeOp::paintAt(const KisPaintInformation& \
info)  }
     
     // reset composite mode and opacity
-    // then cut out the area from the canvas under the brush
-    // and blit it to the temporary painting device
     m_tempPainter->setCompositeOp(COMPOSITE_OVER);
     m_tempPainter->setOpacity(OPACITY_OPAQUE_U8);
-    m_tempPainter->bitBlt(0, 0, painter()->device(), x, y, m_maskBounds.width(), \
m_maskBounds.height()); +    
+    if(m_smudgeRateOption.getMode() == KisSmudgeOption::SMEARING_MODE) {
+        // cut out the area from the canvas under the brush
+        // and blit it to the temporary painting device
+        m_tempPainter->bitBlt(0, 0, painter()->device(), x, y, m_maskBounds.width(), \
m_maskBounds.height()); +    }
+    else {
+        KoColorSpace* cs    = painter()->device()->colorSpace();
+        quint8*       color = new quint8[cs->pixelSize()];
+        qint32        px    = x + m_maskBounds.width()  / 2;
+        qint32        py    = y + m_maskBounds.height() / 2;
+        
+        // get the pixel on the canvas that lies beneath the center
+        // of the dab and fill  the temporary paint device with that color
+        painter()->device()->readBytes(color, px, py, 1, 1);
+        m_tempPainter->fill(0, 0, m_maskBounds.width(), m_maskBounds.height(), \
KoColor(color, cs)); +        delete[] color;
+    }
     
     // if the user selected the color smudge option
     // we will mix some color into the temorary painting device (m_tempDev)
diff --git a/krita/plugins/paintops/colorsmudge/kis_colorsmudgeop.h \
b/krita/plugins/paintops/colorsmudge/kis_colorsmudgeop.h index 1f7bd69..59597da \
                100644
--- a/krita/plugins/paintops/colorsmudge/kis_colorsmudgeop.h
+++ b/krita/plugins/paintops/colorsmudge/kis_colorsmudgeop.h
@@ -33,6 +33,7 @@
 
 #include "kis_overlay_mode_option.h"
 #include "kis_rate_option.h"
+#include "kis_smudge_option.h"
 
 class QPointF;
 class KoAbstractGradient;
@@ -61,7 +62,7 @@ private:
     KisPressureSizeOption     m_sizeOption;
     KisPressureOpacityOption  m_opacityOption;
     KisPressureSpacingOption  m_spacingOption;
-    KisRateOption             m_smudgeRateOption;
+    KisSmudgeOption           m_smudgeRateOption;
     KisRateOption             m_colorRateOption;
     KisOverlayModeOption      m_overlayModeOption;
     KisPressureRotationOption m_rotationOption;
diff --git a/krita/plugins/paintops/colorsmudge/kis_colorsmudgeop_settings_widget.cpp \
b/krita/plugins/paintops/colorsmudge/kis_colorsmudgeop_settings_widget.cpp index \
                fd66770..038dbcd 100644
--- a/krita/plugins/paintops/colorsmudge/kis_colorsmudgeop_settings_widget.cpp
+++ b/krita/plugins/paintops/colorsmudge/kis_colorsmudgeop_settings_widget.cpp
@@ -20,6 +20,7 @@
 #include "kis_brush_based_paintop_settings.h"
 #include "kis_overlay_mode_option.h"
 #include "kis_rate_option_widget.h"
+#include "kis_smudge_option_widget.h"
 
 #include <kis_properties_configuration.h>
 #include <kis_paintop_options_widget.h>
@@ -38,12 +39,14 @@ KisColorSmudgeOpSettingsWidget::KisColorSmudgeOpSettingsWidget(QWidget* \
parent):  KisBrushBasedPaintopOptionWidget(parent)
 {
     setObjectName("brush option widget");
+    
+//     KisSmudgeOptionWidget* opt = 
 
     addPaintOpOption(new KisCompositeOpOption(true));
     addPaintOpOption(new KisCurveOptionWidget(new KisPressureSizeOption()));
     addPaintOpOption(new KisCurveOptionWidget(new KisPressureOpacityOption()));
     addPaintOpOption(new KisCurveOptionWidget(new KisPressureSpacingOption()));
-    addPaintOpOption(new KisRateOptionWidget(i18n("Smudge Rate"), i18n("Rate: "), \
"SmudgeRate", true)); +    addPaintOpOption(new KisSmudgeOptionWidget(i18n("Smudge \
                Rate"), i18n("Rate: "), "SmudgeRate", true));
     addPaintOpOption(new KisRateOptionWidget(i18n("Color Rate") , i18n("Rate: "), \
                "ColorRate" , false));
     addPaintOpOption(new KisCurveOptionWidget(new KisPressureRotationOption()));
     addPaintOpOption(new KisPressureScatterOptionWidget());
diff --git a/krita/plugins/paintops/colorsmudge/kis_rate_option.cpp \
b/krita/plugins/paintops/colorsmudge/kis_rate_option.cpp index 831cb64..38be444 \
                100644
--- a/krita/plugins/paintops/colorsmudge/kis_rate_option.cpp
+++ b/krita/plugins/paintops/colorsmudge/kis_rate_option.cpp
@@ -28,6 +28,8 @@
 #include <KoColor.h>
 #include <KoColorSpace.h>
 
+#include <iostream>
+
 KisRateOption::KisRateOption(const QString& name, const QString& label, bool \
checked, const QString& category):  KisCurveOption(label, name, category, checked) { \
}  
@@ -40,7 +42,6 @@ void KisRateOption::apply(KisPainter& painter, const \
KisPaintInformation& info,  
     qreal  rate    = scaleMin + (scaleMax - scaleMin) * multiplicator * \
                computeValue(info); // scale m_rate into the range scaleMin - \
                scaleMax
     quint8 opacity = qBound(OPACITY_TRANSPARENT_U8, (quint8)(rate * 255.0), \
                OPACITY_OPAQUE_U8);
-
+    
     painter.setOpacity(opacity);
 }
-
diff --git a/krita/plugins/paintops/colorsmudge/kis_rate_option.h \
b/krita/plugins/paintops/colorsmudge/kis_rate_option.h index bc327af..33442d9 100644
--- a/krita/plugins/paintops/colorsmudge/kis_rate_option.h
+++ b/krita/plugins/paintops/colorsmudge/kis_rate_option.h
@@ -32,13 +32,13 @@ class KisRateOption: public KisCurveOption
 {
 public:
     KisRateOption(const QString& name, const QString& label="", bool checked=true, \
                const QString& category=KisPaintOpOption::brushCategory());
-
+    
     /**
      * Set the opacity of the painter based on the rate
      * and the curve (if checked)
      */
     void apply(KisPainter& painter, const KisPaintInformation& info, qreal \
                scaleMin=0.0, qreal scaleMax=1.0, qreal multiplicator=1.0) const;
-
+    
     void setRate(qreal rate) { KisCurveOption::setValue(rate); }
     qreal getRate() const { return KisCurveOption::value(); }
 };
diff --git a/krita/plugins/paintops/colorsmudge/kis_rate_option.cpp \
b/krita/plugins/paintops/colorsmudge/kis_smudge_option.cpp similarity index 62%
copy from krita/plugins/paintops/colorsmudge/kis_rate_option.cpp
copy to krita/plugins/paintops/colorsmudge/kis_smudge_option.cpp
index 831cb64..62ae447 100644
--- a/krita/plugins/paintops/colorsmudge/kis_rate_option.cpp
+++ b/krita/plugins/paintops/colorsmudge/kis_smudge_option.cpp
@@ -18,7 +18,7 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#include "kis_rate_option.h"
+#include "kis_smudge_option.h"
 
 #include <klocale.h>
 
@@ -28,10 +28,11 @@
 #include <KoColor.h>
 #include <KoColorSpace.h>
 
-KisRateOption::KisRateOption(const QString& name, const QString& label, bool \
                checked, const QString& category):
-    KisCurveOption(label, name, category, checked) { }
+KisSmudgeOption::KisSmudgeOption(const QString& name, const QString& label, bool \
checked, const QString& category): +    KisRateOption(name, label, checked, \
category), +    mMode(SMEARING_MODE) { }
 
-void KisRateOption::apply(KisPainter& painter, const KisPaintInformation& info, \
qreal scaleMin, qreal scaleMax, qreal multiplicator) const +void \
KisSmudgeOption::apply(KisPainter& painter, const KisPaintInformation& info, qreal \
scaleMin, qreal scaleMax, qreal multiplicator) const  {
     if(!isChecked()) {
         painter.setOpacity((quint8)(scaleMax * 255.0));
@@ -40,7 +41,22 @@ void KisRateOption::apply(KisPainter& painter, const \
KisPaintInformation& info,  
     qreal  rate    = scaleMin + (scaleMax - scaleMin) * multiplicator * \
                computeValue(info); // scale m_rate into the range scaleMin - \
                scaleMax
     quint8 opacity = qBound(OPACITY_TRANSPARENT_U8, (quint8)(rate * 255.0), \
                OPACITY_OPAQUE_U8);
-
+    
     painter.setOpacity(opacity);
 }
 
+void KisSmudgeOption::writeOptionSetting(KisPropertiesConfiguration* setting) const
+{
+    KisRateOption::writeOptionSetting(setting);
+    setting->setProperty(name() + "Mode", mMode);
+}
+
+void KisSmudgeOption::readOptionSetting(const KisPropertiesConfiguration* setting)
+{
+    KisRateOption::readOptionSetting(setting);
+    
+    if(setting->hasProperty(name() + "Mode"))
+        mMode = (Mode)setting->getInt(name() + "Mode", mMode);
+    else
+        mMode = SMEARING_MODE;
+}
diff --git a/krita/plugins/paintops/colorsmudge/kis_rate_option.h \
b/krita/plugins/paintops/colorsmudge/kis_smudge_option.h similarity index 63%
copy from krita/plugins/paintops/colorsmudge/kis_rate_option.h
copy to krita/plugins/paintops/colorsmudge/kis_smudge_option.h
index bc327af..36dff06 100644
--- a/krita/plugins/paintops/colorsmudge/kis_rate_option.h
+++ b/krita/plugins/paintops/colorsmudge/kis_smudge_option.h
@@ -18,29 +18,39 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef KIS_RATE_OPTION_H
-#define KIS_RATE_OPTION_H
+#ifndef KIS_SMUDGE_OPTION_H
+#define KIS_SMUDGE_OPTION_H
 
-#include "kis_curve_option.h"
+#include "kis_rate_option.h"
 #include <kis_paint_information.h>
 #include <kis_types.h>
 
+// static const QString SMUDGE_MODE = "SmudgeMode";
+
 class KisPropertiesConfiguration;
 class KisPainter;
 
-class KisRateOption: public KisCurveOption
+class KisSmudgeOption: public KisRateOption
 {
 public:
-    KisRateOption(const QString& name, const QString& label="", bool checked=true, \
                const QString& category=KisPaintOpOption::brushCategory());
-
+    KisSmudgeOption(const QString& name, const QString& label="", bool checked=true, \
const QString& category=KisPaintOpOption::brushCategory()); +    
+    enum Mode { SMEARING_MODE, DULLING_MODE };
+    
     /**
      * Set the opacity of the painter based on the rate
      * and the curve (if checked)
      */
     void apply(KisPainter& painter, const KisPaintInformation& info, qreal \
                scaleMin=0.0, qreal scaleMax=1.0, qreal multiplicator=1.0) const;
-
-    void setRate(qreal rate) { KisCurveOption::setValue(rate); }
-    qreal getRate() const { return KisCurveOption::value(); }
+    
+    Mode getMode()          { return mMode;  }
+    void setMode(Mode mode) { mMode = mode; }
+    
+    virtual void writeOptionSetting(KisPropertiesConfiguration* setting) const;
+    virtual void readOptionSetting(const KisPropertiesConfiguration* setting);
+    
+private:
+    Mode mMode;
 };
 
-#endif // KIS_RATE_OPTION_H
+#endif // KIS_SMUDGE_OPTION_H
diff --git a/krita/plugins/paintops/colorsmudge/kis_smudge_option_widget.cpp \
b/krita/plugins/paintops/colorsmudge/kis_smudge_option_widget.cpp new file mode \
100644 index 0000000..21b0adb
--- /dev/null
+++ b/krita/plugins/paintops/colorsmudge/kis_smudge_option_widget.cpp
@@ -0,0 +1,69 @@
+/* This file is part of the KDE project
+ * 
+ * Copyright (C) 2011 Silvio Heinrich <plassy@web.de>
+ *
+ * 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 <klocale.h>
+#include <QWidget>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QComboBox>
+#include <QLabel>
+
+#include "kis_smudge_option_widget.h"
+#include "kis_smudge_option.h"
+
+KisSmudgeOptionWidget::KisSmudgeOptionWidget(const QString& label, const QString& \
sliderLabel, const QString& name, bool checked): +    KisCurveOptionWidget(new \
KisSmudgeOption(name, label, checked)) +{
+    mCbSmudgeMode = new QComboBox();
+    mCbSmudgeMode->addItem(i18n("Smearing"), KisSmudgeOption::SMEARING_MODE);
+    mCbSmudgeMode->addItem(i18n("Dulling") , KisSmudgeOption::DULLING_MODE);
+    
+    QHBoxLayout* h = new QHBoxLayout();
+    h->addWidget(new QLabel(i18n("Smudge Mode")));
+    h->addWidget(mCbSmudgeMode, 1);
+    
+    QVBoxLayout* v = new QVBoxLayout();
+    QWidget*     w = new QWidget();
+    
+    v->addLayout(h);
+    v->addWidget(curveWidget());
+    w->setLayout(v);
+    
+    KisCurveOptionWidget::setConfigurationPage(w);
+    
+    connect(mCbSmudgeMode, SIGNAL(currentIndexChanged(int)), this, \
SLOT(slotCurrentIndexChanged(int))); +}
+
+void KisSmudgeOptionWidget::slotCurrentIndexChanged(int index)
+{
+    static_cast<KisSmudgeOption*>(curveOption())->setMode((KisSmudgeOption::Mode)index);
 +    emit sigSettingChanged();
+}
+
+void KisSmudgeOptionWidget::readOptionSetting(const KisPropertiesConfiguration* \
setting) +{
+    KisCurveOptionWidget::readOptionSetting(setting);
+    
+    KisSmudgeOption::Mode mode = \
static_cast<KisSmudgeOption*>(curveOption())->getMode(); +    
+    mCbSmudgeMode->blockSignals(true);
+    mCbSmudgeMode->setCurrentIndex(mode == KisSmudgeOption::SMEARING_MODE ? 0 : 1);
+    mCbSmudgeMode->blockSignals(false);
+}
diff --git a/krita/plugins/paintops/colorsmudge/kis_rate_option.h \
b/krita/plugins/paintops/colorsmudge/kis_smudge_option_widget.h similarity index 53%
copy from krita/plugins/paintops/colorsmudge/kis_rate_option.h
copy to krita/plugins/paintops/colorsmudge/kis_smudge_option_widget.h
index bc327af..13ef679 100644
--- a/krita/plugins/paintops/colorsmudge/kis_rate_option.h
+++ b/krita/plugins/paintops/colorsmudge/kis_smudge_option_widget.h
@@ -18,29 +18,27 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef KIS_RATE_OPTION_H
-#define KIS_RATE_OPTION_H
+#ifndef KIS_SMUDGE_OPTION_WIDGET_H
+#define KIS_SMUDGE_OPTION_WIDGET_H
 
-#include "kis_curve_option.h"
-#include <kis_paint_information.h>
-#include <kis_types.h>
+#include <kis_curve_option_widget.h>
 
-class KisPropertiesConfiguration;
-class KisPainter;
+class QComboBox;
 
-class KisRateOption: public KisCurveOption
+class KisSmudgeOptionWidget: public KisCurveOptionWidget
 {
+    Q_OBJECT
+    
 public:
-    KisRateOption(const QString& name, const QString& label="", bool checked=true, \
                const QString& category=KisPaintOpOption::brushCategory());
-
-    /**
-     * Set the opacity of the painter based on the rate
-     * and the curve (if checked)
-     */
-    void apply(KisPainter& painter, const KisPaintInformation& info, qreal \
                scaleMin=0.0, qreal scaleMax=1.0, qreal multiplicator=1.0) const;
-
-    void setRate(qreal rate) { KisCurveOption::setValue(rate); }
-    qreal getRate() const { return KisCurveOption::value(); }
+    KisSmudgeOptionWidget(const QString& label, const QString& sliderLabel, const \
QString& name, bool checked); +    
+    virtual void readOptionSetting(const KisPropertiesConfiguration* setting);
+    
+private slots:
+    void slotCurrentIndexChanged(int index);
+    
+private:
+    QComboBox* mCbSmudgeMode;
 };
 
-#endif // KIS_RATE_OPTION_H
+#endif // KIS_SMUDGE_OPTION_WIDGET_H


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic