Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Rework the color history on the advanced selectors' side.
Wolthera van Hövell tot Westerflier53c5726bccde
diff --git a/plugins/dockers/advancedcolorselector/kis_color_history.cpp b/plugins/dockers/advancedcolorselector/kis_color_history.cppindex d752f3fa79..fd78d94be1 100644--- a/plugins/dockers/advancedcolorselector/kis_color_history.cpp+++ b/plugins/dockers/advancedcolorselector/kis_color_history.cpp@@ -35,7 +35,7 @@ KisColorHistory::KisColorHistory(QWidget *parent)connect(m_clearButton, SIGNAL(clicked()), this, SLOT(clearColorHistory()));connect(KisConfigNotifier::instance(), SIGNAL(colorHistoryModeChanged()), this, SLOT(updateUserSettings()));connect(s_color_history_change_notifier, SIGNAL(colorHistoryChanged(const QList<KoColor>&)),- this, SLOT(colorHistoryChanged(const QList<KoColor>&)));+ this, SLOT(colorHistoryChanged()));setAdditionalButtons({m_clearButton});}@@ -56,15 +56,24 @@ void KisColorHistory::setCanvas(KisCanvas2 *canvas)if (m_resourceProvider) {m_resourceProvider->disconnect(this);+ m_resourceProvider->colorHistory()->disconnect(this);+ }+ if (m_document) {+ m_document->colorHistory()->disconnect(this);}m_resourceProvider = canvas->imageView()->resourceProvider();m_document = canvas->viewManager()->document();- setColors(colorHistory());+ setColors(colorHistory()->colorList());connect(m_resourceProvider, SIGNAL(sigFGColorUsed(KoColor)),this, SLOT(addColorToHistory(KoColor)), Qt::UniqueConnection);++ // Messy, but this whole plugin should be removed shortly in favour of the wide gamut selector.+ // We only really need this so the plugin will respond to the color history being cleared in the wide gamut selector.+ connect(m_resourceProvider->colorHistory(), SIGNAL(sigReset()), this, SLOT(colorHistoryChanged()));+ connect(m_document->colorHistory(), SIGNAL(sigReset()), this, SLOT(colorHistoryChanged()));}KisColorSelectorBase *KisColorHistory::createPopup() const@@ -80,45 +89,35 @@ void KisColorHistory::addColorToHistory(const KoColor &color)// don't add color in erase mode. See https://bugs.kde.org/show_bug.cgi?id=298940if (m_resourceProvider && m_resourceProvider->currentCompositeOp() == COMPOSITE_ERASE) return;- KisColorPatches::addColorPatch(color);+ colorHistory()->addColor(color);- updateColorHistory(colors());- s_color_history_change_notifier->notifyColorHistoryChanged(colors());+ updateColorHistory(colorHistory()->colorList());+ s_color_history_change_notifier->notifyColorHistoryChanged(colorHistory()->colorList());}void KisColorHistory::clearColorHistory(){QList<KoColor> empty;+ colorHistory()->clear();updateColorHistory(empty);s_color_history_change_notifier->notifyColorHistoryChanged(empty);}-QList<KoColor> KisColorHistory::colorHistory()+KisUniqueColorSet *KisColorHistory::colorHistory(){if (m_history_per_document && m_document) {- return m_document->colorHistory()->colorList();+ return m_document->colorHistory();} else if (m_resourceProvider) {- return m_resourceProvider->colorHistory()->colorList();+ return m_resourceProvider->colorHistory();} else {- return QList<KoColor>();+ return new KisUniqueColorSet(this);}}void KisColorHistory::updateColorHistory(const QList<KoColor> &history){- if (m_history_per_document && m_document) {- m_document->colorHistory()->setFromColorList(history);- }-- /**- * Resource provider saves the history all the time, whatever the- * option state is.- */- if (m_resourceProvider) {- m_resourceProvider->colorHistory()->setFromColorList(history);- }-- setColors(history);+ Q_UNUSED(history);+ setColors(colorHistory()->colorList());}void KisColorHistory::updateUserSettings()@@ -126,17 +125,13 @@ void KisColorHistory::updateUserSettings()KisConfig config(true);m_history_per_document = config.colorHistoryPerDocument();- updateColorHistory(colorHistory()); // Show with respect to the current strategy+ updateColorHistory(colorHistory()->colorList()); // Show with respect to the current strategy}-void KisColorHistory::colorHistoryChanged(const QList<KoColor> &history)+void KisColorHistory::colorHistoryChanged(){KIS_SAFE_ASSERT_RECOVER_RETURN(sender() != this);-- if (m_resourceProvider) {- m_resourceProvider->colorHistory()->setFromColorList(history);- }- setColors(history);+ setColors(colorHistory()->colorList());}void KisColorHistoryNotifier::notifyColorHistoryChanged(const QList<KoColor> &history)diff --git a/plugins/dockers/advancedcolorselector/kis_color_history.h b/plugins/dockers/advancedcolorselector/kis_color_history.hindex 36b11a8afd..b37d82c70e 100644--- a/plugins/dockers/advancedcolorselector/kis_color_history.h+++ b/plugins/dockers/advancedcolorselector/kis_color_history.h@@ -12,6 +12,7 @@class QToolButton;class KisCanvasResourceProvider;class KisColorHistoryNotifier;+class KisUniqueColorSet;class KisColorHistory : public KisColorPatches{@@ -32,11 +33,11 @@ public Q_SLOTS:void updateUserSettings();// Receive notification that the color history changed in some selector- void colorHistoryChanged(const QList<KoColor> &history);+ void colorHistoryChanged();private:// Get reference to the relevant color history, either from resource provider or document.- QList<KoColor> colorHistory();+ KisUniqueColorSet *colorHistory();// Write the changed color history where it is stored, depending on the settings.void updateColorHistory(const QList<KoColor> &history);