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 | class DeclarativeDropArea : public QQuickItem |
16 | { |
17 | Q_OBJECT |
18 | |
19 | /** |
20 | * If false the area will receive no drop events |
21 | */ |
22 | Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) |
23 | |
24 | /** |
25 | * |
26 | */ |
27 | Q_PROPERTY(bool preventStealing READ preventStealing WRITE setPreventStealing NOTIFY preventStealingChanged) |
28 | |
29 | Q_PROPERTY(bool containsDrag READ containsDrag NOTIFY containsDragChanged) |
30 | |
31 | public: |
32 | DeclarativeDropArea(QQuickItem *parent = nullptr); |
33 | bool isEnabled() const; |
34 | void setEnabled(bool enabled); |
35 | |
36 | bool preventStealing() const; |
37 | void setPreventStealing(bool prevent); |
38 | bool containsDrag() const; |
39 | |
40 | Q_SIGNALS: |
41 | /** |
42 | * Emitted when the mouse cursor dragging something enters in the drag area |
43 | * @param event description of the dragged content |
44 | * @see DeclarativeDragDropEvent |
45 | */ |
46 | void dragEnter(DeclarativeDragDropEvent *event); |
47 | |
48 | /** |
49 | * Emitted when the mouse cursor dragging something leaves the drag area |
50 | * @param event description of the dragged content |
51 | * @see DeclarativeDragDropEvent |
52 | */ |
53 | void dragLeave(DeclarativeDragDropEvent *event); |
54 | |
55 | /** |
56 | * Emitted when the mouse cursor dragging something moves over the drag area |
57 | * @param event description of the dragged content |
58 | * @see DeclarativeDragDropEvent |
59 | */ |
60 | void dragMove(DeclarativeDragDropEvent *event); |
61 | |
62 | /** |
63 | * Emitted when the user drops something in the area |
64 | * @param event description of the dragged content |
65 | * @see DeclarativeDragDropEvent |
66 | */ |
67 | void drop(DeclarativeDragDropEvent *event); |
68 | |
69 | // Notifiers |
70 | void enabledChanged(); |
71 | |
72 | void preventStealingChanged(); |
73 | |
74 | void containsDragChanged(bool contained); |
75 | |
76 | protected: |
77 | void dragEnterEvent(QDragEnterEvent *event) override; |
78 | void dragLeaveEvent(QDragLeaveEvent *event) override; |
79 | void dragMoveEvent(QDragMoveEvent *event) override; |
80 | void dropEvent(QDropEvent *event) override; |
81 | |
82 | private Q_SLOTS: |
83 | void temporaryInhibitParent(bool inhibit); |
84 | |
85 | private: |
86 | void setContainsDrag(bool dragging); |
87 | |
88 | bool m_enabled : 1; |
89 | bool m_preventStealing : 1; |
90 | bool m_temporaryInhibition : 1; |
91 | bool m_containsDrag : 1; |
92 | QPoint m_oldDragMovePos; |
93 | }; |
94 | |
95 | #endif |
96 | |