1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:47:35 +00:00

PixelPaint: Expand Filter Gallery to know how to apply filters

This commit is contained in:
Tobias Christiansen 2022-01-01 00:45:43 +01:00 committed by Andreas Kling
parent ddaf496aa0
commit f2feebc6f6
2 changed files with 13 additions and 4 deletions

View file

@ -37,9 +37,16 @@ FilterGallery::FilterGallery(GUI::Window* parent_window, ImageEditor* editor)
filter_tree->set_model(filter_model);
filter_tree->expand_tree();
apply_button->on_click = [this](auto) {
dbgln("Click!");
apply_button->on_click = [this, filter_tree](auto) {
auto selected_index = filter_tree->selection().first();
if (!selected_index.is_valid())
done(ExecResult::ExecAborted);
auto selected_filter = static_cast<const FilterModel::FilterInfo*>(selected_index.internal_data());
if (selected_filter->type != FilterModel::FilterInfo::Type::Filter)
done(ExecResult::ExecAborted);
selected_filter->apply_filter();
done(ExecResult::ExecOK);
};

View file

@ -24,14 +24,16 @@ public:
String text;
Function<void()> apply_filter;
NonnullRefPtrVector<FilterInfo> children;
FilterInfo* parent;
static NonnullRefPtr<FilterInfo> create_filter(String const& text, FilterInfo* parent = nullptr)
static NonnullRefPtr<FilterInfo> create_filter(String const& text, Function<void()> apply_filter, FilterInfo* parent = nullptr)
{
auto filter = adopt_ref(*new FilterInfo(Type::Filter, text, parent));
filter->ref();
filter->apply_filter = move(apply_filter);
if (parent)
parent->children.append(filter);
return filter;