[Libreoffice-commits] core.git: vcl/qt5

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Oct 12 13:21:50 UTC 2018


 vcl/qt5/Qt5Clipboard.cxx |   33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)

New commits:
commit 3f29d2cb7ccb7150d5ecd8f6e2bdc2f0de9efb1d
Author:     Katarina Behrens <Katarina.Behrens at cib.de>
AuthorDate: Mon Oct 8 09:41:37 2018 +0200
Commit:     Katarina Behrens <Katarina.Behrens at cib.de>
CommitDate: Fri Oct 12 15:21:24 2018 +0200

    Support HTML paste from qt5 clipboard
    
    Change-Id: I23b615bf0720fdcdb1849e7890956c1d9f1a79c1
    Reviewed-on: https://gerrit.libreoffice.org/61516
    Tested-by: Jenkins
    Reviewed-by: Katarina Behrens <Katarina.Behrens at cib.de>

diff --git a/vcl/qt5/Qt5Clipboard.cxx b/vcl/qt5/Qt5Clipboard.cxx
index 52c43a2541b1..6a777cc1af3e 100644
--- a/vcl/qt5/Qt5Clipboard.cxx
+++ b/vcl/qt5/Qt5Clipboard.cxx
@@ -15,6 +15,7 @@
 
 #include <QtWidgets/QApplication>
 #include <QtGui/QClipboard>
+#include <QtCore/QMimeData>
 
 #include <Qt5Clipboard.hxx>
 #include <Qt5Tools.hxx>
@@ -23,11 +24,23 @@ std::vector<css::datatransfer::DataFlavor> Qt5Transferable::getTransferDataFlavo
 {
     std::vector<css::datatransfer::DataFlavor> aVector;
 
-    // FIXME: this is fake
+    const QClipboard* clipboard = QApplication::clipboard();
+    const QMimeData* mimeData = clipboard->mimeData();
     css::datatransfer::DataFlavor aFlavor;
-    aFlavor.MimeType = "text/plain;charset=utf-16";
-    aFlavor.DataType = cppu::UnoType<OUString>::get();
-    aVector.push_back(aFlavor);
+
+    if (mimeData->hasHtml())
+    {
+        aFlavor.MimeType = "text/html";
+        aFlavor.DataType = cppu::UnoType<Sequence<sal_Int8>>::get();
+        aVector.push_back(aFlavor);
+    }
+
+    if (mimeData->hasText())
+    {
+        aFlavor.MimeType = "text/plain;charset=utf-16";
+        aFlavor.DataType = cppu::UnoType<OUString>::get();
+        aVector.push_back(aFlavor);
+    }
 
     return aVector;
 }
@@ -53,15 +66,23 @@ css::uno::Any SAL_CALL
 Qt5Transferable::getTransferData(const css::datatransfer::DataFlavor& rFlavor)
 {
     css::uno::Any aRet;
+    const QClipboard* clipboard = QApplication::clipboard();
+    const QMimeData* mimeData = clipboard->mimeData();
 
     if (rFlavor.MimeType == "text/plain;charset=utf-16")
     {
-        const QClipboard* clipboard = QApplication::clipboard();
-        QString clipboardContent = clipboard->text();
+        QString clipboardContent = mimeData->text();
         OUString sContent = toOUString(clipboardContent);
 
         aRet <<= sContent.replaceAll("\r\n", "\n");
     }
+    else if (rFlavor.MimeType == "text/html")
+    {
+        QString clipboardContent = mimeData->html();
+        std::string aStr = clipboardContent.toStdString();
+        Sequence<sal_Int8> aSeq(reinterpret_cast<const sal_Int8*>(aStr.c_str()), aStr.length());
+        aRet <<= aSeq;
+    }
 
     return aRet;
 }


More information about the Libreoffice-commits mailing list