~ubuntu-branches/ubuntu/quantal/lightdm-kde/quantal

« back to all changes in this revision

Viewing changes to themes/userbar/main.qml

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-04-18 15:20:54 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120418152054-ahcwjazzqvda1u5n
Tags: 0.1.0-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
*/
19
19
import QtQuick 1.0
20
20
import org.kde.plasma.graphicswidgets 0.1 as PlasmaWidgets
 
21
import org.kde.plasma.components 0.1 as PlasmaComponents
21
22
import org.kde.plasma.core 0.1 as PlasmaCore
22
23
import MyLibrary 1.0 as LightDMPlasmaWidgets
23
24
 
26
27
    width: screenSize.width;
27
28
    height: screenSize.height;
28
29
 
 
30
    property string guestLogin: "*guest"
 
31
 
29
32
    Image {
30
33
        fillMode: Image.PreserveAspectCrop
31
34
        source: plasmaTheme.wallpaperPath()
41
44
        }
42
45
 
43
46
        onAuthenticationComplete: {
44
 
            var session = sessionCombo.itemData(sessionCombo.currentIndex);
 
47
            var session = sessionButton.dataForIndex(sessionButton.currentIndex);
 
48
            console.log("session: " + session);
45
49
            if (session == "") {
46
50
                session = "default";
47
51
            }
54
58
        }
55
59
    }
56
60
 
57
 
    Text {
 
61
    Component.onCompleted: {
 
62
        setTabOrder([usersList, loginButtonItem, sessionButton, suspendButton, hibernateButton, restartButton, shutdownButton]);
 
63
        usersList.forceActiveFocus();
 
64
    }
 
65
 
 
66
    function setTabOrder(lst) {
 
67
        var idx;
 
68
        var lastIdx = lst.length - 1;
 
69
        for (idx = 0; idx <= lastIdx; ++idx) {
 
70
            var item = lst[idx];
 
71
            item.KeyNavigation.backtab = lst[idx > 0 ? idx - 1 : lastIdx];
 
72
            item.KeyNavigation.tab = lst[idx < lastIdx ? idx + 1 : 0];
 
73
        }
 
74
    }
 
75
 
 
76
    PlasmaComponents.Label {
58
77
        id: welcomeLabel
59
78
        anchors.horizontalCenter: parent.horizontalCenter
60
79
        anchors.top: parent.top
 
80
        anchors.topMargin: 5
61
81
        font.pointSize: 14
62
82
        text: i18n("Welcome to %1", greeter.hostname);
63
83
    }
66
86
        id: feedbackLabel
67
87
        anchors.horizontalCenter: parent.horizontalCenter
68
88
        anchors.top: welcomeLabel.bottom
 
89
        anchors.topMargin: 5
69
90
        font.pointSize: 14
70
91
    }
71
92
 
72
 
    property int userItemWidth: 150
73
 
    property int userItemHeight: 150
 
93
    property int userItemWidth: 120
 
94
    property int userItemHeight: 80
 
95
    property int userFaceSize: 64
74
96
 
75
 
    property int padding: 20
 
97
    property int padding: 6
76
98
 
77
99
    Component {
78
100
        id: userDelegate
81
103
            id: wrapper
82
104
 
83
105
            property bool isCurrent: ListView.isCurrentItem
 
106
            property bool activeFocus: ListView.view.activeFocus
84
107
 
85
108
            /* Expose current item info to the outer world. I can't find
86
109
             * another way to access this from outside the list. */
99
122
            }
100
123
 
101
124
            PlasmaCore.FrameSvgItem {
 
125
                id: frameFocus
 
126
                anchors {
 
127
                    fill: frame
 
128
                    leftMargin: -margins.left
 
129
                    topMargin: -margins.top
 
130
                    bottomMargin: -margins.bottom
 
131
                    rightMargin: -margins.right
 
132
                }
 
133
                imagePath: "widgets/button"
 
134
                prefix: "hover"
 
135
                visible: wrapper.isCurrent
 
136
                opacity: wrapper.activeFocus ? 1 : 0
 
137
                Behavior on opacity {
 
138
                    NumberAnimation { duration: 100 }
 
139
                }
 
140
            }
 
141
 
 
142
            PlasmaCore.FrameSvgItem {
 
143
                id: frame
102
144
                anchors.centerIn: face
103
145
                width: face.width + padding * 2
104
146
                height: face.height + padding * 2
105
 
                imagePath: "opaque/dialogs/background"
106
 
                opacity: 0.618
 
147
                imagePath: "widgets/lineedit"
 
148
                prefix: "base"
 
149
                enabledBorders: "NoBorder"
 
150
            }
 
151
 
 
152
            PlasmaCore.FrameSvgItem {
 
153
                id: frameHover
 
154
                anchors.fill: frame
 
155
                imagePath: "widgets/lineedit"
 
156
                prefix: "hover"
 
157
                opacity: (mouseArea.containsMouse && !(wrapper.isCurrent && wrapper.activeFocus)) ? 1 : 0
 
158
                Behavior on opacity {
 
159
                    NumberAnimation { duration: 100 }
 
160
                }
107
161
            }
