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