2021-03-18 14:07:33 +00:00
|
|
|
/*
|
|
|
|
|
* 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 {
|
2021-03-24 13:48:56 +00:00
|
|
|
id: root
|
2021-03-18 14:07:33 +00:00
|
|
|
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-18 14:07:33 +00:00
|
|
|
enum ScrollDirection {
|
|
|
|
|
None,
|
|
|
|
|
Horizontal,
|
|
|
|
|
Vertical
|
|
|
|
|
}
|
2021-03-18 17:27:18 +00:00
|
|
|
|
2021-03-18 14:07:33 +00:00
|
|
|
property real __initialMainFlickableX
|
|
|
|
|
property int __scrollDirection: DragGestureHandler.None
|
2021-03-18 17:27:18 +00:00
|
|
|
onTranslationChanged: {
|
2021-03-18 14:07:33 +00:00
|
|
|
if (active) {
|
2021-03-24 13:48:56 +00:00
|
|
|
if (root.appDrawer.offset > PlasmaCore.Units.gridUnit) {
|
2021-03-18 14:07:33 +00:00
|
|
|
__scrollDirection = DragGestureHandler.Vertical;
|
2021-03-18 17:27:18 +00:00
|
|
|
snapPage();
|
2021-03-18 14:07:33 +00:00
|
|
|
} else if (Math.abs(mainFlickable.contentX - __initialMainFlickableX) > PlasmaCore.Units.gridUnit) {
|
|
|
|
|
__scrollDirection = DragGestureHandler.Horizontal;
|
2021-03-24 13:48:56 +00:00
|
|
|
root.appDrawer.close();
|
2021-03-18 14:07:33 +00:00
|
|
|
}
|
2021-03-18 17:27:18 +00:00
|
|
|
|
2021-03-18 14:07:33 +00:00
|
|
|
if (__scrollDirection !== DragGestureHandler.Horizontal) {
|
2021-03-24 13:48:56 +00:00
|
|
|
root.appDrawer.offset = -translation.y;
|
2021-03-18 14:07:33 +00:00
|
|
|
}
|
|
|
|
|
if (__scrollDirection !== DragGestureHandler.Vertical) {
|
|
|
|
|
mainFlickable.contentX = Math.max(0, __initialMainFlickableX - translation.x);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
onActiveChanged: {
|
|
|
|
|
if (active) {
|
|
|
|
|
__initialMainFlickableX = mainFlickable.contentX;
|
|
|
|
|
} else {
|
2021-03-18 17:27:18 +00:00
|
|
|
__scrollDirection = DragGestureHandler.None;
|
2021-03-24 13:48:56 +00:00
|
|
|
root.appDrawer.snapDrawerStatus();
|
2021-03-18 17:27:18 +00:00
|
|
|
snapPage();
|
2021-03-18 14:07:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|