mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-29 15:03: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
|
xAxis.enabled: enabled
|
||||||
property Flickable mainFlickable
|
property Flickable mainFlickable
|
||||||
property Launcher.AppDrawer appDrawer
|
property Launcher.AppDrawer appDrawer
|
||||||
|
signal snapPage
|
||||||
|
|
||||||
enum ScrollDirection {
|
enum ScrollDirection {
|
||||||
None,
|
None,
|
||||||
Horizontal,
|
Horizontal,
|
||||||
Vertical
|
Vertical
|
||||||
}
|
}
|
||||||
|
|
||||||
property real __initialMainFlickableX
|
property real __initialMainFlickableX
|
||||||
property int __scrollDirection: DragGestureHandler.None
|
property int __scrollDirection: DragGestureHandler.None
|
||||||
onTranslationChanged: {print(translation.x)
|
onTranslationChanged: {
|
||||||
if (active) {
|
if (active) {
|
||||||
if (appDrawer.offset > PlasmaCore.Units.gridUnit) {
|
if (appDrawer.offset > PlasmaCore.Units.gridUnit) {
|
||||||
__scrollDirection = DragGestureHandler.Vertical;
|
__scrollDirection = DragGestureHandler.Vertical;
|
||||||
|
snapPage();
|
||||||
} else if (Math.abs(mainFlickable.contentX - __initialMainFlickableX) > PlasmaCore.Units.gridUnit) {
|
} else if (Math.abs(mainFlickable.contentX - __initialMainFlickableX) > PlasmaCore.Units.gridUnit) {
|
||||||
__scrollDirection = DragGestureHandler.Horizontal;
|
__scrollDirection = DragGestureHandler.Horizontal;
|
||||||
|
appDrawer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (__scrollDirection !== DragGestureHandler.Horizontal) {
|
if (__scrollDirection !== DragGestureHandler.Horizontal) {
|
||||||
appDrawer.offset = -translation.y;
|
appDrawer.offset = -translation.y;
|
||||||
}
|
}
|
||||||
|
|
@ -41,7 +47,9 @@ DragHandler {
|
||||||
if (active) {
|
if (active) {
|
||||||
__initialMainFlickableX = mainFlickable.contentX;
|
__initialMainFlickableX = mainFlickable.contentX;
|
||||||
} else {
|
} else {
|
||||||
|
__scrollDirection = DragGestureHandler.None;
|
||||||
appDrawer.snapDrawerStatus();
|
appDrawer.snapDrawerStatus();
|
||||||
|
snapPage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,12 @@ Item {
|
||||||
plasmoid.nativeInterface.applicationListModel.maxFavoriteCount = Math.max(4, Math.floor(Math.min(width, height) / appletsLayout.cellWidth));
|
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
|
//END functions
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -177,47 +183,14 @@ Item {
|
||||||
onContentYChanged: MobileShell.HomeScreenControls.homeScreenPosition = contentY
|
onContentYChanged: MobileShell.HomeScreenControls.homeScreenPosition = contentY
|
||||||
|
|
||||||
LauncherPrivate.DragGestureHandler {
|
LauncherPrivate.DragGestureHandler {
|
||||||
|
id: gestureHandler
|
||||||
|
target: appletsLayout
|
||||||
appDrawer: appDrawer
|
appDrawer: appDrawer
|
||||||
mainFlickable: mainFlickable
|
mainFlickable: mainFlickable
|
||||||
enabled: root.focus && appDrawer.status !== Launcher.AppDrawer.Status.Open && !appletsLayout.editMode && !plasmoid.editMode && !launcherDragManager.active
|
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 {
|
NumberAnimation {
|
||||||
id: scrollAnim
|
id: scrollAnim
|
||||||
target: mainFlickable
|
target: mainFlickable
|
||||||
|
|
@ -326,7 +299,7 @@ Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
signal appletsLayoutInteracted
|
signal appletsLayoutInteracted
|
||||||
onChildrenRectChanged: print("AAAAAA"+childrenRect.width)
|
|
||||||
TapHandler {
|
TapHandler {
|
||||||
target: mainFlickable
|
target: mainFlickable
|
||||||
enabled: appDrawer.status !== Launcher.AppDrawer.Status.Open
|
enabled: appDrawer.status !== Launcher.AppDrawer.Status.Open
|
||||||
|
|
@ -441,20 +414,12 @@ onChildrenRectChanged: print("AAAAAA"+childrenRect.width)
|
||||||
}
|
}
|
||||||
appletsLayout: appletsLayout
|
appletsLayout: appletsLayout
|
||||||
|
|
||||||
DragHandler {
|
LauncherPrivate.DragGestureHandler {
|
||||||
target: favoriteStrip
|
target: favoriteStrip
|
||||||
yAxis.enabled: !appletsLayout.editMode
|
appDrawer: appDrawer
|
||||||
enabled: root.focus && appDrawer.status !== Launcher.AppDrawer.Status.Open
|
mainFlickable: mainFlickable
|
||||||
onTranslationChanged: {
|
enabled: root.focus && appDrawer.status !== Launcher.AppDrawer.Status.Open && !appletsLayout.editMode && !plasmoid.editMode && !launcherDragManager.active
|
||||||
if (active) {
|
onSnapPage: root.snapPage();
|
||||||
appDrawer.offset = -translation.y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
onActiveChanged: {
|
|
||||||
if (!active) {
|
|
||||||
appDrawer.snapDrawerStatus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
TapHandler {
|
TapHandler {
|
||||||
target: favoriteStrip
|
target: favoriteStrip
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue