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 | #ifndef QQUICKDROPAREA_P_H |
5 | #define QQUICKDROPAREA_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <private/qtquickglobal_p.h> |
19 | |
20 | #include <QtQuick/qquickitem.h> |
21 | |
22 | #include <QtGui/qevent.h> |
23 | |
24 | QT_REQUIRE_CONFIG(quick_draganddrop); |
25 | |
26 | QT_BEGIN_NAMESPACE |
27 | |
28 | class QQuickDropAreaPrivate; |
29 | class QQuickDragEvent : public QObject |
30 | { |
31 | Q_OBJECT |
32 | Q_PROPERTY(qreal x READ x FINAL) |
33 | Q_PROPERTY(qreal y READ y FINAL) |
34 | Q_PROPERTY(QObject *source READ source FINAL) |
35 | Q_PROPERTY(QStringList keys READ keys FINAL) |
36 | Q_PROPERTY(Qt::DropActions supportedActions READ supportedActions FINAL) |
37 | Q_PROPERTY(Qt::DropActions proposedAction READ proposedAction FINAL) |
38 | Q_PROPERTY(Qt::DropAction action READ action WRITE setAction RESET resetAction FINAL) |
39 | Q_PROPERTY(bool accepted READ accepted WRITE setAccepted FINAL) |
40 | Q_PROPERTY(bool hasColor READ hasColor FINAL) |
41 | Q_PROPERTY(bool hasHtml READ hasHtml FINAL) |
42 | Q_PROPERTY(bool hasText READ hasText FINAL) |
43 | Q_PROPERTY(bool hasUrls READ hasUrls FINAL) |
44 | Q_PROPERTY(QVariant colorData READ colorData FINAL) |
45 | Q_PROPERTY(QString html READ html FINAL) |
46 | Q_PROPERTY(QString text READ text FINAL) |
47 | Q_PROPERTY(QList<QUrl> urls READ urls FINAL) |
48 | Q_PROPERTY(QStringList formats READ formats FINAL) |
49 | QML_NAMED_ELEMENT(DragEvent) |
50 | QML_UNCREATABLE("DragEvent is only meant to be created by DropArea") |
51 | QML_ADDED_IN_VERSION(2, 0) |
52 | public: |
53 | QQuickDragEvent(QQuickDropAreaPrivate *d, QDropEvent *event) : d(d), event(event) {} |
54 | |
55 | qreal x() const { return event->position().x(); } |
56 | qreal y() const { return event->position().y(); } |
57 | |
58 | QObject *source() const; |
59 | |
60 | Qt::DropActions supportedActions() const { return event->possibleActions(); } |
61 | Qt::DropActions proposedAction() const { return event->proposedAction(); } |
62 | Qt::DropAction action() const { return event->dropAction(); } |
63 | void setAction(Qt::DropAction action) { event->setDropAction(action); } |
64 | void resetAction() { event->setDropAction(event->proposedAction()); } |
65 | |
66 | QStringList keys() const; |
67 | |
68 | bool accepted() const { return event->isAccepted(); } |
69 | void setAccepted(bool accepted) { event->setAccepted(accepted); } |
70 | |
71 | bool hasColor() const; |
72 | bool hasHtml() const; |
73 | bool hasText() const; |
74 | bool hasUrls() const; |
75 | QVariant colorData() const; |
76 | QString html() const; |
77 | QString text() const; |
78 | QList<QUrl> urls() const; |
79 | QStringList formats() const; |
80 | |
81 | Q_INVOKABLE QString getDataAsString(const QString &format) const; |
82 | Q_INVOKABLE QByteArray getDataAsArrayBuffer(const QString &format) const; |
83 | Q_INVOKABLE void acceptProposedAction(); |
84 | Q_INVOKABLE void accept(); |
85 | Q_INVOKABLE void accept(Qt::DropAction action); |
86 | |
87 | private: |
88 | QQuickDropAreaPrivate *d; |
89 | QDropEvent *event; |
90 | }; |
91 | |
92 | class QQuickDropAreaDrag : public QObject |
93 | { |
94 | Q_OBJECT |
95 | Q_PROPERTY(qreal x READ x NOTIFY positionChanged FINAL) |
96 | Q_PROPERTY(qreal y READ y NOTIFY positionChanged FINAL) |
97 | Q_PROPERTY(QObject *source READ source NOTIFY sourceChanged FINAL) |
98 | QML_ANONYMOUS |
99 | QML_ADDED_IN_VERSION(2, 0) |
100 | public: |
101 | QQuickDropAreaDrag(QQuickDropAreaPrivate *d, QObject *parent = nullptr); |
102 | ~QQuickDropAreaDrag(); |
103 | |
104 | qreal x() const; |
105 | qreal y() const; |
106 | QObject *source() const; |
107 | |
108 | Q_SIGNALS: |
109 | void positionChanged(); |
110 | void sourceChanged(); |
111 | |
112 | private: |
113 | QQuickDropAreaPrivate *d; |
114 | |
115 | friend class QQuickDropArea; |
116 | friend class QQuickDropAreaPrivate; |
117 | }; |
118 | |
119 | class QQuickDropAreaPrivate; |
120 | class Q_QUICK_PRIVATE_EXPORT QQuickDropArea : public QQuickItem |
121 | { |
122 | Q_OBJECT |
123 | Q_PROPERTY(bool containsDrag READ containsDrag NOTIFY containsDragChanged FINAL) |
124 | Q_PROPERTY(QStringList keys READ keys WRITE setKeys NOTIFY keysChanged FINAL) |
125 | Q_PROPERTY(QQuickDropAreaDrag *drag READ drag CONSTANT FINAL) |
126 | QML_NAMED_ELEMENT(DropArea) |
127 | QML_ADDED_IN_VERSION(2, 0) |
128 | |
129 | public: |
130 | QQuickDropArea(QQuickItem *parent=0); |
131 | ~QQuickDropArea(); |
132 | |
133 | bool containsDrag() const; |
134 | void setContainsDrag(bool drag); |
135 | |
136 | QStringList keys() const; |
137 | void setKeys(const QStringList &keys); |
138 | |
139 | QQuickDropAreaDrag *drag(); |
140 | |
141 | Q_SIGNALS: |
142 | void containsDragChanged(); |
143 | void keysChanged(); |
144 | void sourceChanged(); |
145 | |
146 | void entered(QQuickDragEvent *drag); |
147 | void exited(); |
148 | void positionChanged(QQuickDragEvent *drag); |
149 | void dropped(QQuickDragEvent *drop); |
150 | |
151 | protected: |
152 | void dragMoveEvent(QDragMoveEvent *event) override; |
153 | void dragEnterEvent(QDragEnterEvent *event) override; |
154 | void dragLeaveEvent(QDragLeaveEvent *event) override; |
155 | void dropEvent(QDropEvent *event) override; |
156 | |
157 | private: |
158 | Q_DISABLE_COPY(QQuickDropArea) |
159 | Q_DECLARE_PRIVATE(QQuickDropArea) |
160 | }; |
161 | |
162 | QT_END_NAMESPACE |
163 | |
164 | QML_DECLARE_TYPE(QQuickDropArea) |
165 | |
166 | #endif // QQUICKDROPAREA_P_H |
167 |