File indexing completed on 2024-12-22 04:15:18
0001 /* 0002 * SPDX-FileCopyrightText: 2009 Cyrille Berger <cberger@cberger.net> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "DodgeBurn.h" 0008 #include <filter/kis_filter_category_ids.h> 0009 #include <filter/kis_color_transformation_configuration.h> 0010 #include <kis_paint_device.h> 0011 #include <KisGlobalResourcesInterface.h> 0012 0013 #include "ui_DodgeBurnConfigurationBaseWidget.h" 0014 0015 KisFilterDodgeBurn::KisFilterDodgeBurn(const QString& id, const QString& prefix, const QString& name ) : KisColorTransformationFilter(KoID(id, name), FiltersCategoryAdjustId, name), m_prefix(prefix) 0016 { 0017 setColorSpaceIndependence(FULLY_INDEPENDENT); 0018 setSupportsPainting(true); 0019 } 0020 0021 KisConfigWidget * KisFilterDodgeBurn::createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP dev, bool) const 0022 { 0023 Q_UNUSED(dev); 0024 return new KisDodgeBurnConfigWidget(parent, id()); 0025 } 0026 0027 KisFilterConfigurationSP KisFilterDodgeBurn::defaultConfiguration(KisResourcesInterfaceSP resourcesInterface) const 0028 { 0029 KisFilterConfigurationSP config = factoryConfiguration(resourcesInterface); 0030 config->setProperty("exposure", 0.5); 0031 config->setProperty("type", KisFilterDodgeBurn::MIDTONES); 0032 return config; 0033 } 0034 0035 KoColorTransformation* KisFilterDodgeBurn::createTransformation(const KoColorSpace* cs, const KisFilterConfigurationSP config) const 0036 { 0037 QHash<QString, QVariant> params; 0038 QString suffix = "Midtones"; 0039 if (config) { 0040 params["exposure"] = config->getDouble("exposure", 0.5); 0041 int type = config->getInt("type", KisFilterDodgeBurn::MIDTONES); 0042 switch(type) 0043 { 0044 case KisFilterDodgeBurn::HIGHLIGHTS: 0045 suffix = "Highlights"; 0046 break; 0047 case KisFilterDodgeBurn::SHADOWS: 0048 suffix = "Shadows"; 0049 break; 0050 default: 0051 break; 0052 } 0053 } 0054 return cs->createColorTransformation(m_prefix + suffix, params); 0055 0056 } 0057 0058 KisDodgeBurnConfigWidget::KisDodgeBurnConfigWidget(QWidget * parent, const QString& id) : KisConfigWidget(parent), m_id(id) 0059 { 0060 m_page = new Ui_DodgeBurnConfigurationBaseWidget(); 0061 m_page->setupUi(this); 0062 0063 connect(m_page->radioButtonHighlights, SIGNAL(toggled(bool)), SIGNAL(sigConfigurationItemChanged())); 0064 connect(m_page->radioButtonMidtones, SIGNAL(toggled(bool)), SIGNAL(sigConfigurationItemChanged())); 0065 connect(m_page->radioButtonShadows, SIGNAL(toggled(bool)), SIGNAL(sigConfigurationItemChanged())); 0066 connect(m_page->sliderExposure, SIGNAL(valueChanged(int)), SIGNAL(sigConfigurationItemChanged())); 0067 } 0068 0069 KisDodgeBurnConfigWidget::~KisDodgeBurnConfigWidget() 0070 { 0071 delete m_page; 0072 } 0073 0074 KisPropertiesConfigurationSP KisDodgeBurnConfigWidget::configuration() const 0075 { 0076 KisColorTransformationConfigurationSP c = new KisColorTransformationConfiguration(m_id, 0, KisGlobalResourcesInterface::instance()); 0077 int type = 0; 0078 if(m_page->radioButtonHighlights->isChecked()) 0079 { 0080 type = KisFilterDodgeBurn::HIGHLIGHTS; 0081 } else if(m_page->radioButtonShadows->isChecked()) 0082 { 0083 type = KisFilterDodgeBurn::SHADOWS; 0084 } else { 0085 type = KisFilterDodgeBurn::MIDTONES; 0086 } 0087 c->setProperty("type", type); 0088 c->setProperty("exposure", m_page->sliderExposure->value() / 100.0); 0089 return c; 0090 } 0091 0092 void KisDodgeBurnConfigWidget::setConfiguration(const KisPropertiesConfigurationSP config) 0093 { 0094 int type = config->getInt("type", KisFilterDodgeBurn::MIDTONES); 0095 switch(type) 0096 { 0097 case KisFilterDodgeBurn::HIGHLIGHTS: 0098 m_page->radioButtonHighlights->setChecked(true); 0099 break; 0100 case KisFilterDodgeBurn::SHADOWS: 0101 m_page->radioButtonShadows->setChecked(true); 0102 break; 0103 default: 0104 case KisFilterDodgeBurn::MIDTONES: 0105 m_page->radioButtonMidtones->setChecked(true); 0106 break; 0107 } 0108 m_page->sliderExposure->setValue(config->getDouble("exposure", 0.5) * 100); 0109 } 0110