Message info
 
To:kde-commits@kde.org From:Boudewijn Rempt Subject:[calligra/krita-texturizer_option-rempt] krita/plugins/paintops: Split the texture option in an option and a properties class Date:Sun, 18 Mar 2012 16:41:31 +0100 (CET)
 

Git commit 5a52425674712e364e404e0141af72d137567846 by Boudewijn Rempt.
Committed on 18/03/2012 at 16:41.
Pushed by rempt into branch 'krita-texturizer_option-rempt'.

Split the texture option in an option and a properties class

Turns out that my knowledge of Krita's api is a couple of years out
of date...

M +2 -2 krita/plugins/paintops/defaultpaintops/brush/kis_brushop.cpp
M +1 -1 krita/plugins/paintops/defaultpaintops/brush/kis_brushop.h
M +54 -29 krita/plugins/paintops/libpaintop/kis_texture_option.cpp
M +29 -3 krita/plugins/paintops/libpaintop/kis_texture_option.h

http://commits.kde.org/calligra/5a52425674712e364e404e0141af72d137567846

diff --git a/krita/plugins/paintops/defaultpaintops/brush/kis_brushop.cpp b/krita/plugins/paintops/defaultpaintops/brush/kis_brushop.cpp
index 989dfa7..7e1eb75 100644
--- a/krita/plugins/paintops/defaultpaintops/brush/kis_brushop.cpp
+++ b/krita/plugins/paintops/defaultpaintops/brush/kis_brushop.cpp
@@ -76,7 +76,7 @@ KisBrushOp::KisBrushOp(const KisBrushBasedPaintOpSettings *settings, KisPainter
m_mixOption.readOptionSetting(settings);
m_scatterOption.readOptionSetting(settings);
m_mirrorOption.readOptionSetting(settings);
- m_textureOption.readOptionSetting(settings);
+ m_textureProperties.fillProperties(settings);

m_opacityOption.sensor()->reset();
m_sizeOption.sensor()->reset();
@@ -172,7 +172,7 @@ qreal KisBrushOp::paintAt(const KisPaintInformation& info)
}

// after applying the coloring information, apply the texturing
- m_textureOption.apply(dab, info.pos().toPoint());
+ m_textureProperties.apply(dab, info.pos().toPoint());
}

MirrorProperties mirrors = m_mirrorOption.apply(info);
diff --git a/krita/plugins/paintops/defaultpaintops/brush/kis_brushop.h b/krita/plugins/paintops/defaultpaintops/brush/kis_brushop.h
index 6a8a69a..1b545ef 100644
--- a/krita/plugins/paintops/defaultpaintops/brush/kis_brushop.h
+++ b/krita/plugins/paintops/defaultpaintops/brush/kis_brushop.h
@@ -69,8 +69,8 @@ private:
KisPressureRotationOption m_rotationOption;
KisPressureMixOption m_mixOption;
KisPressureScatterOption m_scatterOption;
- KisTextureOption m_textureOption;
QList<KisPressureHSVOption*> m_hsvOptions;
+ KisTextureProperties m_textureProperties;

KoColorTransformation *m_hsvTransformation;
KisPaintDeviceSP m_dab;
diff --git a/krita/plugins/paintops/libpaintop/kis_texture_option.cpp b/krita/plugins/paintops/libpaintop/kis_texture_option.cpp
index b94242c..7b367a9 100644
--- a/krita/plugins/paintops/libpaintop/kis_texture_option.cpp
+++ b/krita/plugins/paintops/libpaintop/kis_texture_option.cpp
@@ -108,7 +108,6 @@ public:

KisTextureOption::KisTextureOption(QObject *)
: KisPaintOpOption(i18n("Pattern"), KisPaintOpOption::textureCategory(), true)
- , m_mask(0)
{
setChecked(false);
m_optionWidget = new KisTextureOptionWidget;
@@ -118,25 +117,13 @@ KisTextureOption::KisTextureOption(QObject *)
connect(m_optionWidget->chooser, SIGNAL(resourceSelected(KoResource*)), SLOT(resetGUI(KoResource*)));

resetGUI(m_optionWidget->chooser->currentResource());
-
- // only these options directly influence the calculation of the mask
- connect(m_optionWidget->scaleSlider, SIGNAL(valueChanged(qreal)), SLOT(recalculateMask()));
- connect(m_optionWidget->rotationSlider, SIGNAL(valueChanged(qreal)), SLOT(recalculateMask()));
- connect(m_optionWidget->strengthSlider, SIGNAL(valueChanged(qreal)), SLOT(recalculateMask()));
- connect(m_optionWidget->chkInvert, SIGNAL(toggled(bool)), SLOT(recalculateMask()));
}

KisTextureOption::~KisTextureOption()
{
- qDebug() << "deleting" << this << "parent:" << parent();
delete m_optionWidget;
}

-void KisTextureOption::apply(KisFixedPaintDeviceSP dab, const QPoint &offset)
-{
- if (!isChecked()) return;
-}
-
void KisTextureOption::writeOptionSetting(KisPropertiesConfiguration* setting) const
{
if (!m_optionWidget->chooser->currentResource()) return;
@@ -167,6 +154,8 @@ void KisTextureOption::writeOptionSetting(KisPropertiesConfiguration* setting) c
setting->setProperty("Texture/Pattern/Pattern", ba.toBase64());
setting->setProperty("Texture/Pattern/PatternFileName", pattern->filename());
setting->setProperty("Texture/Pattern/Name", pattern->name());
+
+ setting->setProperty("Texture/Pattern/Enabled", isChecked());
}

