diff --git a/libs/widgets/KisPaletteComboBox.cpp b/libs/widgets/KisPaletteComboBox.cpp --- a/libs/widgets/KisPaletteComboBox.cpp +++ b/libs/widgets/KisPaletteComboBox.cpp @@ -68,7 +68,7 @@ connect(view, SIGNAL(sigIndexSelected(QModelIndex)), SLOT(slotSwatchSelected(QModelIndex))); connect(this, SIGNAL(sigColorSelected(KoColor)), - view, SLOT(slotFGColorChanged(KoColor))); + view, SLOT(slotSelectColor(KoColor))); } void KisPaletteComboBox::slotPaletteChanged() diff --git a/libs/widgets/kis_palette_view.h b/libs/widgets/kis_palette_view.h --- a/libs/widgets/kis_palette_view.h +++ b/libs/widgets/kis_palette_view.h @@ -104,6 +104,18 @@ */ void slotFGColorChanged(const KoColor &); + /** + * @brief slot that reacts to color changes in resource manager + * @param color + */ + void slotFGColorResourceChanged(const KoColor& color); + + /** + * Slot that selects the right index for provided color. + * Called from KisPaletteComboBox when user selects color in the dropdown. + */ + void slotSelectColor(const KoColor& color); + void slotScrollerStateChanged(QScroller::State state){KisKineticScroller::updateCursor(this, state);} private Q_SLOTS: diff --git a/libs/widgets/kis_palette_view.cpp b/libs/widgets/kis_palette_view.cpp --- a/libs/widgets/kis_palette_view.cpp +++ b/libs/widgets/kis_palette_view.cpp @@ -210,6 +210,22 @@ } } +void KisPaletteView::slotFGColorResourceChanged(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); +} + +void KisPaletteView::slotSelectColor(const KoColor &color) +{ + selectClosestColor(color); +} + void KisPaletteView::setPaletteModel(KisPaletteModel *model) { if (m_d->model) { diff --git a/plugins/dockers/palettedocker/palettedocker_dock.h b/plugins/dockers/palettedocker/palettedocker_dock.h --- a/plugins/dockers/palettedocker/palettedocker_dock.h +++ b/plugins/dockers/palettedocker/palettedocker_dock.h @@ -82,6 +82,8 @@ void saveToWorkspace(KisWorkspaceResource* workspace); void loadFromWorkspace(KisWorkspaceResource* workspace); + void slotFGColorResourceChanged(const KoColor& color); + private: void setEntryByForeground(const QModelIndex &index); void setFGColorByPalette(const KisSwatch &entry); @@ -105,6 +107,8 @@ QScopedPointer m_actModify; QScopedPointer m_actEditPalette; QMenu m_viewContextMenu; + + bool m_colorSelfUpdate; }; diff --git a/plugins/dockers/palettedocker/palettedocker_dock.cpp b/plugins/dockers/palettedocker/palettedocker_dock.cpp --- a/plugins/dockers/palettedocker/palettedocker_dock.cpp +++ b/plugins/dockers/palettedocker/palettedocker_dock.cpp @@ -76,6 +76,7 @@ , m_actRemove(new QAction(KisIconUtils::loadIcon("edit-delete"), i18n("Delete color"))) , m_actModify(new QAction(KisIconUtils::loadIcon("edit-rename"), i18n("Modify this spot"))) , m_actEditPalette(new QAction(KisIconUtils::loadIcon("groupLayer"), i18n("Edit this palette"))) + , m_colorSelfUpdate(false) { QWidget *mainWidget = new QWidget(this); setWidget(mainWidget); @@ -150,7 +151,7 @@ connect(m_resourceProvider, SIGNAL(sigLoadingWorkspace(KisWorkspaceResource*)), SLOT(loadFromWorkspace(KisWorkspaceResource*))); connect(m_resourceProvider, SIGNAL(sigFGColorChanged(KoColor)), - m_ui->paletteView, SLOT(slotFGColorChanged(KoColor))); + this, SLOT(slotFGColorResourceChanged(KoColor))); kisview->nodeManager()->disconnect(m_model); } @@ -300,7 +301,9 @@ void PaletteDockerDock::setFGColorByPalette(const KisSwatch &entry) { if (m_resourceProvider) { + m_colorSelfUpdate = true; m_resourceProvider->setFGColor(entry.color()); + m_colorSelfUpdate = false; } } @@ -322,6 +325,13 @@ } } +void PaletteDockerDock::slotFGColorResourceChanged(const KoColor &color) +{ + if (!m_colorSelfUpdate) { + m_ui->paletteView->slotFGColorResourceChanged(color); + } +} + void PaletteDockerDock::slotPaletteIndexSelected(const QModelIndex &index) { bool occupied = qvariant_cast(index.data(KisPaletteModel::CheckSlotRole)); @@ -367,5 +377,7 @@ void PaletteDockerDock::slotNameListSelection(const KoColor &color) { + m_colorSelfUpdate = true; m_resourceProvider->setFGColor(color); + m_colorSelfUpdate = false; }