mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-08-02 01:34:46 +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()
|
signal runPendingNotificationAction()
|
||||||
|
|
||||||
onOpenedChanged: {
|
onOpenedChanged: {
|
||||||
if (opened) flickable.focus = true;
|
if (opened) swipeArea.focus = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
property real oldOffset
|
property real oldOffset
|
||||||
onOffsetChanged: {
|
onOffsetChanged: {
|
||||||
if (offset < 0) {
|
if (offset < 0) {
|
||||||
|
|
@ -129,7 +129,7 @@ Item {
|
||||||
oldOffset = offset;
|
oldOffset = offset;
|
||||||
|
|
||||||
// close panel immediately after panel is not shown, and the flickable is not being dragged
|
// 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();
|
root.updateState();
|
||||||
focus = false;
|
focus = false;
|
||||||
}
|
}
|
||||||
|
|
@ -229,68 +229,29 @@ Item {
|
||||||
onFinished: root.opened = true;
|
onFinished: root.opened = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Components.Flickable {
|
MobileShell.SwipeArea {
|
||||||
id: flickable
|
id: swipeArea
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
contentWidth: root.width
|
onSwipeStarted: {
|
||||||
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: {
|
|
||||||
root.cancelAnimations();
|
root.cancelAnimations();
|
||||||
root.dragging = true;
|
root.dragging = true;
|
||||||
}
|
}
|
||||||
onFlickStarted: root.dragging = true;
|
onSwipeEnded: {
|
||||||
onMovementEnded: {
|
|
||||||
root.dragging = false;
|
root.dragging = false;
|
||||||
root.updateState();
|
root.updateState();
|
||||||
}
|
}
|
||||||
onFlickEnded: {
|
onSwipeMove: (totalDeltaX, totalDeltaY, deltaX, deltaY) => {
|
||||||
root.dragging = true;
|
root.offset += deltaY;
|
||||||
root.updateState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
Loader {
|
||||||
id: contentContainerLoader
|
id: contentContainerLoader
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
property real minimizedQuickSettingsOffset: item ? item.minimizedQuickSettingsOffset : 0
|
property real minimizedQuickSettingsOffset: item ? item.minimizedQuickSettingsOffset : 0
|
||||||
property real maximizedQuickSettingsOffset: item ? item.maximizedQuickSettingsOffset : 0
|
property real maximizedQuickSettingsOffset: item ? item.maximizedQuickSettingsOffset : 0
|
||||||
|
|
||||||
y: flickable.contentY
|
|
||||||
width: root.width
|
|
||||||
height: root.height
|
|
||||||
|
|
||||||
asynchronous: true
|
asynchronous: true
|
||||||
sourceComponent: root.mode == ActionDrawer.Portrait ? portraitContentContainer : landscapeContentContainer
|
sourceComponent: root.mode == ActionDrawer.Portrait ? portraitContentContainer : landscapeContentContainer
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,12 @@
|
||||||
import QtQuick 2.15
|
import QtQuick 2.15
|
||||||
|
|
||||||
import org.kde.plasma.private.mobileshell.shellsettingsplugin as ShellSettings
|
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.
|
* Component that triggers the opening and closing of an ActionDrawer when dragged on with touch or mouse.
|
||||||
*/
|
*/
|
||||||
MouseArea {
|
MobileShell.SwipeArea {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
required property ActionDrawer actionDrawer
|
required property ActionDrawer actionDrawer
|
||||||
|
|
@ -43,22 +44,17 @@ MouseArea {
|
||||||
}
|
}
|
||||||
|
|
||||||
anchors.fill: parent
|
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 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;
|
actionDrawer.openToPinnedMode = ShellSettings.Settings.actionDrawerTopLeftMode == ShellSettings.Settings.Pinned;
|
||||||
} else {
|
} else {
|
||||||
actionDrawer.openToPinnedMode = ShellSettings.Settings.actionDrawerTopRightMode == ShellSettings.Settings.Pinned;
|
actionDrawer.openToPinnedMode = ShellSettings.Settings.actionDrawerTopRightMode == ShellSettings.Settings.Pinned;
|
||||||
}
|
}
|
||||||
|
|
||||||
startSwipe();
|
startSwipe();
|
||||||
}
|
}
|
||||||
onReleased: endSwipe()
|
onSwipeEnded: endSwipe()
|
||||||
onCanceled: endSwipe()
|
onSwipeMove: (totalDeltaX, totalDeltaY, deltaX, deltaY) => updateOffset(deltaY);
|
||||||
onPositionChanged: mouse => {
|
|
||||||
updateOffset(mouse.y - oldMouseY);
|
|
||||||
oldMouseY = mouse.y;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue