From ceadb0d8334ce84b3f225f829342e668222e83c0 Mon Sep 17 00:00:00 2001 From: Yuriy Puchkov Date: Thu, 2 Jul 2020 21:21:32 +0300 Subject: [PATCH] Upload screenshot to S3 on Enter after capture --- src/tools/capturetool.h | 2 ++ src/tools/imgs3/imgs3uploadertool.cpp | 4 ++++ src/tools/imgs3/imgs3uploadertool.h | 1 + src/widgets/capture/capturewidget.cpp | 16 ++++++++++++++-- src/widgets/capture/capturewidget.h | 1 + 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/tools/capturetool.h b/src/tools/capturetool.h index ae1a70c0..d7aab848 100644 --- a/src/tools/capturetool.h +++ b/src/tools/capturetool.h @@ -66,6 +66,8 @@ public: explicit CaptureTool(QObject *parent = nullptr) : QObject(parent){} + virtual void setCapture(const QPixmap &pixmap) {}; + // Returns false when the tool is in an inconsistent state and shouldn't // be included in the tool undo/redo stack. virtual bool isValid() const = 0; diff --git a/src/tools/imgs3/imgs3uploadertool.cpp b/src/tools/imgs3/imgs3uploadertool.cpp index abb33ec9..68aec9ba 100644 --- a/src/tools/imgs3/imgs3uploadertool.cpp +++ b/src/tools/imgs3/imgs3uploadertool.cpp @@ -54,6 +54,10 @@ QWidget* ImgS3UploaderTool::widget() { return new ImgS3Uploader(capture, m_s3CredsUrl, m_s3XApiKey); } +void ImgS3UploaderTool::setCapture(const QPixmap &pixmap) { + capture = pixmap; +} + CaptureTool* ImgS3UploaderTool::copy(QObject *parent) { return new ImgS3UploaderTool(parent); } diff --git a/src/tools/imgs3/imgs3uploadertool.h b/src/tools/imgs3/imgs3uploadertool.h index f3f7d05f..42377526 100644 --- a/src/tools/imgs3/imgs3uploadertool.h +++ b/src/tools/imgs3/imgs3uploadertool.h @@ -34,6 +34,7 @@ public: QWidget* widget() override; CaptureTool* copy(QObject *parent = nullptr) override; + void setCapture(const QPixmap &pixmap); public slots: void pressed(const CaptureContext &context) override; diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index 1db615bb..832383ef 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -33,6 +33,8 @@ #include "src/utils/screenshotsaver.h" #include "src/core/controller.h" #include "src/widgets/capture/modificationcommand.h" +#include "src/tools/imgs3/imgs3uploadertool.h" +#include "src/tools/toolfactory.h" #include #include #include @@ -778,8 +780,11 @@ void CaptureWidget::initShortcuts() { new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Down), this, SLOT(downResize())); new QShortcut(Qt::Key_Space, this, SLOT(togglePanel())); new QShortcut(Qt::Key_Escape, this, SLOT(deleteToolwidgetOrClose())); - new QShortcut(Qt::Key_Return, this, SLOT(copyScreenshot())); - new QShortcut(Qt::Key_Enter, this, SLOT(copyScreenshot())); + +// new QShortcut(Qt::Key_Return, this, SLOT(copyScreenshot())); +// new QShortcut(Qt::Key_Enter, this, SLOT(copyScreenshot())); + new QShortcut(Qt::Key_Return, this, SLOT(uploadScreenshot())); + new QShortcut(Qt::Key_Enter, this, SLOT(uploadScreenshot())); } void CaptureWidget::updateSizeIndicator() { @@ -861,6 +866,13 @@ void CaptureWidget::childLeave() { update(); } +void CaptureWidget::uploadScreenshot() { + m_activeTool = new ImgS3UploaderTool(); + m_activeTool->setCapture(pixmap()); + handleButtonSignal(CaptureTool::REQ_ADD_EXTERNAL_WIDGETS); + close(); +} + void CaptureWidget::copyScreenshot() { m_captureDone = true; ScreenshotSaver().saveToClipboard(pixmap()); diff --git a/src/widgets/capture/capturewidget.h b/src/widgets/capture/capturewidget.h index 171ab33c..eb696dde 100644 --- a/src/widgets/capture/capturewidget.h +++ b/src/widgets/capture/capturewidget.h @@ -74,6 +74,7 @@ private slots: // TODO replace with tools void copyScreenshot(); void saveScreenshot(); + void uploadScreenshot(); void undo(); void redo(); void togglePanel();