Warning, /plasma/plasma-mobile/look-and-feel/contents/lockscreen/FlickContainer.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2021-2022 Devin Lin <devin@kde.org>
0002 // SPDX-License-Identifier: LGPL-2.0-or-later
0003 
0004 import QtQuick 2.15
0005 import QtQuick.Layouts 1.15
0006 
0007 import org.kde.plasma.core 2.1 as PlasmaCore
0008 
0009 Flickable {
0010     id: root
0011     
0012     property int position: 0
0013     
0014     required property real keypadHeight
0015     
0016     signal opened()
0017     
0018     function cancelAnimations() {
0019         positionAnim.stop();
0020     }
0021     
0022     function goToOpenPosition() {
0023         positionAnim.to = keypadHeight;
0024         positionAnim.restart();
0025     }
0026     
0027     function goToClosePosition() {
0028         positionAnim.to = 0;
0029         positionAnim.restart();
0030     }
0031     
0032     function updateState() {
0033         // don't update state if at end
0034         if (position <= 0 || position >= keypadHeight) return;
0035         
0036         if (movingUp) {
0037             goToOpenPosition();
0038         } else {
0039             goToClosePosition();
0040         }
0041     }
0042     
0043     NumberAnimation on position {
0044         id: positionAnim
0045         duration: PlasmaCore.Units.veryLongDuration
0046         easing.type: Easing.OutExpo
0047         
0048         onFinished: {
0049             if (root.position === keypadHeight) {
0050                 root.opened();
0051             }
0052         }
0053     }
0054     
0055     // we use flickable solely for capturing flicks, not positioning elements
0056     contentWidth: width
0057     contentHeight: height * 2
0058     contentX: 0
0059     contentY: startContentY
0060     
0061     readonly property real startContentY: contentHeight / 2
0062     
0063     property int oldPosition: position
0064     property bool movingUp: false 
0065     
0066     onPositionChanged: {
0067         movingUp = oldPosition <= position;
0068         oldPosition = position;
0069     }
0070     
0071     // update position from flickable movement
0072     property real oldContentY
0073     onContentYChanged: {
0074         position = Math.max(0, Math.min(keypadHeight, position + (contentY - oldContentY)));
0075         oldContentY = contentY;
0076     }
0077     
0078     onMovementStarted: cancelAnimations();
0079     onMovementEnded: {
0080         if (!positionAnim.running) {
0081             updateState();
0082         }
0083         resetPosition();
0084     }
0085     
0086     onFlickStarted: root.cancelFlick()
0087     onFlickEnded: resetPosition();
0088     
0089     onDraggingChanged: {
0090         if (!dragging) {
0091             resetPosition();
0092             if (!positionAnim.running) {
0093                 root.updateState();
0094             }
0095         } else {
0096             cancelAnimations();
0097         }
0098     }
0099     
0100     function resetPosition() {
0101         oldContentY = startContentY;
0102         contentY = startContentY;
0103     }
0104 }
0105 
0106