1 | // Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "qwaylanddrag.h" |
5 | |
6 | #include <private/qobject_p.h> |
7 | |
8 | #include "qwaylandview.h" |
9 | #include <QtWaylandCompositor/private/qwaylandseat_p.h> |
10 | #include <QtWaylandCompositor/private/qtwaylandcompositorglobal_p.h> |
11 | |
12 | #if QT_CONFIG(wayland_datadevice) |
13 | #include "qwldatadevice_p.h" |
14 | #endif |
15 | |
16 | QT_BEGIN_NAMESPACE |
17 | |
18 | class QWaylandDragPrivate : public QObjectPrivate |
19 | { |
20 | public: |
21 | QWaylandDragPrivate(QWaylandSeat *seat) |
22 | : seat(seat) |
23 | { |
24 | } |
25 | |
26 | QtWayland::DataDevice *dataDevice() |
27 | { |
28 | return QWaylandSeatPrivate::get(device: seat)->dataDevice(); |
29 | } |
30 | |
31 | const QtWayland::DataDevice *dataDevice() const |
32 | { |
33 | return QWaylandSeatPrivate::get(device: seat)->dataDevice(); |
34 | } |
35 | |
36 | QWaylandSeat *seat = nullptr; |
37 | }; |
38 | |
39 | QWaylandDrag::QWaylandDrag(QWaylandSeat *seat) |
40 | : QObject(* new QWaylandDragPrivate(seat)) |
41 | { |
42 | } |
43 | |
44 | QWaylandSurface *QWaylandDrag::icon() const |
45 | { |
46 | Q_D(const QWaylandDrag); |
47 | |
48 | const QtWayland::DataDevice *dataDevice = d->dataDevice(); |
49 | if (!dataDevice) |
50 | return nullptr; |
51 | |
52 | return dataDevice->dragIcon(); |
53 | } |
54 | |
55 | QWaylandSurface *QWaylandDrag::origin() const |
56 | { |
57 | Q_D(const QWaylandDrag); |
58 | const QtWayland::DataDevice *dataDevice = d->dataDevice(); |
59 | return dataDevice ? dataDevice->dragOrigin() : nullptr; |
60 | } |
61 | |
62 | QWaylandSeat *QWaylandDrag::seat() const |
63 | { |
64 | Q_D(const QWaylandDrag); |
65 | return d->seat; |
66 | } |
67 | |
68 | |
69 | bool QWaylandDrag::visible() const |
70 | { |
71 | Q_D(const QWaylandDrag); |
72 | |
73 | const QtWayland::DataDevice *dataDevice = d->dataDevice(); |
74 | if (!dataDevice) |
75 | return false; |
76 | |
77 | return dataDevice->dragIcon() != nullptr; |
78 | } |
79 | |
80 | void QWaylandDrag::dragMove(QWaylandSurface *target, const QPointF &pos) |
81 | { |
82 | Q_D(QWaylandDrag); |
83 | QtWayland::DataDevice *dataDevice = d->dataDevice(); |
84 | if (!dataDevice) |
85 | return; |
86 | dataDevice->dragMove(target, pos); |
87 | } |
88 | void QWaylandDrag::drop() |
89 | { |
90 | Q_D(QWaylandDrag); |
91 | QtWayland::DataDevice *dataDevice = d->dataDevice(); |
92 | if (!dataDevice) |
93 | return; |
94 | dataDevice->drop(); |
95 | } |
96 | |
97 | void QWaylandDrag::cancelDrag() |
98 | { |
99 | Q_D(QWaylandDrag); |
100 | QtWayland::DataDevice *dataDevice = d->dataDevice(); |
101 | if (!dataDevice) |
102 | return; |
103 | dataDevice->cancelDrag(); |
104 | } |
105 | |
106 | QT_END_NAMESPACE |
107 | |
108 | #include "moc_qwaylanddrag.cpp" |
109 |