forked from qt-creator/qt-creator
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:
@@ -30,6 +30,7 @@ const char TOGGLE_RIGHT_SIDEBAR[] = "QmlDesigner.ToggleRightSideBar";
|
||||
const char TOGGLE_STATES_EDITOR[] = "QmlDesigner.ToggleStatesEditor";
|
||||
const char GO_INTO_COMPONENT[] = "QmlDesigner.GoIntoComponent";
|
||||
const char EXPORT_AS_IMAGE[] = "QmlDesigner.ExportAsImage";
|
||||
const char TAKE_SCREENSHOT[] = "QmlDesigner.TakeScreenshot";
|
||||
const char FORMEDITOR_REFRESH[] = "QmlDesigner.FormEditor.Refresh";
|
||||
const char FORMEDITOR_SNAPPING[] = "QmlDesigner.FormEditor.Snapping";
|
||||
const char FORMEDITOR_NO_SNAPPING[] = "QmlDesigner.FormEditor.NoSnapping";
|
||||
|
||||
@@ -39,21 +39,24 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QMainWindow>
|
||||
#include <QStandardPaths>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
ShortCutManager::ShortCutManager()
|
||||
: QObject(),
|
||||
m_exportAsImageAction(tr("Export as &Image...")),
|
||||
m_undoAction(tr("&Undo")),
|
||||
m_redoAction(tr("&Redo")),
|
||||
m_deleteAction(tr("Delete")),
|
||||
m_cutAction(tr("Cu&t")),
|
||||
m_copyAction(tr("&Copy")),
|
||||
m_pasteAction(tr("&Paste")),
|
||||
m_duplicateAction(tr("&Duplicate")),
|
||||
m_selectAllAction(tr("Select &All")),
|
||||
m_escapeAction(this)
|
||||
: QObject()
|
||||
, m_exportAsImageAction(tr("Export as &Image..."))
|
||||
, m_takeScreenshotAction(tr("Take Screenshot"))
|
||||
, m_undoAction(tr("&Undo"))
|
||||
, m_redoAction(tr("&Redo"))
|
||||
, m_deleteAction(tr("Delete"))
|
||||
, m_cutAction(tr("Cu&t"))
|
||||
, m_copyAction(tr("&Copy"))
|
||||
, m_pasteAction(tr("&Paste"))
|
||||
, m_duplicateAction(tr("&Duplicate"))
|
||||
, 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)
|
||||
->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(); });
|
||||
|
||||
Core::ActionContainer *exportMenu = Core::ActionManager::actionContainer(
|
||||
|
||||
@@ -52,6 +52,7 @@ private:
|
||||
QAction m_saveAction;
|
||||
QAction m_saveAsAction;
|
||||
QAction m_exportAsImageAction;
|
||||
QAction m_takeScreenshotAction;
|
||||
QAction m_closeCurrentEditorAction;
|
||||
QAction m_closeAllEditorsAction;
|
||||
QAction m_closeOtherEditorsAction;
|
||||
|
||||
Reference in New Issue
Block a user