summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/qt5/Qt5Clipboard.hxx6
-rw-r--r--vcl/qt5/Qt5Clipboard.cxx23
2 files changed, 25 insertions, 4 deletions
diff --git a/vcl/inc/qt5/Qt5Clipboard.hxx b/vcl/inc/qt5/Qt5Clipboard.hxx
index 122184b44942..b99534f59039 100644
--- a/vcl/inc/qt5/Qt5Clipboard.hxx
+++ b/vcl/inc/qt5/Qt5Clipboard.hxx
@@ -41,6 +41,8 @@ class Qt5Clipboard final
// has to be set, if LO changes the QClipboard itself, so it won't instantly lose
// ownership by it's self-triggered QClipboard::changed handler
bool m_bOwnClipboardChange;
+ // true, if LO really wants to give up clipboard ownership
+ bool m_bDoClear;
// if not empty, this holds the setContents provided XTransferable or a Qt5ClipboardTransferable
css::uno::Reference<css::datatransfer::XTransferable> m_aContents;
@@ -55,6 +57,10 @@ class Qt5Clipboard final
private Q_SLOTS:
void handleChanged(QClipboard::Mode mode);
+ void handleClearClipboard();
+
+signals:
+ void clearClipboard();
public:
// factory function to construct only valid Qt5Clipboard objects by name
diff --git a/vcl/qt5/Qt5Clipboard.cxx b/vcl/qt5/Qt5Clipboard.cxx
index cadedbfd327e..8720cfe44310 100644
--- a/vcl/qt5/Qt5Clipboard.cxx
+++ b/vcl/qt5/Qt5Clipboard.cxx
@@ -30,11 +30,16 @@ Qt5Clipboard::Qt5Clipboard(const OUString& aModeString, const QClipboard::Mode a
, m_aClipboardName(aModeString)
, m_aClipboardMode(aMode)
, m_bOwnClipboardChange(false)
+ , m_bDoClear(false)
{
assert(isSupported(m_aClipboardMode));
// DirectConnection guarantees the changed slot runs in the same thread as the QClipboard
connect(QApplication::clipboard(), &QClipboard::changed, this, &Qt5Clipboard::handleChanged,
Qt::DirectConnection);
+
+ // explicitly queue an event, so we can eventually ignore it
+ connect(this, &Qt5Clipboard::clearClipboard, this, &Qt5Clipboard::handleClearClipboard,
+ Qt::QueuedConnection);
}
css::uno::Reference<css::uno::XInterface> Qt5Clipboard::create(const OUString& aModeString)
@@ -98,6 +103,13 @@ css::uno::Reference<css::datatransfer::XTransferable> Qt5Clipboard::getContents(
return m_aContents;
}
+void Qt5Clipboard::handleClearClipboard()
+{
+ if (!m_bDoClear)
+ return;
+ QApplication::clipboard()->clear(m_aClipboardMode);
+}
+
void Qt5Clipboard::setContents(
const css::uno::Reference<css::datatransfer::XTransferable>& xTrans,
const css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner>& xClipboardOwner)
@@ -110,15 +122,18 @@ void Qt5Clipboard::setContents(
m_aContents = xTrans;
m_aOwner = xClipboardOwner;
- m_bOwnClipboardChange = true;
- if (m_aContents.is())
+ m_bDoClear = !m_aContents.is();
+ if (!m_bDoClear)
+ {
+ m_bOwnClipboardChange = true;
QApplication::clipboard()->setMimeData(new Qt5MimeData(m_aContents), m_aClipboardMode);
+ m_bOwnClipboardChange = false;
+ }
else
{
assert(!m_aOwner.is());
- QApplication::clipboard()->clear(m_aClipboardMode);
+ Q_EMIT clearClipboard();
}
- m_bOwnClipboardChange = false;
aGuard.clear();