mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-08-03 10:14:45 +00:00
homescreen: Add swipe down panel gesture
This commit is contained in:
parent
0100d26024
commit
25e0f99f43
4 changed files with 72 additions and 22 deletions
|
|
@ -8,6 +8,7 @@
|
||||||
import QtQuick 2.14
|
import QtQuick 2.14
|
||||||
|
|
||||||
import org.kde.plasma.core 2.0 as PlasmaCore
|
import org.kde.plasma.core 2.0 as PlasmaCore
|
||||||
|
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
|
||||||
|
|
||||||
import ".." as Launcher
|
import ".." as Launcher
|
||||||
|
|
||||||
|
|
@ -29,6 +30,7 @@ DragHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
property real __initialMainFlickableX
|
property real __initialMainFlickableX
|
||||||
|
property real __oldTranslationY: 0
|
||||||
property int __scrollDirection: DragGestureHandler.None
|
property int __scrollDirection: DragGestureHandler.None
|
||||||
onTranslationChanged: {
|
onTranslationChanged: {
|
||||||
if (active) {
|
if (active) {
|
||||||
|
|
@ -50,7 +52,20 @@ DragHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (__scrollDirection !== DragGestureHandler.Left && __scrollDirection !== DragGestureHandler.Right) {
|
if (__scrollDirection !== DragGestureHandler.Left && __scrollDirection !== DragGestureHandler.Right) {
|
||||||
|
// if swipe up, scroll app drawer
|
||||||
root.appDrawer.flickable.contentY = Math.min(root.appDrawer.drawerTopMargin, Math.max(0, -translation.y));
|
root.appDrawer.flickable.contentY = Math.min(root.appDrawer.drawerTopMargin, Math.max(0, -translation.y));
|
||||||
|
|
||||||
|
if (translation.y < 0 && MobileShell.TopPanelControls.inSwipe) {
|
||||||
|
MobileShell.TopPanelControls.endSwipe();
|
||||||
|
}
|
||||||
|
|
||||||
|
// if swipe down, scroll top panel
|
||||||
|
if (translation.y > 0) {
|
||||||
|
if (!MobileShell.TopPanelControls.inSwipe) {
|
||||||
|
MobileShell.TopPanelControls.startSwipe();
|
||||||
|
}
|
||||||
|
MobileShell.TopPanelControls.requestRelativeScroll(translation.y - __oldTranslationY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (__scrollDirection !== DragGestureHandler.Vertical) {
|
if (__scrollDirection !== DragGestureHandler.Vertical) {
|
||||||
|
|
@ -67,7 +82,10 @@ DragHandler {
|
||||||
mainFlickable.contentX = newContentX;
|
mainFlickable.contentX = newContentX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__oldTranslationY = translation.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
onActiveChanged: {
|
onActiveChanged: {
|
||||||
if (active) {
|
if (active) {
|
||||||
__initialMainFlickableX = mainFlickable.contentX;
|
__initialMainFlickableX = mainFlickable.contentX;
|
||||||
|
|
@ -75,6 +93,9 @@ DragHandler {
|
||||||
if (root.appDrawer) {
|
if (root.appDrawer) {
|
||||||
root.appDrawer.snapDrawerStatus();
|
root.appDrawer.snapDrawerStatus();
|
||||||
}
|
}
|
||||||
|
if (MobileShell.TopPanelControls.inSwipe) {
|
||||||
|
MobileShell.TopPanelControls.endSwipe();
|
||||||
|
}
|
||||||
if (__scrollDirection === DragGestureHandler.Left && (__initialMainFlickableX - mainFlickable.contentX > PlasmaCore.Units.gridUnit * 5)) {
|
if (__scrollDirection === DragGestureHandler.Left && (__initialMainFlickableX - mainFlickable.contentX > PlasmaCore.Units.gridUnit * 5)) {
|
||||||
snapPrevPage();
|
snapPrevPage();
|
||||||
} else if (__scrollDirection === DragGestureHandler.Right && (mainFlickable.contentX - __initialMainFlickableX > PlasmaCore.Units.gridUnit * 5)) {
|
} else if (__scrollDirection === DragGestureHandler.Right && (mainFlickable.contentX - __initialMainFlickableX > PlasmaCore.Units.gridUnit * 5)) {
|
||||||
|
|
|
||||||
|
|
@ -11,5 +11,10 @@ pragma Singleton
|
||||||
|
|
||||||
QtObject {
|
QtObject {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
|
signal startSwipe()
|
||||||
|
signal endSwipe()
|
||||||
|
signal requestRelativeScroll(real offsetY)
|
||||||
|
property bool inSwipe: false
|
||||||
property real panelHeight: PlasmaCore.Units.gridUnit // set and updated in panel containment
|
property real panelHeight: PlasmaCore.Units.gridUnit // set and updated in panel containment
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ FocusScope {
|
||||||
|
|
||||||
//END functions
|
//END functions
|
||||||
|
|
||||||
// implement API signals
|
//BEGIN API implementation
|
||||||
Connections {
|
Connections {
|
||||||
target: MobileShell.HomeScreenControls
|
target: MobileShell.HomeScreenControls
|
||||||
|
|
||||||
|
|
@ -60,6 +60,7 @@ FocusScope {
|
||||||
lastRequestedPosition = pos.y;
|
lastRequestedPosition = pos.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//END API implementation
|
||||||
|
|
||||||
property bool componentComplete: false
|
property bool componentComplete: false
|
||||||
onWidthChanged: recalculateMaxFavoriteCount()
|
onWidthChanged: recalculateMaxFavoriteCount()
|
||||||
|
|
|
||||||
|
|
@ -34,19 +34,34 @@ Item {
|
||||||
width: 480
|
width: 480
|
||||||
height: PlasmaCore.Units.gridUnit
|
height: PlasmaCore.Units.gridUnit
|
||||||
|
|
||||||
// set height binding to top panel API
|
//BEGIN API implementation
|
||||||
Binding {
|
|
||||||
target: MobileShell.TopPanelControls
|
|
||||||
property: "panelHeight"
|
|
||||||
value: root.height
|
|
||||||
}
|
|
||||||
|
|
||||||
// set height binding to top panel API
|
|
||||||
Binding {
|
Binding {
|
||||||
target: MobileShell.TopPanelControls
|
target: MobileShell.TopPanelControls
|
||||||
property: "panelHeight"
|
property: "panelHeight"
|
||||||
value: root.height
|
value: root.height
|
||||||
}
|
}
|
||||||
|
Binding {
|
||||||
|
target: MobileShell.TopPanelControls
|
||||||
|
property: "inSwipe"
|
||||||
|
value: slidingPanel.userInteracting
|
||||||
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: MobileShell.TopPanelControls
|
||||||
|
|
||||||
|
function onStartSwipe() {
|
||||||
|
swipeMouseArea.startSwipe(0);
|
||||||
|
}
|
||||||
|
function onEndSwipe() {
|
||||||
|
swipeMouseArea.endSwipe();
|
||||||
|
}
|
||||||
|
function onRequestRelativeScroll(offsetY) {
|
||||||
|
swipeMouseArea.updateOffset(offsetY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//END API implementation
|
||||||
|
|
||||||
Plasmoid.backgroundHints: showingApp ? PlasmaCore.Types.StandardBackground : PlasmaCore.Types.NoBackground
|
Plasmoid.backgroundHints: showingApp ? PlasmaCore.Types.StandardBackground : PlasmaCore.Types.NoBackground
|
||||||
|
|
||||||
|
|
@ -196,31 +211,39 @@ Item {
|
||||||
showDropShadow: !showingApp
|
showDropShadow: !showingApp
|
||||||
}
|
}
|
||||||
|
|
||||||
// initial swipe down
|
// initial swipe down gesture
|
||||||
MouseArea {
|
MouseArea {
|
||||||
|
id: swipeMouseArea
|
||||||
z: 99
|
z: 99
|
||||||
property int oldMouseY: 0
|
property int oldMouseY: 0
|
||||||
|
|
||||||
anchors.fill: parent
|
function startSwipe(mouseX) {
|
||||||
onPressed: {
|
|
||||||
slidingPanel.cancelAnimations();
|
slidingPanel.cancelAnimations();
|
||||||
slidingPanel.drawerX = Math.min(Math.max(0, mouse.x - slidingPanel.drawerWidth/2), slidingPanel.width - slidingPanel.contentItem.width)
|
slidingPanel.drawerX = Math.min(Math.max(0, mouseX - slidingPanel.drawerWidth/2), slidingPanel.width - slidingPanel.contentItem.width)
|
||||||
slidingPanel.userInteracting = true;
|
slidingPanel.userInteracting = true;
|
||||||
slidingPanel.flickable.contentY = slidingPanel.closedContentY;
|
slidingPanel.flickable.contentY = slidingPanel.closedContentY;
|
||||||
oldMouseY = mouse.y;
|
|
||||||
slidingPanel.visible = true;
|
slidingPanel.visible = true;
|
||||||
}
|
}
|
||||||
onPositionChanged: {
|
|
||||||
slidingPanel.updateOffset(mouse.y - oldMouseY);
|
function endSwipe() {
|
||||||
|
slidingPanel.userInteracting = false;
|
||||||
|
slidingPanel.updateState();
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateOffset(offsetY) {
|
||||||
|
slidingPanel.updateOffset(offsetY);
|
||||||
|
}
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
onPressed: {
|
||||||
oldMouseY = mouse.y;
|
oldMouseY = mouse.y;
|
||||||
|
startSwipe(mouse.x);
|
||||||
}
|
}
|
||||||
onReleased: {
|
onReleased: endSwipe()
|
||||||
slidingPanel.userInteracting = false;
|
onCanceled: endSwipe()
|
||||||
slidingPanel.updateState();
|
onPositionChanged: {
|
||||||
}
|
updateOffset(mouse.y - oldMouseY);
|
||||||
onCanceled: {
|
oldMouseY = mouse.y;
|
||||||
slidingPanel.userInteracting = false;
|
|
||||||
slidingPanel.updateState();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue