diff --git a/plugins/generators/pattern/kis_wdg_pattern.cpp b/plugins/generators/pattern/kis_wdg_pattern.cpp index 00d1b95c2e..88b5e3ea9e 100644 --- a/plugins/generators/pattern/kis_wdg_pattern.cpp +++ b/plugins/generators/pattern/kis_wdg_pattern.cpp @@ -1,77 +1,162 @@ /* * This file is part of Krita * * Copyright (c) 2006 Cyrille Berger * * 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_pattern.h" #include #include #include #include #include #include #include #include #include #include "ui_wdgpatternoptions.h" KisWdgPattern::KisWdgPattern(QWidget* parent) : KisConfigWidget(parent) { m_widget = new Ui_WdgPatternOptions(); m_widget->setupUi(this); m_widget->lblPattern->setVisible(false); m_widget->lblColor->setVisible(false); m_widget->bnColor->setVisible(false); + + m_widget->sldShearX->setSuffix(i18n(" px")); + m_widget->sldShearY->setSuffix(i18n(" px")); + m_widget->sldShearX->setRange(-5.0, 5.0, 2); + m_widget->sldShearY->setRange(-5.0, 5.0, 2); + m_widget->sldShearX->setSingleStep(0.01); + m_widget->sldShearY->setSingleStep(0.01); + m_widget->sldShearX->setValue(0.0); + m_widget->sldShearY->setValue(0.0); + + + m_widget->spbOffsetX->setSuffix(i18n(" px")); + m_widget->spbOffsetY->setSuffix(i18n(" px")); + m_widget->spbOffsetX->setRange(-10000, 10000); + m_widget->spbOffsetY->setRange(-10000, 10000); + + m_widget->sldRotationX->setSuffix(QChar(Qt::Key_degree)); + m_widget->sldRotationY->setSuffix(QChar(Qt::Key_degree)); + m_widget->sldRotationZ->setSuffix(QChar(Qt::Key_degree)); + m_widget->sldRotationX->setRange(0.0, 360.0, 2); + m_widget->sldRotationY->setRange(0.0, 360.0, 2); + m_widget->sldRotationZ->setRange(0.0, 360.0, 2); + m_widget->sldRotationX->setValue(0.0); + m_widget->sldRotationY->setValue(0.0); + m_widget->sldRotationZ->setValue(0.0); + m_widget->sldRotationX->setSingleStep(1.0); + m_widget->sldRotationY->setSingleStep(1.0); + m_widget->sldRotationZ->setSingleStep(1.0); connect(m_widget->patternChooser, SIGNAL(resourceSelected(KoResourceSP)), this, SIGNAL(sigConfigurationUpdated())); - connect(m_widget->sldRotation, SIGNAL(valueChanged(int)), this, SIGNAL(sigConfigurationUpdated())); + + connect(m_widget->sldShearX, SIGNAL(valueChanged(double)), this, SIGNAL(sigConfigurationUpdated())); + connect(m_widget->sldShearY, SIGNAL(valueChanged(double)), this, SIGNAL(sigConfigurationUpdated())); + + connect(m_widget->spbOffsetX, SIGNAL(valueChanged(int)), this, SIGNAL(sigConfigurationUpdated())); + connect(m_widget->spbOffsetY, SIGNAL(valueChanged(int)), this, SIGNAL(sigConfigurationUpdated())); + + connect(m_widget->spbScaleWidth, SIGNAL(valueChanged(double)), this, SLOT(slotWidthChanged(double))); + connect(m_widget->spbScaleHeight, SIGNAL(valueChanged(double)), this, SLOT(slotHeightChanged(double))); + + connect(m_widget->sldRotationX, SIGNAL(valueChanged(double)), this, SIGNAL(sigConfigurationUpdated())); + connect(m_widget->sldRotationY, SIGNAL(valueChanged(double)), this, SIGNAL(sigConfigurationUpdated())); + connect(m_widget->sldRotationZ, SIGNAL(valueChanged(double)), this, SIGNAL(sigConfigurationUpdated())); } KisWdgPattern::~KisWdgPattern() { delete m_widget; } void KisWdgPattern::setConfiguration(const KisPropertiesConfigurationSP config) { auto source = KisGlobalResourcesInterface::instance()->source(ResourceType::Patterns); KoPatternSP pattern = source.resourceForName(config->getString("pattern", "Grid01.pat")); widget()->patternChooser->setCurrentPattern(pattern ? pattern : source.fallbackResource()); - int rotation = config->getProperty("transform").toInt(); - widget()->sldRotation->setValue(rotation); + m_widget->spbOffsetX->setValue(config->getInt("transform_offset_x", 0)); + m_widget->spbOffsetY->setValue(config->getInt("transform_offset_y", 0)); + + m_widget->spbScaleWidth->setValue(config->getInt("transform_scale_x", 1.0)*100); + m_widget->spbScaleHeight->setValue(config->getInt("transform_scale_y", 1.0)*100); + m_widget->btnLockAspectRatio->setKeepAspectRatio(config->getBool("transform_keep_scale_aspect", true)); + + m_widget->sldShearX->setValue(config->getDouble("transform_shear_x", 0.0)); + m_widget->sldShearY->setValue(config->getDouble("transform_shear_y", 0.0)); + + widget()->sldRotationX->setValue(config->getDouble("transform_rotation_x", 0.0)); + widget()->sldRotationY->setValue(config->getDouble("transform_rotation_y", 0.0)); + widget()->sldRotationZ->setValue(config->getDouble("transform_rotation_z", 0.0)); } KisPropertiesConfigurationSP KisWdgPattern::configuration() const { KisGeneratorSP generator = KisGeneratorRegistry::instance()->get("pattern"); KisFilterConfigurationSP config = generator->factoryConfiguration(KisGlobalResourcesInterface::instance()); QVariant v; if (widget()->patternChooser->currentResource()) { v.setValue(widget()->patternChooser->currentResource()->name()); config->setProperty("pattern", v); } - config->setProperty("transform", widget()->sldRotation->value()); + + config->setProperty("transform_offset_x", m_widget->spbOffsetX->value()); + config->setProperty("transform_offset_y", m_widget->spbOffsetY->value()); + + config->setProperty("transform_scale_x", m_widget->spbScaleWidth->value()/100); + config->setProperty("transform_scale_y", m_widget->spbScaleHeight->value()/100); + + config->setProperty("transform_keep_scale_aspect", m_widget->btnLockAspectRatio->keepAspectRatio()); + + config->setProperty("transform_shear_x", widget()->sldShearX->value()); + config->setProperty("transform_shear_y", widget()->sldShearY->value()); + + config->setProperty("transform_rotation_x", widget()->sldRotationX->value()); + config->setProperty("transform_rotation_y", widget()->sldRotationY->value()); + config->setProperty("transform_rotation_z", widget()->sldRotationZ->value()); return config; } +void KisWdgPattern::slotWidthChanged(double w) +{ + if (m_widget->btnLockAspectRatio->keepAspectRatio()) { + m_widget->spbScaleHeight->blockSignals(true); + m_widget->spbScaleHeight->setValue(w); + m_widget->spbScaleHeight->blockSignals(false); + } + emit sigConfigurationUpdated(); +} + +void KisWdgPattern::slotHeightChanged(double h) +{ + if (m_widget->btnLockAspectRatio->keepAspectRatio()) { + m_widget->spbScaleWidth->blockSignals(true); + m_widget->spbScaleWidth->setValue(h); + m_widget->spbScaleWidth->blockSignals(false); + } + emit sigConfigurationUpdated(); +} + diff --git a/plugins/generators/pattern/kis_wdg_pattern.h b/plugins/generators/pattern/kis_wdg_pattern.h index 771186fd6f..442c69af01 100644 --- a/plugins/generators/pattern/kis_wdg_pattern.h +++ b/plugins/generators/pattern/kis_wdg_pattern.h @@ -1,45 +1,49 @@ /* * This file is part of Krita * * Copyright (c) 2006 Cyrille Berger * * 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_PATTERN_H #define KIS_WDG_PATTERN_H #include class Ui_WdgPatternOptions; class KisWdgPattern : public KisConfigWidget { Q_OBJECT public: KisWdgPattern(QWidget* parent = 0); ~KisWdgPattern() override; public: inline const Ui_WdgPatternOptions* widget() const { return m_widget; } void setConfiguration(const KisPropertiesConfigurationSP) override; KisPropertiesConfigurationSP configuration() const override; +private Q_SLOTS: + + void slotWidthChanged(double w); + void slotHeightChanged(double h); private: Ui_WdgPatternOptions* m_widget; }; #endif diff --git a/plugins/generators/pattern/patterngenerator.cpp b/plugins/generators/pattern/patterngenerator.cpp index 77dff8dac6..8c1dc72207 100644 --- a/plugins/generators/pattern/patterngenerator.cpp +++ b/plugins/generators/pattern/patterngenerator.cpp @@ -1,179 +1,201 @@ /* * This file is part of the KDE project * * Copyright (c) 2008 Boudewijn Rempt * * 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 "patterngenerator.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kis_wdg_pattern.h" #include "ui_wdgpatternoptions.h" K_PLUGIN_FACTORY_WITH_JSON(KritaPatternGeneratorFactory, "kritapatterngenerator.json", registerPlugin();) KritaPatternGenerator::KritaPatternGenerator(QObject *parent, const QVariantList &) : QObject(parent) { KisGeneratorRegistry::instance()->add(new KoPatternGenerator()); } KritaPatternGenerator::~KritaPatternGenerator() { } /****************************************************************************/ /* KoPatternGeneratorConfiguration */ /****************************************************************************/ class KoPatternGeneratorConfiguration : public KisFilterConfiguration { public: KoPatternGeneratorConfiguration(const QString & name, qint32 version, KisResourcesInterfaceSP resourcesInterface) : KisFilterConfiguration(name, version, resourcesInterface) { } KoPatternGeneratorConfiguration(const KoPatternGeneratorConfiguration &rhs) : KisFilterConfiguration(rhs) { } virtual KisFilterConfigurationSP clone() const override { return new KoPatternGeneratorConfiguration(*this); } KoPatternSP pattern(KisResourcesInterfaceSP resourcesInterface) const { const QString patternName = this->getString("pattern", "Grid01.pat"); auto source = resourcesInterface->source(ResourceType::Patterns); return source.resourceForName(patternName); } KoPatternSP pattern() const { return pattern(resourcesInterface()); } QTransform transform() const { - int rotation = this->getProperty("transform").toInt(); QTransform transform; - transform.rotate(rotation); + + transform.shear(this->getDouble("transform_shear_x", 0.0), this->getDouble("transform_shear_y", 0.0)); + + transform.scale(this->getDouble("transform_scale_x", 1.0), this->getDouble("transform_scale_y", 1.0)); + transform.rotate(this->getDouble("transform_rotation_x", 0.0), Qt::XAxis); + transform.rotate(this->getDouble("transform_rotation_y", 0.0), Qt::YAxis); + transform.rotate(this->getDouble("transform_rotation_z", 0.0), Qt::ZAxis); + + transform.translate(this->getInt("transform_offset_x", 0), this->getInt("transform_offset_y", 0)); return transform; } QList linkedResources(KisResourcesInterfaceSP globalResourcesInterface) const override { KoPatternSP pattern = this->pattern(globalResourcesInterface); QList resources; if (pattern) { resources << pattern; } return resources; } }; /****************************************************************************/ /* KoPatternGenerator */ /****************************************************************************/ KoPatternGenerator::KoPatternGenerator() : KisGenerator(id(), KoID("basic"), i18n("&Pattern...")) { setColorSpaceIndependence(FULLY_INDEPENDENT); setSupportsPainting(true); } KisFilterConfigurationSP KoPatternGenerator::factoryConfiguration(KisResourcesInterfaceSP resourcesInterface) const { return new KoPatternGeneratorConfiguration(id().id(), 1, resourcesInterface); } KisFilterConfigurationSP KoPatternGenerator::defaultConfiguration(KisResourcesInterfaceSP resourcesInterface) const { KisFilterConfigurationSP config = factoryConfiguration(resourcesInterface); auto source = resourcesInterface->source(ResourceType::Patterns); config->setProperty("pattern", QVariant::fromValue(source.fallbackResource()->name())); - config->setProperty("transform", QVariant::fromValue(0)); + + + config->setProperty("transform_shear_x", QVariant::fromValue(0.0)); + config->setProperty("transform_shear_y", QVariant::fromValue(0.0)); + + config->setProperty("transform_scale_x", QVariant::fromValue(1.0)); + config->setProperty("transform_scale_y", QVariant::fromValue(1.0)); + + config->setProperty("transform_rotation_x", QVariant::fromValue(0.0)); + config->setProperty("transform_rotation_y", QVariant::fromValue(0.0)); + config->setProperty("transform_rotation_z", QVariant::fromValue(0.0)); + + config->setProperty("transform_offset_x", QVariant::fromValue(0)); + config->setProperty("transform_offset_y", QVariant::fromValue(0)); + + config->setProperty("transform_keep_scale_aspect", QVariant::fromValue(true)); return config; } KisConfigWidget * KoPatternGenerator::createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP dev, bool) const { Q_UNUSED(dev); return new KisWdgPattern(parent); } void KoPatternGenerator::generate(KisProcessingInformation dstInfo, const QSize& size, const KisFilterConfigurationSP _config, KoUpdater* progressUpdater) const { KisPaintDeviceSP dst = dstInfo.paintDevice(); Q_ASSERT(!dst.isNull()); const KoPatternGeneratorConfiguration *config = dynamic_cast(_config.data()); KIS_SAFE_ASSERT_RECOVER_RETURN(config); KoPatternSP pattern = config->pattern(); QTransform transform = config->transform(); KisFillPainter gc(dst); gc.setPattern(pattern); gc.setProgress(progressUpdater); gc.setChannelFlags(config->channelFlags()); gc.setOpacity(OPACITY_OPAQUE_U8); gc.setSelection(dstInfo.selection()); gc.setWidth(size.width()); gc.setHeight(size.height()); gc.setFillStyle(KisFillPainter::FillStylePattern); gc.fillRect(QRect(dstInfo.topLeft(), size), pattern, transform); gc.end(); } #include "patterngenerator.moc" diff --git a/plugins/generators/pattern/wdgpatternoptions.ui b/plugins/generators/pattern/wdgpatternoptions.ui index bc1c9763fa..b847dee948 100644 --- a/plugins/generators/pattern/wdgpatternoptions.ui +++ b/plugins/generators/pattern/wdgpatternoptions.ui @@ -1,103 +1,304 @@ WdgPatternOptions 0 0 - 158 - 78 + 484 + 477 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - 0 - 0 - - - - - - - - &Pattern: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - patternChooser - - - - - - - &Color: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - bnColor - - - - - - - - - - Rotation: - - - - - - - 360 - - - Qt::Horizontal - - - - + + + + + 0 + + + + Pattern + + + + + + &Pattern: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + patternChooser + + + + + + + + 0 + 0 + + + + + + + + &Color: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + bnColor + + + + + + + + + + + Transform + + + + + + 3d Rotation: + + + + + + X-Rotation: + + + + + + + Y-Rotation: + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + + + + + + + + Scale: + + + + + + Width: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + % + + + 1 + + + 500.000000000000000 + + + 100.000000000000000 + + + + + + + + + + Height: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + % + + + 1 + + + 500.000000000000000 + + + 100.000000000000000 + + + + + + + + + + Offset: + + + + + + X: + + + + + + + Y: + + + + + + + + + + + + + + + + Shear: + + + + + + X: + + + + + + + Y: + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + + + + + + + + Rotation: + + + + + + + + + + + KisColorButton QPushButton
kis_color_button.h
KisPatternChooser QWidget
kis_pattern_chooser.h
1
+ + KoAspectButton + QWidget +
KoAspectButton.h
+ 1 +
+ + KisDoubleParseSpinBox + QDoubleSpinBox +
kis_double_parse_spin_box.h
+
+ + KisDoubleSliderSpinBox + QWidget +
kis_slider_spin_box.h
+ 1 +
+ + KisIntParseSpinBox + QSpinBox +
kis_int_parse_spin_box.h
+