1 | /* |
2 | SPDX-FileCopyrightText: 2010 BetterInbox <contact@betterinbox.com> |
3 | SPDX-FileContributor: Gregory Schlomoff <greg@betterinbox.com> |
4 | |
5 | SPDX-License-Identifier: MIT |
6 | */ |
7 | |
8 | #ifndef DECLARATIVEDROPAREA_H |
9 | #define DECLARATIVEDROPAREA_H |
10 | |
11 | #include <QQuickItem> |
12 | |
13 | class DeclarativeDragDropEvent; |
14 | |
15 | /*! |
16 | * \qmltype DropArea |
17 | * \inqmlmodule org.kde.draganddrop |
18 | */ |
19 | class DeclarativeDropArea : public QQuickItem |
20 | { |
21 | Q_OBJECT |
22 | QML_NAMED_ELEMENT(DropArea) |
23 | |
24 | /*! |
25 | * \qmlproperty bool DropArea::enabled |
26 | * If false the area will receive no drop events |
27 | */ |
28 | Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) |
29 | |
30 | /*! |
31 | * \qmlproperty bool DropArea::preventStealing |
32 | */ |
33 | Q_PROPERTY(bool preventStealing READ preventStealing WRITE setPreventStealing NOTIFY preventStealingChanged) |
34 | |
35 | /*! |
36 | * \qmlproperty bool DropArea::containsDrag |
37 | */ |
38 | Q_PROPERTY(bool containsDrag READ containsDrag NOTIFY containsDragChanged) |
39 | |
40 | public: |
41 | DeclarativeDropArea(QQuickItem *parent = nullptr); |
42 | bool isEnabled() const; |
43 | void setEnabled(bool enabled); |
44 | |
45 | bool preventStealing() const; |
46 | void setPreventStealing(bool prevent); |
47 | bool containsDrag() const; |
48 | |
49 | Q_SIGNALS: |
50 | /*! |
51 | * \qmlsignal DropArea::dragEnter(DeclarativeDragDropEvent *event) |
52 | * |
53 | * Emitted when the mouse cursor dragging something enters in the drag area |
54 | * |
55 | * \a event description of the dragged content |
56 | * \sa DragDropEvent |
57 | */ |
58 | void dragEnter(DeclarativeDragDropEvent *event); |
59 | |
60 | /*! |
61 | * \qmlsignal DropArea::dragLeave(DeclarativeDragDropEvent *event) |
62 | * |
63 | * Emitted when the mouse cursor dragging something leaves the drag area |
64 | * |
65 | * \a event description of the dragged content |
66 | * \sa DragDropEvent |
67 | */ |
68 | void dragLeave(DeclarativeDragDropEvent *event); |
69 | |
70 | /*! |
71 | * \qmlsignal DropArea::dragMove(DeclarativeDragDropEvent *event) |
72 | * |
73 | * Emitted when the mouse cursor dragging something moves over the drag area |
74 | * |
75 | * \a event description of the dragged content |
76 | * \sa DragDropEvent |
77 | */ |
78 | void dragMove(DeclarativeDragDropEvent *event); |
79 | |
80 | /*! |
81 | * \qmlsignal DropArea::drop(DeclarativeDragDropEvent *event) |
82 | * |
83 | * Emitted when the user drops something in the area |
84 | * |
85 | * \a event description of the dragged content |
86 | * \sa DragDropEvent |
87 | */ |
88 | void drop(DeclarativeDragDropEvent *event); |
89 | |
90 | // Notifiers |
91 | void enabledChanged(); |
92 | |
93 | void preventStealingChanged(); |
94 | |
95 | void containsDragChanged(bool contained); |
96 | |
97 | protected: |
98 | void dragEnterEvent(QDragEnterEvent *event) override; |
99 | void dragLeaveEvent(QDragLeaveEvent *event) override; |
100 | void dragMoveEvent(QDragMoveEvent *event) override; |
101 | void dropEvent(QDropEvent *event) override; |
102 | |
103 | private Q_SLOTS: |
104 | void temporaryInhibitParent(bool inhibit); |
105 | |
106 | private: |
107 | void setContainsDrag(bool dragging); |
108 | |
109 | bool m_enabled : 1; |
110 | bool m_preventStealing : 1; |
111 | bool m_temporaryInhibition : 1; |
112 | bool m_containsDrag : 1; |
113 | QPoint m_oldDragMovePos; |
114 | }; |
115 | |
116 | #endif |
117 | |