108
162
 
109
163
            Face {
111
165
                anchors.bottom: loginText.top
112
166
                anchors.horizontalCenter: parent.horizontalCenter
113
167
                anchors.bottomMargin: padding * 1.5
114
 
                width: 48
115
 
                height: 48
 
168
                sourceSize.width: userFaceSize
 
169
                sourceSize.height: userFaceSize
116
170
                source: "image://face/" + name
117
171
            }
 
172
 
118
173
            Text {
119
174
                id: loginText
120
175
                anchors.bottom: parent.bottom
123
178
            }
124
179
 
125
180
            MouseArea {
 
181
                id: mouseArea
126
182
                anchors.fill: parent
127
 
                enabled: !isCurrent
128
 
                onClicked: wrapper.ListView.view.currentIndex = index;
 
183
                hoverEnabled: true
 
184
                onClicked: {
 
185
                    wrapper.ListView.view.currentIndex = index;
 
186
                    wrapper.ListView.view.forceActiveFocus();
 
187
                }
129
188
            }
130
189
        }
131
190
    }
132
191
 
133
192
    function startLogin() {
134
193
        var username = usersList.currentItem.username;
135
 
        if (username == "*guest") {
 
194
        if (username == guestLogin) {
136
195
            greeter.authenticateAsGuest();
137
196
        } else {
138
197
            greeter.authenticate(username);
139
198
        }
140
199
    }
141
200
 
142
 
    // Central item. This item is used to position the main items in the screen.
143
 
    Item {
144
 
        property int widgetHeight: 30
145
 
 
146
 
        anchors.horizontalCenter: parent.horizontalCenter
147
 
        /* Hack: we want to have 1/3 space above and 2/3 space below the main
148
 
         * items. We could use (parent.height - childrenRect.height) / 3 but
149
 
         * that causes the view to move down when selecting the guest session
150
 
         * because childrenRect.height decreases. Instead we compute a static
151
 
         * height for our items.
152
 
         */
153
 
        y: (parent.height -
154
 
            (usersList.height
155
 
            + fixedWidgetsColumn.anchors.topMargin
156
 
            + 3 * widgetHeight
157
 
            + 2 * fixedWidgetsColumn.spacing
158
 
            )) / 3
 
201
    ListView {
 
202
        id: usersList
 
203
        anchors {
 
204
            horizontalCenter: parent.horizontalCenter
 
205
            bottom: loginButtonItem.top
 
206
            bottomMargin: 24
 
207
        }
159
208
        width: parent.width
160
 
 
161
 
        ListView {
162
 
            id: usersList
163
 
            anchors.horizontalCenter: parent.horizontalCenter
164
 
            y: 0
165
 
            focus: true
166
 
            width: parent.width
167
 
            height: userItemHeight
168
 
 
169
 
            model: usersModel
170
 
 
171
 
            cacheBuffer: count * 80
172
 
 
173
 
            delegate: userDelegate
174
 
 
175
 
            orientation: ListView.Horizontal
176
 
 
177
 
            highlightRangeMode: ListView.StrictlyEnforceRange
178
 
            preferredHighlightBegin: width / 2 - userItemWidth / 2
179
 
            preferredHighlightEnd: width / 2 + userItemWidth / 2
 
209
        height: userItemHeight
 
210
 
 
211
        model: usersModel
 
212
 
 
213
        cacheBuffer: count * 80
 
214
 
 
215
        delegate: userDelegate
 
216
 
 
217
        orientation: ListView.Horizontal
 
218
 
 
219
        highlightRangeMode: ListView.StrictlyEnforceRange
 
220
        preferredHighlightBegin: width / 2 - userItemWidth / 2
 
221
        preferredHighlightEnd: width / 2 + userItemWidth / 2
 
222
    }
 
223
 
 
224
    FocusScope {
 
225
        id: loginButtonItem
 
226
        anchors {
 
227
            horizontalCenter: parent.horizontalCenter
 
228
            bottom: parent.verticalCenter
180
229
        }
181
 
 
182
 
        // Fixed widgets
183
 
        Column {
184
 
            id: fixedWidgetsColumn
185
 
            anchors.top: usersList.bottom
 
230
        height: 30
 
231
 
 
232
        property bool isGuestLogin: usersList.currentItem.username == guestLogin
 
233
 
 
234
        /*PlasmaComponents.*/TextField {
 
235
            id: passwordInput
186
236
            anchors.horizontalCenter: parent.horizontalCenter
187
237
            width: 200
188
 
            anchors.topMargin: 2 * padding
189
 
            spacing: padding
190
 
 
191
 
            LightDMPlasmaWidgets.PasswordLineEdit {
192
 
                id: passwordInput
193
 
                width: parent.width
194
 
                height: widgetHeight
195
 
                clickMessage: i18n("Password")
196
 
                onReturnPressed: startLogin();
197
 
                visible: usersList.currentItem.username != "*guest"
198
 
            }
199
 
 
200
 
            LightDMPlasmaWidgets.ModelComboBox {
201
 
                id: sessionCombo
202
 
                width: parent.width
203
 
                height: widgetHeight
204
 
                model: sessionsModel
205
 
                currentIndex: indexForData(usersList.currentItem.usersession, sessionsModel.key)
206
 
            }
207
 
 
208
 
            PlasmaWidgets.PushButton {
 
238
            height: parent.height
 
239
            focus: !loginButtonItem.isGuestLogin
 
240
            opacity: loginButtonItem.isGuestLogin ? 0 : 1
 
241
 
 
242
            echoMode: TextInput.Password
 
243
            placeholderText: i18n("Password")
 
244
            onAccepted: startLogin();
 
245
 
 
246
            PlasmaComponents.ToolButton {
209
247
                id: loginButton
210
 
                anchors.horizontalCenter: parent.horizontalCenter
211
 
                height: widgetHeight
212
 
                text: i18n("Login")
 
248
                anchors {
 
249
                    right: parent.right
 
250
                    rightMargin: y
 
251
                    verticalCenter: parent.verticalCenter
 
252
                }
 
253
                width: implicitWidth
 
254
                height: width
 
255
 
 
256
                iconSource: "go-jump-locationbar"
213
257
                onClicked: startLogin();
214
258
            }
215
 
        }
216
 
    }
217
 
 
218
 
    // Bottom "Settings" bar
 
259
 
 
260
            Behavior on opacity {
 
261
                NumberAnimation { duration: 100 }
 
262
            }
 
263
        }
 
264
 
 
265
        PlasmaComponents.Button {
 
266
            id: guestLoginButton
 
267
            anchors.horizontalCenter: parent.horizontalCenter
 
268
            width: userFaceSize + 2 * padding
 
269
            height: parent.height
 
270
            focus: loginButtonItem.isGuestLogin
 
271
            opacity: 1 - passwordInput.opacity
 
272
 
 
273
            iconSource: loginButton.iconSource
 
274
            text: "Login"
 
275
            onClicked: startLogin();
 
276
 
 
277
            Behavior on opacity {
 
278
                NumberAnimation { duration: 100 }
 
279
            }
 
280
        }
 
281
    }
 
282
 
 
283
    ListButton {
 
284
        id: sessionButton
 
285
        anchors {
 
286
            top: loginButtonItem.bottom
 
287
            topMargin: 24
 
288
            bottom: powerBar.top
 
289
            horizontalCenter: parent.horizontalCenter
 
290
        }
 
291
 
 
292
        model: sessionsModel
 
293
        dataRole: "key"
 
294
        currentIndex: indexForData(usersList.currentItem.usersession)
 
295
    }
 
296
 
 
297
    // Bottom "Power" bar
219
298
    PlasmaCore.FrameSvgItem {
 
299
        id: powerBar
220
300
        anchors.bottom: parent.bottom
221
301
        anchors.right: parent.right
222
302
        width: childrenRect.width + margins.left
224
304
        imagePath: "translucent/widgets/panel-background"
225
305
        prefix: "south-mini"
226
306
 
227
 
        // Hack to hide left and bottom corners. Tried to use enabledBorders but failed.
228
 
        anchors.rightMargin: -margins.right
229
 
        anchors.bottomMargin: -margins.bottom
 
307
        enabledBorders: "LeftBorder|TopBorder"
230
308
 
231
309
        Row {
232
310
            spacing: 5
233
311
            x: parent.margins.left
234
312
            y: parent.margins.top
235
313
 
236
 
            PowerButton {
 
314
            /*PlasmaComponents.*/ToolButton {
 
315
                id: suspendButton
237
316
                text: i18n("Suspend")
238
 
                icon: QIcon("system-suspend")
 
317
                iconSource: "system-suspend"
239
318
                enabled: power.canSuspend;
240
319
                onClicked: power.suspend();
241
320
            }
242
321
 
243
 
            PowerButton {
 
322
            /*PlasmaComponents.*/ToolButton {
 
323
                id: hibernateButton
244
324
                text: i18n("Hibernate")
245
 
                icon: QIcon("system-suspend-hibernate")
 
325
                iconSource: "system-suspend-hibernate"
246
326
                enabled: power.canHibernate
247
327
                onClicked: power.hibernate();
248
328
            }
249
329
 
250
 
            PowerButton {
 
330
            /*PlasmaComponents.*/ToolButton {
 
331
                id: restartButton
251
332
                text: i18n("Restart")
252
 
                icon: QIcon("system-reboot")
 
333
                iconSource: "system-reboot"
253
334
                enabled: power.canRestart
254
335
                onClicked: power.restart();
255
336
            }
256
337
 
257
 
            PowerButton {
 
338
            /*PlasmaComponents.*/ToolButton {
 
339
                id: shutdownButton
258
340
                text: i18n("Shutdown")
259
 
                icon: QIcon("system-shutdown")
 
341
                iconSource: "system-shutdown"
260
342
                enabled: power.canShutdown
261
343
                onClicked: power.shutDown();
262
344
            }