on xenial help sign in
implement progressive scrolling in desktop spread
commita8eaacf33fc2a6dd8071076892a6bf2d4c63778f authorMichael Zanetti <michael.zanetti@canonical.com> dateFri 28 Aug 2015, 14:18 (11 years ago) parent26142f7
2 files changed+67−4
qml/Stages/DesktopStage.qml+30−1 tests/qmltests/tst_Shell.qml+37−3
qml/Stages/DesktopStage.qml+30−1
@@ -478,27 +478,55 @@ Rectangle {
478478 anchors.fill: appContainer
479479 propagateComposedEvents: true
480480 hoverEnabled: true
481+
482+ property int scrollAreaWidth: root.width / 3
483+ property bool progressiveScrollingEnabled: false
484+
481485 onMouseXChanged: {
482486 mouse.accepted = false
487+
488+ // Find the howered item and mark it active
483489 var mapped = mapToItem(appContainer, hoverMouseArea.mouseX, hoverMouseArea.mouseY)
484490 var itemUnder = appContainer.childAt(mapped.x, mapped.y)
485491 if (itemUnder) {
486492 mapped = mapToItem(itemUnder, hoverMouseArea.mouseX, hoverMouseArea.mouseY)
487493 var delegateChild = itemUnder.childAt(mapped.x, mapped.y)
488− if (delegateChild.objectName === "decoratedWindow") {
494+ print("delegateChild", delegateChild)
495+ if (delegateChild.objectName === "decoratedWindow" || delegateChild.objectName === "tileInfo") {
489496 appRepeater.highlightedIndex = appRepeater.indexOf(itemUnder)
490497 }
491498 }
499+
500+ var margins = spreadFlickable.width * 0.05;
501+
502+ if (!progressiveScrollingEnabled && mouseX < spreadFlickable.width - scrollAreaWidth) {
503+ progressiveScrollingEnabled = true
504+ }
505+
506+ // do we need to scroll?
507+ if (mouseX < scrollAreaWidth) {
508+ var progress = Math.min(1, (scrollAreaWidth + margins - mouseX) / (scrollAreaWidth - margins));
509+ var contentX = (1 - progress) * (spreadFlickable.contentWidth - spreadFlickable.width)
510+ spreadFlickable.contentX = Math.max(0, Math.min(spreadFlickable.contentX, contentX))
511+ }
512+ if (mouseX > spreadFlickable.width - scrollAreaWidth && progressiveScrollingEnabled) {
513+ var progress = Math.min(1, (mouseX - (spreadFlickable.width - scrollAreaWidth)) / (scrollAreaWidth - margins))
514+ var contentX = progress * (spreadFlickable.contentWidth - spreadFlickable.width)
515+ spreadFlickable.contentX = Math.min(spreadFlickable.contentWidth - spreadFlickable.width, Math.max(spreadFlickable.contentX, contentX))
516+ }
492517 }
493518 onPressed: mouse.accepted = false
494519 }
495520
496521 FloatingFlickable {
497522 id: spreadFlickable
523+ objectName: "spreadFlickable"
498524 anchors.fill: parent
499525 contentWidth: Math.max(6, ApplicationManager.count) * Math.min(height / 4, width / 5)
500526 enabled: false
501527
528+ onContentXChanged: print("cx", contentX)
529+
502530 function snapTo(contentX) {
503531 snapAnimation.stop();
504532 snapAnimation.to = contentX
@@ -623,6 +651,7 @@ Rectangle {
623651 from: "*"
624652 to: "altTab"
625653 SequentialAnimation {
654+ PropertyAction { target: hoverMouseArea; property: "progressiveScrollingEnabled"; value: false }
626655 PropertyAction { target: appRepeater; property: "highlightedIndex"; value: Math.min(ApplicationManager.count - 1, 1) }
627656 PauseAnimation { duration: 50 }
628657 PropertyAction { target: workspaceSelector; property: "visible" }
tests/qmltests/tst_Shell.qml+37−3
@@ -1566,8 +1566,6 @@ Rectangle {
15661566 keyPress(Qt.Key_Control)
15671567 keyClick(Qt.Key_Tab);
15681568
1569− appRemovedSpy.clear();
1570−
15711569 var focusAppId = ApplicationManager.get(2).appId;
15721570 var appDelegate2 = appRepeater.itemAt(2);
15731571 var decoratedWindow = findChild(appDelegate2, "decoratedWindow");
@@ -1577,7 +1575,7 @@ Rectangle {
15771575
15781576 // Move the mouse over tile 2 and verify the highlight becomes visible
15791577 var x = 0;
1580− var y = shell.height * (data.tileInfo ? .5 : 0.95)
1578+ var y = shell.height * (data.tileInfo ? .95 : 0.5)
15811579 mouseMove(shell, x, y)
15821580 while (appRepeater.highlightedIndex !== 2 && x <= 4000) {
15831581 x+=10;
@@ -1595,5 +1593,41 @@ Rectangle {
15951593
15961594 keyRelease(Qt.Key_Control);
15971595 }
1596+
1597+ function test_progressiveAutoScrolling() {
1598+ loadDesktopShellWithApps()
1599+
1600+ var appRepeater = findInvisibleChild(shell, "appRepeater");
1601+ verify(appRepeater !== null);
1602+
1603+ keyPress(Qt.Key_Control)
1604+ keyClick(Qt.Key_Tab);
1605+
1606+ var spreadFlickable = findChild(shell, "spreadFlickable")
1607+ print("have flickable", spreadFlickable, spreadFlickable.contentX)
1608+
1609+ compare(spreadFlickable.contentX, 0);
1610+
1611+ // Move the mouse to the right and make sure it scrolls the Flickable
1612+ var x = 0;
1613+ var y = shell.height * .5
1614+ mouseMove(shell, x, y)
1615+ while (x <= spreadFlickable.width) {
1616+ x+=10;
1617+ mouseMove(shell, x, y)
1618+ wait(0); // spin the loop so bindings get evaluated
1619+ }
1620+ tryCompare(spreadFlickable, "contentX", spreadFlickable.contentWidth - spreadFlickable.width);
1621+
1622+ // And turn around
1623+ while (x > 0) {
1624+ x-=10;
1625+ mouseMove(shell, x, y)
1626+ wait(0); // spin the loop so bindings get evaluated
1627+ }
1628+ tryCompare(spreadFlickable, "contentX", 0);
1629+
1630+ keyRelease(Qt.Key_Control);
1631+ }
15981632 }
15991633}