[graphics/krita] libs/ui: GUI: Add a "Clear colors" button to the popup palette
Boudewijn Rempt
null at kde.org
Thu Oct 8 11:12:29 BST 2020
Git commit cd6e08d1e0c1deb3c8e85a6b5f6af998d30ef19e by Boudewijn Rempt, on behalf of Emilio Del Castillo.
Committed on 08/10/2020 at 10:12.
Pushed by rempt into branch 'master'.
GUI: Add a "Clear colors" button to the popup palette
This adds the possibility to clear the color history from the popup palette.
M +13 -1 libs/ui/kis_favorite_resource_manager.cpp
M +4 -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/cd6e08d1e0c1deb3c8e85a6b5f6af998d30ef19e
diff --git a/libs/ui/kis_favorite_resource_manager.cpp b/libs/ui/kis_favorite_resource_manager.cpp
index cd9edc39a6..4a29e94e87 100644
--- a/libs/ui/kis_favorite_resource_manager.cpp
+++ b/libs/ui/kis_favorite_resource_manager.cpp
@@ -37,7 +37,6 @@
#include <kis_paintop_preset.h>
-
class KisFavoriteResourceManager::ColorDataList
{
public:
@@ -96,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++);
@@ -303,6 +310,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 35a062e97b..182dc27059 100644
--- a/libs/ui/kis_favorite_resource_manager.h
+++ b/libs/ui/kis_favorite_resource_manager.h
@@ -69,6 +69,7 @@ public:
//BgColor;
KoColor bgColor() const;
+
Q_SIGNALS:
void sigSetFGColor(const KoColor& c);
@@ -96,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 configChanged();
diff --git a/libs/ui/kis_popup_palette.cpp b/libs/ui/kis_popup_palette.cpp
index 2872c9a635..0ba499457a 100644
--- a/libs/ui/kis_popup_palette.cpp
+++ b/libs/ui/kis_popup_palette.cpp
@@ -249,12 +249,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);
@@ -587,7 +598,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