Changeset View
Changeset View
Standalone View
Standalone View
plugins/dockers/artisticcolorselector/kis_color_selector.h
Show All 23 Lines | |||||
24 | #include <QImage> | 24 | #include <QImage> | ||
25 | #include <QPainterPath> | 25 | #include <QPainterPath> | ||
26 | 26 | | |||
27 | #include "kis_color.h" | 27 | #include "kis_color.h" | ||
28 | #include "kis_radian.h" | 28 | #include "kis_radian.h" | ||
29 | #include "kis_acs_types.h" | 29 | #include "kis_acs_types.h" | ||
30 | #include "kis_signal_compressor_with_param.h" | 30 | #include "kis_signal_compressor_with_param.h" | ||
31 | 31 | | |||
32 | #include <resources/KoGamutMask.h> | ||||
33 | #include <KisGamutMaskViewConverter.h> | ||||
34 | | ||||
32 | class QPainter; | 35 | class QPainter; | ||
33 | class QPainter; | 36 | class QPainter; | ||
34 | 37 | | |||
35 | class KisColorSelector: public QWidget | 38 | class KisColorSelector: public QWidget | ||
36 | { | 39 | { | ||
37 | Q_OBJECT | 40 | Q_OBJECT | ||
38 | 41 | | |||
39 | typedef KisRadian<float> Radian; | 42 | typedef KisRadian<float> Radian; | ||
Show All 20 Lines | 45 | { | |||
60 | QVector<QPainterPath> pieced; | 63 | QVector<QPainterPath> pieced; | ||
61 | }; | 64 | }; | ||
62 | 65 | | |||
63 | public: | 66 | public: | ||
64 | KisColorSelector(QWidget* parent, KisColor::Type type=KisColor::HSL); | 67 | KisColorSelector(QWidget* parent, KisColor::Type type=KisColor::HSL); | ||
65 | 68 | | |||
66 | void setColorSpace(KisColor::Type type); | 69 | void setColorSpace(KisColor::Type type); | ||
67 | void setNumPieces(int num); | 70 | void setNumPieces(int num); | ||
68 | void setNumLightPieces(int num); | 71 | void setNumLightPieces(int num) __attribute__((optimize(0))); | ||
69 | void setNumRings(int num); | 72 | void setNumRings(int num); | ||
70 | void resetRings(); | 73 | void resetRings(); | ||
71 | void resetSelectedRing(); | 74 | void resetSelectedRing(); | ||
72 | void resetLight(); | 75 | void resetLight(); | ||
73 | void setLight(float light=0.0f, bool relative=true); | 76 | void setLight(float light=0.0f, bool relative=true); | ||
74 | void setInverseSaturation(bool inverse); | 77 | void setInverseSaturation(bool inverse); | ||
75 | void selectColor(const KisColor& color); | 78 | void selectColor(const KisColor& color); | ||
76 | void setFgColor(const KisColor& fgColor); | 79 | void setFgColor(const KisColor& fgColor); | ||
77 | void setBgColor(const KisColor& bgColor); | 80 | void setBgColor(const KisColor& bgColor); | ||
78 | 81 | | |||
82 | void setDefaultHueSteps(int num); | ||||
83 | void setDefaultSaturationSteps(int num); | ||||
84 | void setDefaultValueScaleSteps(int num); | ||||
85 | void setShowColorBlip(bool value); | ||||
86 | void setShowBgColor(bool value); | ||||
87 | void setShowValueScaleNumbers(bool value); | ||||
88 | void setGamutMask(KoGamutMask* gamutMask); | ||||
89 | bool gamutMaskOn(); | ||||
90 | void setGamutMaskOn(bool gamutMaskOn); | ||||
91 | void setEnforceGamutMask(bool enforce); | ||||
92 | KoGamutMask* gamutMask(); | ||||
93 | | ||||
94 | bool maskPreviewActive(); | ||||
95 | void setMaskPreviewActive(bool value); | ||||
96 | | ||||
97 | bool saturationIsInvertible(); | ||||
98 | | ||||
79 | void saveSettings(); | 99 | void saveSettings(); | ||
80 | void loadSettings(); | 100 | void loadSettings(); | ||
81 | 101 | | |||
82 | KisColor::Type getColorSpace () const { return m_colorSpace; } | 102 | KisColor::Type getColorSpace () const { return m_colorSpace; } | ||
83 | qint32 getNumRings () const { return m_colorRings.size(); } | 103 | qint32 getNumRings () const { return m_colorRings.size(); } | ||
84 | qint32 getNumPieces () const { return m_numPieces; } | 104 | qint32 getNumPieces () const { return m_numPieces; } | ||
85 | qint32 getNumLightPieces () const { return m_numLightPieces; } | 105 | qint32 getNumLightPieces () const { return m_numLightPieces; } | ||
86 | qreal getLight () const { return m_light; } | 106 | qreal getLight () const { return m_light; } | ||
87 | bool isSaturationInverted() const { return m_inverseSaturation; } | 107 | bool isSaturationInverted() const { return m_inverseSaturation; } | ||
88 | bool islightRelative () const { return m_relativeLight; } | 108 | bool islightRelative () const { return m_relativeLight; } | ||
89 | 109 | | |||
110 | quint32 getDefaultHueSteps () const { return m_defaultHueSteps; } | ||||
111 | quint32 getDefaultSaturationSteps () const { return m_defaultSaturationSteps; } | ||||
112 | quint32 getDefaultValueScaleSteps () const { return m_defaultValueScaleSteps; } | ||||
113 | bool getShowColorBlip () const { return m_showColorBlip; } | ||||
114 | bool getShowBgColor () const { return m_showBgColor; } | ||||
115 | bool getShowValueScaleNumbers () const { return m_showValueScaleNumbers; } | ||||
116 | bool enforceGamutMask () const { return m_enforceGamutMask; } | ||||
117 | | ||||
90 | Q_SIGNALS: | 118 | Q_SIGNALS: | ||
91 | void sigFgColorChanged(const KisColor& color); | 119 | void sigFgColorChanged(const KisColor& color); | ||
92 | void sigBgColorChanged(const KisColor& color); | 120 | void sigBgColorChanged(const KisColor& color); | ||
93 | 121 | | |||
94 | private: | 122 | private: | ||
95 | void mousePressEvent(QMouseEvent* event) override; | 123 | void mousePressEvent(QMouseEvent* event) override; | ||
96 | void mouseMoveEvent(QMouseEvent* event) override; | 124 | void mouseMoveEvent(QMouseEvent* event) override; | ||
97 | void mouseReleaseEvent(QMouseEvent* event) override; | 125 | void mouseReleaseEvent(QMouseEvent* event) override; | ||
98 | void resizeEvent(QResizeEvent* event) override; | 126 | void resizeEvent(QResizeEvent* event) override; | ||
99 | void paintEvent(QPaintEvent* event) override; | 127 | void paintEvent(QPaintEvent* event) override; | ||
128 | void leaveEvent(QEvent* e) override; | ||||
100 | 129 | | |||
130 | bool colorIsClear(const KisColor &color); | ||||
131 | bool colorIsClear(const QPointF &colorPoint); | ||||
101 | void requestUpdateColorAndPreview(const KisColor &color, Acs::ColorRole role); | 132 | void requestUpdateColorAndPreview(const KisColor &color, Acs::ColorRole role); | ||
102 | 133 | | |||
103 | void recalculateAreas(quint8 numLightPieces); | 134 | void recalculateAreas(quint8 numLightPieces); | ||
104 | void recalculateRings(quint8 numRings, quint8 numPieces); | 135 | void recalculateRings(quint8 numRings, quint8 numPieces); | ||
105 | void createRing(ColorRing& wheel, quint8 numPieces, qreal innerRadius, qreal outerRadius); | 136 | void createRing(ColorRing& wheel, quint8 numPieces, qreal innerRadius, qreal outerRadius); | ||
106 | 137 | | |||
107 | void drawRing(QPainter& painter, ColorRing& wheel, const QRect& rect); | 138 | void drawRing(QPainter& painter, int ringIndex, ColorRing& wheel, const QRect& rect); | ||
108 | void drawOutline(QPainter& painter, const QRect& rect); | 139 | void drawOutline(QPainter& painter, const QRect& rect); | ||
140 | void drawBlip(QPainter& painter, const QRect& rect); | ||||
109 | void drawLightStrip(QPainter& painter, const QRect& rect); | 141 | void drawLightStrip(QPainter& painter, const QRect& rect); | ||
142 | void drawGamutMaskShape(QPainter& painter, const QRect& rect); | ||||
110 | 143 | | |||
111 | qint8 getHueIndex(Radian hue, Radian shift=0.0f) const; | 144 | qint8 getHueIndex(Radian hue, Radian shift=0.0f) const; | ||
112 | qreal getHue(int hueIdx, Radian shift=0.0f) const; | 145 | qreal getHue(int hueIdx, Radian shift=0.0f) const; | ||
113 | qint8 getLightIndex(const QPointF& pt) const; | 146 | qint8 getLightIndex(const QPointF& pt) const; | ||
114 | qint8 getLightIndex(qreal light) const; | 147 | qint8 getLightIndex(qreal light) const; | ||
115 | qreal getLight(qreal light, qreal hue, bool relative) const; | 148 | qreal getLight(qreal light, qreal hue, bool relative) const; | ||
116 | qreal getLight(const QPointF& pt) const; | 149 | qreal getLight(const QPointF& pt) const; | ||
117 | qint8 getSaturationIndex(const QPointF& pt) const; | 150 | qint8 getSaturationIndex(const QPointF& pt) const; | ||
118 | qint8 getSaturationIndex(qreal saturation) const; | 151 | qint8 getSaturationIndex(qreal saturation) const; | ||
119 | qreal getSaturation(int saturationIdx) const; | 152 | qreal getSaturation(int saturationIdx) const; | ||
120 | 153 | | |||
121 | QPointF mapCoord(const QPointF& pt, const QRectF& rect) const; | 154 | // QPointF mapCoord(const QPointF& pt, const QRectF& rect) const; | ||
155 | | ||||
156 | QPointF mapCoordToView(const QPointF& pt, const QRectF& viewRect) const; | ||||
157 | QPointF mapCoordToUnit(const QPointF& pt, const QRectF& viewRect) const; | ||||
158 | QPointF mapColorToUnit(const KisColor& color, bool invertSaturation = true) const; | ||||
122 | 159 | | |||
123 | public: | 160 | public: | ||
124 | // This is a private interface for signal compressor, don't use it. | 161 | // This is a private interface for signal compressor, don't use it. | ||
125 | // Use requestUpdateColorAndPreview() instead | 162 | // Use requestUpdateColorAndPreview() instead | ||
126 | void slotUpdateColorAndPreview(QPair<KisColor, Acs::ColorRole> color); | 163 | void slotUpdateColorAndPreview(QPair<KisColor, Acs::ColorRole> color); | ||
127 | 164 | | |||
128 | private: | 165 | private: | ||
129 | KisColor::Type m_colorSpace; | 166 | KisColor::Type m_colorSpace; | ||
130 | quint8 m_numPieces; | 167 | quint8 m_numPieces; | ||
131 | quint8 m_numLightPieces; | 168 | quint8 m_numLightPieces; | ||
132 | bool m_inverseSaturation; | 169 | bool m_inverseSaturation; | ||
133 | bool m_relativeLight; | 170 | bool m_relativeLight; | ||
134 | float m_light; | 171 | float m_light; | ||
135 | qint8 m_selectedRing; | 172 | qint8 m_selectedRing; | ||
136 | qint8 m_selectedPiece; | 173 | qint8 m_selectedPiece; | ||
137 | qint8 m_selectedLightPiece; | 174 | qint8 m_selectedLightPiece; | ||
138 | KisColor m_selectedColor; | 175 | KisColor m_selectedColor; | ||
139 | KisColor m_fgColor; | 176 | KisColor m_fgColor; | ||
140 | KisColor m_bgColor; | 177 | KisColor m_bgColor; | ||
141 | QImage m_renderBuffer; | 178 | QImage m_renderBuffer; | ||
179 | QImage m_maskBuffer; | ||||
142 | QRect m_renderArea; | 180 | QRect m_renderArea; | ||
143 | QRect m_lightStripArea; | 181 | QRect m_lightStripArea; | ||
144 | bool m_mouseMoved; | 182 | bool m_mouseMoved; | ||
145 | Acs::ColorRole m_selectedColorRole; | 183 | Acs::ColorRole m_selectedColorRole; | ||
146 | QPointF m_clickPos; | 184 | QPointF m_clickPos; | ||
147 | qint8 m_clickedRing; | 185 | qint8 m_clickedRing; | ||
148 | QVector<ColorRing> m_colorRings; | 186 | QVector<ColorRing> m_colorRings; | ||
149 | Qt::MouseButtons m_pressedButtons; | 187 | Qt::MouseButtons m_pressedButtons; | ||
188 | const QColor m_grayColor; | ||||
189 | const QColor m_gamutMaskColor; | ||||
190 | | ||||
191 | // docker settings | ||||
192 | quint8 m_defaultHueSteps; | ||||
193 | quint8 m_defaultSaturationSteps; | ||||
194 | quint8 m_defaultValueScaleSteps; | ||||
195 | bool m_showColorBlip; | ||||
196 | bool m_showValueScaleNumbers; | ||||
197 | bool m_showBgColor; | ||||
198 | | ||||
199 | bool m_gamutMaskOn; | ||||
200 | KoGamutMask* m_currentGamutMask; | ||||
201 | bool m_enforceGamutMask; | ||||
202 | QSize m_renderAreaSize; | ||||
203 | bool m_maskPreviewActive; | ||||
204 | KisGamutMaskViewConverter* m_viewConverter; | ||||
205 | | ||||
206 | bool m_widgetUpdatesSelf; | ||||
150 | 207 | | |||
151 | typedef KisSignalCompressorWithParam<QPair<KisColor, Acs::ColorRole>> ColorCompressorType; | 208 | typedef KisSignalCompressorWithParam<QPair<KisColor, Acs::ColorRole>> ColorCompressorType; | ||
152 | QScopedPointer<ColorCompressorType> m_updateColorCompressor; | 209 | QScopedPointer<ColorCompressorType> m_updateColorCompressor; | ||
153 | }; | 210 | }; | ||
154 | 211 | | |||
155 | #endif // H_KIS_COLOR_SELECTOR_H | 212 | #endif // H_KIS_COLOR_SELECTOR_H |