File indexing completed on 2024-09-22 04:08:34

0001 /*
0002  *  SPDX-FileCopyrightText: 2022 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 #ifndef KISCURVEOPTIONDATACOMMON_H
0007 #define KISCURVEOPTIONDATACOMMON_H
0008 
0009 #include <boost/operators.hpp>
0010 
0011 #include "kis_assert.h"
0012 #include "kis_paintop_option.h"
0013 #include "KisDynamicSensorIds.h"
0014 #include "kritapaintop_export.h"
0015 
0016 #include <KisSensorPackInterface.h>
0017 
0018 
0019 struct PAINTOP_EXPORT KisCurveOptionDataCommon : boost::equality_comparable<KisCurveOptionDataCommon>
0020 {
0021     static constexpr bool supports_prefix = true;
0022 
0023     KisCurveOptionDataCommon(const QString &prefix,
0024                             const KoID &id,
0025                             bool isCheckable,
0026                             bool isChecked,
0027                             qreal minValue,
0028                             qreal maxValue,
0029                             KisSensorPackInterface *sensorInterface);
0030 
0031     KisCurveOptionDataCommon(const KoID &id,
0032                             bool isCheckable,
0033                             bool isChecked,
0034                             qreal minValue,
0035                             qreal maxValue,
0036                             KisSensorPackInterface *sensorInterface);
0037 
0038     inline friend bool operator==(const KisCurveOptionDataCommon &lhs, const KisCurveOptionDataCommon &rhs) {
0039         return lhs.id == rhs.id &&
0040                 lhs.prefix == rhs.prefix &&
0041                 lhs.isCheckable == rhs.isCheckable &&
0042                 lhs.isChecked == rhs.isChecked &&
0043                 lhs.useCurve == rhs.useCurve &&
0044                 lhs.useSameCurve == rhs.useSameCurve &&
0045                 lhs.curveMode == rhs.curveMode &&
0046                 lhs.commonCurve == rhs.commonCurve &&
0047                 lhs.strengthValue == rhs.strengthValue &&
0048                 lhs.strengthMinValue == rhs.strengthMinValue &&
0049                 lhs.strengthMaxValue == rhs.strengthMaxValue &&
0050                 lhs.sensorData->compare(rhs.sensorData.constData());
0051     }
0052 
0053     KoID id;
0054     QString prefix;
0055     bool isCheckable = true;
0056     qreal strengthMinValue = 0.0;
0057     qreal strengthMaxValue = 1.0;
0058 
0059     bool isChecked = true;
0060     bool useCurve = true;
0061     bool useSameCurve = true;
0062 
0063     int curveMode = 0; // TODO: to enum!
0064     QString commonCurve = DEFAULT_CURVE_STRING;
0065     qreal strengthValue = 1.0;
0066 
0067     QSharedDataPointer<KisSensorPackInterface> sensorData;
0068 
0069     std::vector<const KisSensorData *> sensors() const;
0070     std::vector<KisSensorData*> sensors();
0071 
0072     bool read(const KisPropertiesConfiguration *setting);
0073     void write(KisPropertiesConfiguration *setting) const;
0074 
0075     using ValueFixUpReadCallback = std::function<void (KisCurveOptionDataCommon *, const KisPropertiesConfiguration *)>;
0076     ValueFixUpReadCallback valueFixUpReadCallback;
0077 
0078     using ValueFixUpWriteCallback= std::function<void (qreal, KisPropertiesConfiguration *)>;
0079     ValueFixUpWriteCallback valueFixUpWriteCallback;
0080 
0081 private:
0082     bool readPrefixed(const KisPropertiesConfiguration *setting);
0083     void writePrefixed(KisPropertiesConfiguration *setting) const;
0084 };
0085 
0086 #endif // KISCURVEOPTIONDATACOMMON_H