mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-28 22:53:09 +00:00
snap for horizontal page scrolling
This commit is contained in:
parent
e4d297dd73
commit
9c080a2676
2 changed files with 25 additions and 52 deletions
|
|
@ -15,20 +15,26 @@ DragHandler {
|
|||
xAxis.enabled: enabled
|
||||
property Flickable mainFlickable
|
||||
property Launcher.AppDrawer appDrawer
|
||||
signal snapPage
|
||||
|
||||
enum ScrollDirection {
|
||||
None,
|
||||
Horizontal,
|
||||
Vertical
|
||||
}
|
||||
|
||||
property real __initialMainFlickableX
|
||||
property int __scrollDirection: DragGestureHandler.None
|
||||
onTranslationChanged: {print(translation.x)
|
||||
onTranslationChanged: {
|
||||
if (active) {
|
||||
if (appDrawer.offset > PlasmaCore.Units.gridUnit) {
|
||||
__scrollDirection = DragGestureHandler.Vertical;
|
||||
snapPage();
|
||||
} else if (Math.abs(mainFlickable.contentX - __initialMainFlickableX) > PlasmaCore.Units.gridUnit) {
|
||||
__scrollDirection = DragGestureHandler.Horizontal;
|
||||
appDrawer.close();
|
||||
}
|
||||
|
||||
if (__scrollDirection !== DragGestureHandler.Horizontal) {
|
||||
appDrawer.offset = -translation.y;
|
||||
}
|
||||
|
|
@ -41,7 +47,9 @@ DragHandler {
|
|||
if (active) {
|
||||
__initialMainFlickableX = mainFlickable.contentX;
|
||||
} else {
|
||||
__scrollDirection = DragGestureHandler.None;
|
||||
appDrawer.snapDrawerStatus();
|
||||
snapPage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,6 +67,12 @@ Item {
|
|||
plasmoid.nativeInterface.applicationListModel.maxFavoriteCount = Math.max(4, Math.floor(Math.min(width, height) / appletsLayout.cellWidth));
|
||||
}
|
||||
|
||||
function snapPage() {
|
||||
scrollAnim.running = false;
|
||||
scrollAnim.to = mainFlickable.width * Math.round(mainFlickable.contentX / mainFlickable.width)
|
||||
scrollAnim.running = true;
|
||||
}
|
||||
|
||||
//END functions
|
||||
|
||||
|
||||
|
|
@ -177,47 +183,14 @@ Item {
|
|||
onContentYChanged: MobileShell.HomeScreenControls.homeScreenPosition = contentY
|
||||
|
||||
LauncherPrivate.DragGestureHandler {
|
||||
id: gestureHandler
|
||||
target: appletsLayout
|
||||
appDrawer: appDrawer
|
||||
mainFlickable: mainFlickable
|
||||
enabled: root.focus && appDrawer.status !== Launcher.AppDrawer.Status.Open && !appletsLayout.editMode && !plasmoid.editMode && !launcherDragManager.active
|
||||
onSnapPage: root.snapPage();
|
||||
}
|
||||
/*
|
||||
DragHandler {
|
||||
target: mainFlickable
|
||||
yAxis.enabled: !appletsLayout.editMode && !plasmoid.editMode && !launcherDragManager.active
|
||||
xAxis.enabled: yAxis.enabled
|
||||
enabled: root.focus && appDrawer.status !== Launcher.AppDrawer.Status.Open
|
||||
property real initialMainFlickableX
|
||||
enum ScrollDirection {
|
||||
None,
|
||||
Horizontal,
|
||||
Vertical
|
||||
}
|
||||
property int scrollDirection: None
|
||||
onTranslationChanged: {print(translation.x)
|
||||
if (active) {
|
||||
if (appDrawer.offset > PlasmaCore.Units.gridUnit) {
|
||||
scrollDirection = Vertical;
|
||||
} else if (Math.abs(mainFlickable.contentX - initialMainFlickableX) > PlasmaCore.Units.gridUnit) {
|
||||
scrollDirection = Horizontal;
|
||||
}
|
||||
if (scrollDirection !== Horizontal) {
|
||||
appDrawer.offset = -translation.y;
|
||||
}
|
||||
if (scrollDirection !== Vertical) {
|
||||
mainFlickable.contentX = Math.max(0, initialMainFlickableX - translation.x);
|
||||
}
|
||||
}
|
||||
}
|
||||
onActiveChanged: {
|
||||
if (active) {
|
||||
initialMainFlickableX = mainFlickable.contentX;
|
||||
} else {
|
||||
appDrawer.snapDrawerStatus();
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
NumberAnimation {
|
||||
id: scrollAnim
|
||||
target: mainFlickable
|
||||
|
|
@ -326,7 +299,7 @@ Item {
|
|||
}
|
||||
|
||||
signal appletsLayoutInteracted
|
||||
onChildrenRectChanged: print("AAAAAA"+childrenRect.width)
|
||||
|
||||
TapHandler {
|
||||
target: mainFlickable
|
||||
enabled: appDrawer.status !== Launcher.AppDrawer.Status.Open
|
||||
|
|
@ -441,20 +414,12 @@ onChildrenRectChanged: print("AAAAAA"+childrenRect.width)
|
|||
}
|
||||
appletsLayout: appletsLayout
|
||||
|
||||
DragHandler {
|
||||
LauncherPrivate.DragGestureHandler {
|
||||
target: favoriteStrip
|
||||
yAxis.enabled: !appletsLayout.editMode
|
||||
enabled: root.focus && appDrawer.status !== Launcher.AppDrawer.Status.Open
|
||||
onTranslationChanged: {
|
||||
if (active) {
|
||||
appDrawer.offset = -translation.y
|
||||
}
|
||||
}
|
||||
onActiveChanged: {
|
||||
if (!active) {
|
||||
appDrawer.snapDrawerStatus();
|
||||
}
|
||||
}
|
||||
appDrawer: appDrawer
|
||||
mainFlickable: mainFlickable
|
||||
enabled: root.focus && appDrawer.status !== Launcher.AppDrawer.Status.Open && !appletsLayout.editMode && !plasmoid.editMode && !launcherDragManager.active
|
||||
onSnapPage: root.snapPage();
|
||||
}
|
||||
TapHandler {
|
||||
target: favoriteStrip
|
||||
|
|
|
|||
Loading…
Reference in a new issue