diff --git a/src/ui/widget/recolor-art-manager.cpp b/src/ui/widget/recolor-art-manager.cpp index 8780d3a25c25a43543cee7dca0ee7843a637b8ee..1622bd02b83cf18689f3441ef5638bca8cd2a0b8 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 0726aecf75fdf5d3b45b3e8251e89a5cddb4794d..79a0f06f047f91fe2057dc74c442a06099afc6c2 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 d549a48552a1e8cfc0f155e22024eafe71b78d96..2b324e9364865ec822c6f72869bdc2cf8cb78ee7 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 c1f131beff7e2a93b2cd5eea9a68fd1e57a7c215..0d24aa430ccc342da98263445e598dece6c52916 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) {