QmlDesigner: Add action for taking screenshots

Task-numner: QDS-9431
Change-Id: I091e8cef646d08ee67935e2b3cea903b68a37a0c
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Thomas Hartmann
2023-03-31 15:31:30 +02:00
parent 9c7dcea60b
commit 07adb77dd1
3 changed files with 33 additions and 11 deletions

View File

@@ -30,6 +30,7 @@ const char TOGGLE_RIGHT_SIDEBAR[] = "QmlDesigner.ToggleRightSideBar";
const char TOGGLE_STATES_EDITOR[] = "QmlDesigner.ToggleStatesEditor"; const char TOGGLE_STATES_EDITOR[] = "QmlDesigner.ToggleStatesEditor";
const char GO_INTO_COMPONENT[] = "QmlDesigner.GoIntoComponent"; const char GO_INTO_COMPONENT[] = "QmlDesigner.GoIntoComponent";
const char EXPORT_AS_IMAGE[] = "QmlDesigner.ExportAsImage"; const char EXPORT_AS_IMAGE[] = "QmlDesigner.ExportAsImage";
const char TAKE_SCREENSHOT[] = "QmlDesigner.TakeScreenshot";
const char FORMEDITOR_REFRESH[] = "QmlDesigner.FormEditor.Refresh"; const char FORMEDITOR_REFRESH[] = "QmlDesigner.FormEditor.Refresh";
const char FORMEDITOR_SNAPPING[] = "QmlDesigner.FormEditor.Snapping"; const char FORMEDITOR_SNAPPING[] = "QmlDesigner.FormEditor.Snapping";
const char FORMEDITOR_NO_SNAPPING[] = "QmlDesigner.FormEditor.NoSnapping"; const char FORMEDITOR_NO_SNAPPING[] = "QmlDesigner.FormEditor.NoSnapping";

View File

@@ -39,21 +39,24 @@
#include <QApplication> #include <QApplication>
#include <QClipboard> #include <QClipboard>
#include <QMainWindow>
#include <QStandardPaths>
namespace QmlDesigner { namespace QmlDesigner {
ShortCutManager::ShortCutManager() ShortCutManager::ShortCutManager()
: QObject(), : QObject()
m_exportAsImageAction(tr("Export as &Image...")), , m_exportAsImageAction(tr("Export as &Image..."))
m_undoAction(tr("&Undo")), , m_takeScreenshotAction(tr("Take Screenshot"))
m_redoAction(tr("&Redo")), , m_undoAction(tr("&Undo"))
m_deleteAction(tr("Delete")), , m_redoAction(tr("&Redo"))
m_cutAction(tr("Cu&t")), , m_deleteAction(tr("Delete"))
m_copyAction(tr("&Copy")), , m_cutAction(tr("Cu&t"))
m_pasteAction(tr("&Paste")), , m_copyAction(tr("&Copy"))
m_duplicateAction(tr("&Duplicate")), , m_pasteAction(tr("&Paste"))
m_selectAllAction(tr("Select &All")), , m_duplicateAction(tr("&Duplicate"))
m_escapeAction(this) , m_selectAllAction(tr("Select &All"))
, m_escapeAction(this)
{ {
} }
@@ -111,6 +114,23 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex
Core::ActionManager::actionContainer(Core::Constants::M_EDIT) Core::ActionManager::actionContainer(Core::Constants::M_EDIT)
->addAction(command, Core::Constants::G_EDIT_OTHER); ->addAction(command, Core::Constants::G_EDIT_OTHER);
command = Core::ActionManager::registerAction(&m_takeScreenshotAction,
QmlDesigner::Constants::TAKE_SCREENSHOT);
connect(&m_takeScreenshotAction, &QAction::triggered, [] {
const auto folder = Utils::FilePath::fromString(
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation))
.pathAppended("QtDesignStudio/screenshots/");
folder.createDir();
const auto file = folder.pathAppended(QDateTime::currentDateTime().toString("dddd-hh-mm-ss")
+ ".png");
QPixmap pixmap = Core::ICore::mainWindow()->grab();
const bool b = pixmap.save(file.toString(), "PNG");
qWarning() << "screenshot" << file << b << pixmap;
});
connect(action, &QAction::triggered, this, [] { ToolBarBackend::launchGlobalAnnotations(); }); connect(action, &QAction::triggered, this, [] { ToolBarBackend::launchGlobalAnnotations(); });
Core::ActionContainer *exportMenu = Core::ActionManager::actionContainer( Core::ActionContainer *exportMenu = Core::ActionManager::actionContainer(

View File

@@ -52,6 +52,7 @@ private:
QAction m_saveAction; QAction m_saveAction;
QAction m_saveAsAction; QAction m_saveAsAction;
QAction m_exportAsImageAction; QAction m_exportAsImageAction;
QAction m_takeScreenshotAction;
QAction m_closeCurrentEditorAction; QAction m_closeCurrentEditorAction;
QAction m_closeAllEditorsAction; QAction m_closeAllEditorsAction;
QAction m_closeOtherEditorsAction; QAction m_closeOtherEditorsAction;