Changeset View
Changeset View
Standalone View
Standalone View
plugins/tools/tool_lazybrush/kis_tool_lazy_brush_options_widget.cpp
Context not available. | |||||
37 | struct KisToolLazyBrushOptionsWidget::Private | 37 | struct KisToolLazyBrushOptionsWidget::Private | ||
---|---|---|---|---|---|
38 | { | 38 | { | ||
39 | Private() | 39 | Private() | ||
40 | : transparentColorIndex(-1), | 40 | : baseNodeChangedCompressor(500, KisSignalCompressor::FIRST_ACTIVE) | ||
41 | baseNodeChangedCompressor(500, KisSignalCompressor::FIRST_ACTIVE) | | |||
42 | { | 41 | { | ||
43 | } | 42 | } | ||
44 | 43 | | |||
Context not available. | |||||
51 | KisColorizeMaskSP activeMask; | 50 | KisColorizeMaskSP activeMask; | ||
52 | 51 | | |||
53 | KoColorSet colorSet; | 52 | KoColorSet colorSet; | ||
54 | int transparentColorIndex = -1; | 53 | int transparentColorIndex; | ||
55 | 54 | | |||
56 | KisSignalCompressor baseNodeChangedCompressor; | 55 | KisSignalCompressor baseNodeChangedCompressor; | ||
57 | }; | 56 | }; | ||
Context not available. | |||||
102 | "that are placed outside the closed contours. 0% - no effect, 100% - max effect")); | 101 | "that are placed outside the closed contours. 0% - no effect, 100% - max effect")); | ||
103 | 102 | | |||
104 | 103 | | |||
105 | connect(m_d->ui->colorView, SIGNAL(indexEntrySelected(QModelIndex)), this, SLOT(entrySelected(QModelIndex))); | 104 | connect(m_d->ui->colorView, SIGNAL(sigIndexSelected(QModelIndex)), this, SLOT(entrySelected(QModelIndex))); | ||
106 | connect(m_d->ui->btnTransparent, SIGNAL(toggled(bool)), this, SLOT(slotMakeTransparent(bool))); | 105 | connect(m_d->ui->btnTransparent, SIGNAL(toggled(bool)), this, SLOT(slotMakeTransparent(bool))); | ||
107 | connect(m_d->ui->btnRemove, SIGNAL(clicked()), this, SLOT(slotRemove())); | 106 | connect(m_d->ui->btnRemove, SIGNAL(clicked()), this, SLOT(slotRemove())); | ||
108 | 107 | | |||
Context not available. | |||||
115 | 114 | | |||
116 | connect(&m_d->baseNodeChangedCompressor, SIGNAL(timeout()), this, SLOT(slotUpdateNodeProperties())); | 115 | connect(&m_d->baseNodeChangedCompressor, SIGNAL(timeout()), this, SLOT(slotUpdateNodeProperties())); | ||
117 | 116 | | |||
118 | | ||||
119 | m_d->provider = provider; | 117 | m_d->provider = provider; | ||
120 | 118 | | |||
121 | const KoColorSpace *cs = KoColorSpaceRegistry::instance()->rgb8(); | 119 | m_d->colorSet.setIsGlobal(false); | ||
120 | m_d->colorSet.setIsEditable(true); | ||||
121 | m_d->colorModel->setPalette(&m_d->colorSet); | ||||
122 | 122 | | |||
123 | m_d->colorSet.add(KoColorSetEntry(KoColor(Qt::red, cs), "color1")); | 123 | const KoColorSpace *cs = KoColorSpaceRegistry::instance()->rgb8(); | ||
124 | m_d->colorSet.add(KoColorSetEntry(KoColor(Qt::green, cs), "color2")); | | |||
125 | m_d->colorSet.add(KoColorSetEntry(KoColor(Qt::blue, cs), "color3")); | | |||
126 | 124 | | |||
127 | m_d->colorModel->setColorSet(&m_d->colorSet); | 125 | m_d->colorModel->addEntry(KisSwatch(KoColor(Qt::red, cs), "color1")); | ||
126 | m_d->colorModel->addEntry(KisSwatch(KoColor(Qt::green, cs), "color2")); | ||||
127 | m_d->colorModel->addEntry(KisSwatch(KoColor(Qt::blue, cs), "color3")); | ||||
128 | } | 128 | } | ||
129 | 129 | | |||
130 | KisToolLazyBrushOptionsWidget::~KisToolLazyBrushOptionsWidget() | 130 | KisToolLazyBrushOptionsWidget::~KisToolLazyBrushOptionsWidget() | ||
Context not available. | |||||
157 | void KisToolLazyBrushOptionsWidget::entrySelected(QModelIndex index) | 157 | void KisToolLazyBrushOptionsWidget::entrySelected(QModelIndex index) | ||
158 | { | 158 | { | ||
159 | if (!index.isValid()) return; | 159 | if (!index.isValid()) return; | ||
160 | if (!qvariant_cast<bool>(index.data(KisPaletteModel::CheckSlotRole))) return; | ||||
160 | 161 | | |||
161 | const int i = m_d->colorModel->idFromIndex(index); | 162 | KisSwatch entry = m_d->colorModel->getEntry(index); | ||
163 | m_d->provider->setFGColor(entry.color()); | ||||
162 | 164 | | |||
163 | if (i >= 0 && i < (int)m_d->colorSet.nColors()) { | 165 | int idxInList = m_d->activeMask->keyStrokesColors().colors.indexOf(entry.color()); | ||
164 | KoColorSetEntry entry = m_d->colorModel->colorSetEntryFromIndex(index); | | |||
165 | m_d->provider->setFGColor(entry.color()); | | |||
166 | } | | |||
167 | 166 | | |||
168 | const bool transparentChecked = i >= 0 && i == m_d->transparentColorIndex; | 167 | if (idxInList != -1) { | ||
169 | KisSignalsBlocker b(m_d->ui->btnTransparent); | 168 | const bool transparentChecked = idxInList == m_d->transparentColorIndex; | ||
170 | m_d->ui->btnTransparent->setChecked(transparentChecked); | 169 | KisSignalsBlocker b(m_d->ui->btnTransparent); | ||
170 | m_d->ui->btnTransparent->setChecked(transparentChecked); | ||||
171 | } | ||||
171 | } | 172 | } | ||
172 | 173 | | |||
173 | void KisToolLazyBrushOptionsWidget::slotCurrentFgColorChanged(const KoColor &color) | 174 | void KisToolLazyBrushOptionsWidget::slotCurrentFgColorChanged(const KoColor &color) | ||
174 | { | 175 | { | ||
175 | int selectedIndex = -1; | 176 | bool found = false; | ||
176 | 177 | | |||
177 | for (quint32 i = 0; i < m_d->colorSet.nColors(); i++) { | 178 | QModelIndex candidateIdx = m_d->colorModel->indexForClosest(color); | ||
178 | KoColorSetEntry entry = m_d->colorSet.getColorGlobal(i); | 179 | if (m_d->colorModel->getEntry(candidateIdx).color() == color) { | ||
179 | if (entry.color() == color) { | 180 | found = true; | ||
180 | selectedIndex = (int)i; | | |||
181 | break; | | |||
182 | } | | |||
183 | } | 181 | } | ||
184 | 182 | | |||
185 | m_d->ui->btnRemove->setEnabled(selectedIndex >= 0); | 183 | m_d->ui->btnRemove->setEnabled(found); | ||
186 | m_d->ui->btnTransparent->setEnabled(selectedIndex >= 0); | 184 | m_d->ui->btnTransparent->setEnabled(found); | ||
187 | 185 | | |||
188 | if (selectedIndex < 0) { | 186 | if (!found) { | ||
189 | KisSignalsBlocker b(m_d->ui->btnTransparent); | 187 | KisSignalsBlocker b(m_d->ui->btnTransparent); | ||
190 | m_d->ui->btnTransparent->setChecked(false); | 188 | m_d->ui->btnTransparent->setChecked(false); | ||
191 | } | 189 | } | ||
192 | 190 | | |||
193 | QModelIndex newIndex = | 191 | QModelIndex newIndex = found ? candidateIdx : QModelIndex(); | ||
194 | selectedIndex >= 0 ? | | |||
195 | m_d->colorModel->indexFromId(selectedIndex) : QModelIndex(); | | |||
196 | 192 | | |||
197 | if (newIndex != m_d->ui->colorView->currentIndex()) { | 193 | if (!found) { | ||
194 | m_d->ui->colorView->selectionModel()->clear(); | ||||
195 | } | ||||
196 | if (newIndex.isValid() && newIndex != m_d->ui->colorView->currentIndex()) { | ||||
198 | m_d->ui->colorView->setCurrentIndex(newIndex); | 197 | m_d->ui->colorView->setCurrentIndex(newIndex); | ||
198 | m_d->ui->colorView->update(newIndex); | ||||
199 | } | 199 | } | ||
200 | } | 200 | } | ||
201 | 201 | | |||
202 | void KisToolLazyBrushOptionsWidget::slotColorLabelsChanged() | 202 | void KisToolLazyBrushOptionsWidget::slotColorLabelsChanged() | ||
203 | { | 203 | { | ||
204 | m_d->colorSet.clear(); | 204 | m_d->colorModel->clear(); | ||
205 | | ||||
205 | m_d->transparentColorIndex = -1; | 206 | m_d->transparentColorIndex = -1; | ||
206 | 207 | | |||
207 | if (m_d->activeMask) { | 208 | if (m_d->activeMask) { | ||
Context not available. | |||||
210 | 211 | | |||
211 | for (int i = 0; i < colors.colors.size(); i++) { | 212 | for (int i = 0; i < colors.colors.size(); i++) { | ||
212 | const QString name = i == m_d->transparentColorIndex ? "transparent" : ""; | 213 | const QString name = i == m_d->transparentColorIndex ? "transparent" : ""; | ||
213 | m_d->colorSet.add(KoColorSetEntry(colors.colors[i], name)); | 214 | m_d->colorModel->addEntry(KisSwatch(colors.colors[i], name)); | ||
214 | } | 215 | } | ||
215 | } | 216 | } | ||
216 | 217 | | |||
217 | m_d->colorModel->setColorSet(&m_d->colorSet); | | |||
218 | slotCurrentFgColorChanged(m_d->provider->fgColor()); | 218 | slotCurrentFgColorChanged(m_d->provider->fgColor()); | ||
219 | } | 219 | } | ||
220 | 220 | | |||
Context not available. | |||||
289 | KIS_ASSERT_RECOVER_RETURN(m_d->activeMask); | 289 | KIS_ASSERT_RECOVER_RETURN(m_d->activeMask); | ||
290 | 290 | | |||
291 | QModelIndex index = m_d->ui->colorView->currentIndex(); | 291 | QModelIndex index = m_d->ui->colorView->currentIndex(); | ||
292 | KisSwatch activeSwatch = m_d->colorModel->getEntry(index); | ||||
292 | if (!index.isValid()) return; | 293 | if (!index.isValid()) return; | ||
293 | 294 | | |||
294 | const int activeIndex = m_d->colorModel->idFromIndex(index); | 295 | int activeIndex = -1; | ||
295 | KIS_ASSERT_RECOVER_RETURN(activeIndex >= 0); | | |||
296 | 296 | | |||
297 | KisColorizeMask::KeyStrokeColors colors; | 297 | KisColorizeMask::KeyStrokeColors colors; | ||
298 | 298 | | |||
299 | for (quint32 i = 0; i < m_d->colorSet.nColors(); i++) { | 299 | int i = 0; | ||
300 | colors.colors << m_d->colorSet.getColorGlobal(i).color(); | 300 | Q_FOREACH (const QString &groupName, m_d->colorSet.getGroupNames()) { | ||
301 | KisSwatchGroup *group = m_d->colorSet.getGroup(groupName); | ||||
302 | Q_FOREACH (const KisSwatchGroup::SwatchInfo &info, group->infoList()) { | ||||
303 | colors.colors << info.swatch.color(); | ||||
304 | if (activeSwatch == info.swatch) { activeIndex = i; } | ||||
305 | i++; | ||||
306 | } | ||||
301 | } | 307 | } | ||
302 | 308 | | |||
303 | colors.transparentIndex = value ? activeIndex : -1; | 309 | colors.transparentIndex = value ? activeIndex : -1; | ||
Context not available. | |||||
312 | QModelIndex index = m_d->ui->colorView->currentIndex(); | 318 | QModelIndex index = m_d->ui->colorView->currentIndex(); | ||
313 | if (!index.isValid()) return; | 319 | if (!index.isValid()) return; | ||
314 | 320 | | |||
315 | const int activeIndex = m_d->colorModel->idFromIndex(index); | 321 | const KoColor color = m_d->colorModel->getEntry(index).color(); | ||
316 | KIS_ASSERT_RECOVER_RETURN(activeIndex >= 0); | | |||
317 | | ||||
318 | | ||||
319 | const KoColor color = m_d->colorSet.getColorGlobal((quint32)activeIndex).color(); | | |||
320 | m_d->activeMask->removeKeyStroke(color); | 322 | m_d->activeMask->removeKeyStroke(color); | ||
321 | } | 323 | } | ||
322 | 324 | | |||
Context not available. |