2022-06-18 20:47:41 +00:00
|
|
|
// SPDX-FileCopyrightText: 2021-2022 Devin Lin <devin@kde.org>
|
|
|
|
|
// SPDX-License-Identifier: LGPL-2.0-or-later
|
2022-02-12 05:19:44 +00:00
|
|
|
|
|
|
|
|
import QtQuick 2.15
|
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
|
|
2023-07-25 01:13:52 +00:00
|
|
|
import org.kde.kirigami 2.20 as Kirigami
|
2023-09-30 05:57:58 +00:00
|
|
|
import org.kde.plasma.private.mobileshell as MobileShell
|
2022-02-12 05:19:44 +00:00
|
|
|
|
2023-09-30 05:57:58 +00:00
|
|
|
MobileShell.SwipeArea {
|
2022-02-12 05:19:44 +00:00
|
|
|
id: root
|
2023-09-30 17:06:41 +00:00
|
|
|
mode: MobileShell.SwipeArea.VerticalOnly
|
2022-02-12 05:19:44 +00:00
|
|
|
|
|
|
|
|
property int position: 0
|
|
|
|
|
|
|
|
|
|
required property real keypadHeight
|
|
|
|
|
|
2022-06-18 20:47:41 +00:00
|
|
|
signal opened()
|
|
|
|
|
|
2022-02-12 05:19:44 +00:00
|
|
|
function cancelAnimations() {
|
|
|
|
|
positionAnim.stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function goToOpenPosition() {
|
|
|
|
|
positionAnim.to = keypadHeight;
|
|
|
|
|
positionAnim.restart();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function goToClosePosition() {
|
|
|
|
|
positionAnim.to = 0;
|
|
|
|
|
positionAnim.restart();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateState() {
|
2022-02-17 05:52:34 +00:00
|
|
|
// don't update state if at end
|
|
|
|
|
if (position <= 0 || position >= keypadHeight) return;
|
|
|
|
|
|
2022-02-12 05:19:44 +00:00
|
|
|
if (movingUp) {
|
|
|
|
|
goToOpenPosition();
|
|
|
|
|
} else {
|
|
|
|
|
goToClosePosition();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NumberAnimation on position {
|
|
|
|
|
id: positionAnim
|
2023-07-25 01:13:52 +00:00
|
|
|
duration: Kirigami.Units.veryLongDuration
|
2022-12-04 17:09:00 +00:00
|
|
|
easing.type: Easing.OutExpo
|
2022-06-18 20:47:41 +00:00
|
|
|
|
|
|
|
|
onFinished: {
|
|
|
|
|
if (root.position === keypadHeight) {
|
|
|
|
|
root.opened();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-12 05:19:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
property int oldPosition: position
|
|
|
|
|
property bool movingUp: false
|
|
|
|
|
|
|
|
|
|
onPositionChanged: {
|
|
|
|
|
movingUp = oldPosition <= position;
|
|
|
|
|
oldPosition = position;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-30 05:57:58 +00:00
|
|
|
onSwipeStarted: cancelAnimations();
|
|
|
|
|
onSwipeEnded: {
|
2022-02-12 05:19:44 +00:00
|
|
|
if (!positionAnim.running) {
|
|
|
|
|
updateState();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-30 05:57:58 +00:00
|
|
|
|
|
|
|
|
onSwipeMove: (totalDeltaX, totalDeltaY, deltaX, deltaY) => {
|
2023-10-22 03:59:27 +00:00
|
|
|
position = Math.max(0, Math.min(keypadHeight, position - deltaY));
|
2022-02-12 05:19:44 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|