finished moving the horizontal flicking in component

This commit is contained in:
Marco Martin 2021-03-24 14:48:56 +01:00
parent 5393452390
commit 70805d04eb
6 changed files with 135 additions and 122 deletions

View file

@ -13,9 +13,7 @@ import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 3.0 as PlasmaComponents import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.draganddrop 2.0 as DragDrop import org.kde.draganddrop 2.0 as DragDrop
import "launcher" as Launcher import "private" as Private
//TODO: everything using this will eventually move in Launcher
import "launcher/private" as LauncherPrivate
import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager
@ -27,11 +25,7 @@ import org.kde.plasma.private.mobileshell 1.0 as MobileShell
Flickable { Flickable {
id: mainFlickable id: mainFlickable
anchors { property AppDrawer appDrawer
fill: parent
topMargin: plasmoid.availableScreenRect.y
bottomMargin: favoriteStrip.height + plasmoid.screenGeometry.height - plasmoid.availableScreenRect.height - plasmoid.availableScreenRect.y
}
opacity: 1 - appDrawer.openFactor opacity: 1 - appDrawer.openFactor
transform: Translate { transform: Translate {
@ -53,13 +47,63 @@ Flickable {
onContentYChanged: MobileShell.HomeScreenControls.homeScreenPosition = contentY onContentYChanged: MobileShell.HomeScreenControls.homeScreenPosition = contentY
LauncherPrivate.DragGestureHandler {
//Autoscroll related functions
function scrollLeft() {
if (mainFlickable.atXBeginning) {
return;
}
autoScrollTimer.scrollRight = false;
autoScrollTimer.running = true;
scrollLeftIndicator.opacity = 1;
scrollRightIndicator.opacity = 0;
}
function scrollRight() {
if (mainFlickable.atXEnd) {
return;
}
autoScrollTimer.scrollRight = true;
autoScrollTimer.running = true;
scrollLeftIndicator.opacity = 0;
scrollRightIndicator.opacity = 1;
}
function stopScroll() {
autoScrollTimer.running = false;
scrollLeftIndicator.opacity = 0;
scrollRightIndicator.opacity = 0;
}
function snapPage() {
scrollAnim.running = false;
scrollAnim.to = mainFlickable.width * Math.round(mainFlickable.contentX / mainFlickable.width)
scrollAnim.running = true;
}
Timer {
id: autoScrollTimer
property bool scrollRight: true
repeat: true
interval: 1500
onTriggered: {
scrollAnim.to = scrollRight ?
//Scroll Right
Math.min(mainFlickable.contentItem.width - mainFlickable.width, mainFlickable.contentX + mainFlickable.width) :
//Scroll Left
Math.max(0, mainFlickable.contentX - mainFlickable.width);
scrollAnim.running = true;
}
}
Private.DragGestureHandler {
id: gestureHandler id: gestureHandler
target: appletsLayout target: appletsLayout
appDrawer: appDrawer appDrawer: mainFlickable.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 !== AppDrawer.Status.Open && !appletsLayout.editMode && !plasmoid.editMode && !launcherDragManager.active
onSnapPage: root.snapPage(); onSnapPage: mainFlickable.snapPage();
} }
NumberAnimation { NumberAnimation {
@ -84,6 +128,25 @@ Flickable {
visible: count > 1 visible: count > 1
currentIndex: Math.round(mainFlickable.contentX / mainFlickable.width) currentIndex: Math.round(mainFlickable.contentX / mainFlickable.width)
} }
Private.ScrollIndicator {
id: scrollLeftIndicator
parent: mainFlickable
anchors {
left: parent.left
leftMargin: units.smallSpacing
}
elementId: "left-arrow"
}
Private.ScrollIndicator {
id: scrollRightIndicator
parent: mainFlickable
anchors {
right: parent.right
rightMargin: units.smallSpacing
}
elementId: "right-arrow"
}
} }

View file

@ -57,6 +57,12 @@ ContainmentLayoutManager.ItemContainer {
onApplicationRunningChanged: { onApplicationRunningChanged: {
syncDelegateGeometry(); syncDelegateGeometry();
} }
onDragActiveChanged: {
if (dragActive) {
removeButton.show();
mouseArea.enabled = true;
}
}
Connections { Connections {
target: mainFlickable target: mainFlickable
function onCancelEditModeForItemsRequested() { function onCancelEditModeForItemsRequested() {
@ -79,45 +85,6 @@ ContainmentLayoutManager.ItemContainer {
} }
} }
onDragActiveChanged: {
launcherDragManager.active = dragActive
if (dragActive) {
// Must be 0, 0 as at this point dragCenterX and dragCenterY are on the drag before"
launcherDragManager.startDrag(delegate);
launcherDragManager.currentlyDraggedDelegate = delegate;
removeButton.show();
mouseArea.enabled = true;
} else {
launcherDragManager.dropItem(delegate, dragCenterX, dragCenterY);
plasmoid.editMode = false;
editMode = false;
plasmoid.fullRepresentationItem.stopScroll();
launcherDragManager.currentlyDraggedDelegate = null;
forceActiveFocus();
}
}
onUserDrag: {
dragCenterX = dragCenter.x;
dragCenterY = dragCenter.y;
launcherDragManager.dragItem(delegate, dragCenter.x, dragCenter.y);
delegate.width = appletsLayout.cellWidth;
delegate.height = appletsLayout.cellHeight;
var pos = plasmoid.fullRepresentationItem.mapFromItem(delegate, dragCenter.x, dragCenter.y);
//SCROLL LEFT
if (pos.x < units.gridUnit) {
plasmoid.fullRepresentationItem.scrollLeft();
//SCROLL RIGHT
} else if (pos.x > mainFlickable.width - units.gridUnit) {
plasmoid.fullRepresentationItem.scrollRight();
//DON't SCROLL
} else {
plasmoid.fullRepresentationItem.stopScroll();
}
}
contentItem: MouseArea { contentItem: MouseArea {
id: mouseArea id: mouseArea
onClicked: { onClicked: {

View file

@ -28,6 +28,10 @@ Repeater {
property int cellWidth property int cellWidth
property int cellHeight property int cellHeight
signal scrollLeftRequested
signal scrollRightRequested
signal stopScrollRequested
delegate: HomeDelegate { delegate: HomeDelegate {
id: delegate id: delegate
width: launcherRepeater.cellWidth width: launcherRepeater.cellWidth
@ -57,6 +61,44 @@ Repeater {
} }
} }
onUserDrag: {
dragCenterX = dragCenter.x;
dragCenterY = dragCenter.y;
launcherDragManager.dragItem(delegate, dragCenter.x, dragCenter.y);
delegate.width = appletsLayout.cellWidth;
delegate.height = appletsLayout.cellHeight;
var pos = plasmoid.fullRepresentationItem.mapFromItem(delegate, dragCenter.x, dragCenter.y);
//SCROLL LEFT
if (pos.x < units.gridUnit) {
launcherRepeater.scrollLeftRequested();
//SCROLL RIGHT
} else if (pos.x > mainFlickable.width - units.gridUnit) {
launcherRepeater.scrollRightRequested();
//DON't SCROLL
} else {
launcherRepeater.stopScrollRequested();
}
}
onDragActiveChanged: {
launcherDragManager.active = dragActive
if (dragActive) {
// Must be 0, 0 as at this point dragCenterX and dragCenterY are on the drag before"
launcherDragManager.startDrag(delegate);
launcherDragManager.currentlyDraggedDelegate = delegate;
} else {
launcherDragManager.dropItem(delegate, dragCenterX, dragCenterY);
plasmoid.editMode = false;
editMode = false;
launcherRepeater.stopScrollRequested();
launcherDragManager.currentlyDraggedDelegate = null;
forceActiveFocus();
}
}
onLaunch: (x, y, icon, title) => { onLaunch: (x, y, icon, title) => {
if (icon !== "") { if (icon !== "") {
print(delegate.iconItem) print(delegate.iconItem)

View file

@ -11,6 +11,7 @@ import org.kde.plasma.core 2.0 as PlasmaCore
import ".." as Launcher import ".." as Launcher
DragHandler { DragHandler {
id: root
yAxis.enabled: enabled yAxis.enabled: enabled
xAxis.enabled: enabled xAxis.enabled: enabled
property Flickable mainFlickable property Flickable mainFlickable
@ -27,16 +28,16 @@ DragHandler {
property int __scrollDirection: DragGestureHandler.None property int __scrollDirection: DragGestureHandler.None
onTranslationChanged: { onTranslationChanged: {
if (active) { if (active) {
if (appDrawer.offset > PlasmaCore.Units.gridUnit) { if (root.appDrawer.offset > PlasmaCore.Units.gridUnit) {
__scrollDirection = DragGestureHandler.Vertical; __scrollDirection = DragGestureHandler.Vertical;
snapPage(); 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(); root.appDrawer.close();
} }
if (__scrollDirection !== DragGestureHandler.Horizontal) { if (__scrollDirection !== DragGestureHandler.Horizontal) {
appDrawer.offset = -translation.y; root.appDrawer.offset = -translation.y;
} }
if (__scrollDirection !== DragGestureHandler.Vertical) { if (__scrollDirection !== DragGestureHandler.Vertical) {
mainFlickable.contentX = Math.max(0, __initialMainFlickableX - translation.x); mainFlickable.contentX = Math.max(0, __initialMainFlickableX - translation.x);
@ -48,7 +49,7 @@ DragHandler {
__initialMainFlickableX = mainFlickable.contentX; __initialMainFlickableX = mainFlickable.contentX;
} else { } else {
__scrollDirection = DragGestureHandler.None; __scrollDirection = DragGestureHandler.None;
appDrawer.snapDrawerStatus(); root.appDrawer.snapDrawerStatus();
snapPage(); snapPage();
} }
} }

View file

@ -32,32 +32,6 @@ FocusScope {
property Item toolBox property Item toolBox
//BEGIN functions //BEGIN functions
//Autoscroll related functions
function scrollLeft() {
if (mainFlickable.atXBeginning) {
return;
}
autoScrollTimer.scrollRight = false;
autoScrollTimer.running = true;
scrollLeftIndicator.opacity = 1;
scrollRightIndicator.opacity = 0;
}
function scrollRight() {
if (mainFlickable.atXEnd) {
return;
}
autoScrollTimer.scrollRight = true;
autoScrollTimer.running = true;
scrollLeftIndicator.opacity = 0;
scrollRightIndicator.opacity = 1;
}
function stopScroll() {
autoScrollTimer.running = false;
scrollLeftIndicator.opacity = 0;
scrollRightIndicator.opacity = 0;
}
function recalculateMaxFavoriteCount() { function recalculateMaxFavoriteCount() {
if (!componentComplete) { if (!componentComplete) {
@ -67,12 +41,6 @@ FocusScope {
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
@ -121,25 +89,9 @@ FocusScope {
} }
} }
Timer {
id: autoScrollTimer
property bool scrollRight: true
repeat: true
interval: 1500
onTriggered: {
scrollAnim.to = scrollRight ?
//Scroll Right
Math.min(mainFlickable.contentItem.width - mainFlickable.width, mainFlickable.contentX + mainFlickable.width) :
//Scroll Left
Math.max(0, mainFlickable.contentX - mainFlickable.width);
scrollAnim.running = true;
}
}
Connections { Connections {
target: plasmoid target: plasmoid
onEditModeChanged: { function onEditModeChanged() {
appletsLayout.editMode = plasmoid.editMode appletsLayout.editMode = plasmoid.editMode
} }
} }
@ -161,6 +113,8 @@ FocusScope {
bottomMargin: favoriteStrip.height + plasmoid.screenGeometry.height - plasmoid.availableScreenRect.height - plasmoid.availableScreenRect.y bottomMargin: favoriteStrip.height + plasmoid.screenGeometry.height - plasmoid.availableScreenRect.height - plasmoid.availableScreenRect.y
} }
appDrawer: appDrawer
// TODO: span on multiple pages // TODO: span on multiple pages
DragDrop.DropArea { DragDrop.DropArea {
id: dropArea id: dropArea
@ -322,6 +276,9 @@ FocusScope {
cellHeight: appletsLayout.cellHeight cellHeight: appletsLayout.cellHeight
appletsLayout: appletsLayout appletsLayout: appletsLayout
favoriteStrip: favoriteStrip favoriteStrip: favoriteStrip
onScrollLeftRequested: mainFlickable.scrollLeft()
onScrollRightRequested: mainFlickable.scrollRight()
onStopScrollRequested: mainFlickable.stopScroll()
} }
} }
} }
@ -335,23 +292,6 @@ FocusScope {
bottomPadding: favoriteStrip.height + plasmoid.screenGeometry.height - plasmoid.availableScreenRect.height - plasmoid.availableScreenRect.y bottomPadding: favoriteStrip.height + plasmoid.screenGeometry.height - plasmoid.availableScreenRect.height - plasmoid.availableScreenRect.y
} }
ScrollIndicator {
id: scrollLeftIndicator
anchors {
left: parent.left
leftMargin: units.smallSpacing
}
elementId: "left-arrow"
}
ScrollIndicator {
id: scrollRightIndicator
anchors {
right: parent.right
rightMargin: units.smallSpacing
}
elementId: "right-arrow"
}
Launcher.FavoriteStrip { Launcher.FavoriteStrip {
id: favoriteStrip id: favoriteStrip
anchors { anchors {
@ -367,7 +307,7 @@ FocusScope {
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(); onSnapPage: mainFlickable.snapPage();
} }
TapHandler { TapHandler {
target: favoriteStrip target: favoriteStrip