diff options
author | Marcus Nilsson <brainbomb@gmail.com> | 2021-07-01 15:04:04 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-05 20:39:30 +0200 |
commit | 8d205ae62ee1637168efa19b1166e92071c9ac89 (patch) | |
tree | 6d734cafc35f5b6499372f98f5cc1ed922fe7c24 /Userland/Applications | |
parent | 9df3550e5818e0426ff5391437b14fc6da131c9e (diff) | |
download | serenity-8d205ae62ee1637168efa19b1166e92071c9ac89.zip |
PixelPaint: Use layer menu as context menu in LayerListWidget
This enables the layer menu as a context menu in LayerListWidget,
setting the clicked layer as active for now, but in the future it
would be nice to have custom menu applying to the clicked layer instead
of the active layer.
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/PixelPaint/LayerListWidget.cpp | 14 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/LayerListWidget.h | 2 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/main.cpp | 4 |
3 files changed, 20 insertions, 0 deletions
diff --git a/Userland/Applications/PixelPaint/LayerListWidget.cpp b/Userland/Applications/PixelPaint/LayerListWidget.cpp index 6bf6c00d27..5b31ab2cc4 100644 --- a/Userland/Applications/PixelPaint/LayerListWidget.cpp +++ b/Userland/Applications/PixelPaint/LayerListWidget.cpp @@ -183,6 +183,20 @@ void LayerListWidget::mouseup_event(GUI::MouseEvent& event) m_image->change_layer_index(old_index, new_index); } +void LayerListWidget::context_menu_event(GUI::ContextMenuEvent& event) +{ + Gfx::IntPoint translated_event_point = { 0, vertical_scrollbar().value() + event.position().y() }; + + auto gadget_index = gadget_at(translated_event_point); + if (gadget_index.has_value()) { + auto& layer = m_image->layer(gadget_index.value()); + set_selected_layer(&layer); + } + + if (on_context_menu_request) + on_context_menu_request(event); +} + void LayerListWidget::image_did_add_layer(size_t layer_index) { if (m_moving_gadget_index.has_value()) { diff --git a/Userland/Applications/PixelPaint/LayerListWidget.h b/Userland/Applications/PixelPaint/LayerListWidget.h index 5a904d9c0a..e1d2008c95 100644 --- a/Userland/Applications/PixelPaint/LayerListWidget.h +++ b/Userland/Applications/PixelPaint/LayerListWidget.h @@ -23,6 +23,7 @@ public: void set_selected_layer(Layer*); Function<void(Layer*)> on_layer_select; + Function<void(GUI::ContextMenuEvent&)> on_context_menu_request; void select_bottom_layer(); void select_top_layer(); @@ -35,6 +36,7 @@ private: virtual void mousedown_event(GUI::MouseEvent&) override; virtual void mousemove_event(GUI::MouseEvent&) override; virtual void mouseup_event(GUI::MouseEvent&) override; + virtual void context_menu_event(GUI::ContextMenuEvent&) override; virtual void resize_event(GUI::ResizeEvent&) override; virtual void image_did_add_layer(size_t) override; diff --git a/Userland/Applications/PixelPaint/main.cpp b/Userland/Applications/PixelPaint/main.cpp index 27167d347c..78e6a910d3 100644 --- a/Userland/Applications/PixelPaint/main.cpp +++ b/Userland/Applications/PixelPaint/main.cpp @@ -405,6 +405,10 @@ int main(int argc, char** argv) }, window)); + layer_list_widget.on_context_menu_request = [&](auto& event) { + layer_menu.popup(event.screen_position()); + }; + auto& filter_menu = menubar->add_menu("&Filter"); auto& spatial_filters_menu = filter_menu.add_submenu("&Spatial"); |