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;
}
}
}
|