From 4e4c18ee2f94e95876873b6ae8ae765f3398486b Mon Sep 17 00:00:00 2001 From: ftomara Date: Tue, 25 Nov 2025 10:12:25 +0200 Subject: [PATCH] Fix marker recolor button logic to not appear if the marker has no colors so it doesnt open an empty color list updated colorlist when changing marker and the recolor popover is open --- src/ui/widget/recolor-art-manager.cpp | 71 +++++++++++++++++++----- src/ui/widget/recolor-art-manager.h | 1 + src/ui/widget/recolor-art.cpp | 4 -- src/ui/widget/style/marker-combo-box.cpp | 10 +++- 4 files changed, 65 insertions(+), 21 deletions(-) diff --git a/src/ui/widget/recolor-art-manager.cpp b/src/ui/widget/recolor-art-manager.cpp index 8780d3a25c..1622bd02b8 100644 --- a/src/ui/widget/recolor-art-manager.cpp +++ b/src/ui/widget/recolor-art-manager.cpp @@ -13,33 +13,40 @@ #include "object/sp-gradient.h" #include "object/sp-pattern.h" #include "object/sp-use.h" +#include "object/sp-marker.h" #include "style.h" namespace Inkscape::UI::Widget { namespace { -bool has_colors_pattern(SPItem const *item) +class MoreThan1ColorChecker { - if (!item || !item->style) { - return false; - } - - std::optional first_col; - - // Return true when a second colour is found. - auto check_color = [&] (SPIPaint const &paint) { +public: + bool operator()(SPIPaint const &paint) + { if (!paint.isColor()) { return false; } - if (!first_col) { - first_col = paint.getColor(); + if (!_first) { + _first = paint.getColor(); return false; } else { - return paint.getColor() != first_col; + return paint.getColor() != _first; } - }; + } + +private: + std::optional _first; +}; +bool has_colors_pattern(SPItem const *item) +{ + if (!item || !item->style) { + return false; + } + + MoreThan1ColorChecker check; // Search a pattern for colours, returning true when a second colour is found. auto search_pattern = [&] (SPPaintServer const *ps) { auto pat = cast(ps); @@ -51,14 +58,14 @@ bool has_colors_pattern(SPItem const *item) if (auto group = cast(&child)) { for (auto const &child : group->children) { if (auto c = cast(&child)) { - if (check_color(c->style->fill) || check_color(c->style->stroke)) { + if (check(c->style->fill) || check(c->style->stroke)) { return true; } } } } - if (check_color(child.style->fill) || check_color(child.style->stroke)) { + if (check(child.style->fill) || check(child.style->stroke)) { return true; } } @@ -117,6 +124,40 @@ bool RecolorArtManager::checkSelection(Inkscape::Selection *selection) has_colors_pattern(item); } +bool RecolorArtManager::checkMarkerObject(SPMarker *marker) +{ + if (!marker) { + return false; + } + + if (marker->getMaskObject()) { + return true; + } + + MoreThan1ColorChecker check; + for (auto const &child : marker->children) { + + if (auto item = cast(&child)) { + if (item->style) { + if (check(item->style->fill) || check(item->style->stroke)) { + return true; + } + } + } + if (auto group = cast(&child)) { + for (auto const &child : group->children) { + if (auto c = cast(&child)) { + if (check(c->style->fill) || check(c->style->stroke)) { + return true; + } + } + } + } + } + + return false; +} + bool RecolorArtManager::checkMeshObject(Inkscape::Selection *selection) { if (selection->size() > 1) { diff --git a/src/ui/widget/recolor-art-manager.h b/src/ui/widget/recolor-art-manager.h index 0726aecf75..79a0f06f04 100644 --- a/src/ui/widget/recolor-art-manager.h +++ b/src/ui/widget/recolor-art-manager.h @@ -30,6 +30,7 @@ public: static bool checkSelection(Inkscape::Selection *selection); static bool checkMeshObject(Inkscape::Selection *selection); + static bool checkMarkerObject(SPMarker *marker); private: RecolorArtManager(); diff --git a/src/ui/widget/recolor-art.cpp b/src/ui/widget/recolor-art.cpp index d549a48552..2b324e9364 100644 --- a/src/ui/widget/recolor-art.cpp +++ b/src/ui/widget/recolor-art.cpp @@ -604,8 +604,6 @@ void RecolorArt::updateFromSelection() generateVisualList(); auto first_button_id = _manager.getFirstKey(); onOriginalColorClicked(first_button_id); - } - if (!_manager.isColorsEmpty()) { _color_wheel->setColors(_manager.getColors()); } } @@ -628,8 +626,6 @@ void RecolorArt::showForObject(SPDesktop *desktop, SPObject *object) generateVisualList(); auto first_button_id = _manager.getFirstKey(); onOriginalColorClicked(first_button_id); - } - if (!_manager.isColorsEmpty()) { _color_wheel->setColors(_manager.getColors()); } } diff --git a/src/ui/widget/style/marker-combo-box.cpp b/src/ui/widget/style/marker-combo-box.cpp index c1f131beff..0d24aa430c 100644 --- a/src/ui/widget/style/marker-combo-box.cpp +++ b/src/ui/widget/style/marker-combo-box.cpp @@ -396,9 +396,10 @@ void MarkerComboBox::update_widgets_from_marker(SPMarker* marker) { _orient_angle.set_active(); _angle_btn.set_sensitive(true); } - } - _recolorButtonTrigger->set_visible(marker); + bool should_show = RecolorArtManager::checkMarkerObject(marker); + _recolorButtonTrigger->set_visible(should_show); + } } void MarkerComboBox::update_scale_link() { @@ -632,6 +633,11 @@ void MarkerComboBox::set_current(SPObject *marker) // update menu button only update_menu_btn(); } + + auto& mgr = RecolorArtManager::get(); + if (mgr.popover.is_visible() && RecolorArtManager::checkMarkerObject(get_current())) { + mgr.widget.showForObject(_desktop, get_current()); + } } void MarkerComboBox::update_ui(SPMarker* marker, bool select) { -- GitLab