Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwaylanddnd.cpp
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
6
12
13#include <QtGui/private/qshapedpixmapdndwindow_p.h>
14
15#include <QDebug>
16
18#if QT_CONFIG(draganddrop)
19namespace QtWaylandClient {
20
21QWaylandDrag::QWaylandDrag(QWaylandDisplay *display)
22 : m_display(display)
23{
24}
25
26QWaylandDrag::~QWaylandDrag()
27{
28}
29
30void QWaylandDrag::startDrag()
31{
32 // Some compositors do not send a pointer leave before starting a drag, some do.
33 // This is discussed upstream at: https://gitlab.freedesktop.org/wayland/wayland/-/issues/444
34 // For consistency between compositors we emit the leave event here, upon drag start.
35 m_display->currentInputDevice()->handleStartDrag();
36
37 QBasicDrag::startDrag();
38 QWaylandWindow *icon = static_cast<QWaylandWindow *>(shapedPixmapWindow()->handle());
39 if (m_display->currentInputDevice()->dataDevice()->startDrag(drag()->mimeData(), drag()->supportedActions(), icon)) {
40 icon->addAttachOffset(-drag()->hotSpot());
41 } else {
42 // Cancelling immediately does not work, since the event loop for QDrag::exec is started
43 // after this function returns.
44 QMetaObject::invokeMethod(this, [this](){ cancelDrag(); }, Qt::QueuedConnection);
45 }
46}
47
48void QWaylandDrag::cancel()
49{
50 QBasicDrag::cancel();
51
52 m_display->currentInputDevice()->dataDevice()->cancelDrag();
53
54 if (drag())
55 drag()->deleteLater();
56}
57
58void QWaylandDrag::move(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods)
59{
60 Q_UNUSED(globalPos);
61 Q_UNUSED(b);
62 Q_UNUSED(mods);
63 // Do nothing
64}
65
66void QWaylandDrag::drop(const QPoint &globalPos, Qt::MouseButtons b, Qt::KeyboardModifiers mods)
67{
68 QBasicDrag::drop(globalPos, b, mods);
69}
70
71void QWaylandDrag::endDrag()
72{
73 m_display->currentInputDevice()->handleEndDrag();
74}
75
76void QWaylandDrag::setResponse(bool accepted)
77{
78 // This method is used for old DataDevices where the drag action is not communicated
79 Qt::DropAction action = defaultAction(drag()->supportedActions(), m_display->currentInputDevice()->modifiers());
80 setResponse(QPlatformDropQtResponse(accepted, action));
81}
82
83void QWaylandDrag::setResponse(const QPlatformDropQtResponse &response)
84{
85 setCanDrop(response.isAccepted());
86
87 if (canDrop()) {
88 updateCursor(response.acceptedAction());
89 } else {
90 updateCursor(Qt::IgnoreAction);
91 }
92}
93
94void QWaylandDrag::setDropResponse(const QPlatformDropQtResponse &response)
95{
96 setExecutedDropAction(response.isAccepted() ? response.acceptedAction() : Qt::IgnoreAction);
97}
98
99void QWaylandDrag::finishDrag()
100{
101 QKeyEvent event(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier);
102 eventFilter(shapedPixmapWindow(), &event);
103
104 if (drag())
105 drag()->deleteLater();
106}
107
108bool QWaylandDrag::ownsDragObject() const
109{
110 return true;
111}
112
113}
114#endif // draganddrop
115QT_END_NAMESPACE
Combined button and popup list for selecting options.