File indexing completed on 2024-05-12 15:58:10

0001 /*
0002  *  SPDX-FileCopyrightText: 2008 Boudewijn Rempt <boud@valdyas.org>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 #ifndef _KIS_BASE_PROCESSOR_H_
0007 #define _KIS_BASE_PROCESSOR_H_
0008 
0009 #include <list>
0010 
0011 #include <QString>
0012 
0013 #include <klocalizedstring.h>
0014 #include <QKeySequence>
0015 
0016 #include "KoID.h"
0017 #include "KoColorSpace.h"
0018 
0019 #include "kis_types.h"
0020 #include "kis_shared.h"
0021 #include "kis_image.h"
0022 #include "kis_filter_configuration.h"
0023 #include "kritaimage_export.h"
0024 
0025 class QWidget;
0026 
0027 class KisBookmarkedConfigurationManager;
0028 class KisConfigWidget;
0029 
0030 class KoResource;
0031 typedef QSharedPointer<KoResource> KoResourceSP;
0032 
0033 class KisResourcesInterface;
0034 typedef QSharedPointer<KisResourcesInterface> KisResourcesInterfaceSP;
0035 
0036 /**
0037  * Base class for classes that process areas of pixels.
0038  * Processors can either read in pixels and write out pixels
0039  * or just write out pixels, using a certain set of configuration
0040  * pixels.
0041  *
0042  * in-out processing is typically filtering: @see KisFilter.
0043  * out-only processing is typically generating: @see KisGenerator.
0044  *
0045  * Information about the area that needs to be processed is contained
0046  * @see KisProcessingInformation and @see KisConstProcessingInformation.
0047  */
0048 class KRITAIMAGE_EXPORT KisBaseProcessor : public KisShared
0049 {
0050     friend class KisBaseProcessorConfigurationFactory;
0051 
0052 public:
0053 
0054 
0055     KisBaseProcessor(const KoID& id, const KoID & category, const QString & entry);
0056 
0057     virtual ~KisBaseProcessor();
0058 
0059     /**
0060      * Return the configuration set as the default by the user or the default
0061      * configuration from the filter writer as returned by factoryConfiguration.
0062      *
0063      * This configuration is used by default for the configuration widget and
0064      * given to the process function if there is no configuration widget.
0065      *
0066      * @return the default configuration of this widget
0067      */
0068     virtual KisFilterConfigurationSP  defaultConfiguration(KisResourcesInterfaceSP resourcesInterface) const;
0069 
0070     /**
0071      * @return the bookmark manager for this processor
0072      */
0073     KisBookmarkedConfigurationManager* bookmarkManager();
0074 
0075     /**
0076      * @return the bookmark manager for this processor
0077      */
0078     const KisBookmarkedConfigurationManager* bookmarkManager() const;
0079 
0080     /// @return Unique identification for this processor
0081     QString id() const;
0082 
0083     /// @return User-visible identification for this processor
0084     QString name() const;
0085 
0086     /// @return the submenu in the filters menu does processor want to go?
0087     KoID menuCategory() const;
0088 
0089     /// @return the i18n'ed string this filter wants to show itself in the menu
0090     QString menuEntry() const;
0091 
0092     /**
0093      * Return the default keyboard shortcut for activation of this filter
0094      *
0095      * @return the shortcut
0096      */
0097     QKeySequence shortcut() const;
0098 
0099     /**
0100      * Create the configuration widget for this processor.
0101      *
0102      * @param parent the Qt owner widget of this widget
0103      * @param dev the paintdevice this filter will act on
0104      * @param useForMasks shown if the filer is going to be used in a mask. Some filters
0105      *        may provide limited options when applied as a mask (e.g. Gaussian Blur)
0106      */
0107     virtual KisConfigWidget * createConfigurationWidget(QWidget * parent, const KisPaintDeviceSP dev, bool useForMasks) const;
0108     // "Support" functions
0109 public:
0110     /**
0111      * If true, this filter can be used in painting tools as a paint operation
0112      */
0113     bool supportsPainting() const;
0114 
0115     /// This filter can be used in adjustment layers
0116     bool supportsAdjustmentLayers() const;
0117 
0118     /**
0119      * This filter supports cutting up the work area and filtering
0120      * each chunk in a separate thread. Filters that need access to the
0121      * whole area for correct computations should return false.
0122      */
0123     bool supportsThreading() const;
0124 
0125     /// If true, the filter wants to show a configuration widget
0126     bool showConfigurationWidget();
0127 
0128     /**
0129      * Determine the colorspace independence of this filter.
0130      * @see ColorSpaceIndependence
0131      *
0132      * @return the degree of independence
0133      */
0134     ColorSpaceIndependence colorSpaceIndependence() const;
0135 
0136     /// @return the default configuration object as defined by whoever wrote the plugin.
0137     /// This object must be filled in with fromXML after that.
0138     virtual KisFilterConfigurationSP factoryConfiguration(KisResourcesInterfaceSP resourcesInterface) const;
0139 
0140 protected:
0141 
0142     void setSupportsPainting(bool v);
0143     void setSupportsAdjustmentLayers(bool v);
0144     void setSupportsThreading(bool v);
0145     void setColorSpaceIndependence(ColorSpaceIndependence v);
0146     void setShowConfigurationWidget(bool v);
0147 
0148     /**
0149      * Set the default shortcut for activation of this filter.
0150      */
0151     void setShortcut(const QKeySequence & shortcut);
0152 
0153 protected:
0154 
0155     void init(const QString& configEntryGroup);
0156 
0157 private:
0158     struct Private;
0159     Private* const d;
0160 };
0161 
0162 
0163 #endif