[graphics/krita/krita/4.3] libs/ui: GUI: Add a "Clear colors" button to the popup palette

Boudewijn Rempt null at kde.org
Thu Oct 8 11:20:11 BST 2020


Git commit d12f9a74d2404325331e03a82845f8ee48876152 by Boudewijn Rempt, on behalf of Emilio Del Castillo.
Committed on 08/10/2020 at 10:13.
Pushed by rempt into branch 'krita/4.3'.

GUI: Add a "Clear colors" button to the popup palette

This adds the possibility to clear the color history from the popup palette.

(cherry picked from commit cd6e08d1e0c1deb3c8e85a6b5f6af998d30ef19e)

M  +15   -0    libs/ui/kis_favorite_resource_manager.cpp
M  +3    -0    libs/ui/kis_favorite_resource_manager.h
M  +11   -1    libs/ui/kis_popup_palette.cpp
M  +1    -0    libs/ui/kis_popup_palette.h

https://invent.kde.org/graphics/krita/commit/d12f9a74d2404325331e03a82845f8ee48876152

diff --git a/libs/ui/kis_favorite_resource_manager.cpp b/libs/ui/kis_favorite_resource_manager.cpp
index bca8e0f365..cebc53453b 100644
--- a/libs/ui/kis_favorite_resource_manager.cpp
+++ b/libs/ui/kis_favorite_resource_manager.cpp
@@ -34,6 +34,8 @@
 #include "kis_min_heap.h"
 #include "kis_config.h"
 #include "kis_config_notifier.h"
+#include <kis_paintop_preset.h>
+
 
 class KisFavoriteResourceManager::ColorDataList
 {
@@ -93,6 +95,14 @@ public:
         m_priorityList.remove(0);
     }
 
+    void clearHistory() {
+        Q_ASSERT_X(size() >= 0, "ColorDataList::clearHistory", "index out of bound");
+        if (size() <= 0 ) return;
+        while (size() > 0){
+            removeLeastUsed();
+        }
+    }
+
     void updateKey(int guiPos) {
         if (m_guiList.at(guiPos)->key == m_key - 1) return;
         m_priorityList.changeKey(m_guiList.at(guiPos)->pos, m_key++);
@@ -299,6 +309,11 @@ int KisFavoriteResourceManager::recentColorsTotal()
     return m_colorList->size();
 }
 
+void KisFavoriteResourceManager::slotClearHistory()
+{
+    m_colorList->clearHistory();
+}
+
 const KoColor& KisFavoriteResourceManager::recentColorAt(int pos)
 {
     return m_colorList->guiColor(pos);
diff --git a/libs/ui/kis_favorite_resource_manager.h b/libs/ui/kis_favorite_resource_manager.h
index 19d1b5b128..6ebb93d39d 100644
--- a/libs/ui/kis_favorite_resource_manager.h
+++ b/libs/ui/kis_favorite_resource_manager.h
@@ -97,6 +97,9 @@ public Q_SLOTS:
 
     void slotSetBGColor(const KoColor c);
 
+    /** Clears the color history shown in the popup palette. */
+    void slotClearHistory();
+
 private Q_SLOTS:
     void updateFavoritePresets();
     void configChanged();
diff --git a/libs/ui/kis_popup_palette.cpp b/libs/ui/kis_popup_palette.cpp
index 77f5057e06..0d2937bd94 100644
--- a/libs/ui/kis_popup_palette.cpp
+++ b/libs/ui/kis_popup_palette.cpp
@@ -245,12 +245,23 @@ KisPopupPalette::KisPopupPalette(KisViewManager* viewManager, KisCoordinatesConv
     connect(zoomCanvasSlider, SIGNAL(sliderPressed()), this, SLOT(slotZoomSliderPressed()));
     connect(zoomCanvasSlider, SIGNAL(sliderReleased()), this, SLOT(slotZoomSliderReleased()));
 
+    clearHistoryButton = new QPushButton(this);
+    clearHistoryButton->setFixedHeight(35);
+
+    clearHistoryButton->setText(i18n("Clear colors"));
+    clearHistoryButton->setToolTip(i18n("Clear the colors of the popup palette"));
+
+    connect(clearHistoryButton, SIGNAL(clicked(bool)), m_resourceManager, SLOT(slotClearHistory()));
+    //Otherwise the colors won't disappear until the cursor moves away from the button:
+    connect(clearHistoryButton, SIGNAL(released()), this, SLOT(slotUpdate()));
+
     slotUpdateIcons();
 
     hLayout->addWidget(mirrorMode);
     hLayout->addWidget(canvasOnlyButton);
     hLayout->addWidget(zoomToOneHundredPercentButton);
     hLayout->addWidget(zoomCanvasSlider);
+    hLayout->addWidget(clearHistoryButton);
 
     setVisible(true);
     setVisible(false);
@@ -583,7 +594,6 @@ void KisPopupPalette::paintEvent(QPaintEvent* e)
             painter.drawPath(recentColorsPath);
             painter.rotate(rotationAngle);
         }
-
     }
 
     // painting hovered color
diff --git a/libs/ui/kis_popup_palette.h b/libs/ui/kis_popup_palette.h
index 8938c7732b..0fc7351ad4 100644
--- a/libs/ui/kis_popup_palette.h
+++ b/libs/ui/kis_popup_palette.h
@@ -140,6 +140,7 @@ private:
     QSlider *zoomCanvasSlider {0};
     int zoomSliderMinValue {10};
     int zoomSliderMaxValue {200};
+    QPushButton *clearHistoryButton {0};
     KisAcyclicSignalConnector *m_acyclicConnector = 0;
 
     int m_cachedNumSlots {0};



More information about the kde-doc-english mailing list