fix logic for open/close top panel

This commit is contained in:
Marco Martin 2020-08-20 11:44:56 +02:00
parent 0998bcfa27
commit 5be8125c62
2 changed files with 28 additions and 5 deletions

View file

@ -45,18 +45,33 @@ NanoShell.FullScreenOverlay {
//width: Screen.width //width: Screen.width
//height: Screen.height //height: Screen.height
enum MovementDirection {
None = 0,
Up,
Down
}
property int direction: SlidingPanel.MovementDirection.None
function open() { function open() {
window.showFullScreen(); window.showFullScreen();
open.running = true; openAnim.restart();
} }
function close() { function close() {
closeAnim.running = true; closeAnim.restart();
} }
function updateState() { function updateState() {
if (window.direction === SlidingPanel.MovementDirection.None) {
if (offset < openThreshold) { if (offset < openThreshold) {
close(); close();
} else { } else {
openAnim.running = true; openAnim.restart();
}
} else if (offset > openThreshold && window.direction === SlidingPanel.MovementDirection.Down) {
openAnim.restart();
} else if (mainFlickable.contentY > openThreshold) {
close();
} else {
openAnim.restart();
} }
} }
Timer { Timer {
@ -163,8 +178,15 @@ NanoShell.FullScreenOverlay {
} }
//no loop as those 2 values compute to exactly the same //no loop as those 2 values compute to exactly the same
onContentYChanged: { onContentYChanged: {
window.offset = -contentY + contentArea.height if (contentY === oldContentY) {
window.direction = SlidingPanel.MovementDirection.None;
} else {
window.direction = contentY > oldContentY ? SlidingPanel.MovementDirection.Up : SlidingPanel.MovementDirection.Down;
} }
window.offset = -contentY + contentArea.height
oldContentY = contentY;
}
property real oldContentY
boundsBehavior: Flickable.StopAtBounds boundsBehavior: Flickable.StopAtBounds
contentWidth: window.width contentWidth: window.width
contentHeight: window.height*2 contentHeight: window.height*2

View file

@ -262,6 +262,7 @@ Item {
} }
onPositionChanged: { onPositionChanged: {
slidingPanel.offset = Math.min(slidingPanel.contentItem.height, slidingPanel.offset + (mouse.y - oldMouseY)); slidingPanel.offset = Math.min(slidingPanel.contentItem.height, slidingPanel.offset + (mouse.y - oldMouseY));
oldMouseY = mouse.y; oldMouseY = mouse.y;
} }
onReleased: { onReleased: {
@ -274,7 +275,7 @@ Item {
id: slidingPanel id: slidingPanel
width: plasmoid.availableScreenRect.width width: plasmoid.availableScreenRect.width
height: plasmoid.availableScreenRect.height height: plasmoid.availableScreenRect.height
openThreshold: units.gridUnit * 10 openThreshold: units.gridUnit * 2
headerHeight: root.height headerHeight: root.height
onClosed: quickSettings.closed() onClosed: quickSettings.closed()