From f2feebc6f605e458907f7c1438f311ed225b9169 Mon Sep 17 00:00:00 2001 From: Tobias Christiansen Date: Sat, 1 Jan 2022 00:45:43 +0100 Subject: [PATCH] PixelPaint: Expand Filter Gallery to know how to apply filters --- Userland/Applications/PixelPaint/FilterGallery.cpp | 11 +++++++++-- Userland/Applications/PixelPaint/FilterModel.h | 6 ++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Userland/Applications/PixelPaint/FilterGallery.cpp b/Userland/Applications/PixelPaint/FilterGallery.cpp index 6105ef02dc..cddf2e3ff6 100644 --- a/Userland/Applications/PixelPaint/FilterGallery.cpp +++ b/Userland/Applications/PixelPaint/FilterGallery.cpp @@ -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(selected_index.internal_data()); + if (selected_filter->type != FilterModel::FilterInfo::Type::Filter) + done(ExecResult::ExecAborted); + + selected_filter->apply_filter(); done(ExecResult::ExecOK); }; diff --git a/Userland/Applications/PixelPaint/FilterModel.h b/Userland/Applications/PixelPaint/FilterModel.h index 30dd477ee6..01a7c25d2d 100644 --- a/Userland/Applications/PixelPaint/FilterModel.h +++ b/Userland/Applications/PixelPaint/FilterModel.h @@ -24,14 +24,16 @@ public: String text; + Function apply_filter; + NonnullRefPtrVector children; FilterInfo* parent; - static NonnullRefPtr create_filter(String const& text, FilterInfo* parent = nullptr) + static NonnullRefPtr create_filter(String const& text, Function 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;