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