2 * Copyright (C) 2015 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18import Lomiri.Components 1.3
19import Lomiri.Components.ListItems 1.3
25 objectName: "sessionsList"
27 signal sessionSelected(string sessionKey)
28 signal showLoginList()
30 // Sets the position of the background highlight
31 function updateHighlight(session) {
32 sessionsList.currentIndex = getIndexOfSession(session);
33 sessionsList.currentItem.initialSession = session;
36 function getIndexOfSession(session) {
37 for (var i = 0; i < sessionsList.model.count; i++) {
38 var key = sessionsList.model.get(i).key;
39 if (key === session) {
44 return 0; // Just choose the first session
47 function currentKey() {
48 var session = LightDMService.sessions.data(
49 sessionsList.currentIndex, LightDMService.sessionRoles.KeyRole)
53 Keys.onEnterPressed: {
54 sessionSelected(currentKey());
56 event.accepted = true;
59 Keys.onEscapePressed: {
61 event.accepted = true;
64 Keys.onReturnPressed: {
65 sessionSelected(currentKey());
67 event.accepted = true;
71 if (sessionsList.currentIndex < sessionsList.model.count - 1)
72 sessionsList.currentIndex++;
73 event.accepted = true;
77 if (sessionsList.currentIndex > 0)
78 sessionsList.currentIndex--;
79 event.accepted = true;
83 readonly property real margins: sessionsList.anchors.margins
84 readonly property real preferredHeight: {
85 if (sessionsList.currentItem) {
86 return (sessionsList.currentItem.height *
87 (1 + sessionsList.model.count)) + 2 * margins
89 return sessionsList.headerItem.height + 2 * margins
93 height: preferredHeight < parent.height ? preferredHeight : parent.height - units.gu(4)
99 verticalCenter: parent.verticalCenter
113 height: parent.height - units.gu(2.5)
114 boundsBehavior: Flickable.StopAtBounds
116 model: LightDMService.sessions
117 header: ListItemLayout {
120 padding.leading: 0 // handled by parent's margins
122 title.color: theme.palette.normal.raisedSecondaryText
123 title.font.pixelSize: units.gu(2.1)
124 title.text: i18n.tr("Select desktop environment")
129 color: theme.palette.normal.raisedSecondaryText
130 SlotsLayout.position: SlotsLayout.Leading
135 onClicked: showLoginList()
140 headerPositioning: ListView.OverlayHeader
142 // The highlighting is all self-managed, so account for that
143 highlightFollowsCurrentItem: false
144 highlight: QtObject {}
148 objectName: "sessionDelegate" + index
150 property string initialSession: ""
152 divider.visible: false
153 visible: y > sessionsList.headerItem.y
154 + sessionsList.headerItem.height
155 - sessionsList.anchors.margins
160 sessionsList.currentIndex = index
167 id: backgroundHighlight
169 height: sessionsList.currentItem.height
170 width: sessionsList.currentItem.width
171 color: theme.palette.normal.selection
173 visible: initialSession === key && !!key
177 height: parent.height
181 color: theme.palette.normal.focus
185 visible: index === sessionsList.currentIndex
191 readonly property color itemColor: theme.palette.normal.raisedSecondaryText
195 SlotsLayout.position: SlotsLayout.Leading
196 color: parent.itemColor
200 title.color: itemColor