[Libreoffice-commits] core.git: Branch 'libreoffice-6-2' - vcl/qt5
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Mon Feb 4 13:36:17 UTC 2019
vcl/qt5/Qt5Clipboard.cxx | 111 +++++++++++++++++++++++++++++------------------
1 file changed, 70 insertions(+), 41 deletions(-)
New commits:
commit b0b203b5d09054250a257c052d7c7870eb1c4ffe
Author: Aleksei Nikiforov <darktemplar at basealt.ru>
AuthorDate: Thu Jan 17 15:31:51 2019 +0300
Commit: Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Mon Feb 4 14:35:55 2019 +0100
tdf#120836 KDE5: allow adding multiple mime types to clipboard
Also correct processing "text/html" and "image/png" mime types
to fix slow select in Calc:
if both "text/html" and "image/png" mime types were present,
"image/png" data was requested, but it was processed as if it was
"text/html" data.
Change-Id: Ie192fff06cd9de28f466547dac32343620fe2730
Reviewed-on: https://gerrit.libreoffice.org/66576
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
(cherry picked from commit 7e01a02b12a9ea3a39b5a627f3b26d94bc1ad921)
Reviewed-on: https://gerrit.libreoffice.org/67362
Tested-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
diff --git a/vcl/qt5/Qt5Clipboard.cxx b/vcl/qt5/Qt5Clipboard.cxx
index 6ed8b1086e4a..a9134506896f 100644
--- a/vcl/qt5/Qt5Clipboard.cxx
+++ b/vcl/qt5/Qt5Clipboard.cxx
@@ -184,63 +184,92 @@ void VclQt5Clipboard::setContents(
bool bHasHtml = false, bHasImage = false;
lcl_peekFormats(aFormats, bHasHtml, bHasImage);
- css::datatransfer::DataFlavor aFlavor;
- QClipboard* clipboard = QApplication::clipboard();
+ std::unique_ptr<QMimeData> pMimeData(new QMimeData);
- if (bHasImage)
- {
- //FIXME: other image formats?
- aFlavor.MimeType = "image/png";
- aFlavor.DataType = cppu::UnoType<sal_Int8>::get();
- }
- else if (bHasHtml)
+ // Add html data if present
+ if (bHasHtml)
{
+ css::datatransfer::DataFlavor aFlavor;
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();
- }
+ aFlavor.DataType = cppu::UnoType<Sequence<sal_Int8>>::get();
- Any aValue;
- try
- {
- aValue = xTrans->getTransferData(aFlavor);
- }
- catch (...)
- {
- }
-
- 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;
+ Any aValue;
+ try
+ {
+ aValue = xTrans->getTransferData(aFlavor);
+ }
+ catch (...)
+ {
+ }
- if (bHasHtml)
+ if (aValue.getValueType() == cppu::UnoType<Sequence<sal_Int8>>::get())
{
+ Sequence<sal_Int8> aData;
+ aValue >>= aData;
+
OUString aHtmlAsString(reinterpret_cast<const char*>(aData.getConstArray()),
aData.getLength(), RTL_TEXTENCODING_UTF8);
- QMimeData* mimeData = new QMimeData;
- mimeData->setHtml(toQString(aHtmlAsString));
- clipboard->setMimeData(mimeData);
+ pMimeData->setHtml(toQString(aHtmlAsString));
}
- else if (bHasImage)
+ }
+
+ // Add image data if present
+ if (bHasImage)
+ {
+ css::datatransfer::DataFlavor aFlavor;
+ //FIXME: other image formats?
+ aFlavor.MimeType = "image/png";
+ aFlavor.DataType = cppu::UnoType<Sequence<sal_Int8>>::get();
+
+ Any aValue;
+ try
{
+ aValue = xTrans->getTransferData(aFlavor);
+ }
+ catch (...)
+ {
+ }
+
+ if (aValue.getValueType() == cppu::UnoType<Sequence<sal_Int8>>::get())
+ {
+ Sequence<sal_Int8> aData;
+ aValue >>= aData;
+
QImage image;
image.loadFromData(reinterpret_cast<const uchar*>(aData.getConstArray()),
aData.getLength());
- clipboard->setImage(image);
+
+ pMimeData->setImageData(image);
+ }
+ }
+
+ // Add text data
+ // TODO: consider checking if text of suitable type is present
+ {
+ css::datatransfer::DataFlavor aFlavor;
+ aFlavor.MimeType = "text/plain;charset=utf-16";
+ aFlavor.DataType = cppu::UnoType<OUString>::get();
+
+ Any aValue;
+ try
+ {
+ aValue = xTrans->getTransferData(aFlavor);
+ }
+ catch (...)
+ {
+ }
+
+ if (aValue.getValueTypeClass() == TypeClass_STRING)
+ {
+ OUString aString;
+ aValue >>= aString;
+ pMimeData->setText(toQString(aString));
}
}
+
+ QClipboard* clipboard = QApplication::clipboard();
+ clipboard->setMimeData(pMimeData.release());
}
aEv.Contents = getContents();
More information about the Libreoffice-commits
mailing list