2023-11-05 05:14:39 +00:00
|
|
|
// SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org>
|
|
|
|
|
// SPDX-License-Identifier: LGPL-2.0-or-later
|
|
|
|
|
|
|
|
|
|
import QtQuick
|
|
|
|
|
|
2025-09-11 14:13:26 +00:00
|
|
|
import org.kde.kirigami as Kirigami
|
2026-05-21 09:13:36 +00:00
|
|
|
import org.kde.plasma.private.mobileshell as MobileShell
|
2025-09-11 14:13:26 +00:00
|
|
|
|
2023-11-05 05:14:39 +00:00
|
|
|
import '../delegate'
|
|
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
|
id: root
|
2023-11-14 04:21:57 +00:00
|
|
|
height: 10 + touchPadding * 2
|
|
|
|
|
width: 10 + touchPadding * 2
|
2023-11-05 05:14:39 +00:00
|
|
|
|
2023-11-14 04:21:57 +00:00
|
|
|
readonly property real touchPadding: 20
|
2026-05-21 09:13:36 +00:00
|
|
|
readonly property int pressAnimationDuration: MobileShell.Motion.duration(MobileShell.Motion.EffectsSlow)
|
|
|
|
|
readonly property color resizeHandleColor: Kirigami.Theme.highlightColor
|
2023-11-05 05:14:39 +00:00
|
|
|
|
|
|
|
|
property int orientation
|
|
|
|
|
|
|
|
|
|
signal dragEvent(real leftEdgeDelta, real rightEdgeDelta, real topEdgeDelta, real bottomEdgeDelta)
|
|
|
|
|
|
2023-11-14 04:21:57 +00:00
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
|
|
2023-11-05 05:14:39 +00:00
|
|
|
drag {
|
|
|
|
|
target: root
|
|
|
|
|
axis: {
|
|
|
|
|
switch (orientation) {
|
|
|
|
|
case WidgetHandlePosition.TopCenter:
|
|
|
|
|
return Drag.YAxis;
|
|
|
|
|
case WidgetHandlePosition.LeftCenter:
|
|
|
|
|
return Drag.XAxis;
|
|
|
|
|
case WidgetHandlePosition.RightCenter:
|
|
|
|
|
return Drag.XAxis;
|
|
|
|
|
case WidgetHandlePosition.BottomCenter:
|
|
|
|
|
return Drag.YAxis;
|
|
|
|
|
}
|
|
|
|
|
return Drag.XAndYAxis;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
property real pressX
|
|
|
|
|
property real pressY
|
|
|
|
|
|
|
|
|
|
onPressed: {
|
|
|
|
|
pressX = mouseX;
|
|
|
|
|
pressY = mouseY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onPositionChanged: {
|
|
|
|
|
// HACK: need to call it twice to work
|
|
|
|
|
updateDrag();
|
|
|
|
|
updateDrag();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drag { target: root; axis: Drag.XAndYAxis }
|
|
|
|
|
|
|
|
|
|
function updateDrag() {
|
|
|
|
|
if (!drag.active) return;
|
|
|
|
|
|
|
|
|
|
const dx = mouseX;
|
|
|
|
|
const dy = mouseY;
|
|
|
|
|
|
|
|
|
|
switch (orientation) {
|
|
|
|
|
case WidgetHandlePosition.TopCenter:
|
|
|
|
|
root.dragEvent(0, 0, -dy, 0);
|
|
|
|
|
break;
|
|
|
|
|
case WidgetHandlePosition.LeftCenter:
|
|
|
|
|
root.dragEvent(-dx, 0, 0, 0);
|
|
|
|
|
break;
|
|
|
|
|
case WidgetHandlePosition.RightCenter:
|
|
|
|
|
root.dragEvent(0, dx, 0, 0);
|
|
|
|
|
break;
|
|
|
|
|
case WidgetHandlePosition.BottomCenter:
|
|
|
|
|
root.dragEvent(0, 0, 0, dy);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Rectangle {
|
2023-11-14 04:21:57 +00:00
|
|
|
id: rect
|
2023-11-05 05:14:39 +00:00
|
|
|
anchors.fill: parent
|
2023-11-14 04:21:57 +00:00
|
|
|
anchors.margins: root.touchPadding
|
2026-05-21 09:13:36 +00:00
|
|
|
color: root.resizeHandleColor
|
2023-11-05 05:14:39 +00:00
|
|
|
radius: width / 2
|
|
|
|
|
|
|
|
|
|
transform: Scale {
|
2026-05-21 09:13:36 +00:00
|
|
|
property real scaleFactor: root.pressed ? MobileShell.Motion.pressScaleOut : 1.0
|
2023-11-05 05:14:39 +00:00
|
|
|
|
|
|
|
|
Behavior on scaleFactor {
|
2026-05-21 09:13:36 +00:00
|
|
|
MobileShell.MotionNumberAnimation { type: MobileShell.Motion.EffectsSlow; duration: root.pressAnimationDuration }
|
2023-11-05 05:14:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xScale: scaleFactor
|
|
|
|
|
yScale: scaleFactor
|
2023-11-14 04:21:57 +00:00
|
|
|
origin.x: rect.width / 2
|
|
|
|
|
origin.y: rect.height / 2
|
2023-11-05 05:14:39 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|