forked from qt-creator/qt-creator
ScreenRecorder: Offer saving of the current cropped frame
The "crop and trim" dialog gets two new buttons. The first offers to save the current, cropped frame as png image. The second one copies the image into the clipboard. Copyuing into clipboard is also triggered by the QKeySequence::Copy shortcut. The location where the last image was saved gets remembered in the settings. Change-Id: Id4ac93838d59f6a6fa801456fe8d9c17d1e74154 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
#include "screenrecordersettings.h"
|
#include "screenrecordersettings.h"
|
||||||
#include "screenrecordertr.h"
|
#include "screenrecordertr.h"
|
||||||
|
|
||||||
|
#include <utils/fileutils.h>
|
||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
#include <utils/process.h>
|
#include <utils/process.h>
|
||||||
#include <utils/qtcsettings.h>
|
#include <utils/qtcsettings.h>
|
||||||
@@ -16,8 +17,10 @@
|
|||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
|
||||||
|
#include <QClipboard>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
|
#include <QGuiApplication>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
@@ -164,6 +167,14 @@ void CropScene::setImage(const QImage &image)
|
|||||||
resize(sceneSize);
|
resize(sceneSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QImage CropScene::croppedImage() const
|
||||||
|
{
|
||||||
|
if (!m_image)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
return m_image->copy(m_cropRect);
|
||||||
|
}
|
||||||
|
|
||||||
void CropScene::mouseMoveEvent(QMouseEvent *event)
|
void CropScene::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
const QPoint imagePos = toImagePos(event->pos());
|
const QPoint imagePos = toImagePos(event->pos());
|
||||||
@@ -267,6 +278,18 @@ CropWidget::CropWidget(QWidget *parent)
|
|||||||
|
|
||||||
m_warningIcon = new CropSizeWarningIcon(CropSizeWarningIcon::StandardVariant);
|
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;
|
using namespace Layouting;
|
||||||
Column {
|
Column {
|
||||||
scrollArea,
|
scrollArea,
|
||||||
@@ -278,6 +301,8 @@ CropWidget::CropWidget(QWidget *parent)
|
|||||||
m_resetButton,
|
m_resetButton,
|
||||||
m_warningIcon,
|
m_warningIcon,
|
||||||
st,
|
st,
|
||||||
|
saveImageButton,
|
||||||
|
copyImageToClipboardButton,
|
||||||
},
|
},
|
||||||
noMargin(),
|
noMargin(),
|
||||||
}.attachTo(this);
|
}.attachTo(this);
|
||||||
@@ -290,6 +315,25 @@ CropWidget::CropWidget(QWidget *parent)
|
|||||||
connect(m_resetButton, &QToolButton::pressed, this, [this] {
|
connect(m_resetButton, &QToolButton::pressed, this, [this] {
|
||||||
m_cropScene->setFullySelected();
|
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();
|
updateWidgets();
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@ public:
|
|||||||
void setFullySelected();
|
void setFullySelected();
|
||||||
QRect fullRect() const;
|
QRect fullRect() const;
|
||||||
void setImage(const QImage &image);
|
void setImage(const QImage &image);
|
||||||
|
QImage croppedImage() const;
|
||||||
|
|
||||||
const static int lineWidth = 1;
|
const static int lineWidth = 1;
|
||||||
|
|
||||||
|
@@ -107,6 +107,10 @@ ScreenRecorderSettings::ScreenRecorderSettings()
|
|||||||
exportLastDirectory.setExpectedKind(PathChooser::ExistingDirectory);
|
exportLastDirectory.setExpectedKind(PathChooser::ExistingDirectory);
|
||||||
exportLastDirectory.setDefaultValue(FileUtils::homePath().toString());
|
exportLastDirectory.setDefaultValue(FileUtils::homePath().toString());
|
||||||
|
|
||||||
|
lastSaveImageDirectory.setSettingsKey("LastSaveImageDir");
|
||||||
|
lastSaveImageDirectory.setExpectedKind(PathChooser::ExistingDirectory);
|
||||||
|
lastSaveImageDirectory.setDefaultValue(FileUtils::homePath().toString());
|
||||||
|
|
||||||
recordFrameRate.setSettingsKey("RecordFrameRate");
|
recordFrameRate.setSettingsKey("RecordFrameRate");
|
||||||
recordFrameRate.setDefaultValue(24);
|
recordFrameRate.setDefaultValue(24);
|
||||||
recordFrameRate.setLabelText(Tr::tr("Recording frame rate:"));
|
recordFrameRate.setLabelText(Tr::tr("Recording frame rate:"));
|
||||||
|
@@ -40,6 +40,7 @@ public:
|
|||||||
// Used in other places
|
// Used in other places
|
||||||
Utils::FilePathAspect lastOpenDirectory{this};
|
Utils::FilePathAspect lastOpenDirectory{this};
|
||||||
Utils::FilePathAspect exportLastDirectory{this};
|
Utils::FilePathAspect exportLastDirectory{this};
|
||||||
|
Utils::FilePathAspect lastSaveImageDirectory{this};
|
||||||
Utils::IntegerAspect recordFrameRate{this};
|
Utils::IntegerAspect recordFrameRate{this};
|
||||||
Utils::IntegerAspect recordScreenId{this};
|
Utils::IntegerAspect recordScreenId{this};
|
||||||
Utils::StringListAspect recordScreenCropRect{this};
|
Utils::StringListAspect recordScreenCropRect{this};
|
||||||
|
Reference in New Issue
Block a user