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 DECLARATIVEDRAGDROPEVENT_H |
9 | #define DECLARATIVEDRAGDROPEVENT_H |
10 | |
11 | #include "DeclarativeDropArea.h" |
12 | #include "DeclarativeMimeData.h" |
13 | #include <QObject> |
14 | |
15 | /*! |
16 | * \qmltype DragDropEvent |
17 | * \inqmlmodule org.kde.draganddrop |
18 | */ |
19 | class DeclarativeDragDropEvent : public QObject |
20 | { |
21 | Q_OBJECT |
22 | QML_NAMED_ELEMENT(DragDropEvent) |
23 | QML_UNCREATABLE("DragDropEvent cannot be created from QML." ) |
24 | |
25 | /*! |
26 | * \qmlproperty int DragDropEvent::x |
27 | * The mouse X position of the event relative to the DropArea that is receiving the event. |
28 | */ |
29 | Q_PROPERTY(int x READ x) |
30 | |
31 | /*! |
32 | * \qmlproperty int DragDropEvent::y |
33 | * The mouse Y position of the event relative to the DropArea that is receiving the event. |
34 | */ |
35 | Q_PROPERTY(int y READ y) |
36 | |
37 | /*! |
38 | * \qmlproperty int DragDropEvent::buttons |
39 | * The pressed mouse buttons. |
40 | * A combination of: |
41 | * \value Qt.NoButton The button state does not refer to any button (see QMouseEvent::button()). |
42 | * \value Qt.LeftButton The left button is pressed, or an event refers to the left button. (The left button may be the right button on left-handed mice.) |
43 | * \value Qt.RightButton The right button. |
44 | * \value Qt.MidButton The middle button. |
45 | * \value Qt.MiddleButton MidButton The middle button. |
46 | * \value Qt.XButton1 The first X button. |
47 | * \value Qt.XButton2 The second X button. |
48 | */ |
49 | Q_PROPERTY(int buttons READ buttons) |
50 | |
51 | /*! |
52 | * \qmlproperty int DragDropEvent::modifiers |
53 | * Pressed keyboard modifiers, a combination of: |
54 | * \value Qt.NoModifier No modifier key is pressed. |
55 | * \value Qt.ShiftModifier A Shift key on the keyboard is pressed. |
56 | * \value Qt.ControlModifier A Ctrl key on the keyboard is pressed. |
57 | * \value Qt.AltModifier An Alt key on the keyboard is pressed. |
58 | * \value Qt.MetaModifier A Meta key on the keyboard is pressed. |
59 | * \value Qt.KeypadModifier A keypad button is pressed. |
60 | * \value Qt.GroupSwitchModifier X11 only. A Mode_switch key on the keyboard is pressed. |
61 | */ |
62 | Q_PROPERTY(int modifiers READ modifiers) |
63 | |
64 | /*! |
65 | * \qmlproperty MimeData DragDropEvent::mimeData |
66 | * The mime data of this operation |
67 | * \sa MimeData |
68 | */ |
69 | Q_PROPERTY(DeclarativeMimeData *mimeData READ mimeData) |
70 | |
71 | /*! |
72 | * \qmlproperty Qt::DropActions DragDropEvent::possibleActions |
73 | * The possible kinds of action that can be done in the drop, |
74 | * a combination of: |
75 | * \value Qt.CopyAction |
76 | * 0x1 Copy the data to the target. |
77 | * \value Qt.MoveAction |
78 | * 0x2 Move the data from the source to the target. |
79 | * \value Qt.LinkAction |
80 | * 0x4 Create a link from the source to the target. |
81 | * \value Qt.ActionMask |
82 | * 0xff |
83 | * \value Qt.IgnoreAction |
84 | * 0x0 Ignore the action (do nothing with the data). |
85 | * \value Qt.TargetMoveAction |
86 | * 0x8002 On Windows, this value is used when the ownership of |
87 | * the D&D data should be taken over by the target application, |
88 | * i.e., the source application should not delete the data. |
89 | * On X11 this value is used to do a move. |
90 | * TargetMoveAction is not used on the Mac. |
91 | */ |
92 | Q_PROPERTY(Qt::DropActions possibleActions READ possibleActions) |
93 | |
94 | /*! |
95 | * \qmlproperty Qt::DropAction DragDropEvent::proposedAction |
96 | * Default action |
97 | * \sa possibleActions |
98 | */ |
99 | Q_PROPERTY(Qt::DropAction proposedAction READ proposedAction) |
100 | |
101 | public: |
102 | DeclarativeDragDropEvent(QDropEvent *e, DeclarativeDropArea *parent = nullptr); |
103 | DeclarativeDragDropEvent(QDragLeaveEvent *e, DeclarativeDropArea *parent = nullptr); |
104 | |
105 | int x() const |
106 | { |
107 | return m_x; |
108 | } |
109 | int y() const |
110 | { |
111 | return m_y; |
112 | } |
113 | int buttons() const |
114 | { |
115 | return m_buttons; |
116 | } |
117 | int modifiers() const |
118 | { |
119 | return m_modifiers; |
120 | } |
121 | DeclarativeMimeData *mimeData(); |
122 | Qt::DropAction proposedAction() const |
123 | { |
124 | return m_event->proposedAction(); |
125 | } |
126 | Qt::DropActions possibleActions() const |
127 | { |
128 | return m_event->possibleActions(); |
129 | } |
130 | |
131 | public Q_SLOTS: |
132 | /*! |
133 | * \qmlmethod DragDropEvent::accept(int action) |
134 | */ |
135 | void accept(int action); |
136 | |
137 | /*! |
138 | * \qmlmethod DragDropEvent::ignore() |
139 | */ |
140 | void ignore(); |
141 | |
142 | private: |
143 | int m_x; |
144 | int m_y; |
145 | Qt::MouseButtons m_buttons; |
146 | Qt::KeyboardModifiers m_modifiers; |
147 | QScopedPointer<DeclarativeMimeData> m_data; |
148 | QDropEvent *m_event; |
149 | }; |
150 | |
151 | #endif // DECLARATIVEDRAGDROPEVENT_H |
152 | |