فهرست منبع

PixelPaint: Expand Filter Gallery to know how to apply filters

Tobias Christiansen 3 سال پیش
والد
کامیت
f2feebc6f6
2فایلهای تغییر یافته به همراه13 افزوده شده و 4 حذف شده
  1. 9 2
      Userland/Applications/PixelPaint/FilterGallery.cpp
  2. 4 2
      Userland/Applications/PixelPaint/FilterModel.h

+ 9 - 2
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<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);
     };
 

+ 4 - 2
Userland/Applications/PixelPaint/FilterModel.h

@@ -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;