1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qwaylanddnd_p.h" |
5 | |
6 | #include "qwaylanddatadevice_p.h" |
7 | #include "qwaylanddatadevicemanager_p.h" |
8 | #include "qwaylanddataoffer_p.h" |
9 | #include "qwaylandinputdevice_p.h" |
10 | #include "qwaylanddisplay_p.h" |
11 | |
12 | #include <QtGui/private/qshapedpixmapdndwindow_p.h> |
13 | |
14 | #include <QDebug> |
15 | |
16 | QT_BEGIN_NAMESPACE |
17 | #if QT_CONFIG(draganddrop) |
18 | namespace QtWaylandClient { |
19 | |
20 | QWaylandDrag::QWaylandDrag(QWaylandDisplay *display) |
21 | : m_display(display) |
22 | { |
23 | } |
24 | |
25 | QWaylandDrag::~QWaylandDrag() |
26 | { |
27 | } |
28 | |
29 | void QWaylandDrag::startDrag() |
30 | { |
31 | QBasicDrag::startDrag(); |
32 | QWaylandWindow *icon = static_cast<QWaylandWindow *>(shapedPixmapWindow()->handle()); |
33 | if (m_display->currentInputDevice()->dataDevice()->startDrag(mimeData: drag()->mimeData(), supportedActions: drag()->supportedActions(), icon)) { |
34 | icon->addAttachOffset(point: -drag()->hotSpot()); |
35 | } else { |
36 | // Cancelling immediately does not work, since the event loop for QDrag::exec is started |
37 | // after this function returns. |
38 | QMetaObject::invokeMethod(object: this, function: [this](){ cancelDrag(); }, type: Qt::QueuedConnection); |
39 | } |
40 | } |
41 | |
42 | void QWaylandDrag::cancel() |
43 | { |
44 | QBasicDrag::cancel(); |
45 | |
46 | m_display->currentInputDevice()->dataDevice()->cancelDrag(); |
47 | |
48 | if (drag()) |
49 | drag()->deleteLater(); |
50 | } |
51 | |
52 | void QWaylandDrag::move(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods) |
53 | { |
54 | Q_UNUSED(globalPos); |
55 | Q_UNUSED(b); |
56 | Q_UNUSED(mods); |
57 | // Do nothing |
58 | } |
59 | |
60 | void QWaylandDrag::drop(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods) |
61 | { |
62 | QBasicDrag::drop(globalPos, b, mods); |
63 | } |
64 | |
65 | void QWaylandDrag::endDrag() |
66 | { |
67 | m_display->currentInputDevice()->handleEndDrag(); |
68 | } |
69 | |
70 | void QWaylandDrag::setResponse(bool accepted) |
71 | { |
72 | // This method is used for old DataDevices where the drag action is not communicated |
73 | Qt::DropAction action = defaultAction(possibleActions: drag()->supportedActions(), modifiers: m_display->currentInputDevice()->modifiers()); |
74 | setResponse(QPlatformDropQtResponse(accepted, action)); |
75 | } |
76 | |
77 | void QWaylandDrag::setResponse(const QPlatformDropQtResponse &response) |
78 | { |
79 | setCanDrop(response.isAccepted()); |
80 | |
81 | if (canDrop()) { |
82 | updateCursor(action: response.acceptedAction()); |
83 | } else { |
84 | updateCursor(action: Qt::IgnoreAction); |
85 | } |
86 | } |
87 | |
88 | void QWaylandDrag::setDropResponse(const QPlatformDropQtResponse &response) |
89 | { |
90 | setExecutedDropAction(response.acceptedAction()); |
91 | } |
92 | |
93 | void QWaylandDrag::finishDrag() |
94 | { |
95 | QKeyEvent event(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier); |
96 | eventFilter(o: shapedPixmapWindow(), e: &event); |
97 | |
98 | if (drag()) |
99 | drag()->deleteLater(); |
100 | } |
101 | |
102 | bool QWaylandDrag::ownsDragObject() const |
103 | { |
104 | return true; |
105 | } |
106 | |
107 | } |
108 | #endif // draganddrop |
109 | QT_END_NAMESPACE |
110 | |