void KisTextureOption::readOptionSetting(const KisPropertiesConfiguration* setting)
@@ -215,7 +204,7 @@ void KisTextureOption::readOptionSetting(const KisPropertiesConfiguration* setti
m_optionWidget->chkInvert->setChecked(setting->getBool("Texture/Pattern/Invert"));
m_optionWidget->cmbChannel->setCurrentIndex(setting->getInt("Texture/Pattern/Channel"));

- recalculateMask();
+ setChecked(setting->getBool("Texture/Pattern/Enabled"));
}

void KisTextureOption::resetGUI(KoResource* res)
@@ -230,35 +219,28 @@ void KisTextureOption::resetGUI(KoResource* res)
m_optionWidget->strengthSlider->setValue(1.0);
m_optionWidget->chkInvert->setChecked(false);
m_optionWidget->cmbChannel->setCurrentIndex(0);
-
- recalculateMask();
}

-void KisTextureOption::recalculateMask()
+void KisTextureProperties::recalculateMask()
{
- if (!m_optionWidget->chooser->currentResource()) return;
+ if (!pattern) return;

delete m_mask;
m_mask = 0;

- KisPattern *pattern = static_cast<KisPattern*>(m_optionWidget->chooser->currentResource());
-
QImage mask = pattern->image();

- if (!qFuzzyCompare(m_optionWidget->rotationSlider->value(), 0.0)) {
+ if (!qFuzzyCompare(rotation, 0.0)) {
// do rotation
}
- if (!qFuzzyCompare(m_optionWidget->scaleSlider->value(), 0.0)) {
+ if (!qFuzzyCompare(scale, 0.0)) {

QTransform tf;
- tf.scale(m_optionWidget->scaleSlider->value(), m_optionWidget->scaleSlider->value());
+ tf.scale(scale, scale);
QRect rc = tf.mapRect(mask.rect());
mask = mask.scaled(rc.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
}

- // convert to grayscale mask and apply the strength
- float strength = m_optionWidget->strengthSlider->value();
-
QRgb* pixel = reinterpret_cast<QRgb*>( mask.bits() );
int width = mask.width();
int height = mask.height();
@@ -282,7 +264,50 @@ void KisTextureOption::recalculateMask()
cs->setOpacity(maskData + (row * width + col), maskValue, 1);
}
}
- static int i = 0;
- m_mask->convertToQImage(0).save(QString("mask_%1.png").arg(i));
- i++;
+// static int i = 0;
+// m_mask->convertToQImage(0).save(QString("mask_%1.png").arg(i));
+// i++;
}
+
+
+void KisTextureProperties::fillProperties(const KisPropertiesConfiguration *setting)
+{
+ QByteArray ba = QByteArray::fromBase64(setting->getString("Texture/Pattern/Pattern").toAscii());
+ QImage img;
+ img.loadFromData(ba, "PNG");
+ QString name = setting->getString("Texture/Pattern/Name");
+ if (name.isEmpty()) {
+ name = setting->getString("Texture/Pattern/FileName");
+ }
+
+ pattern = 0;
+ if (!img.isNull()) {
+ pattern = new KisPattern(img, name);
+ }
+ if (pattern) {
+ foreach(KoResource *res, KisResourceServerProvider::instance()->patternServer()->resources()) {
+ KisPattern *pat = static_cast<KisPattern *>(res);
+ if (pat == pattern) {
+ delete pattern;
+ pattern = pat;
+ break;
+ }
+ }
+ }
+
+ enabled = setting->getBool("Texture/Pattern/Enabled", false);
+ scale = setting->getDouble("Texture/Pattern/Scale", 1.0);
+ rotation = setting->getDouble("Texture/Pattern/Rotation");
+ offsetX = setting->getInt("Texture/Pattern/OffsetX");
+ offsetY = setting->getInt("Texture/Pattern/OffsetY");
+ strength = setting->getDouble("Texture/Pattern/Strength");
+ invert = setting->getBool("Texture/Pattern/Invert");
+ activeChannel = (KisTextureOption::TextureChannel)setting->getInt("Texture/Pattern/Channel");
+
+ recalculateMask();
+}
+
+void KisTextureProperties::apply(KisFixedPaintDeviceSP dab, const QPoint &offset)
+{
+}
+
diff --git a/krita/plugins/paintops/libpaintop/kis_texture_option.h b/krita/plugins/paintops/libpaintop/kis_texture_option.h
index 066a802..14a6964 100644
--- a/krita/plugins/paintops/libpaintop/kis_texture_option.h
+++ b/krita/plugins/paintops/libpaintop/kis_texture_option.h
@@ -44,8 +44,6 @@ public:
explicit KisTextureOption(QObject *parent= 0);
virtual ~KisTextureOption();

- void apply(KisFixedPaintDeviceSP dab, const QPoint& _offset);
-
public slots:

virtual void writeOptionSetting(KisPropertiesConfiguration* setting) const;
@@ -54,11 +52,39 @@ public slots:
private slots:

void resetGUI(KoResource*); /// called when a new pattern is selected
- void recalculateMask();
+
private:
KisTextureOptionWidget *m_optionWidget;
+
+
+};
+
+class PAINTOP_EXPORT KisTextureProperties
+{
+public:
+ KisTextureProperties()
+ : pattern(0)
+ , m_mask(0)
+ {}
+
+ bool enabled;
+ qreal scale;
+ qreal rotation;
+ int offsetX;
+ int offsetY;
+ qreal strength;
+ bool invert;
+ KisTextureOption::TextureChannel activeChannel;
+ KisPattern *pattern;
+
+ void apply(KisFixedPaintDeviceSP dab, const QPoint& _offset);
+ void fillProperties(const KisPropertiesConfiguration *setting);
+
+private:
+
KisFixedPaintDevice *m_mask;

+ void recalculateMask();
};

#endif // KIS_TEXTURE_OPTION_H