diff --git a/src/plugins/screenrecorder/cropandtrim.cpp b/src/plugins/screenrecorder/cropandtrim.cpp index 16cdb3ec3c3..c6c35560ea1 100644 --- a/src/plugins/screenrecorder/cropandtrim.cpp +++ b/src/plugins/screenrecorder/cropandtrim.cpp @@ -7,6 +7,7 @@ #include "screenrecordersettings.h" #include "screenrecordertr.h" +#include #include #include #include @@ -16,8 +17,10 @@ #include +#include #include #include +#include #include #include #include @@ -164,6 +167,14 @@ void CropScene::setImage(const QImage &image) resize(sceneSize); } +QImage CropScene::croppedImage() const +{ + if (!m_image) + return {}; + + return m_image->copy(m_cropRect); +} + void CropScene::mouseMoveEvent(QMouseEvent *event) { const QPoint imagePos = toImagePos(event->pos()); @@ -267,6 +278,18 @@ CropWidget::CropWidget(QWidget *parent) m_warningIcon = new CropSizeWarningIcon(CropSizeWarningIcon::StandardVariant); + auto saveImageButton = new QToolButton; + saveImageButton->setToolTip(Tr::tr("Save current, cropped frame as image file...")); + saveImageButton->setIcon(Icons::SAVEFILE.icon()); + + auto copyImageToClipboardAction = new QAction(Tr::tr("Copy current, cropped frame as image " + "into the Clipboard"), this); + copyImageToClipboardAction->setIcon(Icons::COPY.icon()); + copyImageToClipboardAction->setShortcut(QKeySequence::Copy); + + auto copyImageToClipboardButton = new QToolButton; + copyImageToClipboardButton->setDefaultAction(copyImageToClipboardAction); + using namespace Layouting; Column { scrollArea, @@ -278,6 +301,8 @@ CropWidget::CropWidget(QWidget *parent) m_resetButton, m_warningIcon, st, + saveImageButton, + copyImageToClipboardButton, }, noMargin(), }.attachTo(this); @@ -290,6 +315,25 @@ CropWidget::CropWidget(QWidget *parent) connect(m_resetButton, &QToolButton::pressed, this, [this] { m_cropScene->setFullySelected(); }); + connect(saveImageButton, &QToolButton::clicked, this, [this] { + FilePathAspect &lastDir = Internal::settings().lastSaveImageDirectory; + const QString ext(".png"); + FilePath file = FileUtils::getSaveFilePath(nullptr, Tr::tr("Save Current Frame As"), + lastDir(), "*" + ext); + if (!file.isEmpty()) { + if (!file.endsWith(ext)) + file = file.stringAppended(ext); + lastDir.setValue(file.parentDir()); + lastDir.writeToSettingsImmediatly(); + const QImage image = m_cropScene->croppedImage(); + image.save(file.toString()); + } + }); + connect(copyImageToClipboardAction, &QAction::triggered, this, [this] { + const QImage image = m_cropScene->croppedImage(); + QClipboard *clipboard = QGuiApplication::clipboard(); + clipboard->setImage(image); + }); updateWidgets(); } diff --git a/src/plugins/screenrecorder/cropandtrim.h b/src/plugins/screenrecorder/cropandtrim.h index 164f0dbbd20..1ac2cbae453 100644 --- a/src/plugins/screenrecorder/cropandtrim.h +++ b/src/plugins/screenrecorder/cropandtrim.h @@ -26,6 +26,7 @@ public: void setFullySelected(); QRect fullRect() const; void setImage(const QImage &image); + QImage croppedImage() const; const static int lineWidth = 1; diff --git a/src/plugins/screenrecorder/screenrecordersettings.cpp b/src/plugins/screenrecorder/screenrecordersettings.cpp index 98dfefdcf63..ae01d321175 100644 --- a/src/plugins/screenrecorder/screenrecordersettings.cpp +++ b/src/plugins/screenrecorder/screenrecordersettings.cpp @@ -107,6 +107,10 @@ ScreenRecorderSettings::ScreenRecorderSettings() exportLastDirectory.setExpectedKind(PathChooser::ExistingDirectory); exportLastDirectory.setDefaultValue(FileUtils::homePath().toString()); + lastSaveImageDirectory.setSettingsKey("LastSaveImageDir"); + lastSaveImageDirectory.setExpectedKind(PathChooser::ExistingDirectory); + lastSaveImageDirectory.setDefaultValue(FileUtils::homePath().toString()); + recordFrameRate.setSettingsKey("RecordFrameRate"); recordFrameRate.setDefaultValue(24); recordFrameRate.setLabelText(Tr::tr("Recording frame rate:")); diff --git a/src/plugins/screenrecorder/screenrecordersettings.h b/src/plugins/screenrecorder/screenrecordersettings.h index ac05169bc40..75527da6538 100644 --- a/src/plugins/screenrecorder/screenrecordersettings.h +++ b/src/plugins/screenrecorder/screenrecordersettings.h @@ -40,6 +40,7 @@ public: // Used in other places Utils::FilePathAspect lastOpenDirectory{this}; Utils::FilePathAspect exportLastDirectory{this}; + Utils::FilePathAspect lastSaveImageDirectory{this}; Utils::IntegerAspect recordFrameRate{this}; Utils::IntegerAspect recordScreenId{this}; Utils::StringListAspect recordScreenCropRect{this};