File indexing completed on 2024-12-22 04:15:13

0001 /*
0002  * This file is part of the KDE project
0003  *
0004  * SPDX-FileCopyrightText: 2005 Michael Thaler <michael.thaler@physik.tu-muenchen.de>
0005  *
0006  *  SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #include "kis_separate_channels_plugin.h"
0010 
0011 #include <QApplication>
0012 
0013 #include <klocalizedstring.h>
0014 #include <kis_debug.h>
0015 #include <kpluginfactory.h>
0016 
0017 #include <KoProgressUpdater.h>
0018 #include <KoUpdater.h>
0019 #include <KoColorSpace.h>
0020 
0021 #include <KisViewManager.h>
0022 #include <kis_types.h>
0023 #include <kis_image.h>
0024 #include <kis_paint_device.h>
0025 #include <kis_layer.h>
0026 #include <kis_statusbar.h>
0027 #include <kis_node_manager.h>
0028 #include <widgets/kis_progress_widget.h>
0029 #include <kis_action.h>
0030 #include <KisCursorOverrideLock.h>
0031 
0032 #include "kis_channel_separator.h"
0033 #include "dlg_separate.h"
0034 
0035 K_PLUGIN_FACTORY_WITH_JSON(KisSeparateChannelsPluginFactory, "kritaseparatechannels.json", registerPlugin<KisSeparateChannelsPlugin>();)
0036 
0037 KisSeparateChannelsPlugin::KisSeparateChannelsPlugin(QObject *parent, const QVariantList &)
0038     : KisActionPlugin(parent)
0039 {
0040     KisAction *action  = createAction("separate");
0041     connect(action, SIGNAL(triggered(bool)), SLOT(slotSeparate()));
0042 }
0043 
0044 KisSeparateChannelsPlugin::~KisSeparateChannelsPlugin()
0045 {
0046 }
0047 
0048 void KisSeparateChannelsPlugin::slotSeparate()
0049 {
0050     KisImageSP image = viewManager()->image();
0051     if (!image) return;
0052 
0053     KisLayerSP l = viewManager()->nodeManager()->activeLayer();
0054     if (!l) return;
0055 
0056     KisPaintDeviceSP dev = l->paintDevice();
0057     if (!dev) return;
0058 
0059     DlgSeparate * dlgSeparate = new DlgSeparate(dev->colorSpace()->name(),
0060                                                 image->colorSpace()->name(), viewManager()->mainWindowAsQWidget(), "Separate");
0061     Q_CHECK_PTR(dlgSeparate);
0062 
0063     dlgSeparate->setCaption(i18n("Separate Image"));
0064 
0065     // If we're 8-bits, disable the downscale option
0066     if (dev->pixelSize() == dev->channelCount()) {
0067         dlgSeparate->enableDownscale(false);
0068     }
0069 
0070     if (dlgSeparate->exec() == QDialog::Accepted) {
0071 
0072         KisCursorOverrideLock cursorLock(Qt::BusyCursor);
0073 
0074         KisChannelSeparator separator(viewManager());
0075         separator.separate(viewManager()->createUnthreadedUpdater(i18n("Separate Image")),
0076                            dlgSeparate->getAlphaOptions(),
0077                            dlgSeparate->getSource(),
0078                            dlgSeparate->getDownscale(),
0079                            dlgSeparate->getToColor(),
0080                            dlgSeparate->getActivateCurrentChannel());
0081     }
0082 
0083     delete dlgSeparate;
0084 
0085 }
0086 
0087 #include "kis_separate_channels_plugin.moc"