Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_wdg_convert_height_to_normal_map.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2017 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
8#include <klocalizedstring.h>
9#include <KoChannelInfo.h>
11
13 : KisConfigWidget(parent)
14 , ui(new Ui_WidgetConvertHeightToNormalMap)
15 , m_cs(cs)
16
17{
18 if (cs->channelCount() < 3) {
19 QVBoxLayout *layout = new QVBoxLayout(this);
20 layout->addWidget(new QLabel(i18n("Height to Normal Map does not work on this colorspace.")));
21 return;
22 }
23
24
25 ui->setupUi(this);
26 m_types << "prewitt"<< "sobol"<< "simple";
27 m_types_translatable << i18n("Prewitt") << i18n("Sobel") << i18n("Simple");
29 swizzle<< "X+" << "X-" << "Y+" << "Y-" << "Z+" << "Z-";
30
31 ui->cmbType->addItems(m_types_translatable);
32 ui->cmbRed->addItems(swizzle);
33 ui->cmbGreen->addItems(swizzle);
34 ui->cmbBlue->addItems(swizzle);
35
36 const QList<KoChannelInfo*> channels = m_cs->channels();
37
38 for (int c = 0; c < (int)m_cs->channelCount(); c++) {
39 ui->cmbChannel->addItem(channels.at(c)->name());
40 }
41
42 ui->btnAspect->setKeepAspectRatio(false);
43 ui->sldHorizontalRadius->setRange(1.0, 100.0, 2);
44 ui->sldHorizontalRadius->setSingleStep(0.01);
45 ui->sldHorizontalRadius->setPrefix(i18n("Horizontal Radius:"));
46 connect(ui->sldHorizontalRadius, SIGNAL(valueChanged(qreal)), this, SLOT(horizontalRadiusChanged(qreal)));
47
48 ui->sldVerticalRadius->setRange(1.0, 100.0, 2);
49 ui->sldVerticalRadius->setSingleStep(0.01);
50 ui->sldVerticalRadius->setPrefix(i18n("Vertical Radius:"));
51 connect(ui->sldVerticalRadius, SIGNAL(valueChanged(qreal)), this, SLOT(verticalRadiusChanged(qreal)));
52
53 connect(ui->sldHorizontalRadius, SIGNAL(valueChanged(qreal)), this, SIGNAL(sigConfigurationItemChanged()));
54 connect(ui->sldVerticalRadius, SIGNAL(valueChanged(qreal)), this, SIGNAL(sigConfigurationItemChanged()));
55 connect(ui->btnAspect, SIGNAL(keepAspectRatioChanged(bool)), this, SLOT(aspectLockChanged(bool)));
56 connect(ui->cmbType, SIGNAL(currentIndexChanged(int)), this, SIGNAL(sigConfigurationItemChanged()));
57 connect(ui->cmbChannel, SIGNAL(currentIndexChanged(int)), this, SIGNAL(sigConfigurationItemChanged()));
58 connect(ui->cmbRed, SIGNAL(currentIndexChanged(int)), this, SIGNAL(sigConfigurationItemChanged()));
59 connect(ui->cmbGreen, SIGNAL(currentIndexChanged(int)), this, SIGNAL(sigConfigurationItemChanged()));
60 connect(ui->cmbBlue, SIGNAL(currentIndexChanged(int)), this, SIGNAL(sigConfigurationItemChanged()));
61
62}
63
68
70{
72 if (m_cs->channelCount() < 3) return config;
73
74 config->setProperty("horizRadius", ui->sldHorizontalRadius->value());
75 config->setProperty("vertRadius", ui->sldVerticalRadius->value());
76 config->setProperty("type", m_types.at(ui->cmbType->currentIndex()));
77 config->setProperty("lockAspect", ui->btnAspect->keepAspectRatio());
78 config->setProperty("channelToConvert", ui->cmbChannel->currentIndex());
79 config->setProperty("redSwizzle", ui->cmbRed->currentIndex());
80 config->setProperty("greenSwizzle", ui->cmbGreen->currentIndex());
81 config->setProperty("blueSwizzle", ui->cmbBlue->currentIndex());
82
83 return config;
84}
85
87{
88 if (m_cs->channelCount() < 3) return;
89
90 ui->sldHorizontalRadius->setValue(config->getFloat("horizRadius", 1.0));
91 ui->sldVerticalRadius->setValue(config->getFloat("vertRadius", 1.0));
92 int index = 0;
93 if (m_types.contains(config->getString("type", "prewitt"))){
94 index = m_types.indexOf(config->getString("type", "sobol"));
95 }
96 ui->cmbType->setCurrentIndex(index);
97 ui->cmbChannel->setCurrentIndex(config->getInt("channelToConvert", 0));
98 ui->btnAspect->setKeepAspectRatio(config->getBool("lockAspect", false));
99 ui->cmbRed->setCurrentIndex(config->getInt("redSwizzle", xPlus));
100 ui->cmbGreen->setCurrentIndex(config->getInt("greenSwizzle", yPlus));
101 ui->cmbBlue->setCurrentIndex(config->getInt("blueSwizzle", zPlus));
102}
103
105{
106 ui->sldHorizontalRadius->blockSignals(true);
107 ui->sldHorizontalRadius->setValue(r);
108 ui->sldHorizontalRadius->blockSignals(false);
109
110 if (ui->btnAspect->keepAspectRatio()) {
111 ui->sldVerticalRadius->blockSignals(true);
112 ui->sldVerticalRadius->setValue(r);
113 ui->sldVerticalRadius->blockSignals(false);
114 }
115}
116
118{
119 ui->sldVerticalRadius->blockSignals(true);
120 ui->sldVerticalRadius->setValue(r);
121 ui->sldVerticalRadius->blockSignals(false);
122
123 if (ui->btnAspect->keepAspectRatio()) {
124 ui->sldHorizontalRadius->blockSignals(true);
125 ui->sldHorizontalRadius->setValue(r);
126 ui->sldHorizontalRadius->blockSignals(false);
127 }
128}
129
131{
132 if (v) {
133 ui->sldVerticalRadius->setValue( ui->sldHorizontalRadius->value() );
134 }
135}
qreal v
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void sigConfigurationItemChanged()
static KisResourcesInterfaceSP instance()
void setConfiguration(const KisPropertiesConfigurationSP config) override
KisWdgConvertHeightToNormalMap(QWidget *parent, const KoColorSpace *cs)
KisPropertiesConfigurationSP configuration() const override
QList< KoChannelInfo * > channels
virtual quint32 channelCount() const =0