| 1 | /**************************************************************************** |
|---|---|
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtQuick module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #ifndef QQUICKDROPAREA_P_H |
| 41 | #define QQUICKDROPAREA_P_H |
| 42 | |
| 43 | // |
| 44 | // W A R N I N G |
| 45 | // ------------- |
| 46 | // |
| 47 | // This file is not part of the Qt API. It exists purely as an |
| 48 | // implementation detail. This header file may change from version to |
| 49 | // version without notice, or even be removed. |
| 50 | // |
| 51 | // We mean it. |
| 52 | // |
| 53 | |
| 54 | #include "qquickitem.h" |
| 55 | |
| 56 | #include <QtGui/qevent.h> |
| 57 | |
| 58 | QT_REQUIRE_CONFIG(quick_draganddrop); |
| 59 | |
| 60 | QT_BEGIN_NAMESPACE |
| 61 | |
| 62 | class QQuickDropAreaPrivate; |
| 63 | class QQuickDropEvent : public QObject |
| 64 | { |
| 65 | Q_OBJECT |
| 66 | Q_PROPERTY(qreal x READ x) |
| 67 | Q_PROPERTY(qreal y READ y) |
| 68 | Q_PROPERTY(QObject *source READ source) |
| 69 | Q_PROPERTY(QStringList keys READ keys) |
| 70 | Q_PROPERTY(Qt::DropActions supportedActions READ supportedActions) |
| 71 | Q_PROPERTY(Qt::DropActions proposedAction READ proposedAction) |
| 72 | Q_PROPERTY(Qt::DropAction action READ action WRITE setAction RESET resetAction) |
| 73 | Q_PROPERTY(bool accepted READ accepted WRITE setAccepted) |
| 74 | Q_PROPERTY(bool hasColor READ hasColor) |
| 75 | Q_PROPERTY(bool hasHtml READ hasHtml) |
| 76 | Q_PROPERTY(bool hasText READ hasText) |
| 77 | Q_PROPERTY(bool hasUrls READ hasUrls) |
| 78 | Q_PROPERTY(QVariant colorData READ colorData) |
| 79 | Q_PROPERTY(QString html READ html) |
| 80 | Q_PROPERTY(QString text READ text) |
| 81 | Q_PROPERTY(QList<QUrl> urls READ urls) |
| 82 | Q_PROPERTY(QStringList formats READ formats) |
| 83 | QML_ANONYMOUS |
| 84 | public: |
| 85 | QQuickDropEvent(QQuickDropAreaPrivate *d, QDropEvent *event) : d(d), event(event) {} |
| 86 | |
| 87 | qreal x() const { return event->pos().x(); } |
| 88 | qreal y() const { return event->pos().y(); } |
| 89 | |
| 90 | QObject *source() const; |
| 91 | |
| 92 | Qt::DropActions supportedActions() const { return event->possibleActions(); } |
| 93 | Qt::DropActions proposedAction() const { return event->proposedAction(); } |
| 94 | Qt::DropAction action() const { return event->dropAction(); } |
| 95 | void setAction(Qt::DropAction action) { event->setDropAction(action); } |
| 96 | void resetAction() { event->setDropAction(event->proposedAction()); } |
| 97 | |
| 98 | QStringList keys() const; |
| 99 | |
| 100 | bool accepted() const { return event->isAccepted(); } |
| 101 | void setAccepted(bool accepted) { event->setAccepted(accepted); } |
| 102 | |
| 103 | bool hasColor() const; |
| 104 | bool hasHtml() const; |
| 105 | bool hasText() const; |
| 106 | bool hasUrls() const; |
| 107 | QVariant colorData() const; |
| 108 | QString html() const; |
| 109 | QString text() const; |
| 110 | QList<QUrl> urls() const; |
| 111 | QStringList formats() const; |
| 112 | |
| 113 | Q_INVOKABLE void getDataAsString(QQmlV4Function *); |
| 114 | Q_INVOKABLE void getDataAsArrayBuffer(QQmlV4Function *); |
| 115 | Q_INVOKABLE void acceptProposedAction(QQmlV4Function *); |
| 116 | Q_INVOKABLE void accept(QQmlV4Function *); |
| 117 | |
| 118 | private: |
| 119 | QQuickDropAreaPrivate *d; |
| 120 | QDropEvent *event; |
| 121 | }; |
| 122 | |
| 123 | class QQuickDropAreaDrag : public QObject |
| 124 | { |
| 125 | Q_OBJECT |
| 126 | Q_PROPERTY(qreal x READ x NOTIFY positionChanged) |
| 127 | Q_PROPERTY(qreal y READ y NOTIFY positionChanged) |
| 128 | Q_PROPERTY(QObject *source READ source NOTIFY sourceChanged) |
| 129 | QML_ANONYMOUS |
| 130 | public: |
| 131 | QQuickDropAreaDrag(QQuickDropAreaPrivate *d, QObject *parent = 0); |
| 132 | ~QQuickDropAreaDrag(); |
| 133 | |
| 134 | qreal x() const; |
| 135 | qreal y() const; |
| 136 | QObject *source() const; |
| 137 | |
| 138 | Q_SIGNALS: |
| 139 | void positionChanged(); |
| 140 | void sourceChanged(); |
| 141 | |
| 142 | private: |
| 143 | QQuickDropAreaPrivate *d; |
| 144 | |
| 145 | friend class QQuickDropArea; |
| 146 | friend class QQuickDropAreaPrivate; |
| 147 | }; |
| 148 | |
| 149 | class QQuickDropAreaPrivate; |
| 150 | class Q_AUTOTEST_EXPORT QQuickDropArea : public QQuickItem |
| 151 | { |
| 152 | Q_OBJECT |
| 153 | Q_PROPERTY(bool containsDrag READ containsDrag NOTIFY containsDragChanged) |
| 154 | Q_PROPERTY(QStringList keys READ keys WRITE setKeys NOTIFY keysChanged) |
| 155 | Q_PROPERTY(QQuickDropAreaDrag *drag READ drag CONSTANT) |
| 156 | QML_NAMED_ELEMENT(DropArea) |
| 157 | |
| 158 | public: |
| 159 | QQuickDropArea(QQuickItem *parent=0); |
| 160 | ~QQuickDropArea(); |
| 161 | |
| 162 | bool containsDrag() const; |
| 163 | void setContainsDrag(bool drag); |
| 164 | |
| 165 | QStringList keys() const; |
| 166 | void setKeys(const QStringList &keys); |
| 167 | |
| 168 | QQuickDropAreaDrag *drag(); |
| 169 | |
| 170 | Q_SIGNALS: |
| 171 | void containsDragChanged(); |
| 172 | void keysChanged(); |
| 173 | void sourceChanged(); |
| 174 | |
| 175 | void entered(QQuickDropEvent *drag); |
| 176 | void exited(); |
| 177 | void positionChanged(QQuickDropEvent *drag); |
| 178 | void dropped(QQuickDropEvent *drop); |
| 179 | |
| 180 | protected: |
| 181 | void dragMoveEvent(QDragMoveEvent *event) override; |
| 182 | void dragEnterEvent(QDragEnterEvent *event) override; |
| 183 | void dragLeaveEvent(QDragLeaveEvent *event) override; |
| 184 | void dropEvent(QDropEvent *event) override; |
| 185 | |
| 186 | private: |
| 187 | Q_DISABLE_COPY(QQuickDropArea) |
| 188 | Q_DECLARE_PRIVATE(QQuickDropArea) |
| 189 | }; |
| 190 | |
| 191 | QT_END_NAMESPACE |
| 192 | |
| 193 | QML_DECLARE_TYPE(QQuickDropEvent) |
| 194 | QML_DECLARE_TYPE(QQuickDropArea) |
| 195 | |
| 196 | #endif // QQUICKDROPAREA_P_H |
| 197 |
