summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qdrag.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>2012-02-22 10:58:28 +0100
committerQt by Nokia <qt-info@nokia.com>2012-02-29 20:10:30 +0100
commit3a72a1c7ed5adcdf3e473b50cc9c932e9290ee81 (patch)
treec9c6ab476e935c1141675382c051ef86e003440d /src/gui/kernel/qdrag.cpp
parent70784b9069fbd1c73eddbbfc83ffb44b2ca15854 (diff)
Refactor the QPA dnd interface.
- Give QPlatformDrag a synchronous drag() function returning the Qt::DropAction - Move the base functionality for asynchronous event handling to the platformsupport library as QBasicDrag (extendable base class handling drag icon and providing new virtuals) and QSimpleDrag (sample implementation for drag within the Qt application). - Change the Windows implementation accordingly. - Change XCB to be based on QBasicDrag. - Clean up QDragManager. Change-Id: I654f76f0e55a385ba189bd74f3ceaded6a8fe318 Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
Diffstat (limited to 'src/gui/kernel/qdrag.cpp')
-rw-r--r--src/gui/kernel/qdrag.cpp89
1 files changed, 63 insertions, 26 deletions
diff --git a/src/gui/kernel/qdrag.cpp b/src/gui/kernel/qdrag.cpp
index 694b12a180..ead0805bd1 100644
--- a/src/gui/kernel/qdrag.cpp
+++ b/src/gui/kernel/qdrag.cpp
@@ -40,6 +40,7 @@
****************************************************************************/
#include <qdrag.h>
+#include "private/qguiapplication_p.h"
#include <qpixmap.h>
#include <qpoint.h>
#include "qdnd_p.h"
@@ -114,9 +115,9 @@ QDrag::QDrag(QObject *dragSource)
d->target = 0;
d->data = 0;
d->hotspot = QPoint(-10, -10);
- d->possible_actions = Qt::CopyAction;
d->executed_action = Qt::IgnoreAction;
- d->defaultDropAction = Qt::IgnoreAction;
+ d->supported_actions = Qt::IgnoreAction;
+ d->default_action = Qt::IgnoreAction;
}
/*!
@@ -126,9 +127,6 @@ QDrag::~QDrag()
{
Q_D(QDrag);
delete d->data;
- QDragManager *manager = QDragManager::self();
- if (manager && manager->object == this)
- manager->cancel(false);
}
/*!
@@ -264,24 +262,22 @@ Qt::DropAction QDrag::exec(Qt::DropActions supportedActions, Qt::DropAction defa
qWarning("QDrag: No mimedata set before starting the drag");
return d->executed_action;
}
- QDragManager *manager = QDragManager::self();
- d->defaultDropAction = Qt::IgnoreAction;
- d->possible_actions = supportedActions;
-
- if (manager) {
- if (defaultDropAction == Qt::IgnoreAction) {
- if (supportedActions & Qt::MoveAction) {
- d->defaultDropAction = Qt::MoveAction;
- } else if (supportedActions & Qt::CopyAction) {
- d->defaultDropAction = Qt::CopyAction;
- } else if (supportedActions & Qt::LinkAction) {
- d->defaultDropAction = Qt::LinkAction;
- }
- } else {
- d->defaultDropAction = defaultDropAction;
+ Qt::DropAction transformedDefaultDropAction = Qt::IgnoreAction;
+
+ if (defaultDropAction == Qt::IgnoreAction) {
+ if (supportedActions & Qt::MoveAction) {
+ transformedDefaultDropAction = Qt::MoveAction;
+ } else if (supportedActions & Qt::CopyAction) {
+ transformedDefaultDropAction = Qt::CopyAction;
+ } else if (supportedActions & Qt::LinkAction) {
+ transformedDefaultDropAction = Qt::LinkAction;
}
- d->executed_action = manager->drag(this);
+ } else {
+ transformedDefaultDropAction = defaultDropAction;
}
+ d->supported_actions = supportedActions;
+ d->default_action = transformedDefaultDropAction;
+ d->executed_action = QDragManager::self()->drag(this);
return d->executed_action;
}
@@ -308,11 +304,9 @@ Qt::DropAction QDrag::start(Qt::DropActions request)
qWarning("QDrag: No mimedata set before starting the drag");
return d->executed_action;
}
- QDragManager *manager = QDragManager::self();
- d->defaultDropAction = Qt::IgnoreAction;
- d->possible_actions = request | Qt::CopyAction;
- if (manager)
- d->executed_action = manager->drag(this);
+ d->supported_actions = request | Qt::CopyAction;
+ d->default_action = Qt::IgnoreAction;
+ d->executed_action = QDragManager::self()->drag(this);
return d->executed_action;
}
@@ -336,6 +330,49 @@ void QDrag::setDragCursor(const QPixmap &cursor, Qt::DropAction action)
}
/*!
+ Returns the drag cursor for the \a action.
+
+ \since 5.0
+*/
+
+QPixmap QDrag::dragCursor(Qt::DropAction action) const
+{
+ typedef QMap<Qt::DropAction, QPixmap>::const_iterator Iterator;
+
+ Q_D(const QDrag);
+ const Iterator it = d->customCursors.constFind(action);
+ if (it != d->customCursors.constEnd())
+ return it.value();
+
+ Qt::CursorShape shape = Qt::ForbiddenCursor;
+ switch (action) {
+ case Qt::MoveAction:
+ shape = Qt::DragMoveCursor;
+ break;
+ case Qt::CopyAction:
+ shape = Qt::DragCopyCursor;
+ break;
+ case Qt::LinkAction:
+ shape = Qt::DragLinkCursor;
+ break;
+ default:
+ shape = Qt::ForbiddenCursor;
+ }
+ return QGuiApplicationPrivate::instance()->getPixmapCursor(shape);
+}
+
+Qt::DropActions QDrag::supportedActions() const
+{
+ Q_D(const QDrag);
+ return d->supported_actions;
+}
+
+Qt::DropAction QDrag::defaultAction() const
+{
+ Q_D(const QDrag);
+ return d->default_action;
+}
+/*!
\fn void QDrag::actionChanged(Qt::DropAction action)
This signal is emitted when the \a action associated with the