on xenial help sign in
Cleanup initial highlight
commite0401e04300df078c8058f0a69285ca5893cd32d authorJosh Arenson <joshua.arenson@canonical.com> dateWed 15 Mar 2017, 16:57 (10 years ago) parent175e752
2 files changed+21−15
qml/Greeter/SessionsList.qml+18−11 qml/Greeter/WideView.qml+3−4
qml/Greeter/SessionsList.qml+18−11
@@ -24,26 +24,26 @@ Item {
2424 id: root
2525 objectName: "sessionsList"
2626
27− property string initiallySelectedSession
2827 signal sessionSelected(string sessionKey)
2928 signal showLoginList()
3029
31− onInitiallySelectedSessionChanged: {
32− sessionsList.currentIndex = getSelectedIndex();
30+ // Sets the position of the background highlight
31+ function updateHighlight(session) {
32+ sessionsList.currentIndex = getIndexOfSession(session);
3333
34− // A workaround to get the initial highlight correct
35− sessionsList.highlightFollowsCurrentItem = true;
36− sessionsList.positionViewAtIndex(sessionsList.currentIndex, ListView.Contain);
37− sessionsList.highlightFollowsCurrentItem = false;
34+ var newY = sessionsList.currentItem.y + sessionsList.headerItem.height
35+ sessionsList.backgroundHighlight.y = newY;
3836 }
3937
40− function getSelectedIndex() {
38+ function getIndexOfSession(session) {
4139 for (var i = 0; i < sessionsList.model.count; i++) {
42− var key = sessionsList.model.get(i).key
43− if (key === initiallySelectedSession) {
40+ var key = sessionsList.model.get(i).key;
41+ if (key === session) {
4442 return i;
4543 }
4644 }
45+
46+ return 0; // Just choose the first session
4747 }
4848
4949 function currentKey() {
@@ -104,6 +104,8 @@ Item {
104104 UbuntuListView {
105105 id: sessionsList
106106
107+ readonly property alias backgroundHighlight: backgroundHighlight
108+
107109 anchors {
108110 top: parent.top
109111 left: parent.left
@@ -139,9 +141,14 @@ Item {
139141 }
140142
141143 headerPositioning: ListView.OverlayHeader
144+
145+ // The highlighting is all self-managed, so account for that
142146 highlightFollowsCurrentItem: false
147+ highlight: QtObject {}
148+
149+ Rectangle {
150+ id: backgroundHighlight
143151
144− highlight: Rectangle {
145152 height: sessionsList.currentItem.height
146153 width: sessionsList.currentItem.width
147154 color: theme.palette.normal.selection
qml/Greeter/WideView.qml+3−4
@@ -157,10 +157,9 @@ FocusScope {
157157 active: false
158158
159159 onLoaded: sessionChooserLoader.item.forceActiveFocus();
160− Binding {
161− target: sessionChooserLoader.item
162− property: "initiallySelectedSession"
163− value: loginList.currentSession
160+ onActiveChanged: {
161+ if (!active) return;
162+ item.updateHighlight(loginList.currentSession);
164163 }
165164
166165 Connections {