Changeset View
Changeset View
Standalone View
Standalone View
applets/notifications/package/contents/ui/DraggableFileArea.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2016,2019 Kai Uwe Broulik <kde@privat.broulik.de> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU Library General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2, 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 Library General Public License for more details | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Library General Public | ||||
15 | * License 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.8 | ||||
21 | | ||||
22 | MouseArea { | ||||
23 | id: area | ||||
24 | | ||||
25 | signal activated | ||||
26 | signal contextMenuRequested(int x, int y) | ||||
27 | | ||||
28 | property Item dragParent | ||||
29 | property url dragUrl | ||||
30 | property var dragPixmap | ||||
31 | | ||||
32 | readonly property bool dragging: plasmoid.nativeInterface.dragActive | ||||
33 | | ||||
34 | property int _pressX: -1 | ||||
35 | property int _pressY: -1 | ||||
36 | | ||||
37 | preventStealing: true | ||||
38 | cursorShape: pressed ? Qt.ClosedHandCursor : Qt.OpenHandCursor | ||||
39 | acceptedButtons: Qt.LeftButton | Qt.RightButton | ||||
40 | | ||||
41 | onClicked: { | ||||
42 | if (mouse.button === Qt.LeftButton) { | ||||
43 | area.activated(); | ||||
44 | } | ||||
45 | } | ||||
46 | onPressed: { | ||||
47 | if (mouse.button === Qt.LeftButton) { | ||||
48 | _pressX = mouse.x; | ||||
49 | _pressY = mouse.y; | ||||
50 | } else if (mouse.button === Qt.RightButton) { | ||||
51 | area.contextMenuRequested(mouse.x, mouse.y); | ||||
52 | } | ||||
53 | } | ||||
54 | onPositionChanged: { | ||||
55 | if (_pressX !== -1 && _pressY !== -1 && plasmoid.nativeInterface.isDrag(_pressX, _pressY, mouse.x, mouse.y)) { | ||||
56 | plasmoid.nativeInterface.startDrag(area.dragParent, area.dragUrl, area.dragPixmap); | ||||
57 | _pressX = -1; | ||||
58 | _pressY = -1; | ||||
59 | } | ||||
60 | } | ||||
61 | onReleased: { | ||||
62 | _pressX = -1; | ||||
63 | _pressY = -1; | ||||
64 | } | ||||
65 | onContainsMouseChanged: { | ||||
66 | if (!containsMouse) { | ||||
67 | _pressX = -1; | ||||
68 | _pressY = -1; | ||||
69 | } | ||||
70 | } | ||||
71 | } |