浏览代码

PixelPaint: Add a way to quickly create an image from clipboard

Ctrl+Shift+V, like in GIMP.
Maciej 3 年之前
父节点
当前提交
41d02bd5e6
共有 2 个文件被更改,包括 20 次插入0 次删除
  1. 19 0
      Userland/Applications/PixelPaint/MainWidget.cpp
  2. 1 0
      Userland/Applications/PixelPaint/MainWidget.h

+ 19 - 0
Userland/Applications/PixelPaint/MainWidget.cpp

@@ -117,6 +117,24 @@ void MainWidget::initialize_menubar(GUI::Window& window)
             }
         });
 
+    m_new_image_from_clipboard_action = GUI::Action::create(
+        "&New Image from Clipboard", { Mod_Ctrl | Mod_Shift, Key_V }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/new.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
+            auto bitmap = GUI::Clipboard::the().fetch_data_and_type().as_bitmap();
+            if (!bitmap) {
+                GUI::MessageBox::show(&window, "There is no image in a clipboard to paste.", "PixelPaint", GUI::MessageBox::Type::Warning);
+                return;
+            }
+
+            auto image = PixelPaint::Image::try_create_with_size(bitmap->size()).release_value_but_fixme_should_propagate_errors();
+            auto layer = PixelPaint::Layer::try_create_with_bitmap(image, *bitmap, "Pasted layer").release_value_but_fixme_should_propagate_errors();
+            image->add_layer(*layer);
+            image->set_title("Untitled");
+
+            create_new_editor(*image);
+            m_layer_list_widget->set_image(image);
+            m_layer_list_widget->set_selected_layer(layer);
+        });
+
     m_open_image_action = GUI::CommonActions::make_open_action([&](auto&) {
         auto result = FileSystemAccessClient::Client::the().open_file(window.window_id());
         if (result.error != 0)
@@ -141,6 +159,7 @@ void MainWidget::initialize_menubar(GUI::Window& window)
     });
 
     file_menu.add_action(*m_new_image_action);
+    file_menu.add_action(*m_new_image_from_clipboard_action);
     file_menu.add_action(*m_open_image_action);
     file_menu.add_action(*m_save_image_as_action);
 

+ 1 - 0
Userland/Applications/PixelPaint/MainWidget.h

@@ -58,6 +58,7 @@ private:
     RefPtr<GUI::ComboBox> m_zoom_combobox;
 
     RefPtr<GUI::Action> m_new_image_action;
+    RefPtr<GUI::Action> m_new_image_from_clipboard_action;
     RefPtr<GUI::Action> m_open_image_action;
     RefPtr<GUI::Action> m_save_image_as_action;