From b3b26721eba7cfb9de0c3ff6466ab76e768f4524 Mon Sep 17 00:00:00 2001 From: Hugo Therrien Date: Sun, 15 Jan 2023 11:52:58 -0500 Subject: [PATCH] New action: screenshot to clipboard --- src/lay/lay/gsiDeclLayMainWindow.cc | 1 + src/lay/lay/layMainWindow.cc | 16 ++++++++++++++++ src/lay/lay/layMainWindow.h | 1 + 3 files changed, 18 insertions(+) diff --git a/src/lay/lay/gsiDeclLayMainWindow.cc b/src/lay/lay/gsiDeclLayMainWindow.cc index e2e23fc38..e449f08b6 100644 --- a/src/lay/lay/gsiDeclLayMainWindow.cc +++ b/src/lay/lay/gsiDeclLayMainWindow.cc @@ -85,6 +85,7 @@ static const char *cm_symbols[] = { "cm_cancel", "cm_redraw", "cm_screenshot", + "cm_screenshot_to_clipboard", "cm_save_layer_props", "cm_load_layer_props", "cm_save_bookmarks", diff --git a/src/lay/lay/layMainWindow.cc b/src/lay/lay/layMainWindow.cc index 931c0ef05..de3aa47a8 100644 --- a/src/lay/lay/layMainWindow.cc +++ b/src/lay/lay/layMainWindow.cc @@ -36,6 +36,7 @@ #include #include #include +#include #if defined(__APPLE__) && (QT_VERSION < 0x050401) // A workaround for the issue of Qt 4.8.x when handling "File Reference URL" in OSX @@ -2162,6 +2163,18 @@ MainWindow::cm_screenshot () } } +void +MainWindow::cm_screenshot_to_clipboard () +{ + if (current_view ()) { + QImage screenshot = current_view ()->get_screenshot (); + QClipboard *clipboard = QGuiApplication::clipboard(); + clipboard->setImage(screenshot); + } else { + throw tl::Exception (tl::to_string (QObject::tr ("No view open to create a screenshot from"))); + } +} + void MainWindow::cm_save_current_cell_as () { @@ -3939,6 +3952,8 @@ MainWindow::menu_activated (const std::string &symbol) cm_load_bookmarks (); } else if (symbol == "cm_screenshot") { cm_screenshot (); + } else if (symbol == "cm_screenshot_to_clipboard") { + cm_screenshot_to_clipboard (); } else if (symbol == "cm_save_current_cell_as") { cm_save_current_cell_as (); } else if (symbol == "cm_save") { @@ -4297,6 +4312,7 @@ public: menu_entries.push_back (lay::menu_item ("cm_setup", "setup:edit", at, tl::to_string (QObject::tr ("Setup")))); menu_entries.push_back (lay::separator ("misc_group", at)); menu_entries.push_back (lay::menu_item ("cm_screenshot", "screenshot:edit", at, tl::to_string (QObject::tr ("Screenshot(Print)")))); + menu_entries.push_back (lay::menu_item ("cm_screenshot_to_clipboard", "screenshot_to_clipboard:edit", at, tl::to_string (QObject::tr ("Screenshot to clipboard")))); menu_entries.push_back (lay::menu_item ("cm_layout_props", "layout_props:edit", at, tl::to_string (QObject::tr ("Layout Properties")))); menu_entries.push_back (lay::menu_item ("cm_layout_stats", "layout_stats:edit", at, tl::to_string (QObject::tr ("Layout Statistics")))); menu_entries.push_back (lay::separator ("layer_group", at)); diff --git a/src/lay/lay/layMainWindow.h b/src/lay/lay/layMainWindow.h index 1600622fd..e6b4d76aa 100644 --- a/src/lay/lay/layMainWindow.h +++ b/src/lay/lay/layMainWindow.h @@ -780,6 +780,7 @@ private: void cm_save_bookmarks (); void cm_load_bookmarks (); void cm_screenshot (); + void cm_screenshot_to_clipboard (); void cm_save_current_cell_as (); void cm_save (); void cm_save_as ();