File indexing completed on 2024-12-22 04:15:37
0001 /* 0002 * This file is part of the KDE project 0003 * 0004 * SPDX-FileCopyrightText: 2008 Boudewijn Rempt <boud@valdyas.org> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "colorgenerator.h" 0010 0011 #include <QPoint> 0012 0013 #include <kis_debug.h> 0014 0015 #include <kpluginfactory.h> 0016 #include <klocalizedstring.h> 0017 0018 #include <kis_fill_painter.h> 0019 #include <kis_image.h> 0020 #include <kis_paint_device.h> 0021 #include <kis_layer.h> 0022 #include <generator/kis_generator_registry.h> 0023 #include <kis_global.h> 0024 #include <kis_selection.h> 0025 #include <kis_types.h> 0026 #include <filter/kis_filter_configuration.h> 0027 #include <kis_processing_information.h> 0028 0029 #include "kis_wdg_color.h" 0030 #include "ui_wdgcoloroptions.h" 0031 0032 K_PLUGIN_FACTORY_WITH_JSON(KritaColorGeneratorFactory, "kritacolorgenerator.json", registerPlugin<KritaColorGenerator>();) 0033 0034 KritaColorGenerator::KritaColorGenerator(QObject *parent, const QVariantList &) 0035 : QObject(parent) 0036 { 0037 KisGeneratorRegistry::instance()->add(new KisColorGenerator()); 0038 } 0039 0040 KritaColorGenerator::~KritaColorGenerator() 0041 { 0042 } 0043 0044 KisColorGenerator::KisColorGenerator() : KisGenerator(id(), KoID("basic"), i18n("&Solid Color...")) 0045 { 0046 setColorSpaceIndependence(FULLY_INDEPENDENT); 0047 setSupportsPainting(true); 0048 } 0049 0050 KisFilterConfigurationSP KisColorGenerator::defaultConfiguration(KisResourcesInterfaceSP resourcesInterface) const 0051 { 0052 KisFilterConfigurationSP config = factoryConfiguration(resourcesInterface); 0053 0054 QVariant v; 0055 v.setValue(KoColor()); 0056 config->setProperty("color", v); 0057 return config; 0058 } 0059 0060 KisConfigWidget * KisColorGenerator::createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP dev, bool) const 0061 { 0062 Q_UNUSED(dev); 0063 return new KisWdgColor(parent); 0064 } 0065 0066 void KisColorGenerator::generate(KisProcessingInformation dstInfo, 0067 const QSize& size, 0068 const KisFilterConfigurationSP config, 0069 KoUpdater* progressUpdater) const 0070 { 0071 KisPaintDeviceSP dst = dstInfo.paintDevice(); 0072 0073 Q_ASSERT(!dst.isNull()); 0074 Q_ASSERT(config); 0075 0076 KoColor c; 0077 if (config) { 0078 c = config->getColor("color"); 0079 0080 0081 KisFillPainter gc(dst); 0082 gc.setProgress(progressUpdater); 0083 gc.setChannelFlags(config->channelFlags()); 0084 gc.setOpacity(100); 0085 gc.setSelection(dstInfo.selection()); 0086 gc.fillRect(QRect(dstInfo.topLeft(), size), c); 0087 gc.end(); 0088 } 0089 } 0090 0091 #include "colorgenerator.moc"