on xenial help sign in
implement progressive scrolling in desktop spread
a8eaacfMichael Zanetti
qml/Stages/DesktopStage.qml+30−1
@@ -478,27 +478,55 @@ Rectangle {
478 anchors.fill: appContainer
478 anchors.fill: appContainer
479 propagateComposedEvents: true
479 propagateComposedEvents: true
480 hoverEnabled: true
480 hoverEnabled: true
481+
482+ property int scrollAreaWidth: root.width / 3
483+ property bool progressiveScrollingEnabled: false
484+
481 onMouseXChanged: {
485 onMouseXChanged: {
482 mouse.accepted = false
486 mouse.accepted = false
487+
488+ // Find the howered item and mark it active
483 var mapped = mapToItem(appContainer, hoverMouseArea.mouseX, hoverMouseArea.mouseY)
489 var mapped = mapToItem(appContainer, hoverMouseArea.mouseX, hoverMouseArea.mouseY)
484 var itemUnder = appContainer.childAt(mapped.x, mapped.y)
490 var itemUnder = appContainer.childAt(mapped.x, mapped.y)
485 if (itemUnder) {
491 if (itemUnder) {
486 mapped = mapToItem(itemUnder, hoverMouseArea.mouseX, hoverMouseArea.mouseY)
492 mapped = mapToItem(itemUnder, hoverMouseArea.mouseX, hoverMouseArea.mouseY)
487 var delegateChild = itemUnder.childAt(mapped.x, mapped.y)
493 var delegateChild = itemUnder.childAt(mapped.x, mapped.y)
494+ print("delegateChild", delegateChild)
488− if (delegateChild.objectName === "decoratedWindow") {
495+ if (delegateChild.objectName === "decoratedWindow" || delegateChild.objectName === "tileInfo") {
489 appRepeater.highlightedIndex = appRepeater.indexOf(itemUnder)
496 appRepeater.highlightedIndex = appRepeater.indexOf(itemUnder)
490 }
497 }
491 }
498 }
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+ }
492 }
517 }
493 onPressed: mouse.accepted = false
518 onPressed: mouse.accepted = false
494 }
519 }
495
520
496 FloatingFlickable {
521 FloatingFlickable {
497 id: spreadFlickable
522 id: spreadFlickable
523+ objectName: "spreadFlickable"
498 anchors.fill: parent
524 anchors.fill: parent
499 contentWidth: Math.max(6, ApplicationManager.count) * Math.min(height / 4, width / 5)
525 contentWidth: Math.max(6, ApplicationManager.count) * Math.min(height / 4, width / 5)
500 enabled: false
526 enabled: false
501
527
528+ onContentXChanged: print("cx", contentX)
529+
502 function snapTo(contentX) {
530 function snapTo(contentX) {
503 snapAnimation.stop();
531 snapAnimation.stop();
504 snapAnimation.to = contentX
532 snapAnimation.to = contentX
@@ -623,6 +651,7 @@ Rectangle {
623 from: "*"
651 from: "*"
624 to: "altTab"
652 to: "altTab"
625 SequentialAnimation {
653 SequentialAnimation {
654+ PropertyAction { target: hoverMouseArea; property: "progressiveScrollingEnabled"; value: false }
626 PropertyAction { target: appRepeater; property: "highlightedIndex"; value: Math.min(ApplicationManager.count - 1, 1) }
655 PropertyAction { target: appRepeater; property: "highlightedIndex"; value: Math.min(ApplicationManager.count - 1, 1) }
627 PauseAnimation { duration: 50 }
656 PauseAnimation { duration: 50 }
628 PropertyAction { target: workspaceSelector; property: "visible" }
657 PropertyAction { target: workspaceSelector; property: "visible" }
tests/qmltests/tst_Shell.qml+37−3
@@ -1566,8 +1566,6 @@ Rectangle {
1566 keyPress(Qt.Key_Control)
1566 keyPress(Qt.Key_Control)
1567 keyClick(Qt.Key_Tab);
1567 keyClick(Qt.Key_Tab);
1568
1568
1569− appRemovedSpy.clear();
1570−
1571 var focusAppId = ApplicationManager.get(2).appId;
1569 var focusAppId = ApplicationManager.get(2).appId;
1572 var appDelegate2 = appRepeater.itemAt(2);
1570 var appDelegate2 = appRepeater.itemAt(2);
1573 var decoratedWindow = findChild(appDelegate2, "decoratedWindow");
1571 var decoratedWindow = findChild(appDelegate2, "decoratedWindow");
@@ -1577,7 +1575,7 @@ Rectangle {
1577
1575
1578 // Move the mouse over tile 2 and verify the highlight becomes visible
1576 // Move the mouse over tile 2 and verify the highlight becomes visible
1579 var x = 0;
1577 var x = 0;
1580− var y = shell.height * (data.tileInfo ? .5 : 0.95)
1578+ var y = shell.height * (data.tileInfo ? .95 : 0.5)
1581 mouseMove(shell, x, y)
1579 mouseMove(shell, x, y)
1582 while (appRepeater.highlightedIndex !== 2 && x <= 4000) {
1580 while (appRepeater.highlightedIndex !== 2 && x <= 4000) {
1583 x+=10;
1581 x+=10;
@@ -1595,5 +1593,41 @@ Rectangle {
1595
1593
1596 keyRelease(Qt.Key_Control);
1594 keyRelease(Qt.Key_Control);
1597 }
1595 }
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+ }
1598 }
1632 }
1599}
1633}