diff --git a/plugins/filters/colorsfilters/kis_hsv_adjustment_filter.cpp b/plugins/filters/colorsfilters/kis_hsv_adjustment_filter.cpp index d5584f6d8f..83d1c5b383 100644 --- a/plugins/filters/colorsfilters/kis_hsv_adjustment_filter.cpp +++ b/plugins/filters/colorsfilters/kis_hsv_adjustment_filter.cpp @@ -1,197 +1,190 @@ /* * Copyright (c) 2007 Cyrille Berger * * 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; version 2 * of the License. * * 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; 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 "kis_hsv_adjustment_filter.h" #include #include #include #include #include +namespace { +struct SliderConfig { + QString m_text; + int m_minimum; + int m_maximum; + + inline void apply(QSpinBox* spinBox, QSlider* slider, QLabel* label) const + { + label->setText(m_text); + slider->setMinimum(m_minimum); + slider->setMaximum(m_maximum); + spinBox->setMinimum(m_minimum); + spinBox->setMaximum(m_maximum); + + int sliderValue = slider->value(); + if (sliderValue < m_minimum || sliderValue > m_maximum) { + slider->setValue((m_minimum + m_maximum) / 2); + } + } + + inline double normalize(int value) const + { + return (double)value / (double)m_maximum; + } +}; + +struct WidgetSlidersConfig { + SliderConfig m_sliders[3]; +}; + +#define PERCENT_FIELD_REL(x) {x, -100, 100} +#define PERCENT_FIELD_ABS(x) {x, 0, 100} +#define DEGREES_FIELD_REL(x) {x, -180, 180} +#define DEGREES_FIELD_ABS(x) {x, 0, 360} +#define HSX_CONFIGS(x) { \ + { {DEGREES_FIELD_REL(i18n("Hue:")), PERCENT_FIELD_REL(i18n("Saturation:")), PERCENT_FIELD_REL(x)} }, \ + { {DEGREES_FIELD_ABS(i18n("Hue:")), PERCENT_FIELD_ABS(i18n("Saturation:")), PERCENT_FIELD_REL(x)} } \ +} + +const WidgetSlidersConfig WIDGET_CONFIGS[][2] = { + // Hue/Saturation/Value + HSX_CONFIGS(i18n("Value:")), + // Hue/Saturation/Lightness + HSX_CONFIGS(i18n("Lightness:")), + // Hue/Saturation/Intensity + HSX_CONFIGS(i18n("Intensity:")), + // Hue/Saturation/Luminosity + HSX_CONFIGS(i18n("Luma:")), + // Blue Chroma/Red Chroma/Luma + {{ {PERCENT_FIELD_REL(i18n("Yellow-Blue:")), PERCENT_FIELD_REL(i18n("Green-Red:")), PERCENT_FIELD_REL(i18n("Luma:"))} }, + { {PERCENT_FIELD_ABS(i18n("Yellow-Blue:")), PERCENT_FIELD_ABS(i18n("Green-Red:")), PERCENT_FIELD_REL(i18n("Luma:"))} }} +}; + +inline const WidgetSlidersConfig& getCurrentWidgetConfig(int type, bool colorize) { + return WIDGET_CONFIGS[type][colorize ? 1 : 0]; +} +} + KisHSVAdjustmentFilter::KisHSVAdjustmentFilter() : KisColorTransformationFilter(id(), categoryAdjust(), i18n("&HSV Adjustment...")) { setShortcut(QKeySequence(Qt::CTRL + Qt::Key_U)); setSupportsPainting(true); } KisConfigWidget * KisHSVAdjustmentFilter::createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP dev) const { Q_UNUSED(dev); return new KisHSVConfigWidget(parent); } KoColorTransformation* KisHSVAdjustmentFilter::createTransformation(const KoColorSpace* cs, const KisFilterConfiguration* config) const { QHash params; if (config) { - if (config->getBool("colorize")) { - params["h"] = config->getDouble("h", 0.5) / 360.0; - } - else { - params["h"] = config->getDouble("h", 0) / 180.0; + int type = config->getInt("type", 1); + bool colorize = config->getBool("colorize", false); + const WidgetSlidersConfig& widgetConfig = getCurrentWidgetConfig(type, colorize); - } - params["s"] = config->getInt("s", 0) * 0.01; - params["v"] = config->getInt("v", 0) * 0.01; + params["h"] = widgetConfig.m_sliders[0].normalize(config->getInt("h", 0)); + params["s"] = widgetConfig.m_sliders[1].normalize(config->getInt("s", 0)); + params["v"] = widgetConfig.m_sliders[2].normalize(config->getInt("v", 0)); - params["type"] = config->getInt("type", 1); - params["colorize"] = config->getBool("colorize", false); + params["type"] = type; + params["colorize"] = colorize; params["lumaRed"] = cs->lumaCoefficients()[0]; params["lumaGreen"] = cs->lumaCoefficients()[1]; params["lumaBlue"] = cs->lumaCoefficients()[2]; } return cs->createColorTransformation("hsv_adjustment", params); } KisFilterConfiguration* KisHSVAdjustmentFilter::factoryConfiguration(const KisPaintDeviceSP) const { KisColorTransformationConfiguration* config = new KisColorTransformationConfiguration(id().id(), 1); config->setProperty("h", 0); config->setProperty("s", 0); config->setProperty("v", 0); config->setProperty("type", 1); config->setProperty("colorize", false); return config; } KisHSVConfigWidget::KisHSVConfigWidget(QWidget * parent, Qt::WFlags f) : KisConfigWidget(parent, f) { m_page = new Ui_WdgHSVAdjustment(); m_page->setupUi(this); - m_page->hueSlider->setRange(-180, 180); - m_page->hueSlider->setValue(0); - m_page->hueSpinBox->setRange(-180, 180); - m_page->hueSpinBox->setValue(0); - - - m_page->saturationSlider->setRange(-100, 100); - m_page->saturationSlider->setValue(0); - m_page->saturationSpinBox->setRange(-100, 100); - m_page->saturationSpinBox->setValue(0); - - - - m_page->valueSlider->setRange(-100, 100); - m_page->valueSlider->setValue(0); - m_page->valueSpinBox->setRange(-100, 100); - m_page->valueSpinBox->setValue(0); - - connect(m_page->cmbType, SIGNAL(activated(int)), SLOT(switchType(int))); - connect(m_page->chkColorize, SIGNAL(toggled(bool)), SLOT(switchColorize(bool))); + connect(m_page->cmbType, SIGNAL(activated(int)), this, SLOT(configureSliderLimitsAndLabels())); + connect(m_page->chkColorize, SIGNAL(toggled(bool)), this, SLOT(configureSliderLimitsAndLabels())); // connect horizontal sliders connect(m_page->hueSlider, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged())); connect(m_page->saturationSlider, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged())); connect(m_page->valueSlider, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged())); connect(m_page->hueSpinBox, SIGNAL(valueChanged(int)), m_page->hueSlider, SLOT(setValue(int))); connect(m_page->saturationSpinBox, SIGNAL(valueChanged(int)), m_page->saturationSlider, SLOT(setValue(int))); connect(m_page->valueSpinBox, SIGNAL(valueChanged(int)), m_page->valueSlider, SLOT(setValue(int))); connect(m_page->hueSlider, SIGNAL(valueChanged(int)), m_page->hueSpinBox, SLOT(setValue(int))); connect(m_page->saturationSlider, SIGNAL(valueChanged(int)), m_page->saturationSpinBox, SLOT(setValue(int))); connect(m_page->valueSlider, SIGNAL(valueChanged(int)), m_page->valueSpinBox, SLOT(setValue(int))); } KisHSVConfigWidget::~KisHSVConfigWidget() { delete m_page; } KisPropertiesConfiguration * KisHSVConfigWidget::configuration() const { KisColorTransformationConfiguration* c = new KisColorTransformationConfiguration(KisHSVAdjustmentFilter::id().id(), 0); c->setProperty("h", m_page->hueSlider->value()); c->setProperty("s", m_page->saturationSlider->value()); c->setProperty("v", m_page->valueSlider->value()); c->setProperty("type", m_page->cmbType->currentIndex()); c->setProperty("colorize", m_page->chkColorize->isChecked()); return c; } void KisHSVConfigWidget::setConfiguration(const KisPropertiesConfiguration * config) { m_page->cmbType->setCurrentIndex(config->getInt("type", 1)); + m_page->chkColorize->setChecked(config->getBool("colorize", false)); m_page->hueSlider->setValue(config->getInt("h", 0)); m_page->saturationSlider->setValue(config->getInt("s", 0)); m_page->valueSlider->setValue(config->getInt("v", 0)); - m_page->chkColorize->setChecked(config->getBool("colorize", false)); - switchType(m_page->cmbType->currentIndex()); -} - -void KisHSVConfigWidget::switchType(int index) -{ - emit sigConfigurationItemChanged(); - m_page->label->setText(i18n("Hue:")); - m_page->label_2->setText(i18n("Saturation:")); - - switch(index) { - case 0: - m_page->label_3->setText(i18n("Value:")); - return; - case 1: - m_page->label_3->setText(i18n("Lightness:")); - return; - case 2: - m_page->label_3->setText(i18n("Intensity:")); - return; - case 3: - m_page->label_3->setText(i18n("Luma:")); - return; - case 4: - m_page->label->setText(i18n("Yellow-Blue:")); - m_page->label_2->setText(i18n("Green-Red:")); - m_page->label_3->setText(i18n("Luma:")); - m_page->hueSlider->setRange(-100, 100); - m_page->hueSlider->setValue(0); - default: - m_page->label_3->setText(i18n("Lightness:")); - } - - + configureSliderLimitsAndLabels(); } -void KisHSVConfigWidget::switchColorize(bool toggle) +void KisHSVConfigWidget::configureSliderLimitsAndLabels() { - if (toggle) { - m_page->hueSlider->setMinimum(0); - m_page->hueSlider->setMaximum(360); + const WidgetSlidersConfig& widget = getCurrentWidgetConfig(m_page->cmbType->currentIndex(), m_page->chkColorize->isChecked()); - m_page->saturationSlider->setMinimum(0); - m_page->saturationSlider->setMaximum(100); + widget.m_sliders[0].apply(m_page->hueSpinBox, m_page->hueSlider, m_page->label); + widget.m_sliders[1].apply(m_page->saturationSpinBox, m_page->saturationSlider, m_page->label_2); + widget.m_sliders[2].apply(m_page->valueSpinBox, m_page->valueSlider, m_page->label_3); - if (m_page->saturationSlider->value() < m_page->saturationSlider->minimum() || m_page->saturationSlider->value() > m_page->saturationSlider->maximum()) { - m_page->saturationSlider->setValue(50); - } - switchType(1); - } - else { - m_page->hueSlider->setMinimum(-180); - m_page->hueSlider->setMaximum(180); - m_page->saturationSlider->setMinimum(-100); - m_page->saturationSlider->setMaximum(100); - - } emit sigConfigurationItemChanged(); } diff --git a/plugins/filters/colorsfilters/kis_hsv_adjustment_filter.h b/plugins/filters/colorsfilters/kis_hsv_adjustment_filter.h index 63204599a6..7c38c3d65a 100644 --- a/plugins/filters/colorsfilters/kis_hsv_adjustment_filter.h +++ b/plugins/filters/colorsfilters/kis_hsv_adjustment_filter.h @@ -1,78 +1,77 @@ /* * Copyright (c) 2007 Cyrille Berger * * 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; version 2 * of the License. * * 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; 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 _KIS_HSV_ADJUSTMENT_FILTER_H_ #define _KIS_HSV_ADJUSTMENT_FILTER_H_ #include #include "filter/kis_filter.h" #include "kis_config_widget.h" #include "ui_wdg_hsv_adjustment.h" #include "filter/kis_color_transformation_filter.h" class QWidget; class KoColorTransformation; /** * This class affect Intensity Y of the image */ class KisHSVAdjustmentFilter : public KisColorTransformationFilter { public: KisHSVAdjustmentFilter(); public: virtual KisConfigWidget * createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP dev) const; virtual KoColorTransformation* createTransformation(const KoColorSpace* cs, const KisFilterConfiguration* config) const; static inline KoID id() { return KoID("hsvadjustment", i18n("HSV/HSL Adjustment")); } virtual KisFilterConfiguration* factoryConfiguration(const KisPaintDeviceSP) const; }; class KisHSVConfigWidget : public KisConfigWidget { Q_OBJECT public: KisHSVConfigWidget(QWidget * parent, Qt::WFlags f = 0); virtual ~KisHSVConfigWidget(); virtual KisPropertiesConfiguration * configuration() const; virtual void setConfiguration(const KisPropertiesConfiguration* config); Ui_WdgHSVAdjustment * m_page; private Q_SLOTS: - void switchType(int index); - void switchColorize(bool toggle); + void configureSliderLimitsAndLabels(); }; #endif