on xenial help sign in
fix keyboard spread navigation; add mouse wheel support
commit1d4dbef2fafee1a095cf4230066b8fb2c9229de0 authorLukáš Tinkl <lukas.tinkl@canonical.com> dateFri 16 Sep 2016, 16:36 (10 years ago) parent1e10bf9
2 files changed+19−9
qml/Stage/Spread/Spread.qml+9−8 qml/Stage/Stage.qml+10−1
qml/Stage/Spread/Spread.qml+9−8
@@ -9,6 +9,7 @@ Item {
99 property int highlightedIndex: -1
1010 property var model: null
1111 property int leftMargin: 0
12+ property var spreadFlickable
1213
1314 // some config options
1415 property real contentMargin: 0.16 * root.height
@@ -133,10 +134,10 @@ Item {
133134 }
134135
135136 highlightedIndex = (highlightedIndex + 1) % totalItemCount;
136− var newContentX = ((spreadTotalWidth) / (totalItemCount + 1)) * Math.max(0, Math.min(totalItemCount - 5, highlightedIndex - 3));
137−// if (spreadFlickable.contentX < newContentX || spreadRepeater.highlightedIndex == 0) {
138−// spreadFlickable.snapTo(newContentX)
139−// }
137+ var newContentX = (spreadTotalWidth / (totalItemCount + 1)) * Math.max(0, Math.min(totalItemCount - 1, highlightedIndex - 1));
138+ if (spreadFlickable.contentX < newContentX || highlightedIndex == 0) {
139+ spreadFlickable.contentX = newContentX;
140+ }
140141 }
141142
142143 function selectPrevious(isAutoRepeat) {
@@ -146,10 +147,10 @@ Item {
146147
147148 var newIndex = highlightedIndex - 1 >= 0 ? highlightedIndex - 1 : totalItemCount - 1;
148149 highlightedIndex = newIndex;
149−// var newContentX = ((spreadFlickable.contentWidth) / (topLevelSurfaceList.count + 1)) * Math.max(0, Math.min(topLevelSurfaceList.count - 5, spreadRepeater.highlightedIndex - 1));
150−// if (spreadFlickable.contentX > newContentX || newIndex == topLevelSurfaceList.count -1) {
151−// spreadFlickable.snapTo(newContentX)
152−// }
150+ var newContentX = (spreadFlickable.contentWidth / (totalItemCount + 1)) * Math.max(0, Math.min(totalItemCount - 1, highlightedIndex - 1));
151+ if (spreadFlickable.contentX > newContentX || newIndex == totalItemCount - 1) {
152+ spreadFlickable.contentX = newContentX
153+ }
153154 }
154155
155156}
qml/Stage/Stage.qml+10−1
@@ -455,6 +455,7 @@ AbstractStage {
455455 anchors.fill: appContainer
456456 leftMargin: root.leftMargin
457457 model: root.topLevelSurfaceList
458+ spreadFlickable: floatingFlickable
458459 z: 10
459460
460461 onLeaveSpread: {
@@ -1617,6 +1618,14 @@ AbstractStage {
16171618 }
16181619 }
16191620 }
1621+ onWheel: {
1622+ if (wheel.angleDelta.y >= 120) {
1623+ spreadItem.selectNext(false);
1624+ } else if (wheel.angleDelta.y < 120 ){
1625+ spreadItem.selectPrevious(false);
1626+ }
1627+ }
1628+
16201629 onPressed: mouse.accepted = false
16211630 }
16221631
@@ -1642,7 +1651,7 @@ AbstractStage {
16421651 anchors { top: parent.top; right: parent.right; bottom: parent.bottom }
16431652 width: root.dragAreaWidth
16441653
1645− property var gesturePoints: new Array()
1654+ property var gesturePoints: []
16461655 property bool cancelled: false
16471656
16481657 property real progress: dragging ? -touchPosition.x / root.width : 0