From 6f65ddbc217a8c82b091d31e88faf3dc23baa13b Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 10 Jul 2015 13:35:11 +0200 Subject: Implement canceling of Qt-initiated drags. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add new virtual QPlatformDrag::cancelDrag() [avoiding a conflict with existing QBasicDrag::cancel()] - Implement on Windows by returning DRAGDROP_S_CANCEL from IOleDropSource::QueryContinueDrag() as suggested on report. - Implement in QBasicDrag by calling QBasicDrag::cancel() and quitting the event loop. - Add new API static void QDrag::cancel() for it. Task-number: QTBUG-47004 Change-Id: I4b4bb52e5fc226c8e04688ac1b0f9550daaf918e Reviewed-by: Jørgen Lind Reviewed-by: David Faure --- src/gui/kernel/qdrag.cpp | 19 +++++++++++++++++++ src/gui/kernel/qdrag.h | 2 ++ src/gui/kernel/qplatformdrag.cpp | 14 ++++++++++++++ src/gui/kernel/qplatformdrag.h | 1 + src/gui/kernel/qsimpledrag.cpp | 8 ++++++++ src/gui/kernel/qsimpledrag_p.h | 1 + 6 files changed, 45 insertions(+) (limited to 'src/gui') diff --git a/src/gui/kernel/qdrag.cpp b/src/gui/kernel/qdrag.cpp index 2736fac8e0..36527966b7 100644 --- a/src/gui/kernel/qdrag.cpp +++ b/src/gui/kernel/qdrag.cpp @@ -33,6 +33,8 @@ #include #include "private/qguiapplication_p.h" +#include "qpa/qplatformintegration.h" +#include "qpa/qplatformdrag.h" #include #include #include "qdnd_p.h" @@ -223,6 +225,8 @@ QObject *QDrag::target() const loop. Other events are still delivered to the application while the operation is performed. On Windows, the Qt event loop is blocked during the operation. + + \sa cancel() */ Qt::DropAction QDrag::exec(Qt::DropActions supportedActions) @@ -377,6 +381,21 @@ Qt::DropAction QDrag::defaultAction() const Q_D(const QDrag); return d->default_action; } + +/*! + Cancels a drag operation initiated by Qt. + + \note This is currently implemented on Windows and X11. + + \since 5.6 + \sa exec() +*/ +void QDrag::cancel() +{ + if (QPlatformDrag *platformDrag = QGuiApplicationPrivate::platformIntegration()->drag()) + platformDrag->cancelDrag(); +} + /*! \fn void QDrag::actionChanged(Qt::DropAction action) diff --git a/src/gui/kernel/qdrag.h b/src/gui/kernel/qdrag.h index 0672cb00f9..961d7c89d9 100644 --- a/src/gui/kernel/qdrag.h +++ b/src/gui/kernel/qdrag.h @@ -77,6 +77,8 @@ public: Qt::DropActions supportedActions() const; Qt::DropAction defaultAction() const; + static void cancel(); + Q_SIGNALS: void actionChanged(Qt::DropAction action); void targetChanged(QObject *newTarget); diff --git a/src/gui/kernel/qplatformdrag.cpp b/src/gui/kernel/qplatformdrag.cpp index d789c75d1d..11230194fc 100644 --- a/src/gui/kernel/qplatformdrag.cpp +++ b/src/gui/kernel/qplatformdrag.cpp @@ -154,6 +154,20 @@ Qt::DropAction QPlatformDrag::defaultAction(Qt::DropActions possibleActions, return default_action; } +/*! + \brief Cancels the currently active drag (only for drags of + the current application initiated by QPlatformDrag::drag()). + + The default implementation does nothing. + + \since 5.6 + */ + +void QPlatformDrag::cancelDrag() +{ + Q_UNIMPLEMENTED(); +} + /*! \brief Called to notify QDrag about changes of the current action. */ diff --git a/src/gui/kernel/qplatformdrag.h b/src/gui/kernel/qplatformdrag.h index 10ee88477f..72e28d2745 100644 --- a/src/gui/kernel/qplatformdrag.h +++ b/src/gui/kernel/qplatformdrag.h @@ -92,6 +92,7 @@ public: virtual QMimeData *platformDropData() = 0; virtual Qt::DropAction drag(QDrag *m_drag) = 0; + virtual void cancelDrag(); void updateAction(Qt::DropAction action); virtual Qt::DropAction defaultAction(Qt::DropActions possibleActions, Qt::KeyboardModifiers modifiers) const; diff --git a/src/gui/kernel/qsimpledrag.cpp b/src/gui/kernel/qsimpledrag.cpp index 6acac4cade..d2efeaca28 100644 --- a/src/gui/kernel/qsimpledrag.cpp +++ b/src/gui/kernel/qsimpledrag.cpp @@ -191,6 +191,14 @@ Qt::DropAction QBasicDrag::drag(QDrag *o) return m_executed_drop_action; } +void QBasicDrag::cancelDrag() +{ + if (m_eventLoop) { + cancel(); + m_eventLoop->quit(); + } +} + void QBasicDrag::restoreCursor() { if (m_restoreCursor) { diff --git a/src/gui/kernel/qsimpledrag_p.h b/src/gui/kernel/qsimpledrag_p.h index 4c9edbae05..34679a7540 100644 --- a/src/gui/kernel/qsimpledrag_p.h +++ b/src/gui/kernel/qsimpledrag_p.h @@ -66,6 +66,7 @@ public: virtual ~QBasicDrag(); virtual Qt::DropAction drag(QDrag *drag) Q_DECL_OVERRIDE; + void cancelDrag() Q_DECL_OVERRIDE; virtual bool eventFilter(QObject *o, QEvent *e) Q_DECL_OVERRIDE; -- cgit v1.2.3