Forráskód Böngészése

MdEditor: copy backgorund when copying in-place preview

Le Tan 7 éve
szülő
commit
c2bb490378
1 módosított fájl, 14 hozzáadás és 2 törlés
  1. 14 2
      src/vmdeditor.cpp

+ 14 - 2
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);