Merge lp:~osomon/unity-2d/DropItem into lp:unity-2d/3.0
- DropItem
- Merge into natty
Proposed by
Olivier Tilloy
Status: | Merged |
---|---|
Approved by: | Florian Boucault |
Approved revision: | 399 |
Merged at revision: | 421 |
Proposed branch: | lp:~osomon/unity-2d/DropItem |
Merge into: | lp:unity-2d/3.0 |
Diff against target: |
450 lines (+133/-122) 11 files modified
launcher/Launcher.qml (+4/-1) launcher/LauncherItem.qml (+1/-4) launcher/LauncherList.qml (+2/-2) launcher/app/launcherview.cpp (+16/-91) launcher/app/launcherview.h (+6/-20) libunity-2d-private/Unity2d/CMakeLists.txt (+2/-0) libunity-2d-private/Unity2d/dropitem.cpp (+47/-0) libunity-2d-private/Unity2d/dropitem.h (+46/-0) libunity-2d-private/Unity2d/plugin.cpp (+2/-0) libunity-2d-private/src/dragdropevent.cpp (+3/-1) libunity-2d-private/src/dragdropevent.h (+4/-3) |
To merge this branch: | bzr merge lp:~osomon/unity-2d/DropItem |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Florian Boucault | Pending | ||
Review via email: mp+51915@code.launchpad.net |
Commit message
[launcher] Better implementation of drag’n’drop in QML.
The DropItem element has the following advantages:
- less code
- more re-usable
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'launcher/Launcher.qml' | |||
2 | --- launcher/Launcher.qml 2011-03-01 16:40:00 +0000 | |||
3 | +++ launcher/Launcher.qml 2011-03-02 16:04:16 +0000 | |||
4 | @@ -2,7 +2,7 @@ | |||
5 | 2 | import UnityApplications 1.0 | 2 | import UnityApplications 1.0 |
6 | 3 | import Unity2d 1.0 /* required for drag’n’drop handling */ | 3 | import Unity2d 1.0 /* required for drag’n’drop handling */ |
7 | 4 | 4 | ||
9 | 5 | Item { | 5 | DropItem { |
10 | 6 | id: launcher | 6 | id: launcher |
11 | 7 | 7 | ||
12 | 8 | Image { | 8 | Image { |
13 | @@ -13,6 +13,9 @@ | |||
14 | 13 | source: "artwork/background.png" | 13 | source: "artwork/background.png" |
15 | 14 | } | 14 | } |
16 | 15 | 15 | ||
17 | 16 | onDragEnter: launcherView.onDragEnter(event) | ||
18 | 17 | onDrop: launcherView.onDrop(event) | ||
19 | 18 | |||
20 | 16 | LauncherList { | 19 | LauncherList { |
21 | 17 | id: main | 20 | id: main |
22 | 18 | anchors.top: parent.top | 21 | anchors.top: parent.top |
23 | 19 | 22 | ||
24 | === modified file 'launcher/LauncherItem.qml' | |||
25 | --- launcher/LauncherItem.qml 2011-03-02 10:34:42 +0000 | |||
26 | +++ launcher/LauncherItem.qml 2011-03-02 16:04:16 +0000 | |||
27 | @@ -27,11 +27,8 @@ | |||
28 | 27 | Additionally, when the tile is marked as 'urgent' it will start an animation where the | 27 | Additionally, when the tile is marked as 'urgent' it will start an animation where the |
29 | 28 | rotation is changed so that it appears to be "shaking". | 28 | rotation is changed so that it appears to be "shaking". |
30 | 29 | */ | 29 | */ |
32 | 30 | Item { | 30 | DropItem { |
33 | 31 | id: item | 31 | id: item |
34 | 32 | /* The object name is used by the launcher view to find the current | ||
35 | 33 | launcher item under the mouse cursor during a drag’n’drop event. */ | ||
36 | 34 | objectName: "launcherItem" | ||
37 | 35 | 32 | ||
38 | 36 | anchors.horizontalCenter: parent.horizontalCenter | 33 | anchors.horizontalCenter: parent.horizontalCenter |
39 | 37 | /* Manually add some padding to compensate for the spacing | 34 | /* Manually add some padding to compensate for the spacing |
40 | 38 | 35 | ||
41 | === modified file 'launcher/LauncherList.qml' | |||
42 | --- launcher/LauncherList.qml 2011-03-01 13:05:38 +0000 | |||
43 | +++ launcher/LauncherList.qml 2011-03-02 16:04:16 +0000 | |||
44 | @@ -68,8 +68,8 @@ | |||
45 | 68 | Binding { target: item.menu; property: "title"; value: item.name } | 68 | Binding { target: item.menu; property: "title"; value: item.name } |
46 | 69 | 69 | ||
47 | 70 | /* Drag’n’drop handling */ | 70 | /* Drag’n’drop handling */ |
50 | 71 | function dragEnterEvent(event) { item.onDragEnter(event) } | 71 | onDragEnter: item.onDragEnter(event) |
51 | 72 | function dropEvent(event) { item.onDrop(event) } | 72 | onDrop: item.onDrop(event) |
52 | 73 | 73 | ||
53 | 74 | function showMenu() { | 74 | function showMenu() { |
54 | 75 | /* Prevent the simultaneous display of multiple menus */ | 75 | /* Prevent the simultaneous display of multiple menus */ |
55 | 76 | 76 | ||
56 | === modified file 'launcher/app/launcherview.cpp' | |||
57 | --- launcher/app/launcherview.cpp 2011-03-02 08:31:11 +0000 | |||
58 | +++ launcher/app/launcherview.cpp 2011-03-02 16:04:16 +0000 | |||
59 | @@ -28,24 +28,18 @@ | |||
60 | 28 | #include <QDeclarativeEngine> | 28 | #include <QDeclarativeEngine> |
61 | 29 | #include <QDeclarativeContext> | 29 | #include <QDeclarativeContext> |
62 | 30 | #include <QDeclarativeImageProvider> | 30 | #include <QDeclarativeImageProvider> |
63 | 31 | #include <QGraphicsObject> | ||
64 | 32 | #include <QMetaObject> | ||
65 | 33 | 31 | ||
66 | 34 | #include <X11/Xlib.h> | 32 | #include <X11/Xlib.h> |
67 | 35 | #include <X11/Xatom.h> | 33 | #include <X11/Xatom.h> |
68 | 36 | 34 | ||
69 | 37 | #include "dragdropevent.h" | ||
70 | 38 | #include <keyboardmodifiersmonitor.h> | 35 | #include <keyboardmodifiersmonitor.h> |
71 | 39 | #include <hotkey.h> | 36 | #include <hotkey.h> |
72 | 40 | #include <hotkeymonitor.h> | 37 | #include <hotkeymonitor.h> |
73 | 38 | #include <dragdropevent.h> | ||
74 | 41 | 39 | ||
75 | 42 | LauncherView::LauncherView() : | 40 | LauncherView::LauncherView() : |
79 | 43 | QDeclarativeView(), | 41 | QDeclarativeView(), m_superKeyPressed(false) |
77 | 44 | m_dndCurrentLauncherItem(NULL), m_dndCurrentLauncherItemAccepted(false), | ||
78 | 45 | m_dndAccepted(false), m_superKeyPressed(false) | ||
80 | 46 | { | 42 | { |
81 | 47 | setAcceptDrops(true); | ||
82 | 48 | |||
83 | 49 | m_enableSuperKey.setKey("/desktop/unity/launcher/super_key_enable"); | 43 | m_enableSuperKey.setKey("/desktop/unity/launcher/super_key_enable"); |
84 | 50 | QObject::connect(&m_enableSuperKey, SIGNAL(valueChanged()), | 44 | QObject::connect(&m_enableSuperKey, SIGNAL(valueChanged()), |
85 | 51 | this, SLOT(updateSuperKeyMonitoring())); | 45 | this, SLOT(updateSuperKeyMonitoring())); |
86 | @@ -126,45 +120,8 @@ | |||
87 | 126 | } | 120 | } |
88 | 127 | } | 121 | } |
89 | 128 | 122 | ||
90 | 129 | QGraphicsObject* | ||
91 | 130 | LauncherView::launcherItemAt(const QPoint& pos) const | ||
92 | 131 | { | ||
93 | 132 | QGraphicsItem* item = itemAt(pos); | ||
94 | 133 | while(item != NULL) { | ||
95 | 134 | QGraphicsObject* object = qgraphicsitem_cast<QGraphicsObject*>(item); | ||
96 | 135 | if (object->objectName() == "launcherItem") { | ||
97 | 136 | return object; | ||
98 | 137 | } | ||
99 | 138 | item = item->parentItem(); | ||
100 | 139 | } | ||
101 | 140 | return NULL; | ||
102 | 141 | } | ||
103 | 142 | |||
104 | 143 | void | ||
105 | 144 | LauncherView::delegateDragEventHandlingToItem(QDropEvent* event, QGraphicsObject* item) | ||
106 | 145 | { | ||
107 | 146 | if (item == NULL) { | ||
108 | 147 | return; | ||
109 | 148 | } | ||
110 | 149 | DeclarativeDragDropEvent dde(event, this); | ||
111 | 150 | QMetaObject::invokeMethod(item, "dragEnterEvent", | ||
112 | 151 | Q_ARG(QVariant, QVariant::fromValue(&dde))); | ||
113 | 152 | } | ||
114 | 153 | |||
115 | 154 | bool | ||
116 | 155 | LauncherView::acceptDndEvent(QDragEnterEvent* event) | ||
117 | 156 | { | ||
118 | 157 | Q_FOREACH(QUrl url, getEventUrls(event)) { | ||
119 | 158 | if ((url.scheme() == "file" && url.path().endsWith(".desktop")) || | ||
120 | 159 | url.scheme().startsWith("http")) { | ||
121 | 160 | return true; | ||
122 | 161 | } | ||
123 | 162 | } | ||
124 | 163 | return false; | ||
125 | 164 | } | ||
126 | 165 | |||
127 | 166 | QList<QUrl> | 123 | QList<QUrl> |
129 | 167 | LauncherView::getEventUrls(QDropEvent* event) | 124 | LauncherView::getEventUrls(DeclarativeDragDropEvent* event) |
130 | 168 | { | 125 | { |
131 | 169 | const QMimeData* mimeData = event->mimeData(); | 126 | const QMimeData* mimeData = event->mimeData(); |
132 | 170 | if (mimeData->hasUrls()) { | 127 | if (mimeData->hasUrls()) { |
133 | @@ -191,57 +148,25 @@ | |||
134 | 191 | return QList<QUrl>(); | 148 | return QList<QUrl>(); |
135 | 192 | } | 149 | } |
136 | 193 | 150 | ||
155 | 194 | void | 151 | void LauncherView::onDragEnter(DeclarativeDragDropEvent* event) |
156 | 195 | LauncherView::dragEnterEvent(QDragEnterEvent* event) | 152 | { |
157 | 196 | { | 153 | Q_FOREACH(QUrl url, getEventUrls(event)) { |
158 | 197 | m_dndCurrentLauncherItem = NULL; | 154 | if ((url.scheme() == "file" && url.path().endsWith(".desktop")) || |
159 | 198 | m_dndCurrentLauncherItemAccepted = false; | 155 | url.scheme().startsWith("http")) { |
142 | 199 | /* Compute whether the launcher itself accepts the event only once for this | ||
143 | 200 | given event. */ | ||
144 | 201 | m_dndAccepted = acceptDndEvent(event); | ||
145 | 202 | /* Always accept the event so that subsequent move events are received. */ | ||
146 | 203 | event->setAccepted(true); | ||
147 | 204 | } | ||
148 | 205 | |||
149 | 206 | void | ||
150 | 207 | LauncherView::dragMoveEvent(QDragMoveEvent* event) | ||
151 | 208 | { | ||
152 | 209 | QGraphicsObject* launcherItem = launcherItemAt(event->pos()); | ||
153 | 210 | if (launcherItem == m_dndCurrentLauncherItem) { | ||
154 | 211 | if (m_dndCurrentLauncherItemAccepted || m_dndAccepted) { | ||
160 | 212 | event->setAccepted(true); | 156 | event->setAccepted(true); |
175 | 213 | } | 157 | return; |
162 | 214 | } else { | ||
163 | 215 | m_dndCurrentLauncherItem = launcherItem; | ||
164 | 216 | m_dndCurrentLauncherItemAccepted = false; | ||
165 | 217 | |||
166 | 218 | if (m_dndCurrentLauncherItem != NULL) { | ||
167 | 219 | delegateDragEventHandlingToItem(event, m_dndCurrentLauncherItem); | ||
168 | 220 | if (event->isAccepted()) { | ||
169 | 221 | m_dndCurrentLauncherItemAccepted = true; | ||
170 | 222 | } | ||
171 | 223 | } else { | ||
172 | 224 | if (m_dndAccepted) { | ||
173 | 225 | event->setAccepted(true); | ||
174 | 226 | } | ||
176 | 227 | } | 158 | } |
177 | 228 | } | 159 | } |
178 | 229 | } | 160 | } |
179 | 230 | 161 | ||
182 | 231 | void | 162 | void LauncherView::onDrop(DeclarativeDragDropEvent* event) |
181 | 232 | LauncherView::dropEvent(QDropEvent* event) | ||
183 | 233 | { | 163 | { |
195 | 234 | if (m_dndCurrentLauncherItemAccepted) { | 164 | foreach (QUrl url, getEventUrls(event)) { |
196 | 235 | DeclarativeDragDropEvent dde(event, this); | 165 | if (url.scheme() == "file" && url.path().endsWith(".desktop")) { |
197 | 236 | QMetaObject::invokeMethod(m_dndCurrentLauncherItem, "dropEvent", | 166 | emit desktopFileDropped(url.path()); |
198 | 237 | Q_ARG(QVariant, QVariant::fromValue(&dde))); | 167 | } |
199 | 238 | } else if (m_dndAccepted) { | 168 | else if (url.scheme().startsWith("http")) { |
200 | 239 | Q_FOREACH(QUrl url, getEventUrls(event)) { | 169 | emit webpageUrlDropped(url); |
190 | 240 | if (url.scheme() == "file" && url.path().endsWith(".desktop")) { | ||
191 | 241 | emit desktopFileDropped(url.path()); | ||
192 | 242 | } else if (url.scheme().startsWith("http")) { | ||
193 | 243 | emit webpageUrlDropped(url); | ||
194 | 244 | } | ||
201 | 245 | } | 170 | } |
202 | 246 | } | 171 | } |
203 | 247 | } | 172 | } |
204 | 248 | 173 | ||
205 | === modified file 'launcher/app/launcherview.h' | |||
206 | --- launcher/app/launcherview.h 2011-03-02 08:31:11 +0000 | |||
207 | +++ launcher/app/launcherview.h 2011-03-02 16:04:16 +0000 | |||
208 | @@ -21,12 +21,12 @@ | |||
209 | 21 | #define LAUNCHERVIEW | 21 | #define LAUNCHERVIEW |
210 | 22 | 22 | ||
211 | 23 | #include <QDeclarativeView> | 23 | #include <QDeclarativeView> |
212 | 24 | #include <QList> | ||
213 | 24 | #include <QUrl> | 25 | #include <QUrl> |
216 | 25 | #include <QList> | 26 | |
215 | 26 | #include <QDragEnterEvent> | ||
217 | 27 | #include "gconfitem-qml-wrapper.h" | 27 | #include "gconfitem-qml-wrapper.h" |
218 | 28 | 28 | ||
220 | 29 | class QGraphicsObject; | 29 | class DeclarativeDragDropEvent; |
221 | 30 | 30 | ||
222 | 31 | class LauncherView : public QDeclarativeView | 31 | class LauncherView : public QDeclarativeView |
223 | 32 | { | 32 | { |
224 | @@ -37,6 +37,8 @@ | |||
225 | 37 | public: | 37 | public: |
226 | 38 | explicit LauncherView(); | 38 | explicit LauncherView(); |
227 | 39 | Q_INVOKABLE QList<QVariant> getColorsFromIcon(QUrl source, QSize size) const; | 39 | Q_INVOKABLE QList<QVariant> getColorsFromIcon(QUrl source, QSize size) const; |
228 | 40 | Q_INVOKABLE void onDragEnter(DeclarativeDragDropEvent* event); | ||
229 | 41 | Q_INVOKABLE void onDrop(DeclarativeDragDropEvent* event); | ||
230 | 40 | 42 | ||
231 | 41 | bool superKeyPressed() const { return m_superKeyPressed; } | 43 | bool superKeyPressed() const { return m_superKeyPressed; } |
232 | 42 | 44 | ||
233 | @@ -52,25 +54,9 @@ | |||
234 | 52 | void updateSuperKeyMonitoring(); | 54 | void updateSuperKeyMonitoring(); |
235 | 53 | 55 | ||
236 | 54 | private: | 56 | private: |
238 | 55 | QList<QUrl> getEventUrls(QDropEvent*); | 57 | QList<QUrl> getEventUrls(DeclarativeDragDropEvent* event); |
239 | 56 | void changeKeyboardShortcutsState(bool enabled); | 58 | void changeKeyboardShortcutsState(bool enabled); |
240 | 57 | 59 | ||
241 | 58 | /* Custom drag’n’drop handling */ | ||
242 | 59 | void dragEnterEvent(QDragEnterEvent*); | ||
243 | 60 | void dragMoveEvent(QDragMoveEvent*); | ||
244 | 61 | void dropEvent(QDropEvent*); | ||
245 | 62 | |||
246 | 63 | QGraphicsObject* launcherItemAt(const QPoint&) const; | ||
247 | 64 | void delegateDragEventHandlingToItem(QDropEvent*, QGraphicsObject*); | ||
248 | 65 | bool acceptDndEvent(QDragEnterEvent*); | ||
249 | 66 | |||
250 | 67 | /* The launcher item currently under the mouse cursor during a dnd event */ | ||
251 | 68 | QGraphicsObject* m_dndCurrentLauncherItem; | ||
252 | 69 | /* Whether it accepted the event */ | ||
253 | 70 | bool m_dndCurrentLauncherItemAccepted; | ||
254 | 71 | /* Whether the launcher itself handles the current dnd event */ | ||
255 | 72 | bool m_dndAccepted; | ||
256 | 73 | |||
257 | 74 | GConfItemQmlWrapper m_enableSuperKey; | 60 | GConfItemQmlWrapper m_enableSuperKey; |
258 | 75 | bool m_superKeyPressed; | 61 | bool m_superKeyPressed; |
259 | 76 | }; | 62 | }; |
260 | 77 | 63 | ||
261 | === modified file 'libunity-2d-private/Unity2d/CMakeLists.txt' | |||
262 | --- libunity-2d-private/Unity2d/CMakeLists.txt 2011-02-14 19:59:09 +0000 | |||
263 | +++ libunity-2d-private/Unity2d/CMakeLists.txt 2011-03-02 16:04:16 +0000 | |||
264 | @@ -15,6 +15,7 @@ | |||
265 | 15 | cacheeffect.cpp | 15 | cacheeffect.cpp |
266 | 16 | workspacesinfo.cpp | 16 | workspacesinfo.cpp |
267 | 17 | signalwaiter.cpp | 17 | signalwaiter.cpp |
268 | 18 | dropitem.cpp | ||
269 | 18 | ) | 19 | ) |
270 | 19 | 20 | ||
271 | 20 | set(unity-2d-private-qml_MOC_HDRS | 21 | set(unity-2d-private-qml_MOC_HDRS |
272 | @@ -26,6 +27,7 @@ | |||
273 | 26 | cacheeffect.h | 27 | cacheeffect.h |
274 | 27 | workspacesinfo.h | 28 | workspacesinfo.h |
275 | 28 | signalwaiter.h | 29 | signalwaiter.h |
276 | 30 | dropitem.h | ||
277 | 29 | ) | 31 | ) |
278 | 30 | 32 | ||
279 | 31 | qt4_wrap_cpp(unity-2d-private-qml_MOC_SRCS ${unity-2d-private-qml_MOC_HDRS}) | 33 | qt4_wrap_cpp(unity-2d-private-qml_MOC_SRCS ${unity-2d-private-qml_MOC_HDRS}) |
280 | 32 | 34 | ||
281 | === added file 'libunity-2d-private/Unity2d/dropitem.cpp' | |||
282 | --- libunity-2d-private/Unity2d/dropitem.cpp 1970-01-01 00:00:00 +0000 | |||
283 | +++ libunity-2d-private/Unity2d/dropitem.cpp 2011-03-02 16:04:16 +0000 | |||
284 | @@ -0,0 +1,47 @@ | |||
285 | 1 | /* | ||
286 | 2 | * Copyright (C) 2011 Canonical, Ltd. | ||
287 | 3 | * | ||
288 | 4 | * Authors: | ||
289 | 5 | * Florian Boucault <florian.boucault@canonical.com> | ||
290 | 6 | * | ||
291 | 7 | * This program is free software; you can redistribute it and/or modify | ||
292 | 8 | * it under the terms of the GNU General Public License as published by | ||
293 | 9 | * the Free Software Foundation; version 3. | ||
294 | 10 | * | ||
295 | 11 | * This program is distributed in the hope that it will be useful, | ||
296 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
297 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
298 | 14 | * GNU General Public License for more details. | ||
299 | 15 | * | ||
300 | 16 | * You should have received a copy of the GNU General Public License | ||
301 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
302 | 18 | */ | ||
303 | 19 | |||
304 | 20 | #include "dropitem.h" | ||
305 | 21 | |||
306 | 22 | #include <QGraphicsSceneDragDropEvent> | ||
307 | 23 | |||
308 | 24 | #include "dragdropevent.h" | ||
309 | 25 | |||
310 | 26 | DeclarativeDropItem::DeclarativeDropItem(QDeclarativeItem *parent) : QDeclarativeItem(parent) | ||
311 | 27 | { | ||
312 | 28 | setAcceptDrops(true); | ||
313 | 29 | } | ||
314 | 30 | |||
315 | 31 | void DeclarativeDropItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) | ||
316 | 32 | { | ||
317 | 33 | DeclarativeDragDropEvent dragDropEvent(event, this); | ||
318 | 34 | Q_EMIT dragEnter(&dragDropEvent); | ||
319 | 35 | } | ||
320 | 36 | |||
321 | 37 | void DeclarativeDropItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) | ||
322 | 38 | { | ||
323 | 39 | DeclarativeDragDropEvent dragDropEvent(event, this); | ||
324 | 40 | Q_EMIT dragLeave(&dragDropEvent); | ||
325 | 41 | } | ||
326 | 42 | |||
327 | 43 | void DeclarativeDropItem::dropEvent(QGraphicsSceneDragDropEvent *event) | ||
328 | 44 | { | ||
329 | 45 | DeclarativeDragDropEvent dragDropEvent(event, this); | ||
330 | 46 | Q_EMIT drop(&dragDropEvent); | ||
331 | 47 | } | ||
332 | 0 | 48 | ||
333 | === added file 'libunity-2d-private/Unity2d/dropitem.h' | |||
334 | --- libunity-2d-private/Unity2d/dropitem.h 1970-01-01 00:00:00 +0000 | |||
335 | +++ libunity-2d-private/Unity2d/dropitem.h 2011-03-02 16:04:16 +0000 | |||
336 | @@ -0,0 +1,46 @@ | |||
337 | 1 | /* | ||
338 | 2 | * Copyright (C) 2011 Canonical, Ltd. | ||
339 | 3 | * | ||
340 | 4 | * Authors: | ||
341 | 5 | * Florian Boucault <florian.boucault@canonical.com> | ||
342 | 6 | * | ||
343 | 7 | * This program is free software; you can redistribute it and/or modify | ||
344 | 8 | * it under the terms of the GNU General Public License as published by | ||
345 | 9 | * the Free Software Foundation; version 3. | ||
346 | 10 | * | ||
347 | 11 | * This program is distributed in the hope that it will be useful, | ||
348 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
349 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
350 | 14 | * GNU General Public License for more details. | ||
351 | 15 | * | ||
352 | 16 | * You should have received a copy of the GNU General Public License | ||
353 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
354 | 18 | */ | ||
355 | 19 | |||
356 | 20 | #ifndef DROPITEM_H | ||
357 | 21 | #define DROPITEM_H | ||
358 | 22 | |||
359 | 23 | #include <QDeclarativeItem> | ||
360 | 24 | |||
361 | 25 | class QGraphicsSceneDragDropEvent; | ||
362 | 26 | class DeclarativeDragDropEvent; | ||
363 | 27 | |||
364 | 28 | class DeclarativeDropItem : public QDeclarativeItem | ||
365 | 29 | { | ||
366 | 30 | Q_OBJECT | ||
367 | 31 | |||
368 | 32 | public: | ||
369 | 33 | DeclarativeDropItem(QDeclarativeItem *parent=0); | ||
370 | 34 | |||
371 | 35 | Q_SIGNALS: | ||
372 | 36 | void dragEnter(DeclarativeDragDropEvent* event); | ||
373 | 37 | void dragLeave(DeclarativeDragDropEvent* event); | ||
374 | 38 | void drop(DeclarativeDragDropEvent* event); | ||
375 | 39 | |||
376 | 40 | protected: | ||
377 | 41 | void dragEnterEvent(QGraphicsSceneDragDropEvent *event); | ||
378 | 42 | void dragLeaveEvent(QGraphicsSceneDragDropEvent *event); | ||
379 | 43 | void dropEvent(QGraphicsSceneDragDropEvent *event); | ||
380 | 44 | }; | ||
381 | 45 | |||
382 | 46 | #endif // DROPITEM_H | ||
383 | 0 | 47 | ||
384 | === modified file 'libunity-2d-private/Unity2d/plugin.cpp' | |||
385 | --- libunity-2d-private/Unity2d/plugin.cpp 2011-02-21 02:37:20 +0000 | |||
386 | +++ libunity-2d-private/Unity2d/plugin.cpp 2011-03-02 16:04:16 +0000 | |||
387 | @@ -34,6 +34,7 @@ | |||
388 | 34 | 34 | ||
389 | 35 | #include "mimedata.h" | 35 | #include "mimedata.h" |
390 | 36 | #include "dragdropevent.h" | 36 | #include "dragdropevent.h" |
391 | 37 | #include "dropitem.h" | ||
392 | 37 | 38 | ||
393 | 38 | #include <QtDeclarative/qdeclarative.h> | 39 | #include <QtDeclarative/qdeclarative.h> |
394 | 39 | #include <QDeclarativeEngine> | 40 | #include <QDeclarativeEngine> |
395 | @@ -75,6 +76,7 @@ | |||
396 | 75 | qmlRegisterType<QGraphicsDropShadowEffect>("Effects", 1, 0, "DropShadow"); | 76 | qmlRegisterType<QGraphicsDropShadowEffect>("Effects", 1, 0, "DropShadow"); |
397 | 76 | 77 | ||
398 | 77 | /* Custom drag’n’drop implementation in QML */ | 78 | /* Custom drag’n’drop implementation in QML */ |
399 | 79 | qmlRegisterType<DeclarativeDropItem>(uri, 0, 1, "DropItem"); | ||
400 | 78 | qmlRegisterType<DeclarativeMimeData>(); | 80 | qmlRegisterType<DeclarativeMimeData>(); |
401 | 79 | qmlRegisterType<DeclarativeDragDropEvent>(); | 81 | qmlRegisterType<DeclarativeDragDropEvent>(); |
402 | 80 | } | 82 | } |
403 | 81 | 83 | ||
404 | === modified file 'libunity-2d-private/src/dragdropevent.cpp' | |||
405 | --- libunity-2d-private/src/dragdropevent.cpp 2011-02-15 10:28:23 +0000 | |||
406 | +++ libunity-2d-private/src/dragdropevent.cpp 2011-03-02 16:04:16 +0000 | |||
407 | @@ -19,7 +19,9 @@ | |||
408 | 19 | 19 | ||
409 | 20 | #include "dragdropevent.h" | 20 | #include "dragdropevent.h" |
410 | 21 | 21 | ||
412 | 22 | DeclarativeDragDropEvent::DeclarativeDragDropEvent(QDropEvent* event, QObject* parent) | 22 | #include <QGraphicsSceneDragDropEvent> |
413 | 23 | |||
414 | 24 | DeclarativeDragDropEvent::DeclarativeDragDropEvent(QGraphicsSceneDragDropEvent* event, QObject* parent) | ||
415 | 23 | : QObject(parent) | 25 | : QObject(parent) |
416 | 24 | , m_event(event) | 26 | , m_event(event) |
417 | 25 | , m_mimeData(event->mimeData()) | 27 | , m_mimeData(event->mimeData()) |
418 | 26 | 28 | ||
419 | === modified file 'libunity-2d-private/src/dragdropevent.h' | |||
420 | --- libunity-2d-private/src/dragdropevent.h 2011-02-15 10:28:23 +0000 | |||
421 | +++ libunity-2d-private/src/dragdropevent.h 2011-03-02 16:04:16 +0000 | |||
422 | @@ -25,9 +25,10 @@ | |||
423 | 25 | 25 | ||
424 | 26 | #include "mimedata.h" | 26 | #include "mimedata.h" |
425 | 27 | 27 | ||
426 | 28 | #include <QtGui/QDropEvent> | ||
427 | 29 | #include <QtCore/Qt> | 28 | #include <QtCore/Qt> |
428 | 30 | 29 | ||
429 | 30 | class QGraphicsSceneDragDropEvent; | ||
430 | 31 | |||
431 | 31 | class DeclarativeDragDropEvent : public QObject | 32 | class DeclarativeDragDropEvent : public QObject |
432 | 32 | { | 33 | { |
433 | 33 | Q_OBJECT | 34 | Q_OBJECT |
434 | @@ -37,7 +38,7 @@ | |||
435 | 37 | Q_PROPERTY(Qt::DropAction dropAction READ dropAction WRITE setDropAction) | 38 | Q_PROPERTY(Qt::DropAction dropAction READ dropAction WRITE setDropAction) |
436 | 38 | 39 | ||
437 | 39 | public: | 40 | public: |
439 | 40 | DeclarativeDragDropEvent(QDropEvent* event, QObject* parent=0); | 41 | DeclarativeDragDropEvent(QGraphicsSceneDragDropEvent* event, QObject* parent=0); |
440 | 41 | 42 | ||
441 | 42 | /* getters */ | 43 | /* getters */ |
442 | 43 | DeclarativeMimeData* mimeData() { return &m_mimeData; } | 44 | DeclarativeMimeData* mimeData() { return &m_mimeData; } |
443 | @@ -49,7 +50,7 @@ | |||
444 | 49 | void setDropAction(Qt::DropAction action); | 50 | void setDropAction(Qt::DropAction action); |
445 | 50 | 51 | ||
446 | 51 | private: | 52 | private: |
448 | 52 | QDropEvent* m_event; | 53 | QGraphicsSceneDragDropEvent* m_event; |
449 | 53 | DeclarativeMimeData m_mimeData; | 54 | DeclarativeMimeData m_mimeData; |
450 | 54 | }; | 55 | }; |
451 | 55 | 56 |