diff --git a/src/core/flameshotdaemon.cpp b/src/core/flameshotdaemon.cpp index b8fdf3cdd3..8a9d2fba7d 100644 --- a/src/core/flameshotdaemon.cpp +++ b/src/core/flameshotdaemon.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -269,6 +270,45 @@ void FlameshotDaemon::attachPin(const QPixmap& pixmap, QRect geometry) pinWidget->activateWindow(); } +/** + * @brief Initiate a new pin capture to replace `existing`. + * + * Starts a new screenshot capture with the selection region initialized to be + * the same as `existing`. When it is completed the selection will be pinned and + * the previous pin (the `existing` argument) will be closed. + */ +void FlameshotDaemon::editPin(PinWidget& existing) +{ + CaptureRequest req(CaptureRequest::GRAPHICAL_MODE); + req.addTask(CaptureRequest::PIN); + QRect contentsRect = + existing.geometry() - existing.layout()->contentsMargins(); + req.setInitialSelection(contentsRect); + + Flameshot* flameshot = Flameshot::instance(); + flameshot->gui(req); + + // Connect to signals emitted when a capture (hopefully the one we just + // initiated!) is finished, both when it succeeds and when it is aborted. + auto successConn = std::make_shared(); + auto failureConn = std::make_shared(); + *successConn = QObject::connect(flameshot, + &Flameshot::captureTaken, + [&existing, successConn, failureConn]() { + // Only close the old pin on success. + existing.close(); + + QObject::disconnect(*successConn); + QObject::disconnect(*failureConn); + }); + *failureConn = QObject::connect(flameshot, + &Flameshot::captureTaken, + [&existing, successConn, failureConn]() { + QObject::disconnect(*successConn); + QObject::disconnect(*failureConn); + }); +} + void FlameshotDaemon::attachScreenshotToClipboard(const QPixmap& pixmap) { m_hostingClipboard = true; diff --git a/src/core/flameshotdaemon.h b/src/core/flameshotdaemon.h index e49c815e3c..f4f203b1ad 100644 --- a/src/core/flameshotdaemon.h +++ b/src/core/flameshotdaemon.h @@ -1,5 +1,6 @@ #pragma once +#include "pinwidget.h" #include #include #include @@ -27,6 +28,7 @@ class FlameshotDaemon : public QObject static void copyToClipboard(const QPixmap& capture); static void copyToClipboard(const QString& text, const QString& notification = ""); + static void editPin(PinWidget& pinned); static bool isThisInstanceHostingWidgets(); void sendTrayNotification( diff --git a/src/tools/pin/pinwidget.cpp b/src/tools/pin/pinwidget.cpp index 8baa19e783..f642d0cc31 100644 --- a/src/tools/pin/pinwidget.cpp +++ b/src/tools/pin/pinwidget.cpp @@ -7,6 +7,7 @@ #include "pinwidget.h" #include "qguiappcurrentscreen.h" #include "screenshotsaver.h" +#include "src/core/flameshotdaemon.h" #include "src/utils/confighandler.h" #include "src/utils/globalvalues.h" @@ -328,6 +329,10 @@ void PinWidget::showContextMenu(const QPoint& pos) &PinWidget::decreaseOpacity); contextMenu.addAction(&decreaseOpacityAction); + QAction editAction(tr("Edit Pin"), this); + connect(&editAction, &QAction::triggered, this, &PinWidget::edit); + contextMenu.addAction(&editAction); + QAction closePinAction(tr("Close"), this); connect(&closePinAction, &QAction::triggered, this, &PinWidget::closePin); contextMenu.addSeparator(); @@ -340,9 +345,15 @@ void PinWidget::copyToClipboard() { saveToClipboard(m_pixmap); } + void PinWidget::saveToFile() { hide(); saveToFilesystemGUI(m_pixmap); show(); } + +void PinWidget::edit() +{ + FlameshotDaemon::editPin(*this); +} diff --git a/src/tools/pin/pinwidget.h b/src/tools/pin/pinwidget.h index 1e26baff75..deb5f4dc67 100644 --- a/src/tools/pin/pinwidget.h +++ b/src/tools/pin/pinwidget.h @@ -61,4 +61,5 @@ private slots: void showContextMenu(const QPoint& pos); void copyToClipboard(); void saveToFile(); + void edit(); };