mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-29 15:03:09 +00:00
actiondrawer: Port from Flickable to SwipeArea
This commit is contained in:
parent
2d37ef0771
commit
911d41e5ce
2 changed files with 20 additions and 63 deletions
|
|
@ -113,9 +113,9 @@ Item {
|
|||
signal runPendingNotificationAction()
|
||||
|
||||
onOpenedChanged: {
|
||||
if (opened) flickable.focus = true;
|
||||
if (opened) swipeArea.focus = true;
|
||||
}
|
||||
|
||||
|
||||
property real oldOffset
|
||||
onOffsetChanged: {
|
||||
if (offset < 0) {
|
||||
|
|
@ -129,7 +129,7 @@ Item {
|
|||
oldOffset = offset;
|
||||
|
||||
// close panel immediately after panel is not shown, and the flickable is not being dragged
|
||||
if (opened && root.offset <= 0 && !flickable.dragging && !closeAnim.running && !openAnim.running) {
|
||||
if (opened && root.offset <= 0 && !swipeArea.moving && !closeAnim.running && !openAnim.running) {
|
||||
root.updateState();
|
||||
focus = false;
|
||||
}
|
||||
|
|
@ -229,68 +229,29 @@ Item {
|
|||
onFinished: root.opened = true;
|
||||
}
|
||||
|
||||
Components.Flickable {
|
||||
id: flickable
|
||||
MobileShell.SwipeArea {
|
||||
id: swipeArea
|
||||
anchors.fill: parent
|
||||
|
||||
contentWidth: root.width
|
||||
contentHeight: root.height + 999999
|
||||
contentY: contentHeight / 2
|
||||
|
||||
// if the recent root.offset change was due to this flickable
|
||||
property bool offsetChangedDueToContentY: false
|
||||
Connections {
|
||||
target: root
|
||||
function onOffsetChanged() {
|
||||
if (!flickable.offsetChangedDueToContentY) {
|
||||
// ensure the flickable's contentY is not moving when other sources change root.offset
|
||||
flickable.cancelFlick();
|
||||
}
|
||||
flickable.offsetChangedDueToContentY = false;
|
||||
}
|
||||
}
|
||||
|
||||
property real oldContentY
|
||||
onContentYChanged: {
|
||||
offsetChangedDueToContentY = true;
|
||||
root.offset += oldContentY - contentY;
|
||||
oldContentY = contentY;
|
||||
}
|
||||
|
||||
onMovementStarted: {
|
||||
|
||||
onSwipeStarted: {
|
||||
root.cancelAnimations();
|
||||
root.dragging = true;
|
||||
}
|
||||
onFlickStarted: root.dragging = true;
|
||||
onMovementEnded: {
|
||||
onSwipeEnded: {
|
||||
root.dragging = false;
|
||||
root.updateState();
|
||||
}
|
||||
onFlickEnded: {
|
||||
root.dragging = true;
|
||||
root.updateState();
|
||||
onSwipeMove: (totalDeltaX, totalDeltaY, deltaX, deltaY) => {
|
||||
root.offset += deltaY;
|
||||
}
|
||||
|
||||
onDraggingChanged: {
|
||||
if (!dragging) {
|
||||
root.dragging = false;
|
||||
flickable.cancelFlick();
|
||||
root.updateState();
|
||||
}
|
||||
}
|
||||
|
||||
// the flickable is only used to measure drag changes, we implement our own UI component movements
|
||||
// the root element is not affected by contentY changes (it's effectively anchored to the flickable)
|
||||
|
||||
Loader {
|
||||
id: contentContainerLoader
|
||||
anchors.fill: parent
|
||||
|
||||
property real minimizedQuickSettingsOffset: item ? item.minimizedQuickSettingsOffset : 0
|
||||
property real maximizedQuickSettingsOffset: item ? item.maximizedQuickSettingsOffset : 0
|
||||
|
||||
y: flickable.contentY
|
||||
width: root.width
|
||||
height: root.height
|
||||
|
||||
asynchronous: true
|
||||
sourceComponent: root.mode == ActionDrawer.Portrait ? portraitContentContainer : landscapeContentContainer
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,11 +7,12 @@
|
|||
import QtQuick 2.15
|
||||
|
||||
import org.kde.plasma.private.mobileshell.shellsettingsplugin as ShellSettings
|
||||
import org.kde.plasma.private.mobileshell as MobileShell
|
||||
|
||||
/**
|
||||
* Component that triggers the opening and closing of an ActionDrawer when dragged on with touch or mouse.
|
||||
*/
|
||||
MouseArea {
|
||||
MobileShell.SwipeArea {
|
||||
id: root
|
||||
|
||||
required property ActionDrawer actionDrawer
|
||||
|
|
@ -43,22 +44,17 @@ MouseArea {
|
|||
}
|
||||
|
||||
anchors.fill: parent
|
||||
onPressed: mouse => {
|
||||
oldMouseY = mouse.y;
|
||||
|
||||
|
||||
onSwipeStarted: (point) => {
|
||||
// if the user swiped from the top left, otherwise it's from the top right
|
||||
if (mouse.x < root.width / 2) {
|
||||
if (point.x < root.width / 2) {
|
||||
actionDrawer.openToPinnedMode = ShellSettings.Settings.actionDrawerTopLeftMode == ShellSettings.Settings.Pinned;
|
||||
} else {
|
||||
actionDrawer.openToPinnedMode = ShellSettings.Settings.actionDrawerTopRightMode == ShellSettings.Settings.Pinned;
|
||||
}
|
||||
|
||||
|
||||
startSwipe();
|
||||
}
|
||||
onReleased: endSwipe()
|
||||
onCanceled: endSwipe()
|
||||
onPositionChanged: mouse => {
|
||||
updateOffset(mouse.y - oldMouseY);
|
||||
oldMouseY = mouse.y;
|
||||
}
|
||||
onSwipeEnded: endSwipe()
|
||||
onSwipeMove: (totalDeltaX, totalDeltaY, deltaX, deltaY) => updateOffset(deltaY);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue