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-2.0-or-later 0006 */ 0007 #ifndef KIS_VISUAL_COLOR_SELECTOR_H 0008 #define KIS_VISUAL_COLOR_SELECTOR_H 0009 0010 #include <QWidget> 0011 #include <QScopedPointer> 0012 0013 #include <resources/KoGamutMask.h> 0014 0015 #include "KisColorSelectorInterface.h" 0016 #include "KisVisualColorModel.h" 0017 #include "kritawidgets_export.h" 0018 0019 class QVector4D; 0020 class KisColorSelectorConfiguration; 0021 0022 /** 0023 * @brief The KisVisualColorSelector class 0024 * 0025 * This gives a color selector box that draws gradients and everything. 0026 * 0027 * Unlike other color selectors, this one draws the full gamut of the given 0028 * colorspace. 0029 */ 0030 class KRITAWIDGETS_EXPORT KisVisualColorSelector : public KisColorSelectorInterface 0031 { 0032 Q_OBJECT 0033 public: 0034 0035 enum RenderMode { 0036 StaticBackground, 0037 DynamicBackground, 0038 CompositeBackground 0039 }; 0040 0041 /** 0042 * @brief KisVisualColorSelector constructor. 0043 * @param parent The parent widget. 0044 * @param model The color model to work with. If not provided, a new one will be created. 0045 */ 0046 explicit KisVisualColorSelector(QWidget *parent = 0, KisVisualColorModelSP model = KisVisualColorModelSP()); 0047 ~KisVisualColorSelector() override; 0048 0049 QSize minimumSizeHint() const override; 0050 void setSelectorModel(KisVisualColorModelSP model); 0051 KisVisualColorModelSP selectorModel() const; 0052 /** 0053 * @brief setConfig 0054 * @param forceCircular 0055 * Force circular is for space where you only have room for a circular selector. 0056 * @param forceSelfUpdate 0057 * ignored, can possibly be removed from parent class now 0058 */ 0059 void setConfig(bool forceCircular, bool forceSelfUpdate) override; 0060 const KisColorSelectorConfiguration& configuration() const; 0061 /** 0062 * @brief Explicitly set the shape configuration. 0063 * Accepts all valid combinations of Advanced Color Selector, however parameters 0064 * will be converted to HSV equivalent since color model is independent. 0065 * @param config 0066 * Passing null will load the Advanced Color Selector configuration 0067 * Note: Null will also set the HSX color model for compatibility reasons, 0068 * while otherwise shape layout and color model are independent. 0069 */ 0070 void setConfiguration(const KisColorSelectorConfiguration *config); 0071 void setAcceptTabletEvents(bool on); 0072 KoColor getCurrentColor() const override; 0073 void setMinimumSliderWidth(int width); 0074 const KoColorDisplayRendererInterface* displayRenderer() const; 0075 RenderMode renderMode() const; 0076 void setRenderMode(RenderMode mode); 0077 /** 0078 * @brief Get the state of automatic exposure adjustment. 0079 * If enabled, the selector will set new maximum channel values on the selectorModel 0080 * whenever the set display renderer signals a configuration change. 0081 * The default value is true. 0082 * @return the current state 0083 */ 0084 bool autoAdjustExposure() const; 0085 void setAutoAdjustExposure(bool enabled); 0086 bool proofColors() const; 0087 void setProofColors(bool enabled); 0088 /** 0089 * @brief Set the slider position for slider + square and slider + wheel configurations. 0090 * @param edge Edge to position the slider; currently only supports LeftEdge and TopEdge 0091 */ 0092 void setSliderPosition(Qt::Edge edge); 0093 KoGamutMask* activeGamutMask() const; 0094 0095 public Q_SLOTS: 0096 void slotSetColor(const KoColor &c) override; 0097 void slotSetColorSpace(const KoColorSpace *cs) override; 0098 void slotConfigurationChanged(); 0099 void setDisplayRenderer(const KoColorDisplayRendererInterface *displayRenderer) override; 0100 void slotGamutMaskChanged(KoGamutMaskSP mask); 0101 void slotGamutMaskUnset(); 0102 void slotGamutMaskPreviewUpdate(); 0103 0104 private Q_SLOTS: 0105 void slotChannelValuesChanged(const QVector4D &values, quint32 channelFlags); 0106 void slotColorModelChanged(); 0107 void slotColorSpaceChanged(); 0108 void slotCursorMoved(QPointF pos); 0109 void slotDisplayConfigurationChanged(); 0110 void slotReloadConfiguration(); 0111 0112 Q_SIGNALS: 0113 /** 0114 * @brief sigInteraction is emitted whenever mouse interaction status changes 0115 * @param active when true, the user started dragging a handle, when false the 0116 * interaction has just finished 0117 */ 0118 void sigInteraction(bool active); 0119 0120 protected: 0121 void resizeEvent(QResizeEvent *) override; 0122 0123 private: 0124 bool useHorizontalSlider(); 0125 void rebuildSelector(); 0126 void loadACSConfig(); 0127 void switchDisplayRenderer(const KoColorDisplayRendererInterface *displayRenderer); 0128 QVector4D calculateMaxChannelValues(); 0129 static KisColorSelectorConfiguration validatedConfiguration(const KisColorSelectorConfiguration &cfg); 0130 0131 struct Private; 0132 const QScopedPointer<Private> m_d; 0133 }; 0134 0135 #endif // KIS_VISUAL_COLOR_SELECTOR_H