shift-shell/components/mobilehomescreencomponents/qml/private/DragGestureHandler.qml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

89 lines
3 KiB
QML
Raw Normal View History

/*
* SPDX-FileCopyrightText: 2021 Marco Martin <mart@kde.org>
*
* SPDX-License-Identifier: LGPL-2.0-or-later
*/
import QtQuick 2.14
import org.kde.plasma.core 2.0 as PlasmaCore
import ".." as Launcher
DragHandler {
id: root
yAxis.enabled: enabled
xAxis.enabled: enabled
property Flickable mainFlickable
property Launcher.AppDrawer appDrawer
2021-03-18 17:27:18 +00:00
signal snapPage
2021-03-25 16:04:59 +00:00
signal snapNextPage
signal snapPrevPage
2021-03-18 17:27:18 +00:00
enum ScrollDirection {
None,
2021-03-25 16:04:59 +00:00
Left,
Right,
Vertical
}
2021-03-18 17:27:18 +00:00
property real __initialMainFlickableX
property int __scrollDirection: DragGestureHandler.None
2021-03-18 17:27:18 +00:00
onTranslationChanged: {
if (active) {
if (root.appDrawer) {
if (__scrollDirection === DragGestureHandler.None) {
if (root.appDrawer.offset > PlasmaCore.Units.gridUnit) {
__scrollDirection = DragGestureHandler.Vertical;
snapPage();
} else if (mainFlickable.contentX - __initialMainFlickableX > PlasmaCore.Units.gridUnit) {
__scrollDirection = DragGestureHandler.Right;
root.appDrawer.close();
} else if (__initialMainFlickableX - mainFlickable.contentX > PlasmaCore.Units.gridUnit) {
__scrollDirection = DragGestureHandler.Left;
root.appDrawer.close();
}
}
2021-03-18 17:27:18 +00:00
if (__scrollDirection !== DragGestureHandler.Left && __scrollDirection !== DragGestureHandler.Right) {
root.appDrawer.offset = -translation.y;
}
}
if (__scrollDirection !== DragGestureHandler.Vertical) {
2021-03-25 16:04:59 +00:00
let newContentX = Math.min((mainFlickable.width * mainFlickable.totalPages) - mainFlickable.width, Math.max(0, __initialMainFlickableX - translation.x));
if (__scrollDirection !== DragGestureHandler.None) {
if (mainFlickable.contentX < newContentX) {
__scrollDirection = DragGestureHandler.Right;
} else {
__scrollDirection = DragGestureHandler.Left;
}
2021-03-25 16:04:59 +00:00
}
mainFlickable.contentX = newContentX;
}
}
}
onActiveChanged: {
if (active) {
__initialMainFlickableX = mainFlickable.contentX;
} else {
if (root.appDrawer) {
root.appDrawer.snapDrawerStatus();
}
2021-03-25 16:04:59 +00:00
if (__scrollDirection === DragGestureHandler.Left && (__initialMainFlickableX - mainFlickable.contentX > PlasmaCore.Units.gridUnit * 5)) {
snapPrevPage();
} else if (__scrollDirection === DragGestureHandler.Right && (mainFlickable.contentX - __initialMainFlickableX > PlasmaCore.Units.gridUnit * 5)) {
snapNextPage();
2021-04-08 15:36:23 +00:00
} else {
2021-03-25 16:04:59 +00:00
snapPage();
}
__scrollDirection = DragGestureHandler.None;
}
}
}