on xenial help sign in
Cleanup initial highlight
e0401e0Josh Arenson
qml/Greeter/SessionsList.qml+18−11
@@ -24,26 +24,26 @@ Item {
24 id: root
24 id: root
25 objectName: "sessionsList"
25 objectName: "sessionsList"
26
26
27− property string initiallySelectedSession
28 signal sessionSelected(string sessionKey)
27 signal sessionSelected(string sessionKey)
29 signal showLoginList()
28 signal showLoginList()
30
29
31− onInitiallySelectedSessionChanged: {
30+ // Sets the position of the background highlight
31+ function updateHighlight(session) {
32− sessionsList.currentIndex = getSelectedIndex();
32+ sessionsList.currentIndex = getIndexOfSession(session);
33
33
34− // A workaround to get the initial highlight correct
34+ var newY = sessionsList.currentItem.y + sessionsList.headerItem.height
35− sessionsList.highlightFollowsCurrentItem = true;
35+ sessionsList.backgroundHighlight.y = newY;
36− sessionsList.positionViewAtIndex(sessionsList.currentIndex, ListView.Contain);
37− sessionsList.highlightFollowsCurrentItem = false;
38 }
36 }
39
37
40− function getSelectedIndex() {
38+ function getIndexOfSession(session) {
41 for (var i = 0; i < sessionsList.model.count; i++) {
39 for (var i = 0; i < sessionsList.model.count; i++) {
42− var key = sessionsList.model.get(i).key
40+ var key = sessionsList.model.get(i).key;
43− if (key === initiallySelectedSession) {
41+ if (key === session) {
44 return i;
42 return i;
45 }
43 }
46 }
44 }
45+
46+ return 0; // Just choose the first session
47 }
47 }
48
48
49 function currentKey() {
49 function currentKey() {
@@ -104,6 +104,8 @@ Item {
104 UbuntuListView {
104 UbuntuListView {
105 id: sessionsList
105 id: sessionsList
106
106
107+ readonly property alias backgroundHighlight: backgroundHighlight
108+
107 anchors {
109 anchors {
108 top: parent.top
110 top: parent.top
109 left: parent.left
111 left: parent.left
@@ -139,9 +141,14 @@ Item {
139 }
141 }
140
142
141 headerPositioning: ListView.OverlayHeader
143 headerPositioning: ListView.OverlayHeader
144+
145+ // The highlighting is all self-managed, so account for that
142 highlightFollowsCurrentItem: false
146 highlightFollowsCurrentItem: false
147+ highlight: QtObject {}
148+
149+ Rectangle {
150+ id: backgroundHighlight
143
151
144− highlight: Rectangle {
145 height: sessionsList.currentItem.height
152 height: sessionsList.currentItem.height
146 width: sessionsList.currentItem.width
153 width: sessionsList.currentItem.width
147 color: theme.palette.normal.selection
154 color: theme.palette.normal.selection
qml/Greeter/WideView.qml+3−4
@@ -157,10 +157,9 @@ FocusScope {
157 active: false
157 active: false
158
158
159 onLoaded: sessionChooserLoader.item.forceActiveFocus();
159 onLoaded: sessionChooserLoader.item.forceActiveFocus();
160− Binding {
160+ onActiveChanged: {
161− target: sessionChooserLoader.item
161+ if (!active) return;
162− property: "initiallySelectedSession"
163− value: loginList.currentSession
162+ item.updateHighlight(loginList.currentSession);
164 }
163 }
165
164
166 Connections {
165 Connections {