[krita] libs: FEATURE: make it possible to select the nearest color in the current palette
Boudewijn Rempt
null at kde.org
Mon Oct 15 13:07:03 BST 2018
Git commit 69915f533a67eb8b6141c19b4b41ee95bf79bb73 by Boudewijn Rempt.
Committed on 15/10/2018 at 12:06.
Pushed by rempt into branch 'master'.
FEATURE: make it possible to select the nearest color in the current palette
When enabled, picking a color from the canvas will select the nearest
color in the currently selected palette, so you will always have a
consistent color in use. Default is off, of course.
CCMAIL:kimageshop at kde.org
M +3 -1 libs/ui/dialogs/kis_dlg_preferences.cc
M +7 -0 libs/ui/forms/wdgcolorsettings.ui
M +9 -0 libs/ui/kis_config.cc
M +3 -0 libs/ui/kis_config.h
M +7 -10 libs/widgets/kis_palette_view.cpp
https://commits.kde.org/krita/69915f533a67eb8b6141c19b4b41ee95bf79bb73
diff --git a/libs/ui/dialogs/kis_dlg_preferences.cc b/libs/ui/dialogs/kis_dlg_preferences.cc
index 362f3bd7f02..7a89a68c0b6 100644
--- a/libs/ui/dialogs/kis_dlg_preferences.cc
+++ b/libs/ui/dialogs/kis_dlg_preferences.cc
@@ -481,7 +481,7 @@ ColorSettingsTab::ColorSettingsTab(QWidget *parent, const char *name)
m_page->chkBlackpoint->setChecked(cfg.useBlackPointCompensation());
m_page->chkAllowLCMSOptimization->setChecked(cfg.allowLCMSOptimization());
-
+ m_page->chkForcePaletteColor->setChecked(cfg.forcePaletteColors());
KisImageConfig cfgImage(true);
KisProofingConfigurationSP proofingConfig = cfgImage.defaultProofingconfiguration();
@@ -608,6 +608,7 @@ void ColorSettingsTab::setDefault()
m_page->chkBlackpoint->setChecked(cfg.useBlackPointCompensation(true));
m_page->chkAllowLCMSOptimization->setChecked(cfg.allowLCMSOptimization(true));
+ m_page->chkForcePaletteColor->setChecked(cfg.forcePaletteColors(true));
m_page->cmbMonitorIntent->setCurrentIndex(cfg.monitorRenderIntent(true));
m_page->chkUseSystemMonitorProfile->setChecked(cfg.useSystemMonitorProfile(true));
QAbstractButton *button = m_pasteBehaviourGroup.button(cfg.pasteBehaviour(true));
@@ -1380,6 +1381,7 @@ bool KisDlgPreferences::editPreferences()
(double)dialog->m_colorSettings->m_page->sldAdaptationState->value()/20);
cfg.setUseBlackPointCompensation(dialog->m_colorSettings->m_page->chkBlackpoint->isChecked());
cfg.setAllowLCMSOptimization(dialog->m_colorSettings->m_page->chkAllowLCMSOptimization->isChecked());
+ cfg.setForcePaletteColors(dialog->m_colorSettings->m_page->chkForcePaletteColor->isChecked());
cfg.setPasteBehaviour(dialog->m_colorSettings->m_pasteBehaviourGroup.checkedId());
cfg.setRenderIntent(dialog->m_colorSettings->m_page->cmbMonitorIntent->currentIndex());
diff --git a/libs/ui/forms/wdgcolorsettings.ui b/libs/ui/forms/wdgcolorsettings.ui
index 7502b1cadcf..3a619b76b7c 100644
--- a/libs/ui/forms/wdgcolorsettings.ui
+++ b/libs/ui/forms/wdgcolorsettings.ui
@@ -111,6 +111,13 @@
</property>
</widget>
</item>
+ <item>
+ <widget class="QCheckBox" name="chkForcePaletteColor">
+ <property name="text">
+ <string>Enforce palette colors: always select the nearest color from the active palette.</string>
+ </property>
+ </widget>
+ </item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
diff --git a/libs/ui/kis_config.cc b/libs/ui/kis_config.cc
index ecdba149d1f..0eba622a794 100644
--- a/libs/ui/kis_config.cc
+++ b/libs/ui/kis_config.cc
@@ -575,6 +575,15 @@ void KisConfig::setAllowLCMSOptimization(bool allowLCMSOptimization)
m_cfg.writeEntry("allowLCMSOptimization", allowLCMSOptimization);
}
+bool KisConfig::forcePaletteColors(bool defaultValue) const
+{
+ return (defaultValue ? false : m_cfg.readEntry("colorsettings/forcepalettecolors", false));
+}
+
+void KisConfig::setForcePaletteColors(bool forcePaletteColors)
+{
+ m_cfg.writeEntry("colorsettings/forcepalettecolors", forcePaletteColors);
+}
bool KisConfig::showRulers(bool defaultValue) const
{
diff --git a/libs/ui/kis_config.h b/libs/ui/kis_config.h
index e56793d546b..eb7aa92606d 100644
--- a/libs/ui/kis_config.h
+++ b/libs/ui/kis_config.h
@@ -151,6 +151,9 @@ public:
bool allowLCMSOptimization(bool defaultValue = false) const;
void setAllowLCMSOptimization(bool allowLCMSOptimization);
+ bool forcePaletteColors(bool defaultValue = false) const;
+ void setForcePaletteColors(bool forcePaletteColors);
+
void writeKoColor(const QString& name, const KoColor& color) const;
KoColor readKoColor(const QString& name, const KoColor& color = KoColor()) const;
diff --git a/libs/widgets/kis_palette_view.cpp b/libs/widgets/kis_palette_view.cpp
index 69fcd8a0e2f..6fa8ebbe6ab 100644
--- a/libs/widgets/kis_palette_view.cpp
+++ b/libs/widgets/kis_palette_view.cpp
@@ -48,15 +48,13 @@ int KisPaletteView::MININUM_ROW_HEIGHT = 10;
struct KisPaletteView::Private
{
QPointer<KisPaletteModel> model;
- bool allowPaletteModification; // if modification is allowed from this widget
+ bool allowPaletteModification {false}; // if modification is allowed from this widget
};
KisPaletteView::KisPaletteView(QWidget *parent)
: QTableView(parent)
, m_d(new Private)
{
- m_d->allowPaletteModification = false;
-
setItemDelegate(new KisPaletteDelegate(this));
setShowGrid(true);
@@ -206,9 +204,10 @@ void KisPaletteView::selectClosestColor(const KoColor &color)
void KisPaletteView::slotFGColorChanged(const KoColor &color)
{
- //TODO: We'll need a switch that implements forcing the paint
- //color to always be one from the palette.
- //selectClosestColor(color);
+ KConfigGroup group(KSharedConfig::openConfig(), "");
+ if (group.readEntry("colorsettings/forcepalettecolors", false)) {
+ selectClosestColor(color);
+ }
}
void KisPaletteView::setPaletteModel(KisPaletteModel *model)
@@ -219,11 +218,9 @@ void KisPaletteView::setPaletteModel(KisPaletteModel *model)
m_d->model = model;
setModel(model);
slotAdditionalGuiUpdate();
- connect(model, SIGNAL(sigPaletteModified()),
- SLOT(slotAdditionalGuiUpdate()));
- connect(model, SIGNAL(sigPaletteChanged()),
- SLOT(slotAdditionalGuiUpdate()));
+ connect(model, SIGNAL(sigPaletteModified()), SLOT(slotAdditionalGuiUpdate()));
+ connect(model, SIGNAL(sigPaletteChanged()), SLOT(slotAdditionalGuiUpdate()));
connect(selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), SLOT(slotCurrentSelectionChanged(QModelIndex)));
}
More information about the kimageshop
mailing list