on xenial help sign in
Tune quicklist selection

Mouse on hover selects items Keyboard selection skips non-clickable items

commit604cd88499b3d0dfc38993864a3fbcb27252ad33 authorAlbert Astals Cid <albert.astals@canonical.com> dateFri 17 Mar 2017, 17:33 (10 years ago) parent593d500
2 files changed+48−12
qml/Launcher/LauncherPanel.qml+22−6 tests/qmltests/Launcher/tst_Launcher.qml+26−6
qml/Launcher/LauncherPanel.qml+22−6
@@ -749,16 +749,18 @@ Rectangle {
749749 Keys.onPressed: {
750750 switch (event.key) {
751751 case Qt.Key_Down:
752− selectedIndex++;
753− if (selectedIndex >= popoverRepeater.count) {
754− selectedIndex = 0;
752+ var prevIndex = selectedIndex;
753+ selectedIndex = (selectedIndex + 1 < popoverRepeater.count) ? selectedIndex + 1 : 0;
754+ while (!popoverRepeater.itemAt(selectedIndex).clickable && selectedIndex != prevIndex) {
755+ selectedIndex = (selectedIndex + 1 < popoverRepeater.count) ? selectedIndex + 1 : 0;
755756 }
756757 event.accepted = true;
757758 break;
758759 case Qt.Key_Up:
759− selectedIndex--;
760− if (selectedIndex < 0) {
761− selectedIndex = popoverRepeater.count - 1;
760+ var prevIndex = selectedIndex;
761+ selectedIndex = (selectedIndex > 0) ? selectedIndex - 1 : popoverRepeater.count - 1;
762+ while (!popoverRepeater.itemAt(selectedIndex).clickable && selectedIndex != prevIndex) {
763+ selectedIndex = (selectedIndex > 0) ? selectedIndex - 1 : popoverRepeater.count - 1;
762764 }
763765 event.accepted = true;
764766 break;
@@ -804,6 +806,17 @@ Rectangle {
804806 width: parent.width
805807 height: quickListColumn.height
806808
809+ MouseArea {
810+ anchors.fill: parent
811+ hoverEnabled: true
812+ onPositionChanged: {
813+ var item = quickListColumn.childAt(mouseX, mouseY);
814+ if (item.clickable) {
815+ quickList.selectedIndex = item.index;
816+ }
817+ }
818+ }
819+
807820 Column {
808821 id: quickListColumn
809822 width: parent.width
@@ -814,6 +827,9 @@ Rectangle {
814827 model: quickList.model
815828
816829 ListItem {
830+ readonly property bool clickable: model.clickable
831+ readonly property int index: model.index
832+
817833 objectName: "quickListEntry" + index
818834 selected: index === quickList.selectedIndex
819835 height: label.implicitHeight + label.anchors.topMargin + label.anchors.bottomMargin
tests/qmltests/Launcher/tst_Launcher.qml+26−6
@@ -1235,13 +1235,13 @@ Rectangle {
12351235 tryCompare(quickList, "selectedIndex", 0)
12361236
12371237 // Down should move down the quicklist
1238+ // Because item 1 is not selectable
12381239 keyClick(Qt.Key_Down);
1239− tryCompare(quickList, "selectedIndex", 1)
1240+ tryCompare(quickList, "selectedIndex", 2)
12401241
12411242 // The quicklist should wrap around too
12421243 keyClick(Qt.Key_Down);
12431244 keyClick(Qt.Key_Down);
1244− keyClick(Qt.Key_Down);
12451245 tryCompare(quickList, "selectedIndex", 0)
12461246
12471247 // Left gets us back to the launcher
@@ -1266,14 +1266,14 @@ Rectangle {
12661266
12671267 keyClick(Qt.Key_Down); // Down to launcher item 0
12681268 keyClick(Qt.Key_Down); // Down to launcher item 1
1269− keyClick(Qt.Key_Right); // Into quicklist
1270− keyClick(Qt.Key_Down); // Down to quicklist item 1
1271− keyClick(Qt.Key_Down); // Down to quicklist item 2
1269+ keyClick(Qt.Key_Right); // Into quicklist, item 0 is selected
1270+ keyClick(Qt.Key_Down); // Down to quicklist item 2 (because 1 is not selectable)
1271+ keyClick(Qt.Key_Down); // Down to quicklist item 3
12721272 keyClick(Qt.Key_Enter); // Trigger it
12731273
12741274 compare(signalSpy.count, 1, "Quicklist signal wasn't triggered")
12751275 compare(signalSpy.signalArguments[0][0], LauncherModel.get(1).appId)
1276− compare(signalSpy.signalArguments[0][1], 2)
1276+ compare(signalSpy.signalArguments[0][1], 3)
12771277 assertFocusOnIndex(-2);
12781278 }
12791279
@@ -1500,5 +1500,25 @@ Rectangle {
15001500 tryCompare(launcher, "maxPanelX", 0);
15011501 launcher.panelWidth = oldSize;
15021502 }
1503+
1504+ function test_mouseHoverSelectQuickList() {
1505+ dragLauncherIntoView();
1506+ var clickedItem = findChild(launcher, "launcherDelegate5")
1507+ var quickList = findChild(launcher, "quickList")
1508+
1509+ // Initial state
1510+ tryCompare(quickList, "state", "")
1511+
1512+ // Doing longpress
1513+ mouseClick(clickedItem, clickedItem.width / 2, clickedItem.height / 2, Qt.RightButton)
1514+ verify(quickList, "state", "open")
1515+ compare(quickList.selectedIndex, -1)
1516+
1517+ var qEntry = findChild(launcher, "quickListEntry0");
1518+ mouseMove(qEntry, qEntry.width / 2 , qEntry.height / 2, 10);
1519+ mouseMove(qEntry, qEntry.width / 2 + 1, qEntry.height / 2, 10);
1520+
1521+ tryCompare(quickList, "selectedIndex", 0)
1522+ }
15031523 }
15041524}