summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qdrag.cpp
diff options
context:
space:
mode:
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