~saviq/unity8/common-nodep-tests

« back to all changes in this revision

Viewing changes to qml/Greeter/SessionsList.qml

  • Committer: Michał Sawicz
  • Date: 2017-04-07 07:44:27 UTC
  • mfrom: (2891.1.36 origin/trunk)
  • Revision ID: michal.sawicz@canonical.com-20170407074427-87xejdyvyor7huxs
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    id: root
25
25
    objectName: "sessionsList"
26
26
 
27
 
    property string initiallySelectedSession
28
27
    signal sessionSelected(string sessionKey)
29
28
    signal showLoginList()
30
29
 
31
 
    onInitiallySelectedSessionChanged: {
32
 
        sessionsList.currentIndex = getSelectedIndex();
33
 
        sessionsList.positionViewAtIndex(sessionsList.currentIndex, ListView.Contain);
 
30
    // Sets the position of the background highlight
 
31
    function updateHighlight(session) {
 
32
        sessionsList.currentIndex = getIndexOfSession(session);
 
33
        sessionsList.currentItem.initialSession = session;
34
34
    }
35
35
 
36
 
    function getSelectedIndex() {
 
36
    function getIndexOfSession(session) {
37
37
        for (var i = 0; i < sessionsList.model.count; i++) {
38
 
            var key = sessionsList.model.get(i).key
39
 
            if (key === initiallySelectedSession) {
 
38
            var key = sessionsList.model.get(i).key;
 
39
            if (key === session) {
40
40
                return i;
41
41
            }
42
42
        }
 
43
 
 
44
        return 0; // Just choose the first session
43
45
    }
44
46
 
45
47
    function currentKey() {
49
51
    }
50
52
 
51
53
    Keys.onEnterPressed: {
52
 
        showLoginList(); // Session is already selected
 
54
        sessionSelected(currentKey());
 
55
        showLoginList();
53
56
        event.accepted = true;
54
57
    }
55
58
 
59
62
    }
60
63
 
61
64
    Keys.onReturnPressed: {
 
65
        sessionSelected(currentKey());
62
66
        showLoginList();
63
67
        event.accepted = true;
64
68
    }
66
70
    Keys.onDownPressed: {
67
71
        if (sessionsList.currentIndex < sessionsList.model.count - 1)
68
72
            sessionsList.currentIndex++;
69
 
        sessionSelected(currentKey());
70
73
        event.accepted = true;
71
74
    }
72
75
 
73
76
    Keys.onUpPressed: {
74
77
        if (sessionsList.currentIndex > 0)
75
78
            sessionsList.currentIndex--;
76
 
        sessionSelected(currentKey());
77
79
        event.accepted = true;
78
80
    }
79
81
 
80
82
    LoginAreaContainer {
81
83
        readonly property real margins: sessionsList.anchors.margins
82
 
        readonly property real prefferedHeight: {
 
84
        readonly property real preferredHeight: {
83
85
            if (sessionsList.currentItem) {
84
86
                return (sessionsList.currentItem.height *
85
87
                       (1 + sessionsList.model.count)) + 2 * margins
88
90
            }
89
91
        }
90
92
 
91
 
        height: prefferedHeight < parent.height ? prefferedHeight : parent.height - units.gu(4)
 
93
        height: preferredHeight < parent.height ? preferredHeight : parent.height - units.gu(4)
92
94
        width: parent.width
93
95
 
94
96
        anchors {
107
109
                margins: units.gu(2)
108
110
            }
109
111
 
110
 
            height: parent.height - headerItem.height
111
 
 
 
112
            clip: true
 
113
            height: parent.height - units.gu(2.5)
112
114
            boundsBehavior: Flickable.StopAtBounds
113
115
 
114
116
            model: LightDMService.sessions
135
137
            }
136
138
 
137
139
            headerPositioning: ListView.OverlayHeader
 
140
 
 
141
            // The highlighting is all self-managed, so account for that
138
142
            highlightFollowsCurrentItem: false
 
143
            highlight: QtObject {}
139
144
 
140
145
            delegate: ListItem {
141
146
                id: delegate
142
147
                objectName: "sessionDelegate" + index
143
148
 
 
149
                property string initialSession: ""
 
150
 
144
151
                divider.visible: false
145
 
 
146
152
                visible: y > sessionsList.headerItem.y
147
153
                + sessionsList.headerItem.height
148
154
                - sessionsList.anchors.margins
157
163
                }
158
164
 
159
165
                Rectangle {
 
166
                    id: backgroundHighlight
 
167
 
 
168
                    height: sessionsList.currentItem.height
 
169
                    width: sessionsList.currentItem.width
 
170
                    color: theme.palette.normal.selection
 
171
 
 
172
                    visible: initialSession === key && !!key
 
173
                }
 
174
 
 
175
                Rectangle {
160
176
                    height: parent.height
161
177
                    width: parent.width
162
178
                    color: "transparent"
171
187
                ListItemLayout {
172
188
                    id: layout
173
189
 
 
190
                    readonly property color itemColor: theme.palette.normal.raisedText
174
191
                    SessionIcon {
175
192
                        id: sessionIcon
176
193
                        source: icon_url
177
194
                        SlotsLayout.position: SlotsLayout.Leading
178
 
                        color: theme.palette.normal.raisedSecondaryText
 
195
                        color: parent.itemColor
179
196
                    }
180
197
 
181
198
                    title.text: display
182
 
                    title.color: theme.palette.normal.raisedText
 
199
                    title.color: itemColor
183
200
                }
184
201
            }
185
202
        }