summaryrefslogtreecommitdiff
path: root/vcl/qt5/Qt5Clipboard.cxx
diff options
context:
space:
mode:
authorKatarina Behrens <Katarina.Behrens@cib.de>2018-10-10 13:33:15 +0200
committerKatarina Behrens <Katarina.Behrens@cib.de>2018-10-12 16:59:56 +0200
commitff1bd0f189635a6efe84337f8c6b4a366e7501e2 (patch)
treec336125d8fe46a5c9c1e6d7c683b0a1ef25555ee /vcl/qt5/Qt5Clipboard.cxx
parenta40880ca4b7693f9b926404fe5745d7123b320e6 (diff)
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@cib.de>
Diffstat (limited to 'vcl/qt5/Qt5Clipboard.cxx')
-rw-r--r--vcl/qt5/Qt5Clipboard.cxx74
1 files changed, 67 insertions, 7 deletions
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();