Commit ead62dbb authored by Wolthera van Hövell's avatar Wolthera van Hövell 🛍

Give it a config widget with all the buttons wired up.

parent 3a24e539
......@@ -349,8 +349,8 @@ void KisEdgeDetectionKernel::convertToNormalMap(KisPaintDeviceSP device,
KisPaintDeviceSP x_denormalised = new KisPaintDevice(device->colorSpace());
KisPaintDeviceSP y_denormalised = new KisPaintDevice(device->colorSpace());
KisConvolutionKernelSP kernelHorizLeftRight = KisEdgeDetectionKernel::createHorizontalKernel(yRadius, type, true, channelFlip[0]);
KisConvolutionKernelSP kernelVerticalTopBottom = KisEdgeDetectionKernel::createVerticalKernel(xRadius, type, true, channelFlip[1]);
KisConvolutionKernelSP kernelHorizLeftRight = KisEdgeDetectionKernel::createHorizontalKernel(yRadius, type, true, !channelFlip[1]);
KisConvolutionKernelSP kernelVerticalTopBottom = KisEdgeDetectionKernel::createVerticalKernel(xRadius, type, true, !channelFlip[0]);
qreal horizontalCenter = qreal(kernelHorizLeftRight->width()) / 2.0;
qreal verticalCenter = qreal(kernelVerticalTopBottom->height()) / 2.0;
......
......@@ -16,6 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kis_convert_height_to_normal_map_filter.h"
#include "kis_wdg_convert_height_to_normal_map.h"
#include <kpluginfactory.h>
#include <klocalizedstring.h>
#include <filter/kis_filter_registry.h>
......@@ -42,7 +43,7 @@ KisConvertHeightToNormalMapFilter::KisConvertHeightToNormalMapFilter(): KisFilte
setSupportsAdjustmentLayers(true);
setSupportsLevelOfDetail(true);
setColorSpaceIndependence(FULLY_INDEPENDENT);
setShowConfigurationWidget(false);//for now...
setShowConfigurationWidget(true);
}
void KisConvertHeightToNormalMapFilter::processImpl(KisPaintDeviceSP device, const QRect &rect, const KisFilterConfigurationSP config, KoUpdater *progressUpdater) const
......@@ -77,13 +78,35 @@ void KisConvertHeightToNormalMapFilter::processImpl(KisPaintDeviceSP device, con
int channelToConvert = configuration->getInt("channelToConvert", 0);
QVector<int> channelOrder(3);
channelOrder[0] = 0;
channelOrder[1] = 1;
channelOrder[2] = 2;
QVector<bool> channelFlip(3);
channelFlip[0] = false;
channelFlip[1] = true;
channelFlip[2] = false;
channelFlip.fill(false);
int i = config->getInt("redSwizzle", 0);
if (i%2==1 || i==2) {
channelFlip[0] = true;
}
if (i==3) {
channelFlip[0] = false;
}
channelOrder[device->colorSpace()->channels().at(0)->displayPosition()] = qMax(i/2,0);
i = config->getInt("greenSwizzle", 2);
if (i%2==1 || i==2) {
channelFlip[1] = true;
}
if (i==3) {
channelFlip[1] = false;
}
channelOrder[device->colorSpace()->channels().at(1)->displayPosition()] = qMax(i/2,0);
i = config->getInt("blueSwizzle", 4);
if (i%2==1 || i==2) {
channelFlip[2] = true;
}
if (i==3) {
channelFlip[2] = false;
}
channelOrder[device->colorSpace()->channels().at(2)->displayPosition()] = qMax(i/2,0);
KisEdgeDetectionKernel::convertToNormalMap(device,
rect,
horizontalRadius,
......@@ -101,13 +124,21 @@ KisFilterConfigurationSP KisConvertHeightToNormalMapFilter::factoryConfiguration
KisFilterConfigurationSP config = new KisFilterConfiguration(id().id(), 1);
config->setProperty("horizRadius", 1);
config->setProperty("vertRadius", 1);
config->setProperty("type", "prewitt");
config->setProperty("type", "sobol");
config->setProperty("channelToConvert", 0);
config->setProperty("lockAspect", true);
config->setProperty("redSwizzle", KisWdgConvertHeightToNormalMap::xPlus);
config->setProperty("greenSwizzle", KisWdgConvertHeightToNormalMap::yPlus);
config->setProperty("blueSwizzle", KisWdgConvertHeightToNormalMap::zPlus);
return config;
}
KisConfigWidget *KisConvertHeightToNormalMapFilter::createConfigurationWidget(QWidget *parent, const KisPaintDeviceSP dev) const
{
return new KisWdgConvertHeightToNormalMap(parent, dev->colorSpace());
}
QRect KisConvertHeightToNormalMapFilter::neededRect(const QRect &rect, const KisFilterConfigurationSP _config, int lod) const
{
KisLodTransformScalar t(lod);
......
......@@ -43,7 +43,7 @@ public:
KisFilterConfigurationSP factoryConfiguration() const override;
public:
//KisConfigWidget * createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP dev) const override;
KisConfigWidget * createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP dev) const override;
QRect neededRect(const QRect & rect, const KisFilterConfigurationSP _config, int lod) const override;
QRect changedRect(const QRect & rect, const KisFilterConfigurationSP _config, int lod) const override;
};
......
/*
* Copyright (c) 2017 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kis_wdg_convert_height_to_normal_map.h"
#include <filter/kis_filter_configuration.h>
#include <QComboBox>
#include <klocalizedstring.h>
#include <KoChannelInfo.h>
KisWdgConvertHeightToNormalMap::KisWdgConvertHeightToNormalMap()
KisWdgConvertHeightToNormalMap::KisWdgConvertHeightToNormalMap(QWidget *parent, const KoColorSpace *cs) :
KisConfigWidget(parent),
ui(new Ui_WidgetConvertHeightToNormalMap),
m_cs(cs)
{
ui->setupUi(this);
m_types << "prewitt"<< "sobol"<< "simple";
m_types_translatable << i18n("Prewitt") << i18n("Sobol") << i18n("Simple");
QStringList swizzle;
swizzle<< "X+" << "X-" << "Y+" << "Y-" << "Z+" << "Z-";
ui->cmbType->addItems(m_types_translatable);
ui->cmbRed->addItems(swizzle);
ui->cmbGreen->addItems(swizzle);
ui->cmbBlue->addItems(swizzle);
for (int c=0; c<abs(m_cs->channelCount()); c++) {
ui->cmbChannel->addItem(m_cs->channels().at(c)->name());
}
ui->btnAspect->setKeepAspectRatio(false);
ui->sldHorizontalRadius->setRange(1.0, 100.0, 2);
ui->sldHorizontalRadius->setPrefix(i18n("Horizontal Radius:"));
connect(ui->sldHorizontalRadius, SIGNAL(valueChanged(qreal)), this, SLOT(horizontalRadiusChanged(qreal)));
ui->sldVerticalRadius->setRange(1.0, 100.0, 2);
ui->sldVerticalRadius->setPrefix(i18n("Vertical Radius:"));
connect(ui->sldVerticalRadius, SIGNAL(valueChanged(qreal)), this, SLOT(verticalRadiusChanged(qreal)));
connect(ui->sldHorizontalRadius, SIGNAL(valueChanged(qreal)), this, SIGNAL(sigConfigurationItemChanged()));
connect(ui->sldVerticalRadius, SIGNAL(valueChanged(qreal)), this, SIGNAL(sigConfigurationItemChanged()));
connect(ui->btnAspect, SIGNAL(keepAspectRatioChanged(bool)), this, SLOT(aspectLockChanged(bool)));
connect(ui->cmbType, SIGNAL(currentIndexChanged(int)), this, SIGNAL(sigConfigurationItemChanged()));
connect(ui->cmbChannel, SIGNAL(currentIndexChanged(int)), this, SIGNAL(sigConfigurationItemChanged()));
connect(ui->cmbRed, SIGNAL(currentIndexChanged(int)), this, SIGNAL(sigConfigurationItemChanged()));
connect(ui->cmbGreen, SIGNAL(currentIndexChanged(int)), this, SIGNAL(sigConfigurationItemChanged()));
connect(ui->cmbBlue, SIGNAL(currentIndexChanged(int)), this, SIGNAL(sigConfigurationItemChanged()));
}
KisWdgConvertHeightToNormalMap::~KisWdgConvertHeightToNormalMap()
{
delete ui;
}
KisPropertiesConfigurationSP KisWdgConvertHeightToNormalMap::configuration() const
{
KisFilterConfigurationSP config = new KisFilterConfiguration("height to normal", 1);
config->setProperty("horizRadius", ui->sldHorizontalRadius->value());
config->setProperty("vertRadius", ui->sldVerticalRadius->value());
config->setProperty("type", m_types.at(ui->cmbType->currentIndex()));
config->setProperty("lockAspect", ui->btnAspect->keepAspectRatio());
config->setProperty("channelToConvert", ui->cmbChannel->currentIndex());
config->setProperty("redSwizzle", ui->cmbRed->currentIndex());
config->setProperty("greenSwizzle", ui->cmbGreen->currentIndex());
config->setProperty("blueSwizzle", ui->cmbBlue->currentIndex());
return config;
}
void KisWdgConvertHeightToNormalMap::setConfiguration(const KisPropertiesConfigurationSP config)
{
ui->sldHorizontalRadius->setValue(config->getFloat("horizRadius", 1.0));
ui->sldVerticalRadius->setValue(config->getFloat("vertRadius", 1.0));
int index = 0;
if (m_types.contains(config->getString("type", "prewitt"))){
index = m_types.indexOf(config->getString("type", "sobol"));
}
ui->cmbType->setCurrentIndex(index);
ui->cmbChannel->setCurrentIndex(config->getInt("channelToConvert", 0));
ui->btnAspect->setKeepAspectRatio(config->getBool("lockAspect", false));
ui->cmbRed->setCurrentIndex(config->getInt("redSwizzle", xPlus));
ui->cmbGreen->setCurrentIndex(config->getInt("greenSwizzle", yPlus));
ui->cmbBlue->setCurrentIndex(config->getInt("blueSwizzle", zPlus));
}
void KisWdgConvertHeightToNormalMap::horizontalRadiusChanged(qreal r)
{
ui->sldHorizontalRadius->blockSignals(true);
ui->sldHorizontalRadius->setValue(r);
ui->sldHorizontalRadius->blockSignals(false);
if (ui->btnAspect->keepAspectRatio()) {
ui->sldVerticalRadius->blockSignals(true);
ui->sldVerticalRadius->setValue(r);
ui->sldVerticalRadius->blockSignals(false);
}
}
void KisWdgConvertHeightToNormalMap::verticalRadiusChanged(qreal r)
{
ui->sldVerticalRadius->blockSignals(true);
ui->sldVerticalRadius->setValue(r);
ui->sldVerticalRadius->blockSignals(false);
if (ui->btnAspect->keepAspectRatio()) {
ui->sldHorizontalRadius->blockSignals(true);
ui->sldHorizontalRadius->setValue(r);
ui->sldHorizontalRadius->blockSignals(false);
}
}
void KisWdgConvertHeightToNormalMap::aspectLockChanged(bool v)
{
if (v) {
ui->sldVerticalRadius->setValue( ui->sldHorizontalRadius->value() );
}
}
/*
* Copyright (c) 2017 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KIS_WDG_CONVERT_HEIGHT_TO_NORMAL_MAP_H
#define KIS_WDG_CONVERT_HEIGHT_TO_NORMAL_MAP_H
#include <kis_config_widget.h>
#include <QWidget>
#include <KoColorSpace.h>
#include "ui_wdg_convert_height_to_normal_map.h"
class Ui_WidgetConvertHeightToNormalMap;
class KisWdgConvertHeightToNormalMap
class KisWdgConvertHeightToNormalMap : public KisConfigWidget
{
Q_OBJECT
public:
KisWdgConvertHeightToNormalMap();
KisWdgConvertHeightToNormalMap(QWidget *parent, const KoColorSpace *cs);
~KisWdgConvertHeightToNormalMap();
KisPropertiesConfigurationSP configuration() const override;
void setConfiguration(const KisPropertiesConfigurationSP config) override;
enum swizzle {
xPlus,
xMin,
yPlus,
yMin,
zPlus,
zMin
};
private:
Ui_WidgetConvertHeightToNormalMap *ui;
QStringList m_types;
QStringList m_types_translatable;
const KoColorSpace *m_cs;
private Q_SLOTS:
void horizontalRadiusChanged(qreal r);
void verticalRadiusChanged(qreal r);
void aspectLockChanged(bool v);
};
#endif // KIS_WDG_CONVERT_HEIGHT_TO_NORMAL_MAP_H
\ No newline at end of file
#endif // KIS_WDG_CONVERT_HEIGHT_TO_NORMAL_MAP_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<class>WidgetConvertHeightToNormalMap</class>
<widget class="QWidget" name="WidgetConvertHeightToNormalMap">
<property name="geometry">
<rect>
<x>0</x>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment