File: DraggableFileArea.qml

package info (click to toggle)
plasma-workspace 4%3A5.27.5-2%2Bdeb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 102,040 kB
  • sloc: cpp: 121,800; xml: 3,238; python: 645; perl: 586; sh: 254; javascript: 113; ruby: 62; makefile: 15; ansic: 13
file content (63 lines) | stat: -rw-r--r-- 1,729 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
    SPDX-FileCopyrightText: 2016, 2019 Kai Uwe Broulik <kde@privat.broulik.de>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

import QtQuick 2.8

import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.private.notifications 2.0 as Notifications

MouseArea {
    id: area

    signal activated
    signal contextMenuRequested(int x, int y)

    property Item dragParent
    property url dragUrl
    property var dragPixmap
    property int dragPixmapSize: PlasmaCore.Units.iconSizes.large

    readonly property bool dragging: Notifications.DragHelper.dragActive

    property int _pressX: -1
    property int _pressY: -1

    preventStealing: true
    cursorShape: pressed ? Qt.ClosedHandCursor : Qt.OpenHandCursor
    acceptedButtons: Qt.LeftButton | Qt.RightButton

    onClicked: {
        if (mouse.button === Qt.LeftButton) {
            area.activated();
        }
    }
    onPressed: {
        if (mouse.button === Qt.LeftButton) {
            _pressX = mouse.x;
            _pressY = mouse.y;
        } else if (mouse.button === Qt.RightButton) {
            area.contextMenuRequested(mouse.x, mouse.y);
        }
    }
    onPositionChanged: {
        if (_pressX !== -1 && _pressY !== -1 && Notifications.DragHelper.isDrag(_pressX, _pressY, mouse.x, mouse.y)) {
            Notifications.DragHelper.dragPixmapSize = area.dragPixmapSize;
            Notifications.DragHelper.startDrag(area.dragParent, area.dragUrl, area.dragPixmap);
            _pressX = -1;
            _pressY = -1;
        }
    }
    onReleased: {
        _pressX = -1;
        _pressY = -1;
    }
    onContainsMouseChanged: {
        if (!containsMouse) {
            _pressX = -1;
            _pressY = -1;
        }
    }
}