diff options
author | Pierre <pierre.git@posteo.de> | 2020-05-14 14:22:30 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-14 14:44:27 +0200 |
commit | 49727ffee424d8c0038ce18b91b0bf0ff33b1a4d (patch) | |
tree | 5ebc0d4fa0ec4e4bb3a77ad52a71ee6482a055e6 /Applications | |
parent | 80a360683f5625cb0e8e2b802d19565da9754905 (diff) | |
download | serenity-49727ffee424d8c0038ce18b91b0bf0ff33b1a4d.zip |
PaintBrush: Added 'Move active layer up/down' to the Menu
This allowes the active layer to be moved up or down.
Diffstat (limited to 'Applications')
-rw-r--r-- | Applications/PaintBrush/Image.cpp | 20 | ||||
-rw-r--r-- | Applications/PaintBrush/Image.h | 2 | ||||
-rw-r--r-- | Applications/PaintBrush/main.cpp | 17 |
3 files changed, 39 insertions, 0 deletions
diff --git a/Applications/PaintBrush/Image.cpp b/Applications/PaintBrush/Image.cpp index 6cb92d039e..2236b38358 100644 --- a/Applications/PaintBrush/Image.cpp +++ b/Applications/PaintBrush/Image.cpp @@ -104,6 +104,26 @@ void Image::move_layer_to_front(Layer& layer) m_layers.append(layer); } +void Image::move_layer_down(Layer& layer) +{ + NonnullRefPtr<Layer> protector(layer); + auto index = index_of(layer); + if (!index) + return; + m_layers.remove(index); + m_layers.insert(index - 1, layer); +} + +void Image::move_layer_up(Layer& layer) +{ + NonnullRefPtr<Layer> protector(layer); + auto index = index_of(layer); + if (index == m_layers.size() - 1) + return; + m_layers.remove(index); + m_layers.insert(index + 1, layer); +} + void Image::remove_layer(Layer& layer) { NonnullRefPtr<Layer> protector(layer); diff --git a/Applications/PaintBrush/Image.h b/Applications/PaintBrush/Image.h index 9526f0efe4..96e87e73ff 100644 --- a/Applications/PaintBrush/Image.h +++ b/Applications/PaintBrush/Image.h @@ -57,6 +57,8 @@ public: void move_layer_to_front(Layer&); void move_layer_to_back(Layer&); + void move_layer_up(Layer&); + void move_layer_down(Layer&); void remove_layer(Layer&); private: diff --git a/Applications/PaintBrush/main.cpp b/Applications/PaintBrush/main.cpp index 3c57fbbf8b..749a3cdcf2 100644 --- a/Applications/PaintBrush/main.cpp +++ b/Applications/PaintBrush/main.cpp @@ -151,6 +151,23 @@ int main(int argc, char** argv) layer_table_view.selection().set(layer_table_view.model()->index(0)); }, window)); layer_menu.add_separator(); + layer_menu.add_action(GUI::Action::create("Move active layer up", { Mod_Ctrl, Key_PageUp }, [&](auto&) { + auto active_layer = image_editor.active_layer(); + if(!active_layer) + return; + image_editor.image()->move_layer_up(*active_layer); + layer_table_view.move_selection(1); + image_editor.layers_did_change(); + }, window)); + layer_menu.add_action(GUI::Action::create("Move active layer down", { Mod_Ctrl, Key_PageDown }, [&](auto&) { + auto active_layer = image_editor.active_layer(); + if(!active_layer) + return; + image_editor.image()->move_layer_down(*active_layer); + layer_table_view.move_selection(-1); + image_editor.layers_did_change(); + }, window)); + layer_menu.add_separator(); layer_menu.add_action(GUI::Action::create("Remove active layer", { Mod_Ctrl , Key_D }, [&](auto&) { auto active_layer = image_editor.active_layer(); if(!active_layer) |