File indexing completed on 2024-05-19 04:29:29
0001 /* 0002 * SPDX-FileCopyrightText: 2016 Wolthera van Hovell tot Westerflier <griffinvalley@gmail.com> 0003 * SPDX-FileCopyrightText: 2022 Mathias Wein <lynx.mw+kde@gmail.com> 0004 * 0005 * SPDX-License-Identifier: GPL-3.0-or-later 0006 */ 0007 0008 #ifndef KIS_VISUAL_COLOR_MODEL_H 0009 #define KIS_VISUAL_COLOR_MODEL_H 0010 0011 #include <QObject> 0012 #include <QScopedPointer> 0013 0014 #include <KoColor.h> 0015 0016 #include "kritawidgets_export.h" 0017 0018 class KoColorSpace; 0019 class KoColorDisplayRendererInterface; 0020 0021 /** 0022 * @brief The KisVisualColorModel class allows manipulating a KoColor using various color models 0023 * 0024 * This enables different widgets to easily manipulate the same color representation 0025 * (like HSV channels of an RGB color etc.) in a synchronized way without having to know 0026 * the details of the underlying color space. 0027 * NOTE: This class is meant to be shared between GUI classes using KisVisualColorModelSP, 0028 * so DO NOT SET a QObject parent in this case. 0029 */ 0030 0031 class KRITAWIDGETS_EXPORT KisVisualColorModel : public QObject 0032 { 0033 Q_OBJECT 0034 public: 0035 enum ColorModel { None, Channel, HSV, HSL, HSI, HSY, YUV }; 0036 0037 KisVisualColorModel(); 0038 ~KisVisualColorModel() override; 0039 0040 KoColor currentColor() const; 0041 QVector4D channelValues() const; 0042 int colorChannelCount() const; 0043 ColorModel colorModel() const; 0044 QVector4D maxChannelValues() const; 0045 void setMaxChannelValues(const QVector4D &maxValues); 0046 /** 0047 * @brief Copy the internal state of another KisVisualColorModel 0048 * 0049 * This will emit all necessary signals to update widgets so they 0050 * can reflect the new state correctly. 0051 * 0052 * @param other the model to copy 0053 */ 0054 void copyState(const KisVisualColorModel &other); 0055 /** 0056 * @brief Set the HSX color model used for RGB color spaces. 0057 */ 0058 void setRGBColorModel(ColorModel model); 0059 const KoColorSpace* colorSpace() const; 0060 bool isHSXModel() const; 0061 bool supportsExposure() const; 0062 KoColor convertChannelValuesToKoColor(const QVector4D &values) const; 0063 QVector4D convertKoColorToChannelValues(KoColor c) const; 0064 0065 public Q_SLOTS: 0066 0067 void slotSetColor(const KoColor &c); 0068 void slotSetColorSpace(const KoColorSpace *cs); 0069 void slotSetChannelValues(const QVector4D &values); 0070 /** 0071 * @brief slotLoadACSConfig loads supported settings from Advanced Color Selector 0072 */ 0073 void slotLoadACSConfig(); 0074 0075 private: 0076 void loadColorSpace(const KoColorSpace *cs); 0077 void emitChannelValues(); 0078 0079 Q_SIGNALS: 0080 /** 0081 * @brief sigColorModelChanged is emitted whenever the color model changes. 0082 * 0083 * This can either be due to a change in color space that uses a different channel 0084 * model, or when the same color space gets represented in a different way, 0085 * for example RGB representation switches from HSV to HSL etc. so the values of 0086 * sigChannelValuesChanged() change meaning. 0087 * Note: This will be followed by sigChannelValuesChanged() unless caused by a 0088 * color space change, new channel values are not available yet when this signal occurs. 0089 * 0090 * @see getColorModel() 0091 */ 0092 void sigColorModelChanged(); 0093 /** 0094 * @brief sigColorSpaceChanged notifies that the color space from which the 0095 * channel values are derived changed, and thus invalidating the current ones. 0096 */ 0097 void sigColorSpaceChanged(); 0098 void sigChannelValuesChanged(const QVector4D &values, quint32 channelFlags); 0099 void sigNewColor(const KoColor &c); 0100 0101 private: 0102 struct Private; 0103 const QScopedPointer<Private> m_d; 0104 0105 }; 0106 0107 typedef QSharedPointer<KisVisualColorModel> KisVisualColorModelSP; 0108 0109 #endif // KIS_VISUAL_COLOR_MODEL_H