Commit c06107d6 authored by Anna Medonosová's avatar Anna Medonosová

Fix 'Enforce palette colors' feature

Since the 'Enforce palette colors' is a feature of the internal color
selector, this commit moves the functionality from KisPaletteView to
KisDlgInternalColorSelector. Also, that way the color change is forced
only once upon foreground color change, preventing cycling signals and confusing color changes
(KisPaletteView can be used more than once with different color palettes).

Removes KisPaletteView::slotFGColorResourceChanged, the function is
obsolete: it was meant to solve bug 402072 that is now fixed in a better way.

BACKPORT:krita/4.2
BUG:408256
CCBUG:402072
parent e09e18e5
......@@ -181,6 +181,12 @@ void KisDlgInternalColorSelector::slotColorUpdated(KoColor newColor)
{
//if the update did not come from this selector...
if (m_d->allowUpdates || QObject::sender() == this->parent()) {
// Enforce palette colors
KConfigGroup group(KSharedConfig::openConfig(), "");
if (group.readEntry("colorsettings/forcepalettecolors", false)) {
newColor = m_ui->paletteBox->closestColor(newColor);
}
if (m_d->lockUsedCS){
newColor.convertTo(m_d->currentColorSpace);
m_d->currentColor = newColor;
......@@ -283,8 +289,7 @@ void KisDlgInternalColorSelector::updateAllElements(QObject *source)
m_d->hexColorInput->update();
}
KConfigGroup group(KSharedConfig::openConfig(), "");
if (source != m_ui->paletteBox && group.readEntry("colorsettings/forcepalettecolors", false)) {
if (source != m_ui->paletteBox) {
m_ui->paletteBox->selectClosestColor(m_d->currentColor);
}
......
......@@ -201,26 +201,20 @@ void KisPaletteView::selectClosestColor(const KoColor &color)
selectionModel()->clearSelection();
QModelIndex index = m_d->model->indexForClosest(color);
selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select);
}
void KisPaletteView::slotFGColorChanged(const KoColor &color)
const KoColor KisPaletteView::closestColor(const KoColor &color) const
{
KConfigGroup group(KSharedConfig::openConfig(), "");
if (group.readEntry("colorsettings/forcepalettecolors", false)) {
selectClosestColor(color);
}
QModelIndex index = m_d->model->indexForClosest(color);
KisSwatch swatch = m_d->model->getEntry(index);
return swatch.color();
}
void KisPaletteView::slotFGColorResourceChanged(const KoColor& color)
void KisPaletteView::slotFGColorChanged(const KoColor &color)
{
// This slot is called, because fg color was changed in the resource manager.
// To enable re-picking the swatch color again, we reset currentIndex
// of the selectionModel. We are not clearing the selection itself,
// so the user can see the swatch selected previously.
// See bug 402072
selectionModel()->clearCurrentIndex();
slotFGColorChanged(color);
selectClosestColor(color);
}
void KisPaletteView::setPaletteModel(KisPaletteModel *model)
......
......@@ -74,6 +74,14 @@ public:
*/
void selectClosestColor(const KoColor &color);
/**
* @brief closestColor
* determines closest swatch in the active palette and returns it's color as KoColor
* @param color
* @return KoColor
*/
const KoColor closestColor(const KoColor& color) const;
/**
* add an entry with a dialog window.
* @warning deprecated.
......@@ -104,12 +112,6 @@ public Q_SLOTS:
*/
void slotFGColorChanged(const KoColor &);
/**
* @brief slot that reacts to color changes in resource manager
* @param color
*/
void slotFGColorResourceChanged(const KoColor& color);
void slotScrollerStateChanged(QScroller::State state){KisKineticScroller::updateCursor(this, state);}
private Q_SLOTS:
......
......@@ -328,7 +328,7 @@ void PaletteDockerDock::loadFromWorkspace(KisWorkspaceResource* workspace)
void PaletteDockerDock::slotFGColorResourceChanged(const KoColor &color)
{
if (!m_colorSelfUpdate) {
m_ui->paletteView->slotFGColorResourceChanged(color);
m_ui->paletteView->slotFGColorChanged(color);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment