File indexing completed on 2024-12-22 04:15:31
0001 /* 0002 * KDE. Krita Project. 0003 * 0004 * SPDX-FileCopyrightText: 2020 Deif Lou <ginoba@gmail.com> 0005 * SPDX-FileCopyrightText: 2021 L. E. Segovia <amy@amyspark.me> 0006 * 0007 * SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #include <kpluginfactory.h> 0011 #include <KoUpdater.h> 0012 #include <kis_processing_information.h> 0013 #include <filter/kis_filter_configuration.h> 0014 #include <kis_gradient_painter.h> 0015 #include "KoCompositeOpRegistry.h" 0016 0017 #include "KisGradientGenerator.h" 0018 #include "KisGradientGeneratorConfigWidget.h" 0019 0020 KisGradientGenerator::KisGradientGenerator() : KisGenerator(id(), KoID("basic"), i18n("&Gradient...")) 0021 { 0022 setSupportsPainting(true); 0023 } 0024 0025 void KisGradientGenerator::generate(KisProcessingInformation dst, 0026 const QSize &size, 0027 const KisFilterConfigurationSP config, 0028 KoUpdater *progressUpdater) const 0029 { 0030 KisPaintDeviceSP device = dst.paintDevice(); 0031 Q_ASSERT(!device.isNull()); 0032 0033 KIS_SAFE_ASSERT_RECOVER_RETURN(config); 0034 const KisGradientGeneratorConfiguration *generatorConfiguration = 0035 dynamic_cast<const KisGradientGeneratorConfiguration*>(config.data()); 0036 KIS_SAFE_ASSERT_RECOVER_RETURN(generatorConfiguration); 0037 0038 0039 QSize imageSize = device->defaultBounds()->imageBorderRect().size(); 0040 QPair<QPointF, QPointF> positions = 0041 generatorConfiguration->absoluteCartesianPositionsInPixels(imageSize.width(), imageSize.height()); 0042 0043 KisGradientPainter painter(device); 0044 painter.setCompositeOpId(COMPOSITE_COPY); 0045 painter.setProgress(progressUpdater); 0046 painter.setGradientShape(generatorConfiguration->shape()); 0047 painter.setGradient(generatorConfiguration->gradient()); 0048 painter.paintGradient( 0049 positions.first, 0050 positions.second, 0051 generatorConfiguration->repeat(), 0052 generatorConfiguration->antiAliasThreshold(), 0053 generatorConfiguration->reverse(), 0054 QRect(dst.topLeft(), size), 0055 generatorConfiguration->dither() 0056 ); 0057 } 0058 0059 KisFilterConfigurationSP KisGradientGenerator::factoryConfiguration(KisResourcesInterfaceSP resourcesInterface) const 0060 { 0061 return new KisGradientGeneratorConfiguration(resourcesInterface); 0062 } 0063 0064 KisFilterConfigurationSP KisGradientGenerator::defaultConfiguration(KisResourcesInterfaceSP resourcesInterface) const 0065 { 0066 KisGradientGeneratorConfiguration *config = new KisGradientGeneratorConfiguration(resourcesInterface); 0067 config->setDefaults(); 0068 return config; 0069 } 0070 0071 KisConfigWidget* KisGradientGenerator::createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP dev, bool) const 0072 { 0073 Q_UNUSED(dev); 0074 return new KisGradientGeneratorConfigWidget(parent); 0075 }