LockScreen.qml 3.99 KB
Newer Older
Aaron J. Seigo's avatar
Aaron J. Seigo committed
1
import QtQuick 2.0
Aaron J. Seigo's avatar
Aaron J. Seigo committed
2
3
import org.kde.plasma.core 2.0 as PlasmaCore
import "../components"
Aaron J. Seigo's avatar
Aaron J. Seigo committed
4

Aaron J. Seigo's avatar
Aaron J. Seigo committed
5
Leaves {
6
    id: lockscreen
7
    signal tryUnlock(string code)
8

Aaron J. Seigo's avatar
Aaron J. Seigo committed
9
10
11
12
13
    PlasmaCore.Svg {
        id: symbolsSvg
        imagePath:  Qt.resolvedUrl("images/symbols.svgz")
    }

Aaron J. Seigo's avatar
Aaron J. Seigo committed
14
    MouseArea {
Aaron J. Seigo's avatar
Aaron J. Seigo committed
15
        anchors.fill: parent
Aaron J. Seigo's avatar
Aaron J. Seigo committed
16
        onPressed: {
Aaron J. Seigo's avatar
Aaron J. Seigo committed
17
            stripe.opacity = 1;
Aaron J. Seigo's avatar
Aaron J. Seigo committed
18
        }
Aaron J. Seigo's avatar
Aaron J. Seigo committed
19
20
    }

Aaron J. Seigo's avatar
time    
Aaron J. Seigo committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
    PlasmaCore.DataSource {
        id: dataSource
        engine: "time"
        connectedSources: "Local"
        interval: 30000

        onDataChanged: {
            var date = new Date(data["Local"]["DateTime"]);
            hour.text = date.getHours();
            minute.text = date.getMinutes();
        }

        Component.onCompleted: {
            onDataChanged();
        }
    }

    Text {
        id: hour

        onTextChanged: {
            if (text.length < 2) {
                minute.text = "0" + text;
            }
        }

        anchors {
            top: parent.top
            left: parent.left
            right: parent.right
            bottom: stripe.top
        }
        color: "white" // FIXME: base on wallpaper?
        text: "00"
        font.pixelSize: Math.floor((width - (units.largeSpacing)) / 2)
        horizontalAlignment: Qt.AlignCenter
        verticalAlignment: Qt.AlignVCenter
    }

Aaron J. Seigo's avatar
Aaron J. Seigo committed
60
61
    SatelliteStripe {
        id: stripe
Aaron J. Seigo's avatar
Aaron J. Seigo committed
62
63
        opacity: 0

64
65
        property string code

66
        function lockKeyPressed(id) {
Aaron J. Seigo's avatar
Aaron J. Seigo committed
67
            hideTimer.stop();
68
            code += id;
69
        }
Aaron J. Seigo's avatar
Aaron J. Seigo committed
70

71
        function lockKeyReleased(id) {
Aaron J. Seigo's avatar
Aaron J. Seigo committed
72
            hideTimer.start();
73
            code += id;
74
75
        }

Aaron J. Seigo's avatar
Aaron J. Seigo committed
76
77
        Behavior on opacity {
            NumberAnimation {
Aaron J. Seigo's avatar
Aaron J. Seigo committed
78
                duration: 500
Aaron J. Seigo's avatar
Aaron J. Seigo committed
79
80
81
                easing.type: Easing.InOutQuad
            }
        }
Aaron J. Seigo's avatar
Aaron J. Seigo committed
82

Aaron J. Seigo's avatar
Aaron J. Seigo committed
83
84
85
        MouseArea {
            anchors.fill: parent
            onPressed: {
86
87
88
89
90
                if (stripe.opacity < 1) {
                    stripe.opacity = 1;
                    return;
                }

Aaron J. Seigo's avatar
Aaron J. Seigo committed
91
92
                stripe.lockKeyPressed(stripe.childAt(mouseX, mouseY).value);
            }
Aaron J. Seigo's avatar
Aaron J. Seigo committed
93

Aaron J. Seigo's avatar
Aaron J. Seigo committed
94
            onReleased: {
95
96
97
98
                if (stripe.opacity < 1) {
                    return;
                }

Aaron J. Seigo's avatar
Aaron J. Seigo committed
99
100
101
102
                stripe.lockKeyReleased(stripe.childAt(mouseX, mouseY).value);
            }
        }

Aaron J. Seigo's avatar
Aaron J. Seigo committed
103
104
105
106
        Timer {
            id: hideTimer
            interval: 1000
            running: parent.opacity == 1
107
108
109
110
111
            onTriggered: {
                stripe.opacity = 0;
                lockscreen.tryUnlock(stripe.code);
                stripe.code = '';
            }
Aaron J. Seigo's avatar
Aaron J. Seigo committed
112
113
        }

114
        LockKey {
Aaron J. Seigo's avatar
Aaron J. Seigo committed
115
            id: square
116
            value: 1
Aaron J. Seigo's avatar
Aaron J. Seigo committed
117
            anchors.left: parent.left
Aaron J. Seigo's avatar
Aaron J. Seigo committed
118
119
120
            elementId: "square"
        }

121
        LockKey {
Aaron J. Seigo's avatar
Aaron J. Seigo committed
122
            id: circle
123
            value: 2
Aaron J. Seigo's avatar
Aaron J. Seigo committed
124
125
126
127
128
            anchors.left: square.right

            elementId: "circle"
        }

129
        LockKey {
Aaron J. Seigo's avatar
Aaron J. Seigo committed
130
            id: ex
131
            value: 3
Aaron J. Seigo's avatar
Aaron J. Seigo committed
132
133
134
135
136
137
            anchors.left: circle.right

            elementId: "ex"

        }

138
        LockKey {
Aaron J. Seigo's avatar
Aaron J. Seigo committed
139
            id: triangle
140
            value: 4
Aaron J. Seigo's avatar
Aaron J. Seigo committed
141
142
143
144
            anchors.left: ex.right

            elementId: "triangle"
        }
145
    }
Aaron J. Seigo's avatar
time    
Aaron J. Seigo committed
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162


    Text {
        id: minute

        onTextChanged: {
            if (text.length < 2) {
                minute.text = "0" + text;
            }
        }

        anchors {
            top: stripe.bottom
            left: parent.left
            right: parent.right
            bottom: parent.bottom
        }
Aaron J. Seigo's avatar
Aaron J. Seigo committed
163
        color: hour.color
Aaron J. Seigo's avatar
time    
Aaron J. Seigo committed
164
165
166
167
168
        text: "00"
        font.pixelSize: Math.floor((width - (units.largeSpacing)) / 2)
        horizontalAlignment: Qt.AlignCenter
        verticalAlignment: Qt.AlignVCenter
    }
Aaron J. Seigo's avatar
Aaron J. Seigo committed
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188

    Text {
        id: emergencyCall

        anchors {
            left: parent.left
            right: parent.right
            bottom: parent.bottom
        }

        horizontalAlignment: Qt.AlignCenter
        color: minute.color
        text: i18n("Emergency Call")

        MouseArea {
            anchors.fill: parent
            onClicked: { print("FIXME: Launch the dialer service!") }
        }
    }
}