[Libreoffice-commits] core.git: vcl/qt5
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Fri Oct 12 15:00:22 UTC 2018
vcl/qt5/Qt5Clipboard.cxx | 74 ++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 67 insertions(+), 7 deletions(-)
New commits:
commit ff1bd0f189635a6efe84337f8c6b4a366e7501e2
Author: Katarina Behrens <Katarina.Behrens at cib.de>
AuthorDate: Wed Oct 10 13:33:15 2018 +0200
Commit: Katarina Behrens <Katarina.Behrens at cib.de>
CommitDate: Fri Oct 12 16:59:56 2018 +0200
HTML and image copy into qt5 clipboard
Change-Id: I1c26db35b801694fcc3935baab842027eac1e561
Reviewed-on: https://gerrit.libreoffice.org/61611
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 14e98d4b6ed3..6ed8b1086e4a 100644
--- a/vcl/qt5/Qt5Clipboard.cxx
+++ b/vcl/qt5/Qt5Clipboard.cxx
@@ -20,6 +20,22 @@
#include <Qt5Clipboard.hxx>
#include <Qt5Tools.hxx>
+namespace
+{
+void lcl_peekFormats(const css::uno::Sequence<css::datatransfer::DataFlavor>& rFormats,
+ bool& bHasHtml, bool& bHasImage)
+{
+ for (int i = 0; i < rFormats.getLength(); ++i)
+ {
+ const css::datatransfer::DataFlavor& rFlavor = rFormats[i];
+
+ if (rFlavor.MimeType == "text/html")
+ bHasHtml = true;
+ else if (rFlavor.MimeType.startsWith("image"))
+ bHasImage = true;
+ }
+}
+}
std::vector<css::datatransfer::DataFlavor> Qt5Transferable::getTransferDataFlavorsAsVector()
{
@@ -163,9 +179,30 @@ void VclQt5Clipboard::setContents(
if (m_aContents.is())
{
+ css::uno::Sequence<css::datatransfer::DataFlavor> aFormats
+ = xTrans->getTransferDataFlavors();
+ bool bHasHtml = false, bHasImage = false;
+ lcl_peekFormats(aFormats, bHasHtml, bHasImage);
+
css::datatransfer::DataFlavor aFlavor;
- aFlavor.MimeType = "text/plain;charset=utf-16";
- aFlavor.DataType = cppu::UnoType<OUString>::get();
+ QClipboard* clipboard = QApplication::clipboard();
+
+ if (bHasImage)
+ {
+ //FIXME: other image formats?
+ aFlavor.MimeType = "image/png";
+ aFlavor.DataType = cppu::UnoType<sal_Int8>::get();
+ }
+ else if (bHasHtml)
+ {
+ aFlavor.MimeType = "text/html";
+ aFlavor.DataType = cppu::UnoType<sal_Int8>::get();
+ }
+ else
+ {
+ aFlavor.MimeType = "text/plain;charset=utf-16";
+ aFlavor.DataType = cppu::UnoType<OUString>::get();
+ }
Any aValue;
try
@@ -176,11 +213,34 @@ void VclQt5Clipboard::setContents(
{
}
- OUString aString;
- aValue >>= aString;
-
- QClipboard* clipboard = QApplication::clipboard();
- clipboard->setText(toQString(aString));
+ if (aValue.getValueTypeClass() == TypeClass_STRING)
+ {
+ OUString aString;
+ aValue >>= aString;
+ clipboard->setText(toQString(aString));
+ }
+ else if (aValue.getValueType() == cppu::UnoType<Sequence<sal_Int8>>::get())
+ {
+ Sequence<sal_Int8> aData;
+ aValue >>= aData;
+
+ if (bHasHtml)
+ {
+ OUString aHtmlAsString(reinterpret_cast<const char*>(aData.getConstArray()),
+ aData.getLength(), RTL_TEXTENCODING_UTF8);
+ QMimeData* mimeData = new QMimeData;
+
+ mimeData->setHtml(toQString(aHtmlAsString));
+ clipboard->setMimeData(mimeData);
+ }
+ else if (bHasImage)
+ {
+ QImage image;
+ image.loadFromData(reinterpret_cast<const uchar*>(aData.getConstArray()),
+ aData.getLength());
+ clipboard->setImage(image);
+ }
+ }
}
aEv.Contents = getContents();
More information about the Libreoffice-commits
mailing list