Changeset View
Changeset View
Standalone View
Standalone View
plugins/dockers/artisticcolorselector/kis_color_selector.cpp
Show All 30 Lines | |||||
31 | 31 | | |||
32 | #include <kis_config.h> | 32 | #include <kis_config.h> | ||
33 | #include <kis_arcs_constants.h> | 33 | #include <kis_arcs_constants.h> | ||
34 | #include <resources/KoGamutMask.h> | 34 | #include <resources/KoGamutMask.h> | ||
35 | #include <KisGamutMaskViewConverter.h> | 35 | #include <KisGamutMaskViewConverter.h> | ||
36 | 36 | | |||
37 | #include "kis_color_selector.h" | 37 | #include "kis_color_selector.h" | ||
38 | 38 | | |||
39 | //#define DEBUG_ARC_SELECTOR | ||||
40 | | ||||
39 | KisColorSelector::KisColorSelector(QWidget* parent, KisColor::Type type) | 41 | KisColorSelector::KisColorSelector(QWidget* parent, KisColor::Type type) | ||
40 | : QWidget(parent) | 42 | : QWidget(parent) | ||
41 | , m_colorSpace(type) | 43 | , m_colorSpace(type) | ||
42 | , m_inverseSaturation(false) | 44 | , m_inverseSaturation(false) | ||
43 | , m_relativeLight(true) | 45 | , m_gamma(1.0f) | ||
44 | , m_light(0.5f) | | |||
45 | , m_selectedColorRole(Acs::Foreground) | | |||
46 | , m_clickedRing(-1) | 46 | , m_clickedRing(-1) | ||
47 | , m_gamutMaskOn(false) | 47 | , m_gamutMaskOn(false) | ||
48 | , m_widgetUpdatesSelf(false) | | |||
49 | , m_grayColor(QColor(128,128,128,255)) | | |||
50 | , m_gamutMaskColor(QColor(128,128,128,255)) | | |||
51 | , m_currentGamutMask(nullptr) | 48 | , m_currentGamutMask(nullptr) | ||
52 | , m_maskPreviewActive(true) | 49 | , m_maskPreviewActive(true) | ||
50 | , m_widgetUpdatesSelf(false) | ||||
53 | { | 51 | { | ||
54 | m_viewConverter = new KisGamutMaskViewConverter(); | 52 | m_viewConverter = new KisGamutMaskViewConverter(); | ||
55 | 53 | | |||
56 | recalculateRings(9, 12); | 54 | recalculateRings(DEFAULT_SATURATION_STEPS, DEFAULT_HUE_STEPS); | ||
57 | recalculateAreas(9); | 55 | recalculateAreas(DEFAULT_VALUE_SCALE_STEPS); | ||
58 | selectColor(KisColor(Qt::red, KisColor::HSY)); | 56 | selectColor(KisColor(Qt::red, KisColor::HSY)); | ||
59 | 57 | | |||
60 | using namespace std::placeholders; // For _1 placeholder | 58 | using namespace std::placeholders; // For _1 placeholder | ||
61 | auto function = std::bind(&KisColorSelector::slotUpdateColorAndPreview, this, _1); | 59 | auto function = std::bind(&KisColorSelector::slotUpdateColorAndPreview, this, _1); | ||
62 | m_updateColorCompressor.reset(new ColorCompressorType(20 /* ms */, function)); | 60 | m_updateColorCompressor.reset(new ColorCompressorType(20 /* ms */, function)); | ||
63 | } | 61 | } | ||
64 | 62 | | |||
65 | void KisColorSelector::setColorSpace(KisColor::Type type) | 63 | void KisColorSelector::setColorSpace(KisColor::Type type, float valueScaleGamma) | ||
66 | { | 64 | { | ||
67 | m_colorSpace = type; | 65 | m_colorSpace = type; | ||
66 | setGamma(valueScaleGamma); | ||||
68 | m_selectedColor = KisColor(m_selectedColor, m_colorSpace); | 67 | m_selectedColor = KisColor(m_selectedColor, m_colorSpace); | ||
68 | | ||||
69 | #ifdef DEBUG_ARC_SELECTOR | ||||
70 | dbgPlugins << "KisColorSelector::setColorSpace: set to:" << m_colorSpace; | ||||
71 | #endif | ||||
72 | | ||||
69 | update(); | 73 | update(); | ||
70 | } | 74 | } | ||
71 | 75 | | |||
72 | void KisColorSelector::setNumLightPieces(int num) | 76 | void KisColorSelector::setNumLightPieces(int num) | ||
73 | { | 77 | { | ||
74 | num = qBound(MIN_NUM_LIGHT_PIECES, num, MAX_NUM_LIGHT_PIECES); | 78 | num = qBound(MIN_NUM_LIGHT_PIECES, num, MAX_NUM_LIGHT_PIECES); | ||
75 | 79 | | |||
76 | recalculateAreas(quint8(num)); | 80 | recalculateAreas(quint8(num)); | ||
77 | 81 | | |||
78 | if (m_selectedLightPiece >= 0) | 82 | if (m_selectedLightPiece >= 0) | ||
79 | m_selectedLightPiece = getLightIndex(m_selectedColor.getX()); | 83 | m_selectedLightPiece = getLightIndex(m_selectedColor.getX(m_gamma)); | ||
80 | 84 | | |||
81 | update(); | 85 | update(); | ||
82 | } | 86 | } | ||
83 | 87 | | |||
84 | void KisColorSelector::setNumPieces(int num) | 88 | void KisColorSelector::setNumPieces(int num) | ||
85 | { | 89 | { | ||
86 | num = qBound(MIN_NUM_HUE_PIECES, num, MAX_NUM_HUE_PIECES); | 90 | num = qBound(MIN_NUM_HUE_PIECES, num, MAX_NUM_HUE_PIECES); | ||
87 | 91 | | |||
Show All 17 Lines | 101 | { | |||
105 | update(); | 109 | update(); | ||
106 | } | 110 | } | ||
107 | 111 | | |||
108 | void KisColorSelector::selectColor(const KisColor& color) | 112 | void KisColorSelector::selectColor(const KisColor& color) | ||
109 | { | 113 | { | ||
110 | m_selectedColor = KisColor(color, m_colorSpace); | 114 | m_selectedColor = KisColor(color, m_colorSpace); | ||
111 | m_selectedPiece = getHueIndex(m_selectedColor.getH() * PI2); | 115 | m_selectedPiece = getHueIndex(m_selectedColor.getH() * PI2); | ||
112 | m_selectedRing = getSaturationIndex(m_selectedColor.getS()); | 116 | m_selectedRing = getSaturationIndex(m_selectedColor.getS()); | ||
113 | m_selectedLightPiece = getLightIndex(m_selectedColor.getX()); | 117 | m_selectedLightPiece = getLightIndex(m_selectedColor.getX(m_gamma)); | ||
114 | update(); | 118 | update(); | ||
115 | } | 119 | } | ||
116 | 120 | | |||
117 | void KisColorSelector::setFgColor(const KisColor& fgColor) | 121 | void KisColorSelector::setFgColor(const KisColor& fgColor) | ||
118 | { | 122 | { | ||
119 | if (!m_widgetUpdatesSelf) { | 123 | if (!m_widgetUpdatesSelf) { | ||
120 | m_fgColor = KisColor(fgColor, m_colorSpace); | 124 | m_fgColor = KisColor(fgColor, m_colorSpace); | ||
125 | m_selectedColor = KisColor(fgColor, m_colorSpace); | ||||
126 | | ||||
127 | #ifdef DEBUG_ARC_SELECTOR | ||||
121 | dbgPlugins << "KisColorSelector::setFgColor: m_fgColor set to:" | 128 | dbgPlugins << "KisColorSelector::setFgColor: m_fgColor set to:" | ||
122 | << "H:" << m_fgColor.getH() | 129 | << "H:" << m_fgColor.getH() | ||
123 | << "S:" << m_fgColor.getS() | 130 | << "S:" << m_fgColor.getS() | ||
124 | << "X:" << m_fgColor.getX(); | 131 | << "X:" << m_fgColor.getX(m_gamma); | ||
125 | 132 | | |||
126 | m_selectedColor = KisColor(fgColor, m_colorSpace); | | |||
127 | dbgPlugins << "KisColorSelector::setFgColor: m_selectedColor set to:" | 133 | dbgPlugins << "KisColorSelector::setFgColor: m_selectedColor set to:" | ||
128 | << "H:" << m_selectedColor.getH() | 134 | << "H:" << m_selectedColor.getH() | ||
129 | << "S:" << m_selectedColor.getS() | 135 | << "S:" << m_selectedColor.getS() | ||
130 | << "X:" << m_selectedColor.getX(); | 136 | << "X:" << m_selectedColor.getX(m_gamma); | ||
137 | #endif | ||||
131 | update(); | 138 | update(); | ||
132 | } else { | | |||
133 | dbgPlugins << "KisColorSelector::setFgColor: m_widgetUpdatesSelf == true, not updating color"; | | |||
134 | } | 139 | } | ||
135 | } | 140 | } | ||
136 | 141 | | |||
137 | void KisColorSelector::setBgColor(const KisColor& bgColor) | 142 | void KisColorSelector::setBgColor(const KisColor& bgColor) | ||
138 | { | 143 | { | ||
139 | if (!m_widgetUpdatesSelf) { | 144 | if (!m_widgetUpdatesSelf) { | ||
140 | m_bgColor = KisColor(bgColor, m_colorSpace); | 145 | m_bgColor = KisColor(bgColor, m_colorSpace); | ||
146 | #ifdef DEBUG_ARC_SELECTOR | ||||
141 | dbgPlugins << "KisColorSelector::setBgColor: m_bgColor set to:" | 147 | dbgPlugins << "KisColorSelector::setBgColor: m_bgColor set to:" | ||
142 | << "H:" << m_bgColor.getH() | 148 | << "H:" << m_bgColor.getH() | ||
143 | << "S:" << m_bgColor.getS() | 149 | << "S:" << m_bgColor.getS() | ||
144 | << "X:" << m_bgColor.getX(); | 150 | << "X:" << m_bgColor.getX(m_gamma); | ||
151 | #endif | ||||
145 | update(); | 152 | update(); | ||
146 | } else { | | |||
147 | dbgPlugins << "KisColorSelector::setBgColor: m_widgetUpdatesSelf == true, not updating color"; | | |||
148 | } | | |||
149 | } | 153 | } | ||
150 | | ||||
151 | void KisColorSelector::resetRings() | | |||
152 | { | | |||
153 | for(int i=0; i<m_colorRings.size(); ++i) | | |||
154 | m_colorRings[i].angle = 0.0f; | | |||
155 | | ||||
156 | update(); | | |||
157 | } | 154 | } | ||
158 | 155 | | |||
159 | void KisColorSelector::resetLight() | 156 | void KisColorSelector::setLight(float light) | ||
160 | { | 157 | { | ||
161 | m_light = (m_colorSpace == KisColor::HSV) ? 1.0f : 0.5f; | 158 | m_selectedColor.setX(qBound(0.0f, light, 1.0f), m_gamma); | ||
162 | m_selectedLightPiece = getLightIndex(m_light); | 159 | m_selectedLightPiece = getLightIndex(m_selectedColor.getX(m_gamma)); | ||
163 | update(); | 160 | update(); | ||
164 | } | 161 | } | ||
165 | 162 | | |||
166 | void KisColorSelector::resetSelectedRing() | 163 | void KisColorSelector::setGamma(float gamma) { | ||
167 | { | 164 | if (m_colorSpace == KisColor::HSY) { | ||
168 | if (m_selectedRing >= 0) { | 165 | m_gamma = gamma; | ||
169 | m_colorRings[m_selectedRing].angle = 0.0f; | 166 | } else { | ||
170 | update(); | 167 | m_gamma = 1.0f; | ||
171 | } | | |||
172 | } | 168 | } | ||
173 | 169 | | |||
174 | void KisColorSelector::setLight(float light, bool relative) | 170 | #ifdef DEBUG_ARC_SELECTOR | ||
175 | { | 171 | dbgPlugins << "KisColorSelector::setGamma: set to:" << m_gamma; | ||
176 | m_light = qBound(0.0f, light, 1.0f); | 172 | #endif | ||
177 | 173 | | |||
178 | m_selectedColor.setX(getLight(m_light, m_selectedColor.getH(), relative)); | | |||
179 | m_relativeLight = relative; | | |||
180 | m_selectedLightPiece = getLightIndex(m_selectedColor.getX()); | | |||
181 | update(); | 174 | update(); | ||
182 | } | 175 | } | ||
183 | 176 | | |||
184 | void KisColorSelector::setInverseSaturation(bool inverse) | 177 | void KisColorSelector::setInverseSaturation(bool inverse) | ||
185 | { | 178 | { | ||
186 | if (m_inverseSaturation != inverse) { | 179 | if (m_inverseSaturation != inverse) { | ||
187 | m_selectedRing = (getNumRings()-1) - m_selectedRing; | 180 | m_selectedRing = (getNumRings()-1) - m_selectedRing; | ||
188 | m_inverseSaturation = inverse; | 181 | m_inverseSaturation = inverse; | ||
Show All 32 Lines | |||||
221 | bool KisColorSelector::gamutMaskOn() | 214 | bool KisColorSelector::gamutMaskOn() | ||
222 | { | 215 | { | ||
223 | return m_gamutMaskOn; | 216 | return m_gamutMaskOn; | ||
224 | } | 217 | } | ||
225 | 218 | | |||
226 | 219 | | |||
227 | void KisColorSelector::setGamutMaskOn(bool gamutMaskOn) | 220 | void KisColorSelector::setGamutMaskOn(bool gamutMaskOn) | ||
228 | { | 221 | { | ||
229 | // do not allow the mask on, if it is a nullptr | | |||
230 | if (m_currentGamutMask) { | 222 | if (m_currentGamutMask) { | ||
231 | m_gamutMaskOn = gamutMaskOn; | 223 | m_gamutMaskOn = gamutMaskOn; | ||
232 | update(); | 224 | update(); | ||
233 | } | 225 | } | ||
234 | } | 226 | } | ||
235 | 227 | | |||
236 | void KisColorSelector::setEnforceGamutMask(bool enforce) | 228 | void KisColorSelector::setEnforceGamutMask(bool enforce) | ||
237 | { | 229 | { | ||
Show All 18 Lines | 246 | { | |||
256 | qreal h = viewRect.height() / 2.0; | 248 | qreal h = viewRect.height() / 2.0; | ||
257 | qreal x = pt.x() - (viewRect.x() + w); | 249 | qreal x = pt.x() - (viewRect.x() + w); | ||
258 | qreal y = pt.y() - (viewRect.y() + h); | 250 | qreal y = pt.y() - (viewRect.y() + h); | ||
259 | return QPointF(x/w, y/h); | 251 | return QPointF(x/w, y/h); | ||
260 | } | 252 | } | ||
261 | 253 | | |||
262 | QPointF KisColorSelector::mapColorToUnit(const KisColor& color, bool invertSaturation) const | 254 | QPointF KisColorSelector::mapColorToUnit(const KisColor& color, bool invertSaturation) const | ||
263 | { | 255 | { | ||
264 | qreal angle = color.getH() * 2.0 * M_PI; | | |||
265 | | ||||
266 | qreal radius; | 256 | qreal radius; | ||
267 | if (invertSaturation && m_inverseSaturation) { | 257 | if (invertSaturation && m_inverseSaturation) { | ||
268 | radius = 1.0 - color.getS(); | 258 | radius = 1.0 - color.getS(); | ||
269 | } else { | 259 | } else { | ||
270 | radius = color.getS(); | 260 | radius = color.getS(); | ||
271 | } | 261 | } | ||
272 | 262 | | |||
273 | qreal x = std::cos(angle)*radius; | 263 | QPointF hueCoord = mapHueToAngle(color.getH()); | ||
274 | qreal y = std::sin(-angle)*radius; | 264 | qreal x = hueCoord.x()*radius; | ||
265 | qreal y = hueCoord.y()*radius; | ||||
266 | | ||||
267 | return QPointF(x,y); | ||||
268 | } | ||||
269 | | ||||
270 | KisColorSelector::Radian KisColorSelector::mapCoordToAngle(qreal x, qreal y) const | ||||
271 | { | ||||
272 | float angle = std::atan2(-y, -x); | ||||
273 | | ||||
274 | #ifdef DEBUG_ARC_SELECTOR | ||||
275 | dbgPlugins << "KisColorSelector::mapCoordToAngle: " | ||||
276 | << "X:" << x | ||||
277 | << "Y:" << y | ||||
278 | << "angle:" << angle; | ||||
279 | #endif | ||||
280 | | ||||
281 | return angle; | ||||
282 | } | ||||
283 | | ||||
284 | QPointF KisColorSelector::mapHueToAngle(float hue) const | ||||
285 | { | ||||
286 | float angle = hue * 2.0 * M_PI - M_PI; | ||||
287 | float x = std::cos(angle); | ||||
288 | float y = std::sin(angle); | ||||
275 | 289 | | |||
276 | return QPointF(x,y); | 290 | return QPointF(x,y); | ||
277 | } | 291 | } | ||
278 | 292 | | |||
279 | 293 | | |||
280 | qint8 KisColorSelector::getLightIndex(const QPointF& pt) const | 294 | qint8 KisColorSelector::getLightIndex(const QPointF& pt) const | ||
281 | { | 295 | { | ||
282 | if (m_lightStripArea.contains(pt.toPoint(), true)) { | 296 | if (m_lightStripArea.contains(pt.toPoint(), true)) { | ||
283 | qreal t = (pt.x() - m_lightStripArea.x()) / qreal(m_lightStripArea.width()); | 297 | qreal t = (pt.x() - m_lightStripArea.x()) / qreal(m_lightStripArea.width()); | ||
284 | t = (pt.y() - m_lightStripArea.y()) / qreal(m_lightStripArea.height()); | 298 | t = (pt.y() - m_lightStripArea.y()) / qreal(m_lightStripArea.height()); | ||
285 | 299 | | |||
286 | return qint8(t * getNumLightPieces()); | 300 | return qint8(t * getNumLightPieces()); | ||
287 | } | 301 | } | ||
288 | 302 | | |||
289 | return -1; | 303 | return -1; | ||
290 | } | 304 | } | ||
291 | 305 | | |||
292 | qint8 KisColorSelector::getLightIndex(qreal light) const | 306 | qint8 KisColorSelector::getLightIndex(qreal light) const | ||
293 | { | 307 | { | ||
294 | light = qreal(1) - qBound(qreal(0), light, qreal(1)); | 308 | light = qreal(1) - qBound(qreal(0), light, qreal(1)); | ||
295 | return qint8(qRound(light * (getNumLightPieces()-1))); | 309 | return qint8(qRound(light * (getNumLightPieces()-1))); | ||
296 | } | 310 | } | ||
297 | 311 | | |||
298 | qreal KisColorSelector::getLight(qreal light, qreal hue, bool relative) const | | |||
299 | { | | |||
300 | if (relative) { | | |||
301 | KisColor color(hue, 1.0f, m_colorSpace); | | |||
302 | qreal cl = color.getX(); | | |||
303 | light = (light * 2.0f) - 1.0f; | | |||
304 | return (light < 0.0f) ? (cl + cl*light) : (cl + (1.0f-cl)*light); | | |||
305 | } | | |||
306 | | ||||
307 | return light; | | |||
308 | } | | |||
309 | | ||||
310 | qreal KisColorSelector::getLight(const QPointF& pt) const | 312 | qreal KisColorSelector::getLight(const QPointF& pt) const | ||
311 | { | 313 | { | ||
312 | qint8 clickedLightPiece = getLightIndex(pt); | 314 | qint8 clickedLightPiece = getLightIndex(pt); | ||
313 | 315 | | |||
314 | if (clickedLightPiece >= 0) { | 316 | if (clickedLightPiece >= 0) { | ||
315 | if (getNumLightPieces() > 1) { | 317 | if (getNumLightPieces() > 1) { | ||
316 | return 1.0 - (qreal(clickedLightPiece) / qreal(getNumLightPieces()-1)); | 318 | return 1.0 - (qreal(clickedLightPiece) / qreal(getNumLightPieces()-1)); | ||
317 | } | 319 | } | ||
318 | return 1.0 - (qreal(pt.y()) / qreal(m_lightStripArea.height())); | 320 | return 1.0 - (qreal(pt.y()) / qreal(m_lightStripArea.height())); | ||
319 | } | 321 | } | ||
320 | 322 | | |||
321 | return qreal(0); | 323 | return qreal(0); | ||
322 | } | 324 | } | ||
323 | 325 | | |||
324 | qint8 KisColorSelector::getHueIndex(Radian hue, Radian shift) const | 326 | qint8 KisColorSelector::getHueIndex(Radian hue) const | ||
325 | { | 327 | { | ||
326 | hue -= shift; | | |||
327 | qreal partSize = 1.0 / qreal(getNumPieces()); | 328 | qreal partSize = 1.0 / qreal(getNumPieces()); | ||
328 | return qint8(qRound(hue.scaled(0.0f, 1.0f) / partSize) % getNumPieces()); | 329 | return qint8(qRound(hue.scaled(0.0f, 1.0f) / partSize) % getNumPieces()); | ||
329 | } | 330 | } | ||
330 | 331 | | |||
331 | qreal KisColorSelector::getHue(int hueIdx, Radian shift) const | 332 | qreal KisColorSelector::getHue(int hueIdx, Radian shift) const | ||
332 | { | 333 | { | ||
333 | Radian hue = (qreal(hueIdx) / qreal(getNumPieces())) * PI2; | 334 | Radian hue = (qreal(hueIdx) / qreal(getNumPieces())) * PI2; | ||
334 | hue += shift; | 335 | hue += shift; | ||
Show All 22 Lines | |||||
357 | qreal KisColorSelector::getSaturation(int saturationIdx) const | 358 | qreal KisColorSelector::getSaturation(int saturationIdx) const | ||
358 | { | 359 | { | ||
359 | qreal sat = qreal(saturationIdx) / qreal(getNumRings()-1); | 360 | qreal sat = qreal(saturationIdx) / qreal(getNumRings()-1); | ||
360 | return m_inverseSaturation ? (1.0 - sat) : sat; | 361 | return m_inverseSaturation ? (1.0 - sat) : sat; | ||
361 | } | 362 | } | ||
362 | 363 | | |||
363 | void KisColorSelector::recalculateAreas(quint8 numLightPieces) | 364 | void KisColorSelector::recalculateAreas(quint8 numLightPieces) | ||
364 | { | 365 | { | ||
365 | const qreal LIGHT_STRIP_RATIO = 0.075; | 366 | | ||
367 | qreal LIGHT_STRIP_RATIO = 0.075; | ||||
368 | if (m_showValueScaleNumbers) { | ||||
369 | LIGHT_STRIP_RATIO = 0.25; | ||||
370 | } | ||||
366 | 371 | | |||
367 | int width = QWidget::width(); | 372 | int width = QWidget::width(); | ||
368 | int height = QWidget::height(); | 373 | int height = QWidget::height(); | ||
369 | int size = qMin(width, height); | 374 | int size = qMin(width, height); | ||
370 | int stripThick = int(size * LIGHT_STRIP_RATIO); | 375 | int stripThick = int(size * LIGHT_STRIP_RATIO); | ||
371 | 376 | | |||
372 | width -= stripThick; | 377 | width -= stripThick; | ||
373 | 378 | | |||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | 437 | { | |||
446 | } | 451 | } | ||
447 | 452 | | |||
448 | return false; | 453 | return false; | ||
449 | } | 454 | } | ||
450 | 455 | | |||
451 | 456 | | |||
452 | void KisColorSelector::requestUpdateColorAndPreview(const KisColor &color, Acs::ColorRole role) | 457 | void KisColorSelector::requestUpdateColorAndPreview(const KisColor &color, Acs::ColorRole role) | ||
453 | { | 458 | { | ||
459 | #ifdef DEBUG_ARC_SELECTOR | ||||
454 | dbgPlugins << "KisColorSelector::requestUpdateColorAndPreview: requesting update to: " | 460 | dbgPlugins << "KisColorSelector::requestUpdateColorAndPreview: requesting update to: " | ||
455 | << "H:" << color.getH() | 461 | << "H:" << color.getH() | ||
456 | << "S:" << color.getS() | 462 | << "S:" << color.getS() | ||
457 | << "X:" << color.getX(); | 463 | << "X:" << color.getX(m_gamma); | ||
458 | 464 | #endif | |||
459 | m_updateColorCompressor->start(qMakePair(color, role)); | 465 | m_updateColorCompressor->start(qMakePair(color, role)); | ||
460 | } | 466 | } | ||
461 | 467 | | |||
462 | void KisColorSelector::slotUpdateColorAndPreview(QPair<KisColor, Acs::ColorRole> color) | 468 | void KisColorSelector::slotUpdateColorAndPreview(QPair<KisColor, Acs::ColorRole> color) | ||
463 | { | 469 | { | ||
464 | const bool selectAsFgColor = color.second == Acs::Foreground; | 470 | const bool selectAsFgColor = color.second == Acs::Foreground; | ||
465 | 471 | | |||
466 | if (selectAsFgColor) { m_fgColor = color.first; } | 472 | if (selectAsFgColor) { m_fgColor = color.first; } | ||
467 | else { m_bgColor = color.first; } | 473 | else { m_bgColor = color.first; } | ||
468 | 474 | | |||
469 | m_selectedColor = color.first; | 475 | m_selectedColor = color.first; | ||
470 | m_selectedColorRole = color.second; | | |||
471 | 476 | | |||
477 | #ifdef DEBUG_ARC_SELECTOR | ||||
472 | dbgPlugins << "KisColorSelector::slotUpdateColorAndPreview: m_selectedColor set to:" | 478 | dbgPlugins << "KisColorSelector::slotUpdateColorAndPreview: m_selectedColor set to:" | ||
473 | << "H:" << m_selectedColor.getH() | 479 | << "H:" << m_selectedColor.getH() | ||
474 | << "S:" << m_selectedColor.getS() | 480 | << "S:" << m_selectedColor.getS() | ||
475 | << "X:" << m_selectedColor.getX() | 481 | << "X:" << m_selectedColor.getX(m_gamma); | ||
476 | << "role:" << m_selectedColorRole; | 482 | #endif | ||
477 | | ||||
478 | 483 | | |||
479 | if (selectAsFgColor) { emit sigFgColorChanged(m_selectedColor); } | 484 | if (selectAsFgColor) { emit sigFgColorChanged(m_selectedColor); } | ||
480 | else { emit sigBgColorChanged(m_selectedColor); } | 485 | else { emit sigBgColorChanged(m_selectedColor); } | ||
481 | } | 486 | } | ||
482 | 487 | | |||
483 | void KisColorSelector::drawRing(QPainter& painter, int ringIndex, KisColorSelector::ColorRing& ring, const QRect& rect) | 488 | void KisColorSelector::drawRing(QPainter& painter, KisColorSelector::ColorRing& ring, const QRect& rect) | ||
484 | { | 489 | { | ||
485 | painter.save(); | 490 | painter.save(); | ||
486 | painter.setRenderHint(QPainter::Antialiasing, true); | 491 | painter.setRenderHint(QPainter::Antialiasing, true); | ||
487 | painter.resetTransform(); | 492 | painter.resetTransform(); | ||
488 | painter.translate(rect.width()/2, rect.height()/2); | 493 | painter.translate(rect.width()/2, rect.height()/2); | ||
489 | 494 | | |||
490 | if (ring.pieced.size() > 1) { | 495 | if (ring.pieced.size() > 1) { | ||
491 | painter.rotate(-ring.getShift().degrees()); | 496 | QTransform mirror; | ||
497 | mirror.rotate(180, Qt::YAxis); | ||||
498 | painter.setTransform(mirror, true); | ||||
492 | painter.scale(rect.width()/2, rect.height()/2); | 499 | painter.scale(rect.width()/2, rect.height()/2); | ||
493 | // painter.setPen(Qt::NoPen); | 500 | QPen normalPen = QPen(QBrush(COLOR_NORMAL_OUTLINE), 0.005); | ||
494 | QPen normalPen = QPen(QBrush(m_grayColor), 0.005); | 501 | QPen clearMaskPen = QPen(QBrush(COLOR_MASK_CLEAR), 0.005); | ||
495 | QPen clearMaskPen = QPen(QBrush(Qt::white), 0.005); | | |||
496 | QBrush brush(Qt::SolidPattern); | 502 | QBrush brush(Qt::SolidPattern); | ||
497 | 503 | | |||
498 | for(int i=0; i<ring.pieced.size(); ++i) { | 504 | for(int i=0; i<ring.pieced.size(); ++i) { | ||
499 | float hue = float(i) / float(ring.pieced.size()) + ring.getShift().scaled(0.0f, 1.0f); | 505 | float hue = float(i) / float(ring.pieced.size()); | ||
500 | hue = (hue >= 1.0f) ? (hue - 1.0f) : hue; | 506 | hue = (hue >= 1.0f) ? (hue - 1.0f) : hue; | ||
501 | hue = (hue < 0.0f) ? (hue + 1.0f) : hue; | 507 | hue = (hue < 0.0f) ? (hue + 1.0f) : hue; | ||
502 | 508 | | |||
503 | KisColor color(hue, 1.0f, m_colorSpace); | 509 | KisColor color(hue, 1.0f, m_colorSpace); | ||
504 | color.setS(ring.saturation); | 510 | color.setS(ring.saturation); | ||
505 | color.setX(getLight(m_light, hue, m_relativeLight)); | 511 | color.setX(m_selectedColor.getX(m_gamma), m_gamma); | ||
506 | 512 | | |||
507 | if(m_gamutMaskOn && m_enforceGamutMask && colorIsClear(color)) { | 513 | if(m_gamutMaskOn && m_enforceGamutMask && colorIsClear(color)) { | ||
508 | painter.setPen(clearMaskPen); | 514 | painter.setPen(clearMaskPen); | ||
509 | } else { | 515 | } else { | ||
510 | painter.setPen(normalPen); | 516 | painter.setPen(normalPen); | ||
511 | } | 517 | } | ||
512 | 518 | | |||
513 | if ((m_enforceGamutMask) && (!colorIsClear(color))) { | 519 | if ((m_enforceGamutMask) && (!colorIsClear(color))) { | ||
514 | brush.setColor(m_gamutMaskColor); | 520 | brush.setColor(COLOR_MASK_FILL); | ||
515 | } else { | 521 | } else { | ||
516 | brush.setColor(color.getQColor()); | 522 | brush.setColor(color.getQColor()); | ||
517 | } | 523 | } | ||
518 | painter.setBrush(brush); | 524 | painter.setBrush(brush); | ||
519 | 525 | | |||
520 | painter.drawPath(ring.pieced[i]); | 526 | painter.drawPath(ring.pieced[i]); | ||
521 | } | 527 | } | ||
522 | } | 528 | } | ||
523 | else { | 529 | else { | ||
524 | KisColor colors[7] = { | 530 | KisColor colors[7] = { | ||
525 | KisColor(Qt::red , m_colorSpace), | | |||
526 | KisColor(Qt::yellow , m_colorSpace), | | |||
527 | KisColor(Qt::green , m_colorSpace), | | |||
528 | KisColor(Qt::cyan , m_colorSpace), | 531 | KisColor(Qt::cyan , m_colorSpace), | ||
529 | KisColor(Qt::blue , m_colorSpace), | 532 | KisColor(Qt::green , m_colorSpace), | ||
533 | KisColor(Qt::yellow , m_colorSpace), | ||||
534 | KisColor(Qt::red , m_colorSpace), | ||||
530 | KisColor(Qt::magenta, m_colorSpace), | 535 | KisColor(Qt::magenta, m_colorSpace), | ||
531 | KisColor(Qt::red , m_colorSpace) | 536 | KisColor(Qt::blue , m_colorSpace), | ||
537 | KisColor(Qt::cyan , m_colorSpace) | ||||
532 | }; | 538 | }; | ||
533 | 539 | | |||
534 | QConicalGradient gradient(0, 0, 0); | 540 | QConicalGradient gradient(0, 0, 0); | ||
535 | 541 | | |||
536 | for(int i=0; i<=6; ++i) { | 542 | for(int i=0; i<=6; ++i) { | ||
537 | qreal hue = float(i) / 6.0f; | 543 | qreal hue = float(i) / 6.0f; | ||
538 | colors[i].setS(ring.saturation); | 544 | colors[i].setS(ring.saturation); | ||
539 | colors[i].setX(getLight(m_light, hue, m_relativeLight)); | 545 | colors[i].setX(m_selectedColor.getX(m_gamma), m_gamma); | ||
540 | gradient.setColorAt(hue, colors[i].getQColor()); | 546 | gradient.setColorAt(hue, colors[i].getQColor()); | ||
541 | } | 547 | } | ||
542 | 548 | | |||
543 | painter.scale(rect.width()/2, rect.height()/2); | 549 | painter.scale(rect.width()/2, rect.height()/2); | ||
544 | painter.fillPath(ring.pieced[0], QBrush(gradient)); | 550 | painter.fillPath(ring.pieced[0], QBrush(gradient)); | ||
545 | } | 551 | } | ||
546 | 552 | | |||
547 | // painter.resetTransform(); | | |||
548 | painter.restore(); | 553 | painter.restore(); | ||
549 | } | 554 | } | ||
550 | 555 | | |||
551 | void KisColorSelector::drawOutline(QPainter& painter, const QRect& rect) | 556 | void KisColorSelector::drawOutline(QPainter& painter, const QRect& rect) | ||
552 | { | 557 | { | ||
553 | painter.setRenderHint(QPainter::Antialiasing, true); | 558 | painter.setRenderHint(QPainter::Antialiasing, true); | ||
554 | painter.resetTransform(); | 559 | painter.resetTransform(); | ||
555 | painter.translate(rect.x() + rect.width()/2, rect.y() + rect.height()/2); | 560 | painter.translate(rect.x() + rect.width()/2, rect.y() + rect.height()/2); | ||
556 | painter.scale(rect.width()/2, rect.height()/2); | 561 | painter.scale(rect.width()/2, rect.height()/2); | ||
557 | 562 | | |||
558 | QPen normalPen = QPen(QBrush(m_grayColor), 0.005); | 563 | QPen normalPen = QPen(QBrush(COLOR_NORMAL_OUTLINE), 0.005); | ||
559 | QPen selectedPen = QPen(QBrush(Qt::red), 0.01); | 564 | QPen selectedPen = QPen(QBrush(COLOR_SELECTED), 0.01); | ||
560 | 565 | | |||
561 | painter.setPen(normalPen); | 566 | painter.setPen(normalPen); | ||
562 | 567 | | |||
563 | if (getNumPieces() > 1) { | 568 | if (getNumPieces() > 1) { | ||
564 | // for(int i=0; i<getNumRings(); ++i) { | | |||
565 | // painter.resetTransform(); | | |||
566 | // painter.translate(rect.x() + rect.width()/2, rect.y() + rect.height()/2); | | |||
567 | // painter.scale(rect.width()/2, rect.height()/2); | | |||
568 | // painter.rotate(-m_colorRings[i].getShift().degrees()); | | |||
569 | | ||||
570 | // for(int j=0; j<m_colorRings[i].pieced.size(); ++j) | | |||
571 | // painter.drawPath(m_colorRings[i].pieced[j]); | | |||
572 | // } | | |||
573 | | ||||
574 | if (m_selectedRing >= 0 && m_selectedPiece >= 0) { | 569 | if (m_selectedRing >= 0 && m_selectedPiece >= 0) { | ||
575 | painter.resetTransform(); | 570 | painter.resetTransform(); | ||
576 | painter.translate(rect.x() + rect.width()/2, rect.y() + rect.height()/2); | 571 | painter.translate(rect.x() + rect.width()/2, rect.y() + rect.height()/2); | ||
577 | painter.rotate(-m_colorRings[m_selectedRing].getShift().degrees()); | 572 | QTransform mirror; | ||
573 | mirror.rotate(180, Qt::YAxis); | ||||
574 | painter.setTransform(mirror, true); | ||||
578 | painter.scale(rect.width()/2, rect.height()/2); | 575 | painter.scale(rect.width()/2, rect.height()/2); | ||
579 | 576 | | |||
580 | painter.setPen(selectedPen); | 577 | painter.setPen(selectedPen); | ||
581 | painter.drawPath(m_colorRings[m_selectedRing].pieced[m_selectedPiece]); | 578 | painter.drawPath(m_colorRings[m_selectedRing].pieced[m_selectedPiece]); | ||
582 | } | 579 | } | ||
583 | } | 580 | } | ||
584 | else { | 581 | else { | ||
585 | for(int i=0; i<getNumRings(); ++i) { | 582 | for(int i=0; i<getNumRings(); ++i) { | ||
586 | qreal rad = m_colorRings[i].outerRadius; | 583 | qreal rad = m_colorRings[i].outerRadius; | ||
587 | painter.drawEllipse(QRectF(-rad, -rad, rad*2.0, rad*2.0)); | 584 | painter.drawEllipse(QRectF(-rad, -rad, rad*2.0, rad*2.0)); | ||
588 | } | 585 | } | ||
589 | 586 | | |||
590 | if (m_selectedRing >= 0) { | 587 | if (m_selectedRing >= 0) { | ||
591 | qreal iRad = m_colorRings[m_selectedRing].innerRadius; | 588 | qreal iRad = m_colorRings[m_selectedRing].innerRadius; | ||
592 | qreal oRad = m_colorRings[m_selectedRing].outerRadius; | 589 | qreal oRad = m_colorRings[m_selectedRing].outerRadius; | ||
593 | 590 | | |||
594 | painter.setPen(selectedPen); | 591 | painter.setPen(selectedPen); | ||
595 | painter.drawEllipse(QRectF(-iRad, -iRad, iRad*2.0, iRad*2.0)); | 592 | painter.drawEllipse(QRectF(-iRad, -iRad, iRad*2.0, iRad*2.0)); | ||
596 | painter.drawEllipse(QRectF(-oRad, -oRad, oRad*2.0, oRad*2.0)); | 593 | painter.drawEllipse(QRectF(-oRad, -oRad, oRad*2.0, oRad*2.0)); | ||
597 | 594 | | |||
598 | float c = std::cos(-m_selectedColor.getH() * PI2); | 595 | QPointF lineCoords = mapHueToAngle(m_selectedColor.getH()); | ||
599 | float s = std::sin(-m_selectedColor.getH() * PI2); | 596 | painter.drawLine(QPointF(lineCoords.x()*iRad, lineCoords.y()*iRad), QPointF(lineCoords.x()*oRad, lineCoords.y()*oRad)); | ||
600 | painter.drawLine(QPointF(c*iRad, s*iRad), QPointF(c*oRad, s*oRad)); | | |||
601 | } | 597 | } | ||
602 | } | 598 | } | ||
603 | } | 599 | } | ||
604 | 600 | | |||
605 | void KisColorSelector::drawLightStrip(QPainter& painter, const QRect& rect) | 601 | void KisColorSelector::drawLightStrip(QPainter& painter, const QRect& rect) | ||
606 | { | 602 | { | ||
607 | bool isVertical = true; | | |||
608 | qreal penSize = qreal(qMin(QWidget::width(), QWidget::height())) / 200.0; | 603 | qreal penSize = qreal(qMin(QWidget::width(), QWidget::height())) / 200.0; | ||
609 | KisColor color(m_fgColor); | 604 | KisColor valueScaleColor(m_selectedColor); | ||
605 | KisColor grayScaleColor(Qt::gray, m_colorSpace); | ||||
606 | int rectSize = rect.height(); | ||||
610 | 607 | | |||
611 | painter.resetTransform(); | 608 | painter.resetTransform(); | ||
612 | 609 | painter.save(); | |||
613 | if (getNumLightPieces() > 1) { | | |||
614 | painter.setRenderHint(QPainter::Antialiasing, true); | 610 | painter.setRenderHint(QPainter::Antialiasing, true); | ||
615 | painter.setPen(QPen(QBrush(Qt::red), penSize)); | | |||
616 | 611 | | |||
617 | QTransform matrix; | 612 | QTransform matrix; | ||
618 | matrix.translate(rect.x(), rect.y()); | 613 | matrix.translate(rect.x(), rect.y()); | ||
619 | matrix.scale(rect.width(), rect.height()); | 614 | matrix.scale(rect.width(), rect.height()); | ||
620 | 615 | | |||
616 | qreal rectColorLeftX; | ||||
617 | qreal rectColorWidth; | ||||
618 | | ||||
619 | if (m_showValueScaleNumbers) { | ||||
620 | rectColorLeftX = 0.6; | ||||
621 | rectColorWidth = 0.4; | ||||
622 | } else { | ||||
623 | rectColorLeftX = 0.0; | ||||
624 | rectColorWidth = 1.0; | ||||
625 | } | ||||
626 | | ||||
627 | if (getNumLightPieces() > 1) { | ||||
621 | for(int i=0; i<getNumLightPieces(); ++i) { | 628 | for(int i=0; i<getNumLightPieces(); ++i) { | ||
622 | float t1 = float(i) / float(getNumLightPieces()); | 629 | float t1 = float(i) / float(getNumLightPieces()); | ||
623 | float t2 = float(i+1) / float(getNumLightPieces()); | 630 | float t2 = float(i+1) / float(getNumLightPieces()); | ||
624 | float light = 1.0f - (float(i) / float(getNumLightPieces()-1)); | 631 | float light = 1.0f - (float(i) / float(getNumLightPieces()-1)); | ||
625 | float diff = t2 - t1;// + 0.001; | 632 | float diff = t2 - t1;// + 0.001; | ||
626 | QRectF r = isVertical ? QRectF(0.0, t1, 1.0, diff) : QRect(t1, 0.0, diff, 1.0); | | |||
627 | 633 | | |||
628 | color.setX(getLight(light, color.getH(), m_relativeLight)); | 634 | QRectF rectColor = QRectF(rectColorLeftX, t1, rectColorWidth, diff); | ||
635 | rectColor = matrix.mapRect(rectColor); | ||||
629 | 636 | | |||
630 | r = matrix.mapRect(r); | 637 | valueScaleColor.setX(light, m_gamma); | ||
631 | painter.fillRect(r, color.getQColor()); | | |||
632 | 638 | | |||
633 | if (i == m_selectedLightPiece) | 639 | painter.fillRect(rectColor, valueScaleColor.getQColor()); | ||
634 | painter.drawRect(r); | | |||
635 | 640 | | |||
636 | if (m_showValueScaleNumbers) { | 641 | if (i == m_selectedLightPiece) { | ||
637 | int valueNumber = light*100; | 642 | painter.setPen(QPen(QBrush(COLOR_SELECTED), penSize)); | ||
638 | painter.drawText(r, Qt::AlignCenter, QString::number(valueNumber)); | 643 | painter.drawRect(rectColor); | ||
639 | } | 644 | } | ||
640 | } | 645 | } | ||
641 | } | 646 | } | ||
642 | else { | 647 | else { | ||
643 | int size = isVertical ? rect.height() : rect.width(); | | |||
644 | painter.setRenderHint(QPainter::Antialiasing, false); | 648 | painter.setRenderHint(QPainter::Antialiasing, false); | ||
645 | 649 | | |||
646 | if (isVertical) { | 650 | for(int i=0; i<rectSize; ++i) { | ||
647 | for(int i=0; i<size; ++i) { | | |||
648 | int y = rect.y() + i; | 651 | int y = rect.y() + i; | ||
649 | float light = 1.0f - (float(i) / float(size-1)); | 652 | float light = 1.0f - (float(i) / float(rectSize-1)); | ||
650 | color.setX(getLight(light, color.getH(), m_relativeLight)); | 653 | valueScaleColor.setX(light, m_gamma); | ||
651 | painter.setPen(color.getQColor()); | 654 | painter.setPen(QPen(QBrush(valueScaleColor.getQColor()), penSize)); | ||
652 | painter.drawLine(rect.left(), y, rect.right(), y); | 655 | painter.drawLine(rect.left(), y, rect.right(), y); | ||
653 | } | 656 | } | ||
657 | | ||||
658 | painter.setRenderHint(QPainter::Antialiasing, true); | ||||
659 | | ||||
660 | painter.setPen(QPen(QBrush(COLOR_SELECTED), penSize)); | ||||
661 | float t = 1.0f - m_selectedColor.getX(m_gamma); | ||||
662 | | ||||
663 | int y = rect.y() + int(rectSize * t); | ||||
664 | painter.drawLine(rect.left(), y, rect.right(), y); | ||||
654 | } | 665 | } | ||
655 | else { | 666 | | ||
656 | for(int i=0; i<size; ++i) { | 667 | if (m_showColorBlip) { | ||
657 | int x = rect.x() + i; | 668 | painter.setRenderHint(QPainter::Antialiasing, false); | ||
658 | float light = 1.0f - (float(i) / float(size-1)); | 669 | // draw position of fg color value on the strip | ||
659 | color.setX(getLight(light, color.getH(), m_relativeLight)); | 670 | float fgColorValue = 1.0f - m_fgColor.getX(m_gamma); | ||
660 | painter.setPen(color.getQColor()); | 671 | | ||
661 | painter.drawLine(x, rect.top(), x, rect.bottom()); | 672 | int y = rect.y() + int(rectSize * fgColorValue); | ||
662 | } | 673 | painter.setPen(QPen(QBrush(COLOR_LIGHT), penSize)); | ||
674 | painter.drawLine(rect.left(), y, rect.right(), y); | ||||
675 | painter.setPen(QPen(QBrush(COLOR_DARK), penSize)); | ||||
676 | painter.drawLine(rect.left(), y+1.5*penSize, rect.right(), y+1.5*penSize); | ||||
663 | } | 677 | } | ||
664 | 678 | | |||
679 | if (m_showValueScaleNumbers) { | ||||
665 | painter.setRenderHint(QPainter::Antialiasing, true); | 680 | painter.setRenderHint(QPainter::Antialiasing, true); | ||
666 | painter.setPen(QPen(QBrush(Qt::red), penSize)); | | |||
667 | float t = 1.0f - m_light; | | |||
668 | 681 | | |||
669 | if (isVertical) { | 682 | int valueScalePieces = getNumLightPieces(); | ||
670 | int y = rect.y() + int(size * t); | 683 | if (getNumLightPieces() == 1) { | ||
671 | painter.drawLine(rect.left(), y, rect.right(), y); | 684 | valueScalePieces = 11; | ||
672 | } | 685 | } | ||
673 | else { | 686 | | ||
674 | int x = rect.x() + int(size * t); | 687 | for(int i=0; i<valueScalePieces; ++i) { | ||
675 | painter.drawLine(x, rect.top(), x, rect.bottom()); | 688 | float t1 = float(i) / float(valueScalePieces); | ||
689 | float t2 = float(i+1) / float(valueScalePieces); | ||||
690 | float light = 1.0f - (float(i) / float(valueScalePieces-1)); | ||||
691 | float diff = t2 - t1;// + 0.001; | ||||
692 | | ||||
693 | grayScaleColor.setX(light, m_gamma); | ||||
694 | | ||||
695 | QRectF rectValue = QRectF(0.0, t1, rectColorLeftX, diff); | ||||
696 | rectValue = matrix.mapRect(rectValue); | ||||
697 | | ||||
698 | painter.fillRect(rectValue, grayScaleColor.getQColor()); | ||||
699 | | ||||
700 | int valueNumber = (1.0 - grayScaleColor.getX())*100; | ||||
701 | | ||||
702 | if (valueNumber < 55) { | ||||
703 | painter.setPen(QPen(QBrush(COLOR_DARK), penSize)); | ||||
704 | } else { | ||||
705 | painter.setPen(QPen(QBrush(COLOR_LIGHT), penSize)); | ||||
706 | } | ||||
707 | | ||||
708 | painter.drawText(rectValue, Qt::AlignRight|Qt::AlignBottom, QString("%1%").arg(QString::number(valueNumber))); | ||||
676 | } | 709 | } | ||
677 | } | 710 | } | ||
711 | | ||||
712 | painter.restore(); | ||||
678 | } | 713 | } | ||
679 | 714 | | |||
680 | void KisColorSelector::drawBlip(QPainter& painter, const QRect& rect) | 715 | void KisColorSelector::drawBlip(QPainter& painter, const QRect& rect) | ||
681 | { | 716 | { | ||
682 | painter.setRenderHint(QPainter::Antialiasing, false); | 717 | painter.setRenderHint(QPainter::Antialiasing, false); | ||
683 | painter.resetTransform(); | 718 | painter.resetTransform(); | ||
684 | painter.translate(rect.x() + rect.width()/2, rect.y() + rect.height()/2); | 719 | painter.translate(rect.x() + rect.width()/2, rect.y() + rect.height()/2); | ||
685 | painter.scale(rect.width()/2, rect.height()/2); | 720 | painter.scale(rect.width()/2, rect.height()/2); | ||
686 | 721 | | |||
687 | QPointF fgColorPos = mapColorToUnit(m_fgColor); | 722 | QPointF fgColorPos = mapColorToUnit(m_fgColor); | ||
688 | 723 | | |||
724 | #ifdef DEBUG_ARC_SELECTOR | ||||
689 | dbgPlugins << "KisColorSelector::drawBlip: " | 725 | dbgPlugins << "KisColorSelector::drawBlip: " | ||
690 | << "colorPoint H:" << m_fgColor.getH() << " S:" << m_fgColor.getS() | 726 | << "colorPoint H:" << m_fgColor.getH() << " S:" << m_fgColor.getS() | ||
691 | << "-> coord X:" << fgColorPos.x() << " Y:" << fgColorPos.y(); | 727 | << "-> coord X:" << fgColorPos.x() << " Y:" << fgColorPos.y(); | ||
728 | #endif | ||||
692 | 729 | | |||
693 | 730 | painter.setPen(QPen(QBrush(COLOR_LIGHT), 0.01)); | |||
694 | painter.setPen(QPen(QBrush(Qt::white), 0.01)); | | |||
695 | painter.drawEllipse(fgColorPos, 0.05, 0.05); | 731 | painter.drawEllipse(fgColorPos, 0.05, 0.05); | ||
696 | 732 | | |||
697 | painter.setPen(QPen(QBrush(Qt::black), 0.01)); | 733 | painter.setPen(QPen(QBrush(COLOR_DARK), 0.01)); | ||
698 | painter.setBrush(m_fgColor.getQColor()); | 734 | painter.setBrush(m_fgColor.getQColor()); | ||
699 | painter.drawEllipse(fgColorPos, 0.04, 0.04); | 735 | painter.drawEllipse(fgColorPos, 0.04, 0.04); | ||
700 | } | 736 | } | ||
701 | 737 | | |||
702 | void KisColorSelector::drawGamutMaskShape(QPainter &painter, const QRect &rect) | 738 | void KisColorSelector::drawGamutMaskShape(QPainter &painter, const QRect &rect) | ||
703 | { | 739 | { | ||
704 | painter.save(); | 740 | painter.save(); | ||
705 | painter.setRenderHint(QPainter::Antialiasing, true); | 741 | painter.setRenderHint(QPainter::Antialiasing, true); | ||
706 | 742 | | |||
707 | painter.resetTransform(); | 743 | painter.resetTransform(); | ||
708 | painter.translate(rect.width()/2, rect.height()/2); | 744 | painter.translate(rect.width()/2, rect.height()/2); | ||
709 | painter.scale(rect.width()/2, rect.height()/2); | 745 | painter.scale(rect.width()/2, rect.height()/2); | ||
710 | 746 | | |||
711 | painter.setPen(Qt::NoPen); | 747 | painter.setPen(Qt::NoPen); | ||
712 | painter.setBrush(m_gamutMaskColor); | 748 | painter.setBrush(COLOR_MASK_FILL); | ||
713 | 749 | | |||
714 | painter.drawEllipse(QPointF(0,0), 1.0, 1.0); | 750 | painter.drawEllipse(QPointF(0,0), 1.0, 1.0); | ||
715 | 751 | | |||
716 | painter.resetTransform(); | 752 | painter.resetTransform(); | ||
717 | // painter.setCompositionMode(QPainter::CompositionMode_Xor); | | |||
718 | painter.setCompositionMode(QPainter::CompositionMode_DestinationIn); | | |||
719 | 753 | | |||
754 | painter.setCompositionMode(QPainter::CompositionMode_DestinationIn); | ||||
720 | m_currentGamutMask->paint(painter, *m_viewConverter, m_maskPreviewActive); | 755 | m_currentGamutMask->paint(painter, *m_viewConverter, m_maskPreviewActive); | ||
721 | 756 | | |||
757 | painter.setCompositionMode(QPainter::CompositionMode_SourceOver); | ||||
758 | m_currentGamutMask->paintStroke(painter, *m_viewConverter, m_maskPreviewActive); | ||||
759 | | ||||
722 | painter.restore(); | 760 | painter.restore(); | ||
723 | } | 761 | } | ||
724 | 762 | | |||
725 | void KisColorSelector::paintEvent(QPaintEvent* /*event*/) | 763 | void KisColorSelector::paintEvent(QPaintEvent* /*event*/) | ||
726 | { | 764 | { | ||
727 | // 0 red -> (1,0,0) | 765 | // 0 red -> (1,0,0) | ||
728 | // 1 yellow -> (1,1,0) | 766 | // 1 yellow -> (1,1,0) | ||
729 | // 2 green -> (0,1,0) | 767 | // 2 green -> (0,1,0) | ||
Show All 27 Lines | 788 | if (m_showBgColor) { | |||
757 | wdgPainter.setBrush(m_bgColor.getQColor()); | 795 | wdgPainter.setBrush(m_bgColor.getQColor()); | ||
758 | wdgPainter.setPen(m_bgColor.getQColor()); | 796 | wdgPainter.setPen(m_bgColor.getQColor()); | ||
759 | wdgPainter.drawPolygon(bgPolyPoints, 3); | 797 | wdgPainter.drawPolygon(bgPolyPoints, 3); | ||
760 | } | 798 | } | ||
761 | 799 | | |||
762 | wdgPainter.restore(); | 800 | wdgPainter.restore(); | ||
763 | 801 | | |||
764 | for(int i=0; i<m_colorRings.size(); ++i) | 802 | for(int i=0; i<m_colorRings.size(); ++i) | ||
765 | drawRing(imgPainter, i, m_colorRings[i], m_renderArea); | 803 | drawRing(imgPainter, m_colorRings[i], m_renderArea); | ||
766 | 804 | | |||
767 | wdgPainter.drawImage(m_renderArea, m_renderBuffer); | 805 | wdgPainter.drawImage(m_renderArea, m_renderBuffer); | ||
768 | 806 | | |||
769 | | ||||
770 | // draw the mask either in continuous mode or in discrete mode when enforcing is turned off | 807 | // draw the mask either in continuous mode or in discrete mode when enforcing is turned off | ||
771 | // if enforcing is turned on in discrete mode, | 808 | // if enforcing is turned on in discrete mode, | ||
772 | // drawRing function takes care of delineating the mask swatches | 809 | // drawRing function takes care of delineating the mask swatches | ||
773 | if (m_gamutMaskOn | 810 | if (m_gamutMaskOn | ||
774 | && ((getNumPieces() == 1) || (!m_enforceGamutMask))) { | 811 | && ((getNumPieces() == 1) || (!m_enforceGamutMask))) { | ||
775 | 812 | | |||
776 | m_maskBuffer.fill(0); | 813 | m_maskBuffer.fill(0); | ||
777 | QPainter maskPainter(&m_maskBuffer); | 814 | QPainter maskPainter(&m_maskBuffer); | ||
Show All 9 Lines | |||||
787 | if (m_showColorBlip) { | 824 | if (m_showColorBlip) { | ||
788 | drawBlip (wdgPainter, m_renderArea); | 825 | drawBlip (wdgPainter, m_renderArea); | ||
789 | } | 826 | } | ||
790 | } | 827 | } | ||
791 | 828 | | |||
792 | void KisColorSelector::mousePressEvent(QMouseEvent* event) | 829 | void KisColorSelector::mousePressEvent(QMouseEvent* event) | ||
793 | { | 830 | { | ||
794 | m_widgetUpdatesSelf = true; | 831 | m_widgetUpdatesSelf = true; | ||
832 | #ifdef DEBUG_ARC_SELECTOR | ||||
795 | dbgPlugins << "KisColorSelector::mousePressEvent: m_widgetUpdatesSelf = true"; | 833 | dbgPlugins << "KisColorSelector::mousePressEvent: m_widgetUpdatesSelf = true"; | ||
834 | #endif | ||||
796 | 835 | | |||
797 | m_clickPos = mapCoordToUnit(event->localPos(), m_renderArea); | 836 | m_clickPos = mapCoordToUnit(event->localPos(), m_renderArea); | ||
798 | m_mouseMoved = false; | 837 | m_mouseMoved = false; | ||
799 | m_pressedButtons = event->buttons(); | 838 | m_pressedButtons = event->buttons(); | ||
800 | m_clickedRing = getSaturationIndex(m_clickPos); | 839 | m_clickedRing = getSaturationIndex(m_clickPos); | ||
840 | Acs::ColorRole colorRole = Acs::buttonsToRole(Qt::NoButton, m_pressedButtons); | ||||
801 | 841 | | |||
802 | qint8 clickedLightPiece = getLightIndex(event->localPos()); | 842 | qint8 clickedLightPiece = getLightIndex(event->localPos()); | ||
803 | 843 | | |||
804 | if (clickedLightPiece >= 0) { | 844 | if (clickedLightPiece >= 0) { | ||
805 | setLight(getLight(event->localPos()), m_relativeLight); | 845 | setLight(getLight(event->localPos())); | ||
806 | m_selectedLightPiece = clickedLightPiece; | 846 | m_selectedLightPiece = clickedLightPiece; | ||
807 | requestUpdateColorAndPreview(m_selectedColor, Acs::buttonsToRole(Qt::NoButton, m_pressedButtons)); | 847 | requestUpdateColorAndPreview(m_selectedColor, colorRole); | ||
808 | m_mouseMoved = true; | 848 | m_mouseMoved = true; | ||
809 | } | 849 | } | ||
810 | else if (m_clickedRing >= 0) { | 850 | else if (m_clickedRing >= 0) { | ||
811 | if (getNumPieces() > 1) { | 851 | if (getNumPieces() == 1) { | ||
812 | for(int i=0; i<getNumRings(); ++i) | 852 | Radian angle = mapCoordToAngle(m_clickPos.x(), m_clickPos.y()); | ||
813 | m_colorRings[i].setTemporaries(m_selectedColor); | | |||
814 | } | | |||
815 | else { | | |||
816 | Radian angle = std::atan2(m_clickPos.x(), m_clickPos.y()) - RAD_90; | | |||
817 | 853 | | |||
818 | KisColor color; | 854 | KisColor color(m_colorSpace); | ||
819 | color.setH(angle.scaled(0.0f, 1.0f)); | 855 | color.setHSX(angle.scaled(0.0f, 1.0f) | ||
820 | color.setS(getSaturation(m_clickedRing)); | 856 | , getSaturation(m_clickedRing) | ||
821 | color.setX(getLight(m_light, color.getH(), m_relativeLight)); | 857 | , m_selectedColor.getX(m_gamma) | ||
858 | , color.getA() | ||||
859 | , m_gamma | ||||
860 | ); | ||||
861 | | ||||
862 | #ifdef DEBUG_ARC_SELECTOR | ||||
863 | dbgPlugins << "KisColorSelector::mousePressEvent: picked color: " | ||||
864 | << "H:" << color.getH() | ||||
865 | << "S:" << color.getS() | ||||
866 | << "X:" << color.getX(m_gamma); | ||||
867 | #endif | ||||
822 | 868 | | |||
823 | if ((!m_enforceGamutMask) || colorIsClear(color)) { | 869 | if ((!m_enforceGamutMask) || colorIsClear(color)) { | ||
824 | m_selectedColor.setHSX(color.getH(), color.getS(), color.getX()); | 870 | m_selectedColor.setHSX(color.getH(), color.getS(), color.getX(m_gamma), color.getA(), m_gamma); | ||
825 | requestUpdateColorAndPreview(m_selectedColor, Acs::buttonsToRole(Qt::NoButton, m_pressedButtons)); | 871 | requestUpdateColorAndPreview(m_selectedColor, colorRole); | ||
826 | m_selectedRing = m_clickedRing; | 872 | m_selectedRing = m_clickedRing; | ||
827 | m_mouseMoved = true; | 873 | m_mouseMoved = true; | ||
828 | update(); | 874 | update(); | ||
829 | } | 875 | } | ||
830 | } | 876 | } | ||
831 | } | 877 | } | ||
832 | } | 878 | } | ||
833 | 879 | | |||
834 | void KisColorSelector::mouseMoveEvent(QMouseEvent* event) | 880 | void KisColorSelector::mouseMoveEvent(QMouseEvent* event) | ||
835 | { | 881 | { | ||
836 | QPointF dragPos = mapCoordToUnit(event->localPos(), m_renderArea); | 882 | QPointF dragPos = mapCoordToUnit(event->localPos(), m_renderArea); | ||
837 | qint8 clickedLightPiece = getLightIndex(event->localPos()); | 883 | qint8 clickedLightPiece = getLightIndex(event->localPos()); | ||
884 | Acs::ColorRole colorRole = Acs::buttonsToRole(Qt::NoButton, m_pressedButtons); | ||||
838 | 885 | | |||
839 | if (clickedLightPiece >= 0) { | 886 | if (clickedLightPiece >= 0) { | ||
840 | setLight(getLight(event->localPos()), m_relativeLight); | 887 | setLight(getLight(event->localPos())); | ||
841 | m_selectedLightPiece = clickedLightPiece; | 888 | m_selectedLightPiece = clickedLightPiece; | ||
842 | requestUpdateColorAndPreview(m_selectedColor, m_selectedColorRole); | 889 | requestUpdateColorAndPreview(m_selectedColor, colorRole); | ||
843 | } | 890 | } | ||
844 | 891 | | |||
845 | if (m_clickedRing < 0) | 892 | if (m_clickedRing < 0) | ||
846 | return; | 893 | return; | ||
847 | 894 | | |||
848 | if (getNumPieces() > 1) { | 895 | if (getNumPieces() == 1) { | ||
849 | float angle = std::atan2(dragPos.x(), dragPos.y()) - std::atan2(m_clickPos.x(), m_clickPos.y()); | 896 | Radian angle = mapCoordToAngle(dragPos.x(), dragPos.y()); | ||
850 | float dist = std::sqrt(dragPos.x()*dragPos.x() + dragPos.y()*dragPos.y()) * 0.80f; | 897 | KisColor color(m_colorSpace); | ||
851 | float threshold = 5.0f * (1.0f-(dist*dist)); | 898 | color.setHSX(angle.scaled(0.0f, 1.0f) | ||
852 | 899 | , getSaturation(m_clickedRing) | |||
853 | if (qAbs(angle * TO_DEG) >= threshold || m_mouseMoved) { | 900 | , m_selectedColor.getX(m_gamma) | ||
854 | bool selectedRingMoved = true; | 901 | , color.getA() | ||
855 | 902 | , m_gamma | |||
856 | if (m_pressedButtons & Qt::RightButton) { | 903 | ); | ||
857 | selectedRingMoved = m_clickedRing == m_selectedRing; | | |||
858 | m_colorRings[m_clickedRing].angle = m_colorRings[m_clickedRing].tmpAngle + angle; | | |||
859 | } | | |||
860 | else for(int i=0; i<getNumRings(); ++i) | | |||
861 | m_colorRings[i].angle = m_colorRings[i].tmpAngle + angle; | | |||
862 | | ||||
863 | if (selectedRingMoved) { | | |||
864 | KisColor color = m_colorRings[m_clickedRing].tmpColor; | | |||
865 | Radian angle = m_colorRings[m_clickedRing].getMovedAngel() + (color.getH()*PI2); | | |||
866 | color.setH(angle.scaled(0.0f, 1.0f)); | | |||
867 | color.setX(getLight(m_light, color.getH(), m_relativeLight)); | | |||
868 | | ||||
869 | if ((!m_enforceGamutMask) || colorIsClear(color)) { | | |||
870 | m_selectedPiece = getHueIndex(angle, m_colorRings[m_clickedRing].getShift()); | | |||
871 | requestUpdateColorAndPreview(color, m_selectedColorRole); | | |||
872 | } | | |||
873 | } | | |||
874 | | ||||
875 | m_mouseMoved = true; | | |||
876 | } | | |||
877 | } | | |||
878 | else { | | |||
879 | Radian angle = std::atan2(dragPos.x(), dragPos.y()) - RAD_90; | | |||
880 | KisColor color; | | |||
881 | color.setH(angle.scaled(0.0f, 1.0f)); | | |||
882 | color.setS(getSaturation(m_clickedRing)); | | |||
883 | color.setX(getLight(m_light, color.getH(), m_relativeLight)); | | |||
884 | 904 | | |||
885 | if ((!m_enforceGamutMask) || colorIsClear(color)) { | 905 | if ((!m_enforceGamutMask) || colorIsClear(color)) { | ||
886 | m_selectedColor.setHSX(color.getH(), color.getS(), color.getX()); | 906 | m_selectedColor.setHSX(color.getH(), color.getS(), color.getX(m_gamma), color.getA(), m_gamma); | ||
887 | requestUpdateColorAndPreview(m_selectedColor, m_selectedColorRole); | 907 | requestUpdateColorAndPreview(m_selectedColor, colorRole); | ||
888 | } | 908 | } | ||
889 | } | 909 | } | ||
890 | 910 | | |||
891 | update(); | 911 | update(); | ||
892 | } | 912 | } | ||
893 | 913 | | |||
894 | void KisColorSelector::mouseReleaseEvent(QMouseEvent* /*event*/) | 914 | void KisColorSelector::mouseReleaseEvent(QMouseEvent* /*event*/) | ||
895 | { | 915 | { | ||
916 | Acs::ColorRole colorRole = Acs::buttonsToRole(Qt::NoButton, m_pressedButtons); | ||||
917 | | ||||
896 | if (!m_mouseMoved && m_clickedRing >= 0) { | 918 | if (!m_mouseMoved && m_clickedRing >= 0) { | ||
897 | Radian angle = std::atan2(m_clickPos.x(), m_clickPos.y()) - RAD_90; | 919 | Radian angle = mapCoordToAngle(m_clickPos.x(), m_clickPos.y()); | ||
898 | KisColor color; | 920 | KisColor color(m_colorSpace); | ||
899 | 921 | | |||
900 | qint8 hueIndex = getHueIndex(angle, m_colorRings[m_clickedRing].getShift()); | 922 | qint8 hueIndex = getHueIndex(angle); | ||
901 | 923 | | |||
902 | if (getNumPieces() > 1) { | 924 | if (getNumPieces() > 1) { | ||
903 | color.setH(getHue(hueIndex, m_colorRings[m_clickedRing].getShift())); | 925 | color.setH(getHue(hueIndex)); | ||
904 | } else { | 926 | } else { | ||
905 | color.setH(angle.scaled(0.0f, 1.0f)); | 927 | color.setH(angle.scaled(0.0f, 1.0f)); | ||
906 | } | 928 | } | ||
907 | 929 | | |||
908 | color.setS(getSaturation(m_clickedRing)); | 930 | color.setS(getSaturation(m_clickedRing)); | ||
909 | color.setX(getLight(m_light, color.getH(), m_relativeLight)); | 931 | color.setX(m_selectedColor.getX(m_gamma), m_gamma); | ||
910 | 932 | | |||
911 | if ((!m_enforceGamutMask) || colorIsClear(color)) { | 933 | if ((!m_enforceGamutMask) || colorIsClear(color)) { | ||
912 | m_selectedColor.setHSX(color.getH(), color.getS(), color.getX()); | 934 | m_selectedColor.setHSX(color.getH(), color.getS(), color.getX(m_gamma), color.getA(), m_gamma); | ||
913 | m_selectedPiece = hueIndex; | 935 | m_selectedPiece = hueIndex; | ||
914 | m_selectedRing = m_clickedRing; | 936 | m_selectedRing = m_clickedRing; | ||
915 | requestUpdateColorAndPreview(m_selectedColor, Acs::buttonsToRole(Qt::NoButton, m_pressedButtons)); | 937 | requestUpdateColorAndPreview(m_selectedColor, colorRole); | ||
916 | } | 938 | } | ||
917 | } | 939 | } | ||
918 | else if (m_mouseMoved) | 940 | else if (m_mouseMoved) | ||
919 | requestUpdateColorAndPreview(m_selectedColor, m_selectedColorRole); | 941 | requestUpdateColorAndPreview(m_selectedColor, colorRole); | ||
920 | 942 | | |||
921 | m_clickedRing = -1; | 943 | m_clickedRing = -1; | ||
922 | 944 | | |||
923 | m_widgetUpdatesSelf = false; | 945 | m_widgetUpdatesSelf = false; | ||
946 | #ifdef DEBUG_ARC_SELECTOR | ||||
924 | dbgPlugins << "KisColorSelector::ReleasePressEvent: m_widgetUpdatesSelf = false"; | 947 | dbgPlugins << "KisColorSelector::ReleasePressEvent: m_widgetUpdatesSelf = false"; | ||
948 | #endif | ||||
925 | 949 | | |||
926 | update(); | 950 | update(); | ||
927 | } | 951 | } | ||
928 | 952 | | |||
929 | void KisColorSelector::resizeEvent(QResizeEvent* /*event*/) | 953 | void KisColorSelector::resizeEvent(QResizeEvent* /*event*/) | ||
930 | { | 954 | { | ||
931 | recalculateAreas(quint8(getNumLightPieces())); | 955 | recalculateAreas(quint8(getNumLightPieces())); | ||
932 | } | 956 | } | ||
933 | 957 | | |||
934 | void KisColorSelector::leaveEvent(QEvent* /*e*/) | 958 | void KisColorSelector::leaveEvent(QEvent* /*e*/) | ||
935 | { | 959 | { | ||
936 | m_widgetUpdatesSelf = false; | 960 | m_widgetUpdatesSelf = false; | ||
961 | #ifdef DEBUG_ARC_SELECTOR | ||||
937 | dbgPlugins << "KisColorSelector::leaveEvent: m_widgetUpdatesSelf = false"; | 962 | dbgPlugins << "KisColorSelector::leaveEvent: m_widgetUpdatesSelf = false"; | ||
963 | #endif | ||||
938 | } | 964 | } | ||
939 | 965 | | |||
940 | void KisColorSelector::saveSettings() | 966 | void KisColorSelector::saveSettings() | ||
941 | { | 967 | { | ||
942 | KisConfig cfg; | 968 | KisConfig cfg; | ||
943 | cfg.writeEntry("ArtColorSel.ColorSpace" , qint32(m_colorSpace)); | 969 | cfg.writeEntry("ArtColorSel.ColorSpace" , qint32(m_colorSpace)); | ||
944 | cfg.writeEntry("ArtColorSel.NumRings" , m_colorRings.size()); | 970 | cfg.writeEntry("ArtColorSel.NumRings" , m_colorRings.size()); | ||
945 | cfg.writeEntry("ArtColorSel.RingPieces" , qint32(m_numPieces)); | 971 | cfg.writeEntry("ArtColorSel.RingPieces" , qint32(m_numPieces)); | ||
946 | cfg.writeEntry("ArtColorSel.LightPieces", qint32(m_numLightPieces)); | 972 | cfg.writeEntry("ArtColorSel.LightPieces", qint32(m_numLightPieces)); | ||
947 | 973 | | |||
948 | cfg.writeEntry("ArtColorSel.InversedSaturation", m_inverseSaturation); | 974 | cfg.writeEntry("ArtColorSel.InversedSaturation", m_inverseSaturation); | ||
949 | cfg.writeEntry("ArtColorSel.RelativeLight" , m_relativeLight); | 975 | cfg.writeEntry("ArtColorSel.Light" , m_selectedColor.getX(m_gamma)); | ||
950 | cfg.writeEntry("ArtColorSel.Light" , m_light); | | |||
951 | 976 | | |||
952 | cfg.writeEntry("ArtColorSel.SelColorH", m_selectedColor.getH()); | 977 | cfg.writeEntry("ArtColorSel.SelColorH", m_selectedColor.getH()); | ||
953 | cfg.writeEntry("ArtColorSel.SelColorS", m_selectedColor.getS()); | 978 | cfg.writeEntry("ArtColorSel.SelColorS", m_selectedColor.getS()); | ||
954 | cfg.writeEntry("ArtColorSel.SelColorX", m_selectedColor.getX()); | 979 | cfg.writeEntry("ArtColorSel.SelColorX", m_selectedColor.getX(m_gamma)); | ||
955 | cfg.writeEntry("ArtColorSel.SelColorA", m_selectedColor.getA()); | 980 | cfg.writeEntry("ArtColorSel.SelColorA", m_selectedColor.getA()); | ||
956 | 981 | | |||
957 | cfg.writeEntry("ArtColorSel.defaultHueSteps", quint32(m_defaultHueSteps)); | 982 | cfg.writeEntry("ArtColorSel.defaultHueSteps", quint32(m_defaultHueSteps)); | ||
958 | cfg.writeEntry("ArtColorSel.defaultSaturationSteps", quint32(m_defaultSaturationSteps)); | 983 | cfg.writeEntry("ArtColorSel.defaultSaturationSteps", quint32(m_defaultSaturationSteps)); | ||
959 | cfg.writeEntry("ArtColorSel.defaultValueScaleSteps", quint32(m_defaultValueScaleSteps)); | 984 | cfg.writeEntry("ArtColorSel.defaultValueScaleSteps", quint32(m_defaultValueScaleSteps)); | ||
960 | 985 | | |||
961 | cfg.writeEntry("ArtColorSel.showBgColor", m_showBgColor); | 986 | cfg.writeEntry("ArtColorSel.showBgColor", m_showBgColor); | ||
962 | cfg.writeEntry("ArtColorSel.showColorBlip", m_showColorBlip); | 987 | cfg.writeEntry("ArtColorSel.showColorBlip", m_showColorBlip); | ||
963 | cfg.writeEntry("ArtColorSel.showValueScaleNumber", m_showValueScaleNumbers); | 988 | cfg.writeEntry("ArtColorSel.showValueScale", m_showValueScaleNumbers); | ||
964 | cfg.writeEntry("ArtColorSel.enforceGamutMask", m_enforceGamutMask); | 989 | cfg.writeEntry("ArtColorSel.enforceGamutMask", m_enforceGamutMask); | ||
965 | 990 | | |||
966 | cfg.writeEntry("ArtColorSel.maskPreviewActive", m_maskPreviewActive); | 991 | cfg.writeEntry("ArtColorSel.maskPreviewActive", m_maskPreviewActive); | ||
967 | 992 | cfg.writeEntry("ArtColorSel.valueScaleGamma", gamma()); | |||
968 | QList<float> angles; | | |||
969 | | ||||
970 | for(int i=0; i<m_colorRings.size(); ++i) | | |||
971 | angles.push_back(m_colorRings[i].angle.value()); | | |||
972 | | ||||
973 | cfg.writeList("ArtColorSel.RingAngles", angles); | | |||
974 | } | 993 | } | ||
975 | 994 | | |||
976 | void KisColorSelector::loadSettings() | 995 | void KisColorSelector::loadSettings() | ||
977 | { | 996 | { | ||
978 | KisConfig cfg; | 997 | KisConfig cfg; | ||
979 | setColorSpace(KisColor::Type(cfg.readEntry<qint32>("ArtColorSel.ColorSpace" , KisColor::HSY))); | | |||
980 | 998 | | |||
981 | m_defaultHueSteps = cfg.readEntry("ArtColorSel.defaultHueSteps", DEFAULT_HUE_STEPS); | 999 | m_defaultHueSteps = cfg.readEntry("ArtColorSel.defaultHueSteps", DEFAULT_HUE_STEPS); | ||
982 | m_defaultSaturationSteps = cfg.readEntry("ArtColorSel.defaultSaturationSteps", DEFAULT_SATURATION_STEPS); | 1000 | m_defaultSaturationSteps = cfg.readEntry("ArtColorSel.defaultSaturationSteps", DEFAULT_SATURATION_STEPS); | ||
983 | m_defaultValueScaleSteps = cfg.readEntry("ArtColorSel.defaultValueScaleSteps", DEFAULT_VALUE_SCALE_STEPS); | 1001 | m_defaultValueScaleSteps = cfg.readEntry("ArtColorSel.defaultValueScaleSteps", DEFAULT_VALUE_SCALE_STEPS); | ||
984 | 1002 | | |||
985 | setNumLightPieces(cfg.readEntry("ArtColorSel.LightPieces", DEFAULT_VALUE_SCALE_STEPS)); | 1003 | setNumLightPieces(cfg.readEntry("ArtColorSel.LightPieces", DEFAULT_VALUE_SCALE_STEPS)); | ||
986 | 1004 | | |||
1005 | KisColor::Type colorSpace = KisColor::Type(cfg.readEntry<qint32>("ArtColorSel.ColorSpace" , KisColor::HSY)); | ||||
1006 | float valueScaleGamma = cfg.readEntry("ArtColorSel.valueScaleGamma", 2.2f); | ||||
1007 | if (colorSpace == KisColor::HSY) { | ||||
1008 | setGamma(valueScaleGamma); | ||||
1009 | | ||||
1010 | } | ||||
1011 | | ||||
1012 | setColorSpace(colorSpace, valueScaleGamma); | ||||
1013 | | ||||
987 | m_selectedColor.setH(cfg.readEntry<float>("ArtColorSel.SelColorH", 0.0f)); | 1014 | m_selectedColor.setH(cfg.readEntry<float>("ArtColorSel.SelColorH", 0.0f)); | ||
988 | m_selectedColor.setS(cfg.readEntry<float>("ArtColorSel.SelColorS", 0.0f)); | 1015 | m_selectedColor.setS(cfg.readEntry<float>("ArtColorSel.SelColorS", 0.0f)); | ||
989 | m_selectedColor.setX(cfg.readEntry<float>("ArtColorSel.SelColorX", 0.0f)); | 1016 | m_selectedColor.setX(cfg.readEntry<float>("ArtColorSel.SelColorX", 0.0f), m_gamma); | ||
990 | m_selectedColor.setA(1.0f); | 1017 | m_selectedColor.setA(1.0f); | ||
991 | 1018 | | |||
992 | setInverseSaturation(cfg.readEntry<bool>("ArtColorSel.InversedSaturation", false)); | 1019 | setInverseSaturation(cfg.readEntry<bool>("ArtColorSel.InversedSaturation", false)); | ||
993 | setLight(cfg.readEntry<float>("ArtColorSel.Light", 0.5f), cfg.readEntry<bool>("ArtColorSel.RelativeLight", true)); | 1020 | setLight(cfg.readEntry<float>("ArtColorSel.Light", 0.5f)); | ||
994 | 1021 | | |||
995 | setNumRings(cfg.readEntry("ArtColorSel.NumRings" , DEFAULT_SATURATION_STEPS)); | 1022 | setNumRings(cfg.readEntry("ArtColorSel.NumRings", DEFAULT_SATURATION_STEPS)); | ||
996 | setNumPieces(cfg.readEntry("ArtColorSel.RingPieces", DEFAULT_HUE_STEPS)); | 1023 | setNumPieces(cfg.readEntry("ArtColorSel.RingPieces", DEFAULT_HUE_STEPS)); | ||
997 | 1024 | | |||
998 | QList<float> angles = cfg.readList<float>("ArtColorSel.RingAngles"); | | |||
999 | | ||||
1000 | for (int i = 0; i < m_colorRings.size(); ++i) { | | |||
1001 | if (i < angles.size() && i < m_colorRings.size()) { | | |||
1002 | m_colorRings[i].angle = angles[i]; | | |||
1003 | } | | |||
1004 | } | | |||
1005 | | ||||
1006 | m_showBgColor = cfg.readEntry("ArtColorSel.showBgColor", true); | 1025 | m_showBgColor = cfg.readEntry("ArtColorSel.showBgColor", true); | ||
1007 | m_showColorBlip = cfg.readEntry("ArtColorSel.showColorBlip", true); | 1026 | m_showColorBlip = cfg.readEntry("ArtColorSel.showColorBlip", true); | ||
1008 | m_showValueScaleNumbers = cfg.readEntry("ArtColorSel.showValueScaleNumber", false); | 1027 | m_showValueScaleNumbers = cfg.readEntry("ArtColorSel.showValueScale", false); | ||
1009 | m_enforceGamutMask = cfg.readEntry("ArtColorSel.enforceGamutMask", true); | 1028 | m_enforceGamutMask = cfg.readEntry("ArtColorSel.enforceGamutMask", false); | ||
1010 | 1029 | | |||
1011 | m_maskPreviewActive = cfg.readEntry("ArtColorSel.maskPreviewActive", true); | 1030 | m_maskPreviewActive = cfg.readEntry("ArtColorSel.maskPreviewActive", true); | ||
1012 | 1031 | | |||
1013 | selectColor(m_selectedColor); | 1032 | selectColor(m_selectedColor); | ||
1014 | update(); | 1033 | update(); | ||
1015 | } | 1034 | } | ||
1016 | 1035 | | |||
1017 | void KisColorSelector::setDefaultHueSteps(int num) | 1036 | void KisColorSelector::setDefaultHueSteps(int num) | ||
Show All 23 Lines | |||||
1041 | { | 1060 | { | ||
1042 | m_showBgColor = value; | 1061 | m_showBgColor = value; | ||
1043 | update(); | 1062 | update(); | ||
1044 | } | 1063 | } | ||
1045 | 1064 | | |||
1046 | void KisColorSelector::setShowValueScaleNumbers(bool value) | 1065 | void KisColorSelector::setShowValueScaleNumbers(bool value) | ||
1047 | { | 1066 | { | ||
1048 | m_showValueScaleNumbers = value; | 1067 | m_showValueScaleNumbers = value; | ||
1068 | recalculateAreas(quint8(getNumLightPieces())); | ||||
1049 | update(); | 1069 | update(); | ||
1050 | } | 1070 | } | ||
1051 | 1071 | | |||
1052 | bool KisColorSelector::saturationIsInvertible() | 1072 | bool KisColorSelector::saturationIsInvertible() | ||
1053 | { | 1073 | { | ||
1054 | if (!m_gamutMaskOn) return true; | 1074 | if (!m_gamutMaskOn) return true; | ||
1055 | bool b = (m_enforceGamutMask && getNumPieces() == 1) ? false : true; | 1075 | bool b = (m_enforceGamutMask && getNumPieces() == 1) ? false : true; | ||
1056 | return b; | 1076 | return b; | ||
1057 | } | 1077 | } | ||
1058 | 1078 | |