Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_color_selector_component.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2010 Adam Celarek <kdedev at xibo dot at>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
10
11#include "KoColorSpace.h"
12#include <QPainter>
13#include <QMouseEvent>
15
16
18 QObject(parent),
19 m_hue(0),
20 m_hsvSaturation(1),
21 m_value(1),
22 m_hslSaturation(1),
23 m_lightness(0.5),
24 m_hsiSaturation(1),
25 m_intensity(0.333),
26 m_hsySaturation(1),
27 m_luma(0.299),
28 m_parent(parent),
29 m_gamutMaskOn(false),
30 m_currentGamutMask(nullptr),
31 m_maskPreviewActive(true),
32 m_lastX(0),
33 m_lastY(0),
34 m_x(0),
35 m_y(0),
36 m_width(0),
37 m_height(0),
38 m_dirty(true),
39 m_lastColorSpace(0)
40{
41 Q_ASSERT(parent);
42}
43
44void KisColorSelectorComponent::setGeometry(int x, int y, int width, int height)
45{
46 m_x=x;
47 m_y=y;
50 m_dirty=true;
51}
52
54{
55 painter->save();
56 painter->translate(m_x, m_y);
57 paint(painter);
58 painter->restore();
59
60 m_dirty=false;
62}
63
65{
66 int newX=qBound(0, (x-m_x), width());
67 int newY=qBound(0, (y-m_y), height());
68
69 if (allowsColorSelectionAtPoint(QPoint(newX, newY))) {
70 m_lastSelectedColor = selectColor(newX, newY);
71 m_lastX=newX;
72 m_lastY=newY;
73 }
74}
75
77{
78 const KoColorSpace* cs = m_parent->colorSpace();
79 Q_ASSERT(cs);
80 return cs;
81}
82
88
94
100
106
108{
109 m_gamutMaskOn = state;
110 setDirty();
111 update();
112}
113
114
119
121{
122 if(x>=0 && y>=0 && x<=width() && y<=height())
123 return true;
124 else
125 return false;
126}
127
129{
130 return true;
131}
132
137
138void KisColorSelectorComponent::setParam(qreal hue, qreal hsvSaturation, qreal value, qreal hslSaturation, qreal lightness, qreal hsiSaturation, qreal intensity, qreal hsySaturation, qreal luma)
139{
140 if(qFuzzyCompare(m_hue, hue) &&
141 qFuzzyCompare(m_hsvSaturation, hsvSaturation) &&
143 qFuzzyCompare(m_hslSaturation, hslSaturation) &&
144 qFuzzyCompare(m_lightness, lightness) &&
145 qFuzzyCompare(m_hsiSaturation, hsiSaturation) &&
146 qFuzzyCompare(m_intensity, intensity) &&
147 qFuzzyCompare(m_hsySaturation, hsySaturation) &&
148 qFuzzyCompare(m_luma, luma))
149 return;
150
151 if (hue >= 0) {
152 m_hue = qMin(hue, qreal(1));
153 }
154
155 if (hsvSaturation >= 0) {
156 m_hsvSaturation = qMin(hsvSaturation, qreal(1));
157 m_hslSaturation = -1;
158 m_hsiSaturation = -1;
159 m_hsySaturation = -1;
160 }
161
162 if (value >= 0) {
163 m_value = qMin(value, qreal(1));
164 m_intensity = -1;
165 m_luma = -1;
166 m_lightness = -1;
167 }
168
169 if (hslSaturation >= 0) {
170 m_hslSaturation = qMin(hslSaturation, qreal(1));
171 m_hsvSaturation = -1;
172 m_hsiSaturation = -1;
173 m_hsySaturation = -1;
174 }
175
176 if (lightness >= 0) {
177 m_lightness = qMin(lightness, qreal(1));
178 m_value = -1;
179 m_luma = -1;
180 m_intensity = -1;
181 }
182
183 if (hsiSaturation >= 0) {
184 m_hsiSaturation = qMin(hsiSaturation, qreal(1));
185 m_hsvSaturation = -1;
186 m_hslSaturation = -1;
187 m_hsySaturation = -1;
188 }
189
190 if (intensity >= 0) {
191 m_intensity = qMin(intensity, qreal(1));
192 m_value = -1;
193 m_luma = -1;
194 m_lightness = -1;
195 }
196
197 if (hsySaturation >= 0) {
198 m_hsySaturation = qMin(hsySaturation, qreal(1));
199 m_hsvSaturation = -1;
200 m_hsiSaturation = -1;
201 m_hslSaturation = -1;
202 }
203
204 if (luma >= 0) {
205 m_luma = qMin(luma, qreal(1));
206 m_intensity = -1;
207 m_value = -1;
208 m_lightness = -1;
209 }
210
211 m_dirty=true;
212 Q_EMIT update();
213}
214
216{
217 return m_width;
218}
219
221{
222 return m_height;
223}
224
226{
227 m_parameter = param;
228 m_type = type;
229}
230
232{
233 m_lastSelectedColor = color;
234}
235
237{
238 // prevent movement due to rounding errors
239 if (abs((int)m_lastX - x) > 1 || abs((int)m_lastY - y) > 1) {
240 m_lastX = x;
241 m_lastY = y;
242 }
243}
float value(const T *src, size_t ch)
const KoColorSpace * colorSpace() const
virtual bool containsPointInComponentCoords(int x, int y) const
const KoColorSpace * colorSpace() const
void update()
request for repaint, for instance, if the hue changes.
virtual void mouseEvent(int x, int y)
saves the mouse position, so that a blip can be created.
void setDirty()
force subsequent redraw of the component
void setParam(qreal hue, qreal hsvSaturation, qreal value, qreal hslSaturation, qreal lightness, qreal hsiSaturation, qreal intensity, qreal hsySaturation, qreal luma)
bool isDirty() const
returns true, if ether the color space, the size or the parameters have changed since the last paint ...
KisColorSelectorComponent(KisColorSelector *parent)
virtual bool allowsColorSelectionAtPoint(const QPoint &) const
virtual void setColor(const KoColor &color)
set the color, blibs etc
void setConfiguration(Parameter param, Type type)
setConfiguration can be ignored (for instance ring and triangle, as they can have only one config)
virtual KoColor selectColor(int x, int y)=0
this method must be overloaded to return the color at position x/y and draw a marker on that position
void setGamutMask(KoGamutMaskSP gamutMask)
virtual void paint(QPainter *)=0
KoColor currentColor()
return the color, that was selected by calling mouseEvent
void setGeometry(int x, int y, int width, int height)
static bool qFuzzyCompare(half p1, half p2)