Changeset View
Changeset View
Standalone View
Standalone View
containments/desktop/package/contents/ui/FolderViewDropArea.qml
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2014-2017 by Eike Hein <hein@kde.org> * | ||||
3 | * * | ||||
4 | * This program is free software; you can redistribute it and/or modify * | ||||
5 | * it under the terms of the GNU General Public License as published by * | ||||
6 | * the Free Software Foundation; either version 2 of the License, or * | ||||
7 | * (at your option) any later version. * | ||||
8 | * * | ||||
9 | * This program is distributed in the hope that it will be useful, * | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||||
12 | * GNU General Public License for more details. * | ||||
13 | * * | ||||
14 | * You should have received a copy of the GNU General Public License * | ||||
15 | * along with this program; if not, write to the * | ||||
16 | * Free Software Foundation, Inc., * | ||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * | ||||
18 | ***************************************************************************/ | ||||
19 | | ||||
20 | import QtQuick 2.4 | ||||
21 | | ||||
22 | import org.kde.draganddrop 2.0 as DragDrop | ||||
23 | | ||||
24 | DragDrop.DropArea { | ||||
25 | id: dropArea | ||||
26 | | ||||
27 | property Item folderView: null | ||||
28 | | ||||
29 | function handleDragMove(folderView, event) { | ||||
30 | // Trigger autoscroll. | ||||
31 | folderView.scrollLeft = (event.x < (units.largeSpacing * 3)); | ||||
32 | folderView.scrollRight = (event.x > width - (units.largeSpacing * 3)); | ||||
33 | folderView.scrollUp = (event.y < (units.largeSpacing * 3)); | ||||
34 | folderView.scrollDown = (event.y > height - (units.largeSpacing * 3)); | ||||
35 | | ||||
36 | // Set hovered item. | ||||
37 | folderView.hoveredItem = folderView.itemAt(event.x, event.y); | ||||
38 | } | ||||
39 | | ||||
40 | function handleDragEnd(folderView) { | ||||
41 | // Cancel autoscroll. | ||||
42 | folderView.scrollLeft = false; | ||||
43 | folderView.scrollRight = false; | ||||
44 | folderView.scrollUp = false; | ||||
45 | folderView.scrollDown = false; | ||||
46 | | ||||
47 | // Unset hovered item. | ||||
48 | if (folderView.hoveredItem && !folderView.hoveredItem.popupDialog) { | ||||
49 | folderView.hoveredItem = null; | ||||
50 | } | ||||
51 | } | ||||
52 | | ||||
53 | onDragMove: { | ||||
54 | // TODO: We should reject drag moves onto file items that don't accept drops | ||||
55 | // (cf. QAbstractItemModel::flags() here, but DeclarativeDropArea currently | ||||
56 | // is currently incapable of rejecting drag events. | ||||
57 | | ||||
58 | if (folderView) { | ||||
59 | handleDragMove(folderView, event); | ||||
60 | } | ||||
61 | } | ||||
62 | | ||||
63 | onDragLeave: { | ||||
64 | if (folderView) { | ||||
65 | handleDragEnd(folderView); | ||||
66 | } | ||||
67 | } | ||||
68 | | ||||
69 | onDrop: { | ||||
70 | if (folderView) { | ||||
71 | handleDragEnd(folderView); | ||||
72 | | ||||
73 | folderView.drop(folderView, event, mapToItem(folderView, event.x, event.y)); | ||||
74 | } | ||||
75 | } | ||||
76 | } |