From c2bb490378fc6cd50d6cf49e29f6ba0c6be46bd8 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Mon, 20 Aug 2018 19:10:48 +0800 Subject: [PATCH] MdEditor: copy backgorund when copying in-place preview --- src/vmdeditor.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/vmdeditor.cpp b/src/vmdeditor.cpp index 8382a325..f23132a4 100644 --- a/src/vmdeditor.cpp +++ b/src/vmdeditor.cpp @@ -1625,6 +1625,7 @@ bool VMdEditor::initInPlacePreviewMenu(QAction *p_before, } QPixmap image; + QString background; int pib = p_pos - p_block.position(); for (auto info : previews) { const VPreviewedImageInfo &pii = info->m_imageInfo; @@ -1632,6 +1633,7 @@ bool VMdEditor::initInPlacePreviewMenu(QAction *p_before, const QPixmap *img = findImage(pii.m_imageName); if (img) { image = *img; + background = pii.m_background; } break; @@ -1644,10 +1646,20 @@ bool VMdEditor::initInPlacePreviewMenu(QAction *p_before, QAction *copyImageAct = new QAction(tr("Copy In-Place Preview"), p_menu); connect(copyImageAct, &QAction::triggered, - this, [this, image]() { + this, [this, image, background]() { + QColor co(background); + if (!co.isValid()) { + co = palette().color(QPalette::Base); + } + + QImage img(image.size(), QImage::Format_ARGB32); + img.fill(co); + QPainter pter(&img); + pter.drawPixmap(img.rect(), image); + QClipboard *clipboard = QApplication::clipboard(); VClipboardUtils::setImageToClipboard(clipboard, - image, + img, QClipboard::Clipboard); }); p_menu->insertAction(p_before, copyImageAct);