File indexing completed on 2024-05-19 04:29:05

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2008 Boudewijn Rempt <boud@valdyas.org>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #ifndef KIS_PAINTOP_OPTION_H
0008 #define KIS_PAINTOP_OPTION_H
0009 
0010 #include <kis_types.h>
0011 #include <kritaui_export.h>
0012 #include <kis_properties_configuration.h>
0013 #include <brushengine/kis_locked_properties_proxy.h>
0014 #include <KisPaintopPropertiesBase.h>
0015 
0016 #include <lager/reader.hpp>
0017 #include <lager/cursor.hpp>
0018 
0019 class QWidget;
0020 class QString;
0021 class KisPaintopLodLimitations;
0022 
0023 
0024 /**
0025  * Base interface for paintop options. A paintop option
0026  * can be enabled/disabled, has a configuration page
0027  * (for example, a curve), a user-visible name and can
0028  * be serialized and deserialized into KisPaintOpPresets
0029  *
0030  * Because KisPaintOpOption classes create a QWidget in
0031  * their constructor (the configuration page) you CANNOT
0032  * create those objects in a KisPaintOp. KisPaintOps are
0033  * created in non-gui threads.
0034  *
0035  * Options are disabled by default.
0036  */
0037 class KRITAUI_EXPORT KisPaintOpOption : public QObject
0038 {
0039     Q_OBJECT
0040 public:
0041 
0042     using OptionalLodLimitationsReader = std::optional<lager::reader<KisPaintopLodLimitations>>;
0043 
0044     enum PaintopCategory {
0045         GENERAL,
0046         COLOR,
0047         TEXTURE,
0048         FILTER,
0049         MASKING_BRUSH
0050     };
0051 
0052     KisPaintOpOption(const QString &label, KisPaintOpOption::PaintopCategory category, bool checked);
0053     KisPaintOpOption(const QString &label, KisPaintOpOption::PaintopCategory category,
0054                      lager::cursor<bool> checkedCursor);
0055     KisPaintOpOption(const QString &label, KisPaintOpOption::PaintopCategory category,
0056                      lager::cursor<bool> checkedCursor,
0057                      lager::reader<bool> externallyEnabledLink);
0058     ~KisPaintOpOption() override;
0059 
0060     KisPaintOpOption::PaintopCategory category() const;
0061     virtual bool isCheckable() const;
0062 
0063     virtual bool isChecked() const;
0064     virtual void setChecked(bool checked);
0065 
0066     bool isEnabled() const;
0067 
0068     void setLocked(bool value);
0069     bool isLocked() const;
0070 
0071     QString label() const;
0072 
0073     /**
0074      * Reimplement this to use the image in the option widget
0075      */
0076     virtual void setImage(KisImageWSP image);
0077     virtual void setNode(KisNodeWSP node);
0078     virtual void setResourcesInterface(KisResourcesInterfaceSP resourcesInterface);
0079     virtual void setCanvasResourcesInterface(KoCanvasResourcesInterfaceSP canvasResourcesInterface);
0080 
0081     void startReadOptionSetting(const KisPropertiesConfigurationSP setting);
0082     void startWriteOptionSetting(KisPropertiesConfigurationSP setting) const;
0083 
0084     QWidget *configurationPage() const;
0085 
0086     virtual void lodLimitations(KisPaintopLodLimitations *l) const;
0087     OptionalLodLimitationsReader effectiveLodLimitations() const;
0088 
0089 protected:
0090     virtual OptionalLodLimitationsReader lodLimitationsReader() const;
0091     void setConfigurationPage(QWidget *page);
0092 
0093     KisResourcesInterfaceSP resourcesInterface() const;
0094     KoCanvasResourcesInterfaceSP canvasResourcesInterface() const;
0095 
0096 protected:
0097     /**
0098      * Re-implement this to save the configuration to the paint configuration.
0099      */
0100     virtual void writeOptionSetting(KisPropertiesConfigurationSP setting) const {
0101         Q_UNUSED(setting);
0102     }
0103 
0104     /**
0105      * Re-implement this to set the widgets with the values in @p setting.
0106      */
0107     virtual void readOptionSetting(const KisPropertiesConfigurationSP setting) {
0108         Q_UNUSED(setting);
0109     }
0110 
0111 protected Q_SLOTS:
0112     void emitSettingChanged();
0113     void emitCheckedChanged(bool checked);
0114     void emitEnabledChanged(bool enabled);
0115 
0116 Q_SIGNALS:
0117 
0118     /**
0119      * emit this whenever a setting has changed. It will update the preview
0120      */
0121     void sigSettingChanged();
0122 
0123     /**
0124      * emit this whenever a checked state of the option has changed. It as always
0125      * emitted *before* sigSettingChanged()
0126      */
0127     void sigCheckedChanged(bool value);
0128     void sigEnabledChanged(bool value);
0129 
0130 private:
0131     void slotEnablePageWidget(bool value);
0132 
0133 protected:
0134 
0135     bool m_checkable {false};
0136     bool m_locked {false};
0137 
0138 private:
0139 
0140     struct Private;
0141     Private* const m_d;
0142 };
0143 
0144 #endif