File indexing completed on 2024-12-22 04:15:32
0001 /* 0002 * This file is part of Krita 0003 * 0004 * SPDX-FileCopyrightText: 2020 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "kis_wdg_multigrid_pattern.h" 0010 0011 #include <QLayout> 0012 #include <QDomDocument> 0013 #include <QDomElement> 0014 0015 #include <KoColor.h> 0016 #include <filter/kis_filter_configuration.h> 0017 #include <KisGlobalResourcesInterface.h> 0018 0019 #include "ui_wdgmultigridpatternoptions.h" 0020 0021 KisWdgMultigridPattern::KisWdgMultigridPattern(QWidget* parent, const KoColorSpace *cs) 0022 : KisConfigWidget(parent) 0023 { 0024 m_widget = new Ui_WdgMultigridPatternOptions(); 0025 m_widget->setupUi(this); 0026 m_cs = cs; 0027 0028 QLinearGradient grad; 0029 grad.setColorAt(0, Qt::green); 0030 grad.setColorAt(1.0, Qt::blue); 0031 m_gradient = KoStopGradient::fromQGradient(&grad); 0032 widget()->wdgGradient->setGradient(m_gradient); 0033 widget()->wdgGradient->setCompactMode(true); 0034 0035 widget()->sldDivisions->setRange(0, 100); 0036 widget()->sldDivisions->setPrefix(i18n("Divisions:")); 0037 0038 widget()->sldDimensions->setRange(3, 36); 0039 widget()->sldDimensions->setPrefix(i18nc("The Dimensions of Multigrid pattern generator", "Dimensions:")); 0040 0041 widget()->sldOffset->setRange(0.01, 0.49, 2); 0042 widget()->sldOffset->setPrefix(i18n("Offset:")); 0043 0044 widget()->sldColorRatio->setRange(-2.0, 2.0, 2); 0045 widget()->sldColorRatio->setPrefix(i18nc("Ratio as in fill layer options", "Ratio:")); 0046 0047 widget()->sldColorIndex->setRange(-2.0, 2.0, 2); 0048 widget()->sldColorIndex->setPrefix(i18nc("Index number of how far away from center", "Index:")); 0049 0050 widget()->sldColorIntersect->setRange(-2.0, 2.0, 2); 0051 widget()->sldColorIntersect->setPrefix(i18n("Intersect:")); 0052 0053 widget()->cmbConnectorType->addItem(i18n("No Connectors")); 0054 widget()->cmbConnectorType->addItem(i18n("Acute Angles")); 0055 widget()->cmbConnectorType->addItem(i18n("Obtuse Angles")); 0056 widget()->cmbConnectorType->addItem(i18n("Cross Shape")); 0057 widget()->cmbConnectorType->addItem(i18n("Center Dot")); 0058 widget()->cmbConnectorType->addItem(i18n("Corner Dot")); 0059 0060 connect(m_widget->sldDivisions, SIGNAL(valueChanged(int)), this, SIGNAL(sigConfigurationUpdated())); 0061 connect(m_widget->sldDimensions, SIGNAL(valueChanged(int)), this, SIGNAL(sigConfigurationUpdated())); 0062 connect(m_widget->sldOffset, SIGNAL(valueChanged(qreal)), this, SIGNAL(sigConfigurationUpdated())); 0063 0064 connect(m_widget->sldColorIndex, SIGNAL(valueChanged(qreal)), this, SIGNAL(sigConfigurationUpdated())); 0065 connect(m_widget->sldColorRatio, SIGNAL(valueChanged(qreal)), this, SIGNAL(sigConfigurationUpdated())); 0066 connect(m_widget->sldColorIntersect, SIGNAL(valueChanged(qreal)), this, SIGNAL(sigConfigurationUpdated())); 0067 0068 connect(m_widget->wdgGradient, SIGNAL(sigGradientChanged()), this, SIGNAL(sigConfigurationUpdated())); 0069 0070 connect(m_widget->spnLineWidth, SIGNAL(valueChanged(int)), this, SIGNAL(sigConfigurationUpdated())); 0071 connect(m_widget->bnLineColor, SIGNAL(changed(const KoColor&)), this, SIGNAL(sigConfigurationUpdated())); 0072 0073 connect(m_widget->spnConnectorWidth, SIGNAL(valueChanged(int)), this, SIGNAL(sigConfigurationUpdated())); 0074 connect(m_widget->bnConnectorColor, SIGNAL(changed(const KoColor&)), this, SIGNAL(sigConfigurationUpdated())); 0075 connect(m_widget->cmbConnectorType, SIGNAL(currentIndexChanged(int)), this, SIGNAL(sigConfigurationUpdated())); 0076 } 0077 0078 KisWdgMultigridPattern::~KisWdgMultigridPattern() 0079 { 0080 delete m_widget; 0081 } 0082 0083 0084 void KisWdgMultigridPattern::setConfiguration(const KisPropertiesConfigurationSP config) 0085 { 0086 if (config->hasProperty("gradientXML")) { 0087 QDomDocument doc; 0088 doc.setContent(config->getString("gradientXML", "")); 0089 KoStopGradient gradient = KoStopGradient::fromXML(doc.firstChildElement()); 0090 if (gradient.stops().size() > 0) { 0091 m_gradient->setStops(gradient.stops()); 0092 } 0093 widget()->wdgGradient->setGradient(m_gradient); 0094 } 0095 0096 0097 KoColor c = config->getColor("lineColor"); 0098 c.convertTo(m_cs); 0099 widget()->bnLineColor->setColor(c); 0100 0101 widget()->spnLineWidth->setValue(config->getInt("lineWidth", 1)); 0102 0103 widget()->sldDivisions->setValue(config->getInt("divisions", 1)); 0104 0105 widget()->sldDimensions->setValue(config->getInt("dimensions", 5)); 0106 widget()->sldOffset->setValue(config->getFloat("offset", 0.2)); 0107 0108 widget()->sldColorIndex->setValue(config->getFloat("colorIndex", 1.0)); 0109 widget()->sldColorRatio->setValue(config->getFloat("colorRatio", 0.0)); 0110 widget()->sldColorIntersect->setValue(config->getFloat("colorIntersect", 0.0)); 0111 0112 c = config->getColor("connectorColor"); 0113 c.convertTo(m_cs); 0114 widget()->bnConnectorColor->setColor(c); 0115 widget()->cmbConnectorType->setCurrentIndex(config->getInt("connectorType", 1)); 0116 widget()->spnConnectorWidth->setValue(config->getInt("connectorWidth", 1)); 0117 } 0118 0119 KisPropertiesConfigurationSP KisWdgMultigridPattern::configuration() const 0120 { 0121 KisFilterConfigurationSP config = new KisFilterConfiguration("multigrid", 1, KisGlobalResourcesInterface::instance()); 0122 0123 if (m_gradient) { 0124 QDomDocument doc; 0125 QDomElement elt = doc.createElement("gradient"); 0126 m_gradient->toXML(doc, elt); 0127 doc.appendChild(elt); 0128 config->setProperty("gradientXML", doc.toString()); 0129 } 0130 0131 QVariant v; 0132 KoColor c; 0133 c.fromKoColor(widget()->bnLineColor->color()); 0134 v.setValue(c); 0135 config->setProperty("lineColor", v); 0136 config->setProperty("lineWidth", widget()->spnLineWidth->value()); 0137 0138 config->setProperty("divisions", widget()->sldDivisions->value()); 0139 0140 config->setProperty("dimensions", widget()->sldDimensions->value()); 0141 config->setProperty("offset", widget()->sldOffset->value()); 0142 0143 config->setProperty("colorRatio", widget()->sldColorRatio->value()); 0144 config->setProperty("colorIndex", widget()->sldColorIndex->value()); 0145 config->setProperty("colorIntersect", widget()->sldColorIntersect->value()); 0146 0147 c.fromKoColor(widget()->bnConnectorColor->color()); 0148 v.setValue(c); 0149 config->setProperty("connectorColor", v); 0150 config->setProperty("connectorType", widget()->cmbConnectorType->currentIndex()); 0151 config->setProperty("connectorWidth", widget()->spnConnectorWidth->value()); 0152 0153 return config; 0154 } 0155 0156