Changeset View
Changeset View
Standalone View
Standalone View
plugins/tools/basictools/kis_tool_colorpicker.cc
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright (c) 1999 Matthias Elter <me@kde.org> | 2 | * Copyright (c) 1999 Matthias Elter <me@kde.org> | ||
3 | * Copyright (c) 2002 Patrick Julien <freak@codepimps.org> | 3 | * Copyright (c) 2002 Patrick Julien <freak@codepimps.org> | ||
4 | * Copyright (c) 2010 Lukáš Tvrdý <lukast.dev@gmail.com> | 4 | * Copyright (c) 2010 Lukáš Tvrdý <lukast.dev@gmail.com> | ||
5 | * Copyright (c) 2018 Emmet & Eoin O'Neill <emmetoneill.pdx@gmail.com> | ||||
5 | * | 6 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | 9 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | 10 | * (at your option) any later version. | ||
10 | * | 11 | * | ||
11 | * This program is distributed in the hope that it will be useful, | 12 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | 15 | * GNU General Public License for more details. | ||
15 | * | 16 | * | ||
16 | * You should have received a copy of the GNU General Public License | 17 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | 18 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | */ | 20 | */ | ||
20 | 21 | | |||
21 | #include "kis_tool_colorpicker.h" | 22 | #include "kis_tool_colorpicker.h" | ||
22 | #include <string.h> | | |||
23 | 23 | | |||
24 | #include <boost/thread/locks.hpp> | 24 | #include <boost/thread/locks.hpp> | ||
25 | | ||||
26 | #include <QPoint> | | |||
27 | #include <QLayout> | | |||
28 | #include <QCheckBox> | | |||
29 | #include <QComboBox> | | |||
30 | #include <QSpinBox> | | |||
31 | #include <QListWidget> | | |||
32 | #include <QList> | | |||
33 | #include <QWidget> | | |||
34 | #include <QVector> | | |||
35 | | ||||
36 | #include <ksharedconfig.h> | | |||
37 | #include <kconfiggroup.h> | | |||
38 | #include <klocalizedstring.h> | | |||
39 | | ||||
40 | #include <QMessageBox> | 25 | #include <QMessageBox> | ||
41 | | ||||
42 | #include "kis_layer.h" | | |||
43 | #include "kis_cursor.h" | 26 | #include "kis_cursor.h" | ||
44 | #include "kis_image.h" | | |||
45 | #include "kis_paint_device.h" | | |||
46 | #include "kis_properties_configuration.h" | | |||
47 | #include "KisDocument.h" | 27 | #include "KisDocument.h" | ||
48 | #include "kis_canvas2.h" | 28 | #include "kis_canvas2.h" | ||
49 | #include "KisReferenceImagesLayer.h" | 29 | #include "KisReferenceImagesLayer.h" | ||
50 | | ||||
51 | #include "KoPointerEvent.h" | | |||
52 | #include "KoCanvasBase.h" | 30 | #include "KoCanvasBase.h" | ||
53 | #include "kis_random_accessor_ng.h" | 31 | #include "kis_random_accessor_ng.h" | ||
54 | #include "KoColor.h" | | |||
55 | #include "KoResourceServerProvider.h" | 32 | #include "KoResourceServerProvider.h" | ||
56 | #include <resources/KoColorSet.h> | | |||
57 | #include <KoChannelInfo.h> | | |||
58 | #include <KoMixColorsOp.h> | 33 | #include <KoMixColorsOp.h> | ||
59 | | ||||
60 | #include "kis_wrapped_rect.h" | 34 | #include "kis_wrapped_rect.h" | ||
61 | #include "kis_tool_utils.h" | 35 | #include "kis_tool_utils.h" | ||
62 | 36 | | |||
63 | | ||||
64 | namespace | 37 | namespace | ||
65 | { | 38 | { | ||
66 | // The location of the sample all visible layers in the combobox | 39 | // GUI ComboBox index constants | ||
67 | const int SAMPLE_MERGED = 0; | 40 | const int SAMPLE_MERGED = 0; | ||
68 | } | 41 | } | ||
69 | 42 | | |||
70 | KisToolColorPicker::KisToolColorPicker(KoCanvasBase* canvas) | 43 | KisToolColorPicker::KisToolColorPicker(KoCanvasBase *canvas) | ||
71 | : KisTool(canvas, KisCursor::pickerCursor()), | 44 | : KisTool(canvas, KisCursor::pickerCursor()), | ||
72 | m_config(new KisToolUtils::ColorPickerConfig) | 45 | m_config(new KisToolUtils::ColorPickerConfig) | ||
73 | { | 46 | { | ||
74 | setObjectName("tool_colorpicker"); | 47 | setObjectName("tool_colorpicker"); | ||
75 | m_isActivated = false; | 48 | m_isActivated = false; | ||
76 | m_optionsWidget = 0; | 49 | m_optionsWidget = 0; | ||
77 | m_pickedColor = KoColor(); | 50 | m_pickedColor = KoColor(); | ||
78 | } | 51 | } | ||
79 | 52 | | |||
80 | KisToolColorPicker::~KisToolColorPicker() | 53 | KisToolColorPicker::~KisToolColorPicker() | ||
81 | { | 54 | { | ||
82 | if (m_isActivated) { | 55 | if (m_isActivated) { | ||
83 | m_config->save(m_toolActivationSource == KisTool::DefaultActivation); | 56 | m_config->save(m_toolActivationSource == KisTool::DefaultActivation); | ||
84 | } | 57 | } | ||
85 | } | 58 | } | ||
86 | 59 | | |||
87 | void KisToolColorPicker::paint(QPainter& gc, const KoViewConverter &converter) | 60 | void KisToolColorPicker::paint(QPainter &gc, const KoViewConverter &converter) | ||
88 | { | 61 | { | ||
89 | Q_UNUSED(gc); | 62 | Q_UNUSED(gc); | ||
90 | Q_UNUSED(converter); | 63 | Q_UNUSED(converter); | ||
91 | } | 64 | } | ||
92 | 65 | | |||
93 | void KisToolColorPicker::activate(ToolActivation activation, const QSet<KoShape*> &shapes) | 66 | void KisToolColorPicker::activate(ToolActivation activation, const QSet<KoShape*> &shapes) | ||
94 | { | 67 | { | ||
95 | m_isActivated = true; | 68 | m_isActivated = true; | ||
96 | m_toolActivationSource = activation; | 69 | m_toolActivationSource = activation; | ||
97 | m_config->load(m_toolActivationSource == KisTool::DefaultActivation); | 70 | m_config->load(m_toolActivationSource == KisTool::DefaultActivation); | ||
98 | updateOptionWidget(); | 71 | updateOptionWidget(); | ||
99 | 72 | | |||
100 | KisTool::activate(activation, shapes); | 73 | KisTool::activate(activation, shapes); | ||
101 | } | 74 | } | ||
75 | | ||||
102 | void KisToolColorPicker::deactivate() | 76 | void KisToolColorPicker::deactivate() | ||
103 | { | 77 | { | ||
104 | m_config->save(m_toolActivationSource == KisTool::DefaultActivation); | 78 | m_config->save(m_toolActivationSource == KisTool::DefaultActivation); | ||
105 | m_isActivated = false; | 79 | m_isActivated = false; | ||
106 | KisTool::deactivate(); | 80 | KisTool::deactivate(); | ||
107 | } | 81 | } | ||
108 | 82 | | |||
109 | void KisToolColorPicker::pickColor(const QPointF& pos) | 83 | void KisToolColorPicker::pickColor(const QPointF &pos) | ||
110 | { | 84 | { | ||
111 | if (m_colorPickerDelayTimer.isActive()) { | 85 | if (m_colorPickerDelayTimer.isActive()) { | ||
112 | return; | 86 | return; | ||
113 | } | 87 | } | ||
114 | else { | 88 | else { | ||
115 | m_colorPickerDelayTimer.setSingleShot(true); | 89 | m_colorPickerDelayTimer.setSingleShot(true); | ||
116 | m_colorPickerDelayTimer.start(100); | 90 | m_colorPickerDelayTimer.start(100); | ||
117 | } | 91 | } | ||
118 | 92 | | |||
119 | | ||||
120 | QScopedPointer<boost::lock_guard<KisImage> > imageLocker; | 93 | QScopedPointer<boost::lock_guard<KisImage>> imageLocker; | ||
121 | 94 | | |||
122 | m_pickedColor.setOpacity(0.0); | 95 | m_pickedColor.setOpacity(0.0); | ||
123 | 96 | | |||
124 | if (m_optionsWidget->cmbSources->currentIndex() == SAMPLE_MERGED) { | 97 | if (m_optionsWidget->cmbSources->currentIndex() == SAMPLE_MERGED) { | ||
125 | auto *kisCanvas = dynamic_cast<KisCanvas2 *>(canvas()); | 98 | auto *kisCanvas = dynamic_cast<KisCanvas2 *>(canvas()); | ||
126 | KIS_SAFE_ASSERT_RECOVER_RETURN(kisCanvas); | 99 | KIS_SAFE_ASSERT_RECOVER_RETURN(kisCanvas); | ||
127 | KisReferenceImagesLayer *referenceImageLayer = | 100 | KisReferenceImagesLayer *referenceImageLayer = | ||
128 | kisCanvas->imageView()->document()->referenceImagesLayer(); | 101 | kisCanvas->imageView()->document()->referenceImagesLayer(); | ||
Show All 13 Lines | 114 | if (m_optionsWidget->cmbSources->currentIndex() != SAMPLE_MERGED && | |||
142 | currentNode() && currentNode()->colorPickSourceDevice()) { | 115 | currentNode() && currentNode()->colorPickSourceDevice()) { | ||
143 | dev = currentNode()->colorPickSourceDevice(); | 116 | dev = currentNode()->colorPickSourceDevice(); | ||
144 | } | 117 | } | ||
145 | else { | 118 | else { | ||
146 | imageLocker.reset(new boost::lock_guard<KisImage>(*currentImage())); | 119 | imageLocker.reset(new boost::lock_guard<KisImage>(*currentImage())); | ||
147 | dev = currentImage()->projection(); | 120 | dev = currentImage()->projection(); | ||
148 | } | 121 | } | ||
149 | 122 | | |||
123 | // Color sampling radius. | ||||
150 | if (m_config->radius == 1) { | 124 | if (m_config->radius == 1) { | ||
151 | QPoint realPos = pos.toPoint(); | 125 | QPoint realPos = pos.toPoint(); | ||
152 | if (currentImage()->wrapAroundModePermitted()) { | 126 | if (currentImage()->wrapAroundModePermitted()) { | ||
153 | realPos = KisWrappedRect::ptToWrappedPt(realPos, currentImage()->bounds()); | 127 | realPos = KisWrappedRect::ptToWrappedPt(realPos, currentImage()->bounds()); | ||
154 | } | 128 | } | ||
155 | 129 | | |||
156 | dev->pixel(realPos.x(), realPos.y(), &m_pickedColor); | 130 | dev->pixel(realPos.x(), realPos.y(), &m_pickedColor); | ||
157 | } | 131 | } | ||
158 | else { | 132 | else { | ||
159 | | ||||
160 | const KoColorSpace *cs = dev->colorSpace(); | 133 | const KoColorSpace *cs = dev->colorSpace(); | ||
161 | int pixelSize = cs->pixelSize(); | 134 | int pixelSize = cs->pixelSize(); | ||
162 | 135 | | |||
163 | quint8 *dstColor = new quint8[pixelSize]; | 136 | quint8 *dstColor = new quint8[pixelSize]; | ||
164 | QVector<const quint8 *> pixels; | 137 | QVector<const quint8 *> pixels; | ||
165 | 138 | | |||
166 | KisRandomConstAccessorSP accessor = dev->createRandomConstAccessorNG(0, 0); | 139 | KisRandomConstAccessorSP accessor = dev->createRandomConstAccessorNG(0, 0); | ||
167 | 140 | | |||
168 | for (int y = -m_config->radius; y <= m_config->radius; y++) { | 141 | for (int y = -m_config->radius; y <= m_config->radius; y++) { | ||
169 | for (int x = -m_config->radius; x <= m_config->radius; x++) { | 142 | for (int x = -m_config->radius; x <= m_config->radius; x++) { | ||
170 | if (((x * x) + (y * y)) < m_config->radius * m_config->radius) { | 143 | if (((x * x) + (y * y)) < m_config->radius * m_config->radius) { | ||
171 | 144 | | |||
172 | QPoint realPos(pos.x() + x, pos.y() + y); | 145 | QPoint realPos(pos.x() + x, pos.y() + y); | ||
173 | 146 | | |||
174 | if (currentImage()->wrapAroundModePermitted()) { | 147 | if (currentImage()->wrapAroundModePermitted()) { | ||
175 | realPos = KisWrappedRect::ptToWrappedPt(realPos, currentImage()->bounds()); | 148 | realPos = KisWrappedRect::ptToWrappedPt(realPos, currentImage()->bounds()); | ||
176 | } | 149 | } | ||
177 | 150 | | |||
178 | accessor->moveTo(realPos.x(), realPos.y()); | 151 | accessor->moveTo(realPos.x(), realPos.y()); | ||
179 | pixels << accessor->oldRawData(); | 152 | pixels << accessor->oldRawData(); | ||
180 | } | 153 | } | ||
181 | } | 154 | } | ||
182 | } | 155 | } | ||
183 | 156 | | |||
184 | | ||||
185 | const quint8 **cpixels = const_cast<const quint8 **>(pixels.constData()); | 157 | const quint8 **cpixels = const_cast<const quint8 **>(pixels.constData()); | ||
186 | cs->mixColorsOp()->mixColors(cpixels, pixels.size(), dstColor); | 158 | cs->mixColorsOp()->mixColors(cpixels, pixels.size(), dstColor); | ||
187 | 159 | | |||
188 | m_pickedColor = KoColor(dstColor, cs); | 160 | m_pickedColor = KoColor(dstColor, cs); | ||
189 | 161 | | |||
190 | delete[] dstColor; | 162 | delete[] dstColor; | ||
191 | } | 163 | } | ||
192 | 164 | | |||
193 | m_pickedColor.convertTo(dev->compositionSourceColorSpace()); | 165 | // Color blending. | ||
166 | if(m_config->blend < 100){ | ||||
167 | //Scale from 0..100% to 0..255 range for mixOp weights. | ||||
168 | quint8 blendScaled = static_cast<quint8>(m_config->blend * 2.55f); | ||||
169 | | ||||
170 | KoColor previousColor = canvas()->resourceManager()->foregroundColor(); | ||||
171 | | ||||
172 | const quint8 *colors[2]; | ||||
173 | colors[0] = previousColor.data(); | ||||
174 | colors[1] = m_pickedColor.data(); | ||||
175 | qint16 weights[2]; | ||||
176 | weights[0] = 255 - blendScaled; | ||||
177 | weights[1] = blendScaled; | ||||
178 | | ||||
179 | const KoMixColorsOp *mixOp = dev->colorSpace()->mixColorsOp(); | ||||
180 | mixOp->mixColors(colors, weights, 2, m_pickedColor.data()); | ||||
194 | } | 181 | } | ||
195 | 182 | | |||
183 | m_pickedColor.convertTo(dev->compositionSourceColorSpace()); | ||||
184 | | ||||
196 | if (m_config->updateColor && | 185 | if (m_config->updateColor && | ||
197 | m_pickedColor.opacityU8() != OPACITY_TRANSPARENT_U8) { | 186 | m_pickedColor.opacityU8() != OPACITY_TRANSPARENT_U8) { | ||
198 | 187 | | |||
199 | KoColor publicColor = m_pickedColor; | 188 | KoColor publicColor = m_pickedColor; | ||
200 | publicColor.setOpacity(OPACITY_OPAQUE_U8); | 189 | publicColor.setOpacity(OPACITY_OPAQUE_U8); | ||
201 | 190 | | |||
202 | if (m_config->toForegroundColor) { | 191 | if (m_config->toForegroundColor) { | ||
203 | canvas()->resourceManager()->setResource(KoCanvasResourceManager::ForegroundColor, publicColor); | 192 | canvas()->resourceManager()->setResource(KoCanvasResourceManager::ForegroundColor, publicColor); | ||
204 | } | 193 | } | ||
205 | else { | 194 | else { | ||
206 | canvas()->resourceManager()->setResource(KoCanvasResourceManager::BackgroundColor, publicColor); | 195 | canvas()->resourceManager()->setResource(KoCanvasResourceManager::BackgroundColor, publicColor); | ||
207 | } | 196 | } | ||
208 | } | 197 | } | ||
209 | } | 198 | } | ||
199 | } | ||||
210 | 200 | | |||
211 | void KisToolColorPicker::beginPrimaryAction(KoPointerEvent *event) | 201 | void KisToolColorPicker::beginPrimaryAction(KoPointerEvent *event) | ||
212 | { | 202 | { | ||
213 | bool sampleMerged = m_optionsWidget->cmbSources->currentIndex() == SAMPLE_MERGED; | 203 | bool sampleMerged = m_optionsWidget->cmbSources->currentIndex() == SAMPLE_MERGED; | ||
214 | if (!sampleMerged) { | 204 | if (!sampleMerged) { | ||
215 | if (!currentNode()) { | 205 | if (!currentNode()) { | ||
216 | QMessageBox::information(0, i18nc("@title:window", "Krita"), i18n("Cannot pick a color as no layer is active.")); | 206 | QMessageBox::information(0, i18nc("@title:window", "Krita"), i18n("Cannot pick a color as no layer is active.")); | ||
217 | event->ignore(); | 207 | event->ignore(); | ||
218 | return; | 208 | return; | ||
219 | } | 209 | } | ||
220 | if (!currentNode()->visible()) { | 210 | if (!currentNode()->visible()) { | ||
221 | QMessageBox::information(0, i18nc("@title:window", "Krita"), i18n("Cannot pick a color as the active layer is not visible.")); | 211 | QMessageBox::information(0, i18nc("@title:window", "Krita"), i18n("Cannot pick a color as the active layer is not visible.")); | ||
222 | event->ignore(); | 212 | event->ignore(); | ||
223 | return; | 213 | return; | ||
224 | } | 214 | } | ||
225 | } | 215 | } | ||
226 | 216 | | |||
227 | QPoint pos = convertToImagePixelCoordFloored(event); | 217 | QPoint pos = convertToImagePixelCoordFloored(event); | ||
228 | // the color picking has to start in the visible part of the layer | 218 | // Color picking has to start in the visible part of the layer | ||
229 | if (!currentImage()->bounds().contains(pos) && | 219 | if (!currentImage()->bounds().contains(pos) && | ||
230 | !currentImage()->wrapAroundModePermitted()) { | 220 | !currentImage()->wrapAroundModePermitted()) { | ||
231 | event->ignore(); | 221 | event->ignore(); | ||
232 | return; | 222 | return; | ||
233 | } | 223 | } | ||
234 | 224 | | |||
235 | setMode(KisTool::PAINT_MODE); | 225 | setMode(KisTool::PAINT_MODE); | ||
236 | pickColor(pos); | 226 | pickColor(pos); | ||
Show All 14 Lines | 240 | { | |||
251 | Q_UNUSED(event); | 241 | Q_UNUSED(event); | ||
252 | CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE); | 242 | CHECK_MODE_SANITY_OR_RETURN(KisTool::PAINT_MODE); | ||
253 | 243 | | |||
254 | if (m_config->addPalette) { | 244 | if (m_config->addPalette) { | ||
255 | KoColorSetEntry ent; | 245 | KoColorSetEntry ent; | ||
256 | ent.color = m_pickedColor; | 246 | ent.color = m_pickedColor; | ||
257 | // We don't ask for a name, too intrusive here | 247 | // We don't ask for a name, too intrusive here | ||
258 | 248 | | |||
259 | KoColorSet* palette = m_palettes.at(m_optionsWidget->cmbPalette->currentIndex()); | 249 | KoColorSet *palette = m_palettes.at(m_optionsWidget->cmbPalette->currentIndex()); | ||
260 | palette->add(ent); | 250 | palette->add(ent); | ||
261 | 251 | | |||
262 | if (!palette->save()) { | 252 | if (!palette->save()) { | ||
263 | QMessageBox::critical(0, i18nc("@title:window", "Krita"), i18n("Cannot write to palette file %1. Maybe it is read-only.", palette->filename())); | 253 | QMessageBox::critical(0, i18nc("@title:window", "Krita"), i18n("Cannot write to palette file %1. Maybe it is read-only.", palette->filename())); | ||
264 | } | 254 | } | ||
265 | } | 255 | } | ||
266 | } | 256 | } | ||
267 | 257 | | |||
268 | | ||||
269 | struct PickedChannel { | 258 | struct PickedChannel { | ||
270 | QString name; | 259 | QString name; | ||
271 | QString valueText; | 260 | QString valueText; | ||
272 | }; | 261 | }; | ||
273 | 262 | | |||
274 | void KisToolColorPicker::displayPickedColor() | 263 | void KisToolColorPicker::displayPickedColor() | ||
275 | { | 264 | { | ||
276 | if (m_pickedColor.data() && m_optionsWidget) { | 265 | if (m_pickedColor.data() && m_optionsWidget) { | ||
Show All 36 Lines | 299 | { | |||
313 | m_optionsWidget->listViewChannels->setSortingEnabled(false); | 302 | m_optionsWidget->listViewChannels->setSortingEnabled(false); | ||
314 | 303 | | |||
315 | // See https://bugs.kde.org/show_bug.cgi?id=316896 | 304 | // See https://bugs.kde.org/show_bug.cgi?id=316896 | ||
316 | QWidget *specialSpacer = new QWidget(m_optionsWidget); | 305 | QWidget *specialSpacer = new QWidget(m_optionsWidget); | ||
317 | specialSpacer->setObjectName("SpecialSpacer"); | 306 | specialSpacer->setObjectName("SpecialSpacer"); | ||
318 | specialSpacer->setFixedSize(0, 0); | 307 | specialSpacer->setFixedSize(0, 0); | ||
319 | m_optionsWidget->layout()->addWidget(specialSpacer); | 308 | m_optionsWidget->layout()->addWidget(specialSpacer); | ||
320 | 309 | | |||
310 | // Initialize blend KisSliderSpinBox | ||||
311 | m_optionsWidget->blend->setRange(0,100); | ||||
312 | | ||||
321 | updateOptionWidget(); | 313 | updateOptionWidget(); | ||
322 | 314 | | |||
323 | connect(m_optionsWidget->cbUpdateCurrentColor, SIGNAL(toggled(bool)), SLOT(slotSetUpdateColor(bool))); | 315 | connect(m_optionsWidget->cbUpdateCurrentColor, SIGNAL(toggled(bool)), SLOT(slotSetUpdateColor(bool))); | ||
324 | connect(m_optionsWidget->cbNormaliseValues, SIGNAL(toggled(bool)), SLOT(slotSetNormaliseValues(bool))); | 316 | connect(m_optionsWidget->cbNormaliseValues, SIGNAL(toggled(bool)), SLOT(slotSetNormaliseValues(bool))); | ||
325 | connect(m_optionsWidget->cbPalette, SIGNAL(toggled(bool)), | 317 | connect(m_optionsWidget->cbPalette, SIGNAL(toggled(bool)), | ||
326 | SLOT(slotSetAddPalette(bool))); | 318 | SLOT(slotSetAddPalette(bool))); | ||
327 | connect(m_optionsWidget->radius, SIGNAL(valueChanged(int)), | 319 | connect(m_optionsWidget->radius, SIGNAL(valueChanged(int)), | ||
328 | SLOT(slotChangeRadius(int))); | 320 | SLOT(slotChangeRadius(int))); | ||
321 | connect(m_optionsWidget->blend, SIGNAL(valueChanged(int)), | ||||
322 | SLOT(slotChangeBlend(int))); | ||||
329 | connect(m_optionsWidget->cmbSources, SIGNAL(currentIndexChanged(int)), | 323 | connect(m_optionsWidget->cmbSources, SIGNAL(currentIndexChanged(int)), | ||
330 | SLOT(slotSetColorSource(int))); | 324 | SLOT(slotSetColorSource(int))); | ||
331 | 325 | | |||
332 | KoResourceServer<KoColorSet>* srv = KoResourceServerProvider::instance()->paletteServer(); | 326 | KoResourceServer<KoColorSet> *srv = KoResourceServerProvider::instance()->paletteServer(); | ||
333 | 327 | | |||
334 | if (!srv) { | 328 | if (!srv) { | ||
335 | return m_optionsWidget; | 329 | return m_optionsWidget; | ||
336 | } | 330 | } | ||
337 | 331 | | |||
338 | QList<KoColorSet*> palettes = srv->resources(); | 332 | QList<KoColorSet*> palettes = srv->resources(); | ||
339 | 333 | | |||
340 | Q_FOREACH (KoColorSet *palette, palettes) { | 334 | Q_FOREACH (KoColorSet *palette, palettes) { | ||
Show All 10 Lines | |||||
351 | { | 345 | { | ||
352 | if (!m_optionsWidget) return; | 346 | if (!m_optionsWidget) return; | ||
353 | 347 | | |||
354 | m_optionsWidget->cbNormaliseValues->setChecked(m_config->normaliseValues); | 348 | m_optionsWidget->cbNormaliseValues->setChecked(m_config->normaliseValues); | ||
355 | m_optionsWidget->cbUpdateCurrentColor->setChecked(m_config->updateColor); | 349 | m_optionsWidget->cbUpdateCurrentColor->setChecked(m_config->updateColor); | ||
356 | m_optionsWidget->cmbSources->setCurrentIndex(SAMPLE_MERGED + !m_config->sampleMerged); | 350 | m_optionsWidget->cmbSources->setCurrentIndex(SAMPLE_MERGED + !m_config->sampleMerged); | ||
357 | m_optionsWidget->cbPalette->setChecked(m_config->addPalette); | 351 | m_optionsWidget->cbPalette->setChecked(m_config->addPalette); | ||
358 | m_optionsWidget->radius->setValue(m_config->radius); | 352 | m_optionsWidget->radius->setValue(m_config->radius); | ||
353 | m_optionsWidget->blend->setValue(m_config->blend); | ||||
359 | } | 354 | } | ||
360 | 355 | | |||
361 | void KisToolColorPicker::setToForeground(bool newValue) | 356 | void KisToolColorPicker::setToForeground(bool newValue) | ||
362 | { | 357 | { | ||
363 | m_config->toForegroundColor = newValue; | 358 | m_config->toForegroundColor = newValue; | ||
364 | emit toForegroundChanged(); | 359 | emit toForegroundChanged(); | ||
365 | } | 360 | } | ||
366 | 361 | | |||
367 | bool KisToolColorPicker::toForeground() const | 362 | bool KisToolColorPicker::toForeground() const | ||
368 | { | 363 | { | ||
369 | return m_config->toForegroundColor; | 364 | return m_config->toForegroundColor; | ||
370 | } | 365 | } | ||
371 | 366 | | |||
372 | void KisToolColorPicker::slotSetUpdateColor(bool state) | 367 | void KisToolColorPicker::slotSetUpdateColor(bool state) | ||
373 | { | 368 | { | ||
374 | m_config->updateColor = state; | 369 | m_config->updateColor = state; | ||
375 | } | 370 | } | ||
376 | 371 | | |||
377 | | ||||
378 | void KisToolColorPicker::slotSetNormaliseValues(bool state) | 372 | void KisToolColorPicker::slotSetNormaliseValues(bool state) | ||
379 | { | 373 | { | ||
380 | m_config->normaliseValues = state; | 374 | m_config->normaliseValues = state; | ||
381 | displayPickedColor(); | 375 | displayPickedColor(); | ||
382 | } | 376 | } | ||
383 | 377 | | |||
384 | void KisToolColorPicker::slotSetAddPalette(bool state) | 378 | void KisToolColorPicker::slotSetAddPalette(bool state) | ||
385 | { | 379 | { | ||
386 | m_config->addPalette = state; | 380 | m_config->addPalette = state; | ||
387 | } | 381 | } | ||
388 | 382 | | |||
389 | void KisToolColorPicker::slotChangeRadius(int value) | 383 | void KisToolColorPicker::slotChangeRadius(int value) | ||
390 | { | 384 | { | ||
391 | m_config->radius = value; | 385 | m_config->radius = value; | ||
392 | } | 386 | } | ||
393 | 387 | | |||
388 | void KisToolColorPicker::slotChangeBlend(int value) | ||||
389 | { | ||||
390 | m_config->blend = value; | ||||
391 | } | ||||
392 | | ||||
394 | void KisToolColorPicker::slotSetColorSource(int value) | 393 | void KisToolColorPicker::slotSetColorSource(int value) | ||
395 | { | 394 | { | ||
396 | m_config->sampleMerged = value == SAMPLE_MERGED; | 395 | m_config->sampleMerged = value == SAMPLE_MERGED; | ||
397 | } | 396 | } | ||
398 | 397 | | |||
399 | void KisToolColorPicker::slotAddPalette(KoResource* resource) | 398 | void KisToolColorPicker::slotAddPalette(KoResource *resource) | ||
400 | { | 399 | { | ||
401 | KoColorSet* palette = dynamic_cast<KoColorSet*>(resource); | 400 | KoColorSet *palette = dynamic_cast<KoColorSet*>(resource); | ||
402 | if (palette) { | 401 | if (palette) { | ||
403 | m_optionsWidget->cmbPalette->addSqueezedItem(palette->name()); | 402 | m_optionsWidget->cmbPalette->addSqueezedItem(palette->name()); | ||
404 | m_palettes.append(palette); | 403 | m_palettes.append(palette); | ||
405 | } | 404 | } | ||
406 | } | 405 | } | ||
407 | |